geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r463062 - in /geronimo/plugins/spring/trunk/modules/spring-deployer-service: ./ src/java/org/ src/java/org/apache/ src/java/org/apache/geronimo/ src/java/org/apache/geronimo/plugins/ src/java/org/apache/geronimo/plugins/spring/ src/java/org...
Date Wed, 11 Oct 2006 23:25:52 GMT
Author: ammulder
Date: Wed Oct 11 16:25:51 2006
New Revision: 463062

URL: http://svn.apache.org/viewvc?view=rev&rev=463062
Log:
Add Spring deployer GBean

Added:
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/deployment/
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/deployment/SpringContextDeployerGBean.java
  (with props)
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/geronimo-spring-1.0.xsd
  (with props)
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/xmlconfig.xml
  (with props)
Modified:
    geronimo/plugins/spring/trunk/modules/spring-deployer-service/pom.xml

Modified: geronimo/plugins/spring/trunk/modules/spring-deployer-service/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/spring/trunk/modules/spring-deployer-service/pom.xml?view=diff&rev=463062&r1=463061&r2=463062
==============================================================================
--- geronimo/plugins/spring/trunk/modules/spring-deployer-service/pom.xml (original)
+++ geronimo/plugins/spring/trunk/modules/spring-deployer-service/pom.xml Wed Oct 11 16:25:51
2006
@@ -17,7 +17,6 @@
 
     <build>
         <plugins>
-<!-- TODO
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>xmlbeans-maven-plugin</artifactId>
@@ -38,7 +37,6 @@
                     </xmlConfigs>
                 </configuration>
             </plugin>
--->
         </plugins>
         <sourceDirectory>src/java</sourceDirectory>
         <testSourceDirectory>src/test</testSourceDirectory>

Added: geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/deployment/SpringContextDeployerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/deployment/SpringContextDeployerGBean.java?view=auto&rev=463062
==============================================================================
--- geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/deployment/SpringContextDeployerGBean.java
(added)
+++ geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/deployment/SpringContextDeployerGBean.java
Wed Oct 11 16:25:51 2006
@@ -0,0 +1,301 @@
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.plugins.spring.deployment;
+
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.ConfigurationBuilder;
+import org.apache.geronimo.deployment.DeploymentContext;
+import org.apache.geronimo.deployment.ModuleIDBuilder;
+import org.apache.geronimo.deployment.service.EnvironmentBuilder;
+import org.apache.geronimo.deployment.util.DeploymentUtil;
+import org.apache.geronimo.deployment.xbeans.ArtifactType;
+import org.apache.geronimo.deployment.xbeans.EnvironmentType;
+import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
+import org.apache.geronimo.gbean.*;
+import org.apache.geronimo.j2ee.deployment.EJBReferenceBuilder;
+import org.apache.geronimo.j2ee.deployment.RefContext;
+import org.apache.geronimo.j2ee.deployment.ResourceReferenceBuilder;
+import org.apache.geronimo.j2ee.deployment.ServiceReferenceBuilder;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.Naming;
+import org.apache.geronimo.kernel.config.*;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ArtifactResolver;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.Repository;
+import org.apache.geronimo.plugins.spring.SpringGBean;
+import org.apache.geronimo.plugins.spring.deployment.xbeans.ContextType;
+import org.apache.geronimo.plugins.spring.deployment.xbeans.ContextsDocument;
+import org.apache.geronimo.plugins.spring.deployment.xbeans.ContextsType;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
+
+import javax.xml.namespace.QName;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.jar.JarFile;
+
+/**
+ * Deploys Spring contexts at runtime
+ *
+ * @version $Rev: 355877 $ $Date: 2005-12-10 21:48:27 -0500 (Sat, 10 Dec 2005) $
+ */
+public class SpringContextDeployerGBean implements ConfigurationBuilder {
+    private static final QName SERVICE_QNAME = ContextsDocument.type.getDocumentElementName();
+
+    private final Environment defaultEnvironment;
+    private final Collection repositories;
+    private final Naming naming;
+    private final ConfigurationManager configurationManager;
+    private final SingleElementCollection ejbRefBuilder;
+    private final SingleElementCollection resourceRefBuilder;
+    private final SingleElementCollection serviceRefBuilder;
+
+    public SpringContextDeployerGBean(Environment defaultEnvironment, Collection repositories,
+                             Kernel kernel, Collection ejbRefBuilder, Collection resourceRefBuilder,
Collection serviceRefBuilder) {
+        this(defaultEnvironment, repositories, kernel, new SingleElementCollection(ejbRefBuilder),
+                new SingleElementCollection(resourceRefBuilder), new SingleElementCollection(serviceRefBuilder));
+    }
+
+    public SpringContextDeployerGBean(Environment defaultEnvironment, Collection repositories,
+                             Kernel kernel, SingleElementCollection ejbRefBuilder, SingleElementCollection
resourceRefBuilder,
+                             SingleElementCollection serviceRefBuilder) {
+        this.defaultEnvironment = defaultEnvironment;
+        this.repositories = repositories;
+        naming = kernel.getNaming();
+        configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
+        this.ejbRefBuilder = ejbRefBuilder;
+        this.resourceRefBuilder = resourceRefBuilder;
+        this.serviceRefBuilder = serviceRefBuilder;
+    }
+
+    public Object getDeploymentPlan(File planFile, JarFile jarFile, ModuleIDBuilder idBuilder)
throws DeploymentException {
+        if (planFile == null && jarFile == null) {
+            return null;
+        }
+        URL plan;
+        try {
+            if (planFile != null) {
+                plan = planFile.toURL();
+            } else {
+                plan = DeploymentUtil.createJarURL(jarFile, "META-INF/geronimo-spring.xml");
+            }
+            ContextsDocument moduleDoc =  processPlanURL(plan);
+
+            if(moduleDoc == null) { // Not a Quartz deployment!
+                return null;
+            }
+
+            // If there's no artifact ID and we won't be able to figure one out later, use
the plan file name.  Bit of a hack.
+            if (jarFile == null && (moduleDoc.getContexts().getEnvironment() == null
||
+                    moduleDoc.getContexts().getEnvironment().getModuleId() == null ||
+                    moduleDoc.getContexts().getEnvironment().getModuleId().getArtifactId()
== null)) {
+                if (moduleDoc.getContexts().getEnvironment() == null) {
+                    moduleDoc.getContexts().addNewEnvironment();
+                }
+                if (moduleDoc.getContexts().getEnvironment().getModuleId() == null) {
+                    moduleDoc.getContexts().getEnvironment().addNewModuleId();
+                }
+                String name = planFile.getName();
+                int pos = name.lastIndexOf('.');
+                if (pos > -1) {
+                    name = name.substring(0, pos);
+                }
+                moduleDoc.getContexts().getEnvironment().getModuleId().setArtifactId(name);
+            }
+            return moduleDoc == null ? null : moduleDoc.getContexts();
+        } catch (MalformedURLException e) {
+            throw new DeploymentException("Unable to read plan for from "+planFile+" or "+jarFile);
+        } catch (IOException e) {
+            throw new DeploymentException("no plan at " + planFile, e);
+        }
+    }
+
+    public Artifact getConfigurationID(Object plan, JarFile module, ModuleIDBuilder idBuilder)
throws IOException, DeploymentException {
+        ContextsType configType = (ContextsType) plan;
+        EnvironmentType environmentType = configType.getEnvironment();
+        Environment environment = processEnvironment(environmentType);
+        idBuilder.resolve(environment, module == null ? "" : new File(module.getName()).getName(),
"car");
+        if(!environment.getConfigId().isResolved()) {
+            throw new IllegalStateException("Module ID is not fully populated ("+environment.getConfigId()+")");
+        }
+        return environment.getConfigId();
+    }
+
+    public DeploymentContext buildConfiguration(boolean inPlaceDeployment, Artifact configId,
Object plan, JarFile jar, Collection configurationStores, ArtifactResolver artifactResolver,
ConfigurationStore targetConfigurationStore) throws IOException, DeploymentException {
+        ContextsType configType = (ContextsType) plan;
+
+        return buildConfiguration(inPlaceDeployment, configId, configType, jar, configurationStores,
artifactResolver, targetConfigurationStore);
+    }
+
+    public ContextsDocument processPlanURL(URL url) throws DeploymentException, IOException
{
+        try {
+            XmlObject xmlObject;
+            try {
+                xmlObject = XmlBeansUtil.parse(url);
+            } catch (FileNotFoundException e) {
+                // Most likely it has a JAR but no plan, and nothing at META-INF/geronimo-quartz.xml,
+                // therefore it's not a quartz job deployment
+                return null;
+            }
+            if (xmlObject == null) {
+                return null;
+            }
+
+            XmlCursor cursor = xmlObject.newCursor();
+            try {
+                cursor.toFirstChild();
+                if (!SERVICE_QNAME.equals(cursor.getName())) {
+                    return null;
+                }
+            } finally {
+                cursor.dispose();
+            }
+            ContextsDocument moduleDoc;
+            if (xmlObject instanceof ContextsDocument) {
+                moduleDoc = (ContextsDocument) xmlObject;
+            } else {
+                moduleDoc = (ContextsDocument) xmlObject.changeType(ContextsDocument.type);
+            }
+            Collection errors = new ArrayList();
+            if (!moduleDoc.validate(XmlBeansUtil.createXmlOptions(errors))) {
+                throw new DeploymentException("Invalid deployment descriptor: " + errors
+ "\nDescriptor: " + moduleDoc.toString());
+            }
+            return moduleDoc;
+        } catch (XmlException e) {
+            throw new DeploymentException("Could not parse xml in plan", e);
+        }
+
+    }
+
+    public DeploymentContext buildConfiguration(boolean inPlaceDeployment, Artifact configId,
ContextsType moduleType, JarFile jar, Collection configurationStores, ArtifactResolver artifactResolver,
ConfigurationStore targetConfigurationStore) throws DeploymentException, IOException {
+        ArtifactType type = moduleType.getEnvironment().isSetModuleId() ? moduleType.getEnvironment().getModuleId()
: moduleType.getEnvironment().addNewModuleId();
+        type.setArtifactId(configId.getArtifactId());
+        type.setGroupId(configId.getGroupId());
+        type.setType(configId.getType());
+        type.setVersion(configId.getVersion().toString());
+        Environment environment = processEnvironment(moduleType.getEnvironment());
+        if(!environment.getConfigId().isResolved()) {
+            throw new IllegalStateException("Module ID should be fully resolved by now (not
"+environment.getConfigId()+")");
+        }
+        File outfile;
+        try {
+            outfile = targetConfigurationStore.createNewConfigurationDir(configId);
+        } catch (ConfigurationAlreadyExistsException e) {
+            throw new DeploymentException(e);
+        }
+
+        ConfigurationManager configurationManager = this.configurationManager;
+        if (configurationManager == null) {
+            configurationManager = new SimpleConfigurationManager(configurationStores, artifactResolver,
repositories);
+        }
+        DeploymentContext context = new DeploymentContext(outfile,
+                inPlaceDeployment && null != jar ? DeploymentUtil.toFile(jar) : null,
+                environment,
+                ConfigurationModuleType.SERVICE,
+                naming,
+                configurationManager,
+                repositories
+        );
+        if(jar != null) {
+            File file = new File(jar.getName());
+            context.addIncludeAsPackedJar(URI.create(file.getName()), jar);
+        }
+        try {
+            addContexts(moduleType.getContextArray(), configId, context);
+            return context;
+        } catch (RuntimeException t) {
+            context.close();
+            throw t;
+        } catch (Error e) {
+            context.close();
+            throw e;
+        }
+    }
+
+    public Environment processEnvironment(EnvironmentType environmentType) {
+        return EnvironmentBuilder.buildEnvironment(environmentType, defaultEnvironment);
+    }
+
+    private void addContexts(ContextType[] contexts, Artifact parentModule, DeploymentContext
context) throws DeploymentException {
+        GBeanData[] datas = processContexts(contexts, parentModule, context.getConfiguration());
+        for (int i = 0; i < datas.length; i++) {
+            try {
+                context.addGBean(datas[i]);
+            } catch (GBeanAlreadyExistsException e) {
+                throw new DeploymentException("Cannot add Spring context '"+contexts[i].getName()+"'
for module "+parentModule+"; a context with that name already exists.");
+            }
+        }
+    }
+
+    public GBeanData[] processContexts(ContextType[] contexts, Artifact parentModule, Configuration
config) throws DeploymentException {
+        ClassLoader loader = config.getConfigurationClassLoader();
+        RefContext refContext = new RefContext((EJBReferenceBuilder)ejbRefBuilder.getElement(),
+                (ResourceReferenceBuilder)resourceRefBuilder.getElement(),
+                (ServiceReferenceBuilder)serviceRefBuilder.getElement());
+        List list = new ArrayList();
+        for (int i = 0; i < contexts.length; i++) {
+            ContextType context = contexts[i];
+            GBeanData data = processContext(context, loader, parentModule);
+            list.add(data);
+        }
+        return (GBeanData[]) list.toArray(new GBeanData[list.size()]);
+    }
+
+    private GBeanData processContext(ContextType context, ClassLoader cl, Artifact parentModule)
{
+        GBeanInfo gBeanInfo = GBeanInfo.getGBeanInfo(SpringGBean.class.getName(), cl);
+        String namePart = context.getName();
+        AbstractName moduleName = naming.createRootName(parentModule, parentModule.toString(),
"ServiceModule");
+        AbstractName abstractName = naming.createChildName(moduleName, namePart, "GBean");
+        GBeanData data = new GBeanData(abstractName, gBeanInfo);
+        data.setAttribute("contextName", context.getName());
+        data.setAttribute("configFileName", context.getSpringConfig());
+        return data;
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Spring Context Deployer",
SpringContextDeployerGBean.class, "ConfigBuilder");
+
+        infoFactory.addAttribute("defaultEnvironment", Environment.class, true);
+        infoFactory.addAttribute("kernel", Kernel.class, false, false);
+        infoFactory.addReference("Repository", Repository.class, "Repository");
+
+        infoFactory.addReference("EJBReferenceBuilder", EJBReferenceBuilder.class, "ModuleBuilder");
+        infoFactory.addReference("ResourceReferenceBuilder", ResourceReferenceBuilder.class,
"ModuleBuilder");
+        infoFactory.addReference("ServiceReferenceBuilder", ServiceReferenceBuilder.class,
"ModuleBuilder");
+
+        infoFactory.setConstructor(new String[]{"defaultEnvironment", "Repository", "kernel",
+                                                "EJBReferenceBuilder", "ResourceReferenceBuilder",
+                                                "ServiceReferenceBuilder"});
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Propchange: geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/java/org/apache/geronimo/plugins/spring/deployment/SpringContextDeployerGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/geronimo-spring-1.0.xsd
URL: http://svn.apache.org/viewvc/geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/geronimo-spring-1.0.xsd?view=auto&rev=463062
==============================================================================
--- geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/geronimo-spring-1.0.xsd
(added)
+++ geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/geronimo-spring-1.0.xsd
Wed Oct 11 16:25:51 2006
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright 2004 The Apache Software Foundation
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+
+<xs:schema
+        targetNamespace="http://geronimo.apache.org/xml/ns/plugins/spring-1.0"
+        xmlns:spring="http://geronimo.apache.org/xml/ns/plugins/spring-1.0"
+        xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
+        xmlns:xs="http://www.w3.org/2001/XMLSchema"
+        elementFormDefault="qualified"
+        attributeFormDefault="unqualified"
+        >
+
+    <xs:annotation>
+        <xs:documentation>
+            Schema for deploying a Spring context into Geronimo.
+        </xs:documentation>
+    </xs:annotation>
+
+    <xs:import namespace="http://geronimo.apache.org/xml/ns/deployment-1.1" schemaLocation="geronimo-module-1.1.xsd"/>
+
+    <!--   Top-level elements   -->
+
+    <xs:element name="contexts" type="spring:contextsType">
+        <xs:annotation>
+            <xs:documentation>
+                A list of Spring contexts to deploy as part of this module
+            </xs:documentation>
+        </xs:annotation>
+    </xs:element>
+
+    <xs:complexType name="contextsType">
+        <xs:sequence>
+            <xs:element ref="sys:environment"/>
+            <xs:element name="context" type="spring:contextType" minOccurs="1" maxOccurs="unbounded">
+                <xs:annotation>
+                    <xs:documentation>
+                        A Spring context to deploy in Geronimo
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+
+    <xs:complexType name="contextType">
+        <xs:sequence>
+            <xs:element name="name" type="xs:string">
+                <xs:annotation>
+                    <xs:documentation>
+                        A unique name used to identify the Spring context
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:element>
+            <xs:element name="spring-config" type="xs:string">
+                <xs:annotation>
+                    <xs:documentation>
+                        The path to the Spring context configuration file, which should
+                        be packaged in the JAR file that is deployed.  The path here
+                        should be relative to the root of the JAR; the context config
+                        file will be loaded from the class path where that JAR is on
+                        the class path.
+                    </xs:documentation>
+                </xs:annotation>
+            </xs:element>
+        </xs:sequence>
+    </xs:complexType>
+</xs:schema>
+

Propchange: geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/geronimo-spring-1.0.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/xmlconfig.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/xmlconfig.xml?view=auto&rev=463062
==============================================================================
--- geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/xmlconfig.xml
(added)
+++ geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/xmlconfig.xml
Wed Oct 11 16:25:51 2006
@@ -0,0 +1,7 @@
+<xb:config xmlns:xb="http://www.bea.com/2002/09/xbean/config">
+
+    <xb:namespace uri="http://geronimo.apache.org/xml/ns/plugins/spring-1.0">
+        <xb:package>org.apache.geronimo.plugins.spring.deployment.xbeans</xb:package>
+    </xb:namespace>
+
+</xb:config>
\ No newline at end of file

Propchange: geronimo/plugins/spring/trunk/modules/spring-deployer-service/src/schema/xmlconfig.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message