diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-01 08:01:50 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2008-08-01 08:01:50 +0000 |
commit | 51351f913366cc53733a9f2c923105348799a750 (patch) | |
tree | 4b780f317a1ccad1528602b1c6851298c0d39206 /java | |
parent | b2f867a68539c1ec92689b3dbe67326cd65cbd56 (diff) |
Update to inject references
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@681624 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
2 files changed, 44 insertions, 3 deletions
diff --git a/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java b/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java index 2b14fcef31..e729515988 100644 --- a/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java +++ b/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyAnnotationProcessor.java @@ -26,6 +26,10 @@ import java.lang.reflect.Method; 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 @@ import org.osoa.sca.annotations.Reference; */
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 @@ public class TuscanyAnnotationProcessor implements AnnotationProcessor { }
- 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);
+ }
}
diff --git a/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java b/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java index 8a669a9cc2..c46d1316ce 100644 --- a/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java +++ b/java/sca/modules/runtime-tomcat/src/main/java/org/apache/tuscany/sca/runtime/tomcat/TuscanyHost.java @@ -148,7 +148,7 @@ public class TuscanyHost extends StandardHost { filterMap.addURLPattern("/*"); scaApp.addFilterMap(filterMap); - scaApp.setAnnotationProcessor(new TuscanyAnnotationProcessor()); + scaApp.setAnnotationProcessor(new TuscanyAnnotationProcessor(scaApp)); scaApps.add(scaApp); } |