diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-09 09:17:30 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2008-09-09 09:17:30 +0000 |
commit | dc15447dfebac2b0218cb1ce6903923c574c84df (patch) | |
tree | 5cf9aba844a018bccab0743005af5d3701e98cce /java/sca/modules/assembly/src/main | |
parent | 7ea46da4356a04cd45cfa1cadcad9f7fdb28aa7f (diff) |
Fixes to get the Equinox integration working. Use the parent classloader instead of the Thread context classloader as parent of the contribution classloader. Use the ServiceDiscovery to get instances of DocumentBuilderFactory and TransformerFactory. Pass these factories around instead of creating new instances in different places. Clarified the few prints in the calculator-osgi sample showing which classloader is used.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@693411 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/assembly/src/main')
5 files changed, 114 insertions, 16 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java index 925ca9dc67..6f856986ad 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Map; import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; @@ -34,7 +36,6 @@ import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Property; @@ -69,14 +70,20 @@ public abstract class BaseConfigurationBuilderImpl { private Monitor monitor; private InterfaceContractMapper interfaceContractMapper; private SCADefinitions policyDefinitions; + private DocumentBuilderFactory documentBuilderFactory; + private TransformerFactory transformerFactory; protected BaseConfigurationBuilderImpl(AssemblyFactory assemblyFactory, SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, InterfaceContractMapper interfaceContractMapper, SCADefinitions policyDefinitions, Monitor monitor) { this.assemblyFactory = assemblyFactory; this.scaBindingFactory = scaBindingFactory; + this.documentBuilderFactory = documentBuilderFactory; + this.transformerFactory = transformerFactory; this.interfaceContractMapper = interfaceContractMapper; this.policyDefinitions = policyDefinitions; this.monitor = monitor; @@ -818,7 +825,8 @@ public abstract class BaseConfigurationBuilderImpl { for (Component component : composite.getComponents()) { try { - PropertyConfigurationUtil.sourceComponentProperties(compositeProperties, component); + PropertyConfigurationUtil.sourceComponentProperties(compositeProperties, component, + documentBuilderFactory, transformerFactory); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java index 8dd585f92b..0643421a45 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java @@ -19,6 +19,9 @@ package org.apache.tuscany.sca.assembly.builder.impl; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; + import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.SCABindingFactory; @@ -35,12 +38,27 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ComponentConfigurationBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder { + @Deprecated + public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + super(assemblyFactory, scaBindingFactory, + null, null, + interfaceContractMapper, policyDefinitions, monitor); + } + public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory, SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, InterfaceContractMapper interfaceContractMapper, SCADefinitions policyDefinitions, Monitor monitor) { - super(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); + super(assemblyFactory, scaBindingFactory, + documentBuilderFactory, transformerFactory, + interfaceContractMapper, policyDefinitions, monitor); } public void build(Composite composite) throws CompositeBuilderException { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java index 4c2c369f3e..85af173c0d 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java @@ -19,6 +19,9 @@ package org.apache.tuscany.sca.assembly.builder.impl; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; + import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.SCABindingFactory; @@ -35,12 +38,27 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class CompositeBindingURIBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder { + @Deprecated + public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + super(assemblyFactory, scaBindingFactory, + null, null, + interfaceContractMapper, policyDefinitions, monitor); + } + public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory, SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, InterfaceContractMapper interfaceContractMapper, SCADefinitions policyDefinitions, Monitor monitor) { - super(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); + super(assemblyFactory, scaBindingFactory, + documentBuilderFactory, transformerFactory, + interfaceContractMapper, policyDefinitions, monitor); } public void build(Composite composite) throws CompositeBuilderException { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java index 6fc946b29a..282fe032ba 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java @@ -20,6 +20,9 @@ package org.apache.tuscany.sca.assembly.builder.impl; import java.util.logging.Logger; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.TransformerFactory; + import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.DefaultEndpointFactory; @@ -62,16 +65,65 @@ public class CompositeBuilderImpl implements CompositeBuilder { * * @param assemblyFactory * @param scaBindingFactory + * @param endpointFactory + * @param intentAttachPointTypeFactory + * @param interfaceContractMapper + * @param policyDefinitions + * @param monitor + */ + @Deprecated + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + EndpointFactory endpointFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions, + Monitor monitor) { + this(assemblyFactory, endpointFactory, scaBindingFactory, intentAttachPointTypeFactory, + null, null, interfaceContractMapper, policyDefinitions, monitor); + } + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param scaBindingFactory + * @param endpointFactory + * @param intentAttachPointTypeFactory + * @param interfaceContractMapper + * @param policyDefinitions + * @param monitor + */ + @Deprecated + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + InterfaceContractMapper interfaceContractMapper, + Monitor monitor) { + this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, + null, null, interfaceContractMapper, null, monitor); + } + + /** + * Constructs a new composite builder. + * + * @param assemblyFactory + * @param scaBindingFactory * @param intentAttachPointTypeFactory + * @param documentBuilderFactory + * @param transformerFactory * @param interfaceContractMapper * @param monitor */ public CompositeBuilderImpl(AssemblyFactory assemblyFactory, SCABindingFactory scaBindingFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) { - this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, interfaceContractMapper, null, monitor); + this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, + documentBuilderFactory, transformerFactory, interfaceContractMapper, null, monitor); } /** @@ -89,6 +141,8 @@ public class CompositeBuilderImpl implements CompositeBuilder { EndpointFactory endpointFactory, SCABindingFactory scaBindingFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, InterfaceContractMapper interfaceContractMapper, SCADefinitions policyDefinitions, Monitor monitor) { @@ -102,10 +156,10 @@ public class CompositeBuilderImpl implements CompositeBuilder { componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, endpointFactory, monitor); compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory, monitor); compositeCloneBuilder = new CompositeCloneBuilderImpl(monitor); - componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); + componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper, policyDefinitions, monitor); compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory); compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(assemblyFactory); - compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, policyDefinitions, monitor); + compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper, policyDefinitions, monitor); componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory); compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory); compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java index 71971ef5a4..0105d4af50 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java @@ -59,10 +59,8 @@ import org.xml.sax.InputSource; * @version $Rev$ $Date$ */ abstract class PropertyConfigurationUtil { - private static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance(); - private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); - private static Document evaluate(Document node, XPathExpression expression) + private static Document evaluate(Document node, XPathExpression expression, DocumentBuilderFactory documentBuilderFactory) throws XPathExpressionException, ParserConfigurationException { Node value = node.getDocumentElement(); @@ -72,7 +70,7 @@ abstract class PropertyConfigurationUtil { } // TODO: How to wrap the result into a Document? - Document document = DOC_BUILDER_FACTORY.newDocumentBuilder().newDocument(); + Document document = documentBuilderFactory.newDocumentBuilder().newDocument(); if (result instanceof Document) { return (Document)result; } else { @@ -83,7 +81,7 @@ abstract class PropertyConfigurationUtil { } } - private static Document loadFromFile(String file) throws MalformedURLException, IOException, + private static Document loadFromFile(String file, TransformerFactory transformerFactory) throws MalformedURLException, IOException, TransformerException, ParserConfigurationException { URI uri = URI.create(file); // URI resolution for relative URIs is done when the composite is resolved. @@ -96,7 +94,7 @@ abstract class PropertyConfigurationUtil { Source streamSource = new SAXSource(new InputSource(is)); DOMResult result = new DOMResult(); - javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); + javax.xml.transform.Transformer transformer = transformerFactory.newTransformer(); transformer.transform(streamSource, result); Document document = (Document)result.getNode(); @@ -115,7 +113,9 @@ abstract class PropertyConfigurationUtil { } static void sourceComponentProperties(Map<String, Property> compositeProperties, - Component componentDefinition) throws CompositeBuilderException, + Component componentDefinition, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory) throws CompositeBuilderException, ParserConfigurationException, XPathExpressionException, TransformerException, @@ -143,7 +143,7 @@ abstract class PropertyConfigurationUtil { Document compositePropDefValues = (Document)compositeProp.getValue(); // FIXME: How to deal with namespaces? - Document node = evaluate(compositePropDefValues, aProperty.getSourceXPathExpression()); + Document node = evaluate(compositePropDefValues, aProperty.getSourceXPathExpression(), documentBuilderFactory); if (node != null) { aProperty.setValue(node); @@ -152,7 +152,7 @@ abstract class PropertyConfigurationUtil { throw new CompositeBuilderException("The 'source' has an invalid value: " + source); } } else if (file != null) { - aProperty.setValue(loadFromFile(aProperty.getFile())); + aProperty.setValue(loadFromFile(aProperty.getFile(), transformerFactory)); } } |