geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r722914 - in /geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main: java/sample/HelloworldServletRequestAttributeListener.java webapp/WEB-INF/web.composite webapp/WEB-INF/web.xml
Date Wed, 03 Dec 2008 14:55:50 GMT
Author: vamsic007
Date: Wed Dec  3 06:55:50 2008
New Revision: 722914

URL: http://svn.apache.org/viewvc?rev=722914&view=rev
Log:
Added a ServletRequestAttributeListener.

Added:
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java
  (with props)
Modified:
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml

Added: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java?rev=722914&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java
(added)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java
Wed Dec  3 06:55:50 2008
@@ -0,0 +1,153 @@
+/*
+ * 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 sample;
+
+import javax.servlet.ServletRequestAttributeEvent;
+import javax.servlet.ServletRequestAttributeListener;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.annotations.ComponentName;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * A ServletRequestAttributeListener that invokes SCA Helloworld services through injected
references.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class HelloworldServletRequestAttributeListener implements ServletRequestAttributeListener
{
+    @Reference
+    protected Helloworld ralservice;
+    
+    // Reference name specified in the annotation
+    @Reference(name="ralservice2")
+    protected Helloworld ser2;
+    
+    // Reference annotation on setter method
+    private Helloworld ser3;
+    @Reference
+    public void setRalservice3(Helloworld service3) {
+        this.ser3 = service3;
+    }
+    
+    /* Test for required */
+    @Reference(required=false)
+    protected Helloworld ralservice4;
+    
+    @Reference(required=false)
+    protected Helloworld ralservice5;
+    
+    @Reference(required=true)
+    protected Helloworld ralservice6;
+
+    @Property
+    protected String ralproperty1;
+    
+    // Property name specified in the annotation
+    @Property(name="ralproperty2")
+    protected int prop2;
+    
+    // Property annotation on setter method
+    private double prop3;
+    @Property
+    public void setRalproperty3(double property3) {
+        this.prop3 = property3;
+    }
+    
+    /* Test for required */
+    @Property(required=false)
+    protected String ralproperty4;
+
+    @Property(required=false)
+    protected String ralproperty5;
+
+    @Property(required=true)
+    protected String ralproperty6;
+    
+    @ComponentName
+    protected String scaComponentName;
+
+    // Annotation on setter method
+    private String scaComponentName1;
+    @ComponentName
+    public void setScaComponentName1(String scaComponentName1) {
+        this.scaComponentName1 = scaComponentName1;
+    }
+    
+    @Context
+    protected ComponentContext componentContext;
+
+    // Annotation on setter method
+    private ComponentContext componentContext1;
+    @Context
+    public void setCompContext(ComponentContext ctx) {
+        componentContext1 = ctx;
+    }
+
+    public void attributeAdded(ServletRequestAttributeEvent event) {
+        if(event.getName().equals(HelloworldServletRequestListener.HELLO_TXT)) {
+            event.getServletRequest().setAttribute(event.getName(), event.getValue()+prepareMessage("Bond"));
+        }
+    }
+
+    public void attributeRemoved(ServletRequestAttributeEvent event) {
+    }
+
+    public void attributeReplaced(ServletRequestAttributeEvent event) {
+    }
+    
+    private String prepareMessage(String name) {
+        StringBuffer sb = new StringBuffer();
+        String greeting = ralservice.sayHello(name);
+        String greeting2 = ser2.sayHello(name);
+        String greeting3 = ser3.sayHello(name);
+        
+        sb.append("<h2>Apache Tuscany Helloworld ServletRequestAttributeListener</h2>");
+        sb.append("<h3>@Reference</h3>");
+        sb.append("<br>Injected into field. <br><strong>Result: </strong>"
+ greeting);
+        sb.append("<br><br>Injected into field with reference name specified
in the annotation. <br><strong>Result: </strong>" + greeting2);
+        sb.append("<br><br>Injected using setter method. <br><strong>Result:
</strong>" + greeting3);
+        sb.append("<br><br>Required is false. Reference is not specified. "+ralservice4);
+        sb.append("<br><br>Required is false. Reference is specified. "+ralservice5);
+        sb.append("<br><br>Required is true. Reference is specified. "+ralservice6);
+        sb.append("<hr>");
+        
+        sb.append("<h3>@Property</h3>");
+        sb.append("<br>Injected into field: property1 = "+ralproperty1);
+        sb.append("<br>Injected into field with property name specified in the annotation:
property2 = "+prop2);
+        sb.append("<br>Injected using setter method: Property3 = "+prop3);
+        sb.append("<br>Required is false. Property is not specified. "+ralproperty4);
+        sb.append("<br>Required is false. Property is specified. "+ralproperty5);
+        sb.append("<br>Required is true. Property is specified. "+ralproperty6);
+        sb.append("<hr>");
+        
+        sb.append("<h3>@ComponentName</h3>");
+        sb.append("<br>Injected into annotated field: "+scaComponentName);
+        sb.append("<br>Injected using annotated method: "+scaComponentName1);
+        sb.append("<hr>");
+
+        sb.append("<h3>@Context</h3>");
+        sb.append("<br>Injected into annotated field: "+componentContext);
+        sb.append("<br>Injected using annotated method: "+componentContext1);
+        sb.append("<hr>");
+
+        return sb.toString();
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletRequestAttributeListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite?rev=722914&r1=722913&r2=722914&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite
(original)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.composite
Wed Dec  3 06:55:50 2008
@@ -68,5 +68,19 @@
         <!-- <property name="rlproperty4" type="xsd:string">RlProp4</property>
-->
         <property name="rlproperty5" type="xsd:string">RlProp5</property>
         <property name="rlproperty6" type="xsd:string">RlProp6</property>
+
+        <reference name="ralservice" target="HelloworldComponent"/>
+        <reference name="ralservice2" target="HelloworldTeluguComponent"/>
+        <reference name="Ralservice3" target="HelloworldFrenchComponent"/>
+        <!-- <reference name="ralservice4" target="HelloworldComponent"/> -->
+        <reference name="ralservice5" target="HelloworldComponent"/>
+        <reference name="ralservice6" target="HelloworldComponent"/>
+        
+        <property name="ralproperty1" type="xsd:string">RalProp1</property>
+        <property name="ralproperty2" type="xsd:int">700</property>
+        <property name="Ralproperty3" type="xsd:double">0.007</property>
+        <!-- <property name="rlproperty4" type="xsd:string">RalProp4</property>
-->
+        <property name="ralproperty5" type="xsd:string">RalProp5</property>
+        <property name="ralproperty6" type="xsd:string">RalProp6</property>
     </component>
 </composite>

Modified: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml?rev=722914&r1=722913&r2=722914&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml
(original)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/webapp/WEB-INF/web.xml
Wed Dec  3 06:55:50 2008
@@ -35,6 +35,9 @@
   <listener>
       <listener-class>sample.HelloworldServletRequestListener</listener-class>
   </listener>
+  <listener>
+      <listener-class>sample.HelloworldServletRequestAttributeListener</listener-class>
+  </listener>
 
   <welcome-file-list id="WelcomeFileList">
     <welcome-file>hello.jsp</welcome-file>



Mime
View raw message