tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r681624 - in /tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat: TuscanyAnnotationProcessor.java TuscanyHost.java
Date Fri, 01 Aug 2008 08:01:50 GMT
Author: antelder
Date: Fri Aug  1 01:01:50 2008
New Revision: 681624

URL: http://svn.apache.org/viewvc?rev=681624&view=rev
Log:
Update to inject references

Modified:
    tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java
    tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java

Modified: tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java?rev=681624&r1=681623&r2=681624&view=diff
==============================================================================
--- tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java
(original)
+++ tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java
Fri Aug  1 01:01:50 2008
@@ -26,6 +26,10 @@
 import javax.naming.NamingException;
 
 import org.apache.AnnotationProcessor;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.util.DefaultAnnotationProcessor;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.host.webapp.WebAppServletHost;
 import org.osoa.sca.annotations.Reference;
 
 /**
@@ -33,6 +37,14 @@
  */
 public class TuscanyAnnotationProcessor implements AnnotationProcessor {
 
+    private StandardContext scaApp;
+    
+    DefaultAnnotationProcessor x;
+
+    public TuscanyAnnotationProcessor(StandardContext scaApp) {
+       this.scaApp = scaApp;
+    }
+
     public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException
{
     }
 
@@ -61,12 +73,41 @@
 
     }
 
-    protected void injectFieldResource(Object instance, Field field, Reference annotation)
{
+    protected void injectFieldResource(Object instance, Field field, Reference annotation)
throws IllegalArgumentException, IllegalAccessException {
         System.out.println("TuscanyAnnotationProcessor.injectFieldResource" + annotation);
+
+        String serviceName = annotation.name();
+        if (serviceName == null || serviceName.length() < 1) {
+            serviceName = field.getName();
+        }
+
+        Object service = getSCADomain().getService(field.getType(), serviceName);
+
+        boolean accessibility = field.isAccessible();
+        field.setAccessible(true);
+        field.set(instance, service);
+        field.setAccessible(accessibility);
     }
 
-    protected void injectMethodResource(Object instance, Method method, Reference annotation)
{
+    protected void injectMethodResource(Object instance, Method method, Reference annotation)
throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
         System.out.println("TuscanyAnnotationProcessor.injectMethodResource" + annotation);
+
+        String serviceName = annotation.name();
+        if (serviceName == null || serviceName.length() < 1) {
+            StringBuilder setterName = new StringBuilder(method.getName());
+            setterName.setCharAt(4, Character.toLowerCase(setterName.charAt(4)));
+            serviceName = setterName.substring(4);
+        }
+
+        Object service = getSCADomain().getService(method.getParameterTypes()[0], serviceName);
+
+        boolean accessibility = method.isAccessible();
+        method.setAccessible(true);
+        method.invoke(instance, service);
+        method.setAccessible(accessibility);
     }
 
+    protected SCADomain getSCADomain() {
+        return (SCADomain)scaApp.getServletContext().getAttribute(WebAppServletHost.SCA_DOMAIN_ATTRIBUTE);
+    }
 }

Modified: tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java?rev=681624&r1=681623&r2=681624&view=diff
==============================================================================
--- tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java
(original)
+++ tuscany/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java
Fri Aug  1 01:01:50 2008
@@ -148,7 +148,7 @@
         filterMap.addURLPattern("/*");
         scaApp.addFilterMap(filterMap);
 
-        scaApp.setAnnotationProcessor(new TuscanyAnnotationProcessor());
+        scaApp.setAnnotationProcessor(new TuscanyAnnotationProcessor(scaApp));
         
         scaApps.add(scaApp);
     }



Mime
View raw message