Force usage of vanilla Xalan when in OSGi
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 16 Nov 2009 20:24:33 +0000 (20:24 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 16 Nov 2009 20:24:33 +0000 (20:24 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@3093 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

modules/agent/org.argeo.slc.agent.ext.xalan/META-INF/MANIFEST.MF
modules/agent/org.argeo.slc.agent.jms/META-INF/spring/osgi.xml
modules/agent/org.argeo.slc.agent/META-INF/MANIFEST.MF
runtime/org.argeo.slc.core/pom.xml
runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/ExecutionThread.java
runtime/org.argeo.slc.support.castor/pom.xml
runtime/org.argeo.slc.support.osgi/pom.xml
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/MultipleServiceExporterPostProcessor.java
runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java

index 5e06b35d249b20872616bf982e120ed122ae5b07..ea4b7ef1cff2a57d83cb11e36c9fab2937a78f1c 100644 (file)
@@ -3,4 +3,5 @@ Bundle-ManifestVersion: 2
 Fragment-Host: com.springsource.org.apache.xalan
 Bundle-Version: 0.12.1.SNAPSHOT
 Bundle-SymbolicName: org.argeo.slc.agent.ext.xalan
-Import-Package: org.w3c.dom.traversal;resolution:=optional
+Import-Package: com.sun.org.apache.xml.internal.dtm;resolution:=optional,
+ org.w3c.dom.traversal;resolution:=optional
index 395db0502428ac3914cecb43a68138e48376c25c..a40763c4362d7c0f4cd9da61eed3323ef9533a11 100644 (file)
@@ -18,5 +18,6 @@
        <service ref="jmsAgent.attachmentUploader" interface="org.argeo.slc.core.attachment.AttachmentUploader" />\r
 \r
        <reference id="modulesManager"\r
-               interface="org.argeo.slc.execution.ExecutionModulesManager" />\r
+               interface="org.argeo.slc.execution.ExecutionModulesManager"\r
+               context-class-loader="service-provider" />\r
 </beans:beans>
\ No newline at end of file
index dd7dadd60cd595bd5ea69fe1415bb54e58447f4f..2c6d13b0a9d8f1c213e462022dc5f7604e50f255 100644 (file)
@@ -4,3 +4,5 @@ Require-Bundle: org.argeo.slc.specs,org.argeo.slc.core,org.argeo.slc.s
 Bundle-Version: 0.12.1.SNAPSHOT
 Bundle-Name: Argeo SLC Agent
 Bundle-SymbolicName: org.argeo.slc.agent
+Import-Package: org.apache.xalan.processor,
+ org.apache.xerces.jaxp
index d9e1ae098a38e1e39655e86be63732b8fd1d6b75..fbd77f4097e40766719ee10d45e8c90ef1b84c9b 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.slc</groupId>
                        <artifactId>org.argeo.dep.osgi.commons.exec</artifactId>
                </dependency>
 
-               <!--
-                       <dependency> <groupId>org.apache.commons</groupId>
-                       <artifactId>com.springsource.org.apache.commons.logging</artifactId>
-                       </dependency> <dependency> <groupId>org.apache.log4j</groupId>
-                       <artifactId>com.springsource.org.apache.log4j</artifactId>
-                       </dependency>
-               -->
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
index 1450ab98a065f5dbe614d7c8c52b8bfb125c7dfc..3c85055f816dfa8efcda98a93677085e170ef27e 100644 (file)
@@ -28,6 +28,13 @@ public class ExecutionThread extends Thread {
        }
 
        public void run() {
+               if (getContextClassLoader() != null) {
+                       if (log.isTraceEnabled())
+                               log.debug("Context class loader set to "
+                                               + getContextClassLoader());
+               }
+
+               // Retrieve execution flow descriptor
                ExecutionFlowDescriptor executionFlowDescriptor = realizedFlow
                                .getFlowDescriptor();
                String flowName = executionFlowDescriptor.getName();
@@ -63,5 +70,4 @@ public class ExecutionThread extends Thread {
                        it.next().addSteps(slcExecution, steps);
                }
        }
-
 }
index 47957b742c166339139036064bcc4abee31257b1..e486f68eac183d1714028c29da6786ca1ecd7e02 100644 (file)
@@ -53,7 +53,8 @@
                                                        org.argeo.slc.msg.event;resolution:=optional,
                                                        org.argeo.slc.msg.test.tree;resolution:=optional,
                                                        org.argeo.slc.detached;resolution:=optional,
-                                                       org.apache.xml.serialize
+                                                       org.apache.xml.serialize;resolution:=optional,
+                                                       org.apache.xerces.jaxp;resolution:=optional
                                                </Import-Package>
                                                <Fragment-Host>com.springsource.org.castor</Fragment-Host>
                                        </instructions>
index 535f2cb015edf4e2b136bb2f88ceace408d15edb..a34ce66ef1c3798c73968c7a10171f3eac4a6920 100644 (file)
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.slc</groupId>
                        <artifactId>org.argeo.slc.osgiboot</artifactId>
                </dependency>
 
+               <!--
+                       Xalan and Xerces are implicitly required since the JDK provided
+                       implementations are overridden in the execution modules manager
+               -->
+               <dependency>
+                       <groupId>org.apache.xalan</groupId>
+                       <artifactId>com.springsource.org.apache.xalan</artifactId>
+               </dependency>
+
        </dependencies>
 </project>
index de759110f4ec1002a52691c94295593d0591489c..f5d0a3853c46e70e34159b37bae3c30b970d05c8 100644 (file)
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.support.RootBeanDefinition;
 import org.springframework.core.Ordered;
 import org.springframework.core.PriorityOrdered;
+import org.springframework.osgi.service.exporter.support.ExportContextClassLoader;
 import org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean;
 
 @SuppressWarnings(value = { "unchecked" })
@@ -29,6 +30,8 @@ public class MultipleServiceExporterPostProcessor implements
 
        private Class osgiServiceFactoryClass = OsgiServiceFactoryBean.class;
 
+       private Boolean useServiceProviderContextClassLoader = false;
+
        public void postProcessBeanFactory(
                        ConfigurableListableBeanFactory beanFactory) throws BeansException {
                if (!(beanFactory instanceof BeanDefinitionRegistry)) {
@@ -50,6 +53,9 @@ public class MultipleServiceExporterPostProcessor implements
                        MutablePropertyValues mpv = new MutablePropertyValues();
                        mpv.addPropertyValue("interfaces", interfaces.toArray());
                        mpv.addPropertyValue("targetBeanName", beanName);
+                       if (useServiceProviderContextClassLoader)
+                               mpv.addPropertyValue("contextClassLoader",
+                                               ExportContextClassLoader.SERVICE_PROVIDER);
                        RootBeanDefinition bd = new RootBeanDefinition(
                                        osgiServiceFactoryClass, mpv);
 
@@ -79,4 +85,10 @@ public class MultipleServiceExporterPostProcessor implements
        public int getOrder() {
                return Ordered.LOWEST_PRECEDENCE;
        }
+
+       public void setUseServiceProviderContextClassLoader(
+                       Boolean useServiceProviderContextClassLoader) {
+               this.useServiceProviderContextClassLoader = useServiceProviderContextClassLoader;
+       }
+
 }
index b2038b928b859083531119973b9b57bf9485dbbc..6c442c71defc6883e61a87f637bc6147dff4bcbe 100644 (file)
@@ -7,6 +7,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import org.apache.commons.logging.Log;
@@ -34,6 +35,27 @@ import org.springframework.osgi.service.importer.OsgiServiceLifecycleListener;
 public class OsgiExecutionModulesManager extends
                AbstractExecutionModulesManager implements InitializingBean,
                DisposableBean, OsgiServiceLifecycleListener {
+
+       static {
+               // Force usage of vanilla Xalan when in OSGi
+               // We would like to do it in a cleaner way
+               // but the integration of Xalan and Xerces in the JRE
+               // makes it very difficult
+               // Suggestions welcome!
+               Properties systemProperties = System.getProperties();
+//             if (!systemProperties
+//                             .containsKey("javax.xml.parsers.DocumentBuilderFactory"))
+//                     System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
+//                                     "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
+//             if (!systemProperties.containsKey("javax.xml.parsers.SAXParserFactory"))
+//                     System.setProperty("javax.xml.parsers.SAXParserFactory",
+//                                     "org.apache.xerces.jaxp.SAXParserFactoryImpl");
+               if (!systemProperties
+                               .containsKey("javax.xml.transform.TransformerFactory"))
+                       System.setProperty("javax.xml.transform.TransformerFactory",
+                                       "org.apache.xalan.processor.TransformerFactoryImpl");
+       }
+
        private final static String PROPERTY_CACHE_SERVICES = "slc.osgi.execution.cacheServices";
 
        private final static Log log = LogFactory