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 2008/11/26 17:02:22 UTC

svn commit: r720907 - in /geronimo/plugins/tuscany/trunk: geronimo-tuscany/pom.xml geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java pom.xml tuscany-jetty/pom.xml tuscany-tomcat/pom.xml

Author: vamsic007
Date: Wed Nov 26 08:02:22 2008
New Revision: 720907

URL: http://svn.apache.org/viewvc?rev=720907&view=rev
Log:
GERONIMO-4343 Tuscany Geronimo plugin bring up
 o Adding a ModuleBuilderExtension for openejb-deployer.
 o For now, hook up the MBE by modifying var/config/config.xml as given in http://www.mail-archive.com/dev@geronimo.apache.org/msg66316.html .  Make sure the server is stopped before modifying config.xml.
 o Support injection for @Property, @Reference, @Context and @ComponentName annotations on EJB fields and setter methods.

Modified:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
    geronimo/plugins/tuscany/trunk/pom.xml
    geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml
    geronimo/plugins/tuscany/trunk/tuscany-tomcat/pom.xml

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml?rev=720907&r1=720906&r2=720907&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml (original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml Wed Nov 26 08:02:22 2008
@@ -48,12 +48,20 @@
             <groupId>org.apache.geronimo.modules</groupId>
             <artifactId>geronimo-naming-builder</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-openejb-builder</artifactId>
+        </dependency>
 
         <!-- Tuscany dependencies -->
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-host-embedded</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-ejb</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

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=720907&r1=720906&r2=720907&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 Wed Nov 26 08:02:22 2008
@@ -24,9 +24,13 @@
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
+import java.util.jar.JarInputStream;
 import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 
@@ -55,13 +59,21 @@
 import org.apache.geronimo.kernel.config.IOUtil;
 import org.apache.geronimo.kernel.repository.Environment;
 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.ServletType;
 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.InjectionInfo;
+import org.apache.openejb.assembler.classic.ReferenceLocationInfo;
+import org.apache.openejb.assembler.classic.ResourceEnvReferenceInfo;
 import org.apache.tuscany.sca.assembly.Component;
 import org.apache.tuscany.sca.assembly.Composite;
 import org.apache.tuscany.sca.contribution.Artifact;
 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.xmlbeans.XmlObject;
 import org.osoa.sca.annotations.ComponentName;
 import org.osoa.sca.annotations.Context;
@@ -102,6 +114,8 @@
         System.out.println("Inside TuscanyModuleBuilderExtension.addGBeans");
         if(module instanceof WebModule) {
             handleWebModule(earContext, module, cl, repository);
+        } else if(module instanceof EjbModule) {
+            handleEjbModule(earContext, module, cl, repository);
         }
     }
 
@@ -241,6 +255,179 @@
         namingBuilders.buildNaming(webApp, vendorWebApp, webModule, buildingContext);
     }
 
