openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gerdo...@apache.org
Subject svn commit: r739084 - in /incubator/openwebbeans/trunk/samples/guess/src/main: java/org/apache/webbeans/sample/guess/ webapp/ webapp/WEB-INF/
Date Thu, 29 Jan 2009 23:51:31 GMT
Author: gerdogdu
Date: Thu Jan 29 23:51:31 2009
New Revision: 739084

URL: http://svn.apache.org/viewvc?rev=739084&view=rev
Log:
Updated examples.

Added:
    incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/
    incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/Highest.java
  (with props)
    incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/JSFNumberGuess.java
  (with props)
    incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NextNumber.java
  (with props)
    incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NumberProducer.java
  (with props)
Modified:
    incubator/openwebbeans/trunk/samples/guess/src/main/webapp/WEB-INF/beans.xml
    incubator/openwebbeans/trunk/samples/guess/src/main/webapp/home.xhtml
    incubator/openwebbeans/trunk/samples/guess/src/main/webapp/login.xhtml

Added: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/Highest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/Highest.java?rev=739084&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/Highest.java
(added)
+++ incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/Highest.java
Thu Jan 29 23:51:31 2009
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.webbeans.sample.guess;
+
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+@BindingType
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+public @interface Highest
+{
+
+}

Propchange: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/Highest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/JSFNumberGuess.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/JSFNumberGuess.java?rev=739084&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/JSFNumberGuess.java
(added)
+++ incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/JSFNumberGuess.java
Thu Jan 29 23:51:31 2009
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
+ * or agreed to in writing, software distributed under the License is
+ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.apache.webbeans.sample.guess;
+
+import java.lang.annotation.Annotation;
+
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.inject.AnnotationLiteral;
+import javax.inject.Current;
+import javax.inject.Initializer;
+import javax.inject.manager.Manager;
+
+@Named(value = "game")
+@SessionScoped
+public class JSFNumberGuess
+{
+    private int no;
+    private boolean correct = false;
+    private int guess = 1;
+    private int smallRange;
+    private int maxRange;
+    private int remainder;
+    private @Current
+    Manager manager;
+
+    public JSFNumberGuess()
+    {
+
+    }
+
+    @Initializer
+    public JSFNumberGuess(@NextNumber Integer number, @Highest Integer maxNumber)
+    {
+        this.no = number;
+        this.smallRange = 1;
+        this.maxRange = maxNumber;
+        this.remainder = 10;
+    }
+
+    public String clear()
+    {
+        Annotation[] anns = new Annotation[1];
+        anns[0] = new AnnotationLiteral<NextNumber>()
+        {
+        };
+
+        Annotation[] anns2 = new Annotation[1];
+        anns2[0] = new AnnotationLiteral<Highest>()
+        {
+        };
+
+        this.no = manager.getInstanceByType(Integer.class, anns);
+        setSmallRange(1);
+        setMaxRange(manager.getInstanceByType(Integer.class, anns2));
+        setRemainder(10);
+        setGuess(1);
+        setCorrect(false);
+
+        return null;
+    }
+
+    public String checkNumber()
+    {
+        if (correct)
+        {
+            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Game is
over! Please restart the game..."));
+            return null;
+        }
+
+        if (guess > no)
+        {
+            maxRange = guess - 1;
+        }
+        if (guess < no)
+        {
+            smallRange = guess + 1;
+        }
+        if (guess == no)
+        {
+            correct = true;
+            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Correct!
Please restart the game..."));
+
+            return null;
+        }
+
+        if (remainder == 0)
+        {
+            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Game is
over! Please restart the game..."));
+            this.correct = false;
+
+            return null;
+        }
+        else
+        {
+            remainder-=1;
+        }
+
+        return null;
+    }
+
+    /**
+     * @return the no
+     */
+    public int getNo()
+    {
+        return no;
+    }
+
+    /**
+     * @param no the no to set
+     */
+    public void setNo(int no)
+    {
+        this.no = no;
+    }
+
+    /**
+     * @return the correct
+     */
+    public boolean isCorrect()
+    {
+        return correct;
+    }
+
+    /**
+     * @param correct the correct to set
+     */
+    public void setCorrect(boolean correct)
+    {
+        this.correct = correct;
+    }
+
+    /**
+     * @return the guess
+     */
+    public int getGuess()
+    {
+        return guess;
+    }
+
+    /**
+     * @param guess the guess to set
+     */
+    public void setGuess(int guess)
+    {
+        this.guess = guess;
+    }
+
+    /**
+     * @return the smallRange
+     */
+    public int getSmallRange()
+    {
+        return smallRange;
+    }
+
+    /**
+     * @param smallRange the smallRange to set
+     */
+    public void setSmallRange(int smallRange)
+    {
+        this.smallRange = smallRange;
+    }
+
+    /**
+     * @return the maxRange
+     */
+    public int getMaxRange()
+    {
+        return maxRange;
+    }
+
+    /**
+     * @param maxRange the maxRange to set
+     */
+    public void setMaxRange(int maxRange)
+    {
+        this.maxRange = maxRange;
+    }
+
+    /**
+     * @return the remainder
+     */
+    public int getRemainder()
+    {
+        return remainder;
+    }
+
+    /**
+     * @param remainder the remainder to set
+     */
+    public void setRemainder(int remainder)
+    {
+        this.remainder = remainder;
+    }
+
+    /**
+     * @return the manager
+     */
+    public Manager getManager()
+    {
+        return manager;
+    }
+
+    /**
+     * @param manager the manager to set
+     */
+    public void setManager(Manager manager)
+    {
+        this.manager = manager;
+    }
+
+}

