geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r719569 - in /geronimo/plugins/tuscany/trunk: geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/ samples/helloworld-servlet/src/main/java/sample/ samples/helloworld-servlet/src/main/webapp/WEB-INF/
Date Fri, 21 Nov 2008 12:52:11 GMT
Author: vamsic007
Date: Fri Nov 21 04:52:11 2008
New Revision: 719569

URL: http://svn.apache.org/viewvc?rev=719569&view=rev
Log:
Handle required property of @Reference and @Property annotations.

Modified:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAPropertyReference.java
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAServiceReference.java
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
    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/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAPropertyReference.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAPropertyReference.java?rev=719569&r1=719568&r2=719569&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAPropertyReference.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAPropertyReference.java
Fri Nov 21 04:52:11 2008
@@ -27,6 +27,7 @@
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.xbean.naming.reference.SimpleReference;
 import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceRuntimeException;
 
 /**
  * @version $Rev$ $Date$
@@ -35,11 +36,13 @@
     private String componentName;
     private Class propertyType;
     private String propertyName;
+    private boolean required;
     
-    public SCAPropertyReference(Class propertyType, String componentName, String propertyName)
{
+    public SCAPropertyReference(Class propertyType, String componentName, String propertyName,
boolean required) {
         this.propertyType = propertyType;
         this.componentName = componentName;
         this.propertyName = propertyName;
+        this.required = required;
     }
 
     @Override
@@ -53,6 +56,14 @@
             }
         }
         
-        return componentContext.getProperty(propertyType, propertyName);
+        try {
+            return componentContext.getProperty(propertyType, propertyName);
+        } catch(ServiceRuntimeException e) {
+            if(!required && e.getMessage().startsWith("Property not found")) {
+                return null;
+            } else {
+                throw e;
+            }
+        }
     }
 }

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAServiceReference.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAServiceReference.java?rev=719569&r1=719568&r2=719569&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAServiceReference.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCAServiceReference.java
Fri Nov 21 04:52:11 2008
@@ -27,6 +27,7 @@
 import org.apache.tuscany.sca.runtime.RuntimeComponent;
 import org.apache.xbean.naming.reference.SimpleReference;
 import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceRuntimeException;
 
 /**
  * @version $Rev$ $Date$
@@ -35,11 +36,13 @@
     private String componentName;
     private String interfaceName;
     private String referenceName;
+    private boolean required;
     
-    public SCAServiceReference(String interfaceName, String componentName, String referenceName)
{
+    public SCAServiceReference(String interfaceName, String componentName, String referenceName,
boolean required) {
         this.interfaceName = interfaceName;
         this.componentName = componentName;
         this.referenceName = referenceName;
+        this.required = required;
     }
 
     @Override
@@ -55,7 +58,15 @@
                 }
             }
             
-            return componentContext.getService(referenceInterface, referenceName);
+            try {
+                return componentContext.getService(referenceInterface, referenceName);
+            } catch(ServiceRuntimeException e) {
+                if(!required && e.getMessage().startsWith("Reference not found"))
{
+                    return null;
+                } else {
+                    throw e;
+                }
+            }
         } catch (ClassNotFoundException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java?rev=719569&r1=719568&r2=719569&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
Fri Nov 21 04:52:11 2008
@@ -186,12 +186,12 @@
                         Reference ref = field.getAnnotation(Reference.class);
                         String referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : field.getName();
                         holder.addInjection(servletClassName, new Injection(servletClassName,
field.getName(), servletClassName+"/"+field.getName()));
-                        compContext.put("env/"+servletClassName+"/"+field.getName(), new
SCAServiceReference(field.getType().getName(), thisComponentName, referenceName));
+                        compContext.put("env/"+servletClassName+"/"+field.getName(), new
SCAServiceReference(field.getType().getName(), thisComponentName, referenceName, ref.required()));
                     } else if(field.isAnnotationPresent(Property.class)) {
                         Property prop = field.getAnnotation(Property.class);
                         String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : field.getName();
                         holder.addInjection(servletClassName, new Injection(servletClassName,
field.getName(), servletClassName+"/"+field.getName()));
-                        compContext.put("env/"+servletClassName+"/"+field.getName(), new
SCAPropertyReference(field.getType(), thisComponentName, propertyName));
+                        compContext.put("env/"+servletClassName+"/"+field.getName(), new
SCAPropertyReference(field.getType(), thisComponentName, propertyName, prop.required()));
                     } else if(field.isAnnotationPresent(ComponentName.class)) {
                         holder.addInjection(servletClassName, new Injection(servletClassName,
field.getName(), servletClassName+"/"+field.getName()));
                         compContext.put("env/"+servletClassName+"/"+field.getName(), thisComponentName);
@@ -211,12 +211,12 @@
                         Reference ref = method.getAnnotation(Reference.class);
                         String referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : targetName;
                         holder.addInjection(servletClassName, new Injection(servletClassName,
targetName, servletClassName+"/"+targetName));
-                        compContext.put("env/"+servletClassName+"/"+targetName, new SCAServiceReference(type.getName(),
thisComponentName, referenceName));
+                        compContext.put("env/"+servletClassName+"/"+targetName, new SCAServiceReference(type.getName(),
thisComponentName, referenceName, ref.required()));
                     } else if(method.isAnnotationPresent(Property.class)) {
                         Property prop = method.getAnnotation(Property.class);
                         String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : targetName;
                         holder.addInjection(servletClassName, new Injection(servletClassName,
targetName, servletClassName+"/"+targetName));
-                        compContext.put("env/"+servletClassName+"/"+targetName, new SCAPropertyReference(type,
thisComponentName, propertyName));
+                        compContext.put("env/"+servletClassName+"/"+targetName, new SCAPropertyReference(type,
thisComponentName, propertyName, prop.required()));
                     } else if(method.isAnnotationPresent(ComponentName.class)) {
                         holder.addInjection(servletClassName, new Injection(servletClassName,
targetName, servletClassName+"/"+targetName));
                         compContext.put("env/"+servletClassName+"/"+targetName, thisComponentName);

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=719569&r1=719568&r2=719569&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
Fri Nov 21 04:52:11 2008
@@ -52,6 +52,16 @@
         this.ser3 = service3;
     }
     
+    /* Test for required */
+    @Reference(required=false)
+    protected Helloworld service4;
+    
+    @Reference(required=false)
+    protected Helloworld service5;
+    
+    @Reference(required=true)
+    protected Helloworld service6;
+
     @Property
     protected String property1;
     