+    private void handleEjbModule(EARContext earContext, Module module, ClassLoader cl, Collection repository) throws DeploymentException {
+        System.out.println("Inside TuscanyModuleBuilderExtension.handleEjbModule()");
+        
+        Naming naming = earContext.getNaming();
+        
+        // Add EmbeddedRuntimeGBean to the application config.
+        AbstractName moduleName = earContext.getModuleName();
+        AbstractName abstractName = naming.createChildName(moduleName, "EmbeddedRuntime", "GBean");
+        GBeanInfo gBeanInfo = GBeanInfo.getGBeanInfo(EmbeddedRuntimeGBean.class.getName(), cl);
+        GBeanData data = new GBeanData(abstractName, gBeanInfo);        
+        data.setReferencePattern("embeddedSCADomainRef", embeddedSCADomainQuery);
+        data.setReferencePattern("Repository", new AbstractNameQuery(Repository.class.getName()));
+
+        // FIXME: Eliminate this hack.
+        // HACK: Create a JAR file with the ejb-jar.composite file and place it as META-INF/application-composite.jar
+        // to deploy to the SCA domain
+        File ejbJarFile = new File(earContext.getBaseDir(), "ejb.jar");
+        File appCompositeJarFile = new File(earContext.getBaseDir(), "META-INF/application-composite.jar");
+        JarOutputStream jarOut = null;
+        JarInputStream jin = null;
+        try {
+            jin = new JarInputStream(new FileInputStream(ejbJarFile));
+            JarEntry entry;
+            while((entry = jin.getNextJarEntry()) != null) { 
+                if(entry.getName().equalsIgnoreCase("META-INF/ejb-jar.composite")) {
+                    break;
+                }
+            }
+            appCompositeJarFile.getParentFile().mkdirs();
+            jarOut = new JarOutputStream(new FileOutputStream(appCompositeJarFile));
+            jarOut.putNextEntry(new ZipEntry("ejb-jar.composite"));
+            int b;
+            while((b = jin.read()) != -1) {
+                jarOut.write(b);
+            }
+            jarOut.closeEntry();
+        } catch (Exception e) {
+            throw new DeploymentException(e);
+        } finally {
+            IOUtil.close(jin);
+            IOUtil.close(jarOut);
+        }
+        
+        data.setAttribute("jarFileName", "META-INF/application-composite.jar");
+        try {
+            earContext.addGBean(data);
+        } catch (GBeanAlreadyExistsException e) {
+            throw new DeploymentException(e);
+        }
+        
+        // Find the various components
+        Map<String, String> ejb2component = new HashMap<String, String>();
+        ModelResolverImpl modelResolver = new ModelResolverImpl(cl);
+        try {
+            Contribution contribution = getEmbeddedSCADomain().getContributionService().contribute(appCompositeJarFile.toURL().toString(), appCompositeJarFile.toURL(), modelResolver, false);
+            for(Artifact artifact : contribution.getArtifacts()) {
+                if (artifact.getModel() instanceof Composite) {
+                    for(Component component : ((Composite)artifact.getModel()).getComponents()) {
+                        if(component.getImplementation() instanceof EJBImplementation) {
+                            ejb2component.put(((EJBImplementation)component.getImplementation()).getEJBLink(), component.getName());
+                        }
+                    }
+                }
+            }
+        } catch (Exception e1) {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
+        }
+        
+        
+        EjbModule ejbModule = (EjbModule) module;
+        EjbJarInfo ejbJarInfo = ejbModule.getEjbJarInfo();
+
+        Map<String, Map<String, Object>> contextMaps = new HashMap<String, Map<String, Object>>();
+        
+        for (EnterpriseBeanInfo beanInfo : ejbJarInfo.enterpriseBeans) {
+            String beanName = beanInfo.ejbName;
+            if(!ejb2component.containsKey(beanName)) {
+                continue;
+            }
+            String componentName = ejb2component.get(beanName);
+            String beanClassName = beanInfo.ejbClass;
+            Class<?> beanClass = null;;
+            try {
+                beanClass = cl.loadClass(beanClassName);
+            } catch (ClassNotFoundException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+                continue;
+            }
+            
+            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)) {
+                    Reference ref = field.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.getName(), 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));
+                }
+            }
+
+            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; 
+                    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.getName(), componentName, referenceName, ref.required()));
+                } else if(method.isAnnotationPresent(ComponentName.class)) {
+                    addEJBInjectionPoint(beanInfo, targetName, type);
+                    contextMap.put(beanClassName+ "/" +targetName, componentName);
+                } else if(method.isAnnotationPresent(Context.class)) {
+                    addEJBInjectionPoint(beanInfo, targetName, type);
+                    contextMap.put(beanClassName+ "/" +targetName, new SCAContextReference(componentName));
+                }
+            }       
+        }
+
+        // Update EJB GBeanData to add the componentContexts
+        Set<GBeanData> gBeanDatas = earContext.getConfiguration().findGBeanDatas(Collections.singleton(new AbstractNameQuery(EjbDeployment.class.getName())));
+        for(GBeanData gbeanData : gBeanDatas) {
+            String beanName = (String) gbeanData.getAttribute("ejbName");
+            Map<String, Object> contextMap = contextMaps.get(beanName);
+            if(contextMap != null && !contextMap.entrySet().isEmpty()) {
+                Map compContext = (Map)gbeanData.getAttribute("componentContextMap");
+                for(Map.Entry<String, Object> entry : contextMap.entrySet()) {
+                    compContext.put(entry.getKey(), entry.getValue());
+                }
+                gbeanData.setAttribute("componentContextMap", compContext);
+            }
+        }
+    }
+
+    private void addEJBInjectionPoint(EnterpriseBeanInfo beanInfo, String targetName, Class<?> type) {
+        String beanClassName = beanInfo.ejbClass;
+        ResourceEnvReferenceInfo resEnvRef = new ResourceEnvReferenceInfo();
+        resEnvRef.location = new ReferenceLocationInfo();
+        resEnvRef.location.jndiName = "java:comp/geronimo/"+beanClassName+ "/" +targetName;
+        resEnvRef.resourceEnvRefName = beanClassName+ "/" +targetName;
+        resEnvRef.resourceEnvRefType = type.getName();
+        resEnvRef.resourceID = "jndi:java:comp/geronimo/"+beanClassName+ "/" +targetName;
+        InjectionInfo injection = new InjectionInfo();
+        injection.className = beanClassName;
+        injection.propertyName = targetName;
+        resEnvRef.targets.add(injection);
+        beanInfo.jndiEnc.resourceEnvRefs.add(resEnvRef);
+    }
+
     private EmbeddedSCADomain getEmbeddedSCADomain() throws NamingException {
         InitialContext ctx = new InitialContext();
         EmbeddedSCADomain domain = (EmbeddedSCADomain) ctx.lookup("ger:/SCADomain");

Modified: geronimo/plugins/tuscany/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/pom.xml?rev=720907&r1=720906&r2=720907&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/pom.xml (original)
+++ geronimo/plugins/tuscany/trunk/pom.xml Wed Nov 26 08:02:22 2008
@@ -200,6 +200,12 @@
                 <type>car</type>
             </dependency>
             <dependency>
+                <groupId>org.apache.geronimo.configs</groupId>
+                <artifactId>openejb-deployer</artifactId>
+                <version>${geronimoVersion}</version>
+                <type>car</type>
+            </dependency>
+            <dependency>
                 <groupId>org.apache.geronimo.framework</groupId>
                 <artifactId>rmi-naming</artifactId>
                 <version>${geronimoVersion}</version>
@@ -258,6 +264,11 @@
                 <version>${geronimoVersion}</version>
             </dependency>
             <dependency>
+                <groupId>org.apache.geronimo.modules</groupId>
+                <artifactId>geronimo-openejb-builder</artifactId>
+                <version>${geronimoVersion}</version>
+            </dependency>
+            <dependency>
                 <groupId>org.apache.geronimo.framework</groupId>
                 <artifactId>geronimo-service-builder</artifactId>
                 <version>${geronimoVersion}</version>

Modified: geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml?rev=720907&r1=720906&r2=720907&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml (original)
+++ geronimo/plugins/tuscany/trunk/tuscany-jetty/pom.xml Wed Nov 26 08:02:22 2008
@@ -46,6 +46,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.plugins</groupId>
+            <artifactId>geronimo-tuscany-implementation-ejb</artifactId>
+            <version>${version}</version>
+            <type>jar</type>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.plugins</groupId>
             <artifactId>geronimo-tuscany-implementation-web</artifactId>
             <version>${version}</version>
             <type>jar</type>
@@ -148,6 +154,11 @@
             <type>car</type>
         </dependency>
         <dependency>
+            <groupId>org.apache.geronimo.configs</groupId>
+            <artifactId>openejb-deployer</artifactId>
+            <type>car</type>
+        </dependency>
+        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-commonj_1.1_spec</artifactId>
         </dependency>
@@ -292,6 +303,10 @@
         </dependency>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-ejb</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-java</artifactId>
         </dependency>
         <dependency>

Modified: geronimo/plugins/tuscany/trunk/tuscany-tomcat/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/tuscany-tomcat/pom.xml?rev=720907&r1=720906&r2=720907&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/tuscany-tomcat/pom.xml (original)
+++ geronimo/plugins/tuscany/trunk/tuscany-tomcat/pom.xml Wed Nov 26 08:02:22 2008
@@ -46,6 +46,12 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.plugins</groupId>
+            <artifactId>geronimo-tuscany-implementation-ejb</artifactId>
+            <version>${version}</version>
+            <type>jar</type>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.plugins</groupId>
             <artifactId>geronimo-tuscany-implementation-web</artifactId>
             <version>${version}</version>
             <type>jar</type>
@@ -138,6 +144,11 @@
             <type>car</type>
         </dependency>
         <dependency>
+            <groupId>org.apache.geronimo.configs</groupId>
+            <artifactId>openejb-deployer</artifactId>
+            <type>car</type>
+        </dependency>
+        <dependency>
             <groupId>org.apache.geronimo.framework</groupId>
             <artifactId>rmi-naming</artifactId>
             <type>car</type>
@@ -292,6 +303,10 @@
         </dependency>
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
+            <artifactId>tuscany-implementation-ejb</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-implementation-java</artifactId>
         </dependency>
         <dependency>