dain        2004/09/26 06:09:56

  Modified:    modules/core/src/java/org/openejb/deployment
                        OpenEJBModuleBuilder.java
  Log:

  Refactored deployment to the complexity of the conversational interface between the 
ear builder and the module builders
  
  Revision  Changes    Path
  1.31      +68 -163   
openejb/modules/core/src/java/org/openejb/deployment/OpenEJBModuleBuilder.java
  
  Index: OpenEJBModuleBuilder.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/deployment/OpenEJBModuleBuilder.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- OpenEJBModuleBuilder.java 25 Sep 2004 17:31:26 -0000      1.30
  +++ OpenEJBModuleBuilder.java 26 Sep 2004 10:09:56 -0000      1.31
  @@ -50,7 +50,6 @@
   
   import java.io.File;
   import java.io.IOException;
  -import java.io.InputStream;
   import java.net.URI;
   import java.net.URISyntaxException;
   import java.net.URL;
  @@ -58,7 +57,6 @@
   import java.util.HashMap;
   import java.util.Map;
   import java.util.Properties;
  -import java.util.jar.JarEntry;
   import java.util.jar.JarFile;
   import javax.management.MalformedObjectNameException;
   import javax.management.ObjectName;
  @@ -83,8 +81,6 @@
   import org.apache.geronimo.xbeans.j2ee.EjbJarDocument;
   import org.apache.geronimo.xbeans.j2ee.EjbJarType;
   import org.apache.geronimo.xbeans.j2ee.EnterpriseBeansType;
  -import org.apache.xmlbeans.SchemaTypeLoader;
  -import org.apache.xmlbeans.XmlBeans;
   import org.apache.xmlbeans.XmlException;
   import org.apache.xmlbeans.XmlObject;
   import org.openejb.EJBModuleImpl;
  @@ -95,9 +91,9 @@
   import org.openejb.xbeans.ejbjar.OpenejbEntityBeanType;
   import org.openejb.xbeans.ejbjar.OpenejbGbeanType;
   import org.openejb.xbeans.ejbjar.OpenejbMessageDrivenBeanType;
  +import org.openejb.xbeans.ejbjar.OpenejbOpenejbJarDocument;
   import org.openejb.xbeans.ejbjar.OpenejbOpenejbJarType;
   import org.openejb.xbeans.ejbjar.OpenejbSessionBeanType;
  -import org.openejb.xbeans.ejbjar.OpenejbOpenejbJarDocument;
   import org.tranql.ejb.EJBSchema;
   import org.tranql.sql.DataSourceDelegate;
   import org.tranql.sql.sql92.SQL92Schema;
  @@ -107,11 +103,6 @@
    * @version $Revision$ $Date$
    */
   public class OpenEJBModuleBuilder implements ModuleBuilder, EJBReferenceBuilder {
  -    private static final SchemaTypeLoader SCHEMA_TYPE_LOADER = 
XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{
  -        
XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class.getClassLoader()),
  -        
XmlBeans.typeLoaderForClassLoader(OpenejbOpenejbJarType.class.getClassLoader())
  -    });
  -
       final Kernel kernel;
       private final CMPEntityBuilder cmpEntityBuilder;
       private final SessionBuilder sessionBuilder;
  @@ -132,98 +123,101 @@
           return securityBuilder;
       }
   
  -    public XmlObject parseSpecDD(URL path) throws DeploymentException {
  +    public Module createModule(String name, Object plan, JarFile moduleFile, URL 
ejbJarXmlUrl, String targetPath) throws DeploymentException {
  +        String specDD;
  +        EjbJarType ejbJar;
           try {
  -            // check if we have an alt spec dd
  -            return parseSpecDD(SchemaConversionUtils.parse(path.openStream()));
  -        } catch (Exception e) {
  -            throw new DeploymentException("Could not parse path " + path, e);
  -        }
  -    }
  +            if (ejbJarXmlUrl == null) {
  +                ejbJarXmlUrl = JarUtil.createJarURL(moduleFile, 
"META-INF/ejb-jar.xml");
  +            }
  +
  +            specDD = IOUtil.readAll(ejbJarXmlUrl);
   
  -    public XmlObject parseSpecDD(String specDD) throws DeploymentException {
  -        try {
               // check if we have an alt spec dd
  -            return parseSpecDD(SchemaConversionUtils.parse(specDD));
  +            EjbJarDocument ejbJarDoc = 
SchemaConversionUtils.convertToEJBSchema(SchemaConversionUtils.parse(specDD));
  +            ejbJar = ejbJarDoc.getEjbJar();
           } catch (Exception e) {
  -            throw new DeploymentException("could not parse spec dd", e);
  +            return null;
           }
  -    }
  -
  -    private XmlObject parseSpecDD(XmlObject dd) throws XmlException {
  -        EjbJarDocument ejbJarDoc = SchemaConversionUtils.convertToEJBSchema(dd);
  -        return ejbJarDoc.getEjbJar();
  -    }
   
  -    public XmlObject validateVendorDD(XmlObject dd) throws DeploymentException {
  +        OpenejbOpenejbJarType openejbJar = null;
           try {
  -//            dd = SchemaConversionUtils.getNestedObjectAsType(dd, "openejb-jar", 
OpenejbOpenejbJarType.type);
  -            dd = ((OpenejbOpenejbJarDocument)dd).getOpenejbJar();
  -            dd = SchemaConversionUtils.convertToGeronimoNamingSchema(dd);
  -//            SchemaConversionUtils.validateDD(dd);
  -            return dd;
  -        } catch (Exception e) {
  -            throw new DeploymentException(e);
  -        }
  -    }
  +            // load the openejb-jar.xml from either the supplied plan or from the 