@@ -66,6 +76,16 @@
         this.prop3 = property3;
     }
     
+    /* Test for required */
+    @Property(required=false)
+    protected String property4;
+
+    @Property(required=false)
+    protected String property5;
+
+    @Property(required=true)
+    protected String property6;
+    
     @ComponentName
     protected String scaComponentName;
 
@@ -116,12 +136,18 @@
         out.write("<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);
+        out.write("<br><br>Required is false. Reference is specified. "+service5);
+        out.write("<br><br>Required is true. Reference is specified. "+service6);
         out.write("<hr>");
         
         out.write("<h3>@Property</h3>");
         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);
+        out.write("<br>Required is false. Property is not specified. "+property4);
+        out.write("<br>Required is false. Property is specified. "+property5);
+        out.write("<br>Required is true. Property is specified. "+property6);
         out.write("<hr>");
         
         out.write("<h3>@ComponentName</h3>");

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=719569&r1=719568&r2=719569&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
Fri Nov 21 04:52:11 2008
@@ -33,9 +33,19 @@
         <reference name="Service3" target="HelloworldFrenchComponent" >
             <binding.sca/>
         </reference>
+        
+        <!-- <reference name="service4" target="HelloworldComponent"/> -->
+        
+        <reference name="service5" target="HelloworldComponent"/>
+        
+        <reference name="service6" target="HelloworldComponent"/>
+
         <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>
+        <!-- <property name="property4" type="xsd:string">Prop4</property>
-->
+        <property name="property5" type="xsd:string">Prop5</property>
+        <property name="property6" type="xsd:string">Prop6</property>
     </component>
 
 </composite>



Mime
View raw message