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 2009/10/27 08:04:09 UTC
svn commit: r830072 -
/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
Author: vamsic007
Date: Tue Oct 27 07:04:06 2009
New Revision: 830072
URL: http://svn.apache.org/viewvc?rev=830072&view=rev
Log:
Obtain the injection points for web component from implementation.web
Modified:
geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
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=830072&r1=830071&r2=830072&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 Tue Oct 27 07:04:06 2009
@@ -21,13 +21,13 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.lang.annotation.ElementType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
@@ -63,9 +63,6 @@
import org.apache.geronimo.kernel.repository.Repository;
import org.apache.geronimo.openejb.EjbDeployment;
import org.apache.geronimo.openejb.deployment.EjbModule;
-import org.apache.geronimo.xbeans.javaee.FilterType;
-import org.apache.geronimo.xbeans.javaee.ListenerType;
-import org.apache.geronimo.xbeans.javaee.ServletType;
import org.apache.geronimo.xbeans.javaee.WebAppType;
import org.apache.openejb.assembler.classic.EjbJarInfo;
import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
@@ -78,6 +75,8 @@
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain;
import org.apache.tuscany.sca.implementation.ejb.EJBImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
import org.apache.tuscany.sca.implementation.web.WebImplementation;
import org.apache.xmlbeans.XmlObject;
import org.osoa.sca.annotations.Callback;
@@ -276,6 +275,7 @@
buildingContext.put(NamingBuilder.INJECTION_KEY, holder);
String thisComponentName = null;
+ Component thisComponent = null;
ModelResolverImpl modelResolver = new ModelResolverImpl(cl);
try {
Contribution contribution = null;
@@ -298,6 +298,7 @@
if(component.getImplementation() instanceof WebImplementation) {
WebImplementation webImpl = (WebImplementation) component.getImplementation();
if(webImpl.getWebURI().equals(new File(module.getModuleFile().getName()).getName())) {
+ thisComponent = component;
thisComponentName = component.getName();
break;
}
@@ -318,6 +319,7 @@
if(component.getImplementation() instanceof WebImplementation) {
WebImplementation webImpl = (WebImplementation) component.getImplementation();
if(webImpl.getWebURI().equals(module.getName())) {
+ thisComponent = component;
thisComponentName = component.getName();
break;
}
@@ -335,56 +337,85 @@
System.out.println("SCA component name for web module is null");
}
+ // Processing to support dependency injection starts here
WebModule webModule = (WebModule) module;
WebAppType webApp = (WebAppType) webModule.getSpecDD();
XmlObject vendorWebApp = webModule.getVendorDD();
- ClassLoader webClassLoader = module.getEarContext().getClassLoader();
- // Find the injection points
- ServletType[] servlets = webApp.getServletArray();
- for(ServletType servlet:servlets) {
- String servletClassName = servlet.getServletClass().getStringValue().trim();
- try {
- Class servletClass = webClassLoader.loadClass(servletClassName);
- processWebArtifactClass(servletClass, compContext, holder, thisComponentName);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- FilterType[] filters = webApp.getFilterArray();
- for(FilterType filter : filters) {
- String filterClassName = filter.getFilterClass().getStringValue().trim();
- try {
- Class filterClass = webClassLoader.loadClass(filterClassName);
- processWebArtifactClass(filterClass, compContext, holder, thisComponentName);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ WebImplementation implementation = (WebImplementation)thisComponent.getImplementation();
+
+ // Process reference injection points
+ Map<String, JavaElementImpl> injectionPoints = implementation.getReferenceInjectionPoints();
+ for(Map.Entry<String, JavaElementImpl> entry : injectionPoints.entrySet()) {
+ String referenceName = entry.getKey();
+ JavaElementImpl target = entry.getValue();
+ if(target.getElementType().equals(ElementType.FIELD)) {
+ Field field = (Field)target.getAnchor();
+ Reference ref = field.getAnnotation(Reference.class);
+ String className = field.getDeclaringClass().getName();
+ String targetName = field.getName();
+ holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+ compContext.put("env/"+className+"/"+targetName, new SCAServiceReference(target.getType(), thisComponentName, referenceName, ref.required()));
+ } else if(target.getElementType().equals(ElementType.PARAMETER)) {
+ Method method = (Method)target.getAnchor();
+ Reference ref = method.getAnnotation(Reference.class);
+ String className = method.getDeclaringClass().getName();
+ String targetName = method.getName().substring(3);
+ holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+ compContext.put("env/"+className+"/"+targetName, new SCAServiceReference(target.getType(), thisComponentName, referenceName, ref.required()));
}
}
-
- ListenerType[] listeners = webApp.getListenerArray();
- for(ListenerType listener : listeners) {
- String listenerClassName = listener.getListenerClass().getStringValue().trim();
- try {
- Class listenerClass = webClassLoader.loadClass(listenerClassName);
- processWebArtifactClass(listenerClass, compContext, holder, thisComponentName);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
+ // Process property injection points
+ injectionPoints = implementation.getPropertyInjectionPoints();
+ for(Map.Entry<String, JavaElementImpl> entry : injectionPoints.entrySet()) {
+ String propertyName = entry.getKey();
+ JavaElementImpl target = entry.getValue();
+ if(target.getElementType().equals(ElementType.FIELD)) {
+ Field field = (Field)target.getAnchor();
+ Property prop = field.getAnnotation(Property.class);
+ String className = field.getDeclaringClass().getName();
+ String targetName = field.getName();
+ holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+ compContext.put("env/"+className+"/"+targetName, new SCAPropertyReference(target.getType(), thisComponentName, propertyName, prop.required()));
+ } else if(target.getElementType().equals(ElementType.PARAMETER)) {
+ Method method = (Method)target.getAnchor();
+ Property prop = method.getAnnotation(Property.class);
+ String className = method.getDeclaringClass().getName();
+ String targetName = method.getName().substring(3);
+ holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+ compContext.put("env/"+className+"/"+targetName, new SCAPropertyReference(target.getType(), thisComponentName, propertyName, prop.required()));
}
}
-
- // MyFaces processing
- if(webModule.getClassFinder() != null) {
- List<Class> facesClasses = webModule.getClassFinder().findClassesInPackage("", true);
- for(Class clazz: facesClasses) {
- processWebArtifactClass(clazz, compContext, holder, thisComponentName);
+
+ // Process resource injection points
+ Map<String, JavaResourceImpl> resourceInjectionPoints = implementation.getResourceInjectionPoints();
+ for(Map.Entry<String, JavaResourceImpl> entry : resourceInjectionPoints.entrySet()) {
+ JavaResourceImpl resource = entry.getValue();
+ JavaElementImpl target = resource.getElement();
+ if(target.getElementType().equals(ElementType.FIELD)) {
+ Field field = (Field) target.getAnchor();
+ String className = field.getDeclaringClass().getName();
+ String targetName = field.getName();
+ holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+ if(field.isAnnotationPresent(ComponentName.class)) {
+ compContext.put("env/"+className+"/"+targetName, thisComponentName);
+ } else if(field.isAnnotationPresent(Context.class)) {
+ compContext.put("env/"+className+"/"+targetName, new SCAContextReference(thisComponentName));
+ }
+ } else if(target.getElementType().equals(ElementType.PARAMETER)) {
+ Method method = (Method)target.getAnchor();
+ String className = method.getDeclaringClass().getName();
+ String targetName = method.getName().substring(3);
+ holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+ if(method.isAnnotationPresent(ComponentName.class)) {
+ compContext.put("env/"+className+"/"+targetName, thisComponentName);
+ } else if(method.isAnnotationPresent(Context.class)) {
+ compContext.put("env/"+className+"/"+targetName, new SCAContextReference(thisComponentName));
+ }
}
- }
-
+ }
+
// Add dependency so that EmbeddedRuntime starts before the WebAppContext
// ((GBeanData)earContext.getConfiguration().findGBeanDatas(Collections.singleton(new AbstractNameQuery(module.getModuleName()))).toArray()[0]).addDependency(abstractName);
// module name is not good enough to query the webappcontext gbean incase of web modules in a EAR file
@@ -392,55 +423,6 @@
namingBuilders.buildNaming(webApp, vendorWebApp, webModule, buildingContext);
}
- private void processWebArtifactClass(Class clazz, Map compContext, Holder holder, String componentName) {
- System.out.println("Processing class "+clazz);
- String className = clazz.getName();
- for(Field field : clazz.getDeclaredFields()) {
- if(field.isAnnotationPresent(Reference.class)) {
- Reference ref = field.getAnnotation(Reference.class);
- String referenceName = ref.name() != null && !ref.name().equals("") ? ref.name() : field.getName();
- holder.addInjection(className, new Injection(className, field.getName(), className+"/"+field.getName()));
- compContext.put("env/"+className+"/"+field.getName(), new SCAServiceReference(field.getType(), componentName, 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(className, new Injection(className, field.getName(), className+"/"+field.getName()));
- compContext.put("env/"+className+"/"+field.getName(), new SCAPropertyReference(field.getType(), componentName, propertyName, prop.required()));
- } else if(field.isAnnotationPresent(ComponentName.class)) {
- holder.addInjection(className, new Injection(className, field.getName(), className+"/"+field.getName()));
- compContext.put("env/"+className+"/"+field.getName(), componentName);
- } else if(field.isAnnotationPresent(Context.class)) {
- holder.addInjection(className, new Injection(className, field.getName(), className+"/"+field.getName()));
- compContext.put("env/"+className+"/"+field.getName(), new SCAContextReference(componentName));
- }
- }
- for(Method method : clazz.getDeclaredMethods()) {
- if(!method.getName().startsWith("set") || method.getParameterTypes().length != 1) {
- continue;
- }
- String targetName = method.getName().substring(3);
- Class type = method.getParameterTypes()[0];
-
- if(method.isAnnotationPresent(Reference.class)) {
- Reference ref = method.getAnnotation(Reference.class);
- String referenceName = ref.name() != null && !ref.name().equals("") ? ref.name() : targetName;
- holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
- compContext.put("env/"+className+"/"+targetName, new SCAServiceReference(type, componentName, 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(className, new Injection(className, targetName, className+"/"+targetName));
- compContext.put("env/"+className+"/"+targetName, new SCAPropertyReference(type, componentName, propertyName, prop.required()));
- } else if(method.isAnnotationPresent(ComponentName.class)) {
- holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
- compContext.put("env/"+className+"/"+targetName, componentName);
- } else if(method.isAnnotationPresent(Context.class)) {
- holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
- compContext.put("env/"+className+"/"+targetName, new SCAContextReference(componentName));
- }
- }
- }
-
private void handleEjbModule(EARContext earContext, Module module, ClassLoader cl, Collection repository) throws DeploymentException {
System.out.println("Inside TuscanyModuleBuilderExtension.handleEjbModule()");