earFile
  +            try {
  +                if (plan instanceof XmlObject) {
  +                    openejbJar = (OpenejbOpenejbJarType) 
SchemaConversionUtils.getNestedObjectAsType(
  +                            (XmlObject) plan,
  +                            "openejb-jar",
  +                            OpenejbOpenejbJarType.type);
  +                } else {
  +                    OpenejbOpenejbJarDocument openejbJarDoc = null;
  +                    if (plan != null) {
  +                        openejbJarDoc = 
OpenejbOpenejbJarDocument.Factory.parse((File)plan);
  +                    } else {
  +                        URL path = JarUtil.createJarURL(moduleFile, 
"META-INF/openejb-jar.xml");
  +                        openejbJarDoc = 
OpenejbOpenejbJarDocument.Factory.parse(path);
  +                    }
  +                    if (openejbJarDoc != null) {
  +                        openejbJar = openejbJarDoc.getOpenejbJar();
  +                    }
  +                }
  +            } catch (IOException e) {
  +            }
   
  -    public XmlObject getDeploymentPlan(JarFile module) throws DeploymentException {
  -        URL vendorDDUrl = null;
  -        try {
  -            vendorDDUrl = JarUtil.createJarURL(module, "META-INF/openejb-jar.xml");
  -        } catch (DeploymentException e) {
  -            return null;
  -        }
  -        try {
  -//            XmlObject dd = SchemaConversionUtils.parse(vendorDDUrl);
  -            XmlObject dd = OpenejbOpenejbJarDocument.Factory.parse(vendorDDUrl);
  -            OpenejbOpenejbJarType plan = (OpenejbOpenejbJarType) 
validateVendorDD(dd);
  -            if (plan == null) {
  -                return createDefaultPlan(module);
  +            // if we got one extract the validate it otherwise create a default one
  +            if (openejbJar != null) {
  +                openejbJar = (OpenejbOpenejbJarType) 
SchemaConversionUtils.convertToGeronimoNamingSchema(openejbJar);
  +                SchemaConversionUtils.validateDD(openejbJar);
  +            } else {
  +                openejbJar = createDefaultPlan(name, ejbJar);
               }
  -            return plan;
  -        } catch (IOException e) {
  -            return null;
           } catch (XmlException e) {
               throw new DeploymentException(e);
           }
  -    }
   
  -    private OpenejbOpenejbJarType createDefaultPlan(JarFile module) {
  -        URL ejbJarXml;
  +        // get the ids from either the application plan or for a stand alone module 
from the specific deployer
  +        URI configId = null;
           try {
  -            ejbJarXml = JarUtil.createJarURL(module, "META-INF/ejb-jar.xml");
  -        } catch (DeploymentException e) {
  -            return null;
  +            configId = new URI(openejbJar.getConfigId());
  +        } catch (URISyntaxException e) {
  +            throw new DeploymentException("Invalid configId " + 
openejbJar.getConfigId(), e);
           }
   
  -        EjbJarType ejbJar;
  -        try {
  -            ejbJar = (EjbJarType) parseSpecDD(ejbJarXml);
  -        } catch (DeploymentException e) {
  -            return null;
  +        URI parentId = null;
  +        if (openejbJar.isSetParentId()) {
  +            try {
  +                parentId = new URI(openejbJar.getParentId());
  +            } catch (URISyntaxException e) {
  +                throw new DeploymentException("Invalid parentId " + 
openejbJar.getParentId(), e);
  +            }
  +        }
  +
  +        URI moduleURI;
  +        if (targetPath != null) {
  +            moduleURI = URI.create(targetPath);
  +            if (targetPath.endsWith("/")) {
  +                throw new DeploymentException("targetPath must not end with a '/'");
  +            }
  +        } else {
  +            targetPath = "ejb.jar";
  +            moduleURI = URI.create("");
           }
   
  +        return new EJBModule(name, configId, parentId, moduleURI, moduleFile, 
targetPath, ejbJar, openejbJar, specDD);
  +    }
  +
  +    private OpenejbOpenejbJarType createDefaultPlan(String name, EjbJarType ejbJar) 
{
           String id = ejbJar.getId();
           if (id == null) {
  -            // TODO this name is not necessairly the original name specified on the 
command line which is what we want
  -            id = module.getName();
  -            if (id.endsWith("!/")) {
  -                id = id.substring(0, id.length() - 2);
  -            }
  +            id = name;
               if (id.endsWith(".jar")) {
                   id = id.substring(0, id.length() - 4);
               }
               if (id.endsWith("/")) {
                   id = id.substring(0, id.length() - 1);
               }
  -            id = id.substring(id.lastIndexOf('/') + 1);
           }
   
  -        return newOpenejbJarType(ejbJar, id);
  -    }
  -
  -    private OpenejbOpenejbJarType newOpenejbJarType(EjbJarType ejbJar, String id) {
           OpenejbOpenejbJarType openejbEjbJar = 
OpenejbOpenejbJarType.Factory.newInstance();
           openejbEjbJar.setParentId("org/apache/geronimo/Server");
           if (null != ejbJar.getId()) {
  @@ -235,91 +229,6 @@
           return openejbEjbJar;
       }
   
  -    public boolean canHandlePlan(XmlObject plan) {
  -        return plan instanceof OpenejbOpenejbJarType;
  -    }
  -
  -    public URI getParentId(XmlObject plan) throws DeploymentException {
  -        OpenejbOpenejbJarType openejbEjbJar = (OpenejbOpenejbJarType) plan;
  -        URI parentID;
  -        if (openejbEjbJar.isSetParentId()) {
  -            try {
  -                parentID = new URI(openejbEjbJar.getParentId());
  -            } catch (URISyntaxException e) {
  -                throw new DeploymentException("Invalid parentId " + 
openejbEjbJar.getParentId(), e);
  -            }
  -        } else {
  -            parentID = null;
  -        }
  -        return parentID;
  -    }
  -
  -    public URI getConfigId(XmlObject plan) throws DeploymentException {
  -        OpenejbOpenejbJarType openejbEjbJar = (OpenejbOpenejbJarType) plan;
  -        URI configID;
  -        try {
  -            configID = new URI(openejbEjbJar.getConfigId());
  -        } catch (URISyntaxException e) {
  -            throw new DeploymentException("Invalid configId " + 
openejbEjbJar.getConfigId(), e);
  -        }
  -        return configID;
  -    }
  -
  -    public Module createModule(String name, JarFile moduleFile, XmlObject vendorDD) 
throws DeploymentException {
  -        return createModule(name, moduleFile, vendorDD, "ejb.jar", null);
  -    }
  -
  -    public Module createModule(String name, JarFile moduleFile, XmlObject vendorDD, 
String targetPath, URL specDDUrl) throws DeploymentException {
  -        URI moduleURI;
  -        if (targetPath != null) {
  -            moduleURI = URI.create(targetPath);
  -            if (targetPath.endsWith("/")) {
  -                throw new DeploymentException("targetPath must not end with a '/'");
  -            }
  -        } else {
  -            targetPath = "ejb.jar";
  -            moduleURI = URI.create("");
  -        }
  -
  -
  -        if (specDDUrl == null) {
  -            specDDUrl = JarUtil.createJarURL(moduleFile, "META-INF/ejb-jar.xml");
  -        }
  -        String specDD;
  -        try {
  -            specDD = IOUtil.readAll(specDDUrl);
  -        } catch (IOException e) {
  -            throw new DeploymentException("Unable to read specDD: " + 
specDDUrl.toExternalForm());
  -        }
  -        EjbJarType ejbJar = (EjbJarType) parseSpecDD(specDD);
  -
  -        if (vendorDD == null) {
  -            InputStream in = null;
  -            try {
  -                JarEntry entry = moduleFile.getJarEntry("META-INF/openejb-jar.xml");
  -                if (entry != null) {
  -                    in = moduleFile.getInputStream(entry);
  -                    if (in != null) {
  -//                        XmlObject dd = SchemaConversionUtils.parse(in);
  -                        XmlObject dd = OpenejbOpenejbJarDocument.Factory.parse(in);
  -                        vendorDD = validateVendorDD(dd);
  -                    }
  -                }
  -            } catch (Exception e) {
  -                throw new DeploymentException("Unable to parse 
META-INF/openejb-jar.xml", e);
  -            } finally {
  -                IOUtil.close(in);
  -            }
  -        }
  -        if (vendorDD == null) {
  -            vendorDD = newOpenejbJarType(ejbJar, name);
  -        }
  -
  -        OpenejbOpenejbJarType openEJBJar = (OpenejbOpenejbJarType)vendorDD;
  -
  -        return new EJBModule(name, moduleURI, moduleFile, targetPath, ejbJar, 
openEJBJar, specDD);
  -    }
  -
       public void installModule(JarFile earFile, EARContext earContext, Module 
module) throws DeploymentException {
           try {
               // extract the ejbJar file into a standalone packed jar file and add 
the contents to the output
  @@ -468,10 +377,6 @@
   
           mdbBuilder.buildBeans(earContext, module, cl, ejbModule, openejbBeans, 
transactionPolicyHelper, security, enterpriseBeans);
   
  -    }
  -
  -    public SchemaTypeLoader getSchemaTypeLoader() {
  -        return SCHEMA_TYPE_LOADER;
       }
   
       public Object createEJBProxyFactory(String containerId, boolean isSessionBean, 
String remoteInterfaceName, String homeInterfaceName, String localInterfaceName, 
String localHomeInterfaceName, ClassLoader cl) throws DeploymentException {
  
  
  

Reply via email to