X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.osgi%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fosgi%2FOsgiExecutionModulesManager.java;h=6c442c71defc6883e61a87f637bc6147dff4bcbe;hb=1700d7107498d27348384ab6fd9d6c5d535d823b;hp=ca8fabaeee77e830b75dee88aff9ba1223e913b8;hpb=1ad9314cf24ac6c596ca4b168541bce641ac383f;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java index ca8fabaee..6c442c71d 100644 --- a/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java +++ b/runtime/org.argeo.slc.support.osgi/src/main/java/org/argeo/slc/osgi/OsgiExecutionModulesManager.java @@ -7,11 +7,13 @@ 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; import org.apache.commons.logging.LogFactory; import org.argeo.slc.SlcException; +import org.argeo.slc.build.BasicNameVersion; import org.argeo.slc.core.execution.AbstractExecutionModulesManager; import org.argeo.slc.core.execution.DefaultExecutionFlowDescriptorConverter; import org.argeo.slc.deploy.ModuleDescriptor; @@ -33,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 @@ -48,12 +71,33 @@ public class OsgiExecutionModulesManager extends private Boolean useCachedServices = Boolean.parseBoolean(System .getProperty(PROPERTY_CACHE_SERVICES, "true")); - public ExecutionModuleDescriptor getExecutionModuleDescriptor( + public synchronized ExecutionModuleDescriptor getExecutionModuleDescriptor( String moduleName, String version) { ExecutionModuleDescriptor md = new ExecutionModuleDescriptor(); - md.setName(moduleName); - md.setVersion(version); - setMetadataFromBundle(md, null); + if (useCachedServices) { + OsgiBundle osgiBundle = null; + BasicNameVersion nameVersion = new BasicNameVersion(moduleName, + version); + bundles: for (Iterator iterator = executionContexts + .keySet().iterator(); iterator.hasNext();) { + OsgiBundle ob = iterator.next(); + if (ob.equals(nameVersion)) { + osgiBundle = ob; + break bundles; + } + } + if (osgiBundle == null) + throw new SlcException("No execution module registered for " + + nameVersion); + md.setName(osgiBundle.getName()); + md.setVersion(osgiBundle.getVersion()); + md.setLabel(osgiBundle.getLabel()); + md.setDescription(osgiBundle.getDescription()); + } else { + md.setName(moduleName); + md.setVersion(version); + setMetadataFromBundle(md, null); + } ExecutionFlowDescriptorConverter executionFlowDescriptorConverter = getExecutionFlowDescriptorConverter( moduleName, version); if (executionFlowDescriptorConverter == null) @@ -321,6 +365,10 @@ public class OsgiExecutionModulesManager extends if (service instanceof ExecutionContext) { ExecutionContext executionContext = (ExecutionContext) service; OsgiBundle osgiBundle = asOsgiBundle(properties); + Bundle bundle = bundlesManager.findRelatedBundle(osgiBundle); + osgiBundle.setLabel(getHeaderSafe(bundle, Constants.BUNDLE_NAME)); + osgiBundle.setDescription(getHeaderSafe(bundle, + Constants.BUNDLE_DESCRIPTION)); executionContexts.put(osgiBundle, executionContext); if (log.isTraceEnabled()) log.debug("Registered execution context from " + osgiBundle); @@ -364,10 +412,16 @@ public class OsgiExecutionModulesManager extends ExecutionFlow executionFlow = (ExecutionFlow) service; OsgiBundle osgiBundle = asOsgiBundle(properties); if (executionFlows.containsKey(osgiBundle)) { - executionFlows.get(osgiBundle).remove(executionFlow); + Set flows = executionFlows.get(osgiBundle); + flows.remove(executionFlow); if (log.isTraceEnabled()) log.debug("Removed " + executionFlow + " from " + osgiBundle); + if (flows.size() == 0) { + executionFlows.remove(osgiBundle); + if (log.isTraceEnabled()) + log.debug("Removed flows set from " + osgiBundle); + } } } else if (service instanceof ExecutionFlowDescriptorConverter) { OsgiBundle osgiBundle = asOsgiBundle(properties);