Propchange: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/JSFNumberGuess.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NextNumber.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NextNumber.java?rev=739084&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NextNumber.java
(added)
+++ incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NextNumber.java
Thu Jan 29 23:51:31 2009
@@ -0,0 +1,39 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.webbeans.sample.guess;
+
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+@BindingType
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+public @interface NextNumber
+{
+
+}

Propchange: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NextNumber.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NumberProducer.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NumberProducer.java?rev=739084&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NumberProducer.java
(added)
+++ incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NumberProducer.java
Thu Jan 29 23:51:31 2009
@@ -0,0 +1,49 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.webbeans.sample.guess;
+
+
+import javax.annotation.Named;
+import javax.context.SessionScoped;
+import javax.inject.Produces;
+
+@SessionScoped
+@Named
+public class NumberProducer 
+{
+   
+    private int number = 100;
+    
+    public NumberProducer()
+    {
+        
+    }
+      
+   @Produces    
+   @NextNumber
+   public Integer next() { 
+      return new Integer(new java.util.Random().nextInt(101)); 
+   }
+   
+   @Produces 
+   @Highest
+   public Integer getNumber()
+   {
+      return number;
+   }   
+   
+} 
\ No newline at end of file

Propchange: incubator/openwebbeans/trunk/samples/guess/src/main/java/org/apache/webbeans/sample/guess/NumberProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/openwebbeans/trunk/samples/guess/src/main/webapp/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/samples/guess/src/main/webapp/WEB-INF/beans.xml?rev=739084&r1=739083&r2=739084&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/samples/guess/src/main/webapp/WEB-INF/beans.xml (original)
+++ incubator/openwebbeans/trunk/samples/guess/src/main/webapp/WEB-INF/beans.xml Thu Jan 29
23:51:31 2009
@@ -17,9 +17,9 @@
 specific language governing permissions and limitations
 under the License.
 -->
-<WebBeans 	xmlns="urn:java:javax.webbeans"
+<WebBeans 	xmlns="urn:java:ee"
  			xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-			xsi:schemaLocation="urn:java:javax.webbeans http://java.sun.com/jee/web-beans-1.0.xsd">
+			xsi:schemaLocation="urn:java:ee http://java.sun.com/jee/beans-1.0.xsd">
 	
 	<Deploy>
 		<Standard/>

Modified: incubator/openwebbeans/trunk/samples/guess/src/main/webapp/home.xhtml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/samples/guess/src/main/webapp/home.xhtml?rev=739084&r1=739083&r2=739084&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/samples/guess/src/main/webapp/home.xhtml (original)
+++ incubator/openwebbeans/trunk/samples/guess/src/main/webapp/home.xhtml Thu Jan 29 23:51:31
2009
@@ -21,11 +21,33 @@
 	   	<h2>
 			<h:outputText value="Hello #{currentUser.userName} #{currentUser.password}"></h:outputText>
 		</h2>
-    	
-        </h:form>
 		
-    </div>
-    
+      <h1>Please guess a number...</h1>
+   
+          <div style="color: red">
+             <h:messages id="messages" globalOnly="true"/>
+             <h:outputText id="higher" value="Higher..." rendered="#{game.no gt game.guess}"/>
+             <h:outputText id="lower" value="Lower..." rendered="#{game.no lt game.guess}"/>
+          </div>
+   
+          <div>
+             Please guess a number between #{game.smallRange} and #{game.maxRange}. Your
remaining guesses : #{game.remainder}.
+          </div>
+     
+          <div>
+             Your guessed number: 
+             <h:inputText id="inputGuess" value="#{game.guess}" required="true" size="3">
+                <f:validateLongRange maximum="#{game.maxRange}" minimum="#{game.smallRange}"/>
+             </h:inputText>
+            <h:commandButton id="GuessButton" value="Guess Number" action="#{game.checkNumber}"/>
+            <h:commandButton id="Restart" value="Restart" action="#{game.clear}"/>
+          </div>
+   
+          <div>
+             <h:message id="message" for="inputGuess" style="color: red"/>
+          </div>
+        </h:form>
+    </div>    
   </div>
 </body>
 </html>
\ No newline at end of file

Modified: incubator/openwebbeans/trunk/samples/guess/src/main/webapp/login.xhtml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/samples/guess/src/main/webapp/login.xhtml?rev=739084&r1=739083&r2=739084&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/samples/guess/src/main/webapp/login.xhtml (original)
+++ incubator/openwebbeans/trunk/samples/guess/src/main/webapp/login.xhtml Thu Jan 29 23:51:31
2009
@@ -21,7 +21,7 @@
 				<span style="color:red;">User name : admin, Password : admin</span>
 			</div>
 			
-			<div align="center">
+			<div align="center" style="border:1px solid black;">
 			
 				<h:panelGrid columns="2">
 					



Mime
View raw message