geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r833019 - /geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
Date Thu, 05 Nov 2009 07:46:36 GMT
Author: vamsic007
Date: Thu Nov  5 07:46:35 2009
New Revision: 833019

URL: http://svn.apache.org/viewvc?rev=833019&view=rev
Log:
o Obtain the injection points for ejb component from implementation.ejb
o Rewire EJB reference through SCA
o Reconfigure env entries through SCA properties

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=833019&r1=833018&r2=833019&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
Thu Nov  5 07:46:35 2009
@@ -29,6 +29,7 @@
 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;
@@ -67,6 +68,7 @@
 import org.apache.geronimo.xbeans.javaee.WebAppType;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
 import org.apache.openejb.assembler.classic.EnterpriseBeanInfo;
+import org.apache.openejb.assembler.classic.EnvEntryInfo;
 import org.apache.openejb.assembler.classic.InjectionInfo;
 import org.apache.openejb.assembler.classic.ReferenceLocationInfo;
 import org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo;
@@ -535,6 +537,7 @@
         
         // Find the various components
         Map<String, String> ejb2component = new HashMap<String, String>();
+        Map<String, Component> name2component = new HashMap<String, Component>();
         ModelResolverImpl modelResolver = new ModelResolverImpl(cl);
         appCompositeJarFile = ejbJarFile;
         try {
@@ -543,7 +546,7 @@
             try {
                 Thread.currentThread().setContextClassLoader(cl);
                 //contribution = getEmbeddedSCADomain().getContributionService().contribute(appCompositeJarFile.toURL().toString(),
appCompositeJarFile.toURL(), modelResolver, false);
-                contribution = getEmbeddedSCADomain().getContributionService().contribute(appCompositeJarFile.toURL().toString(),
appCompositeJarFile.toURL(), false);
+                contribution = getEmbeddedSCADomain().getContributionService().contribute(ejbJarFile.toURL().toString(),
ejbJarFile.toURL(), false);
             } catch(Throwable t) {
                 t.printStackTrace();
             } finally {
@@ -556,11 +559,13 @@
                             String ejbLink = ((EJBImplementation)component.getImplementation()).getEJBLink();
                             if(ejbLink.indexOf("#") == -1) {
                                 ejb2component.put(ejbLink, component.getName());
+                                name2component.put(component.getName(), component);
                             } else {
                                 String modulePart = ejbLink.substring(0, ejbLink.indexOf("#"));
                                 if(modulePart.equals(module.getName())) {
                                     String ejbPart = ejbLink.substring(ejbLink.indexOf("#")+1);
                                     ejb2component.put(ejbPart, component.getName());
+                                    name2component.put(component.getName(), component);
                                 }
                             }
                         }
@@ -578,11 +583,13 @@
                                 String ejbLink = ((EJBImplementation)component.getImplementation()).getEJBLink();
                                 if(ejbLink.indexOf("#") == -1) {
                                     ejb2component.put(ejbLink, component.getName());
+                                    name2component.put(component.getName(), component);
                                 } else {
                                     String modulePart = ejbLink.substring(0, ejbLink.indexOf("#"));
                                     if(modulePart.equals(module.getName())) {
                                         String ejbPart = ejbLink.substring(ejbLink.indexOf("#")+1);
                                         ejb2component.put(ejbPart, component.getName());
+                                        name2component.put(component.getName(), component);
                                     }
                                 }
                             }
@@ -607,6 +614,8 @@
                 continue;
             }
             String componentName = ejb2component.get(beanName);
