You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by va...@apache.org on 2008/12/09 18:30:00 UTC

svn commit: r724790 - in /geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main: java/sample/HelloworldServlet.java webapp/WEB-INF/web.componentType webapp/WEB-INF/web.composite

Author: vamsic007
Date: Tue Dec  9 09:29:59 2008
New Revision: 724790

URL: http://svn.apache.org/viewvc?rev=724790&view=rev
Log:
Update the sample to add properties and references using componentType side file.

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

Modified: geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/java/sample/HelloworldServlet.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/java/sample/HelloworldServlet.java?rev=724790&r1=724789&r2=724790&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/java/sample/HelloworldServlet.java (original)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/java/sample/HelloworldServlet.java Tue Dec  9 09:29:59 2008
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.Writer;
 
+import javax.servlet.ServletConfig;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -63,6 +64,8 @@
     @Reference(required=true)
     protected Helloworld service6;
 
+    private Helloworld service0;
+
     @Property
     protected String property1;
     
@@ -87,6 +90,9 @@
     @Property(required=true)
     protected String property6;
     
+    private String property0;
+    private String property0D;
+    
     @ComponentName
     protected String scaComponentName;
 
@@ -106,11 +112,20 @@
     public void setCompContext(ComponentContext ctx) {
         componentContext1 = ctx;
     }
+    
+    @Override
+    public void init(ServletConfig config) {
+        // This method assumes that componentContext is injected.
+        service0 = componentContext.getService(Helloworld.class, "service0");
+        property0 = componentContext.getProperty(String.class, "property0");
+        property0D = componentContext.getProperty(String.class, "property0D");
+    }
 
     @Override
     protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
 
         String name = request.getParameter("name");
+        String greeting0 = service0.sayHello(name);
         String greeting = service.sayHello(name);
         String greeting2 = ser2.sayHello(name);
         String greeting3 = ser3.sayHello(name);
@@ -119,7 +134,8 @@
         out.write("<html><head><title>Apache Tuscany Helloworld Servlet Sample</title></head><body>");
         out.write("<h2>Apache Tuscany Helloworld Servlet Sample</h2>");
         out.write("<h3>@Reference</h3>");
-        out.write("<br>Injected into field. <br><strong>Result: </strong>" + greeting);
+        out.write("<br>Reference defined in componentType side file. <br><strong>Result: </strong>" + greeting0);
+        out.write("<br><br>Injected into field. <br><strong>Result: </strong>" + greeting);
         out.write("<br><br>Injected into field with reference name specified in the annotation. <br><strong>Result: </strong>" + greeting2);
         out.write("<br><br>Injected using setter method. <br><strong>Result: </strong>" + greeting3);
         out.write("<br><br>Required is false. Reference is not specified. "+service4);
@@ -128,6 +144,8 @@
         out.write("<hr>");
         
         out.write("<h3>@Property</h3>");
+        out.write("<br>Property defined in componentType side file: property0 = "+property0);
+        out.write("<br>Property with default value defined in componentType side file: property0D = "+property0D);
         out.write("<br>Injected into field: property1 = "+property1);
         out.write("<br>Injected into field with property name specified in the annotation: property2 = "+prop2);
         out.write("<br>Injected using setter method: Property3 = "+prop3);

Added: geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.componentType
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.componentType?rev=724790&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.componentType (added)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.componentType Tue Dec  9 09:29:59 2008
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+    <reference name="service0">
+        <interface.java interface="sample.Helloworld"/>
+    </reference>
+
+    <property name="property0D" type="xsd:string">Prop0DefaultVal</property>
+    <property name="property0" type="xsd:string"/>
+</componentType>

Propchange: geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.componentType
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Modified: geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.composite
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.composite?rev=724790&r1=724789&r2=724790&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.composite (original)
+++ geronimo/plugins/tuscany/trunk/samples/helloworld-servlet/src/main/webapp/WEB-INF/web.composite Tue Dec  9 09:29:59 2008
@@ -17,6 +17,9 @@
  * specific language governing permissions and limitations
  * under the License.    
 -->
+
+<!-- $Rev$ $Date$ -->
+
 <composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
            targetNamespace="http://sample"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
@@ -24,6 +27,7 @@
 
     <component name="bar">
         <implementation.web web-uri="helloworld-servlet.war"/>
+        <reference name="service0" target="HelloworldComponent"/>
         <reference name="service" target="HelloworldComponent" >
             <binding.sca/>
         </reference>
@@ -40,6 +44,7 @@
         
         <reference name="service6" target="HelloworldComponent"/>
 
+        <property name="property0" type="xsd:string">Prop0</property>
         <property name="property1" type="xsd:string">Prop1</property>
         <property name="property2" type="xsd:int">7</property>
         <property name="Property3" type="xsd:double">0.7</property>