geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r722866 - in /geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main: java/sample/HelloworldServletContextAttributeListener.java webapp/WEB-INF/web.composite webapp/WEB-INF/web.xml
Date Wed, 03 Dec 2008 12:27:12 GMT
Author: vamsic007
Date: Wed Dec  3 04:27:11 2008
New Revision: 722866

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

Added:
    geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletContextAttributeListener.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/HelloworldServletContextAttributeListener.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletContextAttributeListener.java?rev=722866&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletContextAttributeListener.java
(added)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletContextAttributeListener.java
Wed Dec  3 04:27:11 2008
@@ -0,0 +1,155 @@
+/*
+ * 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.ServletContextAttributeEvent;
+import javax.servlet.ServletContextAttributeListener;
+
+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 ServletContextAttributeListener that invokes SCA Helloworld services through injected
references and appends content to "hellotxt"
+ * attribute in the ServletContext.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class HelloworldServletContextAttributeListener implements ServletContextAttributeListener
{
+    @Reference
+    protected Helloworld calservice;
+    
+    // Reference name specified in the annotation
+    @Reference(name="calservice2")
+    protected Helloworld ser2;
+    
+    // Reference annotation on setter method
+    private Helloworld ser3;
+    @Reference
+    public void setCalservice3(Helloworld service3) {
+        this.ser3 = service3;
+    }
+    
+    /* Test for required */
+    @Reference(required=false)
+    protected Helloworld calservice4;
+    
+    @Reference(required=false)
+    protected Helloworld calservice5;
+    
+    @Reference(required=true)
+    protected Helloworld calservice6;
+
+    @Property
+    protected String calproperty1;
+    
+    // Property name specified in the annotation
+    @Property(name="calproperty2")
+    protected int prop2;
+    
+    // Property annotation on setter method
+    private double prop3;
+    @Property
+    public void setCalproperty3(double property3) {
+        this.prop3 = property3;
+    }
+    
+    /* Test for required */
+    @Property(required=false)
+    protected String calproperty4;
+
+    @Property(required=false)
+    protected String calproperty5;
+
+    @Property(required=true)
+    protected String calproperty6;
+    
+    @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(ServletContextAttributeEvent event) {
+		System.out.println("attributeAdded: " + event.getName());
+		if(event.getName().equals(HelloworldServletContextListener.HELLO_TXT)) {
+    		event.getServletContext().setAttribute(event.getName(), event.getValue()+prepareMessage("Chinnipandu"));
+		}
+	}
+
+	public void attributeRemoved(ServletContextAttributeEvent event) {
+	}
+
+	public void attributeReplaced(ServletContextAttributeEvent event) {
+	}
+
+    private String prepareMessage(String name) {
+        StringBuffer sb = new StringBuffer();
+        String greeting = calservice.sayHello(name);
+        String greeting2 = ser2.sayHello(name);
+        String greeting3 = ser3.sayHello(name);
+        
+        sb.append("<h2>Apache Tuscany Helloworld ServletContextAttributeListener</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. "+calservice4);
+        sb.append("<br><br>Required is false. Reference is specified. "+calservice5);
+        sb.append("<br><br>Required is true. Reference is specified. "+calservice6);
+        sb.append("<hr>");
+        
+        sb.append("<h3>@Property</h3>");
+        sb.append("<br>Injected into field: property1 = "+calproperty1);
+        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. "+calproperty4);
+        sb.append("<br>Required is false. Property is specified. "+calproperty5);
+        sb.append("<br>Required is true. Property is specified. "+calproperty6);
+        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/HelloworldServletContextAttributeListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-listener/src/main/java/sample/HelloworldServletContextAttributeListener.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=722866&r1=722865&r2=722866&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 04:27:11 2008
@@ -40,5 +40,19 @@
         <!-- <property name="clproperty4" type="xsd:string">ClProp4</property>
-->
         <property name="clproperty5" type="xsd:string">ClProp5</property>
         <property name="clproperty6" type="xsd:string">ClProp6</property>
+    
+        <reference name="calservice" target="HelloworldComponent"/>
+        <reference name="calservice2" target="HelloworldTeluguComponent"/>
+        <reference name="Calservice3" target="HelloworldFrenchComponent"/>
+        <!-- <reference name="calservice4" target="HelloworldComponent"/> -->
+        <reference name="calservice5" target="HelloworldComponent"/>
+        <reference name="calservice6" target="HelloworldComponent"/>
+        
+        <property name="calproperty1" type="xsd:string">CalProp1</property>
+        <property name="calproperty2" type="xsd:int">700</property>
+        <property name="Calproperty3" type="xsd:double">0.007</property>
+        <!-- <property name="calproperty4" type="xsd:string">CalProp4</property>
-->
+        <property name="calproperty5" type="xsd:string">CalProp5</property>
+        <property name="calproperty6" type="xsd:string">CalProp6</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=722866&r1=722865&r2=722866&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 04:27:11 2008
@@ -29,6 +29,9 @@
   <listener>
       <listener-class>sample.HelloworldServletContextListener</listener-class>
   </listener>
+  <listener>
+      <listener-class>sample.HelloworldServletContextAttributeListener</listener-class>
+  </listener>
 
   <welcome-file-list id="WelcomeFileList">
     <welcome-file>hello.jsp</welcome-file>



Mime
View raw message