+            Component component = name2component.get(componentName);
+            EJBImplementation implementation = (EJBImplementation)component.getImplementation();
             String beanClassName = beanInfo.ejbClass;
             Class<?> beanClass = null;;
             try {
@@ -620,59 +629,157 @@
             Map<String, Object> contextMap = new HashMap<String, Object>();
             contextMaps.put(beanName, contextMap);
             
-            // Identify the injection points
-            for(Field field : beanClass.getDeclaredFields()) {
-                String targetName = field.getName();
-                Class<?> type = field.getType();
-                if(field.isAnnotationPresent(Property.class)) {
-                    Property prop = field.getAnnotation(Property.class);
-                    String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : targetName;
-                    addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, new SCAPropertyReference(type,
componentName, propertyName, prop.required()));
-                } else if(field.isAnnotationPresent(Reference.class)) {
+            // Processing to support dependency injection starts here
+            
+            // 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 referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : targetName; 
+                    String targetName = field.getName();
+                    Class<?> type = target.getType();
                     addEJBInjectionPoint(beanInfo, targetName, type);
                     contextMap.put(beanClassName+ "/" +targetName, new SCAServiceReference(type,
componentName, referenceName, ref.required()));
-                } else if(field.isAnnotationPresent(ComponentName.class)) {
-                    addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, componentName);
-                } else if(field.isAnnotationPresent(Context.class)) {
-                    addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, new SCAContextReference(componentName));
-                } else if(field.isAnnotationPresent(Callback.class)) {
+                } else if(target.getElementType().equals(ElementType.PARAMETER)) {
+                    Method method = (Method)target.getAnchor();
+                    Reference ref = method.getAnnotation(Reference.class);
+                    String targetName = method.getName().substring(3);
+                    Class<?> type = target.getType();
                     addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, new SCACallbackReference(componentName));
+                    contextMap.put(beanClassName+ "/" +targetName, new SCAServiceReference(type,
componentName, referenceName, ref.required()));
                 }
             }
-
-            for(Method method : beanClass.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(Property.class)) {
-                    Property prop = method.getAnnotation(Property.class);
-                    String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : targetName; 
+            
+            // 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 targetName = field.getName();
+                    Class<?> type = target.getType();
                     addEJBInjectionPoint(beanInfo, targetName, type);
                     contextMap.put(beanClassName+ "/" +targetName, new SCAPropertyReference(type,
componentName, propertyName, prop.required()));
-                } else if(method.isAnnotationPresent(Reference.class)) {
-                    Reference ref = method.getAnnotation(Reference.class);
-                    String referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : targetName; 
-                    addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, new SCAServiceReference(type,
componentName, referenceName, ref.required()));
-                } else if(method.isAnnotationPresent(ComponentName.class)) {
+                } else if(target.getElementType().equals(ElementType.PARAMETER)) {
+                    Method method = (Method)target.getAnchor();
+                    Property prop = method.getAnnotation(Property.class);
+                    String targetName = method.getName().substring(3);
+                    Class<?> type = target.getType();
                     addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, componentName);
-                } else if(method.isAnnotationPresent(Context.class)) {
+                    contextMap.put(beanClassName+ "/" +targetName, new SCAPropertyReference(type,
componentName, propertyName, prop.required()));
+                }
+            }
+
+            // 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 targetName = field.getName();
+                    Class<?> type = target.getType();
                     addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, new SCAContextReference(componentName));
-                } else if(method.isAnnotationPresent(Callback.class)) {
+                    if(field.isAnnotationPresent(ComponentName.class)) {
+                        contextMap.put(beanClassName+ "/" +targetName, componentName);
+                    } else if(field.isAnnotationPresent(Context.class)) {
+                        contextMap.put(beanClassName+ "/" +targetName, new SCAContextReference(componentName));
+                    }
+                } else if(target.getElementType().equals(ElementType.PARAMETER)) {
+                    Method method = (Method)target.getAnchor();
+                    String targetName = method.getName().substring(3);
+                    Class<?> type = target.getType();
                     addEJBInjectionPoint(beanInfo, targetName, type);
-                    contextMap.put(beanClassName+ "/" +targetName, new SCACallbackReference(componentName));
+                    if(method.isAnnotationPresent(ComponentName.class)) {
+                        contextMap.put(beanClassName+ "/" +targetName, componentName);
+                    } else if(method.isAnnotationPresent(Context.class)) {
+                        contextMap.put(beanClassName+ "/" +targetName, new SCAContextReference(componentName));
+                    }
                 }
