diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-21 18:00:07 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-21 18:00:07 +0000 |
commit | 11d80a409e2d7e65be7e46ca872d995d35964f83 (patch) | |
tree | ede8e38bd57fb796fd81362a4ac6744fccaf6d16 /java/sca/modules | |
parent | 685e0996023a229894a43185d3da8a8f0e148669 (diff) |
Set the monitor to ValidatingXMLStreamReader
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@828119 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
13 files changed, 85 insertions, 72 deletions
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java index fab5aadb51..b5fe005812 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java @@ -24,7 +24,6 @@ import java.io.InputStream; import java.net.URI; import java.net.URL; -import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; @@ -46,7 +45,7 @@ import org.apache.tuscany.sca.monitor.Monitor; * @version $Rev$ $Date$ */ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<ComponentType> { - private XMLInputFactory inputFactory; + private ValidatingXMLInputFactory inputFactory; /** * Constructs a new componentType processor. @@ -67,6 +66,7 @@ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implem // Create a stream reader urlStream = IOHelper.openStream(url); XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); + ValidatingXMLInputFactory.setMonitor(reader, monitor); reader.nextTag(); // Reader the componentType model diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java index 2969e257d6..f3f25f0b65 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java @@ -24,7 +24,6 @@ import java.io.InputStream; import java.net.URI; import java.net.URL; -import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; @@ -94,12 +93,11 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements monitor.setArtifactName(uri.toString()); } //end if + XMLStreamReader reader = inputFactory.createXMLStreamReader(scdlStream); // set the monitor on the input factory as the standard XMLInputFactory // methods used for creating readers don't allow for the context to // be passed in - inputFactory.setMonitor(context.getMonitor()); - - XMLStreamReader reader = inputFactory.createXMLStreamReader(scdlStream); + ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor()); reader.nextTag(); diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsDocumentProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsDocumentProcessor.java index a047377aed..d0a42be34e 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsDocumentProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsDocumentProcessor.java @@ -113,7 +113,7 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini //urlStream = createInputStream(url); XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); - + ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor()); Definitions definitions = definitionsFactory.createDefinitions(); int event = reader.getEventType(); while (reader.hasNext()) { diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java index 5e32051515..a886908589 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java @@ -47,6 +47,7 @@ import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.junit.BeforeClass; import org.junit.Test; import org.xml.sax.InputSource; @@ -129,7 +130,7 @@ public class ReadDocumentTestCase { ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString()); - XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null); + XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas); DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()); factories.addFactory(validatingInputFactory); @@ -155,10 +156,11 @@ public class ReadDocumentTestCase { @Test public void testReadBinding() throws Exception { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint(); schemas.addSchema(getClass().getClassLoader().getResource(TUSCANY_11_XSD).toString()); - XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null); - DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()); + XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas); + DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(registry); factories.addFactory(validatingInputFactory); CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(factories, staxProcessor); diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java index 1e48e241a4..42730415b3 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyElementTestCase.java @@ -24,7 +24,6 @@ import static org.junit.Assert.assertNotNull; import java.io.ByteArrayOutputStream; import java.io.StringReader; -import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamReader; @@ -74,7 +73,7 @@ public class ReadWriteAnyElementTestCase { "</composite>"; - private XMLInputFactory inputFactory; + private ValidatingXMLInputFactory inputFactory; private ExtensibleStAXArtifactProcessor staxProcessor; private ProcessorContext context; @@ -97,6 +96,7 @@ public class ReadWriteAnyElementTestCase { @Test public void testReadWriteExtendedRecursiveElement() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); + ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor()); Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); reader.close(); diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java index a6e7e8b6e3..c38061c1bf 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java @@ -61,8 +61,6 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; import org.w3c.dom.DOMImplementation; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSInput; @@ -82,7 +80,7 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory private DocumentBuilderFactory documentBuilderFactory; private DOMImplementationLS ls; private ValidationSchemaExtensionPoint schemas; - private Monitor monitor; + private MonitorFactory monitorFactory; private boolean initialized; private boolean hasSchemas; private Schema aggregatedSchema; @@ -93,6 +91,8 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory this.inputFactory = factoryExtensionPoint.getFactory(XMLInputFactory.class); this.documentBuilderFactory = factoryExtensionPoint.getFactory(DocumentBuilderFactory.class); this.schemas = registry.getExtensionPoint(ValidationSchemaExtensionPoint.class); + this.monitorFactory = + registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class); this.helper = StAXHelper.getInstance(registry); } @@ -102,16 +102,11 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory * @param inputFactory * @param schemas */ - public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas, Monitor monitor) { + public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas) { this.inputFactory = inputFactory; this.schemas = schemas; - this.monitor = monitor; } - @Override - public void setMonitor(Monitor monitor) { - this.monitor = monitor; - } /** * Report a exception. @@ -120,30 +115,12 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory * @param message * @param model */ - private void error(String message, Object model, Throwable ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "contribution-validation-messages", - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } + private void error(Monitor monitor, String message, Object model, Throwable ex) { + Monitor.error(monitor, this, "contribution-validation-messages", message, ex); } - private void warn(String message, Object model, Throwable ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "contribution-validation-messages", - Severity.WARNING, - model, - message, - ex); - monitor.problem(problem); - } + private void warn(Monitor monitor, String message, Object model, Throwable ex) { + Monitor.warning(monitor, this, "contribution-validation-messages", message, ex); } public static final QName XSD = new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "schema"); @@ -187,8 +164,9 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory /** * Initialize the registered schemas and create an aggregated schema for * validation. + * @param monitor TODO */ - private synchronized void initializeSchemas() { + private synchronized void initializeSchemas(Monitor monitor) { if (initialized) { return; } @@ -231,7 +209,7 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory } }); } catch (PrivilegedActionException e) { - warn("PrivilegedActionException", schemaFactory, (SAXException)e.getException()); + warn(monitor, "PrivilegedActionException", schemaFactory, (SAXException)e.getException()); hasSchemas = false; throw (SAXException)e.getException(); } @@ -242,7 +220,7 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory // throw ie; } catch (Throwable e) { //FIXME Log this, some old JDKs don't support XMLSchema validation - warn(e.getMessage(), schemas, e); + warn(monitor, e.getMessage(), schemas, e); hasSchemas = false; } } @@ -294,7 +272,8 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory @Override public XMLStreamReader createXMLStreamReader(InputStream arg0, String arg1) throws XMLStreamException { - initializeSchemas(); + Monitor monitor = monitorFactory.getContextMonitor(); + initializeSchemas(monitor); if (hasSchemas) { return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); }else { @@ -304,7 +283,8 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory @Override public XMLStreamReader createXMLStreamReader(InputStream arg0) throws XMLStreamException { - initializeSchemas(); + Monitor monitor = monitorFactory.getContextMonitor(); + initializeSchemas(monitor); if (hasSchemas) { return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); } else { @@ -314,7 +294,8 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory @Override public XMLStreamReader createXMLStreamReader(Reader arg0) throws XMLStreamException { - initializeSchemas(); + Monitor monitor = monitorFactory.getContextMonitor(); + initializeSchemas(monitor); if (hasSchemas) { return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); } else { @@ -324,7 +305,8 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory @Override public XMLStreamReader createXMLStreamReader(Source arg0) throws XMLStreamException { - initializeSchemas(); + Monitor monitor = monitorFactory.getContextMonitor(); + initializeSchemas(monitor); if (hasSchemas) { return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor); } else { @@ -334,7 +316,8 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory @Override public XMLStreamReader createXMLStreamReader(String arg0, InputStream arg1) throws XMLStreamException { - initializeSchemas(); + Monitor monitor = monitorFactory.getContextMonitor(); + initializeSchemas(monitor); if (hasSchemas) { return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); } else { @@ -344,7 +327,8 @@ public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory @Override public XMLStreamReader createXMLStreamReader(String arg0, Reader arg1) throws XMLStreamException { - initializeSchemas(); + Monitor monitor = monitorFactory.getContextMonitor(); + initializeSchemas(monitor); if (hasSchemas) { return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor); } else { diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java index 2446862e07..756cd9eb78 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.contribution.processor; import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.monitor.Monitor; @@ -35,7 +36,12 @@ public abstract class ValidatingXMLInputFactory extends XMLInputFactory { * into the create methods. The base definitions of the create methods * don't allow for this. * + * @param reader the XMLStreamReader instance * @param monitor the current monitor object */ - public abstract void setMonitor(Monitor monitor); + public static void setMonitor(XMLStreamReader reader, Monitor monitor) { + if (reader instanceof ValidatingXMLStreamReader) { + ((ValidatingXMLStreamReader)reader).setMonitor(monitor); + } + } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java index 5e88f08529..3f18830a59 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java @@ -51,7 +51,8 @@ class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStrea private static final Logger logger = Logger.getLogger(ValidatingXMLStreamReader.class.getName()); private ValidatorHandler handler; - private final Monitor monitor; + private Schema schema; + private Monitor monitor; /** * Constructs a new ValidatingXMLStreamReader. @@ -63,10 +64,16 @@ class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStrea ValidatingXMLStreamReader(XMLStreamReader reader, Schema schema, Monitor monitor) throws XMLStreamException { super(reader); this.monitor = monitor; - if (schema == null) { - return; + } + + void setMonitor(Monitor monitor) { + this.monitor = monitor; + } + + private synchronized ValidatorHandler getHandler() throws XMLStreamException { + if (schema == null || handler!=null) { + return handler; } - handler = schema.newValidatorHandler(); handler.setDocumentLocator(new LocatorAdapter()); try { @@ -117,6 +124,7 @@ class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStrea return artifactName; } }); + return handler; } /** @@ -149,7 +157,7 @@ class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStrea @Override public int next() throws XMLStreamException { - if (handler == null) { + if (getHandler() == null) { return super.next(); } @@ -197,7 +205,7 @@ class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStrea @Override public int nextTag() throws XMLStreamException { - if (handler == null) { + if (getHandler() == null) { return super.nextTag(); } while (true) { @@ -232,7 +240,7 @@ class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStrea @Override public String getElementText() throws XMLStreamException { - if (handler == null) { + if (getHandler() == null) { return super.getElementText(); } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java index 63521f8977..30220901a0 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java @@ -77,6 +77,8 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess // Create a stream reader urlStream = IOHelper.openStream(url); XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); + ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor()); + reader.nextTag(); // Read the contribution model diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java index 5e83833a05..ad175e009c 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java @@ -70,6 +70,7 @@ public class ServiceDescriptionsDocumentProcessor implements URLArtifactProcesso } try { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor()); Object result = extensionProcessor.read(reader, context); return (ServiceDescriptions)result; } catch (XMLStreamException e) { diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java index 779b92e27a..8a99fa4c7c 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/DefaultMonitorFactory.java @@ -46,11 +46,15 @@ public class DefaultMonitorFactory implements MonitorFactory { return monitor; } - public void removeContextMonitor() { + public Monitor removeContextMonitor() { + Monitor old = contextMonitor.get(); contextMonitor.remove(); + return old; } - public void setContextMonitor(Monitor value) { + public Monitor setContextMonitor(Monitor value) { + Monitor old = contextMonitor.get(); contextMonitor.set(value); + return old; } } diff --git a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java index 9309d4b293..12ac7eba7b 100644 --- a/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java +++ b/java/sca/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java @@ -48,12 +48,14 @@ public interface MonitorFactory { /** * Remove the monitor on the thread + * @return The existing instance */ - void removeContextMonitor(); + Monitor removeContextMonitor(); /** * Set the monitor onto the thread - * @param value + * @param value The new instance + * @return The old instance */ - void setContextMonitor(Monitor monitor); + Monitor setContextMonitor(Monitor monitor); } diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index 768d5a63d7..4de400db11 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -124,16 +124,22 @@ public class NodeImpl implements Node, Client { this.compositeActivator = utilities.getUtility(CompositeActivator.class); try { Monitor monitor = manager.monitorFactory.createMonitor(); - monitor.reset(); - ProcessorContext context = new ProcessorContext(monitor); - if (contributions == null) { - contributions = manager.loadContributions(configuration, context); + // Set up the thead context monitor + Monitor tcm = manager.monitorFactory.setContextMonitor(monitor); + try { + if (contributions == null) { + contributions = manager.loadContributions(configuration, context); + } + domainComposite = manager.configureNode(configuration, contributions, context); + + this.compositeContext = + new CompositeContextImpl(manager.extensionPoints, endpointRegistry, domainComposite); + } finally { + // Reset the thread context monitor + manager.monitorFactory.setContextMonitor(tcm); } - domainComposite = manager.configureNode(configuration, contributions, context); - - this.compositeContext = new CompositeContextImpl(manager.extensionPoints, endpointRegistry, domainComposite); // Activate the composite compositeActivator.activate(compositeContext, domainComposite); |