servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r525287 - in /incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean: AbstractXBeanDeployer.java ClassLoaderXmlPreprocessor.java
Date Tue, 03 Apr 2007 21:35:07 GMT
Author: gnodet
Date: Tue Apr  3 14:35:07 2007
New Revision: 525287

URL: http://svn.apache.org/viewvc?view=rev&rev=525287
Log:
SM-918: Ability to reference Shared Libraries from Service Units

Modified:
    incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
    incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java

Modified: incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java?view=diff&rev=525287&r1=525286&r2=525287
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
(original)
+++ incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
Tue Apr  3 14:35:07 2007
@@ -20,6 +20,8 @@
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ServiceMixComponent;
 import org.apache.servicemix.common.ServiceUnit;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.framework.ComponentContextImpl;
 import org.apache.xbean.kernel.Kernel;
 import org.apache.xbean.kernel.KernelFactory;
 import org.apache.xbean.kernel.ServiceName;
@@ -28,6 +30,7 @@
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 import org.springframework.core.io.FileSystemResource;
 
+import javax.jbi.component.ComponentContext;
 import javax.jbi.management.DeploymentException;
 import java.io.File;
 import java.util.Collections;
@@ -116,8 +119,12 @@
     }
     
     protected List getXmlPreProcessors(String serviceUnitRootPath) {
+        JBIContainer container = null;
+        try {
+            container = ((ComponentContextImpl) component.getComponentContext()).getContainer();
+        } catch (Throwable t) { }
         FileSystemRepository repository = new FileSystemRepository(new File(serviceUnitRootPath));
-        ClassLoaderXmlPreprocessor classLoaderXmlPreprocessor = new ClassLoaderXmlPreprocessor(repository);
+        ClassLoaderXmlPreprocessor classLoaderXmlPreprocessor = new ClassLoaderXmlPreprocessor(repository,
container);
         return Collections.singletonList(classLoaderXmlPreprocessor);
     }
     

Modified: incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java?view=diff&rev=525287&r1=525286&r2=525287
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java
(original)
+++ incubator/servicemix/trunk/common/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java
Tue Apr  3 14:35:07 2007
@@ -26,6 +26,8 @@
 
 import javax.xml.parsers.DocumentBuilder;
 
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.framework.SharedLibrary;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.xbean.classloader.JarFileClassLoader;
 import org.apache.xbean.server.repository.FileSystemRepository;
@@ -52,12 +54,18 @@
     public static final String LIB_DIR = "/lib";
     
     private final FileSystemRepository repository;
+    private final JBIContainer container;
     
     public ClassLoaderXmlPreprocessor(Repository repository) {
+        this(repository, null);
+    }
+
+    public ClassLoaderXmlPreprocessor(Repository repository, JBIContainer container) {
         if (repository instanceof FileSystemRepository == false) {
             throw new IllegalArgumentException("repository must be a FileSystemRepository");
         }
         this.repository = (FileSystemRepository) repository;
+        this.container = container;
     }
 
     public void preprocess(SpringApplicationContext applicationContext, XmlBeanDefinitionReader
reader, Document document) {
@@ -161,6 +169,18 @@
                 classpath.add(location);
             }
             
+            // Add shared libraries
+            List<String> sls = new ArrayList<String>();
+            NodeList libraries = classpathElement.getElementsByTagName("library");
+            for (int i = 0; i < libraries.getLength(); i++) {
+                Element locationElement = (Element) locations.item(i);
+                String library = ((Text) locationElement.getFirstChild()).getData().trim();
+                sls.add(library);
+            }
+            if (sls.size() > 0 && container == null) {
+                throw new IllegalStateException("Can not reference shared libraries if the
component is not deployed in ServiceMix");
+            }
+            
             // convert the paths to URLS
             URL[] urls;
             if (classpath.size() != 0) {
@@ -178,10 +198,15 @@
             }
 
             // create the classloader
-            ClassLoader parentLoader = getParentClassLoader(applicationContext);
+            List<ClassLoader> parents = new ArrayList<ClassLoader>();
+            parents.add(getParentClassLoader(applicationContext));
+            for (String library : sls) {
+                SharedLibrary sl = container.getRegistry().getSharedLibrary(library);
+                parents.add(sl.getClassLoader());
+            }
             classLoader = new JarFileClassLoader(applicationContext.getDisplayName(), 
                                                  urls, 
-                                                 parentLoader,
+                                                 parents.toArray(new ClassLoader[parents.size()]),
                                                  inverse,
                                                  hidden.toArray(new String[hidden.size()]),
                                                  nonOverridable.toArray(new String[nonOverridable.size()]));



Mime
View raw message