Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 55609 invoked from network); 24 Sep 2004 20:21:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 24 Sep 2004 20:21:56 -0000 Received: (qmail 34339 invoked by uid 500); 24 Sep 2004 20:24:07 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 34312 invoked by uid 500); 24 Sep 2004 20:24:05 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@geronimo.apache.org Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 34299 invoked by uid 99); 24 Sep 2004 20:24:04 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 24 Sep 2004 13:24:02 -0700 Received: (qmail 55529 invoked by uid 65534); 24 Sep 2004 20:21:48 -0000 Date: 24 Sep 2004 20:21:48 -0000 Message-ID: <20040924202148.55526.qmail@minotaur.apache.org> From: djencks@apache.org To: scm@geronimo.apache.org Subject: svn commit: rev 47172 - in geronimo/trunk/modules: client-builder/src/java/org/apache/geronimo/client/builder connector connector/src/java/org/apache/geronimo/connector/deployment connector/src/test-data/data connector/src/test-data/ear connector/src/test/org/apache/geronimo/connector/deployment deployment/src/java/org/apache/geronimo/deployment j2ee-schema/src/java/org/apache/geronimo/schema j2ee-schema/src/test/org/apache/geronimo/schema j2ee/src/java/org/apache/geronimo/j2ee/deployment j2ee/src/schema j2ee/src/test-unpacked-ear j2ee/src/test/org/apache/geronimo/j2ee/deployment jetty/src/java/org/apache/geronimo/jetty/deployment X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: djencks Date: Fri Sep 24 13:21:47 2004 New Revision: 47172 Added: geronimo/trunk/modules/connector/src/test-data/data/external-application-plan.xml Modified: geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java geronimo/trunk/modules/connector/maven.xml geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java geronimo/trunk/modules/connector/src/test-data/ear/application.xml geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java geronimo/trunk/modules/j2ee/src/schema/geronimo-application.xsd geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ejb-jar.xml geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ra.xml geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-war.xml geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java Log: Changes to allow embedded vendor dds in geronimo-application.xml, and changes from xxxDocument to xxxType in vendor dd handling. WARNING: THIS BREAKS THE BUILD. Committed to allow easier collaboration Modified: geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java ============================================================================== --- geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java (original) +++ geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java Fri Sep 24 13:21:47 2004 @@ -70,6 +70,7 @@ import org.apache.xmlbeans.SchemaTypeLoader; import org.apache.xmlbeans.XmlBeans; import org.apache.xmlbeans.XmlObject; +import org.apache.xmlbeans.XmlException; /** @@ -132,19 +133,25 @@ } else { moduleBase = new URL("jar:" + module.toString() + "!/"); } - GerApplicationClientDocument plan = (GerApplicationClientDocument) parseVendorDD(new URL(moduleBase, "META-INF/geronimo-application-client.xml")); + URL path = new URL(moduleBase, "META-INF/geronimo-application-client.xml"); + XmlObject dd = SchemaConversionUtils.parse(path.openStream()); + + GerApplicationClientDocument plan = (GerApplicationClientDocument) validateVendorDD(dd); if (plan == null) { return createDefaultPlan(moduleBase); } return plan; } catch (MalformedURLException e) { return null; + } catch (IOException e) { + return null; + } catch (XmlException e) { + throw new DeploymentException(e); } } - public XmlObject parseVendorDD(URL path) throws DeploymentException { + public XmlObject validateVendorDD(XmlObject dd) throws DeploymentException { try { - XmlObject dd = SchemaConversionUtils.parse(path.openStream()); dd = SchemaConversionUtils.convertToGeronimoNamingSchema(dd); return dd.changeType(GerApplicationClientDocument.type); } catch (Exception e) { Modified: geronimo/trunk/modules/connector/maven.xml ============================================================================== --- geronimo/trunk/modules/connector/maven.xml (original) +++ geronimo/trunk/modules/connector/maven.xml Fri Sep 24 13:21:47 2004 @@ -54,12 +54,45 @@ basedir="${basedir}/target/test-rar-15"/> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java ============================================================================== --- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java (original) +++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java Fri Sep 24 13:21:47 2004 @@ -24,11 +24,10 @@ import java.net.URISyntaxException; import java.net.URL; import java.util.Collections; +import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Properties; -import java.util.Enumeration; -import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.zip.ZipEntry; import javax.management.AttributeNotFoundException; @@ -37,7 +36,6 @@ import javax.management.ReflectionException; import org.apache.geronimo.common.propertyeditor.PropertyEditors; -import org.apache.geronimo.common.xml.XmlBeansUtil; import org.apache.geronimo.connector.ActivationSpecInfo; import org.apache.geronimo.connector.outbound.connectionmanagerconfig.LocalTransactions; import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool; @@ -51,8 +49,8 @@ import org.apache.geronimo.connector.outbound.security.PasswordCredentialRealm; import org.apache.geronimo.deployment.DeploymentException; import org.apache.geronimo.deployment.service.GBeanHelper; -import org.apache.geronimo.deployment.util.JarUtil; import org.apache.geronimo.deployment.util.IOUtil; +import org.apache.geronimo.deployment.util.JarUtil; import org.apache.geronimo.gbean.DynamicGAttributeInfo; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; @@ -137,13 +135,15 @@ throw new DeploymentException("Unable to parse specDD"); } - public XmlObject parseVendorDD(URL path) throws DeploymentException { + public XmlObject validateVendorDD(XmlObject dd) throws DeploymentException { try { - XmlObject dd = SchemaConversionUtils.parse(path.openStream()); - return dd.changeType(GerConnectorDocument.type); - } catch (Exception e) { - throw new DeploymentException(e); - } + dd = SchemaConversionUtils.getNestedObjectAsType(dd, "connector", GerConnectorType.type); + SchemaConversionUtils.validateDD(dd); + System.out.println("Successfully validated: " + dd); + return dd; + } catch (Exception e) { + throw new DeploymentException(e); + } } public XmlObject getDeploymentPlan(URL module) throws DeploymentException { @@ -154,18 +154,33 @@ } else { moduleBase = new URL("jar:" + module.toString() + "!/"); } - return (GerConnectorDocument) parseVendorDD(new URL(moduleBase, "META-INF/geronimo-ra.xml")); + URL path = new URL(moduleBase, "META-INF/geronimo-ra.xml"); + return getGerConnector(path); } catch (MalformedURLException e) { return null; + } catch (IOException e) { + return null; + } + } + + GerConnectorType getGerConnector(URL path) throws DeploymentException { + try { + XmlObject dd = SchemaConversionUtils.parse(path.openStream()); + return (GerConnectorType) validateVendorDD(dd); + } catch (IOException e) { + //todo should this throw an exception? we have already opened the stream! + return null; + } catch (XmlException e) { + throw new DeploymentException(e); } } public boolean canHandlePlan(XmlObject plan) { - return plan instanceof GerConnectorDocument; + return plan instanceof GerConnectorType; } public URI getParentId(XmlObject plan) throws DeploymentException { - GerConnectorType geronimoConnector = ((GerConnectorDocument) plan).getConnector(); + GerConnectorType geronimoConnector = (GerConnectorType) plan; if (geronimoConnector.isSetParentId()) { try { return new URI(geronimoConnector.getParentId()); @@ -178,7 +193,7 @@ } public URI getConfigId(XmlObject plan) throws DeploymentException { - GerConnectorType geronimoConnector = ((GerConnectorDocument) plan).getConnector(); + GerConnectorType geronimoConnector = (GerConnectorType) plan; try { return new URI(geronimoConnector.getConfigId()); } catch (URISyntaxException e) { @@ -217,13 +232,8 @@ if (vendorDD == null) { try { - JarEntry entry = moduleFile.getJarEntry("META-INF/geronimo-ra.xml"); - if (entry != null) { - InputStream in = moduleFile.getInputStream(entry); - if (in != null) { - vendorDD = XmlBeansUtil.parse(in, GerConnectorDocument.type); - } - } + URL vendorURL = JarUtil.createJarURL(moduleFile, "META-INF/geronimo-ra.xml"); + vendorDD = getGerConnector(vendorURL); } catch (Exception e) { throw new DeploymentException("Unable to parse META-INF/geronimo-ra.xml", e); } @@ -232,8 +242,7 @@ throw new DeploymentException("No geronimo-ra.xml."); } - GerConnectorDocument geronimoConnectorDoc = (GerConnectorDocument) vendorDD; - GerConnectorType geronimoConnector = geronimoConnectorDoc.getConnector(); + GerConnectorType geronimoConnector = (GerConnectorType) vendorDD; return new ConnectorModule(name, moduleURI, moduleFile, targetPath, connector, geronimoConnector, specDD); } Added: geronimo/trunk/modules/connector/src/test-data/data/external-application-plan.xml ============================================================================== --- (empty file) +++ geronimo/trunk/modules/connector/src/test-data/data/external-application-plan.xml Fri Sep 24 13:21:47 2004 @@ -0,0 +1,183 @@ + + + + + + + + test-rar-10-noger.rar + + + + + + + javax.resource.cci.ConnectionFactory + + FirstTestOutboundConnectionFactory + newvalue1 + newvalue2 + + TargetRealm + + + + + 10 + 5000 + + + + + connectionfactories/testcf + javax.resource.spi.security.PasswordCredential + + + SecondTestOutboundConnectionFactory + newvalue3 + newvalue4 + + + + + + 10 + 5000 + + + + + + ThirdTestOutboundConnectionFactory + StringValue3 + + TargetRealm + + + + + 10 + 5000 + + + + + + + + + + + + + + test-rar-15-noger.rar + + + + + + testRA + NewStringValue + DefaultWorkManager + + + + javax.resource.cci.ConnectionFactory + + FirstTestOutboundConnectionFactory + newvalue1 + newvalue2 + + TargetRealm + + + + + 10 + 5000 + + + + + connectionfactories/testcf + javax.resource.spi.security.PasswordCredential + + + SecondTestOutboundConnectionFactory + newvalue3 + newvalue4 + + TargetRealm + + + + + 10 + 5000 + + + + + + + + org.apache.geronimo.connector.mock.ConnectionFactoryExtension + + ThirdTestOutboundConnectionFactory + StringValue3 + + TargetRealm + + + + + 10 + 5000 + + + + + + + + + org.apache.geronimo.connector.mock.MockAdminObject + org.apache.geronimo.connector.mock.MockAdminObjectImpl + + tweedledee + Dee-value + + + tweedledum + Dum-value + + + + + + + + + \ No newline at end of file Modified: geronimo/trunk/modules/connector/src/test-data/ear/application.xml ============================================================================== --- geronimo/trunk/modules/connector/src/test-data/ear/application.xml (original) +++ geronimo/trunk/modules/connector/src/test-data/ear/application.xml Fri Sep 24 13:21:47 2004 @@ -3,15 +3,9 @@ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4"> - - test - test-war.war - + test-rar-10-noger.rar - test-ejb-jar.jar - - - test-rar.rar + test-rar-15-noger.rar Modified: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java ============================================================================== --- geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java (original) +++ geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java Fri Sep 24 13:21:47 2004 @@ -47,6 +47,7 @@ import org.apache.geronimo.j2ee.deployment.EARContext; import org.apache.geronimo.j2ee.deployment.Module; import org.apache.geronimo.j2ee.deployment.ModuleBuilder; +import org.apache.geronimo.j2ee.deployment.EARConfigBuilder; import org.apache.geronimo.j2ee.management.impl.J2EEServerImpl; import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.config.Configuration; @@ -56,8 +57,10 @@ import org.apache.geronimo.system.serverinfo.ServerInfo; import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument; import org.apache.geronimo.xbeans.j2ee.connector_1_0.ConnectorDocument10; +import org.apache.geronimo.schema.SchemaConversionUtils; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; +import org.apache.xmlbeans.XmlCursor; import org.tranql.sql.jdbc.JDBCUtil; /** @@ -100,9 +103,11 @@ } private File rarFile = new File(basedir, "target/test-rar-10"); + public File getRARFile() { return rarFile; } + public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { moduleBuilder.installModule(new UnpackedJarFile(rarFile), earContext, module); } @@ -121,9 +126,11 @@ } private File rarFile = new File(basedir, "target/test-rar-10"); + public File getRARFile() { return rarFile; } + public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { moduleBuilder.installModule(new UnpackedJarFile(rarFile), earContext, module); } @@ -147,9 +154,11 @@ } private File rarFile = new File(basedir, "target/test-rar-10"); + public File getRARFile() { return rarFile; } + public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { moduleBuilder.installModule(new UnpackedJarFile(rarFile), earContext, module); } @@ -160,7 +169,7 @@ } catch (DeploymentException e) { } } - + public void testBuildUnpackedAltSpecVendorDDModule() throws Exception { InstallAction action = new InstallAction() { public URL getVendorDD() throws MalformedURLException { @@ -173,16 +182,18 @@ } private File rarFile = new File(basedir, "target/test-rar-10"); + public File getRARFile() { return rarFile; } + public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { moduleBuilder.installModule(new UnpackedJarFile(rarFile), earContext, module); } }; executeTestBuildModule(action); } - + public void testBuildPackedModule() throws Exception { InstallAction action = new InstallAction() { public URL getVendorDD() { @@ -194,9 +205,11 @@ } private File rarFile = new File(basedir, "target/test-rar-10.rar"); + public File getRARFile() { return rarFile; } + public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { moduleBuilder.installModule(JarUtil.createJarFile(rarFile), earContext, module); } @@ -211,7 +224,7 @@ String j2eeModuleName = "org/apache/geronimo/j2ee/deployment/test"; ObjectName connectionTrackerName = new ObjectName("geronimo.connector:service=ConnectionTracker"); - ModuleBuilder moduleBuilder = new ConnectorModuleBuilder(); + ConnectorModuleBuilder moduleBuilder = new ConnectorModuleBuilder(); File rarFile = action.getRARFile(); ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); @@ -224,7 +237,7 @@ if (vendorURL == null) { vendorURL = JarUtil.createJarURL(rarJarFile, "META-INF/geronimo-ra.xml"); } - XmlObject plan = moduleBuilder.parseVendorDD(vendorURL); + XmlObject plan = moduleBuilder.getGerConnector(vendorURL); if (plan == null) { throw new DeploymentException(); } @@ -267,6 +280,34 @@ } } + public void testBuildEar() throws Exception { + String j2eeDomainName = "geronimo.server"; + String j2eeServerName = "TestGeronimoServer"; + String j2eeApplicationName = "TestEar"; + String j2eeModuleName = "org/apache/geronimo/j2ee/deployment/test"; + ObjectName connectionTrackerName = new ObjectName("geronimo.connector:service=ConnectionTracker"); + ObjectName j2eeServer = new ObjectName(j2eeDomainName + ":name=" + j2eeServerName); + Kernel kernel = new Kernel("blah"); + kernel.boot(); + + EARConfigBuilder configBuilder = new EARConfigBuilder(j2eeServer, null, connectionTrackerName, null, null, null, null, null, null, new ConnectorModuleBuilder(), null, kernel); + File rarFile = new File(basedir, "target/test-ear-noger.ear"); + File outFile = File.createTempFile("EARTest", ".car"); + try { + File planFile = new File(basedir, "src/test-data/data/external-application-plan.xml"); + XmlObject planDoc = SchemaConversionUtils.parse(planFile.toURL().openStream()); + XmlCursor cursor = planDoc.newCursor(); + cursor.toFirstChild(); + XmlObject plan = cursor.getObject(); + cursor.dispose(); + configBuilder.buildConfiguration(outFile, null, rarFile, plan); + + } finally { + outFile.delete(); + } + } + + private void verifyDeployment(File unpackedDir, ClassLoader cl, String j2eeDomainName, String j2eeServerName, String j2eeApplicationName, String j2eeModuleName) throws Exception { DataSource ds = null; Kernel kernel = null; @@ -428,8 +469,11 @@ private interface InstallAction { File getRARFile(); + void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception; + URL getVendorDD() throws MalformedURLException; + URL getSpecDD() throws MalformedURLException; } Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java ============================================================================== --- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java (original) +++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java Fri Sep 24 13:21:47 2004 @@ -47,6 +47,7 @@ import org.apache.xmlbeans.XmlBeans; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; +import org.apache.xmlbeans.XmlCursor; /** * Command line based deployment utility which combines multiple deployable modules @@ -69,10 +70,8 @@ XmlObject plan = null; if (deploymentPlan != null) { try { - plan = getLoader().parse(deploymentPlan, null, null); - } catch (XmlException e) { - throw new DeploymentException(e); - } catch (IOException e) { + plan = getPlan(deploymentPlan.toURL()); + } catch (MalformedURLException e) { throw new DeploymentException(e); } for (Iterator i = builders.iterator(); i.hasNext();) { @@ -123,6 +122,19 @@ } } + private XmlObject getPlan(URL deploymentPlan) throws DeploymentException { + try { + XmlObject plan = getLoader().parse(deploymentPlan, null, null); + XmlCursor cursor = plan.newCursor(); + cursor.toFirstChild(); + return cursor.getObject(); + } catch (XmlException e) { + throw new DeploymentException(e); + } catch (IOException e) { + throw new DeploymentException(e); + } + } + /** * GBean entry point invoked from an executable CAR. * @@ -139,7 +151,7 @@ // parse the plan XmlObject plan = null; if (cmd.plan != null) { - plan = getLoader().parse(cmd.plan, null, null); + plan = getPlan(cmd.plan); for (Iterator i = builders.iterator(); i.hasNext();) { ConfigurationBuilder candidate = (ConfigurationBuilder) i.next(); if (candidate.canConfigure(plan)) { Modified: geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java ============================================================================== --- geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java (original) +++ geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java Fri Sep 24 13:21:47 2004 @@ -31,6 +31,7 @@ import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlOptions; +import org.apache.xmlbeans.SchemaType; /** * @version $Rev$ $Date$ @@ -203,26 +204,46 @@ public static XmlObject convertToGeronimoNamingSchema(XmlObject xmlObject) { XmlCursor cursor = xmlObject.newCursor(); - XmlCursor end = xmlObject.newCursor(); + XmlCursor end = xmlObject.newCursor(); String version = "1.0"; try { while (cursor.hasNextToken()) { if (cursor.isStart()) { String localName = cursor.getName().getLocalPart(); if (localName.equals("ejb-ref") - || localName.equals("ejb-local-ref") - || localName.equals("resource-ref") - || localName.equals("resource-env-ref")) { + || localName.equals("ejb-local-ref") + || localName.equals("resource-ref") + || localName.equals("resource-env-ref")) { convertElementToSchema(cursor, end, GERONIMO_NAMING_NAMESPACE, GERONIMO_NAMING_NAMESPACE_L0CATION, version); } - } - cursor.toNextToken(); + } + cursor.toNextToken(); } } finally { cursor.dispose(); + end.dispose(); } return xmlObject; + } + public static XmlObject getNestedObjectAsType(XmlObject xmlObject, String desiredElement, SchemaType type) { + XmlCursor cursor = xmlObject.newCursor(); + try { + while (cursor.hasNextToken()) { + if (cursor.isStart()) { + String localName = cursor.getName().getLocalPart(); + if (localName.equals(desiredElement)) { + XmlObject child = cursor.getObject(); + XmlObject result = child.changeType(type); + return result; + } + } + cursor.toNextToken(); + } + } finally { + cursor.dispose(); + } + throw new IllegalArgumentException("xmlobject did not have desired element: " + desiredElement + "/n" + xmlObject); } @@ -252,9 +273,9 @@ public static boolean convertElementToSchema(XmlCursor cursor, XmlCursor end, String namespace, String schemaLocationURL, String version) { //convert namespace - // boolean isFirstStart = true; - end.toCursor(cursor); - end.toEndToken(); + // boolean isFirstStart = true; + end.toCursor(cursor); + end.toEndToken(); while (cursor.hasNextToken() && cursor.isLeftOf(end)) { if (cursor.isStart()) { if (namespace.equals(cursor.getName().getNamespaceURI())) { @@ -263,9 +284,9 @@ } cursor.setName(new QName(namespace, cursor.getName().getLocalPart())); cursor.toNextToken(); - // if (isFirstStart) { - // cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "xsi"), namespace + " " + schemaLocationURL); - // isFirstStart = false; + // if (isFirstStart) { + // cursor.insertAttributeWithValue(new QName("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation", "xsi"), namespace + " " + schemaLocationURL); + // isFirstStart = false; //} } else { cursor.toNextToken(); Modified: geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java ============================================================================== --- geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java (original) +++ geronimo/trunk/modules/j2ee-schema/src/test/org/apache/geronimo/schema/SchemaConversionUtilsTest.java Fri Sep 24 13:21:47 2004 @@ -24,6 +24,7 @@ import junit.framework.TestCase; import org.apache.xmlbeans.XmlCursor; import org.apache.xmlbeans.XmlObject; +import org.apache.geronimo.xbeans.j2ee.EjbJarType; /** * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should @@ -250,6 +251,15 @@ xmlObject = SchemaConversionUtils.convertToGeronimoNamingSchema(xmlObject); boolean ok2 = compareXmlObjects(xmlObject, expected, problems); assertTrue("Differences: " + problems, ok2); + } +// + public void testGetNestedObjectAsType() throws Exception { + File srcXml = new File(basedir, "src/test-data/geronimo/ejb-naming-pre.xml"); +// File expectedOutputXml = new File(basedir, "src/test-data/geronimo/ejb-naming-post.xml"); + XmlObject xmlObject = XmlObject.Factory.parse(srcXml); + //this is not a usable type, we'll see what happens though + xmlObject = SchemaConversionUtils.getNestedObjectAsType(xmlObject, "openejb-jar", EjbJarType.type); +// System.out.println(xmlObject.toString()); } private boolean compareXmlObjects(XmlObject xmlObject, XmlObject expectedObject, List problems) { Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java Fri Sep 24 13:21:47 2004 @@ -165,29 +165,18 @@ URL path = new URL(moduleBase, "META-INF/geronimo-application.xml"); XmlObject plan = null; - try { - plan = SchemaConversionUtils.parse(path.openStream()); - } catch (XmlException e) { - throw new DeploymentException(e); - } catch (IOException e) { - //plan not found, construct default plan - } + plan = getGerConnector(path); if (plan != null) { - plan.changeType(GerApplicationDocument.type); - SchemaConversionUtils.validateDD(plan); return plan; } // try to create a default plan (will return null if this is not an ear file) - GerApplicationDocument defaultPlan = createDefaultPlan(moduleBase); + GerApplicationType defaultPlan = createDefaultPlan(moduleBase); if (defaultPlan != null) { return defaultPlan; } } catch (MalformedURLException e) { - } catch (XmlException e) { - throw new DeploymentException("Invalid geronimo-application.xml", e); } - // support a naked modules if (webConfigBuilder != null) { XmlObject plan = webConfigBuilder.getDeploymentPlan(deploymentURL); @@ -220,7 +209,29 @@ return null; } - private GerApplicationDocument createDefaultPlan(URL deploymentURL) { + private GerApplicationType getGerConnector(URL path) throws DeploymentException { + try { + XmlObject dd = SchemaConversionUtils.parse(path.openStream()); + return (GerApplicationType) validateVendorDD(dd); + } catch (IOException e) { + //todo should this throw an exception? we have already opened the stream! + return null; + } catch (XmlException e) { + throw new DeploymentException(e); + } + } + + private XmlObject validateVendorDD(XmlObject dd) throws DeploymentException { + try { + dd = SchemaConversionUtils.getNestedObjectAsType(dd, "application", GerApplicationType.type); + SchemaConversionUtils.validateDD(dd); + return dd; + } catch (Exception e) { + throw new DeploymentException(e); + } + } + + private GerApplicationType createDefaultPlan(URL deploymentURL) { // load the web.xml URL applicationXmlUrl = null; try { @@ -242,8 +253,7 @@ } // construct the empty geronimo-application.xml - GerApplicationDocument gerApplicationDocument = GerApplicationDocument.Factory.newInstance(); - GerApplicationType gerApplication = gerApplicationDocument.addNewApplication(); + GerApplicationType gerApplication = GerApplicationType.Factory.newInstance(); // set the parentId and configId gerApplication.setParentId(PARENT_ID); @@ -263,7 +273,7 @@ } gerApplication.setConfigId(id); - return gerApplicationDocument; + return gerApplication; } public void buildConfiguration(File outfile, Manifest manifest, final File earFolder, final XmlObject plan) throws IOException, DeploymentException { @@ -388,7 +398,7 @@ } private ApplicationType addModules(final JarFile earFile, XmlObject plan, URI configId, Set moduleLocations, Set modules) throws IOException, DeploymentException { - if (plan instanceof GerApplicationDocument) { + if (plan instanceof GerApplicationType) { ApplicationType application; JarEntry appXMLEntry = earFile.getJarEntry("META-INF/application.xml"); if (appXMLEntry == null) { @@ -399,12 +409,12 @@ // build map from module path to alt vendor dd Map altVendorDDs = new HashMap(); - GerApplicationDocument gerApplication = (GerApplicationDocument) plan; - GerModuleType gerModuleTypes[] = gerApplication.getApplication().getModuleArray(); + GerApplicationType gerApplication = (GerApplicationType) plan; + GerModuleType gerModuleTypes[] = gerApplication.getModuleArray(); for (int i = 0; i < gerModuleTypes.length; i++) { GerModuleType gerModuleType = gerModuleTypes[i]; + String path = null; if (gerModuleType.isSetAltDd()) { - String path = null; if (gerModuleType.isSetEjb()) { path = gerModuleType.getEjb().getStringValue(); } else if (gerModuleType.isSetWeb()) { @@ -412,7 +422,18 @@ } else if (gerModuleType.isSetConnector()) { path = gerModuleType.getConnector().getStringValue(); } - altVendorDDs.put(path, JarUtil.createJarURL(earFile, gerModuleType.getAltDd().getStringValue())); + URL ddURL = JarUtil.createJarURL(earFile, gerModuleType.getAltDd().getStringValue()); + XmlObject dd = null; + try { + dd = SchemaConversionUtils.parse(ddURL.openStream()); + } catch (XmlException e) { + throw new DeploymentException(e); + } + + altVendorDDs.put(path, dd); + } else { + //dd is included explicitly + altVendorDDs.put(path, gerModuleType.getModuleDd()); } } @@ -463,9 +484,9 @@ } XmlObject vendorDD = null; - URL altVendorDD = (URL) altVendorDDs.get(modulePath); + XmlObject altVendorDD = (XmlObject) altVendorDDs.get(modulePath); if (altVendorDD != null) { - vendorDD = builder.parseVendorDD(altVendorDD); + vendorDD = builder.validateVendorDD(altVendorDD); if (vendorDD == null) { throw new DeploymentException("Invalid alt vendor dd: modulePath=" + modulePath + ", url=" + altVendorDD); } @@ -532,9 +553,8 @@ } private URI getParentId(XmlObject plan) throws DeploymentException { - if (plan instanceof GerApplicationDocument) { - GerApplicationDocument applicationDoc = (GerApplicationDocument) plan; - GerApplicationType application = applicationDoc.getApplication(); + if (plan instanceof GerApplicationType) { + GerApplicationType application = (GerApplicationType) plan; if (application.isSetParentId()) { try { return new URI(application.getParentId()); @@ -574,9 +594,8 @@ } private URI getConfigId(XmlObject plan) throws DeploymentException { - if (plan instanceof GerApplicationDocument) { - GerApplicationDocument applicationDoc = (GerApplicationDocument) plan; - GerApplicationType application = applicationDoc.getApplication(); + if (plan instanceof GerApplicationType) { + GerApplicationType application = (GerApplicationType) plan; try { return new URI(application.getConfigId()); } catch (URISyntaxException e) { @@ -612,7 +631,7 @@ } private ConfigurationModuleType getType(XmlObject plan) throws DeploymentException { - if (plan instanceof GerApplicationDocument) { + if (plan instanceof GerApplicationType) { return ConfigurationModuleType.EAR; } Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java Fri Sep 24 13:21:47 2004 @@ -22,7 +22,6 @@ import org.apache.geronimo.deployment.DeploymentException; import org.apache.xmlbeans.SchemaTypeLoader; -import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; /** @@ -31,7 +30,7 @@ public interface ModuleBuilder { XmlObject parseSpecDD(URL path) throws DeploymentException; - XmlObject parseVendorDD(URL vendorURL) throws DeploymentException; + XmlObject validateVendorDD(XmlObject vendorDD) throws DeploymentException; XmlObject getDeploymentPlan(URL module) throws DeploymentException; Modified: geronimo/trunk/modules/j2ee/src/schema/geronimo-application.xsd ============================================================================== --- geronimo/trunk/modules/j2ee/src/schema/geronimo-application.xsd (original) +++ geronimo/trunk/modules/j2ee/src/schema/geronimo-application.xsd Fri Sep 24 13:21:47 2004 @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - + - + @@ -48,22 +48,31 @@ - + - - - + + + + Specifies an optional URI to the post-assembly version of the Geronimo specific deployment descriptor file for a particular J2EE module. - - - + + + + + + + Include the literal vendor dd in the appropriate namespace. + + + + - + @@ -74,7 +83,7 @@ - + @@ -83,9 +92,20 @@ - + - + + + + + contains a literal vendor dd + + + + + + + Modified: geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ejb-jar.xml ============================================================================== --- geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ejb-jar.xml (original) +++ geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ejb-jar.xml Fri Sep 24 13:21:47 2004 @@ -0,0 +1,31 @@ + + + + + DefaultDatasource + + + + SimpleStatelessSession + client/test/simple/SimpleStatelessSessionHome + + + Modified: geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ra.xml ============================================================================== --- geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ra.xml (original) +++ geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-ra.xml Fri Sep 24 13:21:47 2004 @@ -0,0 +1,23 @@ + + + + + + Modified: geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-war.xml ============================================================================== --- geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-war.xml (original) +++ geronimo/trunk/modules/j2ee/src/test-unpacked-ear/alt-ger-war.xml Fri Sep 24 13:21:47 2004 @@ -0,0 +1,29 @@ + + + + + false + + Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java (original) +++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java Fri Sep 24 13:21:47 2004 @@ -16,17 +16,16 @@ */ package org.apache.geronimo.j2ee.deployment; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URL; import java.util.jar.JarFile; -import java.io.InputStream; -import java.io.IOException; import junit.framework.Assert; import org.apache.geronimo.deployment.DeploymentException; import org.apache.xmlbeans.SchemaTypeLoader; import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlException; /** * @version $Rev$ $Date$ @@ -90,21 +89,8 @@ } } - public XmlObject parseVendorDD(URL vendorURL) throws DeploymentException { - InputStream in = null; - try { - in = vendorURL.openStream(); - return XmlObject.Factory.newInstance(); - } catch (IOException e) { - throw new DeploymentException(e); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - } - } - } + public XmlObject validateVendorDD(XmlObject vendorDD) throws DeploymentException { + return XmlObject.Factory.newInstance(); } public void initContext(EARContext earContext, Module connectorModule, ClassLoader cl) { Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java (original) +++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java Fri Sep 24 13:21:47 2004 @@ -16,17 +16,16 @@ */ package org.apache.geronimo.j2ee.deployment; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URL; import java.util.jar.JarFile; -import java.io.InputStream; -import java.io.IOException; import junit.framework.Assert; import org.apache.geronimo.deployment.DeploymentException; import org.apache.xmlbeans.SchemaTypeLoader; import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlException; /** * @version $Rev$ $Date$ @@ -90,21 +89,8 @@ } } - public XmlObject parseVendorDD(URL vendorURL) throws DeploymentException { - InputStream in = null; - try { - in = vendorURL.openStream(); - return XmlObject.Factory.newInstance(); - } catch (IOException e) { - throw new DeploymentException(e); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - } - } - } + public XmlObject validateVendorDD(XmlObject vendorDD) throws DeploymentException { + return XmlObject.Factory.newInstance(); } public void initContext(EARContext earContext, Module ejbModule, ClassLoader cl) { Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java (original) +++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java Fri Sep 24 13:21:47 2004 @@ -16,17 +16,16 @@ */ package org.apache.geronimo.j2ee.deployment; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.URL; import java.util.jar.JarFile; -import java.io.InputStream; -import java.io.IOException; import junit.framework.Assert; import org.apache.geronimo.deployment.DeploymentException; import org.apache.xmlbeans.SchemaTypeLoader; import org.apache.xmlbeans.XmlObject; -import org.apache.xmlbeans.XmlException; /** * @version $Rev$ $Date$ @@ -91,21 +90,8 @@ } } - public XmlObject parseVendorDD(URL vendorURL) throws DeploymentException { - InputStream in = null; - try { - in = vendorURL.openStream(); - return XmlObject.Factory.newInstance(); - } catch (IOException e) { - throw new DeploymentException(e); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - } - } - } + public XmlObject validateVendorDD(XmlObject vendorDD) throws DeploymentException { + return XmlObject.Factory.newInstance(); } public void initContext(EARContext earContext, Module webModule, ClassLoader cl) { Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java ============================================================================== --- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java (original) +++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java Fri Sep 24 13:21:47 2004 @@ -117,9 +117,8 @@ return webAppDoc.getWebApp(); } - public XmlObject parseVendorDD(URL path) throws DeploymentException { + public XmlObject validateVendorDD(XmlObject dd) throws DeploymentException { try { - XmlObject dd = SchemaConversionUtils.parse(path.openStream()); dd = SchemaConversionUtils.convertToGeronimoNamingSchema(dd); dd = dd.changeType(JettyWebAppDocument.type); SchemaConversionUtils.validateDD(dd); @@ -137,13 +136,19 @@ } else { moduleBase = new URL("jar:" + module.toString() + "!/"); } - JettyWebAppDocument plan = (JettyWebAppDocument) parseVendorDD(new URL(moduleBase, "WEB-INF/geronimo-jetty.xml")); + URL path = new URL(moduleBase, "WEB-INF/geronimo-jetty.xml"); + XmlObject dd = SchemaConversionUtils.parse(path.openStream()); + JettyWebAppDocument plan = (JettyWebAppDocument) validateVendorDD(dd); if (plan == null) { return createDefaultPlan(moduleBase); } return plan; } catch (MalformedURLException e) { return null; + } catch (IOException e) { + return null; + } catch (XmlException e) { + throw new DeploymentException(e); } }