-            }       
+            }
+
+            // Process callback injection points
+            Map<String, Collection<JavaElementImpl>> callbackInjectionPoints
= implementation.getCallbackInjectionPoints();
+            for(Map.Entry<String, Collection<JavaElementImpl>> entry : callbackInjectionPoints.entrySet())
{
+                String callbackInterface = entry.getKey();
+                for(JavaElementImpl target : entry.getValue()) {
+                    if(target.getElementType().equals(ElementType.FIELD)) {
+                        Field field = (Field)target.getAnchor();
+                        String targetName = field.getName();
+                        Class<?> type = target.getType();
+                        addEJBInjectionPoint(beanInfo, targetName, type);
+                        contextMap.put(beanClassName+ "/" +targetName, new SCACallbackReference(componentName));
+                    } else if(target.getElementType().equals(ElementType.PARAMETER)) {
+                        Method method = (Method)target.getAnchor();
+                        String targetName = method.getName().substring(3);
+                        Class<?> type = target.getType();
+                        addEJBInjectionPoint(beanInfo, targetName, type);
+                        contextMap.put(beanClassName+ "/" +targetName, new SCACallbackReference(componentName));
+                    }
+                }
+            }
+
+            // Process reference injection points from optional extension
+            Map<InjectionTarget, Class<?>> optExtRefInjectionPoints = implementation.getOptExtensionReferenceInjectionPoints();
+            for(Map.Entry<InjectionTarget, Class<?>> entry : optExtRefInjectionPoints.entrySet())
{
+                InjectionTarget injectionTarget = entry.getKey();
+                String referenceName = injectionTarget.targetClass+"_"+injectionTarget.targetName;
+                // Check if the runtime component has this reference configured
+                boolean found = false;
+                for(ComponentReference runtimeRef : component.getReferences()) {
+                    if(runtimeRef.getName().equals(referenceName)) {
+                        found = true;
+                        break;
+                    }
+                }
+                if(!found) {
+                    continue;
+                }
+                String target = injectionTarget.targetClass+"/"+injectionTarget.targetName;
+                Class<?> targetType = entry.getValue();
+                addEJBInjectionPoint(beanInfo, injectionTarget.targetName, targetType);
+                contextMap.put(target, new SCAServiceReference(targetType, componentName,
referenceName, false));
+            }
+
+            // Process property injection points from optional extension
+            for(Map.Entry<String, String> entry : implementation.getOptExtensionPropertyInjectionPoints().entrySet())
{
+                String target = entry.getKey();
+                String propertyName = target.replace("/", "_");
+                // Check if the runtime component has this property configured
+                boolean found = false;
+                for(ComponentProperty runtimeProp : component.getProperties()) {
+                    if(runtimeProp.getName().equals(propertyName)) {
+                        found = true;
+                        break;
+                    }
+                }
+                if(!found) {
+                    continue;
+                }
+                Class<?> targetType = null;
+                try {
+                    targetType = Class.forName(entry.getValue());
+                } catch (ClassNotFoundException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+                
+                EnvEntryInfo targetEntry = null;
+                for(EnvEntryInfo entryInfo : beanInfo.jndiEnc.envEntries) {
+                    if(entryInfo.name.equals(target)) {
+                        addEJBEnvEntryInjectionPoint(beanInfo, target, targetType, entryInfo.targets);
+                        contextMap.put(target, new SCAPropertyReference(targetType, componentName,
propertyName, false));
+                        targetEntry = entryInfo;
+                        break;
+                    }
+                }
+                beanInfo.jndiEnc.envEntries.remove(targetEntry);
+            }
         }
 
         // Update EJB GBeanData to add the componentContexts
@@ -704,6 +811,17 @@
         resEnvRef.targets.add(injection);
         beanInfo.jndiEnc.resourceEnvRefs.add(resEnvRef);
     }
+    
+    private void addEJBEnvEntryInjectionPoint(EnterpriseBeanInfo beanInfo, String targetName,
Class<?> type, List<InjectionInfo> targets) {
+        ResourceEnvReferenceInfo resEnvRef = new ResourceEnvReferenceInfo();
+        resEnvRef.location = new ReferenceLocationInfo();
+        resEnvRef.location.jndiName = "java:comp/geronimo/"+targetName;
+        resEnvRef.resourceEnvRefName = targetName;
+        resEnvRef.resourceEnvRefType = type.getName();
+        resEnvRef.resourceID = "jndi:java:comp/geronimo/"+targetName;
+        resEnvRef.targets.addAll(targets);
+        beanInfo.jndiEnc.resourceEnvRefs.add(resEnvRef);
+    }
 
     private EmbeddedSCADomain getEmbeddedSCADomain() throws NamingException {
         InitialContext ctx = new InitialContext();



Mime
View raw message