diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-16 05:42:26 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-10-16 05:42:26 +0000 |
commit | 4ae4002366ded3f4b19cd96f403d8b418fcf00a1 (patch) | |
tree | 9179891f11c9add734a777713cabf7e39a980908 /java/sca/modules/assembly-xml/src | |
parent | d4cc9a0bdd43477858b8ac67b69a4cdd615ec741 (diff) |
This is to change the Monitor to be request scoped for most of the cases:
Refactor the ArtifactProcessor/ModelResolver to take a ProcessorContext that holds context such as Monitor, Contribution for the contribution/artifact processing methods
Refactor the Builder to take a BuilderContext that holds context such as Monitor, Definitions, Base binding mapping for the building methods
Change the processor/resolver/builder implementation classes to not cache the Monitor
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@825773 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/assembly-xml/src')
42 files changed, 578 insertions, 552 deletions
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java index e8c555b3c4..fea61f1ea0 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java @@ -77,6 +77,7 @@ import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -106,7 +107,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { protected StAXArtifactProcessor<Object> extensionProcessor; protected PolicySubjectProcessor policyProcessor; private DocumentBuilderFactory documentBuilderFactory; - protected Monitor monitor; + /** * Constructs a new BaseArtifactProcessor. @@ -117,14 +118,12 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { protected BaseAssemblyProcessor(AssemblyFactory assemblyFactory, PolicyFactory policyFactory, DocumentBuilderFactory documentBuilderFactory, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { + StAXArtifactProcessor extensionProcessor) { this.assemblyFactory = assemblyFactory; this.policyFactory = policyFactory; this.documentBuilderFactory = documentBuilderFactory; this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; this.policyProcessor = new PolicySubjectProcessor(policyFactory); - this.monitor = monitor; } /** @@ -133,14 +132,12 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * @param monitor */ protected BaseAssemblyProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { + StAXArtifactProcessor staxProcessor) { this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor; this.policyProcessor = new PolicySubjectProcessor(policyFactory); - this.monitor = monitor; } /** @@ -150,7 +147,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * @param model * @param messageParameters */ - protected void warning(String message, Object model, Object... messageParameters) { + protected void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -170,7 +167,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * @param message * @param model */ - protected void error(String message, Object model, Object... messageParameters) { + protected void error(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -190,7 +187,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * @param message * @param model */ - protected void error(String message, Object model, Exception ex) { + protected void error(Monitor monitor, String message, Object model, Exception ex) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -312,10 +309,11 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * Reads an abstract property element. * @param property * @param reader + * @param context TODO * @throws XMLStreamException * @throws ContributionReadException */ - protected void readAbstractProperty(AbstractProperty property, XMLStreamReader reader) throws XMLStreamException, + protected void readAbstractProperty(AbstractProperty property, XMLStreamReader reader, ProcessorContext context) throws XMLStreamException, ContributionReadException { property.setName(getString(reader, NAME)); @@ -327,7 +325,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { if( property.getXSDElement() != null && property.getXSDType() != null ) { ContributionReadException ce = new ContributionReadException("Error: property has both @type and @element attribute values - " + property.getName()); - error("ContributionReadException", property, ce); + error(context.getMonitor(), "ContributionReadException", property, ce); } // end if } @@ -336,20 +334,21 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * Resolve an implementation. * @param implementation * @param resolver + * @param context * @return * @throws ContributionResolveException */ - protected Implementation resolveImplementation(Implementation implementation, ModelResolver resolver) + protected Implementation resolveImplementation(Implementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (implementation != null) { if (implementation.isUnresolved()) { - implementation = resolver.resolveModel(Implementation.class, implementation); + implementation = resolver.resolveModel(Implementation.class, implementation, context); // Lazily resolve implementations if (implementation.isUnresolved()) { - extensionProcessor.resolve(implementation, resolver); + extensionProcessor.resolve(implementation, resolver, context); if (!implementation.isUnresolved()) { - resolver.addModel(implementation); + resolver.addModel(implementation, context); } } } @@ -361,10 +360,11 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * Resolve interface, callback interface and bindings on a list of contracts. * @param contracts the list of contracts * @param resolver the resolver to use to resolve models + * @param context TODO */ - protected <C extends Contract> void resolveContracts(List<C> contracts, ModelResolver resolver) + protected <C extends Contract> void resolveContracts(List<C> contracts, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - resolveContracts(null, contracts, resolver); + resolveContracts(null, contracts, resolver, context); } /** @@ -372,8 +372,9 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * @param parent element for the contracts * @param contracts the list of contracts * @param resolver the resolver to use to resolve models + * @param context TODO */ - protected <C extends Contract> void resolveContracts(Base parent, List<C> contracts, ModelResolver resolver) + protected <C extends Contract> void resolveContracts(Base parent, List<C> contracts, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { String parentName = @@ -384,13 +385,13 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { // Resolve the interface contract InterfaceContract interfaceContract = contract.getInterfaceContract(); if (interfaceContract != null) { - extensionProcessor.resolve(interfaceContract, resolver); + extensionProcessor.resolve(interfaceContract, resolver, context); } // Resolve bindings for (int i = 0, n = contract.getBindings().size(); i < n; i++) { Binding binding = contract.getBindings().get(i); - extensionProcessor.resolve(binding, resolver); + extensionProcessor.resolve(binding, resolver, context); } @@ -399,7 +400,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { for (int i = 0, n = contract.getCallback().getBindings().size(); i < n; i++) { Binding binding = contract.getCallback().getBindings().get(i); - extensionProcessor.resolve(binding, resolver); + extensionProcessor.resolve(binding, resolver, context); } } } @@ -409,15 +410,16 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * Resolve interface and callback interface on a list of abstract contracts. * @param contracts the list of contracts * @param resolver the resolver to use to resolve models + * @param context TODO */ - protected <C extends AbstractContract> void resolveAbstractContracts(List<C> contracts, ModelResolver resolver) + protected <C extends AbstractContract> void resolveAbstractContracts(List<C> contracts, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { for (AbstractContract contract : contracts) { // Resolve the interface contract InterfaceContract interfaceContract = contract.getInterfaceContract(); if (interfaceContract != null) { - extensionProcessor.resolve(interfaceContract, resolver); + extensionProcessor.resolve(interfaceContract, resolver, context); } } } @@ -509,12 +511,13 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * @param element * @param type * @param reader + * @param context TODO * @return * @throws XMLStreamException * @throws ContributionReadException * @throws ParserConfigurationException */ - protected Document readPropertyValue(QName element, QName type, boolean isMany, XMLStreamReader reader) throws XMLStreamException, + protected Document readPropertyValue(QName element, QName type, boolean isMany, XMLStreamReader reader, ProcessorContext context) throws XMLStreamException, ContributionReadException { Document document; try { @@ -525,7 +528,7 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { document = documentBuilderFactory.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", documentBuilderFactory, ce); + error(context.getMonitor(), "ContributionReadException", documentBuilderFactory, ce); throw ce; } @@ -584,13 +587,13 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { // A property <value/> subelement MUST NOT be used when the @value attribute is used // to specify the value for that property. if (valueAttr != null) { - error("ASM50033: value attribute exists for the property element", name, name); + error(context.getMonitor(), "ASM50033: value attribute exists for the property element", name, name); } // Read <value> if (VALUE_QNAME.equals(name)) { if (gotOneValue && !isMany) { // TODO: TUSCANY-3231 this should be error not warning but that breaks OASIS tests - warning("ASM50032: multiple value elements for single-valued property", name, name); + warning(context.getMonitor(), "ASM50032: multiple value elements for single-valued property", name, name); } loadElement(reader, root); gotOneValue = true; @@ -845,17 +848,19 @@ abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { * * @param reader * @param elementName - * @param estensibleElement * @param extensionAttributeProcessor + * @param context TODO + * @param estensibleElement * @throws ContributionReadException * @throws XMLStreamException */ protected void readExtendedAttributes(XMLStreamReader reader, QName elementName, Extensible extensible, - StAXAttributeProcessor extensionAttributeProcessor) - throws ContributionReadException, XMLStreamException { - super.readExtendedAttributes(reader, extensible, extensionAttributeProcessor, assemblyFactory); + StAXAttributeProcessor extensionAttributeProcessor, + ProcessorContext context) throws ContributionReadException, + XMLStreamException { + super.readExtendedAttributes(reader, extensible, extensionAttributeProcessor, assemblyFactory, context); } 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 672476a834..fab5aadb51 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 @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; @@ -53,14 +54,14 @@ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implem * @param staxProcessor */ public ComponentTypeDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { - super(modelFactories, staxProcessor, monitor); + StAXArtifactProcessor staxProcessor) { + super(modelFactories, staxProcessor); this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); } - public ComponentType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + public ComponentType read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { InputStream urlStream = null; + Monitor monitor = context.getMonitor(); try { // Create a stream reader @@ -69,7 +70,7 @@ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implem reader.nextTag(); // Reader the componentType model - ComponentType componentType = (ComponentType)extensionProcessor.read(reader); + ComponentType componentType = (ComponentType)extensionProcessor.read(reader, context); if (componentType != null) { componentType.setURI(uri.toString()); } @@ -96,11 +97,11 @@ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implem } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error(monitor, "ContributionReadException", inputFactory, ce); throw ce; } catch (IOException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error(monitor, "ContributionReadException", inputFactory, ce); throw ce; } finally { try { @@ -114,8 +115,8 @@ public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implem } } - public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException { - extensionProcessor.resolve(componentType, resolver); + public void resolve(ComponentType componentType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + extensionProcessor.resolve(componentType, resolver, context); } public String getArtifactType() { diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java index c2ba7d10e6..9a4a0dc035 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java @@ -26,9 +26,9 @@ import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * A Model Resolver for ComponentType models. @@ -36,23 +36,23 @@ import org.apache.tuscany.sca.monitor.Monitor; * @version $Rev$ $Date$ */ public class ComponentTypeModelResolver implements ModelResolver { - private Contribution contribution; + private Contribution contribution; private Map<String, ComponentType> map = new HashMap<String, ComponentType>(); - public ComponentTypeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public ComponentTypeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.contribution = contribution; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { ComponentType componentType = (ComponentType)resolved; map.put(componentType.getURI(), componentType); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(((ComponentType)resolved).getURI()); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { //get componentType artifact URI String uri = ((ComponentType)unresolved).getURI(); @@ -80,7 +80,7 @@ public class ComponentTypeModelResolver implements ModelResolver { //check the import location against the computed package name from the componentType URI if (javaImport.getPackage().equals(packageName)) { // Delegate the resolution to the import resolver - resolved = javaImport.getModelResolver().resolveModel(ComponentType.class, (ComponentType)unresolved); + resolved = javaImport.getModelResolver().resolveModel(ComponentType.class, (ComponentType)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java index aee2d89b7c..404574ca02 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java @@ -55,6 +55,7 @@ import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -62,7 +63,6 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.PolicySubject; import org.w3c.dom.Document; @@ -83,12 +83,11 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA */ public ComponentTypeProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor, - Monitor monitor) { - super(modelFactories, extensionProcessor, monitor); + StAXAttributeProcessor extensionAttributeProcessor) { + super(modelFactories, extensionProcessor); } - public ComponentType read(XMLStreamReader reader) throws ContributionReadException { + public ComponentType read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { ComponentType componentType = null; Service service = null; Reference reference = null; @@ -136,11 +135,11 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA // Read a <property> property = assemblyFactory.createProperty(); - readAbstractProperty(property, reader); + readAbstractProperty(property, reader, context); policyProcessor.readPolicies(property, reader); // Read the property value - Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), property.isMany(), reader); + Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), property.isMany(), reader, context); property.setValue(value); componentType.getProperties().add(property); @@ -171,7 +170,7 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA } else { // Read an extension element - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null) { if (extension instanceof InterfaceContract) { @@ -231,13 +230,13 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(context.getMonitor(), "XMLStreamException", reader, ex); } return componentType; } - public void write(ComponentType componentType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(ComponentType componentType, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <componentType> element writeStartDocument(writer, COMPONENT_TYPE, @@ -249,11 +248,11 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA policyProcessor.writePolicies(service)); if (service.getInterfaceContract() != null) { - extensionProcessor.write(service.getInterfaceContract(), writer); + extensionProcessor.write(service.getInterfaceContract(), writer, context); } for (Binding binding: service.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } if (service.getCallback() != null) { @@ -261,17 +260,17 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); for (Binding binding: callback.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } for (Object extension: callback.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); } for (Object extension: service.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -286,10 +285,10 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA writeTargets(reference), policyProcessor.writePolicies(reference)); - extensionProcessor.write(reference.getInterfaceContract(), writer); + extensionProcessor.write(reference.getInterfaceContract(), writer, context); for (Binding binding: reference.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } if (reference.getCallback() != null) { @@ -298,17 +297,17 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA policyProcessor.writePolicies(callback)); for (Binding binding: callback.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } for (Object extension: callback.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); } for (Object extension: reference.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -330,7 +329,7 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA // Write extensions for (Object extension : property.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -339,7 +338,7 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA // Write extension elements if (componentType instanceof Extensible) { for (Object extension: ((Extensible)componentType).getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } } @@ -364,11 +363,11 @@ public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StA writeEndDocument(writer); } - public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ComponentType componentType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Resolve component type services and references - resolveContracts(componentType.getServices(), resolver); - resolveContracts(componentType.getReferences(), resolver); + resolveContracts(componentType.getServices(), resolver, context); + resolveContracts(componentType.getReferences(), resolver, context); } public QName getArtifactType() { 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 c9b029a7ba..8a28efb461 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 @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; @@ -46,7 +47,7 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<Composite> { private XMLInputFactory inputFactory; - private Monitor monitor; + /** * Constructs a composite document processor @@ -55,11 +56,9 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements * @param monitor */ public CompositeDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<?> staxProcessor, - Monitor monitor) { - super(modelFactories, staxProcessor, monitor); + StAXArtifactProcessor<?> staxProcessor) { + super(modelFactories, staxProcessor); this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); - this.monitor = monitor; } /** @@ -69,7 +68,7 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements * @param url - the URL of the composite document * @return a Composite object built from the supplied Composite document */ - public Composite read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + public Composite read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { if( uri == null || url == null ) { throw new ContributionReadException("Request to read composite with uri or url NULL"); } // end if @@ -79,17 +78,17 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements scdlStream = IOHelper.openStream(url);; } catch (IOException e) { ContributionReadException ce = new ContributionReadException("Exception reading " + uri, e); - error("ContributionReadException", url, ce); + error(context.getMonitor(), "ContributionReadException", url, ce); throw ce; } - return read(uri, scdlStream); + return read(uri, scdlStream, context); } - public Composite read(URI uri, InputStream scdlStream) throws ContributionReadException { + public Composite read(URI uri, InputStream scdlStream, ProcessorContext context) throws ContributionReadException { try { Composite composite = null; - + Monitor monitor = context.getMonitor(); // Tag the monitor with the name of the composite artifact if( monitor != null ) { monitor.setArtifactName(uri.toString()); @@ -100,7 +99,7 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements reader.nextTag(); // Read the composite model - composite = (Composite)extensionProcessor.read(reader); + composite = (Composite)extensionProcessor.read(reader, context); if (composite != null) { composite.setURI(uri.toString()); } @@ -109,7 +108,7 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException("Exception reading " + uri, e); - error("ContributionReadException", inputFactory, ce); + error(context.getMonitor(), "ContributionReadException", inputFactory, ce); throw ce; } finally { try { @@ -123,10 +122,10 @@ public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements } } - public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Composite composite, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { try { if (composite != null) - extensionProcessor.resolve(composite, resolver); + extensionProcessor.resolve(composite, resolver, context); } catch (Throwable e ) { // Add information about which composite was being processed when the exception occurred String newMessage = "Processing composite " + composite.getName() + ": " + e.getMessage(); diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java index e9a617b3b6..cd2aa364bd 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java @@ -28,6 +28,7 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.monitor.Monitor; @@ -43,12 +44,11 @@ public class CompositeModelResolver implements ModelResolver { private Map<QName, Composite> map = new HashMap<QName, Composite>(); private Monitor monitor; - public CompositeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public CompositeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.contribution = contribution; - this.monitor = monitor; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { Composite composite = (Composite)resolved; Composite old = map.put(composite.getName(), composite); if (old != null) { @@ -61,11 +61,11 @@ public class CompositeModelResolver implements ModelResolver { } } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(((Composite)resolved).getName()); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { // Lookup a definition for the given namespace QName qname = ((Composite)unresolved).getName(); @@ -81,7 +81,7 @@ public class CompositeModelResolver implements ModelResolver { if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) { // Delegate the resolution to the import resolver - resolved = namespaceImport.getModelResolver().resolveModel(Composite.class, (Composite)unresolved); + resolved = namespaceImport.getModelResolver().resolveModel(Composite.class, (Composite)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java index ef039818cc..ddcf2d4463 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -90,6 +90,7 @@ import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -124,10 +125,9 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt */ public CompositeProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor, - Monitor monitor) { + StAXAttributeProcessor extensionAttributeProcessor) { - this(modelFactories(extensionPoints), extensionProcessor, extensionAttributeProcessor, monitor(extensionPoints)); + this(modelFactories(extensionPoints), extensionProcessor, extensionAttributeProcessor); this.xpathHelper = XPathHelper.getInstance(extensionPoints); this.extensionAttributeProcessor = extensionAttributeProcessor; @@ -142,17 +142,16 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt */ private CompositeProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor, - Monitor monitor) { + StAXAttributeProcessor extensionAttributeProcessor) { - super(modelFactories, extensionProcessor, monitor); + super(modelFactories, extensionProcessor); this.intentAttachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class); this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); this.extensionAttributeProcessor = extensionAttributeProcessor; } - public Composite read(XMLStreamReader reader) throws ContributionReadException { + public Composite read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { Composite composite = null; Composite include = null; Component component = null; @@ -166,7 +165,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt Wire wire = null; Callback callback = null; QName name = null; - + Monitor monitor = context.getMonitor(); try { // Read the composite document while (reader.hasNext()) { @@ -185,7 +184,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt if (!isSet(reader, TARGET_NAMESPACE)) { // spec says that a composite must have a namespace - warning("NoCompositeNamespace", composite, composite.getName().toString()); + warning(monitor, "NoCompositeNamespace", composite, composite.getName().toString()); } if (isSet(reader, AUTOWIRE)) { @@ -193,7 +192,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt } //handle extension attributes - this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor); + this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor, context); composite.setLocal(getBoolean(reader, LOCAL)); composite.setConstrainingType(readConstrainingType(reader)); @@ -218,7 +217,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt //handle extension attributes this - .readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor); + .readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor, context); component.getServices().add(componentService); policyProcessor.readPolicies(contract, reader); @@ -255,7 +254,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt //handle extension attributes this - .readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor); + .readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor, context); composite.getServices().add(compositeService); policyProcessor.readPolicies(contract, reader); @@ -283,7 +282,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt this.readExtendedAttributes(reader, name, componentReference, - extensionAttributeProcessor); + extensionAttributeProcessor, context); component.getReferences().add(componentReference); policyProcessor.readPolicies(contract, reader); @@ -301,7 +300,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt Component promotedComponent = assemblyFactory.createComponent(); int index = refName.indexOf('/'); if (index == -1) { - error("Invalid reference name", compositeReference, refName); + error(monitor, "Invalid reference name", compositeReference, refName); } String promotedComponentName = refName.substring(0, index); promotedComponent.setName(promotedComponentName); @@ -320,7 +319,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt this.readExtendedAttributes(reader, name, compositeReference, - extensionAttributeProcessor); + extensionAttributeProcessor, context); composite.getReferences().add(compositeReference); policyProcessor.readPolicies(contract, reader); @@ -357,7 +356,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt .getNamespaceContext(), source)); } catch (XPathExpressionException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", source, ce); + error(monitor, "ContributionReadException", source, ce); //throw ce; } } @@ -367,15 +366,15 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt this.readExtendedAttributes(reader, name, componentProperty, - extensionAttributeProcessor); + extensionAttributeProcessor, context); policyProcessor.readPolicies(property, reader); - readAbstractProperty(componentProperty, reader); + readAbstractProperty(componentProperty, reader, context); // Read the property value Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), property - .isMany(), reader); + .isMany(), reader, context); property.setValue(value); component.getProperties().add(componentProperty); @@ -384,12 +383,12 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt // Read a <composite><property> property = assemblyFactory.createProperty(); policyProcessor.readPolicies(property, reader); - readAbstractProperty(property, reader); + readAbstractProperty(property, reader, context); // Read the property value Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), property - .isMany(), reader); + .isMany(), reader, context); property.setValue(value); composite.getProperties().add(property); @@ -415,7 +414,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt } //handle extension attributes - this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor); + this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor, context); component.setConstrainingType(readConstrainingType(reader)); composite.getComponents().add(component); @@ -442,7 +441,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt } //handle extension attributes - this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor); + this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor, context); composite.getWires().add(wire); policyProcessor.readPolicies(wire, reader); @@ -454,7 +453,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt contract.setCallback(callback); //handle extension attributes - this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor); + this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor, context); policyProcessor.readPolicies(callback, reader); @@ -466,14 +465,14 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt implementation.setUnresolved(true); //handle extension attributes - this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor); + this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor, context); component.setImplementation(implementation); policyProcessor.readPolicies(implementation, reader); } else { // Read an extension element - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null) { if (extension instanceof InterfaceContract) { @@ -483,7 +482,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt contract.setInterfaceContract((InterfaceContract)extension); } else { if (name.getNamespaceURI().equals(SCA11_NS)) { - error("UnexpectedInterfaceElement", extension); + error(monitor, "UnexpectedInterfaceElement", extension); //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element"); } else { composite.getExtensions().add(extension); @@ -505,7 +504,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt contract.getBindings().add((Binding)extension); } else { if (name.getNamespaceURI().equals(SCA11_NS)) { - error("UnexpectedBindingElement", extension); + error(monitor, "UnexpectedBindingElement", extension); //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element"); } else { composite.getExtensions().add(extension); @@ -526,7 +525,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt component.setImplementation((Implementation)extension); } else { if (name.getNamespaceURI().equals(SCA11_NS)) { - error("UnexpectedImplementationElement", extension); + error(monitor, "UnexpectedImplementationElement", extension); //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element"); } else { composite.getExtensions().add(extension); @@ -589,13 +588,13 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt } } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(monitor, "XMLStreamException", reader, ex); } return composite; } - public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException, + public void write(Composite composite, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <composite> element @@ -609,7 +608,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt policyProcessor.writePolicies(composite)); //write extended attributes - this.writeExtendedAttributes(writer, composite, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, composite, extensionAttributeProcessor, context); // Write <include> elements for (Composite include : composite.getIncludes()) { @@ -617,7 +616,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt writeStart(writer, INCLUDE, new XAttr(NAME, include.getName()), new XAttr(URI, uri)); //write extended attributes - this.writeExtendedAttributes(writer, include, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, include, extensionAttributeProcessor, context); writeEnd(writer); } @@ -644,14 +643,14 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt policyProcessor.writePolicies(service)); //write extended attributes - this.writeExtendedAttributes(writer, service, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, service, extensionAttributeProcessor, context); // Write service interface - extensionProcessor.write(service.getInterfaceContract(), writer); + extensionProcessor.write(service.getInterfaceContract(), writer, context); // Write bindings for (Binding binding : service.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write <callback> element @@ -660,16 +659,16 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); // Write callback bindings for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write extensions for (Object extension : callback.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -677,7 +676,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt // Write extensions for (Object extension : service.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -693,7 +692,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt policyProcessor.writePolicies(component)); //write extended attributes - this.writeExtendedAttributes(writer, component, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, component, extensionAttributeProcessor, context); // Write the component implementation Implementation implementation = component.getImplementation(); @@ -701,15 +700,15 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName())); //write extended attributes - this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor, context); writeEnd(writer); } else { - extensionProcessor.write(component.getImplementation(), writer); + extensionProcessor.write(component.getImplementation(), writer, context); } for (Object extension : component.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } // Write <service> elements @@ -717,14 +716,14 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), policyProcessor.writePolicies(service)); //write extended attributes - this.writeExtendedAttributes(writer, service, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, service, extensionAttributeProcessor, context); // Write service interface - extensionProcessor.write(service.getInterfaceContract(), writer); + extensionProcessor.write(service.getInterfaceContract(), writer, context); // Write bindings for (Binding binding : service.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write <callback> element @@ -733,16 +732,16 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); // Write bindings for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write extensions for (Object extension : callback.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -750,7 +749,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt // Write extensions for (Object extension : service.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -768,14 +767,14 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt policyProcessor.writePolicies(reference)); //write extended attributes - this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor, context); // Write reference interface - extensionProcessor.write(reference.getInterfaceContract(), writer); + extensionProcessor.write(reference.getInterfaceContract(), writer, context); // Write bindings for (Binding binding : reference.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write callback @@ -784,16 +783,16 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); // Write callback bindings for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write extensions for (Object extensions : callback.getExtensions()) { - extensionProcessor.write(extensions, writer); + extensionProcessor.write(extensions, writer, context); } writeEnd(writer); @@ -801,7 +800,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt // Write extensions for (Object extensions : reference.getExtensions()) { - extensionProcessor.write(extensions, writer); + extensionProcessor.write(extensions, writer, context); } writeEnd(writer); @@ -821,14 +820,14 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt policyProcessor.writePolicies(property)); //write extended attributes - this.writeExtendedAttributes(writer, property, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, property, extensionAttributeProcessor, context); // Write property value writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); // Write extensions for (Object extension : property.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -856,14 +855,14 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt policyProcessor.writePolicies(reference)); //write extended attributes - this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor, context); // Write reference interface - extensionProcessor.write(reference.getInterfaceContract(), writer); + extensionProcessor.write(reference.getInterfaceContract(), writer, context); // Write bindings for (Binding binding : reference.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write <callback> element @@ -872,16 +871,16 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt writeStart(writer, CALLBACK); //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); // Write callback bindings for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer); + extensionProcessor.write(binding, writer, context); } // Write extensions for (Object extension : callback.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -889,7 +888,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt // Write extensions for (Object extension : reference.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -907,14 +906,14 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt policyProcessor.writePolicies(property)); //write extended attributes - this.writeExtendedAttributes(writer, property, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, property, extensionAttributeProcessor, context); // Write property value writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); // Write extensions for (Object extension : property.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -926,31 +925,32 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt .getName()), wire.isReplace() ? new XAttr(Constants.REPLACE, true) : null); //write extended attributes - this.writeExtendedAttributes(writer, wire, extensionAttributeProcessor); + this.writeExtendedAttributes(writer, wire, extensionAttributeProcessor, context); // Write extensions for (Object extension : wire.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); } for (Object extension : composite.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEndDocument(writer); } - public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Composite composite, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); try { - this.monitor.pushContext("Composite: " + composite.getName()); + monitor.pushContext("Composite: " + composite.getName()); // Resolve constraining type ConstrainingType constrainingType = composite.getConstrainingType(); if (constrainingType != null) { - constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); + constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType, context); composite.setConstrainingType(constrainingType); } @@ -958,7 +958,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt for (int i = 0, n = composite.getIncludes().size(); i < n; i++) { Composite include = composite.getIncludes().get(i); if (include != null) { - Composite resolved = resolver.resolveModel(Composite.class, include); + Composite resolved = resolver.resolveModel(Composite.class, include, context); if (!resolved.isUnresolved()) { if ((composite.isLocal() && resolved.isLocal()) || (!composite.isLocal() && !resolved.isLocal())) { composite.getIncludes().set(i, resolved); @@ -966,13 +966,13 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt ContributionResolveException ce = new ContributionResolveException("Error: Composite " + composite.getName() + " can only include another composite with the identical @local attribute value"); - error("ContributionResolveException", include, ce); + error(monitor, "ContributionResolveException", include, ce); } } else { ContributionResolveException ce = new ContributionResolveException("Error: Composite " + include.getName() + " is not a valid composite within the domain"); - error("ContributionResolveException", include, ce); + error(monitor, "ContributionResolveException", include, ce); } } } @@ -980,31 +980,31 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt // Resolve extensions for (Object extension : composite.getExtensions()) { if (extension != null) { - extensionProcessor.resolve(extension, resolver); + extensionProcessor.resolve(extension, resolver, context); } } //Resolve composite services and references - resolveContracts(composite, composite.getServices(), resolver); - resolveContracts(composite, composite.getReferences(), resolver); + resolveContracts(composite, composite.getServices(), resolver, context); + resolveContracts(composite, composite.getReferences(), resolver, context); // Resolve component implementations, services and references for (Component component : composite.getComponents()) { constrainingType = component.getConstrainingType(); if (constrainingType != null) { - constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); + constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType, context); component.setConstrainingType(constrainingType); } //resolve component services and references - resolveContracts(component, component.getServices(), resolver); - resolveContracts(component, component.getReferences(), resolver); + resolveContracts(component, component.getServices(), resolver, context); + resolveContracts(component, component.getReferences(), resolver, context); for (ComponentProperty componentProperty : component.getProperties()) { if (componentProperty.getFile() != null) { Artifact artifact = contributionFactory.createArtifact(); artifact.setURI(componentProperty.getFile()); - artifact = resolver.resolveModel(Artifact.class, artifact); + artifact = resolver.resolveModel(Artifact.class, artifact, context); if (artifact.getLocation() != null) { componentProperty.setFile(artifact.getLocation()); } @@ -1017,7 +1017,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt //now resolve the implementation so that even if there is a shared instance //for this that is resolved, the specified intents and policysets are safe in the //component and not lost - implementation = resolveImplementation(implementation, resolver); + implementation = resolveImplementation(implementation, resolver, context); component.setImplementation(implementation); } @@ -1039,7 +1039,7 @@ public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArt } finally { // Pop context - this.monitor.popContext(); + monitor.popContext(); } // end try } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java index a738a69cd9..bcba763c1c 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java @@ -31,10 +31,10 @@ import org.apache.tuscany.sca.assembly.ConfiguredOperation; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.PolicyFactory; /** @@ -47,16 +47,15 @@ public class ConfiguredOperationProcessor implements StAXArtifactProcessor<Confi private AssemblyFactory assemblyFactory; private PolicySubjectProcessor policyProcessor; private PolicyFactory policyFactory; - private Monitor monitor; + - public ConfiguredOperationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public ConfiguredOperationProcessor(FactoryExtensionPoint modelFactories) { this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.policyProcessor = new PolicySubjectProcessor(policyFactory); - this.monitor = monitor; } - public ConfiguredOperation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public ConfiguredOperation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { ConfiguredOperation configuredOp = assemblyFactory.createConfiguredOperation(); //Read an <operation> @@ -77,7 +76,7 @@ public class ConfiguredOperationProcessor implements StAXArtifactProcessor<Confi return configuredOp; } - public void write(ConfiguredOperation configuredOperation, XMLStreamWriter writer) + public void write(ConfiguredOperation configuredOperation, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <operation> @@ -91,7 +90,7 @@ public class ConfiguredOperationProcessor implements StAXArtifactProcessor<Confi writer.writeEndElement(); } - public void resolve(ConfiguredOperation configuredOperation, ModelResolver resolver) + public void resolve(ConfiguredOperation configuredOperation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java index 135fad43e7..a1543401f1 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java @@ -32,12 +32,12 @@ import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * A contrainingType content handler. @@ -53,13 +53,12 @@ public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor imp * @param staxProcessor */ public ConstrainingTypeDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { - super(modelFactories, staxProcessor, monitor); + StAXArtifactProcessor staxProcessor) { + super(modelFactories, staxProcessor); this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); } - public ConstrainingType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + public ConstrainingType read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { InputStream urlStream = null; try { @@ -69,17 +68,17 @@ public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor imp reader.nextTag(); // Read the constrainingType model - ConstrainingType constrainingType = (ConstrainingType)extensionProcessor.read(reader); + ConstrainingType constrainingType = (ConstrainingType)extensionProcessor.read(reader, context); return constrainingType; } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error(context.getMonitor(), "ContributionReadException", inputFactory, ce); throw ce; } catch (IOException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error(context.getMonitor(), "ContributionReadException", inputFactory, ce); throw ce; } finally { try { @@ -93,8 +92,8 @@ public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor imp } } - public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException { - extensionProcessor.resolve(constrainingType, resolver); + public void resolve(ConstrainingType constrainingType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + extensionProcessor.resolve(constrainingType, resolver, context); } public String getArtifactType() { diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java index 3fe6553cae..413a90766c 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java @@ -28,9 +28,9 @@ import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * A Model Resolver for ConstrainingType models. @@ -42,20 +42,20 @@ public class ConstrainingTypeModelResolver implements ModelResolver { private Contribution contribution; private Map<QName, ConstrainingType> map = new HashMap<QName, ConstrainingType>(); - public ConstrainingTypeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public ConstrainingTypeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.contribution = contribution; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { ConstrainingType composite = (ConstrainingType)resolved; map.put(composite.getName(), composite); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(((ConstrainingType)resolved).getName()); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { // Lookup a definition for the given namespace QName qname = ((ConstrainingType)unresolved).getName(); @@ -71,7 +71,7 @@ public class ConstrainingTypeModelResolver implements ModelResolver { if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) { // Delegate the resolution to the import resolver - resolved = namespaceImport.getModelResolver().resolveModel(ConstrainingType.class, (ConstrainingType)unresolved); + resolved = namespaceImport.getModelResolver().resolveModel(ConstrainingType.class, (ConstrainingType)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java index bf53be5dfa..e3e3409b55 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java @@ -50,13 +50,13 @@ import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; -import org.apache.tuscany.sca.monitor.Monitor; import org.w3c.dom.Document; /** @@ -73,12 +73,11 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements * @param extensionProcessor */ public ConstrainingTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { - super(modelFactories, extensionProcessor, monitor); + StAXArtifactProcessor extensionProcessor) { + super(modelFactories, extensionProcessor); } - public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException { + public ConstrainingType read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { ConstrainingType constrainingType = null; AbstractService abstractService = null; AbstractReference abstractReference = null; @@ -124,10 +123,10 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements // Read a <property> abstractProperty = assemblyFactory.createAbstractProperty(); - readAbstractProperty(abstractProperty, reader); + readAbstractProperty(abstractProperty, reader, context); // Read the property value - Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), abstractProperty.isMany(), reader); + Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), abstractProperty.isMany(), reader, context); abstractProperty.setValue(value); constrainingType.getProperties().add(abstractProperty); @@ -144,7 +143,7 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements } else { // Read an extension element - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension instanceof InterfaceContract) { // <service><interface> and <reference><interface> @@ -184,13 +183,13 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(context.getMonitor(), "XMLStreamException", reader, ex); } return constrainingType; } - public void write(ConstrainingType constrainingType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(ConstrainingType constrainingType, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <constrainingType> element writeStartDocument(writer, CONSTRAINING_TYPE, @@ -203,10 +202,10 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), policyProcessor.writePolicies(service)); - extensionProcessor.write(service.getInterfaceContract(), writer); + extensionProcessor.write(service.getInterfaceContract(), writer, context); for (Object extension: service.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -218,10 +217,10 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements writeMultiplicity(reference), policyProcessor.writePolicies(reference)); - extensionProcessor.write(reference.getInterfaceContract(), writer); + extensionProcessor.write(reference.getInterfaceContract(), writer, context); for (Object extension: reference.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -243,7 +242,7 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements // Write extensions for (Object extension : abstractProperty.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEnd(writer); @@ -251,16 +250,16 @@ public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements // Write extension elements for (Object extension: constrainingType.getExtensions()) { - extensionProcessor.write(extension, writer); + extensionProcessor.write(extension, writer, context); } writeEndDocument(writer); } - public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ConstrainingType constrainingType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Resolve component type services and references - resolveAbstractContracts(constrainingType.getServices(), resolver); - resolveAbstractContracts(constrainingType.getReferences(), resolver); + resolveAbstractContracts(constrainingType.getServices(), resolver, context); + resolveAbstractContracts(constrainingType.getReferences(), resolver, context); } public QName getArtifactType() { diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java index 0cf02b6e61..06ca9635f8 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java @@ -38,10 +38,10 @@ import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.PolicySubject; /** @@ -61,9 +61,8 @@ public class DefaultBeanModelProcessor<T> extends BaseAssemblyProcessor implemen public DefaultBeanModelProcessor(FactoryExtensionPoint modeFactories, QName artifactType, Class<T> modelClass, - Object modelFactory, - Monitor monitor) { - super(modeFactories, null, monitor); + Object modelFactory) { + super(modeFactories, null); this.artifactType = artifactType; this.modelClass = modelClass; this.modelFactory = modelFactory; @@ -119,7 +118,7 @@ public class DefaultBeanModelProcessor<T> extends BaseAssemblyProcessor implemen } } - public T read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public T read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Read an element try { @@ -165,12 +164,12 @@ public class DefaultBeanModelProcessor<T> extends BaseAssemblyProcessor implemen } catch (Exception e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", reader, ce); + error(context.getMonitor(), "ContributionReadException", reader, ce); throw ce; } } - public void write(T bean, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(T bean, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { try { // Write the bean properties as attributes List<XAttr> attrs = new ArrayList<XAttr>(); @@ -189,12 +188,12 @@ public class DefaultBeanModelProcessor<T> extends BaseAssemblyProcessor implemen } catch (Exception e) { ContributionWriteException ce = new ContributionWriteException(e); - error("ContributionWriteException", writer, ce); + error(context.getMonitor(), "ContributionWriteException", writer, ce); throw ce; } } - public void resolve(T bean, ModelResolver resolver) throws ContributionResolveException { + public void resolve(T bean, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Resolve and merge the component type associated with an // implementation model @@ -211,7 +210,7 @@ public class DefaultBeanModelProcessor<T> extends BaseAssemblyProcessor implemen componentType.setURI(uri); componentType.setUnresolved(true); - componentType = resolver.resolveModel(ComponentType.class, componentType); + componentType = resolver.resolveModel(ComponentType.class, componentType, context); if (componentType != null && !componentType.isUnresolved()) { // We found a component type, merge it into the implementation model diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointProcessor.java index 8a25912bb1..4b9f07ae7e 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointProcessor.java @@ -32,12 +32,12 @@ import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * @@ -50,10 +50,9 @@ public class EndpointProcessor extends BaseAssemblyProcessor implements StAXArti public EndpointProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor, - Monitor monitor) { + StAXAttributeProcessor extensionAttributeProcessor) { - super(modelFactories(registry), extensionProcessor, monitor); + super(modelFactories(registry), extensionProcessor); this.registry = registry; } @@ -71,10 +70,10 @@ public class EndpointProcessor extends BaseAssemblyProcessor implements StAXArti return ENDPOINT_QNAME; } - public Endpoint read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Endpoint read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { Endpoint endpoint = assemblyFactory.createEndpoint(); reader.nextTag(); - Object model = extensionProcessor.read(reader); + Object model = extensionProcessor.read(reader, context); if (model instanceof Composite) { Composite composite = (Composite)model; Component component = composite.getComponents().get(0); @@ -87,9 +86,9 @@ public class EndpointProcessor extends BaseAssemblyProcessor implements StAXArti return endpoint; } - public void write(Endpoint model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(Endpoint model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // writeStart(writer, ENDPOINT_QNAME); - extensionProcessor.write(wrap(model), writer); + extensionProcessor.write(wrap(model), writer, context); // writeEnd(writer); } @@ -118,6 +117,6 @@ public class EndpointProcessor extends BaseAssemblyProcessor implements StAXArti return Endpoint.class; } - public void resolve(Endpoint model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Endpoint model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java index fc2c891c60..dd1b6f5d62 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java @@ -31,16 +31,15 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * @@ -53,10 +52,9 @@ public class EndpointReferenceProcessor extends BaseAssemblyProcessor implements public EndpointReferenceProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor, - Monitor monitor) { + StAXAttributeProcessor extensionAttributeProcessor) { - super(modelFactories(registry), extensionProcessor, monitor); + super(modelFactories(registry), extensionProcessor); this.registry = registry; } @@ -74,10 +72,10 @@ public class EndpointReferenceProcessor extends BaseAssemblyProcessor implements return ENDPOINT_QNAME; } - public EndpointReference read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public EndpointReference read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { EndpointReference endpointReference = assemblyFactory.createEndpointReference(); reader.nextTag(); - Object model = extensionProcessor.read(reader); + Object model = extensionProcessor.read(reader, context); if (model instanceof Composite) { Composite composite = (Composite)model; Component component = composite.getComponents().get(0); @@ -110,8 +108,8 @@ public class EndpointReferenceProcessor extends BaseAssemblyProcessor implements return endpointReference; } - public void write(EndpointReference model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { - extensionProcessor.write(wrap(model), writer); + public void write(EndpointReference model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { + extensionProcessor.write(wrap(model), writer, context); } private Composite wrap(EndpointReference endpointReference) { @@ -145,6 +143,6 @@ public class EndpointReferenceProcessor extends BaseAssemblyProcessor implements return EndpointReference.class; } - public void resolve(EndpointReference model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(EndpointReference model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicySubjectProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicySubjectProcessor.java index 386fb24bf9..aaf4e97371 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicySubjectProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicySubjectProcessor.java @@ -32,6 +32,7 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.policy.Intent; @@ -202,7 +203,7 @@ public class PolicySubjectProcessor extends BaseStAXArtifactProcessor { return new XAttr(Constants.POLICY_SETS, qnames); } - public void resolvePolicies(Object attachPoint, ModelResolver resolver) { + public void resolvePolicies(Object attachPoint, ModelResolver resolver, ProcessorContext context) { if ( attachPoint instanceof PolicySubject ) { PolicySubject policySetAttachPoint = (PolicySubject)attachPoint; @@ -211,7 +212,7 @@ public class PolicySubjectProcessor extends BaseStAXArtifactProcessor { if ( policySetAttachPoint.getRequiredIntents() != null && policySetAttachPoint.getRequiredIntents().size() > 0 ) { for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) { - resolvedIntent = resolver.resolveModel(Intent.class, intent); + resolvedIntent = resolver.resolveModel(Intent.class, intent, context); requiredIntents.add(resolvedIntent); } policySetAttachPoint.getRequiredIntents().clear(); @@ -222,7 +223,7 @@ public class PolicySubjectProcessor extends BaseStAXArtifactProcessor { List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>(); PolicySet resolvedPolicySet = null; for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) { - resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet); + resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet, context); resolvedPolicySets.add(resolvedPolicySet); } policySetAttachPoint.getPolicySets().clear(); diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java index 29608ac534..8ac0de9617 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java @@ -31,6 +31,7 @@ import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -73,7 +74,7 @@ public class SCABindingProcessor implements StAXArtifactProcessor<SCABinding> { return SCABinding.class; } - public SCABinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public SCABinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { SCABinding scaBinding = scaBindingFactory.createSCABinding(); ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType(); bindingType.setType(getArtifactType()); @@ -104,11 +105,11 @@ public class SCABindingProcessor implements StAXArtifactProcessor<SCABinding> { return scaBinding; } - public void resolve(SCABinding model, ModelResolver resolver) throws ContributionResolveException { - policyProcessor.resolvePolicies(model, resolver); + public void resolve(SCABinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + policyProcessor.resolvePolicies(model, resolver, context); } - public void write(SCABinding scaBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(SCABinding scaBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <binding.sca> writer.writeStartElement(SCA11_NS, BINDING_SCA); diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefaultDefinitionsExtensionPoint.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefaultDefinitionsExtensionPoint.java index cf2d0ea5e3..1f256de3a2 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefaultDefinitionsExtensionPoint.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefaultDefinitionsExtensionPoint.java @@ -31,12 +31,15 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; +import org.apache.tuscany.sca.monitor.MonitorFactory; /** * Default implementation of an extension point for XML definitionss. @@ -47,6 +50,7 @@ public class DefaultDefinitionsExtensionPoint implements DefinitionsExtensionPoi private static final Logger logger = Logger.getLogger(DefaultDefinitionsExtensionPoint.class.getName()); private static final URI DEFINITIONS_URI = URI.create("META-INF/definitions.xml"); private ExtensionPointRegistry registry; + private MonitorFactory monitorFactory; private Set<URL> documents = new HashSet<URL>(); private List<Definitions> definitions = new ArrayList<Definitions>(); private boolean documentsLoaded; @@ -54,6 +58,7 @@ public class DefaultDefinitionsExtensionPoint implements DefinitionsExtensionPoi public DefaultDefinitionsExtensionPoint(ExtensionPointRegistry registry) { this.registry = registry; + this.monitorFactory = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class); } public void addDefinitionsDocument(URL url) { @@ -98,10 +103,11 @@ public class DefaultDefinitionsExtensionPoint implements DefinitionsExtensionPoi URLArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); URLArtifactProcessor<Definitions> processor = processors.getProcessor(Definitions.class); + ProcessorContext context = new ProcessorContext(monitorFactory.createMonitor()); for (URL url : documents) { Definitions def; try { - def = processor.read(null, DEFINITIONS_URI, url); + def = processor.read(null, DEFINITIONS_URI, url, context); definitions.add(def); } catch (ContributionReadException e) { logger.log(Level.SEVERE, e.getMessage(), e); 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 cfda3dbebc..a047377aed 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 @@ -35,6 +35,7 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; @@ -56,7 +57,7 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini private StAXArtifactProcessor<Object> extensionProcessor; private XMLInputFactory inputFactory; private DefinitionsFactory definitionsFactory; - private Monitor monitor; + /** @@ -66,12 +67,10 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini * @param staxProcessor */ public DefinitionsDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> staxProcessor, - Monitor monitor) { + StAXArtifactProcessor<Object> staxProcessor) { this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor; this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); this.definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class); - this.monitor = monitor; } /** @@ -81,7 +80,7 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini * @param message * @param model */ - private void error(String message, Object model, Exception ex) { + private void error(Monitor monitor, String message, Object model, Exception ex) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -94,8 +93,9 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini } } - public Definitions read(URL contributionURL, final URI uri, final URL url) throws ContributionReadException { + public Definitions read(URL contributionURL, final URI uri, final URL url, ProcessorContext context) throws ContributionReadException { InputStream urlStream = null; + Monitor monitor = context.getMonitor(); monitor.pushContext("Definitions: " + url); try { // Allow privileged access to open URL stream. Add FilePermission to added to security @@ -107,7 +107,7 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini } }); } catch (PrivilegedActionException e) { - error("PrivilegedActionException", url, (IOException)e.getException()); + error(monitor, "PrivilegedActionException", url, (IOException)e.getException()); throw (IOException)e.getException(); } @@ -122,12 +122,12 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini // We only deal with the root element if (event == XMLStreamConstants.START_ELEMENT) { // QName name = reader.getName(); - Object model = extensionProcessor.read(reader); + Object model = extensionProcessor.read(reader, context); if (model instanceof Definitions) { DefinitionsUtil.aggregate((Definitions)model, definitions, monitor); return definitions; } else { - error("ContributionReadException", model, null); + error(monitor, "ContributionReadException", model, null); } } } @@ -135,11 +135,11 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini return definitions; } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error(monitor, "ContributionReadException", inputFactory, ce); throw ce; } catch (IOException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error(monitor, "ContributionReadException", inputFactory, ce); throw ce; } finally { @@ -156,8 +156,8 @@ public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Defini } } - public void resolve(Definitions scaDefinitions, ModelResolver resolver) throws ContributionResolveException { - extensionProcessor.resolve(scaDefinitions, resolver); + public void resolve(Definitions scaDefinitions, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + extensionProcessor.resolve(scaDefinitions, resolver, context); } public String getArtifactType() { diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsProcessor.java index 7b80a750d2..384f914e8c 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsProcessor.java @@ -36,12 +36,12 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.definitions.DefinitionsFactory; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.BindingType; import org.apache.tuscany.sca.policy.ImplementationType; import org.apache.tuscany.sca.policy.Intent; @@ -56,7 +56,7 @@ public class DefinitionsProcessor extends BaseStAXArtifactProcessor implements S private StAXArtifactProcessor<Object> extensionProcessor; private DefinitionsFactory definitionsFactory; - private Monitor monitor; + public static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; public static final String BINDING = "binding"; @@ -67,14 +67,12 @@ public class DefinitionsProcessor extends BaseStAXArtifactProcessor implements S public static final String NAME = "name"; public DefinitionsProcessor(FactoryExtensionPoint factoryExtensionPoint, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { + StAXArtifactProcessor<Object> extensionProcessor) { this.extensionProcessor = extensionProcessor; - this.monitor = monitor; this.definitionsFactory = factoryExtensionPoint.getFactory(DefinitionsFactory.class); } - public Definitions read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Definitions read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { QName name = null; Definitions definitions = null; String targetNamespace = null; @@ -89,7 +87,7 @@ public class DefinitionsProcessor extends BaseStAXArtifactProcessor implements S targetNamespace = reader.getAttributeValue(null, TARGET_NAMESPACE); definitions.setTargetNamespace(targetNamespace); } else { - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null) { if (extension instanceof Intent) { Intent intent = (Intent)extension; @@ -134,31 +132,31 @@ public class DefinitionsProcessor extends BaseStAXArtifactProcessor implements S return definitions; } - public void write(Definitions definitions, XMLStreamWriter writer) throws ContributionWriteException, + public void write(Definitions definitions, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writeStartDocument(writer, SCA11_NS, DEFINITIONS, new XAttr(TARGET_NAMESPACE, definitions.getTargetNamespace())); for (Intent policyIntent : definitions.getIntents()) { - extensionProcessor.write(policyIntent, writer); + extensionProcessor.write(policyIntent, writer, context); } for (PolicySet policySet : definitions.getPolicySets()) { - extensionProcessor.write(policySet, writer); + extensionProcessor.write(policySet, writer, context); } for (BindingType bindingType : definitions.getBindingTypes()) { - extensionProcessor.write(bindingType, writer); + extensionProcessor.write(bindingType, writer, context); } for (ImplementationType implType : definitions.getImplementationTypes()) { - extensionProcessor.write(implType, writer); + extensionProcessor.write(implType, writer, context); } writeEndDocument(writer); } - public void resolve(Definitions scaDefns, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Definitions scaDefns, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // start by adding all of the top level artifacts into the resolver as there // are many cross artifact references in a definitions file and we don't want // to be dependent on the order things appear @@ -169,10 +167,10 @@ public class DefinitionsProcessor extends BaseStAXArtifactProcessor implements S for (Intent intent : scaDefns.getIntents()) { intents.add(intent); - resolver.addModel(intent); + resolver.addModel(intent, context); for (Intent i : intent.getQualifiedIntents()) { intents.add(i); - resolver.addModel(i); + resolver.addModel(i, context); } } @@ -183,35 +181,35 @@ public class DefinitionsProcessor extends BaseStAXArtifactProcessor implements S referredPolicySets.add(policySet); } - resolver.addModel(policySet); + resolver.addModel(policySet, context); } for (BindingType bindingType : scaDefns.getBindingTypes()) { - resolver.addModel(bindingType); + resolver.addModel(bindingType, context); } for (ImplementationType implType : scaDefns.getImplementationTypes()) { - resolver.addModel(implType); + resolver.addModel(implType, context); } // now resolve everything to ensure that any references between // artifacts are satisfied for (Intent policyIntent : intents) - extensionProcessor.resolve(policyIntent, resolver); + extensionProcessor.resolve(policyIntent, resolver, context); for (PolicySet policySet : policySets) - extensionProcessor.resolve(policySet, resolver); + extensionProcessor.resolve(policySet, resolver, context); for (PolicySet policySet : referredPolicySets) - extensionProcessor.resolve(policySet, resolver); + extensionProcessor.resolve(policySet, resolver, context); for (BindingType bindingType : scaDefns.getBindingTypes()) { - extensionProcessor.resolve(bindingType, resolver); + extensionProcessor.resolve(bindingType, resolver, context); } for (ImplementationType implementationType : scaDefns.getImplementationTypes()) { - extensionProcessor.resolve(implementationType, resolver); + extensionProcessor.resolve(implementationType, resolver, context); } } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java index 38c7b57f12..70c71c5f1f 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java @@ -22,10 +22,10 @@ package org.apache.tuscany.sca.policy.xml; import javax.xml.namespace.QName; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.BindingType; import org.apache.tuscany.sca.policy.ExtensionType; import org.apache.tuscany.sca.policy.PolicyFactory; @@ -38,15 +38,13 @@ import org.apache.tuscany.sca.policy.PolicyFactory; public class BindingTypeProcessor extends ExtensionTypeProcessor { public BindingTypeProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { - super(policyFactory, extensionProcessor, monitor); + StAXArtifactProcessor<Object> extensionProcessor) { + super(policyFactory, extensionProcessor); } public BindingTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { - super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor); + StAXArtifactProcessor<Object> extensionProcessor) { + super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor); } public QName getArtifactType() { @@ -54,11 +52,11 @@ public class BindingTypeProcessor extends ExtensionTypeProcessor { } @Override - protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver) + protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (extnType instanceof BindingType) { BindingType bindingType = (BindingType)extnType; - return resolver.resolveModel(BindingType.class, bindingType); + return resolver.resolveModel(BindingType.class, bindingType, context); } else { return extnType; } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java index 27f2c93971..95d8e67bf7 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.monitor.Monitor; @@ -52,16 +53,14 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen StAXArtifactProcessor<ExtensionType>, PolicyConstants { private PolicyFactory policyFactory; - private Monitor monitor; + - protected abstract ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver) + protected abstract ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException; public ExtensionTypeProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { + StAXArtifactProcessor<Object> extensionProcessor) { this.policyFactory = policyFactory; - this.monitor = monitor; } /** @@ -71,7 +70,7 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -84,7 +83,7 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen } } - public ExtensionType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public ExtensionType read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { QName extType = getArtifactType(); QName type = getQName(reader, "type"); @@ -95,7 +94,7 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen } else if (IMPLEMENTATION_TYPE_QNAME.equals(extType)) { extensionType = policyFactory.createImplementationType(); } else { - error("UnrecognizedExtensionType", reader, type); + error(context.getMonitor(), "UnrecognizedExtensionType", reader, type); return null; //throw new ContributionReadException("Unrecognized ExtensionType - " + type); } @@ -107,7 +106,7 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen return extensionType; } else { - error("RequiredAttributeMissing", reader, extType); + error(context.getMonitor(), "RequiredAttributeMissing", reader, extType); //throw new ContributionReadException("Required attribute '" + TYPE + //"' missing from BindingType Definition"); } @@ -140,7 +139,7 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen } } - public void write(ExtensionType extnType, XMLStreamWriter writer) throws ContributionWriteException, + public void write(ExtensionType extnType, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <sca:bindingType or sca:implementationType> @@ -185,28 +184,28 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen } } - public void resolve(ExtensionType extnType, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (extnType != null && extnType.isUnresolved()) { - resolveAlwaysProvidedIntents(extnType, resolver); - resolveMayProvideIntents(extnType, resolver); + resolveAlwaysProvidedIntents(extnType, resolver, context); + resolveMayProvideIntents(extnType, resolver, context); extnType.setUnresolved(false); //resolveExtensionType(extnType, resolver); } } - private void resolveAlwaysProvidedIntents(ExtensionType extensionType, ModelResolver resolver) + private void resolveAlwaysProvidedIntents(ExtensionType extensionType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (extensionType != null) { // resolve all provided intents List<Intent> alwaysProvided = new ArrayList<Intent>(); for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) { if (providedIntent.isUnresolved()) { - providedIntent = resolver.resolveModel(Intent.class, providedIntent); + providedIntent = resolver.resolveModel(Intent.class, providedIntent, context); if (!providedIntent.isUnresolved()) { alwaysProvided.add(providedIntent); } else { - error("AlwaysProvidedIntentNotFound", resolver, providedIntent, extensionType); + error(context.getMonitor(), "AlwaysProvidedIntentNotFound", resolver, providedIntent, extensionType); //throw new ContributionResolveException("Always Provided Intent - " + providedIntent //+ " not found for ExtensionType " //+ extensionType); @@ -220,18 +219,18 @@ abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implemen } } - private void resolveMayProvideIntents(ExtensionType extensionType, ModelResolver resolver) + private void resolveMayProvideIntents(ExtensionType extensionType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (extensionType != null) { // resolve all provided intents List<Intent> mayProvide = new ArrayList<Intent>(); for (Intent providedIntent : extensionType.getMayProvidedIntents()) { if (providedIntent.isUnresolved()) { - providedIntent = resolver.resolveModel(Intent.class, providedIntent); + providedIntent = resolver.resolveModel(Intent.class, providedIntent, context); if (!providedIntent.isUnresolved()) { mayProvide.add(providedIntent); } else { - error("MayProvideIntentNotFound", resolver, providedIntent, extensionType); + error(context.getMonitor(), "MayProvideIntentNotFound", resolver, providedIntent, extensionType); //throw new ContributionResolveException("May Provide Intent - " + providedIntent //+ " not found for ExtensionType " //+ extensionType); diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java index 41e2af3809..ec4e17385f 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java @@ -22,10 +22,10 @@ package org.apache.tuscany.sca.policy.xml; import javax.xml.namespace.QName; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.ExtensionType; import org.apache.tuscany.sca.policy.ImplementationType; import org.apache.tuscany.sca.policy.PolicyFactory; @@ -38,15 +38,13 @@ import org.apache.tuscany.sca.policy.PolicyFactory; public class ImplementationTypeProcessor extends ExtensionTypeProcessor { public ImplementationTypeProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { - super(policyFactory, extensionProcessor, monitor); + StAXArtifactProcessor<Object> extensionProcessor) { + super(policyFactory, extensionProcessor); } public ImplementationTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { - super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor); + StAXArtifactProcessor<Object> extensionProcessor) { + super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor); } public QName getArtifactType() { @@ -54,11 +52,11 @@ public class ImplementationTypeProcessor extends ExtensionTypeProcessor { } @Override - protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver) + protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (extnType instanceof ImplementationType) { ImplementationType implType = (ImplementationType)extnType; - return resolver.resolveModel(ImplementationType.class, implType); + return resolver.resolveModel(ImplementationType.class, implType, context); } else { return extnType; } diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java index 2a0d2f6111..ac4f81d5a9 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java @@ -37,6 +37,7 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -57,16 +58,14 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr PolicyConstants { private PolicyFactory policyFactory; - private Monitor monitor; + - public IntentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public IntentProcessor(FactoryExtensionPoint modelFactories) { this.policyFactory = modelFactories.getFactory(PolicyFactory.class); - this.monitor = monitor; } - public IntentProcessor(PolicyFactory policyFactory, Monitor monitor) { + public IntentProcessor(PolicyFactory policyFactory) { this.policyFactory = policyFactory; - this.monitor = monitor; } /** @@ -76,7 +75,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -89,7 +88,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr } } - private void warn(String message, Object model, Object... messageParameters) { + private void warn(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -102,11 +101,11 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr } } - public Intent read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Intent read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { Intent intent = null; String intentLocalName = reader.getAttributeValue(null, NAME); if (intentLocalName == null) { - error("IntentNameMissing", reader); + error(context.getMonitor(), "IntentNameMissing", reader); return null; } @@ -182,7 +181,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr return intent; } - public void write(Intent intent, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(Intent intent, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <sca:intent> writer.writeStartElement(PolicyConstants.SCA11_NS, INTENT); writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI()); @@ -225,7 +224,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr writer.writeEndElement(); } - private void resolveContrainedTypes(Intent intent, ModelResolver resolver) throws ContributionResolveException { + private void resolveContrainedTypes(Intent intent, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { Collection<ExtensionType> resolvedTypes = new HashSet<ExtensionType>(); for (ExtensionType extensionType : intent.getConstrainedTypes()) { if (ExtensionType.BINDING_BASE.equals(extensionType.getType()) || ExtensionType.IMPLEMENTATION_BASE @@ -234,11 +233,11 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr extensionType.setUnresolved(false); resolvedTypes.add(extensionType); } else { - ExtensionType resolved = resolver.resolveModel(ExtensionType.class, extensionType); + ExtensionType resolved = resolver.resolveModel(ExtensionType.class, extensionType, context); if (!resolved.isUnresolved() || resolved != extensionType) { resolvedTypes.add(resolved); } else { - warn("ConstrainedTypeNotFound", intent, extensionType, intent); + warn(context.getMonitor(), "ConstrainedTypeNotFound", intent, extensionType, intent); } } } @@ -246,7 +245,8 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr intent.getConstrainedTypes().addAll(resolvedTypes); } - private void resolveProfileIntent(Intent intent, ModelResolver resolver) throws ContributionResolveException { + private void resolveProfileIntent(Intent intent, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); // FIXME: Need to check for cyclic references first i.e an A requiring B // and then B requiring A... if (intent != null && !intent.getRequiredIntents().isEmpty()) { @@ -254,13 +254,13 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr List<Intent> requiredIntents = new ArrayList<Intent>(); for (Intent required : intent.getRequiredIntents()) { if (required.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, required); + Intent resolved = resolver.resolveModel(Intent.class, required, context); // At this point, when the required intent is not resolved, it does not mean // its undeclared, chances are that their dependency are not resolved yet. // Lets try to resolve them first. if (resolved.isUnresolved()) { if (((resolved).getRequiredIntents()).contains(intent)) { - error("CyclicReferenceFound", resolver, required, intent); + error(monitor, "CyclicReferenceFound", resolver, required, intent); return; } } @@ -268,7 +268,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr if (!resolved.isUnresolved() || resolved != required) { requiredIntents.add(resolved); } else { - error("RequiredIntentNotFound", resolver, required, intent); + error(monitor, "RequiredIntentNotFound", resolver, required, intent); return; //throw new ContributionResolveException("Required Intent - " + requiredIntent //+ " not found for Intent " + policyIntent); @@ -282,7 +282,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr } } - private void resolveQualifiedIntent(Intent qualifed, ModelResolver resolver) throws ContributionResolveException { + private void resolveQualifiedIntent(Intent qualifed, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (qualifed != null) { //resolve the qualifiable intent Intent parent = qualifed.getQualifiableIntent(); @@ -290,7 +290,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr return; } if (parent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, parent); + Intent resolved = resolver.resolveModel(Intent.class, parent, context); // At this point, when the qualifiable intent is not resolved, it does not mean // its undeclared, chances are that their dependency are not resolved yet. // Lets try to resolve them first. @@ -298,7 +298,7 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr if (!resolved.isUnresolved() || resolved != qualifed) { qualifed.setQualifiableIntent(resolved); } else { - error("QualifiableIntentNotFound", resolver, parent, qualifed); + error(context.getMonitor(), "QualifiableIntentNotFound", resolver, parent, qualifed); //throw new ContributionResolveException("Qualifiable Intent - " + qualifiableIntent //+ " not found for Intent " + policyIntent); } @@ -306,11 +306,12 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr } } - public void resolve(Intent intent, ModelResolver resolver) throws ContributionResolveException { - resolveProfileIntent(intent, resolver); - resolveExcludedIntents(intent, resolver); - resolveQualifiedIntent(intent, resolver); - resolveContrainedTypes(intent, resolver); + public void resolve(Intent intent, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); + resolveProfileIntent(intent, resolver, context); + resolveExcludedIntents(intent, resolver, context); + resolveQualifiedIntent(intent, resolver, context); + resolveContrainedTypes(intent, resolver, context); intent.setUnresolved(false); } @@ -359,18 +360,18 @@ public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXAr } } - private void resolveExcludedIntents(Intent policyIntent, ModelResolver resolver) + private void resolveExcludedIntents(Intent policyIntent, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (policyIntent != null) { // resolve all excluded intents List<Intent> excludedIntents = new ArrayList<Intent>(); for (Intent excludedIntent : policyIntent.getExcludedIntents()) { if (excludedIntent.isUnresolved()) { - Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent); + Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent, context); if (!resolvedExcludedIntent.isUnresolved() || resolvedExcludedIntent != excludedIntent) { excludedIntents.add(resolvedExcludedIntent); } else { - error("ExcludedIntentNotFound", resolver, excludedIntent, policyIntent); + error(context.getMonitor(), "ExcludedIntentNotFound", resolver, excludedIntent, policyIntent); return; //throw new ContributionResolveException("Excluded Intent " + excludedIntent //+ " not found for intent " + policyIntent); diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java index 1003889edc..e647d1e575 100644 --- a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java @@ -40,6 +40,7 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -66,28 +67,16 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA private StAXArtifactProcessor<Object> extensionProcessor; private XPathHelper xpathHelper; // private XPathFactory xpathFactory; - private Monitor monitor; + public PolicySetProcessor(ExtensionPointRegistry registry, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { + StAXArtifactProcessor<Object> extensionProcessor) { FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.extensionProcessor = extensionProcessor; - this.monitor = monitor; this.xpathHelper = XPathHelper.getInstance(registry); - // this.xpathFactory = modelFactories.getFactory(XPathFactory.class); } - /* - public PolicySetProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor<Object> extensionProcessor, - Monitor monitor) { - this.policyFactory = policyFactory; - this.extensionProcessor = extensionProcessor; - this.monitor = monitor; - } - */ /** * Report a exception. @@ -96,7 +85,7 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA * @param message * @param model */ - private void error(String message, Object model, Exception ex) { + private void error(Monitor monitor, String message, Object model, Exception ex) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -116,7 +105,7 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -129,16 +118,16 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } } - public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public PolicySet read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { PolicySet policySet = null; - + Monitor monitor = context.getMonitor(); String policySetName = reader.getAttributeValue(null, NAME); String appliesTo = reader.getAttributeValue(null, APPLIES_TO); if (policySetName == null || appliesTo == null) { if (policySetName == null) - error("PolicySetNameMissing", reader); + error(monitor, "PolicySetNameMissing", reader); if (appliesTo == null) - error("PolicySetAppliesToMissing", reader); + error(monitor, "PolicySetAppliesToMissing", reader); return policySet; } @@ -158,13 +147,13 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA if (appliesTo != null) { try { XPath path = xpathHelper.newXPath(); - NamespaceContext context = xpathHelper.getNamespaceContext(appliesTo, reader.getNamespaceContext()); + NamespaceContext nsContext = xpathHelper.getNamespaceContext(appliesTo, reader.getNamespaceContext()); // path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(context)); - XPathExpression expression = xpathHelper.compile(path, context, appliesTo); + XPathExpression expression = xpathHelper.compile(path, nsContext, appliesTo); policySet.setAppliesToXPathExpression(expression); } catch (XPathExpressionException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", policySet, ce); + error(monitor, "ContributionReadException", policySet, ce); //throw ce; } } @@ -173,14 +162,14 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA if (attachTo != null) { try { XPath path = xpathHelper.newXPath(); - NamespaceContext context = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext()); - path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(context)); - XPathExpression expression = xpathHelper.compile(path, context, attachTo); + NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext()); + path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext)); + XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo); policySet.setAttachTo(attachTo); policySet.setAttachToXPathExpression(expression); } catch (XPathExpressionException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", policySet, ce); + error(monitor, "ContributionReadException", policySet, ce); //throw ce; } @@ -202,13 +191,13 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA if (provides != null) { mappedIntent.setName(getQName(reader, PROVIDES)); if (policySet.getProvidedIntents().contains(mappedIntent)) { - readIntentMap(reader, policySet, mappedIntent); + readIntentMap(reader, policySet, mappedIntent, context); } else { - error("IntentNotSpecified", policySet, policySetName); + error(monitor, "IntentNotSpecified", policySet, policySetName); //throw new ContributionReadException("Intent Map provides for Intent not specified as provided by parent PolicySet - " + policySetName); } } else { - error("IntentMapProvidesMissing", reader, policySetName); + error(monitor, "IntentMapProvidesMissing", reader, policySetName); } } else if (POLICY_SET_REFERENCE_QNAME.equals(name)) { PolicySet referredPolicySet = policyFactory.createPolicySet(); @@ -217,14 +206,14 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA referredPolicySet.setName(getQName(reader, NAME)); policySet.getReferencedPolicySets().add(referredPolicySet); } else { - error("PolicySetReferenceNameMissing", reader, policySetName); + error(monitor, "PolicySetReferenceNameMissing", reader, policySetName); } } /*else if ( WS_POLICY_QNAME.equals(name) ) { OMElement policyElement = loadElement(reader); org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement); policySet.getPolicies().add(wsPolicy); } */else { - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null) { PolicyExpression exp = policyFactory.createPolicyExpression(); exp.setName(name); @@ -249,8 +238,9 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA return policySet; } - public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent) + public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent, ProcessorContext context) throws ContributionReadException { + Monitor monitor = context.getMonitor(); QName name = reader.getName(); if (POLICY_INTENT_MAP_QNAME.equals(name)) { @@ -287,14 +277,14 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA intentMap.getQualifiers().add(qualifier); } else { - error("QualifierNameMissing", reader, policySet.getName()); + error(monitor, "QualifierNameMissing", reader, policySet.getName()); } } else if (POLICY_INTENT_MAP_QNAME.equals(name)) { QName providedIntent = getQName(reader, PROVIDES); if (qualifierName.equals(providedIntent.getLocalPart())) { - readIntentMap(reader, policySet, qualifiedIntent); + readIntentMap(reader, policySet, qualifiedIntent, context); } else { - error("IntentMapDoesNotMatch", + error(monitor, "IntentMapDoesNotMatch", providedIntent, providedIntent, qualifierName, @@ -304,7 +294,7 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA //" in policyset - " + policySet); } } else { - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null && qualifier != null) { PolicyExpression exp = policyFactory.createPolicyExpression(); exp.setName(name); @@ -325,13 +315,13 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", reader, ce); + error(monitor, "ContributionReadException", reader, ce); throw ce; } } } - public void write(PolicySet policySet, XMLStreamWriter writer) throws ContributionWriteException, + public void write(PolicySet policySet, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <sca:policySet> @@ -382,11 +372,11 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } } - private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + private void resolvePolicies(PolicySet policySet, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { boolean unresolved = false; if (policySet != null) { for (Object o : policySet.getPolicies()) { - extensionProcessor.resolve(o, resolver); + extensionProcessor.resolve(o, resolver, context); /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) { unresolved = true; }*/ @@ -403,18 +393,18 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA return PolicySet.class; } - private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) + private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (policySet != null) { //resolve all provided intents List<Intent> providedIntents = new ArrayList<Intent>(); for (Intent providedIntent : policySet.getProvidedIntents()) { if (providedIntent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, providedIntent); + Intent resolved = resolver.resolveModel(Intent.class, providedIntent, context); if (!resolved.isUnresolved() || resolved != providedIntent) { providedIntents.add(resolved); } else { - error("ProvidedIntentNotFound", policySet, providedIntent, policySet); + error(context.getMonitor(), "ProvidedIntentNotFound", policySet, providedIntent, policySet); return; //throw new ContributionResolveException("Provided Intent - " + providedIntent //+ " not found for PolicySet " + policySet); @@ -428,16 +418,17 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } } - private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver) + private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); for (IntentMap intentMap : policySet.getIntentMaps()) { Intent intent = intentMap.getProvidedIntent(); if (intent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, intent); + Intent resolved = resolver.resolveModel(Intent.class, intent, context); if (!resolved.isUnresolved() || resolved != intent) { intentMap.setProvidedIntent(resolved); } else { - error("MappedIntentNotFound", policySet, intent, policySet); + error(monitor, "MappedIntentNotFound", policySet, intent, policySet); return; //throw new ContributionResolveException("Mapped Intent - " + mappedIntent //+ " not found for PolicySet " + policySet); @@ -446,11 +437,11 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA for (Qualifier qualifier : intentMap.getQualifiers()) { intent = qualifier.getIntent(); if (intent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, intent); + Intent resolved = resolver.resolveModel(Intent.class, intent, context); if (!resolved.isUnresolved() || resolved != intent) { qualifier.setIntent(resolved); } else { - error("MappedIntentNotFound", policySet, intent, policySet); + error(monitor, "MappedIntentNotFound", policySet, intent, policySet); return; //throw new ContributionResolveException("Mapped Intent - " + mappedIntent //+ " not found for PolicySet " + policySet); @@ -464,17 +455,17 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } - private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) + private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { List<PolicySet> referredPolicySets = new ArrayList<PolicySet>(); for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { if (referredPolicySet.isUnresolved()) { - PolicySet resolved = resolver.resolveModel(PolicySet.class, referredPolicySet); + PolicySet resolved = resolver.resolveModel(PolicySet.class, referredPolicySet, context); if (!resolved.isUnresolved() || resolved != referredPolicySet) { referredPolicySets.add(resolved); } else { - error("ReferredPolicySetNotFound", policySet, referredPolicySet, policySet); + error(context.getMonitor(), "ReferredPolicySetNotFound", policySet, referredPolicySet, policySet); return; //throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet //+ "not found for PolicySet - " + policySet); @@ -495,10 +486,11 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA policySet.getIntentMaps().addAll(referredPolicySet.getIntentMaps()); } - public void resolve(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { - resolveProvidedIntents(policySet, resolver); - resolveIntentsInMappedPolicies(policySet, resolver); - resolveReferredPolicySets(policySet, resolver); + public void resolve(PolicySet policySet, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); + resolveProvidedIntents(policySet, resolver, context); + resolveIntentsInMappedPolicies(policySet, resolver, context); + resolveReferredPolicySets(policySet, resolver, context); for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { includeReferredPolicySets(policySet, referredPolicySet); @@ -506,7 +498,7 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA if (policySet.isUnresolved()) { //resolve the policy attachments - resolvePolicies(policySet, resolver); + resolvePolicies(policySet, resolver, context); /*if ( !policySet.isUnresolved() ) { resolver.addModel(policySet); diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java index 4e74c55949..0d5e69bd61 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MultiplicityReadWriteTestCase.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLOutputFactory; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.junit.Before; @@ -47,31 +48,32 @@ public class MultiplicityReadWriteTestCase { private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private ExtensibleStAXArtifactProcessor staxProcessor; - + private ProcessorContext context; @Before public void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } @Test public void testReadWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Multiplicity.composite"); - Composite composite = staxProcessor.read(is, Composite.class); + Composite composite = staxProcessor.read(is, Composite.class, context); verifyComposite(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); bos.close(); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - composite = staxProcessor.read(bis, Composite.class); + composite = staxProcessor.read(bis, Composite.class, context); verifyComposite(composite); diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java index 54d8f3d260..1dbf5ae8d5 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java @@ -38,6 +38,7 @@ import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; @@ -55,19 +56,21 @@ import org.w3c.dom.Element; public class ReadAllTestCase { private static StAXArtifactProcessor<Object> staxProcessor; private static XMLInputFactory inputFactory; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); inputFactory = XMLInputFactory.newInstance(); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } @Test public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); - Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(composite); assertEquals(composite.getName(), new QName("http://calc", "TestAllCalculator")); assertEquals(composite.getConstrainingType().getName(), new QName("http://calc", "CalculatorComponent")); 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 463e6fec82..93392e7114 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 @@ -38,6 +38,7 @@ import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFa import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; @@ -66,18 +67,20 @@ public class ReadDocumentTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; private static ValidatorHandler handler; + private static ProcessorContext context; @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); inputFactory = XMLInputFactory.newInstance(); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); resolver = new DefaultModelResolver(); handler = getValidationHandler(); @@ -132,11 +135,11 @@ public class ReadDocumentTestCase { factories.addFactory(validatingInputFactory); CompositeDocumentProcessor compositeDocumentProcessor = - new CompositeDocumentProcessor(factories, staxProcessor, null); + new CompositeDocumentProcessor(factories, staxProcessor); URL url = getClass().getResource("Calculator.composite"); URI uri = URI.create("Calculator.composite"); - Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url); + Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url, context); assertNotNull(composite); } @@ -159,11 +162,11 @@ public class ReadDocumentTestCase { DefaultFactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()); factories.addFactory(validatingInputFactory); CompositeDocumentProcessor compositeDocumentProcessor = - new CompositeDocumentProcessor(factories, staxProcessor, null); + new CompositeDocumentProcessor(factories, staxProcessor); URL url = getClass().getResource("RMIBindingTest.composite"); URI uri = URI.create("RMIBindingTest.composite"); - Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url); + Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url, context); assertNotNull(composite); } @@ -172,16 +175,16 @@ public class ReadDocumentTestCase { URL url = getClass().getResource("CalculatorComponent.constrainingType"); URI uri = URI.create("CalculatorComponent.constrainingType"); - ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url, context); assertNotNull(constrainingType); - resolver.addModel(constrainingType); + resolver.addModel(constrainingType, context); url = getClass().getResource("TestAllCalculator.composite"); uri = URI.create("TestAllCalculator.composite"); - Composite composite = (Composite)documentProcessor.read(null, uri, url); + Composite composite = (Composite)documentProcessor.read(null, uri, url, context); assertNotNull(composite); - documentProcessor.resolve(composite, resolver); + documentProcessor.resolve(composite, resolver, context); assertEquals(composite.getConstrainingType(), constrainingType); assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); @@ -191,15 +194,15 @@ public class ReadDocumentTestCase { public void testResolveComposite() throws Exception { URL url = getClass().getResource("Calculator.composite"); URI uri = URI.create("Calculator.composite"); - Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url); + Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url, context); assertNotNull(nestedComposite); - resolver.addModel(nestedComposite); + resolver.addModel(nestedComposite, context); url = getClass().getResource("TestAllCalculator.composite"); uri = URI.create("TestAllCalculator.composite"); - Composite composite = (Composite)documentProcessor.read(null, uri, url); + Composite composite = (Composite)documentProcessor.read(null, uri, url, context); - documentProcessor.resolve(composite, resolver); + documentProcessor.resolve(composite, resolver, context); assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java index beeb6feaea..8b7de877fd 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java @@ -28,6 +28,7 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; @@ -44,13 +45,15 @@ public class ReadTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); } @@ -58,7 +61,7 @@ public class ReadTestCase { public void testReadComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - assertNotNull(staxProcessor.read(reader)); + assertNotNull(staxProcessor.read(reader, context)); is.close(); } @@ -66,7 +69,7 @@ public class ReadTestCase { public void testReadConstrainingType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - assertNotNull(staxProcessor.read(reader)); + assertNotNull(staxProcessor.read(reader, context)); is.close(); } @@ -75,7 +78,7 @@ public class ReadTestCase { public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - assertNotNull(staxProcessor.read(reader)); + assertNotNull(staxProcessor.read(reader, context)); is.close(); } @@ -84,7 +87,7 @@ public class ReadTestCase { public void testReadCompositeAndWireIt() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - assertNotNull(staxProcessor.read(reader)); + assertNotNull(staxProcessor.read(reader, context)); is.close(); } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java index 15754b32e4..9646356eb7 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAnyAttributeTestCase.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; @@ -56,7 +57,7 @@ public class ReadWriteAnyAttributeTestCase { private XMLInputFactory inputFactory; private ExtensibleStAXArtifactProcessor staxProcessor; - + private ProcessorContext context; /** * Initialize the test environment @@ -67,6 +68,7 @@ public class ReadWriteAnyAttributeTestCase { */ private void init(StAXAttributeProcessor<?> attributeProcessor) throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); @@ -75,7 +77,7 @@ public class ReadWriteAnyAttributeTestCase { staxAttributeProcessors.addArtifactProcessor(attributeProcessor); } - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); } /** @@ -88,12 +90,12 @@ public class ReadWriteAnyAttributeTestCase { init(new TestAttributeProcessor()); XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); - Composite composite = (Composite) staxProcessor.read(reader); + Composite composite = (Composite) staxProcessor.read(reader, context); assertNotNull(composite); reader.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); // used for debug comparison // System.out.println(XML); @@ -112,12 +114,12 @@ public class ReadWriteAnyAttributeTestCase { init(null); XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML)); - Composite composite = (Composite) staxProcessor.read(reader); + Composite composite = (Composite) staxProcessor.read(reader, context); assertNotNull(composite); reader.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); // used for debug comparison // System.out.println(XML); 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 0b04c43ad5..1e48e241a4 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 @@ -30,6 +30,7 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; @@ -75,15 +76,18 @@ public class ReadWriteAnyElementTestCase { private XMLInputFactory inputFactory; private ExtensibleStAXArtifactProcessor staxProcessor; + private ProcessorContext context; @Before public void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance(), null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, XMLOutputFactory.newInstance()); } @After @@ -93,12 +97,12 @@ public class ReadWriteAnyElementTestCase { @Test public void testReadWriteExtendedRecursiveElement() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_RECURSIVE_EXTENDED_ELEMENT)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); reader.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); // used for debug comparison // System.out.println(XML_RECURSIVE_EXTENDED_ELEMENT); @@ -111,12 +115,12 @@ public class ReadWriteAnyElementTestCase { @Test public void testReadWriteUnknwonImpl() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); reader.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); // used for debug comparison // System.out.println(XML_UNKNOWN_IMPL); @@ -130,12 +134,12 @@ public class ReadWriteAnyElementTestCase { @Ignore() public void testReadWriteInvalidAttribute() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(XML_UNKNOWN_IMPL_WITH_INVALID_ATTRIBUTE)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); reader.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); // used for debug comparison // System.out.println(XML_UNKNOWN_IMPL); diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java index e86da1c8b4..7787361e62 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteLocalCompositeTestCase.java @@ -32,6 +32,7 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; @@ -50,7 +51,8 @@ public class ReadWriteLocalCompositeTestCase { private XMLInputFactory inputFactory; private ExtensibleStAXArtifactProcessor staxProcessor; - + private ProcessorContext context; + private static final String LOCAL_COMPOSITE_XML = "<?xml version='1.0' encoding='UTF-8'?>"+ "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" targetNamespace=\"http://localcalc\" name=\"LocalCalculator\" local=\"true\">"+ "</composite>"; @@ -58,13 +60,14 @@ public class ReadWriteLocalCompositeTestCase { @Before public void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor()); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); } @After @@ -76,7 +79,7 @@ public class ReadWriteLocalCompositeTestCase { public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("local.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite) staxProcessor.read(reader); + Composite composite = (Composite) staxProcessor.read(reader, context); assertNotNull(composite); assertTrue(composite.isLocal()); is.close(); @@ -86,13 +89,13 @@ public class ReadWriteLocalCompositeTestCase { public void testWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("local.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite) staxProcessor.read(reader); + Composite composite = (Composite) staxProcessor.read(reader, context); assertNotNull(composite); assertTrue(composite.isLocal()); is.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); System.out.println(bos.toString()); assertEquals(LOCAL_COMPOSITE_XML, bos.toString()); diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java index 1e8e838a45..3134a60bbb 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java @@ -31,6 +31,7 @@ import java.net.URL; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; @@ -52,14 +53,16 @@ public class ResolvePolicyTestCase { private static URLArtifactProcessor<Object> documentProcessor; private static ModelResolver resolver; private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor; + private static ProcessorContext context; @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); resolver = new DefaultModelResolver(); URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); // Create StAX processors @@ -72,23 +75,23 @@ public class ResolvePolicyTestCase { URL url = getClass().getResource("CalculatorComponent.constrainingType"); URI uri = URI.create("CalculatorComponent.constrainingType"); - ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url, context); assertNotNull(constrainingType); - resolver.addModel(constrainingType); + resolver.addModel(constrainingType, context); url = getClass().getResource("TestAllCalculator.composite"); uri = URI.create("TestAllCalculator.composite"); - Composite composite = (Composite)documentProcessor.read(null, uri, url); + Composite composite = (Composite)documentProcessor.read(null, uri, url, context); assertNotNull(composite); url = getClass().getResource("test_definitions.xml"); uri = URI.create("test_definitions.xml"); - Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url, context); assertNotNull(scaDefns); preResolvePolicyTests(composite); - documentProcessor.resolve(scaDefns, resolver); - documentProcessor.resolve(composite, resolver); + documentProcessor.resolve(scaDefns, resolver, context); + documentProcessor.resolve(composite, resolver, context); // Comment out the post resolving test // postResolvePolicyTests(composite); @@ -155,15 +158,15 @@ public class ResolvePolicyTestCase { public void testResolveComposite() throws Exception { URL url = getClass().getResource("Calculator.composite"); URI uri = URI.create("Calculator.composite"); - Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url); + Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url, context); assertNotNull(nestedComposite); - resolver.addModel(nestedComposite); + resolver.addModel(nestedComposite, context); url = getClass().getResource("TestAllCalculator.composite"); uri = URI.create("TestAllCalculator.composite"); - Composite composite = (Composite)documentProcessor.read(null, uri, url); + Composite composite = (Composite)documentProcessor.read(null, uri, url, context); - documentProcessor.resolve(composite, resolver); + documentProcessor.resolve(composite, resolver, context); assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java index cc8a88f3d5..81fefdc5ab 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java @@ -29,6 +29,7 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; @@ -48,10 +49,12 @@ public class ResolveTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessorExtensionPoint staxProcessors; private static ModelResolver resolver; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); resolver = new DefaultModelResolver(); @@ -62,19 +65,19 @@ public class ResolveTestCase { InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); StAXArtifactProcessor<ConstrainingType> constrainingTypeReader = staxProcessors.getProcessor(ConstrainingType.class); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - ConstrainingType constrainingType = constrainingTypeReader.read(reader); + ConstrainingType constrainingType = constrainingTypeReader.read(reader, context); is.close(); assertNotNull(constrainingType); - resolver.addModel(constrainingType); + resolver.addModel(constrainingType, context); is = getClass().getResourceAsStream("TestAllCalculator.composite"); StAXArtifactProcessor<Composite> compositeReader = staxProcessors.getProcessor(Composite.class); reader = inputFactory.createXMLStreamReader(is); - Composite composite = compositeReader.read(reader); + Composite composite = compositeReader.read(reader, context); is.close(); assertNotNull(composite); - compositeReader.resolve(composite, resolver); + compositeReader.resolve(composite, resolver, context); assertEquals(composite.getConstrainingType(), constrainingType); assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); @@ -85,17 +88,17 @@ public class ResolveTestCase { InputStream is = getClass().getResourceAsStream("Calculator.composite"); StAXArtifactProcessor<Composite> compositeReader = staxProcessors.getProcessor(Composite.class); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite nestedComposite = compositeReader.read(reader); + Composite nestedComposite = compositeReader.read(reader, context); is.close(); assertNotNull(nestedComposite); - resolver.addModel(nestedComposite); + resolver.addModel(nestedComposite, context); is = getClass().getResourceAsStream("TestAllCalculator.composite"); reader = inputFactory.createXMLStreamReader(is); - Composite composite = compositeReader.read(reader); + Composite composite = compositeReader.read(reader, context); is.close(); - compositeReader.resolve(composite, resolver); + compositeReader.resolve(composite, resolver, context); assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java index 1a100c25b1..b6f4c11ac2 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java @@ -27,6 +27,7 @@ import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -42,11 +43,11 @@ public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements return ATTRIBUTE; } - public String read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public String read(QName attributeName, XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { return reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart()); } - public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(String value, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.setPrefix(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI()); writer.writeAttribute(ATTRIBUTE.getLocalPart(), value); } @@ -55,7 +56,7 @@ public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements return String.class; } - public void resolve(String arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(String arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java index 6180a940d4..cfec8dee7a 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java @@ -26,6 +26,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.policy.PolicyExpression; @@ -41,11 +42,11 @@ public class TestPolicyProcessor implements StAXArtifactProcessor<PolicyExpressi return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); } - public PolicyExpression read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException { + public PolicyExpression read(XMLStreamReader arg0, ProcessorContext context) throws ContributionReadException, XMLStreamException { return new MockPolicyImplOne(); } - public void write(PolicyExpression arg0, XMLStreamWriter arg1) throws ContributionWriteException, + public void write(PolicyExpression arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, XMLStreamException { } @@ -53,7 +54,7 @@ public class TestPolicyProcessor implements StAXArtifactProcessor<PolicyExpressi return PolicyExpression.class; } - public void resolve(PolicyExpression arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(PolicyExpression arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } public class MockPolicyImplOne implements PolicyExpression { diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java index 1fba771a7e..c4b2f773a9 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java @@ -36,6 +36,7 @@ import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; @@ -59,13 +60,15 @@ public class WireTestCase { private static StAXArtifactProcessor<Object> staxProcessor; private static ModelResolver resolver; private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); resolver = new DefaultModelResolver(); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); @@ -80,25 +83,25 @@ public class WireTestCase { public void testResolveConstrainingType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(reader); + ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(reader, context); is.close(); assertNotNull(constrainingType); - resolver.addModel(constrainingType); + resolver.addModel(constrainingType, context); is = getClass().getResourceAsStream("TestAllCalculator.composite"); reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); is.close(); assertNotNull(composite); URL url = getClass().getResource("test_definitions.xml"); URI uri = URI.create("test_definitions.xml"); - Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url, context); assertNotNull(scaDefns); - policyDefinitionsProcessor.resolve(scaDefns, resolver); + policyDefinitionsProcessor.resolve(scaDefns, resolver, context); - staxProcessor.resolve(composite, resolver); + staxProcessor.resolve(composite, resolver, context); assertEquals(composite.getConstrainingType(), constrainingType); assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); @@ -108,18 +111,18 @@ public class WireTestCase { public void testResolveComposite() throws Exception { Composite nestedComposite = readComposite("Calculator.composite"); assertNotNull(nestedComposite); - resolver.addModel(nestedComposite); + resolver.addModel(nestedComposite, context); Composite composite = readComposite("TestAllCalculator.composite"); URL url = getClass().getResource("test_definitions.xml"); URI uri = URI.create("test_definitions.xml"); - Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url, context); assertNotNull(scaDefns); - policyDefinitionsProcessor.resolve(scaDefns, resolver); + policyDefinitionsProcessor.resolve(scaDefns, resolver, context); - staxProcessor.resolve(composite, resolver); + staxProcessor.resolve(composite, resolver, context); assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); } @@ -127,7 +130,7 @@ public class WireTestCase { private Composite readComposite(String resource) throws XMLStreamException, ContributionReadException, IOException { InputStream is = getClass().getResourceAsStream(resource); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); is.close(); return composite; } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java index 6a2c9278fc..4726205f98 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java @@ -37,6 +37,7 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; @@ -59,14 +60,16 @@ public class WriteAllTestCase { private static ExtensibleStAXArtifactProcessor staxProcessor; private static ModelResolver resolver; private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor; + private static ProcessorContext context; @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); resolver = new DefaultModelResolver(); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); @@ -80,16 +83,16 @@ public class WriteAllTestCase { @Test public void testReadWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); - Composite composite = staxProcessor.read(is, Composite.class); + Composite composite = staxProcessor.read(is, Composite.class, context); verifyComposite(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); bos.close(); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - composite = staxProcessor.read(bis, Composite.class); + composite = staxProcessor.read(bis, Composite.class, context); verifyComposite(composite); @@ -98,36 +101,36 @@ public class WriteAllTestCase { @Test public void testReadWireWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); - Composite composite = staxProcessor.read(is, Composite.class); + Composite composite = staxProcessor.read(is, Composite.class, context); URL url = getClass().getResource("test_definitions.xml"); URI uri = URI.create("test_definitions.xml"); - Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + Definitions scaDefns = (Definitions)policyDefinitionsProcessor.read(null, uri, url, context); assertNotNull(scaDefns); - policyDefinitionsProcessor.resolve(scaDefns, resolver); + policyDefinitionsProcessor.resolve(scaDefns, resolver, context); - staxProcessor.resolve(composite, resolver); + staxProcessor.resolve(composite, resolver, context); // compositeBuilder.build(composite, null, monitor); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, bos); + staxProcessor.write(composite, bos, context); } @Test public void testReadWriteComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); - ComponentType componentType = staxProcessor.read(is, ComponentType.class); - staxProcessor.resolve(componentType, resolver); + ComponentType componentType = staxProcessor.read(is, ComponentType.class, context); + staxProcessor.resolve(componentType, resolver, context); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(componentType, bos); + staxProcessor.write(componentType, bos, context); } @Test public void testReadWriteConstrainingType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); - ConstrainingType constrainingType = staxProcessor.read(is, ConstrainingType.class); - staxProcessor.resolve(constrainingType, resolver); + ConstrainingType constrainingType = staxProcessor.read(is, ConstrainingType.class, context); + staxProcessor.resolve(constrainingType, resolver, context); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(constrainingType, bos); + staxProcessor.write(constrainingType, bos, context); } private void verifyComposite(Composite composite) { diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java index dedd0d0660..f50cd5811f 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java @@ -33,6 +33,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; @@ -50,10 +51,13 @@ public class WriteNamespacesTestCase { private static StAXArtifactProcessor<Composite> compositeProcessor; private static XMLOutputFactory outputFactory; private static XMLInputFactory inputFactory; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); outputFactory = modelFactories.getFactory(XMLOutputFactory.class); //outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); @@ -69,7 +73,7 @@ public class WriteNamespacesTestCase { // Read InputStream is = getClass().getResourceAsStream("NestedCalculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = compositeProcessor.read(reader); + Composite composite = compositeProcessor.read(reader, context); Component component = composite.getComponents().get(0); Composite implementation = (Composite)component.getImplementation(); QName qname = implementation.getName(); @@ -77,13 +81,13 @@ public class WriteNamespacesTestCase { // Write ByteArrayOutputStream bos = new ByteArrayOutputStream(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos); - compositeProcessor.write(composite, writer); + compositeProcessor.write(composite, writer, context); System.out.println(bos); // Read again is = new ByteArrayInputStream(bos.toByteArray()); reader = inputFactory.createXMLStreamReader(is); - composite = compositeProcessor.read(reader); + composite = compositeProcessor.read(reader, context); // Compare component = composite.getComponents().get(0); diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java index 7b9400b300..b1720ea8e6 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/ReadDocumentTestCase.java @@ -32,6 +32,7 @@ import java.util.Map; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; @@ -76,11 +77,13 @@ public class ReadDocumentTestCase { private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity"); private static final QName wsBinding = new QName(scaNamespace, "binding.ws"); private static final QName javaImpl = new QName(scaNamespace, "implementation.java"); + private static ProcessorContext context; @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - + context = new ProcessorContext(extensionPoints); + // Create StAX processors StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); @@ -92,7 +95,7 @@ public class ReadDocumentTestCase { URL url = ReadDocumentTestCase.class.getResource("test_definitions.xml"); URI uri = URI.create("test_definitions.xml"); - definitions = policyDefinitionsProcessor.read(null, uri, url); + definitions = policyDefinitionsProcessor.read(null, uri, url, context); for (Intent intent : definitions.getIntents()) { intentTable.put(intent.getName(), intent); @@ -194,7 +197,7 @@ public class ReadDocumentTestCase { assertNull(javaImplType.getMayProvidedIntents().get(0).getDescription()); ModelResolver resolver = new DefaultModelResolver(); - policyDefinitionsProcessor.resolve(definitions, resolver); + policyDefinitionsProcessor.resolve(definitions, resolver, context); //builder.build(scaDefinitions); //testing if policy intents have been linked have property been linked up diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java index 89ec2d0ee9..a148e33029 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/definitions/xml/TestPolicyProcessor.java @@ -26,6 +26,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -39,18 +40,18 @@ public class TestPolicyProcessor implements StAXArtifactProcessor<MockPolicy> { return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); } - public MockPolicy read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException { + public MockPolicy read(XMLStreamReader arg0, ProcessorContext context) throws ContributionReadException, XMLStreamException { return new MockPolicy(); } - public void write(MockPolicy arg0, XMLStreamWriter arg1) throws ContributionWriteException, XMLStreamException { + public void write(MockPolicy arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, XMLStreamException { } public Class<MockPolicy> getModelType() { return MockPolicy.class; } - public void resolve(MockPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(MockPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java index ec19584dbd..c39dede56d 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java @@ -38,15 +38,12 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; 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.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.policy.BindingType; import org.apache.tuscany.sca.policy.ExtensionType; import org.apache.tuscany.sca.policy.ImplementationType; @@ -66,8 +63,8 @@ public class ReadDocumentTestCase { private ModelResolver resolver; private StAXArtifactProcessor<Object> staxProcessor; - private Monitor monitor; - + private ProcessorContext context; + private static final QName elementToProcess = new QName("http://docs.oasis-open.org/ns/opencsa/sca/200903", "implementationType"); @@ -94,17 +91,12 @@ public class ReadDocumentTestCase { public void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); resolver = new DefaultModelResolver(); + context = new ProcessorContext(extensionPoints); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - // Create a monitor - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = new DefaultMonitorFactory(); - if (monitorFactory != null) { - monitor = monitorFactory.createMonitor(); - utilities.addUtility(monitorFactory); - } + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); URL url = getClass().getResource("test_definitions.xml"); @@ -124,7 +116,7 @@ public class ReadDocumentTestCase { int event = reader.getEventType(); switch (event) { case START_ELEMENT: { - Object artifact = staxProcessor.read(reader); + Object artifact = staxProcessor.read(reader, context); if (artifact instanceof PolicySet) { PolicySet policySet = (PolicySet)artifact; policySet.setName(new QName(namespace, policySet.getName().getLocalPart())); @@ -136,7 +128,7 @@ public class ReadDocumentTestCase { for (Intent i : intent.getQualifiedIntents()) { i.setName(new QName(namespace, i.getName().getLocalPart())); intentTable.put(i.getName(), i); - resolver.addModel(i); + resolver.addModel(i, context); } } else if (artifact instanceof BindingType) { BindingType bindingType = (BindingType)artifact; @@ -147,7 +139,7 @@ public class ReadDocumentTestCase { } if (artifact != null) { - resolver.addModel(artifact); + resolver.addModel(artifact, context); } break; @@ -229,25 +221,25 @@ public class ReadDocumentTestCase { List<Intent> intents = new ArrayList<Intent>(intentTable.values()); for (Intent intent : intents) { - staxProcessor.resolve(intent, resolver); + staxProcessor.resolve(intent, resolver, context); } for (PolicySet policySet : policySetTable.values()) { if (policySet.getReferencedPolicySets().isEmpty()) - staxProcessor.resolve(policySet, resolver); + staxProcessor.resolve(policySet, resolver, context); } for (PolicySet policySet : policySetTable.values()) { if (!policySet.getReferencedPolicySets().isEmpty()) - staxProcessor.resolve(policySet, resolver); + staxProcessor.resolve(policySet, resolver, context); } for (ExtensionType bindingType : bindingTypesTable.values()) { - staxProcessor.resolve(bindingType, resolver); + staxProcessor.resolve(bindingType, resolver, context); } for (ExtensionType implType : implTypesTable.values()) { - staxProcessor.resolve(implType, resolver); + staxProcessor.resolve(implType, resolver, context); } //testing if policy intents have been linked have property been linked up diff --git a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java index 08a2b3b2eb..aea2c3adb8 100644 --- a/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java +++ b/java/sca/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java @@ -26,6 +26,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.policy.PolicyExpression; @@ -40,11 +41,11 @@ public class TestPolicyProcessor implements StAXArtifactProcessor<PolicyExpressi return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); } - public PolicyExpression read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException { + public PolicyExpression read(XMLStreamReader arg0, ProcessorContext context) throws ContributionReadException, XMLStreamException { return new MockPolicyImplOne(); } - public void write(PolicyExpression arg0, XMLStreamWriter arg1) throws ContributionWriteException, XMLStreamException { + public void write(PolicyExpression arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, XMLStreamException { } public Class<PolicyExpression> getModelType() { @@ -52,7 +53,7 @@ public class TestPolicyProcessor implements StAXArtifactProcessor<PolicyExpressi return PolicyExpression.class; } - public void resolve(PolicyExpression arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(PolicyExpression arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } |