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 | |
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')
240 files changed, 4400 insertions, 4812 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 { } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java index 4b875d9b34..5f10af6510 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java @@ -24,7 +24,6 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.monitor.Monitor; /** * A builder that handles any build-time configuration needed by bindings. @@ -38,8 +37,9 @@ public interface BindingBuilder<B extends Binding> { * * @param component The component for the binding's service or reference * @param contract The binding's service or reference + * @param context TODO */ - void build(Component component, Contract contract, B binding, Monitor monitor); + void build(Component component, Contract contract, B binding, BuilderContext context); /** * Get QName of the binding type diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderContext.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderContext.java new file mode 100644 index 0000000000..8a16fac9e4 --- /dev/null +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderContext.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder; + +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +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.monitor.DefaultMonitorFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; + +/** + * + */ +public class BuilderContext { + protected Definitions definitions; + protected Map<QName, List<String>> bindingBaseURIs = Collections.emptyMap(); + protected Monitor monitor; + + /** + * @param definitions + * @param bindingBaseURIs + * @param monitor + */ + public BuilderContext(Definitions definitions, Map<QName, List<String>> bindingBaseURIs, Monitor monitor) { + super(); + this.definitions = definitions; + if (bindingBaseURIs != null) { + this.bindingBaseURIs = bindingBaseURIs; + } + this.monitor = monitor; + } + + public BuilderContext(Monitor monitor) { + super(); + this.monitor = monitor; + } + + public BuilderContext(ExtensionPointRegistry registry) { + super(); + MonitorFactory monitorFactory = + registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class); + this.monitor = monitorFactory.createMonitor(); + } + + public BuilderContext() { + super(); + this.monitor = new DefaultMonitorFactory().createMonitor(); + } + + public Monitor getMonitor() { + return monitor; + } + + public Monitor setMonitor(Monitor monitor) { + Monitor old = this.monitor; + this.monitor = monitor; + return old; + } + + public Definitions getDefinitions() { + return definitions; + } + + public Map<QName, List<String>> getBindingBaseURIs() { + return bindingBaseURIs; + } + + public void setDefinitions(Definitions definitions) { + this.definitions = definitions; + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java index e6aaa2d4bb..50bf10f54a 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java @@ -20,8 +20,6 @@ package org.apache.tuscany.sca.assembly.builder; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; /** * A builder that handles the configuration of the components inside a @@ -42,13 +40,12 @@ public interface CompositeBuilder { * Build a composite. * * @param composite The composite - * @param definitions SCA definitions - * @param monitor + * @param context The builder context * @return The composite built from the original one. In most cases, it is the same as the orginal one as * most builders only change the content of the composite. * * @throws CompositeBuilderException */ - Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException; + Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException; } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java index d414913a12..6d85405861 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java @@ -22,11 +22,9 @@ package org.apache.tuscany.sca.assembly.builder; import java.lang.reflect.Constructor; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.xml.namespace.QName; -import javax.xml.ws.EndpointReference; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; @@ -38,12 +36,10 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.LifeCycleListener; 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.ServiceDeclarationParser; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.Monitor; /** * Default implementation of a provider factory extension point. @@ -198,7 +194,7 @@ public class DefaultBuilderExtensionPoint implements BuilderExtensionPoint, Life * A wrapper around a composite builder allowing lazy * loading and initialization of implementation providers. */ - private class LazyCompositeBuilder implements CompositeBuilder, DeployedCompositeBuilder { + private class LazyCompositeBuilder implements CompositeBuilder { private FactoryExtensionPoint factories; private InterfaceContractMapper mapper; @@ -223,16 +219,9 @@ public class DefaultBuilderExtensionPoint implements BuilderExtensionPoint, Life return id; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - return getBuilder().build(composite, definitions, monitor); - } - - public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { - return ((DeployedCompositeBuilder)getBuilder()).build(composite, definitions, bindingBaseURIs, monitor); + return getBuilder().build(composite, context); } private CompositeBuilder getBuilder() { @@ -279,8 +268,8 @@ public class DefaultBuilderExtensionPoint implements BuilderExtensionPoint, Life this.qname = ServiceDeclarationParser.getQName(sd.getAttributes().get("qname")); } - public void build(Component component, Contract contract, Binding binding, Monitor monitor) { - getBuilder().build(component, contract, binding, monitor); + public void build(Component component, Contract contract, Binding binding, BuilderContext context) { + getBuilder().build(component, contract, binding, context); } public QName getBindingType() { @@ -323,8 +312,8 @@ public class DefaultBuilderExtensionPoint implements BuilderExtensionPoint, Life this.qname = ServiceDeclarationParser.getQName(sd.getAttributes().get("qname")); } - public void build(Component component, Implementation implementation, Monitor monitor) { - getBuilder().build(component, implementation, monitor); + public void build(Component component, Implementation implementation, BuilderContext context) { + getBuilder().build(component, implementation, context); } public QName getImplementationType() { @@ -366,8 +355,8 @@ public class DefaultBuilderExtensionPoint implements BuilderExtensionPoint, Life this.qname = ServiceDeclarationParser.getQName(sd.getAttributes().get("qname")); } - public void build(Component component, Implementation implementation, Definitions definitions, Monitor monitor) { - getBuilder().build(component, implementation, definitions, monitor); + public void build(Component component, Implementation implementation, BuilderContext context) { + getBuilder().build(component, implementation, context); } public QName getPolicyType() { @@ -393,12 +382,12 @@ public class DefaultBuilderExtensionPoint implements BuilderExtensionPoint, Life return builder; } - public void build(Endpoint endpoint, Definitions definitions, Monitor monitor) { - getBuilder().build(endpoint, definitions, monitor); + public void build(Endpoint endpoint, BuilderContext context) { + getBuilder().build(endpoint, context); } - public void build(org.apache.tuscany.sca.assembly.EndpointReference endpointReference, Definitions definitions, Monitor monitor) { - getBuilder().build(endpointReference, definitions, monitor); + public void build(org.apache.tuscany.sca.assembly.EndpointReference endpointReference, BuilderContext context) { + getBuilder().build(endpointReference, context); } } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DeployedCompositeBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DeployedCompositeBuilder.java deleted file mode 100644 index 75c7b676e8..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DeployedCompositeBuilder.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder; - -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A builder that handles the configuration of the components inside a - * composite and the wiring of component references to component services. - * - * @version $Rev$ $Date$ - */ -public interface DeployedCompositeBuilder { - - /** - * Returns the ID of the builder. - * - * @return - */ - String getID(); - - /** - * Build a composite. - * - * @param composite - * @param definitions - * @param monitor - * @return - * @throws CompositeBuilderException - */ - Composite build(Composite composite, Definitions definitions, Map<QName, List<String>> bindingBaseURIs, Monitor monitor) - throws CompositeBuilderException; - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java index 6790d0188b..b1e22e195d 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java @@ -23,7 +23,6 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.monitor.Monitor; /** * A builder that handles any build-time configuration needed by implementations. @@ -36,9 +35,10 @@ public interface ImplementationBuilder<I extends Implementation> { * Configure a component implementation. * * @param component The component + * @param context TODO * @param contract The implementation */ - void build(Component component, I implmentation, Monitor monitor); + void build(Component component, I implmentation, BuilderContext context); /** * Get the QName of the implementation type diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java index b22bef8951..2df42c2c23 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java @@ -25,8 +25,6 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; /** * A builder that is contributed by a specific policy languange to validate the configurations @@ -38,25 +36,22 @@ public interface PolicyBuilder<T> { /** * Build (and validate) the policy settings on the endpoint * @param endpoint - * @param definitions * @param monitor */ - void build(Endpoint endpoint, Definitions definitions, Monitor monitor); + void build(Endpoint endpoint, BuilderContext context); /** * Build (and validate) the policy settings on the endpoint reference * @param endpointReference - * @param definitions * @param monitor */ - void build(EndpointReference endpointReference, Definitions definitions, Monitor monitor); + void build(EndpointReference endpointReference, BuilderContext context); /** * Build (and validate) the policy settings on the component implementation * @param component * @param implementation - * @param definitions * @param monitor */ - void build(Component component, Implementation implementation, Definitions definitions, Monitor monitor); + void build(Component component, Implementation implementation, BuilderContext context); } diff --git a/java/sca/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java b/java/sca/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java index d9fb0264ad..6b8ff10d1a 100644 --- a/java/sca/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java +++ b/java/sca/modules/binding-atom/src/test/java/org/apache/tuscany/sca/binding/atom/AtomBindingProcessorTestCase.java @@ -29,13 +29,10 @@ import junit.framework.TestCase; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; /** * @version $Rev$ $Date$ @@ -55,23 +52,16 @@ public class AtomBindingProcessorTestCase extends TestCase { private XMLInputFactory inputFactory; private StAXArtifactProcessor<Object> staxProcessor; - private Monitor monitor; + private ProcessorContext context; @Override protected void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); - // Create a monitor - FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = factories.getFactory(MonitorFactory.class); - if (monitorFactory != null) { - monitor = monitorFactory.createMonitor(); - utilities.addUtility(monitorFactory); - } StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } /** @@ -81,7 +71,7 @@ public class AtomBindingProcessorTestCase extends TestCase { public void testLoadValidComposite() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); AtomBinding binding = (AtomBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); diff --git a/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java b/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java index 1c678a05d1..af0eb8ea08 100644 --- a/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java +++ b/java/sca/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/impl/EJBBindingProcessor.java @@ -30,6 +30,7 @@ import org.apache.tuscany.sca.binding.ejb.EJBBindingFactory; 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; @@ -59,14 +60,13 @@ import org.apache.tuscany.sca.policy.PolicyFactory; public class EJBBindingProcessor implements StAXArtifactProcessor<EJBBinding> { private PolicyFactory policyFactory; private PolicySubjectProcessor policyProcessor; - private Monitor monitor; + private EJBBindingFactory ejbBindingFactory; - public EJBBindingProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public EJBBindingProcessor(FactoryExtensionPoint modelFactories) { this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.ejbBindingFactory = modelFactories.getFactory(EJBBindingFactory.class); this.policyProcessor = new PolicySubjectProcessor(policyFactory); - this.monitor = monitor; } /** @@ -76,7 +76,7 @@ public class EJBBindingProcessor implements StAXArtifactProcessor<EJBBinding> { * @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(), "binding-ejb-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -93,7 +93,7 @@ public class EJBBindingProcessor implements StAXArtifactProcessor<EJBBinding> { /** * {@inheritDoc} */ - public EJBBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public EJBBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { EJBBinding ejbBinding = ejbBindingFactory.createEJBBinding(); // Read the policies @@ -128,7 +128,7 @@ public class EJBBindingProcessor implements StAXArtifactProcessor<EJBBinding> { } else if (ejbVersion.equals("EJB3")) { ejbBinding.setEjbVersion(EJBBinding.EJBVersion.EJB3); } else { - error("UnknownEJBVersion", reader, ejbVersion, name); + error(context.getMonitor(), "UnknownEJBVersion", reader, ejbVersion, name); } } @@ -141,7 +141,7 @@ public class EJBBindingProcessor implements StAXArtifactProcessor<EJBBinding> { return ejbBinding; } - public void write(EJBBinding ejbBinding, XMLStreamWriter writer) throws ContributionWriteException, + public void write(EJBBinding ejbBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write a <binding.ejb> writer.writeStartElement(Constants.SCA11_NS, EJBBinding.BINDING_EJB); @@ -162,6 +162,6 @@ public class EJBBindingProcessor implements StAXArtifactProcessor<EJBBinding> { return EJBBinding.class; } - public void resolve(EJBBinding ejbBinding, ModelResolver modelResolver) throws ContributionResolveException { + public void resolve(EJBBinding ejbBinding, ModelResolver modelResolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java b/java/sca/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java index baa0e44087..056bb8a75e 100644 --- a/java/sca/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java +++ b/java/sca/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java @@ -35,14 +35,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.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; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<HTTPBinding> { private static final String NAME = "name"; @@ -51,17 +49,15 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S private HTTPBindingFactory httpBindingFactory; private StAXArtifactProcessor<Object> extensionProcessor; private StAXAttributeProcessor<Object> extensionAttributeProcessor; - private Monitor monitor; + public HTTPBindingProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor, - Monitor monitor) { + StAXAttributeProcessor extensionAttributeProcessor) { FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); this.httpBindingFactory = modelFactories.getFactory(HTTPBindingFactory.class); this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; this.extensionAttributeProcessor = extensionAttributeProcessor; - this.monitor = monitor; } public QName getArtifactType() { @@ -72,7 +68,7 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S return HTTPBinding.class; } - public HTTPBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public HTTPBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { HTTPBinding httpBinding = httpBindingFactory.createHTTPBinding(); while(reader.hasNext()) { @@ -94,7 +90,7 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S } } else { // Read an extension element - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null) { if (extension instanceof WireFormat) { httpBinding.setRequestWireFormat((WireFormat)extension); @@ -118,7 +114,7 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S return httpBinding; } - public void write(HTTPBinding httpBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(HTTPBinding httpBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { //writer.writeStartElement(Constants.SCA10_NS, BINDING_HTTP); writeStart(writer, HTTPBinding.TYPE.getNamespaceURI(), HTTPBinding.TYPE.getLocalPart()); @@ -138,37 +134,9 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S } - public void resolve(HTTPBinding model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(HTTPBinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Should not need to do anything here for now... } - /** - * Report a warning. - * - * @param problems - * @param message - * @param model - */ - private void warning(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "binding-http-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "binding-http-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java index ef21b6d4c3..be5673bc60 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessor.java @@ -50,6 +50,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; @@ -136,17 +137,16 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St private PolicySubjectProcessor policyProcessor; private ConfiguredOperationProcessor configuredOperationProcessor; protected StAXArtifactProcessor<Object> extensionProcessor; - private Monitor monitor; + private FactoryExtensionPoint modelFactories; // DOB - public JMSBindingProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { + public JMSBindingProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor) { this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.policyProcessor = new PolicySubjectProcessor(policyFactory); this.configuredOperationProcessor = - new ConfiguredOperationProcessor(modelFactories, this.monitor); + new ConfiguredOperationProcessor(modelFactories); this.extensionProcessor = extensionProcessor; - this.monitor = monitor; this.modelFactories = modelFactories; } @@ -157,7 +157,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * @param message * @param model */ - private void warning(String message, Object model, Object... messageParameters) { + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "binding-jms-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -172,7 +172,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * @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(), "binding-jms-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -187,7 +187,8 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St return JMSBinding.class; } - public JMSBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JMSBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + Monitor monitor = context.getMonitor(); JMSBinding jmsBinding = new JMSBinding(); // Reset validation message to keep track of validation issues. @@ -203,7 +204,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St // Read binding URI String uri = reader.getAttributeValue(null, "uri"); if (uri != null && uri.length() > 0) { - parseURI(uri, jmsBinding); + parseURI(uri, jmsBinding, monitor); } // Read correlation scheme @@ -212,7 +213,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (JMSBindingConstants.VALID_CORRELATION_SCHEMES.contains(correlationScheme.toLowerCase())) { jmsBinding.setCorrelationScheme(correlationScheme); } else { - error("InvalidCorrelationScheme", reader, correlationScheme); + error(monitor, "InvalidCorrelationScheme", reader, correlationScheme); } } @@ -277,28 +278,28 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St case START_ELEMENT: String elementName = reader.getName().getLocalPart(); if ("destination".equals(elementName)) { - parseDestination(reader, jmsBinding); + parseDestination(reader, jmsBinding, monitor); } else if ("connectionFactory".equals(elementName)) { - parseConnectionFactory(reader, jmsBinding); + parseConnectionFactory(reader, jmsBinding, monitor); } else if ("activationSpec".equals(elementName)) { - parseActivationSpec(reader, jmsBinding); + parseActivationSpec(reader, jmsBinding, monitor); } else if ("response".equals(elementName)) { - parseResponse(reader, jmsBinding); + parseResponse(reader, jmsBinding, context); } else if ("resourceAdapter".equals(elementName)) { - parseResourceAdapter(reader, jmsBinding); + parseResourceAdapter(reader, jmsBinding, monitor); } else if ("headers".equals(elementName)) { - parseHeaders(reader, jmsBinding); + parseHeaders(reader, jmsBinding, monitor); } else if ("operationProperties".equals(elementName)) { - parseOperationProperties(reader, jmsBinding); + parseOperationProperties(reader, jmsBinding, monitor); } else if ("messageSelection".equals(elementName)) { parseSubscriptionHeaders(reader, jmsBinding); } else if (Constants.OPERATION_QNAME.equals(reader.getName())) { - ConfiguredOperation confOp = configuredOperationProcessor.read(reader); + ConfiguredOperation confOp = configuredOperationProcessor.read(reader, context); if (confOp != null) { ((OperationsConfigurator)jmsBinding).getConfiguredOperations().add(confOp); } } else { - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null) { if (extension instanceof WireFormat) { if (jmsBinding.getRequestWireFormat() == null) { @@ -314,7 +315,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St } } else { - error("UnexpectedElement", reader, extension.toString()); + error(monitor, "UnexpectedElement", reader, extension.toString()); } } } @@ -331,7 +332,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (x.equals(JMSBindingConstants.BINDING_JMS_QNAME)) { endFound = true; } else { - error("UnexpectedElement: expected " + JMSBindingConstants.BINDING_JMS_QNAME + ", found " + x.toString(), + error(monitor, "UnexpectedElement: expected " + JMSBindingConstants.BINDING_JMS_QNAME + ", found " + x.toString(), reader, x.toString()); } } @@ -352,14 +353,14 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St jmsBinding.setResponseWireFormat(jmsBinding.getRequestWireFormat()); } - validate( jmsBinding ); + validate( jmsBinding, monitor ); return jmsBinding; } - protected void parseURI(String uri, JMSBinding jmsBinding) { + protected void parseURI(String uri, JMSBinding jmsBinding, Monitor monitor) { if (!uri.startsWith("jms:")) { - error("MustStartWithSchema", jmsBinding, uri); + error(monitor, "MustStartWithSchema", jmsBinding, uri); return; } int i = uri.indexOf('?'); @@ -370,7 +371,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (s.startsWith("connectionFactoryName=")) { jmsBinding.setConnectionFactoryName(s.substring(22)); } else { - error("UnknownTokenInURI", jmsBinding, s, uri); + error(monitor, "UnknownTokenInURI", jmsBinding, s, uri); return; } } @@ -380,31 +381,32 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St } } - public void resolve(JMSBinding model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(JMSBinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); if (model.getRequestConnectionName() != null) { - model.setRequestConnectionBinding(getConnectionBinding(model, "requestConnection", model.getRequestConnectionName(), resolver)); + model.setRequestConnectionBinding(getConnectionBinding(model, "requestConnection", model.getRequestConnectionName(), resolver, context)); } if (model.getResponseConnectionName() != null) { - model.setResponseConnectionBinding(getConnectionBinding(model, "responseConnection", model.getResponseConnectionName(), resolver)); + model.setResponseConnectionBinding(getConnectionBinding(model, "responseConnection", model.getResponseConnectionName(), resolver, context)); } if (model.getOperationPropertiesName() != null) { - model.setOperationPropertiesBinding(getConnectionBinding(model, "operationProperties", model.getOperationPropertiesName(), resolver)); + model.setOperationPropertiesBinding(getConnectionBinding(model, "operationProperties", model.getOperationPropertiesName(), resolver, context)); } } @SuppressWarnings("unchecked") - private JMSBinding getConnectionBinding(JMSBinding model, String attrName, QName bindingName, ModelResolver resolver) { + private JMSBinding getConnectionBinding(JMSBinding model, String attrName, QName bindingName, ModelResolver resolver, ProcessorContext context) { JMSBinding binding = new JMSBinding(); binding.setTargetNamespace(bindingName.getNamespaceURI()); binding.setName(bindingName.getLocalPart()); binding.setUnresolved(true); - binding = resolver.resolveModel(JMSBinding.class, binding); + binding = resolver.resolveModel(JMSBinding.class, binding, context); if (binding.isUnresolved()) - error("BindingNotFound", model, attrName, bindingName); + error(context.getMonitor(), "BindingNotFound", model, attrName, bindingName); return binding; } - private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseDestination(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "jndiName"); if (name != null && name.length() > 0) { jmsBinding.setDestinationName(name); @@ -412,13 +414,13 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St String type = reader.getAttributeValue(null, "type"); if (type != null && type.length() > 0) { - warning("DoesntProcessDestinationType", jmsBinding); + warning(monitor, "DoesntProcessDestinationType", jmsBinding); if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { jmsBinding.setDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); } else { - error("InvalidDestinationType", reader, type); + error(monitor, "InvalidDestinationType", reader, type); } } @@ -427,30 +429,30 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St jmsBinding.setDestinationCreate(create); } - jmsBinding.getDestinationProperties().putAll(parseBindingProperties(reader)); + jmsBinding.getDestinationProperties().putAll(parseBindingProperties(reader, monitor)); } - private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "jndiName"); if (name != null && name.length() > 0) { jmsBinding.setConnectionFactoryName(name); } else { - error("MissingConnectionFactoryName", reader); + error(monitor, "MissingConnectionFactoryName", reader); } - jmsBinding.getConnectionFactoryProperties().putAll(parseBindingProperties(reader)); + jmsBinding.getConnectionFactoryProperties().putAll(parseBindingProperties(reader, monitor)); } - private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name != null && name.length() > 0) { jmsBinding.setActivationSpecName(name); } else { - warning("MissingActivationSpecName", reader); + warning(monitor, "MissingActivationSpecName", reader); } - jmsBinding.getActivationSpecProperties().putAll(parseBindingProperties(reader)); + jmsBinding.getActivationSpecProperties().putAll(parseBindingProperties(reader, monitor)); } - private void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseResponseDestination(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "jndiName"); if (name != null && name.length() > 0) { jmsBinding.setResponseDestinationName(name); @@ -458,13 +460,13 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St String type = reader.getAttributeValue(null, "type"); if (type != null && type.length() > 0) { - warning("DoesntProcessResponseDestinationType", jmsBinding); + warning(monitor, "DoesntProcessResponseDestinationType", jmsBinding); if (JMSBindingConstants.DESTINATION_TYPE_QUEUE.equalsIgnoreCase(type)) { jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_QUEUE); } else if (JMSBindingConstants.DESTINATION_TYPE_TOPIC.equalsIgnoreCase(type)) { jmsBinding.setResponseDestinationType(JMSBindingConstants.DESTINATION_TYPE_TOPIC); } else { - error("InvalidResponseDestinationType", reader, type); + error(monitor, "InvalidResponseDestinationType", reader, type); } } @@ -473,43 +475,44 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St jmsBinding.setResponseDestinationCreate(create); } - jmsBinding.getResponseDestinationProperties().putAll(parseBindingProperties(reader)); + jmsBinding.getResponseDestinationProperties().putAll(parseBindingProperties(reader, monitor)); } - private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseResponseConnectionFactory(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "jndiName"); if (name != null && name.length() > 0) { jmsBinding.setResponseConnectionFactoryName(name); } else { - warning("MissingResponseConnectionFactory", reader); + warning(monitor, "MissingResponseConnectionFactory", reader); } - jmsBinding.getResponseConnectionFactoryProperties().putAll(parseBindingProperties(reader)); + jmsBinding.getResponseConnectionFactoryProperties().putAll(parseBindingProperties(reader, monitor)); } - private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseResponseActivationSpec(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name != null && name.length() > 0) { jmsBinding.setResponseActivationSpecName(name); } else { - warning("MissingResponseActivationSpec", reader); + warning(monitor, "MissingResponseActivationSpec", reader); } - jmsBinding.getResponseActivationSpecProperties().putAll(parseBindingProperties(reader)); + jmsBinding.getResponseActivationSpecProperties().putAll(parseBindingProperties(reader, monitor)); } - private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding) throws ContributionReadException, XMLStreamException { + private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Read sub-elements of response + Monitor monitor = context.getMonitor(); while (true) { switch (reader.next()) { case START_ELEMENT: String elementName = reader.getName().getLocalPart(); if ("destination".equals(elementName)) { - parseResponseDestination(reader, jmsBinding); + parseResponseDestination(reader, jmsBinding, context.getMonitor()); } else if ("connectionFactory".equals(elementName)) { - parseResponseConnectionFactory(reader, jmsBinding); + parseResponseConnectionFactory(reader, jmsBinding, monitor); } else if ("activationSpec".equals(elementName)) { - parseResponseActivationSpec(reader, jmsBinding); + parseResponseActivationSpec(reader, jmsBinding, monitor); } else { - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null) { if (extension instanceof WireFormat) { if (jmsBinding.getResponseWireFormat() == null) { @@ -518,7 +521,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St throw new ContributionReadException("The response wireformat has already been defined. " + "Only one response wire format can be specified."); } } else { - error("UnexpectedElement", reader, extension.toString()); + error(context.getMonitor(), "UnexpectedElement", reader, extension.toString()); } } reader.next(); @@ -530,20 +533,20 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (x.getLocalPart().equals("response")) { return; } else { - error("UnexpectedResponseElement", reader, x.toString()); + error(context.getMonitor(), "UnexpectedResponseElement", reader, x.toString()); } } } } - private void parseResourceAdapter(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseResourceAdapter(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name != null && name.length() > 0) { jmsBinding.setResourceAdapterName(name); } else { - error("MissingResourceAdapterName", reader); + error(monitor, "MissingResourceAdapterName", reader); } - jmsBinding.getResourceAdapterProperties().putAll(parseBindingProperties(reader)); + jmsBinding.getResourceAdapterProperties().putAll(parseBindingProperties(reader, monitor)); } /** @@ -555,7 +558,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * <property name=”NMTOKEN” type=”NMTOKEN”?>* * </headers>? */ - private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseHeaders(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { String jmsType = reader.getAttributeValue(null, "type"); if (jmsType != null && jmsType.length() > 0) { jmsBinding.setJMSType(jmsType); @@ -568,7 +571,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St } else if ("nonpersistent".equalsIgnoreCase(jmsDeliveryMode)) { jmsBinding.setJMSDeliveryMode(false); } else { - error("InvalidJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + error(monitor, "InvalidJMSDeliveryMode", jmsBinding, jmsDeliveryMode); } } @@ -584,10 +587,10 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (p >= 0 && p <= 9) { jmsBinding.setJMSPriority(p); } else { - warning("InvalidJMSPriority", jmsBinding, jmsPriority); + warning(monitor, "InvalidJMSPriority", jmsBinding, jmsPriority); } } catch (NumberFormatException ex) { - error("InvalidJMSPriority", jmsBinding, jmsPriority); + error(monitor, "InvalidJMSPriority", jmsBinding, jmsPriority); } } @@ -603,7 +606,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (x.getLocalPart().equals("headers")) { return; } else { - error("UnexpectedResponseElement", reader, x.toString()); + error(monitor, "UnexpectedResponseElement", reader, x.toString()); } } } @@ -648,15 +651,15 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * </headers>? * </operationProperties>* */ - private void parseOperationProperties(XMLStreamReader reader, JMSBinding jmsBinding) throws XMLStreamException { + private void parseOperationProperties(XMLStreamReader reader, JMSBinding jmsBinding, Monitor monitor) throws XMLStreamException { if (jmsBinding.getOperationPropertiesName() != null) { - error("DuplicateOperationProperties", jmsBinding); + error(monitor, "DuplicateOperationProperties", jmsBinding); } String opName = reader.getAttributeValue(null, "name"); if (opName == null || opName.length() < 1) { - warning("MissingJMSOperationPropertyName", jmsBinding); + warning(monitor, "MissingJMSOperationPropertyName", jmsBinding); return; } // Since nativeOpName, headers, and property elements are optional, must add opName. @@ -671,9 +674,9 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St switch (reader.next()) { case START_ELEMENT: if (reader.getName().getLocalPart().equals("headers")) { // optional - parseOperationHeaders(reader, jmsBinding, opName); + parseOperationHeaders(reader, jmsBinding, opName, monitor); } else if (reader.getName().getLocalPart().equals("property")) { // optional - processProperty(reader, props); + processProperty(reader, props, monitor); } break; case END_ELEMENT: @@ -689,14 +692,14 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St jmsBinding.getOperationPropertiesProperties(opName).putAll(props); return; } else { - error("UnexpectedResponseElement", reader, x.toString()); + error(monitor, "UnexpectedResponseElement", reader, x.toString()); } } } } } - private void parseOperationHeaders(XMLStreamReader reader, JMSBinding jmsBinding, String opName) throws XMLStreamException { + private void parseOperationHeaders(XMLStreamReader reader, JMSBinding jmsBinding, String opName, Monitor monitor) throws XMLStreamException { String jmsType = reader.getAttributeValue(null, "type"); if (jmsType != null && jmsType.length() > 0) { jmsBinding.setOperationJMSType(opName, jmsType); @@ -709,7 +712,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St } else if ("nonpersistent".equalsIgnoreCase(jmsDeliveryMode)) { jmsBinding.setOperationJMSDeliveryMode(opName, false); } else { - error("InvalidOPJMSDeliveryMode", jmsBinding, jmsDeliveryMode); + error(monitor, "InvalidOPJMSDeliveryMode", jmsBinding, jmsDeliveryMode); } } @@ -725,10 +728,10 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (p >= 0 && p <= 9) { jmsBinding.setOperationJMSPriority(opName, p); } else { - warning("InvalidOPJMSPriority", jmsBinding, jmsPriority); + warning(monitor, "InvalidOPJMSPriority", jmsBinding, jmsPriority); } } catch (NumberFormatException ex) { - error("InvalidOPJMSPriority", jmsBinding, jmsPriority); + error(monitor, "InvalidOPJMSPriority", jmsBinding, jmsPriority); } } @@ -744,7 +747,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (x.getLocalPart().equals("headers")) { return; } else { - error("UnexpectedResponseElement", reader, x.toString()); + error(monitor, "UnexpectedResponseElement", reader, x.toString()); } } } @@ -790,7 +793,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St } // end while } - private Map<String, BindingProperty> parseBindingProperties(XMLStreamReader reader) throws XMLStreamException { + private Map<String, BindingProperty> parseBindingProperties(XMLStreamReader reader, Monitor monitor) throws XMLStreamException { Map<String, BindingProperty> props = new HashMap<String, BindingProperty>(); String parentName = reader.getName().getLocalPart(); // Parse for all the properties within this element, until the end of @@ -801,7 +804,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St case START_ELEMENT: String elementName = reader.getName().getLocalPart(); if ("property".equals(elementName)) { - processProperty(reader, props); + processProperty(reader, props, monitor); } break; case END_ELEMENT: @@ -815,10 +818,10 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St return props; } - private void processProperty(XMLStreamReader reader, Map<String, BindingProperty> props) throws XMLStreamException { + private void processProperty(XMLStreamReader reader, Map<String, BindingProperty> props, Monitor monitor) throws XMLStreamException { String name = reader.getAttributeValue(null, "name"); if (name == null || name.length() < 1) { - error("InvalidPropertyElement", reader); + error(monitor, "InvalidPropertyElement", reader); } String type = reader.getAttributeValue(null, "type"); String value = reader.getElementText(); @@ -833,7 +836,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * The older validate() now calls validate(JMSBinding jmsBinding) with a null model. */ public void validate() { - validate( null ); + validate( null, null ); } /** @@ -846,7 +849,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * @param jmsBinding an optional JMS binding model to check for validity. * @since 1.4 */ - protected void validate( JMSBinding jmsBinding ) { + protected void validate( JMSBinding jmsBinding, Monitor monitor ) { // If no JMSBinding model is provided, that is all the validation we can do. if ( jmsBinding == null ) { return; @@ -857,12 +860,12 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 )) { if (JMSBindingConstants.DESTINATION_TYPE_QUEUE == jmsBinding.getDestinationType()) { if ( connectionFactoryName.contains( "topic" )) { - error("DestinationQueueContradiction", jmsBinding, connectionFactoryName ); + error(monitor, "DestinationQueueContradiction", jmsBinding, connectionFactoryName ); } } if (JMSBindingConstants.DESTINATION_TYPE_TOPIC == jmsBinding.getDestinationType()) { if ( connectionFactoryName.contains( "queue" )) { - error("DestinationTopicContradiction", jmsBinding, connectionFactoryName ); + error(monitor, "DestinationTopicContradiction", jmsBinding, connectionFactoryName ); } } } @@ -871,7 +874,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (( connectionFactoryName != null ) && ( connectionFactoryName.length() > 0 )) { String activationSpecName = jmsBinding.getActivationSpecName(); if ((activationSpecName != null) && (activationSpecName.length() > 0 )) { - error("ConnectionFactoryActivationSpecContradiction", jmsBinding, connectionFactoryName, activationSpecName ); + error(monitor, "ConnectionFactoryActivationSpecContradiction", jmsBinding, connectionFactoryName, activationSpecName ); } } @@ -883,7 +886,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if (( responseConnectionName != null ) && ( responseConnectionName.getLocalPart().length() > 0 )) { String responseDestinationName = jmsBinding.getResponseDestinationName(); if (( responseDestinationName != null ) && (responseDestinationName.length() > 0)) { - error("ResponseAttrElement", jmsBinding, responseConnectionName, responseDestinationName ); + error(monitor, "ResponseAttrElement", jmsBinding, responseConnectionName, responseDestinationName ); } } @@ -904,11 +907,10 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * responseConnection="QName"? * operationProperties="QName"? * ...> - * - * @param jmsBinding JMSBinding model * @param writer an XMLStreamWriter that writes XML attributes and elements + * @param jmsBinding JMSBinding model */ - public void write(JMSBinding jmsBinding, XMLStreamWriter writer) throws ContributionWriteException, + public void write(JMSBinding jmsBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write a <binding.jms> writeStart(writer, Constants.SCA11_NS, JMSBindingConstants.BINDING_JMS, @@ -975,7 +977,7 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St if ((jmsBinding.getResponseWireFormat() != null) && !(jmsBinding.getResponseWireFormat() instanceof WireFormatJMSDefault)){ - writeWireFormat(jmsBinding.getResponseWireFormat(), writer); + writeWireFormat(jmsBinding.getResponseWireFormat(), writer, context); } writer.writeEndElement(); @@ -985,16 +987,16 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St writeResourceAdapterProperties( jmsBinding, writer ); - writeConfiguredOperations( jmsBinding, writer ); + writeConfiguredOperations( jmsBinding, writer, context ); if ((jmsBinding.getRequestWireFormat() != null) && !(jmsBinding.getRequestWireFormat() instanceof WireFormatJMSDefault)){ - writeWireFormat(jmsBinding.getRequestWireFormat(), writer); + writeWireFormat(jmsBinding.getRequestWireFormat(), writer, context); } if ((jmsBinding.getOperationSelector() != null) && !(jmsBinding.getOperationSelector() instanceof OperationSelectorJMSDefault)){ - writeOperationSelector(jmsBinding.getOperationSelector(), writer); + writeOperationSelector(jmsBinding.getOperationSelector(), writer, context); } writeEnd(writer); @@ -1500,14 +1502,14 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * <operation name=\"op1\" requires=\"IntentOne IntentTwo\"/>" * </binding.jms>" */ - private void writeConfiguredOperations( JMSBinding jmsBinding, XMLStreamWriter writer) throws XMLStreamException, ContributionWriteException { + private void writeConfiguredOperations( JMSBinding jmsBinding, XMLStreamWriter writer, ProcessorContext context) throws XMLStreamException, ContributionWriteException { List<ConfiguredOperation> configOps = jmsBinding.getConfiguredOperations(); if (configOps == null || (configOps.size() < 1)) { return; } for( Iterator<ConfiguredOperation> it = configOps.iterator(); it.hasNext();) { - configuredOperationProcessor.write(it.next(), writer); + configuredOperationProcessor.write(it.next(), writer, context); } // Strange bug. Without white space, headers end tag improperly read. @@ -1521,8 +1523,8 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * @param wireFormat * @param writer */ - private void writeWireFormat(WireFormat wireFormat, XMLStreamWriter writer ) throws XMLStreamException, ContributionWriteException { - extensionProcessor.write(wireFormat, writer); + private void writeWireFormat(WireFormat wireFormat, XMLStreamWriter writer, ProcessorContext context ) throws XMLStreamException, ContributionWriteException { + extensionProcessor.write(wireFormat, writer, context); } /** @@ -1532,8 +1534,8 @@ public class JMSBindingProcessor extends BaseStAXArtifactProcessor implements St * @param operationSeletor * @param writer */ - private void writeOperationSelector(OperationSelector operationSeletor, XMLStreamWriter writer ) throws XMLStreamException, ContributionWriteException{ - extensionProcessor.write(operationSeletor, writer); + private void writeOperationSelector(OperationSelector operationSeletor, XMLStreamWriter writer, ProcessorContext context ) throws XMLStreamException, ContributionWriteException{ + extensionProcessor.write(operationSeletor, writer, context); } } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java index 715f371243..4f09eeb9a5 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSDefaultProcessor.java @@ -29,10 +29,10 @@ 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.monitor.Monitor; /** * @@ -44,17 +44,17 @@ public class OperationSelectorJMSDefaultProcessor extends BaseStAXArtifactProces return OperationSelectorJMSDefault.OPERATION_SELECTOR_JMS_DEFAULT_QNAME; } - public OperationSelectorJMSDefaultProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public OperationSelectorJMSDefaultProcessor(FactoryExtensionPoint modelFactories) { } - public OperationSelectorJMSDefault read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public OperationSelectorJMSDefault read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { OperationSelectorJMSDefault wireFormat = new OperationSelectorJMSDefault(); return wireFormat; } - public void write(OperationSelectorJMSDefault wireFormat, XMLStreamWriter writer) + public void write(OperationSelectorJMSDefault wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -69,7 +69,7 @@ public class OperationSelectorJMSDefaultProcessor extends BaseStAXArtifactProces return OperationSelectorJMSDefault.class; } - public void resolve(OperationSelectorJMSDefault arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(OperationSelectorJMSDefault arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java index 84ce89c505..9b731ffb1b 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/operationselector/OperationSelectorJMSUserPropProcessor.java @@ -29,10 +29,10 @@ 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.monitor.Monitor; /** * @@ -44,11 +44,11 @@ public class OperationSelectorJMSUserPropProcessor extends BaseStAXArtifactProce return OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_QNAME; } - public OperationSelectorJMSUserPropProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public OperationSelectorJMSUserPropProcessor(FactoryExtensionPoint modelFactories) { } - public OperationSelectorJMSUserProp read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public OperationSelectorJMSUserProp read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { OperationSelectorJMSUserProp opSelector = new OperationSelectorJMSUserProp(); String propertyName = reader.getAttributeValue(null, OperationSelectorJMSUserProp.OPERATION_SELECTOR_JMS_USERPROP_ATTR); if (propertyName != null && propertyName.length() > 0) { @@ -61,7 +61,7 @@ public class OperationSelectorJMSUserPropProcessor extends BaseStAXArtifactProce return opSelector; } - public void write(OperationSelectorJMSUserProp opSelector, XMLStreamWriter writer) + public void write(OperationSelectorJMSUserProp opSelector, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -80,7 +80,7 @@ public class OperationSelectorJMSUserPropProcessor extends BaseStAXArtifactProce return OperationSelectorJMSUserProp.class; } - public void resolve(OperationSelectorJMSUserProp arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(OperationSelectorJMSUserProp arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java index b73119efa0..4322595515 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/authentication/token/JMSTokenAuthenticationPolicyProcessor.java @@ -31,10 +31,10 @@ 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; -import org.apache.tuscany.sca.monitor.Monitor; /** * @@ -46,11 +46,11 @@ public class JMSTokenAuthenticationPolicyProcessor extends BaseStAXArtifactProce return JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME; } - public JMSTokenAuthenticationPolicyProcessor(ExtensionPointRegistry modelFactories, Monitor monitor) { + public JMSTokenAuthenticationPolicyProcessor(ExtensionPointRegistry registry) { } - public JMSTokenAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JMSTokenAuthenticationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { JMSTokenAuthenticationPolicy policy = new JMSTokenAuthenticationPolicy(); int event = reader.getEventType(); QName name = null; @@ -82,7 +82,7 @@ public class JMSTokenAuthenticationPolicyProcessor extends BaseStAXArtifactProce return policy; } - public void write(JMSTokenAuthenticationPolicy policy, XMLStreamWriter writer) + public void write(JMSTokenAuthenticationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -104,7 +104,7 @@ public class JMSTokenAuthenticationPolicyProcessor extends BaseStAXArtifactProce return JMSTokenAuthenticationPolicy.class; } - public void resolve(JMSTokenAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(JMSTokenAuthenticationPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java index fc60c33470..c925c01554 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/policy/header/JMSHeaderPolicyProcessor.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.core.ExtensionPointRegistry; @@ -45,14 +46,13 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<JMSHeaderPolicy> { - private Monitor monitor; + public QName getArtifactType() { return JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME; } - public JMSHeaderPolicyProcessor(ExtensionPointRegistry modelFactories, Monitor monitor) { - this.monitor = monitor; + public JMSHeaderPolicyProcessor(ExtensionPointRegistry modelFactories) { } /** @@ -62,7 +62,7 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen * @param model * @param messageParameters */ - protected void warning(String message, Object model, String... messageParameters) { + protected void warning(Monitor monitor, String message, Object model, String... messageParameters) { if (monitor != null){ Problem problem = monitor.createProblem(this.getClass().getName(), Messages.RESOURCE_BUNDLE, Severity.WARNING, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -76,7 +76,7 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen * @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(), Messages.RESOURCE_BUNDLE, Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -84,11 +84,11 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen } - public JMSHeaderPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JMSHeaderPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { JMSHeaderPolicy policy = new JMSHeaderPolicy(); int event = reader.getEventType(); QName name = null; - + Monitor monitor = context.getMonitor(); while (reader.hasNext()) { event = reader.getEventType(); switch (event) { @@ -106,7 +106,7 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen } else if (deliveryMode.equals("NON_PERSISTENT")){ policy.setDeliveryModePersistent(false); } else { - error("InvalidDeliveryMode", policy, deliveryMode); + error(monitor, "InvalidDeliveryMode", policy, deliveryMode); } } @@ -116,7 +116,7 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen try { policy.setTimeToLive(Long.valueOf(timeToLive)); } catch (NumberFormatException ex){ - error("InvalidTimeToLive", policy, timeToLive); + error(monitor, "InvalidTimeToLive", policy, timeToLive); } } @@ -126,7 +126,7 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen try { policy.setJmsPriority(Integer.valueOf(priority)); } catch (NumberFormatException ex){ - error("InvalidPriority", policy, priority); + error(monitor, "InvalidPriority", policy, priority); } } } else if (name.getLocalPart().equals(JMSHeaderPolicy.JMS_HEADER_JMS_PROPERTY)) { @@ -153,7 +153,7 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen return policy; } - public void write(JMSHeaderPolicy policy, XMLStreamWriter writer) + public void write(JMSHeaderPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -199,7 +199,7 @@ public class JMSHeaderPolicyProcessor extends BaseStAXArtifactProcessor implemen return JMSHeaderPolicy.class; } - public void resolve(JMSHeaderPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(JMSHeaderPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java index 9516b4abb5..8be904da3e 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesProcessor.java @@ -28,10 +28,10 @@ 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.monitor.Monitor; /** * @@ -43,17 +43,17 @@ public class WireFormatJMSBytesProcessor extends BaseStAXArtifactProcessor imple return WireFormatJMSBytes.WIRE_FORMAT_JMS_BYTES_QNAME; } - public WireFormatJMSBytesProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WireFormatJMSBytesProcessor(FactoryExtensionPoint modelFactories) { } - public WireFormatJMSBytes read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WireFormatJMSBytes read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { WireFormatJMSBytes wireFormat = new WireFormatJMSBytes(); return wireFormat; } - public void write(WireFormatJMSBytes wireFormat, XMLStreamWriter writer) + public void write(WireFormatJMSBytes wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -68,7 +68,7 @@ public class WireFormatJMSBytesProcessor extends BaseStAXArtifactProcessor imple return WireFormatJMSBytes.class; } - public void resolve(WireFormatJMSBytes arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(WireFormatJMSBytes arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java index 5b3ef777c5..33533b23eb 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSBytesXMLProcessor.java @@ -28,10 +28,10 @@ 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.monitor.Monitor; public class WireFormatJMSBytesXMLProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<WireFormatJMSBytesXML> { @@ -40,17 +40,17 @@ public class WireFormatJMSBytesXMLProcessor extends BaseStAXArtifactProcessor im return WireFormatJMSBytesXML.WIRE_FORMAT_JMS_BYTES_QNAME; } - public WireFormatJMSBytesXMLProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WireFormatJMSBytesXMLProcessor(FactoryExtensionPoint modelFactories) { } - public WireFormatJMSBytesXML read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WireFormatJMSBytesXML read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { WireFormatJMSBytesXML wireFormat = new WireFormatJMSBytesXML(); return wireFormat; } - public void write(WireFormatJMSBytesXML wireFormat, XMLStreamWriter writer) + public void write(WireFormatJMSBytesXML wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -65,7 +65,7 @@ public class WireFormatJMSBytesXMLProcessor extends BaseStAXArtifactProcessor im return WireFormatJMSBytesXML.class; } - public void resolve(WireFormatJMSBytesXML arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(WireFormatJMSBytesXML arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java index 35f13edc0c..6b5488a168 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSDefaultProcessor.java @@ -28,10 +28,10 @@ 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.monitor.Monitor; /** * @@ -43,10 +43,10 @@ public class WireFormatJMSDefaultProcessor extends BaseStAXArtifactProcessor imp return WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_QNAME; } - public WireFormatJMSDefaultProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WireFormatJMSDefaultProcessor(FactoryExtensionPoint modelFactories) { } - public WireFormatJMSDefault read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WireFormatJMSDefault read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { WireFormatJMSDefault wireFormat = new WireFormatJMSDefault(); String sendFormat = reader.getAttributeValue(null, WireFormatJMSDefault.WIRE_FORMAT_JMS_DEFAULT_FORMAT_ATTR); @@ -64,7 +64,7 @@ public class WireFormatJMSDefaultProcessor extends BaseStAXArtifactProcessor imp return wireFormat; } - public void write(WireFormatJMSDefault wireFormat, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(WireFormatJMSDefault wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, getArtifactType().getLocalPart(), getArtifactType().getNamespaceURI()); writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS); @@ -82,7 +82,7 @@ public class WireFormatJMSDefaultProcessor extends BaseStAXArtifactProcessor imp return WireFormatJMSDefault.class; } - public void resolve(WireFormatJMSDefault arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(WireFormatJMSDefault arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java index c393a131fb..cf0c0db0d7 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSObjectProcessor.java @@ -28,10 +28,10 @@ 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.monitor.Monitor; /** * @@ -43,11 +43,11 @@ public class WireFormatJMSObjectProcessor extends BaseStAXArtifactProcessor impl return WireFormatJMSObject.WIRE_FORMAT_JMS_BYTES_QNAME; } - public WireFormatJMSObjectProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WireFormatJMSObjectProcessor(FactoryExtensionPoint modelFactories) { } - public WireFormatJMSObject read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WireFormatJMSObject read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { WireFormatJMSObject wireFormat = new WireFormatJMSObject(); String wrappedSingleInput = reader.getAttributeValue(null, WireFormatJMSObject.WIRE_FORMAT_JMS_OBJECT_WRAP_SINGLE_ATTR); @@ -64,7 +64,7 @@ public class WireFormatJMSObjectProcessor extends BaseStAXArtifactProcessor impl return wireFormat; } - public void write(WireFormatJMSObject wireFormat, XMLStreamWriter writer) + public void write(WireFormatJMSObject wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -81,7 +81,7 @@ public class WireFormatJMSObjectProcessor extends BaseStAXArtifactProcessor impl return WireFormatJMSObject.class; } - public void resolve(WireFormatJMSObject arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(WireFormatJMSObject arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java index a27580a347..5c564e044c 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextProcessor.java @@ -28,10 +28,10 @@ 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.monitor.Monitor; /** * @@ -43,17 +43,17 @@ public class WireFormatJMSTextProcessor extends BaseStAXArtifactProcessor implem return WireFormatJMSText.WIRE_FORMAT_JMS_BYTES_QNAME; } - public WireFormatJMSTextProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WireFormatJMSTextProcessor(FactoryExtensionPoint modelFactories) { } - public WireFormatJMSText read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WireFormatJMSText read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { WireFormatJMSText wireFormat = new WireFormatJMSText(); return wireFormat; } - public void write(WireFormatJMSText wireFormat, XMLStreamWriter writer) + public void write(WireFormatJMSText wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -68,7 +68,7 @@ public class WireFormatJMSTextProcessor extends BaseStAXArtifactProcessor implem return WireFormatJMSText.class; } - public void resolve(WireFormatJMSText arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(WireFormatJMSText arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java index 7b7f4e0320..ae544f3163 100644 --- a/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java +++ b/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/wireformat/WireFormatJMSTextXMLProcessor.java @@ -28,10 +28,10 @@ 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.monitor.Monitor; /** * @@ -43,17 +43,17 @@ public class WireFormatJMSTextXMLProcessor extends BaseStAXArtifactProcessor imp return WireFormatJMSTextXML.WIRE_FORMAT_JMS_DEFAULT_QNAME; } - public WireFormatJMSTextXMLProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WireFormatJMSTextXMLProcessor(FactoryExtensionPoint modelFactories) { } - public WireFormatJMSTextXML read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WireFormatJMSTextXML read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { WireFormatJMSTextXML wireFormat = new WireFormatJMSTextXML(); return wireFormat; } - public void write(WireFormatJMSTextXML wireFormat, XMLStreamWriter writer) + public void write(WireFormatJMSTextXML wireFormat, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -68,7 +68,7 @@ public class WireFormatJMSTextXMLProcessor extends BaseStAXArtifactProcessor imp return WireFormatJMSTextXML.class; } - public void resolve(WireFormatJMSTextXML arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(WireFormatJMSTextXML arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java index 202277a2c2..dd30d5ee6b 100644 --- a/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java +++ b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorTestCase.java @@ -32,19 +32,14 @@ import junit.framework.TestCase; import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.OperationsConfigurator;
import org.apache.tuscany.sca.assembly.WireFormat;
-import org.apache.tuscany.sca.binding.jms.BindingProperty;
-import org.apache.tuscany.sca.binding.jms.JMSBinding;
-import org.apache.tuscany.sca.binding.jms.JMSBindingException;
import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSBytes;
import org.apache.tuscany.sca.binding.jms.wireformat.WireFormatJMSObject;
import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
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;
-import org.apache.tuscany.sca.core.UtilityExtensionPoint;
-import org.apache.tuscany.sca.monitor.Monitor;
-import org.apache.tuscany.sca.monitor.MonitorFactory;
/**
* Tests for JMS binding xml
@@ -398,21 +393,15 @@ public class JMSBindingProcessorTestCase extends TestCase { private XMLInputFactory inputFactory;
private StAXArtifactProcessor<Object> staxProcessor;
- private Monitor monitor;
+ private ProcessorContext context;
@Override
protected void setUp() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ context = new ProcessorContext(extensionPoints);
inputFactory = XMLInputFactory.newInstance();
- // Create a monitor
- UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
- MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
- if (monitorFactory != null) {
- monitor = monitorFactory.createMonitor();
- utilities.addUtility(monitorFactory);
- }
StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
- staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
}
@@ -423,7 +412,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testLoadValidComposite() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -433,7 +422,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testHeaders1() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(HEADERS1));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -446,7 +435,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testProperties1() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(PROPERTIES1));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -457,7 +446,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testOpProperties1() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPERTIES1));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -476,7 +465,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testSubscriptionHeaders () throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(SELECTOR));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -490,7 +479,7 @@ public class JMSBindingProcessorTestCase extends TestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID_URI));
try {
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
} catch(Exception e) {
// JMSBindingExceptions are expected with invalid composite.
if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) )
@@ -505,7 +494,7 @@ public class JMSBindingProcessorTestCase extends TestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(HEADERS_INVALID_PRIORITY));
try {
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
} catch(Exception e) {
// JMSBindingExceptions are expected with invalid composite.
if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) )
@@ -522,7 +511,7 @@ public class JMSBindingProcessorTestCase extends TestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID_RESPONSE_ATTR_ELEMENT));
try {
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
} catch(Exception e) {
// JMSBindingExceptions are expected with invalid composite.
if ( !e.getClass().isAssignableFrom( JMSBindingException.class ) )
@@ -535,7 +524,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testDestinationProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(DEST_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -553,7 +542,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testConnectionFactoryProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CF_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -571,7 +560,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testActivationSpecProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(AS_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -589,7 +578,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testResponseDestinationProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_DEST_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -607,7 +596,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testResponseConnectionFactoryProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_CF_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -625,7 +614,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testResponseActivationSpecProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RESP_AS_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -643,7 +632,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testOperationPropertiesProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPS_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -661,7 +650,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testResouceAdapterProperties() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(RES_ADPT_PROPS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -687,7 +676,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testOpProperties2() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROPERTIES1));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -720,7 +709,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testOpProperties3() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_NAMES_NO_PROPERTIES1));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -743,7 +732,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testConfiguredOperations1() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(CONFIGURED_OPERATIONS));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -761,7 +750,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testWireFormat() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(WIRE_FORMAT));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
@@ -775,7 +764,7 @@ public class JMSBindingProcessorTestCase extends TestCase { public void testOpPropertiesName() throws Exception {
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(OP_PROP_NAME));
- Composite composite = (Composite)staxProcessor.read(reader);
+ Composite composite = (Composite)staxProcessor.read(reader, context);
JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
assertNotNull(binding);
diff --git a/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java index f5eede8f41..468295df36 100644 --- a/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java +++ b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/JMSBindingProcessorWriteTestCase.java @@ -29,15 +29,12 @@ import javax.xml.stream.XMLStreamReader; import junit.framework.TestCase; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.binding.jms.JMSBinding; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; /** * Tests for JMS binding XML writes. @@ -49,7 +46,6 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXArtifactProcessor<Object> staxProcessor; - private Monitor monitor; public static final String DEFAULT = "<?xml version=\"1.0\" encoding=\"ASCII\"?>" @@ -71,13 +67,16 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { + " </component>" + "</composite>"; + private ProcessorContext context; + @Override protected void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } /** @@ -86,17 +85,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { */ public void testLoadValidComposite() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.COMPOSITE)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -105,17 +104,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { } public void testHeaders1() throws Exception { - Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.HEADERS1))); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.HEADERS1)), context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -125,17 +124,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testProperties1() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.PROPERTIES1)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -145,17 +144,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testOpProperties1() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROPERTIES1)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -166,17 +165,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testSubscriptionHeaders() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.SELECTOR)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -186,16 +185,16 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testDestinationProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.DEST_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -205,17 +204,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testConnectionFactoryProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.CF_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -225,17 +224,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testActivationSpecProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.AS_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -245,17 +244,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testResponseDestinationProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_DEST_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -265,17 +264,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testResponseConnectionFactoryProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_CF_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -285,17 +284,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testResponseActivationSpecProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RESP_AS_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -305,17 +304,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testOperationPropertiesProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROPS_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -326,17 +325,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testResouceAdapterProperties() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.RES_ADPT_PROPS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -347,17 +346,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testConfiguredOperations() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.CONFIGURED_OPERATIONS)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -368,17 +367,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testWireFormat() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.WIRE_FORMAT)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); @@ -391,12 +390,12 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testDefault() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(DEFAULT)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); System.out.println(bos.toString()); assertEquals(bos.toString(), @@ -419,17 +418,17 @@ public class JMSBindingProcessorWriteTestCase extends TestCase { public void testOperationPropertiesName() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(JMSBindingProcessorTestCase.OP_PROP_NAME)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); JMSBinding binding = (JMSBinding)composite.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding); // Write out JMSBinding model to stream. ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); // Read written JMSBinding to a different JMSBinding model. XMLStreamReader reader2 = inputFactory.createXMLStreamReader(new StringReader(bos.toString())); - Composite composite2 = (Composite)staxProcessor.read(reader2); + Composite composite2 = (Composite)staxProcessor.read(reader2, context); JMSBinding binding2 = (JMSBinding)composite2.getComponents().get(0).getServices().get(0).getBindings().get(0); assertNotNull(binding2); diff --git a/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java index 7bfb355c8a..5180427ec6 100644 --- a/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java +++ b/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/policy/PolicyProcessorTestCase.java @@ -40,6 +40,7 @@ import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAu import org.apache.tuscany.sca.binding.jms.policy.authentication.token.JMSTokenAuthenticationPolicyProcessor; import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicy; import org.apache.tuscany.sca.binding.jms.policy.header.JMSHeaderPolicyProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.junit.Ignore; import org.junit.Test; @@ -57,27 +58,27 @@ public class PolicyProcessorTestCase { public void testRead() throws Exception { List<String> results = new ArrayList<String>(); Map<QName, StAXArtifactProcessor> processors = new HashMap<QName, StAXArtifactProcessor>(); - processors.put(JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME, new JMSHeaderPolicyProcessor(null, null)); - processors.put(JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME, new JMSTokenAuthenticationPolicyProcessor(null, null)); + processors.put(JMSHeaderPolicy.JMS_HEADER_POLICY_QNAME, new JMSHeaderPolicyProcessor(null)); + processors.put(JMSTokenAuthenticationPolicy.JMS_TOKEN_AUTHENTICATION_POLICY_QNAME, new JMSTokenAuthenticationPolicyProcessor(null)); InputStream is = getClass().getResourceAsStream("mock_policy_definitions.xml"); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - + ProcessorContext context =new ProcessorContext(); while (true) { int event = reader.getEventType(); if (event == XMLStreamConstants.START_ELEMENT) { if ("policySet".equals(reader.getName().getLocalPart())) { reader.nextTag(); StAXArtifactProcessor processor = processors.get(reader.getName()); - Object xxx = processor.read(reader); + Object xxx = processor.read(reader, context); // Policy policy = (Policy)processor.read(reader); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(outputStream); - processor.write(xxx, writer); + processor.write(xxx, writer, context); // processor.write(policy, writer); writer.flush(); results.add(outputStream.toString()); diff --git a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java index c6d6f98de6..119d66d14d 100644 --- a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java +++ b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java @@ -28,6 +28,7 @@ import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.xml.CompositeModelResolver; 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,10 +56,11 @@ public class SCABindingTestCase { extensionPoints = new DefaultExtensionPointRegistry(); inputFactory = XMLInputFactory.newInstance(); - StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + StAXArtifactProcessorExtensionPoint staxProcessors = + extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); - resolver = new CompositeModelResolver(null, null, null); + resolver = new CompositeModelResolver(null, null); } @Test @@ -73,26 +75,29 @@ public class SCABindingTestCase { @Test @Ignore public void testBuildModel() { - try{ - InputStream is = getClass().getResourceAsStream("/Calculator.composite"); - XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + try { + InputStream is = getClass().getResourceAsStream("/Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ProcessorContext context = new ProcessorContext(extensionPoints); + Composite composite = (Composite)staxProcessor.read(reader, context); - is.close(); - Assert.assertNotNull(composite); + is.close(); + Assert.assertNotNull(composite); - resolver.addModel(composite); + resolver.addModel(composite, context); - staxProcessor.resolve(composite, resolver); + staxProcessor.resolve(composite, resolver, new ProcessorContext()); - SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0); - SCABinding serviceSCABinding = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0); + SCABinding referenceSCABinding = + (SCABinding)composite.getComponents().get(0).getReferences().get(0).getBindings().get(0); + SCABinding serviceSCABinding = + (SCABinding)composite.getComponents().get(1).getServices().get(0).getBindings().get(0); - Assert.assertNotNull(referenceSCABinding); - Assert.assertNotNull(serviceSCABinding); - } catch (Exception ex) { - Assert.fail(ex.getMessage()); - } + Assert.assertNotNull(referenceSCABinding); + Assert.assertNotNull(serviceSCABinding); + } catch (Exception ex) { + Assert.fail(ex.getMessage()); + } } } diff --git a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java index 6e0e0bbab7..895a551f79 100644 --- a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java +++ b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java @@ -30,6 +30,7 @@ import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.SCABinding; 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; @@ -47,21 +48,23 @@ 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, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } @Test public void testReadComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - ComponentType componentType = (ComponentType)staxProcessor.read(reader); + ComponentType componentType = (ComponentType)staxProcessor.read(reader, context); assertNotNull(componentType); SCABinding referenceSCABinding = (SCABinding) componentType.getReferences().get(0).getBindings().get(0); @@ -77,7 +80,7 @@ public class ReadTestCase { public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("/Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0); diff --git a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java index e40fc34fbc..be464172ed 100644 --- a/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java +++ b/java/sca/modules/binding-sca-runtime/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLOutputFactory; import org.apache.tuscany.sca.assembly.ComponentType; 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.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; @@ -48,24 +49,26 @@ public class WriteTestCase { private static StAXArtifactProcessor<Object> staxProcessor; private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; - + 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(); outputFactory = XMLOutputFactory.newInstance(); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } @Test @Ignore // broken in 2.0 bring up public void testReadWriteComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType"); - ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(componentType); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos), context); assertEquals("<?xml version='1.0' encoding='UTF-8'?><componentType xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" ><service name=\"CalculatorService\"><binding.sca /><interface.java interface=\"calculator.CalculatorService\" /></service><reference name=\"addService\"><binding.sca /><interface.java interface=\"calculator.AddService\" /></reference></componentType>", bos.toString()); } @@ -74,10 +77,10 @@ public class WriteTestCase { @Ignore // broken in 2.0 bring up public void testReadWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("/Calculator.composite"); - Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); assertEquals("<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\"><binding.sca /><interface.java interface=\"calculator.CalculatorService\" /></service><component name=\"CalculatorServiceComponent\"><implementation.java class=\"calculator.CalculatorServiceImpl\" /><reference name=\"addService\" target=\"AddServiceComponent\"><binding.sca /></reference><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\"><implementation.java class=\"calculator.AddServiceImpl\" /><service name=\"AddService\"><binding.sca /><interface.java interface=\"calculator.AddService\" /></service></component><component name=\"SubtractServiceComponent\"><implementation.java class=\"calculator.SubtractServiceImpl\" /></component><component name=\"MultiplyServiceComponent\"><implementation.java class=\"calculator.MultiplyServiceImpl\" /></component><component name=\"DivideServiceComponent\"><implementation.java class=\"calculator.DivideServiceImpl\" /></component></composite>", bos.toString()); } diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java index 9b1f870cee..0d08d42bc5 100644 --- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java +++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/authentication/token/Axis2TokenAuthenticationPolicyProcessor.java @@ -30,10 +30,10 @@ 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.monitor.Monitor; /** * @@ -47,11 +47,11 @@ public class Axis2TokenAuthenticationPolicyProcessor extends BaseStAXArtifactPro return Axis2TokenAuthenticationPolicy.AXIS2_TOKEN_AUTHENTICATION_POLICY_QNAME; } - public Axis2TokenAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public Axis2TokenAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories) { } - public Axis2TokenAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Axis2TokenAuthenticationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { Axis2TokenAuthenticationPolicy policy = new Axis2TokenAuthenticationPolicy(); int event = reader.getEventType(); QName name = null; @@ -83,7 +83,7 @@ public class Axis2TokenAuthenticationPolicyProcessor extends BaseStAXArtifactPro return policy; } - public void write(Axis2TokenAuthenticationPolicy policy, XMLStreamWriter writer) + public void write(Axis2TokenAuthenticationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -106,7 +106,7 @@ public class Axis2TokenAuthenticationPolicyProcessor extends BaseStAXArtifactPro return Axis2TokenAuthenticationPolicy.class; } - public void resolve(Axis2TokenAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(Axis2TokenAuthenticationPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java index 33a1688138..c13c009edf 100644 --- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java +++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/Axis2ConfigParamPolicyProcessor.java @@ -33,10 +33,10 @@ import org.apache.axiom.om.OMFactory; 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; /** * @@ -49,10 +49,10 @@ public class Axis2ConfigParamPolicyProcessor implements StAXArtifactProcessor<Ax return AXIS2_CONFIG_PARAM_POLICY_QNAME; } - public Axis2ConfigParamPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public Axis2ConfigParamPolicyProcessor(FactoryExtensionPoint modelFactories) { } - public Axis2ConfigParamPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Axis2ConfigParamPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { Axis2ConfigParamPolicy policy = new Axis2ConfigParamPolicy(); int event = reader.getEventType(); QName name = null; @@ -87,7 +87,7 @@ public class Axis2ConfigParamPolicyProcessor implements StAXArtifactProcessor<Ax return policy; } - public void write(Axis2ConfigParamPolicy arg0, XMLStreamWriter arg1) throws ContributionWriteException, + public void write(Axis2ConfigParamPolicy arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, XMLStreamException { } @@ -95,7 +95,7 @@ public class Axis2ConfigParamPolicyProcessor implements StAXArtifactProcessor<Ax return Axis2ConfigParamPolicy.class; } - public void resolve(Axis2ConfigParamPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(Axis2ConfigParamPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java index 70afbd22ee..7c163e5db2 100644 --- a/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java +++ b/java/sca/modules/binding-ws-axis2-policy/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/header/Axis2HeaderPolicyProcessor.java @@ -30,10 +30,10 @@ 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.monitor.Monitor; /** * @@ -46,11 +46,11 @@ public class Axis2HeaderPolicyProcessor extends BaseStAXArtifactProcessor implem return Axis2HeaderPolicy.AXIS2_HEADER_POLICY_QNAME; } - public Axis2HeaderPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public Axis2HeaderPolicyProcessor(FactoryExtensionPoint modelFactories) { } - public Axis2HeaderPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Axis2HeaderPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { Axis2HeaderPolicy policy = new Axis2HeaderPolicy(); int event = reader.getEventType(); QName name = null; @@ -82,7 +82,7 @@ public class Axis2HeaderPolicyProcessor extends BaseStAXArtifactProcessor implem return policy; } - public void write(Axis2HeaderPolicy policy, XMLStreamWriter writer) + public void write(Axis2HeaderPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -105,7 +105,7 @@ public class Axis2HeaderPolicyProcessor extends BaseStAXArtifactProcessor implem return Axis2HeaderPolicy.class; } - public void resolve(Axis2HeaderPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(Axis2HeaderPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.java b/java/sca/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.java index 44533fe0b6..44f98b157c 100644 --- a/java/sca/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.java +++ b/java/sca/modules/binding-ws-axis2-policy/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/policy/configuration/PolicyReadTestCase.java @@ -28,6 +28,7 @@ import javax.xml.stream.XMLStreamReader; import junit.framework.TestCase; 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; @@ -45,14 +46,14 @@ public class PolicyReadTestCase extends TestCase { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - StAXArtifactProcessor<Object> staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + StAXArtifactProcessor<Object> staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); URL url = getClass().getResource("mock_policies.xml"); InputStream urlStream = url.openStream(); XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); - Axis2ConfigParamPolicy policy = (Axis2ConfigParamPolicy)staxProcessor.read(reader); + Axis2ConfigParamPolicy policy = (Axis2ConfigParamPolicy)staxProcessor.read(reader, new ProcessorContext(extensionPoints)); assertEquals(policy.getParamElements().size(), 2); } diff --git a/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java b/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java index 04763a3c4b..f1b4942c92 100644 --- a/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java +++ b/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGenerator.java @@ -331,7 +331,7 @@ public class BindingWSDLGenerator { wsdlInterface.setPortType(portType); try { - wsdlFactory.createWSDLInterface(wsdlInterface, portType, wsdlDefinition, resolver); + wsdlFactory.createWSDLInterface(wsdlInterface, portType, wsdlDefinition, resolver, monitor); } catch (InvalidInterfaceException e) { throw new WSDLGenerationException(e); } diff --git a/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java b/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java index 3d1ac356b7..e30298db33 100644 --- a/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java +++ b/java/sca/modules/binding-ws-wsdlgen/src/main/java/org/apache/tuscany/sca/binding/ws/wsdlgen/WebServiceBindingBuilder.java @@ -24,9 +24,9 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.monitor.Monitor; /** * A factory for the calculated WSDL document needed by Web Service bindings. @@ -44,8 +44,8 @@ public class WebServiceBindingBuilder implements BindingBuilder<WebServiceBindin /** * Create a calculated WSDL document and save it in the Web Service binding. */ - public void build(Component component, Contract contract, WebServiceBinding binding, Monitor monitor) { - BindingWSDLGenerator.generateWSDL(component, contract, binding, extensionPoints, monitor); + public void build(Component component, Contract contract, WebServiceBinding binding, BuilderContext context) { + BindingWSDLGenerator.generateWSDL(component, contract, binding, extensionPoints, context.getMonitor()); } public QName getBindingType() { diff --git a/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java b/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java index fe7b9abf58..c1031e14ae 100644 --- a/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java +++ b/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/BindingWSDLGeneratorTestCase.java @@ -61,7 +61,7 @@ public class BindingWSDLGeneratorTestCase extends TestCase { new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, null).visitInterface(iface); new DataBindingJavaInterfaceProcessor(registry).visitInterface(iface); javaIC.setInterface(iface); - WSDLInterfaceContract wsdlIC = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC, false, new XSDModelResolver(null, null, null), dataBindings, wsdlFactory, xsdFactory, documentBuilderFactory, null); + WSDLInterfaceContract wsdlIC = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC, false, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory, documentBuilderFactory, null); assertNotNull(wsdlIC); WSDLInterface wsdlInterface = (WSDLInterface)wsdlIC.getInterface(); assertNotNull(wsdlInterface); @@ -74,7 +74,7 @@ public class BindingWSDLGeneratorTestCase extends TestCase { new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, null).visitInterface(iface2); new DataBindingJavaInterfaceProcessor(registry).visitInterface(iface2); javaIC2.setInterface(iface2); - WSDLInterfaceContract wsdlIC2 = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC2, false, new XSDModelResolver(null, null, null), dataBindings, wsdlFactory, xsdFactory, documentBuilderFactory, null); + WSDLInterfaceContract wsdlIC2 = BindingWSDLGenerator.createWSDLInterfaceContract(javaIC2, false, new XSDModelResolver(null, null), dataBindings, wsdlFactory, xsdFactory, documentBuilderFactory, null); assertNotNull(wsdlIC2); } diff --git a/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java b/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java index f34d5912c3..22f7f01ec9 100644 --- a/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java +++ b/java/sca/modules/binding-ws-wsdlgen/src/test/java/org/apache/tuscany/sca/binding/ws/wsdlgen/Interface2WSDLGeneratorTestCase.java @@ -62,7 +62,7 @@ public class Interface2WSDLGeneratorTestCase { DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); WSDLDefinition wsdlDefinition = wFactory.createWSDLDefinition(); XSDFactory factory = new DefaultXSDFactory(); - Interface2WSDLGenerator generator = new Interface2WSDLGenerator(false, new XSDModelResolver(null, null, null), dataBindings, factory, documentBuilderFactory, null); + Interface2WSDLGenerator generator = new Interface2WSDLGenerator(false, new XSDModelResolver(null, null), dataBindings, factory, documentBuilderFactory, null); Definition definition = generator.generate(iface, wsdlDefinition); // print the generated WSDL file and inline schemas diff --git a/java/sca/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java b/java/sca/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java index 6eac53a7f5..2966a1ef81 100644 --- a/java/sca/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java +++ b/java/sca/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java @@ -39,11 +39,11 @@ import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; 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; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; @@ -51,7 +51,6 @@ import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; import org.apache.tuscany.sca.policy.PolicyFactory; @@ -69,7 +68,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ private PolicyFactory policyFactory; private PolicySubjectProcessor policyProcessor; //private PolicyFactory intentAttachPointTypeFactory; - private Monitor monitor; + public WebServiceBindingProcessor(ExtensionPointRegistry extensionPoints) { this.extensionPoints = extensionPoints; @@ -78,12 +77,6 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ this.wsFactory = modelFactories.getFactory(WebServiceBindingFactory.class); this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); this.policyProcessor = new PolicySubjectProcessor(policyFactory); - //this.intentAttachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class); - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) { - this.monitor = monitorFactory.createMonitor(); - } } /** @@ -93,7 +86,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ * @param message * @param model */ - private void warning(String message, Object model, Object... messageParameters) { + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "binding-wsxml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -107,15 +100,15 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ * @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(), "binding-wsxml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } } - public WebServiceBinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { - + public WebServiceBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + Monitor monitor = context.getMonitor(); // Read a <binding.ws> WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); /*ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType(); @@ -146,7 +139,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ if (wsdlElement != null) { int index = wsdlElement.indexOf('#'); if (index == -1) { - error("InvalidWsdlElementAttr", reader, wsdlElement); + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); return wsBinding; } @@ -165,7 +158,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ localName = localName.substring("wsdl.port(".length(), localName.length() - 1); int s = localName.indexOf('/'); if (s == -1) { - error("InvalidWsdlElementAttr", reader, wsdlElement); + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); } else { wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); @@ -177,7 +170,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ localName = localName.substring("wsdl.endpoint(".length(), localName.length() - 1); int s = localName.indexOf('/'); if (s == -1) { - error("InvalidWsdlElementAttr", reader, wsdlElement); + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); } else { wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); @@ -192,7 +185,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ wsdlElementIsBinding = true; } else { - error("InvalidWsdlElementAttr", reader, wsdlElement); + error(monitor, "InvalidWsdlElementAttr", reader, wsdlElement); //throw new ContributionReadException("Invalid WebService binding wsdlElement attribute: " + wsdlElement); } } @@ -207,7 +200,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ case START_ELEMENT: { if (END_POINT_REFERENCE.equals(reader.getName().getLocalPart())) { if (wsdlElement != null && (wsdlElementIsBinding == null || !wsdlElementIsBinding)) { - error("MustUseWsdlBinding", reader, wsdlElement); + error(monitor, "MustUseWsdlBinding", reader, wsdlElement); throw new ContributionReadException(wsdlElement + " must use wsdl.binding when using wsa:EndpointReference"); } wsBinding.setEndPointReference(EndPointReferenceHelper.readEndPointReference(reader)); @@ -227,7 +220,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ protected void processEndPointReference(XMLStreamReader reader, WebServiceBinding wsBinding) { } - public void write(WebServiceBinding wsBinding, XMLStreamWriter writer) throws ContributionWriteException, + public void write(WebServiceBinding wsBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write a <binding.ws> @@ -298,15 +291,15 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ writer.writeEndElement(); } - public void resolve(WebServiceBinding model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(WebServiceBinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (model == null || !model.isUnresolved()) return; - + Monitor monitor = context.getMonitor(); WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); wsdlDefinition.setUnresolved(true); wsdlDefinition.setNamespace(model.getNamespace()); - WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition); + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition, context); if (!resolved.isUnresolved()) { wsdlDefinition.setDefinition(resolved.getDefinition()); @@ -322,7 +315,7 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ wsdlDefinition.setDefinition(binding.getDefinition()); model.setBinding(binding.getElement()); } else { - warning("WsdlBindingDoesNotMatch", wsdlDefinition, model.getBindingName()); + warning(monitor, "WsdlBindingDoesNotMatch", wsdlDefinition, model.getBindingName()); } } if (model.getServiceName() != null) { @@ -336,11 +329,11 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ model.setPort(port); model.setBinding(port.getBinding()); } else { - warning("WsdlPortTypeDoesNotMatch", wsdlDefinition, model.getPortName()); + warning(monitor, "WsdlPortTypeDoesNotMatch", wsdlDefinition, model.getPortName()); } } } else { - warning("WsdlServiceDoesNotMatch", wsdlDefinition, model.getServiceName()); + warning(monitor, "WsdlServiceDoesNotMatch", wsdlDefinition, model.getServiceName()); } } @@ -349,9 +342,9 @@ public class WebServiceBindingProcessor implements StAXArtifactProcessor<WebServ WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); WSDLInterface wsdlInterface = null; try { - wsdlInterface = wsdlFactory.createWSDLInterface(portType, wsdlDefinition, resolver); + wsdlInterface = wsdlFactory.createWSDLInterface(portType, wsdlDefinition, resolver, context.getMonitor()); } catch (InvalidInterfaceException e) { - warning("InvalidInterfaceException", wsdlFactory, model.getName()); + warning(monitor, "InvalidInterfaceException", wsdlFactory, model.getName()); } interfaceContract.setInterface(wsdlInterface); model.setBindingInterfaceContract(interfaceContract); diff --git a/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java b/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java index bba7ff28ab..85d41bd15c 100644 --- a/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java +++ b/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; @@ -48,20 +49,22 @@ public class ReadTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } @Test public void testReadComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - ComponentType componentType = (ComponentType)staxProcessor.read(reader); + ComponentType componentType = (ComponentType)staxProcessor.read(reader, context); assertNotNull(componentType); } @@ -69,7 +72,7 @@ public class ReadTestCase { public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); } @@ -77,7 +80,7 @@ public class ReadTestCase { public void testReadPolicies() throws Exception { InputStream is = getClass().getResourceAsStream("PoliciedCalculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); } @@ -93,7 +96,7 @@ public class ReadTestCase { InputStream is = getClass().getResourceAsStream("Calculator-bad-wsdlElement.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); try { - staxProcessor.read(reader); + staxProcessor.read(reader, context); fail("ContributionReadException expected."); } catch(ContributionReadException e) { // Expected diff --git a/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java b/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java index 2b3f314fb1..805b1862ce 100644 --- a/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java +++ b/java/sca/modules/binding-ws/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java @@ -31,6 +31,7 @@ import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; @@ -47,32 +48,34 @@ public class WriteTestCase { private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; private static StAXArtifactProcessor<Object> staxProcessor; + 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 = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } @Test public void testReadWriteComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); - ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(componentType); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos), context); } @Test public void testReadWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); - Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); System.out.println(bos.toString()); } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java index bce2b9b2ea..205a3157de 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/BindingURIBuilderImpl.java @@ -32,9 +32,9 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.DeployedCompositeBuilder; import org.apache.tuscany.sca.assembly.builder.Messages; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; @@ -45,7 +45,7 @@ import org.apache.tuscany.sca.monitor.Monitor; * * @version $Rev$ $Date$ */ -public class BindingURIBuilderImpl implements CompositeBuilder, DeployedCompositeBuilder { +public class BindingURIBuilderImpl implements CompositeBuilder { public BindingURIBuilderImpl(ExtensionPointRegistry registry) { } @@ -55,27 +55,12 @@ public class BindingURIBuilderImpl implements CompositeBuilder, DeployedComposit * * @param composite the composite to be configured */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, null, monitor); + configureBindingURIs(composite, null, context.getDefinitions(), context.getBindingBaseURIs(), context.getMonitor()); return composite; } - /** - * Fully resolve the binding URIs based on available information. This includes information - * from the ".composite" files, from resources associated with the binding, e.g. WSDL files, - * from any associated policies and from the default information for each binding type. - * - * @param composite the composite to be configured - * @param defaultBindings list of default binding configurations - */ - public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - configureBindingURIs(composite, null, definitions, defaultBindings, monitor); - return composite; - } /** * Fully resolve the binding URIs based on available information. This includes information diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java index 6b96f9b21e..1f727bb5c0 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentBuilderImpl.java @@ -51,6 +51,7 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.ImplementationBuilder; import org.apache.tuscany.sca.assembly.builder.Messages; @@ -62,7 +63,6 @@ import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractExceptio import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.policy.ExtensionType; import org.apache.tuscany.sca.policy.PolicySubject; import org.w3c.dom.Document; @@ -79,7 +79,6 @@ public class ComponentBuilderImpl { protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); private CompositeComponentTypeBuilderImpl componentTypeBuilder; - private Monitor monitor; private AssemblyFactory assemblyFactory; private SCABindingFactory scaBindingFactory; private DocumentBuilderFactory documentBuilderFactory; @@ -89,8 +88,6 @@ public class ComponentBuilderImpl { public ComponentBuilderImpl(ExtensionPointRegistry registry) { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); @@ -113,8 +110,9 @@ public class ComponentBuilderImpl { * @Param parentComposite the composite that contains the component being configured. Required for property processing * @param component the component to be configured */ - public void configureComponentFromComponentType(Component outerComponent, Composite parentComposite, Component component) { + public void configureComponentFromComponentType(Component outerComponent, Composite parentComposite, Component component, BuilderContext context) { + Monitor monitor = context.getMonitor(); monitor.pushContext("Component: " + component.getName().toString()); try { @@ -132,7 +130,7 @@ public class ComponentBuilderImpl { if (impl != null) { ImplementationBuilder builder = builders.getImplementationBuilder(impl.getType()); if (builder != null) { - builder.build(component, impl, monitor); + builder.build(component, impl, context); } } @@ -141,17 +139,17 @@ public class ComponentBuilderImpl { // composite level property values. Hence we have to calculate whether the component // type property value should be overridden by this component's property value // before we go ahead and calculate the component type - configureProperties(outerComponent, parentComposite, component); + configureProperties(outerComponent, parentComposite, component, monitor); // create the component type for this component // taking any nested composites into account - createComponentType(component); + createComponentType(component, context); // configure services based on the calculated component type - configureServices(component); + configureServices(component, monitor); // configure services based on the calculated component type - configureReferences(component); + configureReferences(component, monitor); } finally { monitor.popContext(); } @@ -195,10 +193,10 @@ public class ComponentBuilderImpl { * * @param component */ - private void createComponentType(Component component) { + private void createComponentType(Component component, BuilderContext context) { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - componentTypeBuilder.createComponentType(component, (Composite)implementation); + componentTypeBuilder.createComponentType(component, (Composite)implementation, context); } } @@ -208,15 +206,15 @@ public class ComponentBuilderImpl { * * @param component */ - private void configureServices(Component component) { + private void configureServices(Component component, Monitor monitor) { // If the component type has services that are not described in this // component then create services for this component - addServicesFromComponentType(component); + addServicesFromComponentType(component, monitor); // Connect this component's services to the // services from its component type - connectServicesToComponentType(component); + connectServicesToComponentType(component, monitor); // look at each component service in turn and calculate its // configuration based on OASIS rules @@ -231,7 +229,7 @@ public class ComponentBuilderImpl { } // interface contracts - calculateServiceInterfaceContract(component, componentService, componentTypeService); + calculateServiceInterfaceContract(component, componentService, componentTypeService, monitor); // bindings calculateBindings(componentService, componentTypeService); @@ -256,15 +254,15 @@ public class ComponentBuilderImpl { * * @param component */ - private void configureReferences(Component component) { + private void configureReferences(Component component, Monitor monitor) { // If the component type has references that are not described in this // component then create references for this component - addReferencesFromComponentType(component); + addReferencesFromComponentType(component, monitor); // Connect this component's references to the // references from its component type - connectReferencesToComponentType(component); + connectReferencesToComponentType(component, monitor); // look at each component reference in turn and calculate its // configuration based on OASIS rules @@ -278,10 +276,10 @@ public class ComponentBuilderImpl { } // reference multiplicity - reconcileReferenceMultiplicity(component, componentReference, componentTypeReference); + reconcileReferenceMultiplicity(component, componentReference, componentTypeReference, monitor); // interface contracts - calculateReferenceInterfaceContract(component, componentReference, componentTypeReference); + calculateReferenceInterfaceContract(component, componentReference, componentTypeReference, monitor); // bindings calculateBindings(componentReference, componentTypeReference); @@ -317,26 +315,26 @@ public class ComponentBuilderImpl { * * @param component */ - private void configureProperties(Component outerComponent, Composite parentComposite, Component component) { + private void configureProperties(Component outerComponent, Composite parentComposite, Component component, Monitor monitor) { // If the component type has properties that are not described in this // component then create properties for this component - addPropertiesFromComponentType(component); + addPropertiesFromComponentType(component, monitor); // Connect this component's properties to the // properties from its component type - connectPropertiesToComponentType(component); + connectPropertiesToComponentType(component, monitor); // Reconcile component properties and their component type properties for (ComponentProperty componentProperty : component.getProperties()) { - reconcileComponentPropertyWithComponentType(component, componentProperty); + reconcileComponentPropertyWithComponentType(component, componentProperty, monitor); // configure the property value based on the @source attribute // At the moment this is done in the parent composite component // type calculation - processPropertySourceAttribute(outerComponent, parentComposite, component, componentProperty); + processPropertySourceAttribute(outerComponent, parentComposite, component, componentProperty, monitor); // configure the property value based on the @file attribute - processPropertyFileAttribute(component, componentProperty); + processPropertyFileAttribute(component, componentProperty, monitor); // Check that a value is supplied if (componentProperty.isMustSupply() && !isPropertyValueSet(componentProperty)) { @@ -361,7 +359,7 @@ public class ComponentBuilderImpl { } } - private void addServicesFromComponentType(Component component) { + private void addServicesFromComponentType(Component component, Monitor monitor) { // Create a component service for each service if (component.getImplementation() != null) { @@ -391,7 +389,7 @@ public class ComponentBuilderImpl { } } - private void addReferencesFromComponentType(Component component) { + private void addReferencesFromComponentType(Component component, Monitor monitor) { // Create a component reference for each reference if (component.getImplementation() != null) { @@ -421,7 +419,7 @@ public class ComponentBuilderImpl { } } - private void addPropertiesFromComponentType(Component component) { + private void addPropertiesFromComponentType(Component component, Monitor monitor) { // Create component property for each property if (component.getImplementation() != null) { @@ -454,7 +452,7 @@ public class ComponentBuilderImpl { } } - private void connectServicesToComponentType(Component component) { + private void connectServicesToComponentType(Component component, Monitor monitor) { // Connect each component service to the corresponding component type service for (ComponentService componentService : component.getServices()) { @@ -492,7 +490,7 @@ public class ComponentBuilderImpl { } } - private void connectReferencesToComponentType(Component component) { + private void connectReferencesToComponentType(Component component, Monitor monitor) { // Connect each component reference to the corresponding component type reference for (ComponentReference componentReference : component.getReferences()) { @@ -530,7 +528,7 @@ public class ComponentBuilderImpl { } } - private void connectPropertiesToComponentType(Component component) { + private void connectPropertiesToComponentType(Component component, Monitor monitor) { // Connect each component property to the corresponding component type property for (ComponentProperty componentProperty : component.getProperties()) { // check for duplicate property names in component @@ -560,7 +558,8 @@ public class ComponentBuilderImpl { private void reconcileReferenceMultiplicity(Component component, Reference componentReference, - Reference componentTypeReference) { + Reference componentTypeReference, + Monitor monitor) { if (componentReference.getMultiplicity() != null) { if (!isValidMultiplicityOverride(componentTypeReference.getMultiplicity(), componentReference .getMultiplicity())) { @@ -576,7 +575,7 @@ public class ComponentBuilderImpl { } } - private void reconcileComponentPropertyWithComponentType(Component component, ComponentProperty componentProperty) { + private void reconcileComponentPropertyWithComponentType(Component component, ComponentProperty componentProperty, Monitor monitor) { Property componentTypeProperty = componentProperty.getProperty(); if (componentTypeProperty != null) { @@ -676,7 +675,8 @@ public class ComponentBuilderImpl { private void processPropertySourceAttribute(Component outerComponent, Composite parentComposite, Component component, - ComponentProperty componentProperty) { + ComponentProperty componentProperty, + Monitor monitor) { String source = componentProperty.getSource(); if (source != null) { @@ -754,7 +754,7 @@ public class ComponentBuilderImpl { * @param parentCompoent the composite that contains the component * @param component */ - private void processPropertyFileAttribute(Component component, ComponentProperty componentProperty) { + private void processPropertyFileAttribute(Component component, ComponentProperty componentProperty, Monitor monitor) { String file = componentProperty.getFile(); if (file != null) { try { @@ -1120,7 +1120,7 @@ public class ComponentBuilderImpl { * @param topContract the top contract * @param bottomContract the bottom contract */ - private void calculateServiceInterfaceContract(Component component, Service topContract, Service bottomContract) { + private void calculateServiceInterfaceContract(Component component, Service topContract, Service bottomContract, Monitor monitor) { // Use the interface contract from the bottom level contract if // none is specified on the top level contract @@ -1160,7 +1160,7 @@ public class ComponentBuilderImpl { * @param topContract the top contract * @param bottomContract the bottom contract */ - private void calculateReferenceInterfaceContract(Component component, Reference topContract, Reference bottomContract) { + private void calculateReferenceInterfaceContract(Component component, Reference topContract, Reference bottomContract, Monitor monitor) { // Use the interface contract from the bottom level contract if // none is specified on the top level contract diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferenceBindingBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferenceBindingBuilderImpl.java index 09d37cacb6..c48d868105 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferenceBindingBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferenceBindingBuilderImpl.java @@ -25,12 +25,11 @@ import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; /** * A composite builder that performs any additional building steps that @@ -46,9 +45,9 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - buildReferenceBindings(composite, monitor); + buildReferenceBindings(composite, context); return composite; } @@ -56,7 +55,7 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.ComponentReferenceBindingBuilder"; } - private void buildReferenceBindings(Composite composite, Monitor monitor) { + private void buildReferenceBindings(Composite composite, BuilderContext context) { // find all the component reference bindings (starting at top level) for (Component component : composite.getComponents()) { @@ -64,7 +63,7 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { for (Binding binding : componentReference.getBindings()) { BindingBuilder builder = builders.getBindingBuilder(binding.getType()); if (builder != null) { - builder.build(component, componentReference, binding, monitor); + builder.build(component, componentReference, binding, context); } } } @@ -74,7 +73,7 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { for (Component component : composite.getComponents()) { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - buildReferenceBindings((Composite)implementation, monitor); + buildReferenceBindings((Composite)implementation, context); } } } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferencePromotionBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferencePromotionBuilderImpl.java index 7e7a96b016..aaa9cbe82c 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferencePromotionBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentReferencePromotionBuilderImpl.java @@ -29,11 +29,11 @@ import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -49,9 +49,9 @@ public class ComponentReferencePromotionBuilderImpl implements CompositeBuilder this.assemblyFactory = factories.getFactory(AssemblyFactory.class); } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - configureNestedCompositeReferences(composite, monitor); + configureNestedCompositeReferences(composite, context.getMonitor()); return composite; } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentServiceBindingBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentServiceBindingBuilderImpl.java index 7fe0689c23..9a74023504 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentServiceBindingBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ComponentServiceBindingBuilderImpl.java @@ -25,12 +25,11 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; /** * A composite builder that performs any additional building steps that @@ -49,19 +48,19 @@ public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.ComponentServiceBindingBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - buildServiceBindings(composite, monitor); + buildServiceBindings(composite, context); return composite; } - private void buildServiceBindings(Composite composite, Monitor monitor) { + private void buildServiceBindings(Composite composite, BuilderContext context) { // build bindings recursively for (Component component : composite.getComponents()) { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - buildServiceBindings((Composite)implementation, monitor); + buildServiceBindings((Composite)implementation, context); } } @@ -71,7 +70,7 @@ public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { for (Binding binding : componentService.getBindings()) { BindingBuilder builder = builders.getBindingBuilder(binding.getType()); if (builder != null) { - builder.build(component, componentService, binding, monitor); + builder.build(component, componentService, binding, context); } } } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeCloneBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeCloneBuilderImpl.java index d59c85d5c6..148a3b5368 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeCloneBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeCloneBuilderImpl.java @@ -25,10 +25,9 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; /** * A composite builder that clones nested composites. @@ -40,7 +39,7 @@ public class CompositeCloneBuilderImpl implements CompositeBuilder { public CompositeCloneBuilderImpl() { } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { if (Composite.DOMAIN_COMPOSITE.equals(composite.getName())) { diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java index 381eb87857..75fda5880a 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeComponentTypeBuilderImpl.java @@ -39,6 +39,7 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.Messages; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -49,7 +50,6 @@ import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractExceptio import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.policy.ExtensionType; import org.apache.tuscany.sca.policy.PolicySubject; @@ -67,7 +67,6 @@ public class CompositeComponentTypeBuilderImpl { protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); private ComponentBuilderImpl componentBuilder; - private Monitor monitor; private AssemblyFactory assemblyFactory; private SCABindingFactory scaBindingFactory; private InterfaceContractMapper interfaceContractMapper; @@ -75,8 +74,6 @@ public class CompositeComponentTypeBuilderImpl { public CompositeComponentTypeBuilderImpl(ExtensionPointRegistry registry) { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); @@ -96,8 +93,9 @@ public class CompositeComponentTypeBuilderImpl { * @param implementation * @return component type */ - public void createComponentType(Component outerComponent, Composite composite) { + public void createComponentType(Component outerComponent, Composite composite, BuilderContext context) { + Monitor monitor = context.getMonitor(); monitor.pushContext("Composite: " + composite.getName().toString()); try { @@ -125,7 +123,7 @@ public class CompositeComponentTypeBuilderImpl { } // configure the component from its component type - componentBuilder.configureComponentFromComponentType(outerComponent, composite, component); + componentBuilder.configureComponentFromComponentType(outerComponent, composite, component, context); } // create the composite component type based on the promoted artifacts @@ -139,10 +137,10 @@ public class CompositeComponentTypeBuilderImpl { indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); // services - calculateServices(composite, components, componentServices); + calculateServices(composite, components, componentServices, monitor); // references - calculateReferences(composite, components, componentReferences); + calculateReferences(composite, components, componentReferences, monitor); // properties // Properties on the composite component are unaffected by properties @@ -216,11 +214,12 @@ public class CompositeComponentTypeBuilderImpl { */ private void calculateServices(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentService> componentServices) { + Map<String, ComponentService> componentServices, + Monitor monitor) { // Connect this component type's services to the // services from child components which it promotes - connectPromotedServices(componentType, components, componentServices); + connectPromotedServices(componentType, components, componentServices, monitor); // look at each component type service in turn and // calculate its configuration based on OASIS rules @@ -229,7 +228,7 @@ public class CompositeComponentTypeBuilderImpl { ComponentService promotedComponentService = compositeService.getPromotedService(); // promote interface contracts - calculatePromotedServiceInterfaceContract(compositeService, promotedComponentService); + calculatePromotedServiceInterfaceContract(compositeService, promotedComponentService, monitor); // promote bindings calculatePromotedBindings(compositeService, promotedComponentService); @@ -251,11 +250,11 @@ public class CompositeComponentTypeBuilderImpl { */ private void calculateReferences(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentReference> componentReferences) { + Map<String, ComponentReference> componentReferences, Monitor monitor) { // Connect this component type's references to the // references from child components which it promotes - connectPromotedReferences(componentType, components, componentReferences); + connectPromotedReferences(componentType, components, componentReferences, monitor); // look at each component type reference in turn and // calculate its configuration based on OASIS rules @@ -266,7 +265,7 @@ public class CompositeComponentTypeBuilderImpl { for (ComponentReference promotedComponentReference : promotedReferences) { // promote interface contracts - calculatePromotedReferenceInterfaceContract(compositeReference, promotedComponentReference); + calculatePromotedReferenceInterfaceContract(compositeReference, promotedComponentReference, monitor); // promote bindings // Don't need to promote reference bindings as any lower level binding will @@ -291,7 +290,8 @@ public class CompositeComponentTypeBuilderImpl { */ private void connectPromotedServices(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentService> componentServices) { + Map<String, ComponentService> componentServices, + Monitor monitor) { for (Service service : componentType.getServices()) { // Connect composite (component type) services to the component services @@ -345,7 +345,8 @@ public class CompositeComponentTypeBuilderImpl { */ private void connectPromotedReferences(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentReference> componentReferences) { + Map<String, ComponentReference> componentReferences, + Monitor monitor) { // Connect composite (component type) references to the component references that they promote for (Reference reference : componentType.getReferences()) { @@ -417,7 +418,7 @@ public class CompositeComponentTypeBuilderImpl { * @param topContract the top contract * @param bottomContract the bottom contract */ - private void calculatePromotedServiceInterfaceContract(Service topContract, Service bottomContract) { + private void calculatePromotedServiceInterfaceContract(Service topContract, Service bottomContract, Monitor monitor) { // Use the interface contract from the bottom level contract if // none is specified on the top level contract InterfaceContract topInterfaceContract = topContract.getInterfaceContract(); @@ -455,7 +456,7 @@ public class CompositeComponentTypeBuilderImpl { * @param topContract the top contract * @param bottomContract the bottom contract */ - private void calculatePromotedReferenceInterfaceContract(Reference topContract, Reference bottomContract) { + private void calculatePromotedReferenceInterfaceContract(Reference topContract, Reference bottomContract, Monitor monitor) { // Use the interface contract from the bottom level contract if // none is specified on the top level contract InterfaceContract topInterfaceContract = topContract.getInterfaceContract(); diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeIncludeBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeIncludeBuilderImpl.java index 8163b0bbe1..b4a897af54 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeIncludeBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositeIncludeBuilderImpl.java @@ -24,10 +24,10 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.assembly.builder.Messages; -import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -44,9 +44,9 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.CompositeIncludeBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - return processIncludes(composite, monitor); + return processIncludes(composite, context.getMonitor()); } /** diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java index d176db39d2..3db76a81e3 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/CompositePolicyBuilderImpl.java @@ -37,12 +37,12 @@ import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.assembly.builder.PolicyBuilder; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentMap; import org.apache.tuscany.sca.policy.PolicyExpression; @@ -66,10 +66,11 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo return "org.apache.tuscany.sca.assembly.builder.CompositePolicyBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - computePolicies(composite, definitions, monitor); - buildPolicies(composite, definitions, monitor); + Definitions definitions = context.getDefinitions(); + computePolicies(composite, definitions, context); + buildPolicies(composite, definitions, context); return composite; } @@ -97,14 +98,14 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo * @param monitor * @return */ - private boolean checkMutualExclusion(PolicySubject subject1, PolicySubject subject2, Monitor monitor) { + private boolean checkMutualExclusion(PolicySubject subject1, PolicySubject subject2, BuilderContext context) { if (subject1 == subject2 || subject1 == null || subject2 == null) { return false; } for (Intent i1 : subject1.getRequiredIntents()) { for (Intent i2 : subject1.getRequiredIntents()) { if (i1.getExcludedIntents().contains(i2) || i2.getExcludedIntents().contains(i1)) { - error(monitor, "MutuallyExclusiveIntents", new Object[] {subject1, subject2}, i1, i2); + error(context.getMonitor(), "MutuallyExclusiveIntents", new Object[] {subject1, subject2}, i1, i2); return true; } } @@ -206,7 +207,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo return null; } - private void resolveAndNormalize(PolicySubject subject, Definitions definitions, Monitor monitor) { + private void resolveAndNormalize(PolicySubject subject, Definitions definitions, BuilderContext context) { Set<Intent> intents = new HashSet<Intent>(); if (definitions != null) { @@ -215,7 +216,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo if (resolved != null) { intents.add(resolved); } else { - warning(monitor, "IntentNotFound", subject, i); + warning(context.getMonitor(), "IntentNotFound", subject, i); // Intent cannot be resolved } } @@ -267,7 +268,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo policySets.add(definitions.getPolicySets().get(index)); } else { // PolicySet cannot be resolved - warning(monitor, "PolicySetNotFound", subject, policySet); + warning(context.getMonitor(), "PolicySetNotFound", subject, policySet); } } } @@ -296,30 +297,30 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo } - protected void computePolicies(Composite composite, Definitions definitions, Monitor monitor) { + protected void computePolicies(Composite composite, Definitions definitions, BuilderContext context) { // compute policies recursively for (Component component : composite.getComponents()) { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - computePolicies((Composite)implementation, definitions, monitor); + computePolicies((Composite)implementation, definitions, context); } } for (Component component : composite.getComponents()) { // Check component against implementation - checkMutualExclusion(component, component.getImplementation(), monitor); + checkMutualExclusion(component, component.getImplementation(), context); for (ComponentService componentService : component.getServices()) { // Check component/service against componentType/service - checkMutualExclusion(componentService, componentService.getService(), monitor); + checkMutualExclusion(componentService, componentService.getService(), context); if (componentService.getInterfaceContract() != null && componentService.getService() != null) { checkMutualExclusion(componentService.getInterfaceContract().getInterface(), componentService - .getService().getInterfaceContract().getInterface(), monitor); + .getService().getInterfaceContract().getInterface(), context); checkMutualExclusion(componentService.getInterfaceContract().getCallbackInterface(), componentService.getService().getInterfaceContract().getCallbackInterface(), - monitor); + context); } for (Endpoint ep : componentService.getEndpoints()) { @@ -337,7 +338,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo if (componentService.getService() != null) { for (Binding binding : componentService.getService().getBindings()) { if (isEqual(ep.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) { - checkMutualExclusion((PolicySubject)ep.getBinding(), (PolicySubject)binding, monitor); + checkMutualExclusion((PolicySubject)ep.getBinding(), (PolicySubject)binding, context); // Inherit from componentType.service.binding inherit(ep, binding); break; @@ -353,21 +354,21 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo // Remove the intents whose @contraints do not include the current element // Replace unqualified intents if there is a qualified intent in the list // Replace qualifiable intents with the default qualied intent - resolveAndNormalize(ep, definitions, monitor); + resolveAndNormalize(ep, definitions, context); } } for (ComponentReference componentReference : component.getReferences()) { // Check component/reference against componentType/reference - checkMutualExclusion(componentReference, componentReference.getReference(), monitor); + checkMutualExclusion(componentReference, componentReference.getReference(), context); if (componentReference.getInterfaceContract() != null && componentReference.getReference() != null) { checkMutualExclusion(componentReference.getInterfaceContract().getInterface(), componentReference - .getReference().getInterfaceContract().getInterface(), monitor); + .getReference().getInterfaceContract().getInterface(), context); checkMutualExclusion(componentReference.getInterfaceContract().getCallbackInterface(), componentReference.getReference().getInterfaceContract() .getCallbackInterface(), - monitor); + context); } for (EndpointReference epr : componentReference.getEndpointReferences()) { @@ -387,7 +388,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo for (Binding binding : componentReference.getReference().getBindings()) { if (epr.getBinding() != null && isEqual(epr.getBinding().getName(), binding.getName()) && (binding instanceof PolicySubject)) { - checkMutualExclusion((PolicySubject)epr.getBinding(), (PolicySubject)binding, monitor); + checkMutualExclusion((PolicySubject)epr.getBinding(), (PolicySubject)binding, context); // Inherit from componentType.reference.binding inherit(epr, binding); break; @@ -402,7 +403,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo // Remove the intents whose @contraints do not include the current element // Replace unqualified intents if there is a qualified intent in the list // Replace qualifiable intents with the default qualied intent - resolveAndNormalize(epr, definitions, monitor); + resolveAndNormalize(epr, definitions, context); } } @@ -427,13 +428,13 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo return names; } - protected void buildPolicies(Composite composite, Definitions definitions, Monitor monitor) { + protected void buildPolicies(Composite composite, Definitions definitions, BuilderContext context) { // compute policies recursively for (Component component : composite.getComponents()) { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - buildPolicies((Composite)implementation, definitions, monitor); + buildPolicies((Composite)implementation, definitions, context); } } @@ -444,7 +445,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo for (QName policyType : getPolicyNames(ep)) { PolicyBuilder builder = builders.getPolicyBuilder(policyType); if (builder != null) { - builder.build(ep, definitions, monitor); + builder.build(ep, context); } } } @@ -455,7 +456,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo for (QName policyType : getPolicyNames(epr)) { PolicyBuilder builder = builders.getPolicyBuilder(policyType); if (builder != null) { - builder.build(epr, definitions, monitor); + builder.build(epr, context); } } } @@ -466,7 +467,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo for (QName policyType : getPolicyNames(implementation)) { PolicyBuilder builder = builders.getPolicyBuilder(policyType); if (builder != null) { - builder.build(component, implementation, definitions, monitor); + builder.build(component, implementation, context); } } } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java index fa67818408..e122df35c3 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointBuilderImpl.java @@ -26,16 +26,16 @@ 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.Implementation; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; /** * creates endpoint models for component services. */ -public class EndpointBuilderImpl { +public class EndpointBuilderImpl implements CompositeBuilder { private AssemblyFactory assemblyFactory; public EndpointBuilderImpl(ExtensionPointRegistry registry) { @@ -50,7 +50,7 @@ public class EndpointBuilderImpl { * @param definitions * @param monitor - a Monitor for logging errors */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { processComponentServices(composite); @@ -98,4 +98,8 @@ public class EndpointBuilderImpl { } } } + + public String getID() { + return "org.apache.tuscany.sca.assembly.builder.EndpointBuilder"; + } } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java index a107880022..b1cc873914 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/EndpointReferenceBuilderImpl.java @@ -37,29 +37,25 @@ import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.assembly.builder.Messages; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; /** * Creates endpoint reference models. */ public class EndpointReferenceBuilderImpl { - private Monitor monitor; private AssemblyFactory assemblyFactory; private InterfaceContractMapper interfaceContractMapper; public EndpointReferenceBuilderImpl(ExtensionPointRegistry registry) { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - monitor = monitorFactory.createMonitor(); interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); @@ -71,16 +67,16 @@ public class EndpointReferenceBuilderImpl { * * @param composite */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - this.monitor = monitor; + Monitor monitor = context.getMonitor(); // process component services - processComponentReferences(composite); + processComponentReferences(composite, monitor); return composite; } - private void processComponentReferences(Composite composite) { + private void processComponentReferences(Composite composite, Monitor monitor) { monitor.pushContext("Composite: " + composite.getName().toString()); try { @@ -102,7 +98,7 @@ public class EndpointReferenceBuilderImpl { // recurse for composite implementations Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - processComponentReferences((Composite)implementation); + processComponentReferences((Composite)implementation, monitor); } // create endpoint references to represent the component reference @@ -111,7 +107,8 @@ public class EndpointReferenceBuilderImpl { component, reference, components, - componentServices); + componentServices, + monitor); // fix up links between endpoints and endpoint references that represent callbacks for (ComponentService service : component.getServices()) { @@ -130,7 +127,7 @@ public class EndpointReferenceBuilderImpl { // Validate that references are wired or promoted, according // to their multiplicity - validateReferenceMultiplicity(composite, component); + validateReferenceMultiplicity(composite, component, monitor); } finally { monitor.popContext(); @@ -275,7 +272,8 @@ public class EndpointReferenceBuilderImpl { Component component, ComponentReference reference, Map<String, Component> components, - Map<String, ComponentService> componentServices) { + Map<String, ComponentService> componentServices, + Monitor monitor) { monitor.pushContext("Reference: " + reference.getName()); @@ -554,7 +552,7 @@ public class EndpointReferenceBuilderImpl { } // end method - private void validateReferenceMultiplicity(Composite composite, Component component) { + private void validateReferenceMultiplicity(Composite composite, Component component, Monitor monitor) { for (ComponentReference componentReference : component.getReferences()) { if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), componentReference.getEndpointReferences())) { diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java index d50653da9d..206afb98da 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/ModelBuilderImpl.java @@ -19,25 +19,22 @@ package org.apache.tuscany.sca.builder.impl; import java.io.ByteArrayOutputStream; -import java.util.List; -import java.util.Map; -import javax.xml.namespace.QName; import javax.xml.stream.XMLOutputFactory; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.DeployedCompositeBuilder; +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.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; -public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuilder { +public class ModelBuilderImpl implements CompositeBuilder { private ExtensionPointRegistry registry; private CompositeBuilder compositeIncludeBuilder; @@ -89,36 +86,29 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil return "org.apache.tuscany.sca.assembly.builder.CompositeBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - return build(composite, definitions, null, monitor); - } - - public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { - + Monitor monitor = context.getMonitor(); try { // Clone the composites that are included or referenced in implementation.composite - composite = compositeCloneBuilder.build(composite, definitions, monitor); + composite = compositeCloneBuilder.build(composite, context); // Collect and fuse includes. Copy all of the components // out of the included composite into the including composite // and discards the included composite - composite = compositeIncludeBuilder.build(composite, definitions, monitor); + composite = compositeIncludeBuilder.build(composite, context); // Set up the structural URIs for components (services/references/bindings?) - composite = structuralURIBuilder.build(composite, definitions, monitor); + composite = structuralURIBuilder.build(composite, context); // need to apply policy external attachment - composite = policyAttachmentBuilder.build(composite, definitions, monitor); + composite = policyAttachmentBuilder.build(composite, context); // Process the implementation hierarchy by calculating the component type // for the top level implementation (composite). This has the effect of // recursively calculating component types and configuring the // components that depend on them - compositeComponentTypeBuilder.createComponentType(null, composite); + compositeComponentTypeBuilder.createComponentType(null, composite, context); // create the runtime model by updating the static model we have just // created. This involves things like creating @@ -132,13 +122,13 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil // Policies // TODO - called here at the moment but we could have a separate build phase // to call these. Also we need to re-org these builders - composite = bindingURIBuilder.build(composite, definitions, monitor); - composite = componentServiceBindingBuilder.build(composite, definitions, monitor); // binding specific build - composite = componentReferenceBindingBuilder.build(composite, definitions, monitor); // binding specific build - endpointBuilder.build(composite, definitions, monitor); - endpointReferenceBuilder.build(composite, definitions, monitor); - composite = componentReferencePromotionBuilder.build(composite, definitions, monitor); // move into the static build? - composite = compositePolicyBuilder.build(composite, definitions, monitor); // the rest of the policy processing? + composite = bindingURIBuilder.build(composite, context); + composite = componentServiceBindingBuilder.build(composite, context); // binding specific build + composite = componentReferenceBindingBuilder.build(composite, context); // binding specific build + endpointBuilder.build(composite, context); + endpointReferenceBuilder.build(composite, context); + composite = componentReferencePromotionBuilder.build(composite, context); // move into the static build? + composite = compositePolicyBuilder.build(composite, context); // the rest of the policy processing? // For debugging - in success cases //System.out.println(dumpBuiltComposite(composite)); @@ -173,7 +163,7 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil .getFactory(XMLOutputFactory.class); try { - compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(registry)); } catch(Exception ex) { return ex.toString(); } diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java index 59cfdc7393..cbbf54b330 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentBuilderImpl.java @@ -42,11 +42,13 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.common.xml.dom.DOMHelper; import org.apache.tuscany.sca.common.xml.stax.StAXHelper; 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.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -72,9 +74,11 @@ import org.xml.sax.SAXException; public class PolicyAttachmentBuilderImpl implements CompositeBuilder { private StAXHelper staxHelper; private DOMHelper domHelper; + private ExtensionPointRegistry registry; private StAXArtifactProcessor<Composite> processor; public PolicyAttachmentBuilderImpl(ExtensionPointRegistry registry) { + this.registry = registry; domHelper = DOMHelper.getInstance(registry); staxHelper = StAXHelper.getInstance(registry); StAXArtifactProcessorExtensionPoint processors = @@ -86,10 +90,10 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.policy.builder.PolicyAttachmentBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { try { - Composite patched = applyXPath(composite, definitions, monitor); + Composite patched = applyXPath(composite, context.getDefinitions(), context.getMonitor()); return patched; } catch (Exception e) { throw new CompositeBuilderException(e); @@ -162,7 +166,7 @@ public class PolicyAttachmentBuilderImpl implements CompositeBuilder { StringWriter sw = new StringWriter(); XMLStreamWriter writer = staxHelper.createXMLStreamWriter(sw); // Write the composite into a DOM document - processor.write(composite, writer); + processor.write(composite, writer, new ProcessorContext(registry)); writer.close(); Document document = domHelper.load(sw.toString()); diff --git a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java index c013780c7b..b543e3347d 100644 --- a/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java +++ b/java/sca/modules/builder/src/main/java/org/apache/tuscany/sca/builder/impl/StructuralURIBuilderImpl.java @@ -20,7 +20,6 @@ package org.apache.tuscany.sca.builder.impl; import java.net.URI; -import java.net.URISyntaxException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,9 +35,9 @@ import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.DeployedCompositeBuilder; import org.apache.tuscany.sca.assembly.builder.Messages; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; @@ -49,7 +48,7 @@ import org.apache.tuscany.sca.monitor.Monitor; * * @version $Rev$ $Date$ */ -public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompositeBuilder { +public class StructuralURIBuilderImpl implements CompositeBuilder { public StructuralURIBuilderImpl(ExtensionPointRegistry registry) { } @@ -119,109 +118,6 @@ public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompo } /** - * Generic URI construction for bindings based on Assembly Specification section 1.7.2 - * - * @param componentURIString the string version of the URI part that comes from the component name - * @param service the service in question - * @param binding the binding for which the URI is being constructed - * @param includeBindingName when set true the serviceBindingURI part should be used - * @param defaultBindings the list of default binding configurations - * @throws CompositeBuilderException - */ - private void constructBindingURI(String componentURIString, - Service service, - Binding binding, - Map<QName, List<String>> defaultBindings, - Monitor monitor) throws CompositeBuilderException { - - try { - - boolean includeBindingName = !service.getName().equals(binding.getName()); - - // calculate the service binding URI - URI bindingURI; - if (binding.getURI() != null) { - bindingURI = new URI(binding.getURI()); - - // if the user has provided an absolute binding URI then use it - if (bindingURI.isAbsolute()) { - return; - } - } else { - bindingURI = null; - } - - String serviceName = service.getName(); - // Get the service binding name - String bindingName; - if (binding.getName() != null) { - bindingName = binding.getName(); - } else { - bindingName = serviceName; - } - - // calculate the component URI - URI componentURI; - if (componentURIString != null) { - componentURI = new URI(addSlashToPath(componentURIString)); - } else { - componentURI = null; - } - - // if the user has provided an absolute component URI then use it - if (componentURI != null && componentURI.isAbsolute()) { - binding.setURI(constructBindingURI(null, - componentURI, - bindingURI, - serviceName, - includeBindingName, - bindingName)); - return; - } - - // calculate the base URI - URI baseURI = null; - if (defaultBindings != null) { - List<String> uris = defaultBindings.get(binding.getType()); - if (uris != null && uris.size() > 0) { - baseURI = new URI(addSlashToPath(uris.get(0))); - } - } - - binding.setURI(constructBindingURI(baseURI, - componentURI, - bindingURI, - serviceName, - includeBindingName, - bindingName)); - } catch (URISyntaxException ex) { - Monitor.error(monitor, - this, - Messages.ASSEMBLY_VALIDATION, - "URLSyntaxException", - componentURIString, - service.getName(), - binding.getName()); - } - } - - /** - * Use to ensure that URI paths end in "/" as here we want to maintain the - * last path element of an base URI when other URI are resolved against it. This is - * not the default behaviour of URI resolution as defined in RFC 2369 - * - * @param path the path string to which the "/" is to be added - * @return the resulting path with a "/" added if it not already there - */ - private static String addSlashToPath(String path) { - if (path.endsWith("/") || path.endsWith("#")) { - return path; - } else { - return path + "/"; - } - } - - /** * Concatenate binding URI parts together based on Assembly Specification section 1.7.2 * * @param baseURI the base of the binding URI @@ -304,9 +200,9 @@ public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompo return URI.create(baseURI.toString() + str).normalize(); } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) + public Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException { - configureStructuralURIs(composite, null, definitions, null, monitor); + configureStructuralURIs(composite, null, context.getDefinitions(), context.getBindingBaseURIs(), context.getMonitor()); return composite; } @@ -314,14 +210,6 @@ public class StructuralURIBuilderImpl implements CompositeBuilder, DeployedCompo return "org.apache.tuscany.sca.assembly.builder.StructualURIBuilder"; } - public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { - configureStructuralURIs(composite, null, definitions, bindingBaseURIs, monitor); - return composite; - } - private void configureStructuralURIs(Composite composite, String parentComponentURI, Definitions definitions, diff --git a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java index e8d065cdcd..0c7105bd9f 100644 --- a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/BuildPolicyTestCase.java @@ -33,10 +33,12 @@ import org.apache.tuscany.sca.assembly.Component; 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.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; 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; @@ -65,10 +67,12 @@ public class BuildPolicyTestCase { private static CompositeBuilder compositeBuilder; private static Composite composite; private static Monitor monitor; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); compositeBuilder = @@ -84,7 +88,7 @@ public class BuildPolicyTestCase { URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints); - documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); policyDefinitionsProcessor = documentProcessors.getProcessor(Definitions.class); StAXArtifactProcessorExtensionPoint staxProcessors = @@ -93,19 +97,20 @@ public class BuildPolicyTestCase { URL url = BuildPolicyTestCase.class.getResource("Calculator.composite"); URI uri = URI.create("TestAllCalculator.composite"); - composite = (Composite)documentProcessor.read(null, uri, url); + composite = (Composite)documentProcessor.read(null, uri, url, context); assertNotNull(composite); url = BuildPolicyTestCase.class.getResource("test_definitions.xml"); uri = URI.create("test_definitions.xml"); - Definitions definitions = (Definitions)policyDefinitionsProcessor.read(null, uri, url); + Definitions definitions = (Definitions)policyDefinitionsProcessor.read(null, uri, url, context); assertNotNull(definitions); policyDefinitions.add(definitions); - documentProcessor.resolve(definitions, resolver); - documentProcessor.resolve(composite, resolver); + documentProcessor.resolve(definitions, resolver, context); + documentProcessor.resolve(composite, resolver, context); - compositeBuilder.build(composite, definitions, monitor); + BuilderContext builderContext = new BuilderContext(definitions, null, monitor); + compositeBuilder.build(composite, builderContext); } @Test diff --git a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java index f309331fff..a99d0df91c 100644 --- a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/CompositeBuilderTestCase.java @@ -29,6 +29,7 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.monitor.DefaultMonitorFactory; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; @@ -77,7 +78,7 @@ public class CompositeBuilderTestCase { c.setName(new QName("http://foo", "C")); c.getIncludes().add(c1); - new CompositeIncludeBuilderImpl().build(c, null, monitor); + new CompositeIncludeBuilderImpl().build(c, new BuilderContext(monitor)); assertTrue(c.getComponents().get(0).getName().equals("a")); assertTrue(c.getComponents().get(1).getName().equals("b")); @@ -120,7 +121,7 @@ public class CompositeBuilderTestCase { z.setImplementation(c1); c.getComponents().add(z); - new CompositeCloneBuilderImpl().build(c, null, monitor); + new CompositeCloneBuilderImpl().build(c, new BuilderContext(monitor)); assertTrue(c.getComponents().get(0).getImplementation() != c1); assertTrue(c.getComponents().get(1).getImplementation() != c2); diff --git a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java index 76b6c8b1f1..9102257b77 100644 --- a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/PolicyAttachmentTestCase.java @@ -31,10 +31,12 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; 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.core.DefaultExtensionPointRegistry; @@ -62,10 +64,13 @@ public class PolicyAttachmentTestCase { private static XMLInputFactory inputFactory; private static AssemblyFactory assemblyFactory; private static BuilderExtensionPoint builders; + private static ProcessorContext context; @BeforeClass public static void init() throws Exception { extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); assemblyFactory = factories.getFactory(AssemblyFactory.class); inputFactory = factories.getFactory(XMLInputFactory.class); @@ -78,7 +83,7 @@ public class PolicyAttachmentTestCase { } StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); staxProcessors.addArtifactProcessor(new TestPolicyProcessor()); builders = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class); @@ -91,9 +96,11 @@ public class PolicyAttachmentTestCase { CompositeBuilder uriBuilder = new StructuralURIBuilderImpl(extensionPoints); - composite = uriBuilder.build(composite, definitions, monitor); + BuilderContext builderContext = new BuilderContext(extensionPoints); + builderContext.setDefinitions(definitions); + composite = uriBuilder.build(composite, builderContext); PolicyAttachmentBuilderImpl builder = new PolicyAttachmentBuilderImpl(extensionPoints); - builder.build(composite, definitions, monitor); + builder.build(composite, builderContext); } private <T> T load(String file) throws IOException, XMLStreamException, ContributionReadException { @@ -102,7 +109,7 @@ public class PolicyAttachmentTestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); reader.nextTag(); - T model = (T)staxProcessor.read(reader); + T model = (T)staxProcessor.read(reader, context); reader.close(); return model; } @@ -130,12 +137,14 @@ public class PolicyAttachmentTestCase { CompositeBuilder cloneBuilder = new CompositeCloneBuilderImpl(); CompositeBuilder uriBuilder = new StructuralURIBuilderImpl(extensionPoints); - domainComposite = cloneBuilder.build(domainComposite, definitions, monitor); - domainComposite = includeBuilder.build(domainComposite, definitions, monitor); - domainComposite = uriBuilder.build(domainComposite, definitions, monitor); + BuilderContext context = new BuilderContext(extensionPoints); + context.setDefinitions(definitions); + domainComposite = cloneBuilder.build(domainComposite, context); + domainComposite = includeBuilder.build(domainComposite, context); + domainComposite = uriBuilder.build(domainComposite, context); PolicyAttachmentBuilderImpl builder = new PolicyAttachmentBuilderImpl(extensionPoints); - domainComposite = builder.build(domainComposite, definitions, monitor); + domainComposite = builder.build(domainComposite, context); } diff --git a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/TestPolicyProcessor.java b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/TestPolicyProcessor.java index 975adf3543..1201b6e36f 100644 --- a/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/TestPolicyProcessor.java +++ b/java/sca/modules/builder/src/test/java/org/apache/tuscany/sca/builder/impl/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/common-java/src/main/java/org/apache/tuscany/sca/common/java/io/IOHelper.java b/java/sca/modules/common-java/src/main/java/org/apache/tuscany/sca/common/java/io/IOHelper.java index faa29fa978..469da29e38 100644 --- a/java/sca/modules/common-java/src/main/java/org/apache/tuscany/sca/common/java/io/IOHelper.java +++ b/java/sca/modules/common-java/src/main/java/org/apache/tuscany/sca/common/java/io/IOHelper.java @@ -100,7 +100,7 @@ public class IOHelper { try { File file = toFile(url); if (file != null) { - return file.getAbsoluteFile().toURI().toURL(); + return file.toURI().toURL(); } else { return toURI(url).toURL(); } diff --git a/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java b/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java index 173ac0832d..7958eb4b6d 100644 --- a/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java +++ b/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java @@ -25,9 +25,9 @@ import java.util.Map; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.osgi.BundleReference; +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; import org.osgi.framework.Bundle; /** @@ -41,32 +41,33 @@ public class OSGiBundleReferenceModelResolver implements ModelResolver { private OSGiBundleProcessor bundleProcessor; - public OSGiBundleReferenceModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public OSGiBundleReferenceModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.contribution = contribution; this.bundleProcessor = new OSGiBundleProcessor(); } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { BundleReference bundleRef = (BundleReference)resolved; refs.put(bundleRef, bundleRef); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return refs.remove(resolved); } /** * Handle artifact resolution when the specific class reference is imported from another contribution * @param unresolved + * @param context * @return */ - private BundleReference resolveImportedModel(BundleReference unresolved) { + private BundleReference resolveImportedModel(BundleReference unresolved, ProcessorContext context) { BundleReference resolved = unresolved; if (this.contribution != null) { for (Import import_ : this.contribution.getImports()) { - resolved = import_.getModelResolver().resolveModel(BundleReference.class, unresolved); + resolved = import_.getModelResolver().resolveModel(BundleReference.class, unresolved, context); if (resolved != unresolved) break; } @@ -75,7 +76,7 @@ public class OSGiBundleReferenceModelResolver implements ModelResolver { return resolved; } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { Object resolved = refs.get(unresolved); if (resolved != null) { @@ -108,7 +109,7 @@ public class OSGiBundleReferenceModelResolver implements ModelResolver { return modelClass.cast(bundleReference); } else { //delegate resolution of the class - resolved = this.resolveImportedModel((BundleReference)unresolved); + resolved = this.resolveImportedModel((BundleReference)unresolved, context); return modelClass.cast(resolved); } diff --git a/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java b/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java index c3d79b5595..3963968940 100644 --- a/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java +++ b/java/sca/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java @@ -20,10 +20,10 @@ package org.apache.tuscany.sca.contribution.osgi.impl; import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.osgi.framework.Bundle; /** @@ -35,19 +35,19 @@ public class OSGiClassReferenceModelResolver implements ModelResolver { // private Contribution contribution; private Bundle bundle; - public OSGiClassReferenceModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public OSGiClassReferenceModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { // this.contribution = contribution; this.bundle = OSGiBundleActivator.findBundle(contribution.getLocation()); } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return resolved; } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { //Load a class on demand Class<?> clazz = null; if (bundle != null) { diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java index df313f3635..86146fc31b 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java @@ -32,12 +32,12 @@ import java.util.Map; 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.ClassReference; import org.apache.tuscany.sca.contribution.resolver.DefaultDelegatingModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.monitor.Monitor; /** * A Model Resolver for ClassReferences. @@ -46,6 +46,7 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ClassLoaderModelResolver extends URLClassLoader implements ModelResolver { private Contribution contribution; + private ProcessorContext context; private Map<String, ModelResolver> importResolvers = new HashMap<String, ModelResolver>(); private static ClassLoader parentClassLoader(Contribution contribution) { @@ -67,10 +68,9 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes return urls.toArray(new URL[urls.size()]); } - public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) throws IOException { + public ClassLoaderModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories) throws IOException { super(getContributionURLs(contribution), parentClassLoader(contribution)); this.contribution = contribution; - // Index Java import resolvers by package name Map<String, List<ModelResolver>> resolverMap = new HashMap<String, List<ModelResolver>>(); for (Import import_: this.contribution.getImports()) { @@ -91,21 +91,21 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes } } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { if (!(unresolved instanceof ClassReference)) { return unresolved; } try { - + this.context = context; // Load the class and return a class reference for it String className = ((ClassReference)unresolved).getClassName(); Class<?> clazz = Class.forName(className, true, this); @@ -159,7 +159,7 @@ public class ClassLoaderModelResolver extends URLClassLoader implements ModelRes // First try to load the class using the Java import resolvers ModelResolver importResolver = importResolvers.get(packageName); if (importResolver != null) { - ClassReference classReference = importResolver.resolveModel(ClassReference.class, new ClassReference(name)); + ClassReference classReference = importResolver.resolveModel(ClassReference.class, new ClassReference(name), context); if (!classReference.isUnresolved()) { return classReference.getJavaClass(); } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java deleted file mode 100644 index c023b3dc5b..0000000000 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.contribution.java.impl; - -import java.lang.ref.WeakReference; -import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.resolver.ClassReference; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A Model Resolver for ClassReferences. - * @deprecated Use ClassLoaderModelResolver instead - * @version $Rev$ $Date$ - */ -@Deprecated() -public class ClassReferenceModelResolver implements ModelResolver { - private Contribution contribution; - private WeakReference<ClassLoader> classLoader; - private Map<String, ClassReference> map = new HashMap<String, ClassReference>(); - - private ModelResolver osgiResolver; - - public ClassReferenceModelResolver(final Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { - this.contribution = contribution; - if (this.contribution != null) { - // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. - // ClassLoader cl = contribution.getClassLoader(); - ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { - public ClassLoader run() { - return contribution.getClassLoader(); - } - }); - - if (cl == null) { - // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. - //ClassLoader contextClassLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { - // public ClassLoader run() { - // return Thread.currentThread().getContextClassLoader(); - // } - //}); - ClassLoader contextClassLoader = ServiceDiscovery.getInstance().getServiceDiscoverer().getClass().getClassLoader(); - cl = new ContributionClassLoader(contribution, contextClassLoader); - contribution.setClassLoader(cl); - } - this.classLoader = new WeakReference<ClassLoader>(cl); - } else { - // This path should be used only for unit testing. - // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy. - // this.classLoader = new WeakReference<ClassLoader>(this.getClass().getClassLoader()); - ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { - public ClassLoader run() { - return this.getClass().getClassLoader(); - } - }); - this.classLoader = new WeakReference<ClassLoader>( cl ); - } - - try { - Class<?> osgiResolverClass = - Class.forName("org.apache.tuscany.sca.contribution.osgi.impl.OSGiClassReferenceModelResolver"); - if (osgiResolverClass != null) { - Constructor<?> constructor = - osgiResolverClass.getConstructor(Contribution.class, FactoryExtensionPoint.class); - this.osgiResolver = (ModelResolver)constructor.newInstance(contribution, modelFactories); - } - } catch (Throwable e) { - // Ignore error, non-OSGi classloading is used in this case - } - } - - public void addModel(Object resolved) { - ClassReference clazz = (ClassReference)resolved; - map.put(clazz.getClassName(), clazz); - } - - public Object removeModel(Object resolved) { - return map.remove(((ClassReference)resolved).getClassName()); - } - - - - public <T> T resolveModel(Class<T> modelClass, T unresolved) { - if (!(unresolved instanceof ClassReference)) { - return unresolved; - } - Object resolved = map.get(((ClassReference)unresolved).getClassName()); - - if (resolved != null) { - return modelClass.cast(resolved); - } - - //Load a class on demand - Class<?> clazz = null; - - if (osgiResolver != null) { - resolved = osgiResolver.resolveModel(modelClass, unresolved); - clazz = ((ClassReference)resolved).getJavaClass(); - } - - if (clazz == null) { - try { - // Search contribution ClassLoader (which has visibility of classes in the contribution - // as well as explicitly imported packages from other contributions) - clazz = Class.forName(((ClassReference)unresolved).getClassName(), true, classLoader.get()); - } catch (ClassNotFoundException e) { - } catch (NoClassDefFoundError e) { - } - } - - if (clazz != null) { - //if we load the class - // Store a new ClassReference wrapping the loaded class - ClassReference classReference = new ClassReference(clazz); - map.put(clazz.getName(), classReference); - - // Return the resolved ClassReference - return modelClass.cast(classReference); - } else { - return unresolved; - } - - } - - - /*************** - * Helper methods - ***************/ - - private String getPackageName(ClassReference clazz) { - int pos = clazz.getClassName().lastIndexOf("."); - return clazz.getClassName().substring(0, pos); - } - -} diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java index c1e3f13b77..9b02ce4abb 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java @@ -20,9 +20,9 @@ package org.apache.tuscany.sca.contribution.java.impl; import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.monitor.Monitor; /** * A model resolver for Java exports. @@ -34,20 +34,20 @@ public class JavaExportModelResolver implements ModelResolver { private JavaExport export; private ModelResolver resolver; - public JavaExportModelResolver(JavaExport export, ModelResolver resolver, Monitor monitor) { + public JavaExportModelResolver(JavaExport export, ModelResolver resolver) { this.export = export; this.resolver = resolver; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { if (!(unresolved instanceof ClassReference)) { return unresolved; } @@ -66,7 +66,7 @@ public class JavaExportModelResolver implements ModelResolver { // Package matches the exported package, delegate to the // contribution's resolver - return resolver.resolveModel(modelClass, unresolved); + return resolver.resolveModel(modelClass, unresolved, context); } else { // Package is not exported, return the unresolved object diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java index 73fbea31a0..de25081832 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; 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; @@ -52,12 +53,10 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { private static final String PACKAGE = "package"; private final JavaImportExportFactory factory; - private final Monitor monitor; - public JavaExportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public JavaExportProcessor(FactoryExtensionPoint modelFactories) { super(); this.factory = modelFactories.getFactory(JavaImportExportFactory.class); - this.monitor = monitor; } /** @@ -67,7 +66,7 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { * @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(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -85,7 +84,7 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { /** * Process <export package=""/> */ - public JavaExport read(XMLStreamReader reader) throws ContributionReadException { + public JavaExport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { JavaExport javaExport = this.factory.createJavaExport(); QName element = null; @@ -100,7 +99,7 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { if (EXPORT_JAVA.equals(element)) { String packageName = reader.getAttributeValue(null, PACKAGE); if (packageName == null) { - error("AttributePackageMissing", reader); + error(context.getMonitor(), "AttributePackageMissing", reader); //throw new ContributionReadException("Attribute 'package' is missing"); } else javaExport.setPackage(packageName); @@ -121,13 +120,13 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(context.getMonitor(), "XMLStreamException", reader, ex); } return javaExport; } - public void write(JavaExport javaExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(JavaExport javaExport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <export.java> writer.writeStartElement(EXPORT_JAVA.getNamespaceURI(), EXPORT_JAVA.getLocalPart()); @@ -139,10 +138,10 @@ public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> { writer.writeEndElement(); } - public void resolve(JavaExport javaExport, ModelResolver resolver) throws ContributionResolveException { + public void resolve(JavaExport javaExport, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (javaExport.getPackage() != null) // Initialize the export resolver - javaExport.setModelResolver(new JavaExportModelResolver(javaExport, resolver, monitor)); + javaExport.setModelResolver(new JavaExportModelResolver(javaExport, resolver)); } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java index 484eddd222..344e730bdc 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.contribution.java.impl; import java.util.List; import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** @@ -48,15 +49,15 @@ public class JavaImportModelResolver implements ModelResolver { return contributions; } - public void addModel(Object resolved) { - modelResolver.addModel(resolved); + public void addModel(Object resolved, ProcessorContext context) { + modelResolver.addModel(resolved, context); } - public Object removeModel(Object resolved) { - return modelResolver.removeModel(resolved); + public Object removeModel(Object resolved, ProcessorContext context) { + return modelResolver.removeModel(resolved, context); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { - return modelResolver.resolveModel(modelClass, unresolved); + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { + return modelResolver.resolveModel(modelClass, unresolved, context); } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java index 48a1698bf4..c16660277a 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory; 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; @@ -53,12 +54,10 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { private static final String LOCATION = "location"; private final JavaImportExportFactory factory; - private final Monitor monitor; - public JavaImportProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public JavaImportProcessor(FactoryExtensionPoint modelFactories) { super(); this.factory = modelFactories.getFactory(JavaImportExportFactory.class); - this.monitor = monitor; } /** @@ -68,7 +67,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { * @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(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -86,7 +85,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { /** * Process <import.java package="" location=""/> */ - public JavaImport read(XMLStreamReader reader) throws ContributionReadException { + public JavaImport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { JavaImport javaImport = this.factory.createJavaImport(); QName element = null; @@ -101,7 +100,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { if (IMPORT_JAVA.equals(element)) { String packageName = reader.getAttributeValue(null, PACKAGE); if (packageName == null) { - error("AttributePackageMissing", reader); + error(context.getMonitor(), "AttributePackageMissing", reader); //throw new ContributionReadException("Attribute 'package' is missing"); } else javaImport.setPackage(packageName); @@ -125,13 +124,13 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(context.getMonitor(), "XMLStreamException", reader, ex); } return javaImport; } - public void write(JavaImport javaImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(JavaImport javaImport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <import.java> writer.writeStartElement(IMPORT_JAVA.getNamespaceURI(), IMPORT_JAVA.getLocalPart()); @@ -147,7 +146,7 @@ public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> { } - public void resolve(JavaImport model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(JavaImport model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java index 5c5ae22f77..7bf3c32c93 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportModelResolver.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.contribution.namespace.impl; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** @@ -34,21 +35,21 @@ public class NamespaceExportModelResolver implements ModelResolver { this.resolver = resolver; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { // Just delegate to the contribution's model resolver, namespace // based filtering is implemented in the model specific model // resolver, which know how to get the namespace of the particular // type of model that they handle - return resolver.resolveModel(modelClass, unresolved); + return resolver.resolveModel(modelClass, unresolved, context); } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java index 030fc1754b..a23f38e8ef 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java @@ -34,6 +34,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.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -57,17 +58,14 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen private final AssemblyFactory extensionFactory; private final StAXArtifactProcessor<Object> extensionProcessor; private final StAXAttributeProcessor<Object> attributeProcessor; - private final Monitor monitor; public NamespaceExportProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor, - StAXAttributeProcessor<Object> attributeProcessor, - Monitor monitor) { + StAXAttributeProcessor<Object> attributeProcessor) { this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class); this.extensionProcessor = extensionProcessor; this.attributeProcessor = attributeProcessor; - this.monitor = monitor; } /** @@ -77,7 +75,7 @@ public class NamespaceExportProcessor 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(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -95,7 +93,7 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen /** * Process <export namespace=""/> */ - public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException { + public NamespaceExport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { NamespaceExport namespaceExport = this.factory.createNamespaceExport(); QName element = null; @@ -110,14 +108,14 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen if (EXPORT.equals(element)) { String ns = reader.getAttributeValue(null, NAMESPACE); if (ns == null) { - error("AttributeNameSpaceMissing", reader); + error(context.getMonitor(), "AttributeNameSpaceMissing", reader); //throw new ContributionReadException("Attribute 'namespace' is missing"); } else { namespaceExport.setNamespace(ns); } - readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory); + readExtendedAttributes(reader, namespaceExport, attributeProcessor, extensionFactory, context); } else { - readExtendedElement(reader, namespaceExport, extensionProcessor); + readExtendedElement(reader, namespaceExport, extensionProcessor, context); } break; @@ -136,13 +134,13 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(context.getMonitor(), "XMLStreamException", reader, ex); } return namespaceExport; } - public void write(NamespaceExport namespaceExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(NamespaceExport namespaceExport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <export> writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart()); @@ -151,14 +149,14 @@ public class NamespaceExportProcessor extends BaseStAXArtifactProcessor implemen writer.writeAttribute(NAMESPACE, namespaceExport.getNamespace()); } - writeExtendedAttributes(writer, namespaceExport, attributeProcessor); + writeExtendedAttributes(writer, namespaceExport, attributeProcessor, context); - writeExtendedElements(writer, namespaceExport, extensionProcessor); + writeExtendedElements(writer, namespaceExport, extensionProcessor, context); writer.writeEndElement(); } - public void resolve(NamespaceExport namespaceExport, ModelResolver resolver) throws ContributionResolveException { + public void resolve(NamespaceExport namespaceExport, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (namespaceExport.getNamespace() != null) // Initialize the export's resolver diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java index b213d5e899..2efa8d6aca 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java @@ -34,6 +34,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.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -59,14 +60,11 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen private final AssemblyFactory extensionFactory; private final StAXArtifactProcessor<Object> extensionProcessor; private final StAXAttributeProcessor<Object> attributeProcessor; - private final Monitor monitor; public NamespaceImportProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor, - StAXAttributeProcessor<Object> attributeProcessor, - Monitor monitor) { + StAXAttributeProcessor<Object> attributeProcessor) { this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); - this.monitor = monitor; this.extensionFactory = modelFactories.getFactory(AssemblyFactory.class); this.extensionProcessor = extensionProcessor; this.attributeProcessor = attributeProcessor; @@ -79,7 +77,7 @@ public class NamespaceImportProcessor 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(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -97,7 +95,7 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen /** * Process <import namespace="" location=""/> */ - public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException { + public NamespaceImport read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { NamespaceImport namespaceImport = this.factory.createNamespaceImport(); QName element; @@ -112,7 +110,7 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen if (IMPORT.equals(element)) { String ns = reader.getAttributeValue(null, NAMESPACE); if (ns == null) { - error("AttributeNameSpaceMissing", reader); + error(context.getMonitor(), "AttributeNameSpaceMissing", reader); //throw new ContributionReadException("Attribute 'namespace' is missing"); } else { namespaceImport.setNamespace(ns); @@ -122,9 +120,9 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen if (location != null) { namespaceImport.setLocation(location); } - readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory); + readExtendedAttributes(reader, namespaceImport, attributeProcessor, extensionFactory, context); } else { - readExtendedElement(reader, namespaceImport, extensionProcessor); + readExtendedElement(reader, namespaceImport, extensionProcessor, context); } break; case XMLStreamConstants.END_ELEMENT: @@ -142,13 +140,13 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(context.getMonitor(), "XMLStreamException", reader, ex); } return namespaceImport; } - public void write(NamespaceImport namespaceImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(NamespaceImport namespaceImport, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <import> writer.writeStartElement(IMPORT.getNamespaceURI(), IMPORT.getLocalPart()); @@ -160,12 +158,12 @@ public class NamespaceImportProcessor extends BaseStAXArtifactProcessor implemen writer.writeAttribute(LOCATION, namespaceImport.getLocation()); } - writeExtendedAttributes(writer, namespaceImport, attributeProcessor); - writeExtendedElements(writer, namespaceImport, extensionProcessor); + writeExtendedAttributes(writer, namespaceImport, attributeProcessor, context); + writeExtendedElements(writer, namespaceImport, extensionProcessor, context); writer.writeEndElement(); } - public void resolve(NamespaceImport model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(NamespaceImport model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java index 5be0b188f4..9ac3aebaf6 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java @@ -34,8 +34,9 @@ public interface ArtifactProcessor<M> { * * @param model The model to resolve * @param resolver The resolver to use to resolve referenced models + * @param context The context for the processor */ - void resolve(M model, ModelResolver resolver) throws ContributionResolveException; + void resolve(M model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException; /** * Returns the type of model handled by this artifact processor. diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java index bae566639a..817e5a5ee2 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java @@ -260,25 +260,26 @@ public abstract class BaseStAXArtifactProcessor { /** * * @param reader - * @param elementName * @param extensible * @param extensionAttributeProcessor * @param extensionAttributeProcessor * @param extensionFactory + * @param context TODO + * @param elementName * @throws ContributionReadException * @throws XMLStreamException */ protected void readExtendedAttributes(XMLStreamReader reader, Extensible extensible, StAXAttributeProcessor extensionAttributeProcessor, - AssemblyFactory extensionFactory) throws ContributionReadException, + AssemblyFactory extensionFactory, ProcessorContext context) throws ContributionReadException, XMLStreamException { QName elementName = reader.getName(); for (int a = 0; a < reader.getAttributeCount(); a++) { QName attributeName = reader.getAttributeName(a); if (attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { if (!elementName.getNamespaceURI().equals(attributeName.getNamespaceURI())) { - Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader, context); Extension attributeExtension; if (attributeValue instanceof Extension) { attributeExtension = (Extension)attributeValue; @@ -296,29 +297,30 @@ public abstract class BaseStAXArtifactProcessor { /** * - * @param attributeModel * @param writer * @param extensibleElement * @param extensionAttributeProcessor + * @param context TODO + * @param attributeModel * @throws ContributionWriteException * @throws XMLStreamException */ protected void writeExtendedAttributes(XMLStreamWriter writer, Extensible extensibleElement, - StAXAttributeProcessor extensionAttributeProcessor) + StAXAttributeProcessor extensionAttributeProcessor, ProcessorContext context) throws ContributionWriteException, XMLStreamException { for (Extension extension : extensibleElement.getAttributeExtensions()) { if (extension.isAttribute()) { - extensionAttributeProcessor.write(extension, writer); + extensionAttributeProcessor.write(extension, writer, context); } } } protected void readExtendedElement(XMLStreamReader reader, Extensible extensible, - StAXArtifactProcessor extensionProcessor) throws ContributionReadException, + StAXArtifactProcessor extensionProcessor, ProcessorContext context) throws ContributionReadException, XMLStreamException { - Object ext = extensionProcessor.read(reader); + Object ext = extensionProcessor.read(reader, context); if (extensible != null) { extensible.getExtensions().add(ext); } @@ -326,10 +328,10 @@ public abstract class BaseStAXArtifactProcessor { protected void writeExtendedElements(XMLStreamWriter writer, Extensible extensible, - StAXArtifactProcessor extensionProcessor) throws ContributionWriteException, + StAXArtifactProcessor extensionProcessor, ProcessorContext context) throws ContributionWriteException, XMLStreamException { for (Object ext : extensible.getExtensions()) { - extensionProcessor.write(ext, writer); + extensionProcessor.write(ext, writer, context); } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java index 945be504be..9c176fe1bf 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java @@ -38,7 +38,6 @@ import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; @@ -52,11 +51,9 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends private ExtensionPointRegistry extensionPoints; private FactoryExtensionPoint modelFactories; - private MonitorFactory monitorFactory; private boolean loaded; private StAXArtifactProcessor<Object> extensibleStAXProcessor; private StAXAttributeProcessor<Object> extensibleStAXAttributeProcessor; - private Monitor monitor = null; /** * Constructs a new extension point. @@ -67,36 +64,12 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) - this.monitor = monitorFactory.createMonitor(); - this.extensibleStAXProcessor = - new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory, this.monitor); + this.extensibleStAXProcessor = new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory); StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); this.extensibleStAXAttributeProcessor = - new ExtensibleStAXAttributeProcessor(attributeExtensionPoint, inputFactory, outputFactory, this.monitor); - } - - /** - * Report a exception. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "contribution-validation-messages", - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } + new ExtensibleStAXAttributeProcessor(attributeExtensionPoint, inputFactory, outputFactory); } public void addArtifactProcessor(StAXArtifactProcessor<?> artifactProcessor) { @@ -143,7 +116,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class.getName()); } catch (IOException e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", extensibleStAXProcessor, ie); throw ie; } @@ -165,7 +137,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends StAXArtifactProcessor<?> processor = new LazyStAXArtifactProcessor(artifactType, modelTypeName, factoryName, processorDeclaration, extensionPoints, modelFactories, extensibleStAXProcessor, - extensibleStAXAttributeProcessor, monitor); + extensibleStAXAttributeProcessor); addArtifactProcessor(processor); } @@ -187,7 +159,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends private Class<?> modelType; private StAXArtifactProcessor<Object> extensionProcessor; private StAXAttributeProcessor<Object> extensionAttributeProcessor; - private Monitor monitor; LazyStAXArtifactProcessor(QName artifactType, String modelTypeName, @@ -196,8 +167,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends ExtensionPointRegistry extensionPoints, FactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor, - StAXAttributeProcessor<Object> extensionAttributeProcessor, - Monitor monitor) { + StAXAttributeProcessor<Object> extensionAttributeProcessor) { this.extensionPoints = extensionPoints; this.artifactType = artifactType; @@ -206,14 +176,13 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends this.processorDeclaration = processorDeclaration; this.extensionProcessor = extensionProcessor; this.extensionAttributeProcessor = extensionAttributeProcessor; - this.monitor = monitor; } public QName getArtifactType() { return artifactType; } - 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(), @@ -250,14 +219,10 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends processorClass.getConstructor(FactoryExtensionPoint.class, QName.class, Class.class, - Object.class, - Monitor.class); - processor = - constructor - .newInstance(modelFactories, artifactType, getModelType(), modelFactory, monitor); + Object.class); + processor = constructor.newInstance(modelFactories, artifactType, getModelType(), modelFactory); } catch (Exception e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); throw ie; } } else { @@ -270,83 +235,51 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends (Class<StAXArtifactProcessor>)processorDeclaration.loadClass(); try { Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); - processor = constructor.newInstance(modelFactories, monitor); + processorClass.getConstructor(FactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); } catch (NoSuchMethodException e) { try { Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, monitor); + processorClass.getConstructor(ExtensionPointRegistry.class); + processor = constructor.newInstance(extensionPoints); } catch (NoSuchMethodException e1) { try { Constructor<StAXArtifactProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, - StAXArtifactProcessor.class, - Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); + StAXArtifactProcessor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor); } catch (NoSuchMethodException e2) { try { Constructor<StAXArtifactProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, - StAXAttributeProcessor.class, - Monitor.class); + StAXAttributeProcessor.class); processor = constructor.newInstance(modelFactories, extensionProcessor, - extensionAttributeProcessor, - monitor); + extensionAttributeProcessor); } catch (NoSuchMethodException e2a) { try { Constructor<StAXArtifactProcessor> constructor = processorClass.getConstructor(ExtensionPointRegistry.class, - StAXArtifactProcessor.class, - Monitor.class); - processor = - constructor.newInstance(extensionPoints, extensionProcessor, monitor); + StAXArtifactProcessor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor); } catch (NoSuchMethodException e3) { try { Constructor<StAXArtifactProcessor> constructor = processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, - StAXAttributeProcessor.class, - Monitor.class); + StAXAttributeProcessor.class); processor = constructor.newInstance(extensionPoints, extensionProcessor, - extensionAttributeProcessor, - monitor); + extensionAttributeProcessor); } catch (NoSuchMethodException e3a) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class); - processor = constructor.newInstance(modelFactories); - } catch (NoSuchMethodException e4) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class); - processor = constructor.newInstance(extensionPoints); - } catch (NoSuchMethodException e4a) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass - .getConstructor(FactoryExtensionPoint.class, - StAXArtifactProcessor.class); - processor = - constructor.newInstance(modelFactories, - extensionProcessor); - } catch (NoSuchMethodException e5) { - Constructor<StAXArtifactProcessor> constructor = - processorClass - .getConstructor(ExtensionPointRegistry.class, - StAXArtifactProcessor.class); - processor = - constructor.newInstance(extensionPoints, - extensionProcessor); - } - } - } + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(); + processor = constructor.newInstance(); + } } } @@ -355,7 +288,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends } } catch (Exception e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); throw ie; } } @@ -363,14 +295,15 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends return processor; } - public Object read(XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException { - return getProcessor().read(inputSource); + public Object read(XMLStreamReader inputSource, ProcessorContext context) throws ContributionReadException, + XMLStreamException { + return getProcessor().read(inputSource, context); } @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, - XMLStreamException { - getProcessor().write(model, outputSource); + public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + getProcessor().write(model, outputSource, context); } public Class<?> getModelType() { @@ -379,7 +312,6 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends modelType = processorDeclaration.loadClass(modelTypeName); } catch (Exception e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); throw ie; } } @@ -387,8 +319,9 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends } @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - getProcessor().resolve(model, resolver); + public void resolve(Object model, ModelResolver resolver, ProcessorContext context) + throws ContributionResolveException { + getProcessor().resolve(model, resolver, context); } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java index d13885bce9..66a605c46a 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java @@ -69,8 +69,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends if (monitorFactory != null) { this.monitor = monitorFactory.createMonitor(); } - this.extensibleStAXAttributeProcessor = - new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory, this.monitor); + this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory); } /** @@ -158,8 +157,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends // Create a processor wrapper and register it StAXAttributeProcessor<?> processor = new LazyStAXAttributeProcessor(artifactType, modelTypeName, factoryName, processorDeclaration, - extensionPoints, modelFactories, extensibleStAXAttributeProcessor, - monitor); + extensionPoints, modelFactories, extensibleStAXAttributeProcessor); addArtifactProcessor(processor); } @@ -180,7 +178,6 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends private StAXAttributeProcessor<?> processor; private Class<?> modelType; private StAXAttributeProcessor<Object> extensionProcessor; - private Monitor monitor; LazyStAXAttributeProcessor(QName artifactType, String modelTypeName, @@ -188,8 +185,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends ServiceDeclaration processorDeclaration, ExtensionPointRegistry extensionPoints, FactoryExtensionPoint modelFactories, - StAXAttributeProcessor<Object> extensionProcessor, - Monitor monitor) { + StAXAttributeProcessor<Object> extensionProcessor) { this.extensionPoints = extensionPoints; this.artifactType = artifactType; @@ -197,26 +193,12 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends this.factoryName = factoryName; this.processorDeclaration = processorDeclaration; this.extensionProcessor = extensionProcessor; - this.monitor = monitor; } public QName getArtifactType() { return artifactType; } - private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "contribution-validation-messages", - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } - } - @SuppressWarnings("unchecked") private StAXAttributeProcessor getProcessor() { if (processor == null) { @@ -228,27 +210,25 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends (Class<StAXAttributeProcessor>)processorDeclaration.loadClass(); try { Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); - processor = constructor.newInstance(modelFactories, monitor); + processorClass.getConstructor(FactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); } catch (NoSuchMethodException e) { try { Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, monitor); + processorClass.getConstructor(ExtensionPointRegistry.class); + processor = constructor.newInstance(extensionPoints); } catch (NoSuchMethodException e1) { try { Constructor<StAXAttributeProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, - StAXArtifactProcessor.class, - Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); + StAXArtifactProcessor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor); } catch (NoSuchMethodException e2) { try { Constructor<StAXAttributeProcessor> constructor = processorClass.getConstructor(ExtensionPointRegistry.class, - StAXArtifactProcessor.class, - Monitor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); + StAXArtifactProcessor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor); } catch (NoSuchMethodException e3) { try { Constructor<StAXAttributeProcessor> constructor = @@ -260,18 +240,11 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends processorClass.getConstructor(ExtensionPointRegistry.class); processor = constructor.newInstance(extensionPoints); } catch (NoSuchMethodException e4a) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, - StAXArtifactProcessor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor); - } catch (NoSuchMethodException e5) { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, - StAXArtifactProcessor.class); - processor = - constructor.newInstance(extensionPoints, extensionProcessor); - } + + Constructor<StAXAttributeProcessor> constructor = + processorClass.getConstructor(); + processor = constructor.newInstance(); + } } } @@ -280,7 +253,6 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends } } catch (Exception e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); throw ie; } @@ -288,15 +260,15 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends return processor; } - public Object read(QName attributeName, XMLStreamReader inputSource) throws ContributionReadException, - XMLStreamException { - return getProcessor().read(attributeName, inputSource); + public Object read(QName attributeName, XMLStreamReader inputSource, ProcessorContext context) + throws ContributionReadException, XMLStreamException { + return getProcessor().read(attributeName, inputSource, context); } @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, - XMLStreamException { - getProcessor().write(model, outputSource); + public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + getProcessor().write(model, outputSource, context); } public Class<?> getModelType() { @@ -305,7 +277,6 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends modelType = processorDeclaration.loadClass(modelTypeName); } catch (Exception e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); throw ie; } } @@ -313,8 +284,9 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends } @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - getProcessor().resolve(model, resolver); + public void resolve(Object model, ModelResolver resolver, ProcessorContext context) + throws ContributionResolveException { + getProcessor().resolve(model, resolver, context); } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java index 3c7c2f1430..3fc6140f6d 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java @@ -38,10 +38,6 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; /** * The default implementation of a URL artifact processor extension point. @@ -54,7 +50,6 @@ public class DefaultURLArtifactProcessorExtensionPoint extends private ExtensionPointRegistry extensionPoints; private StAXArtifactProcessor<?> staxProcessor; private boolean loaded; - private Monitor monitor = null; /** * Constructs a new extension point. @@ -65,32 +60,9 @@ public class DefaultURLArtifactProcessorExtensionPoint extends XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class); XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class); UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) - this.monitor = monitorFactory.createMonitor(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, this.monitor); - } - - /** - * Report a exception. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "contribution-validation-messages", - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } public void addArtifactProcessor(URLArtifactProcessor<?> artifactProcessor) { @@ -232,7 +204,6 @@ public class DefaultURLArtifactProcessorExtensionPoint extends ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class.getName()); } catch (IOException e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", staxProcessor, ie); throw ie; } @@ -245,7 +216,7 @@ public class DefaultURLArtifactProcessorExtensionPoint extends // Create a processor wrapper and register it URLArtifactProcessor<?> processor = new LazyURLArtifactProcessor(artifactType, modelTypeName, processorDeclaration, extensionPoints, - staxProcessor, monitor); + staxProcessor); addArtifactProcessor(processor); } @@ -265,39 +236,23 @@ public class DefaultURLArtifactProcessorExtensionPoint extends private URLArtifactProcessor<?> processor; private Class<?> modelType; private StAXArtifactProcessor<?> staxProcessor; - private Monitor monitor; LazyURLArtifactProcessor(String artifactType, String modelTypeName, ServiceDeclaration processorDeclaration, ExtensionPointRegistry extensionPoints, - StAXArtifactProcessor<?> staxProcessor, - Monitor monitor) { + StAXArtifactProcessor<?> staxProcessor) { this.artifactType = artifactType; this.modelTypeName = modelTypeName; this.processorDeclaration = processorDeclaration; this.extensionPoints = extensionPoints; this.staxProcessor = staxProcessor; - this.monitor = monitor; } public String getArtifactType() { return artifactType; } - private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - "contribution-validation-messages", - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } - } - @SuppressWarnings("unchecked") private URLArtifactProcessor getProcessor() { if (processor == null) { @@ -308,35 +263,32 @@ public class DefaultURLArtifactProcessorExtensionPoint extends (Class<URLArtifactProcessor>)processorDeclaration.loadClass(); try { Constructor<URLArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); - processor = constructor.newInstance(modelFactories, monitor); + processorClass.getConstructor(FactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); } catch (NoSuchMethodException e) { try { Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(FactoryExtensionPoint.class, - StAXArtifactProcessor.class, - Monitor.class); - processor = constructor.newInstance(modelFactories, staxProcessor, monitor); + StAXArtifactProcessor.class); + processor = constructor.newInstance(modelFactories, staxProcessor); } catch (NoSuchMethodException e2) { Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(ExtensionPointRegistry.class, - StAXArtifactProcessor.class, - Monitor.class); - processor = constructor.newInstance(extensionPoints, staxProcessor, monitor); + StAXArtifactProcessor.class); + processor = constructor.newInstance(extensionPoints, staxProcessor); } } } catch (Throwable e) { IllegalStateException ie = new IllegalStateException("Exception during getProcessor() for " + processorDeclaration.getClassName(), e); - error("IllegalStateException", processor, ie); throw ie; } } return processor; } - public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { - return getProcessor().read(contributionURL, artifactURI, artifactURL); + public Object read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException { + return getProcessor().read(contributionURL, artifactURI, artifactURL, context); } public Class<?> getModelType() { @@ -345,7 +297,6 @@ public class DefaultURLArtifactProcessorExtensionPoint extends modelType = processorDeclaration.loadClass(modelTypeName); } catch (ClassNotFoundException e) { IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); throw ie; } } @@ -353,18 +304,18 @@ public class DefaultURLArtifactProcessorExtensionPoint extends } @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { - getProcessor().resolve(model, resolver); + public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + getProcessor().resolve(model, resolver, context); } // end method resolve /** * Preresolve phase, for ExtendedURLArtifactProcessors only */ @SuppressWarnings("unchecked") - public void preResolve( Object model, ModelResolver resolver ) throws ContributionResolveException { + public void preResolve( Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { URLArtifactProcessor<?> processor = getProcessor(); if( processor instanceof ExtendedURLArtifactProcessor ) { - ((ExtendedURLArtifactProcessor)processor).preResolve(model, resolver); + ((ExtendedURLArtifactProcessor)processor).preResolve(model, resolver, context); } // end if } // end method resolve diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java index 952adbc4e3..ca579110ae 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java @@ -34,7 +34,8 @@ public interface ExtendedArtifactProcessor<M> extends ArtifactProcessor<M> { * * @param model The model to resolve * @param resolver The resolver to use to resolve referenced models + * @param context The context */ - void preResolve(M model, ModelResolver resolver) throws ContributionResolveException; + void preResolve(M model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException; } // end interface diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java index a31b24a295..91db32b806 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java @@ -34,6 +34,8 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; 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; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; @@ -54,7 +56,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXArtifactProcessorExtensionPoint processors; - private Monitor monitor; + /** * Constructs a new ExtensibleStAXArtifactProcessor. @@ -64,8 +66,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob */ public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors, XMLInputFactory inputFactory, - XMLOutputFactory outputFactory, - Monitor monitor) { + XMLOutputFactory outputFactory) { super(); this.processors = processors; this.inputFactory = inputFactory; @@ -73,7 +74,17 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob if (this.outputFactory != null) { this.outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); } - this.monitor = monitor; + } + + public ExtensibleStAXArtifactProcessor(ExtensionPointRegistry registry) { + super(); + this.processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.inputFactory = factories.getFactory(XMLInputFactory.class); + this.outputFactory = factories.getFactory(XMLOutputFactory.class); + if (this.outputFactory != null) { + this.outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); + } } /** @@ -83,7 +94,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob * @param message * @param model */ - private void warning(String message, Object model, Object... messageParameters) { + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -103,7 +114,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob * @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(), @@ -123,7 +134,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob * @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(), @@ -136,8 +147,8 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob } } - public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException { - + public Object read(XMLStreamReader source, ProcessorContext context) throws ContributionReadException, XMLStreamException { + Monitor monitor = context.getMonitor(); // Delegate to the processor associated with the element QName int event = source.getEventType(); if (event == XMLStreamConstants.START_DOCUMENT) { @@ -147,49 +158,49 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob StAXArtifactProcessor<?> processor = (StAXArtifactProcessor<?>)processors.getProcessor(name); if (processor == null) { Location location = source.getLocation(); - error("ElementCannotBeProcessed", processors, name, location); + error(monitor, "ElementCannotBeProcessed", processors, name, location); StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT); if (anyElementProcessor != null) { - return anyElementProcessor.read(source); + return anyElementProcessor.read(source, context); } else { return null; } } - return processor.read(source); + return processor.read(source, context); } @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { - + public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) throws ContributionWriteException, XMLStreamException { + Monitor monitor = context.getMonitor(); // Delegate to the processor associated with the model type if (model != null) { StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); if (processor != null) { - processor.write(model, outputSource); + processor.write(model, outputSource, context); } else { if (logger.isLoggable(Level.WARNING)) { logger.warning("No StAX processor is configured to handle " + model.getClass()); } if (!XMLStreamReader.class.isInstance(model)) { - warning("NoStaxProcessor", processors, model.getClass()); + warning(monitor, "NoStaxProcessor", processors, model.getClass()); } StAXArtifactProcessor anyElementProcessor = processors.getProcessor(ANY_ELEMENT); if (anyElementProcessor != null) { - anyElementProcessor.write(model, outputSource); + anyElementProcessor.write(model, outputSource, context); } } } } @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Delegate to the processor associated with the model type if (model != null) { StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); if (processor != null) { - processor.resolve(model, resolver); + processor.resolve(model, resolver, context); } } } @@ -198,10 +209,12 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob * Read a model from an InputStream. * @param is The artifact InputStream * @param type Model type + * @param context TODO * @return The model * @throws ContributionReadException */ - public <M> M read(InputStream is, Class<M> type) throws ContributionReadException { + public <M> M read(InputStream is, Class<M> type, ProcessorContext context) throws ContributionReadException { + Monitor monitor = context.getMonitor(); try { XMLStreamReader reader; try { @@ -209,11 +222,11 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob try { reader.nextTag(); QName name = reader.getName(); - Object mo = read(reader); + Object mo = read(reader, context); if (type.isInstance(mo)) { return type.cast(mo); } else { - error("UnrecognizedElementException", reader, name); + error(monitor, "UnrecognizedElementException", reader, name); UnrecognizedElementException e = new UnrecognizedElementException(name); throw e; } @@ -221,7 +234,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob Location location = reader.getLocation(); e.setLine(location.getLineNumber()); e.setColumn(location.getColumnNumber()); - error("ContributionReadException", reader, e); + error(monitor, "ContributionReadException", reader, e); throw e; } finally { try { @@ -239,7 +252,7 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob } } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", inputFactory, ce); + error(monitor, "ContributionReadException", inputFactory, ce); throw ce; } } @@ -248,17 +261,18 @@ public class ExtensibleStAXArtifactProcessor implements StAXArtifactProcessor<Ob * Write a model to an OutputStream. * @param model * @param os + * @param context * @throws ContributionWriteException */ - public void write(Object model, OutputStream os) throws ContributionWriteException { + public void write(Object model, OutputStream os, ProcessorContext context) throws ContributionWriteException { try { XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os); - write(model, writer); + write(model, writer, context); writer.flush(); writer.close(); } catch (XMLStreamException e) { ContributionWriteException cw = new ContributionWriteException(e); - error("ContributionWriteException", outputFactory, cw); + error(context.getMonitor(), "ContributionWriteException", outputFactory, cw); throw cw; } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java index 084396f733..aa159ac629 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java @@ -57,8 +57,6 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXAttributeProcessorExtensionPoint processors; - private Monitor monitor; - /** * Constructs a new ExtensibleStAXArtifactProcessor. * @param processors @@ -67,8 +65,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< */ public ExtensibleStAXAttributeProcessor(StAXAttributeProcessorExtensionPoint processors, XMLInputFactory inputFactory, - XMLOutputFactory outputFactory, - Monitor monitor) { + XMLOutputFactory outputFactory) { super(); this.processors = processors; this.inputFactory = inputFactory; @@ -76,7 +73,6 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< if (this.outputFactory != null) { this.outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); } - this.monitor = monitor; } /** @@ -86,7 +82,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< * @param message * @param model */ - private void warning(String message, Object model, Object... messageParameters) { + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), @@ -106,7 +102,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< * @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(), @@ -126,7 +122,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< * @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(), @@ -139,7 +135,7 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< } } - public Object read(QName attributeName, XMLStreamReader source) throws ContributionReadException, + public Object read(QName attributeName, XMLStreamReader source, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Delegate to the processor associated with the attribute QName int event = source.getEventType(); @@ -158,10 +154,10 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< if (logger.isLoggable(Level.WARNING)) { logger.warning("Attribute " + attributeName + " cannot be processed. (" + location + ")"); } - warning("AttributeCannotBeProcessed", processors, attributeName, location); + warning(context.getMonitor(), "AttributeCannotBeProcessed", processors, attributeName, location); } } else { - return processor.read(attributeName, source); + return processor.read(attributeName, source, context); } //handle extension attributes without processors @@ -171,14 +167,14 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< if (logger.isLoggable(Level.WARNING)) { logger.warning("Could not find Default Attribute processor !"); } - warning("DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location); + warning(context.getMonitor(), "DefaultAttributeProcessorNotAvailable", processors, ANY_ATTRIBUTE, location); } - return processor == null ? null : processor.read(attributeName, source); + return processor == null ? null : processor.read(attributeName, source, context); } @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { + public void write(Object model, XMLStreamWriter outputSource, ProcessorContext context) throws ContributionWriteException, XMLStreamException { if (model == null) { return; @@ -191,10 +187,10 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< if (logger.isLoggable(Level.WARNING)) { logger.warning("No StAX processor is configured to handle " + model.getClass()); } - warning("NoStaxProcessor", processors, model.getClass()); + warning(context.getMonitor(), "NoStaxProcessor", processors, model.getClass()); } } else { - processor.write(model, outputSource); + processor.write(model, outputSource, context); return; } @@ -204,21 +200,21 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< if (logger.isLoggable(Level.WARNING)) { logger.warning("No Default StAX processor is configured to handle " + model.getClass()); } - warning("NoDefaultStaxProcessor", processors, model.getClass()); + warning(context.getMonitor(), "NoDefaultStaxProcessor", processors, model.getClass()); } else { - processor.write(model, outputSource); + processor.write(model, outputSource, context); return; } } @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Delegate to the processor associated with the model type if (model != null) { StAXAttributeProcessor processor = processors.getProcessor(model.getClass()); if (processor != null) { - processor.resolve(model, resolver); + processor.resolve(model, resolver, context); } } } @@ -240,15 +236,15 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< * @param os * @throws ContributionWriteException */ - public void write(Object model, OutputStream os) throws ContributionWriteException { + public void write(Object model, OutputStream os, ProcessorContext context) throws ContributionWriteException { try { XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os); - write(model, writer); + write(model, writer, context); writer.flush(); writer.close(); } catch (XMLStreamException e) { ContributionWriteException cw = new ContributionWriteException(e); - error("ContributionWriteException", outputFactory, cw); + error(context.getMonitor(), "ContributionWriteException", outputFactory, cw); throw cw; } } @@ -258,6 +254,6 @@ public class ExtensibleStAXAttributeProcessor implements StAXAttributeProcessor< } public Class<Object> getModelType() { - return null; + return Object.class; } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java index 7b4a7cff3a..77940df5aa 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java @@ -37,16 +37,14 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Object> { private URLArtifactProcessorExtensionPoint processors; - private Monitor monitor; /** * Constructs a new ExtensibleURLArtifactProcessor. * * @param processors */ - public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors, Monitor monitor) { + public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors) { this.processors = processors; - this.monitor = monitor; } /** @@ -56,7 +54,7 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje * @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(), @@ -70,7 +68,7 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje } @SuppressWarnings("unchecked") - public Object read(URL contributionURL, URI sourceURI, URL sourceURL) throws ContributionReadException { + public Object read(URL contributionURL, URI sourceURI, URL sourceURL, ProcessorContext context) throws ContributionReadException { URLArtifactProcessor<Object> processor = null; if (sourceURI != null) { //try to retrieve a processor for the specific URI @@ -108,51 +106,40 @@ public class ExtensibleURLArtifactProcessor implements URLArtifactProcessor<Obje if (processor == null) { return null; } - return processor.read(contributionURL, sourceURI, sourceURL); + return processor.read(contributionURL, sourceURI, sourceURL, context); } @SuppressWarnings("unchecked") - public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Object model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Delegate to the processor associated with the model type if (model != null) { URLArtifactProcessor processor = processors.getProcessor(model.getClass()); if (processor != null) { - processor.resolve(model, resolver); + processor.resolve(model, resolver, context); } } } - public <M> M read(URL contributionURL, URI artifactURI, URL artifactUrl, Class<M> type) + public <M> M read(URL contributionURL, URI artifactURI, URL artifactUrl, ProcessorContext context, Class<M> type) throws ContributionReadException { - Object mo = read(contributionURL, artifactURI, artifactUrl); + Object mo = read(contributionURL, artifactURI, artifactUrl, context); if (type.isInstance(mo)) { return type.cast(mo); } else { UnrecognizedElementException e = new UnrecognizedElementException(null); e.setResourceURI(artifactURI.toString()); - error("UnrecognizedElementException", processors, artifactURI.toString()); + error(context.getMonitor(), "UnrecognizedElementException", processors, artifactURI.toString()); throw e; } } public String getArtifactType() { - return null; + return ""; } public Class<Object> getModelType() { - return null; + return Object.class; } - /** - * Returns the file name from a URL. - * @param url - * @return - */ - private static String getFileName(URL url) { - String fileName = url.getPath(); - int pos = fileName.lastIndexOf("/"); - - return fileName.substring(pos + 1); - } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java new file mode 100644 index 0000000000..16404ec78a --- /dev/null +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ProcessorContext.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +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; + +/** + * Context for contribution processors + */ +public class ProcessorContext { + protected Contribution contribution; + protected Monitor monitor; + protected Object parentModel; + + /** + * @param contribution + * @param monitor + */ + public ProcessorContext(Contribution contribution, Monitor monitor) { + super(); + this.contribution = contribution; + this.monitor = monitor; + } + + public ProcessorContext(Monitor monitor) { + super(); + this.monitor = monitor; + } + + public ProcessorContext(ExtensionPointRegistry registry) { + super(); + MonitorFactory monitorFactory = + registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class); + this.monitor = monitorFactory.createMonitor(); + } + + public ProcessorContext() { + super(); + this.monitor = new DefaultMonitorFactory().createMonitor(); + } + + public Contribution getContribution() { + return contribution; + } + + public Contribution setContribution(Contribution contribution) { + Contribution old = this.contribution; + this.contribution = contribution; + return old; + } + + public Monitor getMonitor() { + return monitor; + } + + public Monitor setMonitor(Monitor monitor) { + Monitor old = this.monitor; + this.monitor = monitor; + return old; + } + + public Object getParentModel() { + return parentModel; + } + + public Object setParentModel(Object parentMObject) { + Object old = this.parentModel; + this.parentModel = parentMObject; + return old; + } + +} diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java index 1bf9b4d494..8927acd776 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java @@ -36,19 +36,21 @@ public interface StAXArtifactProcessor<M> extends ArtifactProcessor<M> { * Reads a model from an XMLStreamReader. * * @param reader The XMLStreamReader + * @param context The context * @return A model representation of the input. */ - M read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException; + M read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException; /** * Writes a model to an XMLStreamWriter. * * @param model A model representing the source * @param writer The XML stream writer + * @param context TODO * @throws ContributionWriteException * @throws XMLStreamException */ - void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException; + void write(M model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException; /** * Returns the type of artifact handled by this artifact processor. diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java index b25bf0d669..d33b2c1028 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java @@ -35,21 +35,23 @@ public interface StAXAttributeProcessor<M> extends ArtifactProcessor<M>{ /** * Reads a model from an XMLStreamReader. - * * @param reader The XMLStreamReader + * @param context The context + * * @return A model representation of the input. */ - M read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException; + M read(QName attributeName, XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException; /** * Writes a model to an XMLStreamWriter. * * @param model A model representing the source * @param writer The XML stream writer + * @param context The context * @throws ContributionWriteException * @throws XMLStreamException */ - void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException; + void write(M model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException; /** * Returns the type of artifact handled by this artifact processor. diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java index c44ca0c66a..dd098283bc 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java @@ -36,9 +36,10 @@ public interface URLArtifactProcessor<M> extends ArtifactProcessor<M> { * @param contributionURL Contribution location URL * @param artifactURI Artifact URI * @param artifactURL Artifact location URL + * @param context The context * @return A model representation of the input. */ - M read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException; + M read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException; /** * Returns the type of artifact handled by this artifact processor. diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java index c5bbe3008f..09a6b7dd80 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionContentProcessor.java @@ -37,6 +37,7 @@ import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor; 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.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; @@ -64,36 +65,20 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso private FactoryExtensionPoint modelFactories; private URLArtifactProcessor<Object> artifactProcessor; private StAXArtifactProcessor<Object> extensionProcessor; - // private UtilityExtensionPoint utilities; - private Monitor monitor; private ContributionScannerExtensionPoint scanners; // Marks pre-resolve phase completed private boolean preResolved = false; - public ContributionContentProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { + public ContributionContentProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor) { this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); this.modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - this.monitor = monitor; URLArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors, this.monitor); + this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors); this.extensionProcessor = extensionProcessor; this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); this.scanners = extensionPoints.getExtensionPoint(ContributionScannerExtensionPoint.class); } - /* - public ContributionContentProcessor(FactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, - URLArtifactProcessor<Object> artifactProcessor, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { - this.modelFactories = modelFactories; - this.modelResolvers = modelResolvers; - hackResolvers(modelResolvers); - this.artifactProcessor = artifactProcessor; - this.extensionProcessor = extensionProcessor; - this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); - this.monitor = monitor; - } - */ - public String getArtifactType() { return ".contribution/content"; } @@ -116,19 +101,21 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso return null; } - public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException { + public Contribution read(URL parentURL, URI contributionURI, URL contributionURL, ProcessorContext context) throws ContributionReadException { // Create contribution model Contribution contribution = contributionFactory.createContribution(); contribution.setURI(contributionURI.toString()); contribution.setLocation(contributionURL.toString()); - ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, monitor); + ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); contribution.setModelResolver(modelResolver); contribution.setUnresolved(true); + Monitor monitor = context.getMonitor(); monitor.pushContext("Contribution: " + contribution.getURI()); + Contribution old = context.setContribution(contribution); try { // Create a contribution scanner ContributionScanner scanner = scanners.getContributionScanner(contributionURL.getProtocol()); @@ -153,18 +140,19 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso artifact.setURI(artifactURI); artifact.setLocation(artifactURL.toString()); artifacts.add(artifact); - modelResolver.addModel(artifact); + modelResolver.addModel(artifact, context); monitor.pushContext("Artifact: " + artifactURI); + old = context.setContribution(contribution); try { // Read each artifact - Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL); + Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL, context); if (model != null) { artifact.setModel(model); // Add the loaded model to the model resolver - modelResolver.addModel(model); + modelResolver.addModel(model, context); // Merge contribution metadata into the contribution model if (model instanceof ContributionMetadata) { @@ -179,6 +167,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso } } finally { monitor.popContext(); + context.setContribution(old); } } @@ -200,6 +189,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso } } finally { monitor.popContext(); + context.setContribution(old); } return contribution; @@ -213,26 +203,28 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso * @param resolver - the Resolver to use * @throws ContributionResolveException */ - public void preResolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { + public void preResolve(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Resolve the contribution model itself ModelResolver contributionResolver = contribution.getModelResolver(); contribution.setUnresolved(false); - contributionResolver.addModel(contribution); + contributionResolver.addModel(contribution, context); // Resolve Exports - resolveExports(contribution, contributionResolver); + resolveExports(contribution, contributionResolver, context); // Resolve Imports - resolveImports(contribution, contributionResolver); + resolveImports(contribution, contributionResolver, context); preResolved = true; } // end method preResolve - public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); + Contribution old = context.setContribution(contribution); try { monitor.pushContext("Contribution: " + contribution.getURI()); - if( !preResolved ) preResolve( contribution, resolver); + if( !preResolved ) preResolve( contribution, resolver, context); ModelResolver contributionResolver = contribution.getModelResolver(); // Resolve all artifact models @@ -240,7 +232,7 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso Object model = artifact.getModel(); if (model != null) { try { - artifactProcessor.resolve(model, contributionResolver); + artifactProcessor.resolve(model, contributionResolver, context); } catch (Throwable e) { throw new ContributionResolveException(e); } @@ -251,13 +243,14 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso List<Composite> deployables = contribution.getDeployables(); for (int i = 0, n = deployables.size(); i < n; i++) { Composite deployable = deployables.get(i); - Composite resolved = (Composite)contributionResolver.resolveModel(Composite.class, deployable); + Composite resolved = (Composite)contributionResolver.resolveModel(Composite.class, deployable, context); if (resolved != deployable) { deployables.set(i, resolved); } } // end for } finally { monitor.popContext(); + context.setContribution(old); } // end try } // end method resolve @@ -266,13 +259,13 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso * @param contribution * @param resolver */ - private void resolveExports(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { + private void resolveExports(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { for (Export export: contribution.getExports()) { if (export instanceof DefaultExport) { // Initialize the default export's resolver export.setModelResolver(resolver); } else { - extensionProcessor.resolve(export, resolver); + extensionProcessor.resolve(export, resolver, context); } // end if } // end for @@ -283,9 +276,9 @@ public class ContributionContentProcessor implements ExtendedURLArtifactProcesso * @param contribution * @param resolver */ - private void resolveImports(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { + private void resolveImports(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { for (Import import_: contribution.getImports()) { - extensionProcessor.resolve(import_, resolver); + extensionProcessor.resolve(import_, resolver, context); } // end for } // end method resolveImports diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java deleted file mode 100644 index 2bb6b59e57..0000000000 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/ContributionInfoProcessor.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.contribution.processor.impl; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.common.java.io.IOHelper; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.ContributionMetadata; -import org.apache.tuscany.sca.contribution.DefaultExport; -import org.apache.tuscany.sca.contribution.DefaultImport; -import org.apache.tuscany.sca.contribution.Export; -import org.apache.tuscany.sca.contribution.Import; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.ClassReference; -import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; -import org.apache.tuscany.sca.contribution.scanner.ContributionScanner; -import org.apache.tuscany.sca.contribution.scanner.impl.DirectoryContributionScanner; -import org.apache.tuscany.sca.contribution.scanner.impl.JarContributionScanner; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * URLArtifactProcessor that handles contribution files and returns a contribution - * info model. - * - * @version $Rev$ $Date$ - */ -public class ContributionInfoProcessor implements URLArtifactProcessor<Contribution>{ - private ContributionFactory contributionFactory; - private ModelResolverExtensionPoint modelResolvers; - private FactoryExtensionPoint modelFactories; - private URLArtifactProcessorExtensionPoint artifactProcessors; - private URLArtifactProcessor<Object> artifactProcessor; - private StAXArtifactProcessor<Object> extensionProcessor; - private Monitor monitor; - - public ContributionInfoProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { - this.monitor = monitor; - this.modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - this.modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - hackResolvers(modelResolvers); - URLArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - this.artifactProcessors = artifactProcessors; - this.artifactProcessor = new ExtensibleURLArtifactProcessor(artifactProcessors, monitor); - this.extensionProcessor = extensionProcessor; - this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); - } - - public ContributionInfoProcessor(FactoryExtensionPoint modelFactories, ModelResolverExtensionPoint modelResolvers, URLArtifactProcessor<Object> artifactProcessor) { - this.modelFactories = modelFactories; - this.modelResolvers = modelResolvers; - hackResolvers(modelResolvers); - this.artifactProcessor = artifactProcessor; - this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); - } - - public String getArtifactType() { - return ".contribution/info"; - } - - public Class<Contribution> getModelType() { - return null; - } - - public Contribution read(URL parentURL, URI contributionURI, URL contributionURL) throws ContributionReadException { - - // Create contribution model - Contribution contribution = contributionFactory.createContribution(); - contribution.setURI(contributionURI.toString()); - contribution.setLocation(contributionURL.toString()); - ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, monitor); - contribution.setModelResolver(modelResolver); - contribution.setUnresolved(true); - - // Create a contribution scanner - ContributionScanner scanner = null; - if (scanner == null) { - try { - if ("file".equals(contributionURL.getProtocol()) && new File(contributionURL.toURI()).isDirectory()) { - scanner = new DirectoryContributionScanner(); - } else { - scanner = new JarContributionScanner(); - } - } catch (URISyntaxException e) { - throw new ContributionReadException(e); - } - } - - // Read generated and user sca-contribution.xml files - boolean contributionMetadata = false; - for (String path: new String[]{ - Contribution.SCA_CONTRIBUTION_GENERATED_META, - Contribution.SCA_CONTRIBUTION_META}) { - URL url = scanner.getArtifactURL(contribution, path); - try { - // Check if the file actually exists before trying to read it - InputStream is = IOHelper.openStream(url); - is.close(); - } catch (IOException e) { - continue; - } - contributionMetadata = true; - - // Read the sca-contribution.xml file - ContributionMetadata c = (ContributionMetadata)artifactProcessor.read(contributionURL, URI.create(path), url); - contribution.getImports().addAll(c.getImports()); - contribution.getExports().addAll(c.getExports()); - contribution.getDeployables().addAll(c.getDeployables()); - contribution.getExtensions().addAll(c.getExtensions()); - contribution.getAttributeExtensions().addAll(c.getAttributeExtensions()); - } - - // If no sca-contribution.xml file was provided then consider - // all composites in the contribution as deployables, and also - // read any files that are explicitly asssigned artifact processors - // as they are likely to provide relevant metadata info - if (!contributionMetadata) { - List<String> artifactURIs; - try { - artifactURIs = scanner.scan(contribution); - } catch (ContributionReadException e) { - artifactURIs = null; - } - if (artifactURIs != null) { - for (String artifactURI: artifactURIs) { - boolean read = false; - if (artifactURI.endsWith(".composite")) { - read = true; - } else { - int s= artifactURI.lastIndexOf("/"); - String fileName = artifactURI.substring(s + 1); - if (artifactProcessors.getProcessor(fileName) != null) { - read = true; - } - } - if (read) { - URL artifactURL = scanner.getArtifactURL(contribution, artifactURI); - - // Read each artifact - Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL); - - // In the absence of more info, consider all composites as deployable - if (model instanceof Composite) { - contribution.getDeployables().add((Composite)model); - } - } - } - } - - // Add default contribution import and export - DefaultImport defaultImport = contributionFactory.createDefaultImport(); - defaultImport.setModelResolver(new DefaultModelResolver()); - contribution.getImports().add(defaultImport); - DefaultExport defaultExport = contributionFactory.createDefaultExport(); - contribution.getExports().add(defaultExport); - } - - return contribution; - } - - public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException { - - // Mark the contribution model resolved - ModelResolver contributionResolver = contribution.getModelResolver(); - contribution.setUnresolved(false); - contributionResolver.addModel(contribution); - - // Resolve imports and exports - for (Export export: contribution.getExports()) { - if (export instanceof DefaultExport) { - - // Initialize the default export's resolver - export.setModelResolver(contributionResolver); - - } else { - extensionProcessor.resolve(export, contributionResolver); - } - } - for (Import import_: contribution.getImports()) { - extensionProcessor.resolve(import_, contributionResolver); - } - - } - - /** - * FIXME Temporary hack for testing the ClassLoaderModelResolver. - * - * @param modelResolvers - */ - private static void hackResolvers(ModelResolverExtensionPoint modelResolvers) { - Class<?> resolverClass = modelResolvers.getResolver(ClassReference.class); - if (resolverClass==null || !resolverClass.getName().equals("org.apache.tuscany.sca.contribution.java.impl.ClassLoaderModelResolver")) { - try { - Class<?> loaderResolverClass = Class.forName("org.apache.tuscany.sca.contribution.java.impl.ClassLoaderModelResolver", true, ContributionContentProcessor.class.getClassLoader()); - modelResolvers.addResolver(ClassReference.class, (Class<? extends ModelResolver>)loaderResolverClass); - } catch (ClassNotFoundException e) { - } - } - } -} diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java index 3188b1ca60..f589c6b911 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyAttributeProcessor.java @@ -30,10 +30,10 @@ 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.ExtensibleStAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * A Policy Processor used for testing. @@ -44,7 +44,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements private AssemblyFactory assemblyFactory; - public AnyAttributeProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public AnyAttributeProcessor(FactoryExtensionPoint modelFactories) { this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); } @@ -56,7 +56,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements return Extension.class; } - public Extension read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Extension read(QName attributeName, XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { String attributeValue = reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart()); Extension ext = assemblyFactory.createExtension(); ext.setQName(attributeName); @@ -65,7 +65,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements return ext; } - public void write(Extension attributeExtension, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(Extension attributeExtension, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeAttribute(attributeExtension.getQName().getPrefix(), attributeExtension.getQName().getNamespaceURI(), attributeExtension.getQName().getLocalPart(), @@ -73,7 +73,7 @@ public class AnyAttributeProcessor extends BaseStAXArtifactProcessor implements // are just the string representation fo the attribute } - public void resolve(Extension model, ModelResolver modelResolver) throws ContributionResolveException { + public void resolve(Extension model, ModelResolver modelResolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java index 0b471d1146..db4feeec48 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/xml/AnyElementProcessor.java @@ -31,25 +31,20 @@ import org.apache.tuscany.sca.common.xml.stax.StAXHelper; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; 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.resolver.ModelResolver; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; public class AnyElementProcessor implements StAXArtifactProcessor<Extension> { private AssemblyFactory assemblyFactory; private StAXHelper helper; - @SuppressWarnings("unused") - private Monitor monitor; - - - public AnyElementProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) { + public AnyElementProcessor(ExtensionPointRegistry extensionPoints, StAXArtifactProcessor<Object> extensionProcessor) { FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.helper = StAXHelper.getInstance(extensionPoints); - this.monitor = monitor; } public QName getArtifactType() { @@ -68,7 +63,7 @@ public class AnyElementProcessor implements StAXArtifactProcessor<Extension> { * @return * @throws XMLStreamException */ - public Extension read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public Extension read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { QName name = reader.getName(); String xml = helper.saveAsString(reader); Extension ext = assemblyFactory.createExtension(); @@ -84,7 +79,7 @@ public class AnyElementProcessor implements StAXArtifactProcessor<Extension> { * @param model * @param writer */ - public void write(Extension model, XMLStreamWriter writer) throws XMLStreamException { + public void write(Extension model, XMLStreamWriter writer, ProcessorContext context) throws XMLStreamException { Object value = model.getValue(); if (!(value instanceof String)) { return; @@ -96,6 +91,6 @@ public class AnyElementProcessor implements StAXArtifactProcessor<Extension> { helper.save(reader, writer); } - public void resolve(Extension model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(Extension model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java index 13c622adf0..e17dd176a6 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.contribution.resolver; import java.util.List; import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; /** * A model resolver implementation that delegates to a list of model resolvers. @@ -36,22 +37,22 @@ public class DefaultDelegatingModelResolver implements ModelResolver { this.resolvers = resolvers; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { //TODO optimize and cache results of the resolution later // Go over all resolvers for (ModelResolver resolver: resolvers) { - Object resolved = resolver.resolveModel(modelClass, unresolved); + Object resolved = resolver.resolveModel(modelClass, unresolved, context); // Return the resolved model object if (resolved instanceof Base) { diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java index 5cbf37cf70..7745253bba 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java @@ -25,6 +25,7 @@ import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; /** * A model resolver implementation that considers Exports in a list of contributions. @@ -41,15 +42,15 @@ public class DefaultImportAllModelResolver implements ModelResolver { this.contributions = contributions; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { //TODO optimize and cache results of the resolution later @@ -61,7 +62,7 @@ public class DefaultImportAllModelResolver implements ModelResolver { // If the export matches the export, try to resolve the model object if (import_.match(export)) { - Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved); + Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved, context); // Return the resolved model object if (resolved instanceof Base) { diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java index 9ae57c41d0..8a11cb42f8 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java @@ -23,6 +23,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; /** * A model resolver implementation that delegates to a list of exports. @@ -37,22 +38,22 @@ public class DefaultImportModelResolver implements ModelResolver { this.exports = exports; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { throw new IllegalStateException(); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { //TODO optimize and cache results of the resolution later // Go over all exports for (Export export: exports) { - Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved); + Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved, context); // Return the resolved model object if (resolved instanceof Base) { diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java index 12e5543672..94b2fb0058 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java @@ -25,8 +25,8 @@ import java.util.Map; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.DefaultImport; import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * A default implementation of a model resolver based on a map. @@ -41,11 +41,11 @@ public class DefaultModelResolver implements ModelResolver { public DefaultModelResolver() { } - public DefaultModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public DefaultModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.contribution = contribution; } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { Object resolved = map.get(unresolved); if (resolved != null) { @@ -59,7 +59,7 @@ public class DefaultModelResolver implements ModelResolver { if (contribution != null){ for (Import _import : contribution.getImports()){ if (_import instanceof DefaultImport){ - resolved = _import.getModelResolver().resolveModel(modelClass, unresolved); + resolved = _import.getModelResolver().resolveModel(modelClass, unresolved, context); if (resolved != unresolved){ return modelClass.cast(resolved); } @@ -72,11 +72,11 @@ public class DefaultModelResolver implements ModelResolver { } } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { map.put(resolved, resolved); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(resolved); } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java index 1e6c0f7a18..72e4b03c7f 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java @@ -24,8 +24,8 @@ import java.util.HashMap; import java.util.Map; import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * An implementation of an extensible model resolver which delegates to the @@ -42,31 +42,6 @@ public class ExtensibleModelResolver implements ModelResolver { private final Map<Class<?>, ModelResolver> resolversByImplementationClass = new HashMap<Class<?>, ModelResolver>(); private Map<Object, Object> map = new HashMap<Object, Object>(); private Object lastUnresolved; - private Monitor monitor; - - /** - * Constructs an extensible model resolver - * - * @param contribution - * @param resolverExtensions - * @param modelFactories - * @param defaultResolver - */ - @Deprecated - public ExtensibleModelResolver(Contribution contribution, - ModelResolverExtensionPoint resolverExtensions, - FactoryExtensionPoint modelFactories, - ModelResolver defaultResolver, - Monitor monitor) { - this.contribution = contribution; - this.resolverExtensions = resolverExtensions; - this.modelFactories = modelFactories; - //FIXME Remove this default resolver, this is currently used to resolve policy declarations - // but they should be handled by the contribution import/export mechanism instead of this - // defaultResolver hack. - this.defaultResolver = defaultResolver; - this.monitor = monitor; - } /** * Constructs an extensible model resolver @@ -77,12 +52,10 @@ public class ExtensibleModelResolver implements ModelResolver { */ public ExtensibleModelResolver(Contribution contribution, ModelResolverExtensionPoint resolverExtensions, - FactoryExtensionPoint modelFactories, - Monitor monitor) { + FactoryExtensionPoint modelFactories) { this.contribution = contribution; this.resolverExtensions = resolverExtensions; this.modelFactories = modelFactories; - this.monitor = monitor; } /** @@ -123,10 +96,10 @@ public class ExtensibleModelResolver implements ModelResolver { try { Constructor<? extends ModelResolver> constructor = resolverClass - .getConstructor(new Class[] {Contribution.class, FactoryExtensionPoint.class, Monitor.class}); + .getConstructor(new Class[] {Contribution.class, FactoryExtensionPoint.class}); if (constructor != null) { - resolverInstance = constructor.newInstance(contribution, modelFactories, monitor); + resolverInstance = constructor.newInstance(contribution, modelFactories); resolversByImplementationClass.put(resolverClass, resolverInstance); resolversByModelType.put(c, resolverInstance); return resolverInstance; @@ -140,25 +113,25 @@ public class ExtensibleModelResolver implements ModelResolver { return null; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { ModelResolver resolver = getModelResolverInstance(resolved.getClass()); if (resolver != null) { - resolver.addModel(resolved); + resolver.addModel(resolved, context); } else { map.put(resolved, resolved); } } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { ModelResolver resolver = getModelResolverInstance(resolved.getClass()); if (resolver != null) { - return resolver.removeModel(resolved); + return resolver.removeModel(resolved, context); } else { return map.remove(resolved); } } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { // Protect against dependency cycles causing infinite recursion // Save the current unresolved object and check later if we are trying // to resolve the same object again @@ -169,7 +142,7 @@ public class ExtensibleModelResolver implements ModelResolver { ModelResolver resolver = getModelResolverInstance(unresolved.getClass()); if (resolver != null) { - Object resolved = resolver.resolveModel(modelClass, unresolved); + Object resolved = resolver.resolveModel(modelClass, unresolved, context); if (resolved != null && resolved != unresolved) { lastUnresolved = null; return modelClass.cast(resolved); @@ -179,7 +152,7 @@ public class ExtensibleModelResolver implements ModelResolver { // but they should be handled by the contribution import/export mechanism instead of this // defaultResolver hack. if (defaultResolver != null) { - Object resolved = defaultResolver.resolveModel(modelClass, unresolved); + Object resolved = defaultResolver.resolveModel(modelClass, unresolved, context); if (resolved != null && resolved != unresolved) { lastUnresolved = null; return modelClass.cast(resolved); diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java index 2831bebbc4..ec8495d1d2 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java @@ -19,6 +19,8 @@ package org.apache.tuscany.sca.contribution.resolver; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; + /** * A model resolver, responsible for resolving models in the scope of an * SCA contribution. @@ -47,23 +49,26 @@ public interface ModelResolver { * * @param modelClass the type of artifact * @param unresolved the unresolved model + * @param context The context * @return the resolved model */ - <T> T resolveModel(Class<T> modelClass, T unresolved); + <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context); /** * Add a resolved model. * * @param resolved The model + * @param context */ - void addModel(Object resolved); + void addModel(Object resolved, ProcessorContext context); /** * Remove a resolved model. * * @param resolved + * @param context * @return The removed model, or null if the model was not removed */ - Object removeModel(Object resolved); + Object removeModel(Object resolved, ProcessorContext context); } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java index 0035f360ab..2a36d4fd54 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java @@ -22,7 +22,6 @@ import javax.xml.stream.XMLInputFactory; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * URLArtifactProcessor that handles sca-contribution-generated.xml files. @@ -32,15 +31,13 @@ import org.apache.tuscany.sca.monitor.Monitor; public class ContributionGeneratedMetadataDocumentProcessor extends ContributionMetadataDocumentProcessor { public ContributionGeneratedMetadataDocumentProcessor(XMLInputFactory inputFactory, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { - super(inputFactory, staxProcessor, monitor); + StAXArtifactProcessor staxProcessor) { + super(inputFactory, staxProcessor); } public ContributionGeneratedMetadataDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { - super(modelFactories, staxProcessor, monitor); + StAXArtifactProcessor staxProcessor) { + super(modelFactories, staxProcessor); } @Override diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java index 0ab817e1bc..69cd29ea2e 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java @@ -31,6 +31,7 @@ import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.contribution.ContributionMetadata; 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; @@ -48,22 +49,17 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; public class ContributionMetadataDocumentProcessor implements URLArtifactProcessor<ContributionMetadata>{ private final StAXArtifactProcessor staxProcessor; private final XMLInputFactory inputFactory; - private final Monitor monitor; public ContributionMetadataDocumentProcessor(XMLInputFactory inputFactory, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { + StAXArtifactProcessor staxProcessor) { this.inputFactory = inputFactory; this.staxProcessor = staxProcessor; - this.monitor = monitor; } public ContributionMetadataDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { + StAXArtifactProcessor staxProcessor) { this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); this.staxProcessor = staxProcessor; - this.monitor = monitor; } /** @@ -73,7 +69,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess * @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(), "contribution-xml-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); @@ -88,7 +84,7 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess return ContributionMetadata.class; } - public ContributionMetadata read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + public ContributionMetadata read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { InputStream urlStream = null; try { @@ -98,17 +94,17 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess reader.nextTag(); // Read the contribution model - ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); + ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context); return contribution; } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", inputFactory, ex); + error(context.getMonitor(), "XMLStreamException", inputFactory, ex); throw ex; } catch (IOException e) { ContributionReadException ex = new ContributionReadException(e); - error("IOException", inputFactory, ex); + error(context.getMonitor(), "IOException", inputFactory, ex); throw ex; } finally { try { @@ -122,8 +118,8 @@ public class ContributionMetadataDocumentProcessor implements URLArtifactProcess } } - public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException { - staxProcessor.resolve(contribution, resolver); + public void resolve(ContributionMetadata contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + staxProcessor.resolve(contribution, resolver, context); } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java index 7218a0fb73..4700041775 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java @@ -38,6 +38,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.processor.StAXAttributeProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -62,17 +63,15 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp private final ContributionFactory contributionFactory; private final StAXArtifactProcessor<Object> extensionProcessor; private final StAXAttributeProcessor<Object> attributeProcessor; - private Monitor monitor; + public ContributionMetadataProcessor(FactoryExtensionPoint modelFactories, StAXArtifactProcessor<Object> extensionProcessor, - StAXAttributeProcessor<Object> attributeProcessor, - Monitor monitor) { + StAXAttributeProcessor<Object> attributeProcessor) { this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); this.extensionProcessor = extensionProcessor; this.attributeProcessor = attributeProcessor; - this.monitor = monitor; } /** @@ -82,7 +81,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp * @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(), @@ -102,7 +101,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp * @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(), "contribution-xml-validation-messages", Severity.ERROR, @@ -119,7 +118,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp return ContributionMetadata.class; } - public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException { + public ContributionMetadata read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { ContributionMetadata contribution = null; QName name = null; @@ -135,14 +134,14 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp // Read <contribution> contribution = this.contributionFactory.createContributionMetadata(); contribution.setUnresolved(true); - readExtendedAttributes(reader, contribution, attributeProcessor, assemblyFactory); + readExtendedAttributes(reader, contribution, attributeProcessor, assemblyFactory, context); } else if (DEPLOYABLE_QNAME.equals(name)) { // Read <deployable> QName compositeName = getQName(reader, "composite"); if (compositeName == null) { - error("AttributeCompositeMissing", reader); + error(context.getMonitor(), "AttributeCompositeMissing", reader); //throw new ContributionReadException("Attribute 'composite' is missing"); } else { if (contribution != null) { @@ -155,7 +154,7 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp } else { // Read an extension element - Object extension = extensionProcessor.read(reader); + Object extension = extensionProcessor.read(reader, context); if (extension != null && contribution != null) { if (extension instanceof Import) { contribution.getImports().add((Import)extension); @@ -182,27 +181,27 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp } } catch (XMLStreamException e) { ContributionReadException ex = new ContributionReadException(e); - error("XMLStreamException", reader, ex); + error(context.getMonitor(), "XMLStreamException", reader, ex); } return contribution; } - public void write(ContributionMetadata contribution, XMLStreamWriter writer) throws ContributionWriteException, + public void write(ContributionMetadata contribution, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <contribution> writeStartDocument(writer, CONTRIBUTION_QNAME.getNamespaceURI(), CONTRIBUTION_QNAME.getLocalPart()); - writeExtendedAttributes(writer, contribution, attributeProcessor); + writeExtendedAttributes(writer, contribution, attributeProcessor, context); // Write <import> for (Import imp : contribution.getImports()) { - extensionProcessor.write(imp, writer); + extensionProcessor.write(imp, writer, context); } // Write <export> for (Export export : contribution.getExports()) { - extensionProcessor.write(export, writer); + extensionProcessor.write(export, writer, context); } // Write <deployable> @@ -217,28 +216,28 @@ public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor imp writeEndDocument(writer); } - public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ContributionMetadata contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Resolve imports and exports for (Export export : contribution.getExports()) { - extensionProcessor.resolve(export, resolver); + extensionProcessor.resolve(export, resolver, context); } for (Import import_ : contribution.getImports()) { - extensionProcessor.resolve(import_, resolver); + extensionProcessor.resolve(import_, resolver, context); } // Resolve deployable composites List<Composite> deployables = contribution.getDeployables(); for (int i = 0, n = deployables.size(); i < n; i++) { Composite deployable = deployables.get(i); - Composite resolved = (Composite)resolver.resolveModel(Composite.class, deployable); + Composite resolved = (Composite)resolver.resolveModel(Composite.class, deployable, context); if (resolved != deployable) { deployables.set(i, resolved); } } for (Object ext : contribution.getExtensions()) { - extensionProcessor.resolve(ext, resolver); + extensionProcessor.resolve(ext, resolver, context); } contribution.setUnresolved(false); diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java index 91e74edf47..916630939e 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java @@ -23,9 +23,9 @@ import java.util.HashMap; import java.util.Map; import org.apache.tuscany.sca.contribution.Contribution; +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 Contribution models. @@ -36,19 +36,19 @@ public class ContributionModelResolver implements ModelResolver { private Map<String, Contribution> map = new HashMap<String, Contribution>(); - public ContributionModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public ContributionModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { Contribution contribution = (Contribution)resolved; map.put(contribution.getURI(), contribution); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(((Contribution)resolved).getURI()); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { // Lookup a contribution for the given URI String uri = ((Contribution)unresolved).getURI(); diff --git a/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor index 560bf9abcb..f831bf061c 100644 --- a/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor +++ b/java/sca/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor @@ -19,4 +19,3 @@ org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor;type=/META-INF/sca-contribution.xml,model=org.apache.tuscany.sca.contribution.ContributionMetadata org.apache.tuscany.sca.contribution.xml.ContributionGeneratedMetadataDocumentProcessor;type=/META-INF/sca-contribution-generated.xml org.apache.tuscany.sca.contribution.processor.impl.ContributionContentProcessor;type=.contribution/content,model=org.apache.tuscany.sca.contribution.Contribution -org.apache.tuscany.sca.contribution.processor.impl.ContributionInfoProcessor;type=.contribution/info diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java deleted file mode 100644 index 13945eac24..0000000000 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java +++ /dev/null @@ -1,75 +0,0 @@ - /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.contribution.java.impl; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.apache.tuscany.sca.contribution.resolver.ClassReference; -import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; -import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Test ClassReferenceArtifactResolver. - * - * @version $Rev$ $Date$ - */ -public class ClassReferenceArtifactResolverTestCase { - private static ExtensibleModelResolver resolver; - - @BeforeClass - public static void setUp() throws Exception { - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - - ModelResolverExtensionPoint resolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - resolvers.addResolver(ClassReference.class, ClassReferenceModelResolver.class); - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - resolver = new ExtensibleModelResolver(null, resolvers, modelFactories, null); - } - - /** - * Test ClassReference resolution - * - */ - @Test - public void testResolveClass() { - ClassReference ref = new ClassReference(getClass().getName()); - ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); - assertFalse(clazz.isUnresolved()); - assertTrue(clazz.getJavaClass() == getClass()); - } - - /** - * Test ClassReference resolution of inexistent class - * - */ - @Test - public void testUnresolvedClass() { - ClassReference ref = new ClassReference("NonExistentClass"); - ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); - assertTrue(clazz.isUnresolved()); - assertTrue(clazz.getJavaClass() == null); - } -} diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java index c6bd430e96..f25fb5d981 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java @@ -29,14 +29,12 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.contribution.java.JavaExport; 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; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -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.monitor.Problem; import org.junit.Assert; import org.junit.BeforeClass; @@ -60,20 +58,17 @@ public class JavaExportProcessorTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; private static Monitor monitor; + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + monitor = context.getMonitor(); 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, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } /** @@ -83,7 +78,7 @@ public class JavaExportProcessorTestCase { @Test public void testLoad() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); - JavaExport javaExport = (JavaExport)staxProcessor.read(reader); + JavaExport javaExport = (JavaExport)staxProcessor.read(reader, context); Assert.assertEquals("org.apache.tuscany.sca.contribution.java", javaExport.getPackage()); } @@ -100,7 +95,7 @@ public class JavaExportProcessorTestCase { } catch (ContributionReadException e) { assertTrue(true); }*/ - staxProcessor.read(reader); + staxProcessor.read(reader, context); Problem problem = monitor.getLastProblem(); assertNotNull(problem); assertEquals("AttributePackageMissing", problem.getMessageId()); diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java index 7bcafd6c48..f3b52117bb 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java @@ -29,14 +29,12 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.contribution.java.JavaImport; 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; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -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.monitor.Problem; import org.junit.BeforeClass; import org.junit.Test; @@ -60,19 +58,18 @@ public class JavaImportProcessorTestCase { private static StAXArtifactProcessor<Object> staxProcessor; private static Monitor monitor; + private static ProcessorContext context; + + @BeforeClass public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + monitor = context.getMonitor(); 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, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } /** @@ -82,7 +79,7 @@ public class JavaImportProcessorTestCase { @Test public void testLoad() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); - JavaImport javaImport = (JavaImport)staxProcessor.read(reader); + JavaImport javaImport = (JavaImport)staxProcessor.read(reader, context); assertEquals("org.apache.tuscany.sca.contribution.java", javaImport.getPackage()); assertEquals("sca://contributions/001", javaImport.getLocation()); @@ -101,7 +98,7 @@ public class JavaImportProcessorTestCase { } catch (ContributionReadException e) { assertTrue(true); }*/ - staxProcessor.read(reader); + staxProcessor.read(reader, context); Problem problem = monitor.getLastProblem(); assertNotNull(problem); assertEquals("AttributePackageMissing", problem.getMessageId()); diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java index a1c5189767..cec66b23c3 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java @@ -29,14 +29,12 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; 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; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -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.monitor.Problem; import org.junit.BeforeClass; import org.junit.Test; @@ -60,21 +58,18 @@ public class NamespaceExportProcessorTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; private static Monitor monitor; + private static ProcessorContext context; @BeforeClass public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + monitor = context.getMonitor(); 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); } /** @@ -84,7 +79,7 @@ public class NamespaceExportProcessorTestCase { @Test public void testLoad() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); - NamespaceExport namespaceExport = (NamespaceExport)staxProcessor.read(reader); + NamespaceExport namespaceExport = (NamespaceExport)staxProcessor.read(reader, context); assertEquals("http://foo", namespaceExport.getNamespace()); assertEquals(1, namespaceExport.getAttributeExtensions().size()); assertEquals(1, namespaceExport.getExtensions().size()); @@ -103,7 +98,7 @@ public class NamespaceExportProcessorTestCase { } catch (ContributionReadException e) { assertTrue(true); }*/ - staxProcessor.read(reader); + staxProcessor.read(reader, context); Problem problem = monitor.getLastProblem(); assertNotNull(problem); assertEquals("AttributeNameSpaceMissing", problem.getMessageId()); diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java index 676437042d..03407f9065 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java @@ -31,14 +31,12 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; 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; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -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.monitor.Problem; import org.junit.BeforeClass; import org.junit.Test; @@ -63,20 +61,17 @@ public class NamespaceImportProcessorTestCase { private static XMLInputFactory inputFactory; private static StAXArtifactProcessor<Object> staxProcessor; private static Monitor monitor; + private static ProcessorContext context; @BeforeClass public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + monitor = context.getMonitor(); 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); } /** @@ -86,7 +81,7 @@ public class NamespaceImportProcessorTestCase { @Test public void testLoad() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); - NamespaceImport namespaceImport = (NamespaceImport)staxProcessor.read(reader); + NamespaceImport namespaceImport = (NamespaceImport)staxProcessor.read(reader, context); assertEquals("http://foo", namespaceImport.getNamespace()); assertEquals("sca://contributions/001", namespaceImport.getLocation()); @@ -107,7 +102,7 @@ public class NamespaceImportProcessorTestCase { } catch (ContributionReadException e) { assertTrue(true); }*/ - staxProcessor.read(reader); + staxProcessor.read(reader, context); Problem problem = monitor.getLastProblem(); assertNotNull(problem); assertEquals("AttributeNameSpaceMissing", problem.getMessageId()); diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java index 3a18e2b987..9587d3c024 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java @@ -77,11 +77,11 @@ public class URLartifactProcessorExtensionPointTestCase { public FileTypeArtifactProcessor() { } - public M1 read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + public M1 read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { return null; } - public void resolve(M1 m1, ModelResolver resolver) throws ContributionResolveException { + public void resolve(M1 m1, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } public String getArtifactType() { @@ -97,11 +97,11 @@ public class URLartifactProcessorExtensionPointTestCase { public FileNameArtifactProcessor() { } - public M2 read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + public M2 read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { return null; } - public void resolve(M2 m2, ModelResolver resolver) throws ContributionResolveException { + public void resolve(M2 m2, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } public String getArtifactType() { diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java index b778167217..58d1616aa2 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.DefaultContributionFactory; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.junit.Before; import org.junit.Test; @@ -45,28 +46,30 @@ public class DefaultModelResolverTestCase { @Test public void testResolved() { + ProcessorContext context = new ProcessorContext(); Model a = new Model("a"); - resolver.addModel(a); + resolver.addModel(a, context); Model x = new Model("a"); - x = resolver.resolveModel(Model.class, x); + x = resolver.resolveModel(Model.class, x, context); assertTrue(x == a); } @Test public void testUnresolved() { Model x = new Model("a"); - Model y = resolver.resolveModel(Model.class, x); + Model y = resolver.resolveModel(Model.class, x, new ProcessorContext()); assertTrue(x == y); } @Test public void testResolvedArtifact() { + ProcessorContext context = new ProcessorContext(); Artifact artifact = factory.createArtifact(); artifact.setURI("foo/bar"); - resolver.addModel(artifact); + resolver.addModel(artifact, context); Artifact x = factory.createArtifact(); x.setURI("foo/bar"); - x = resolver.resolveModel(Artifact.class, x); + x = resolver.resolveModel(Artifact.class, x, context); assertTrue(x == artifact); } diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java index b5cfa6f63d..d6461bd094 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java @@ -24,10 +24,10 @@ import static org.junit.Assert.assertTrue; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.DefaultContributionFactory; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.junit.Before; import org.junit.Test; @@ -40,16 +40,17 @@ public class ExtensibleModelResolverTestCase { private ExtensibleModelResolver resolver; private ContributionFactory factory; + private ProcessorContext context; @Before public void setUp() throws Exception { ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint(); resolvers.addResolver(Model.class, TestModelResolver.class); - + context = new ProcessorContext(); FactoryExtensionPoint factories = new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()); - resolver = new ExtensibleModelResolver(null, resolvers, factories, (Monitor)null); + resolver = new ExtensibleModelResolver(null, resolvers, factories); factory = new DefaultContributionFactory(); } @@ -57,32 +58,32 @@ public class ExtensibleModelResolverTestCase { @Test public void testResolvedDefault() { OtherModel a = new OtherModel("a"); - resolver.addModel(a); + resolver.addModel(a, context); OtherModel x = new OtherModel("a"); - x = resolver.resolveModel(OtherModel.class, x); + x = resolver.resolveModel(OtherModel.class, x, context); assertTrue(x == a); } @Test public void testResolvedRegisteredClass() { Model a = new Model("a"); - resolver.addModel(a); + resolver.addModel(a, context); Model x = new Model("a"); - x = resolver.resolveModel(Model.class, x); + x = resolver.resolveModel(Model.class, x, context); assertTrue(x == a); } @Test public void testUnresolvedDefault() { OtherModel x = new OtherModel("a"); - OtherModel y = resolver.resolveModel(OtherModel.class, x); + OtherModel y = resolver.resolveModel(OtherModel.class, x, context); assertTrue(x == y); } @Test public void testUnresolved() { Model x = new Model("a"); - Model y = resolver.resolveModel(Model.class, x); + Model y = resolver.resolveModel(Model.class, x, context); assertTrue(x == y); } @@ -90,10 +91,10 @@ public class ExtensibleModelResolverTestCase { public void testResolvedArtifact() { Artifact artifact = factory.createArtifact(); artifact.setURI("foo/bar"); - resolver.addModel(artifact); + resolver.addModel(artifact, context); Artifact x = factory.createArtifact(); x.setURI("foo/bar"); - x = resolver.resolveModel(Artifact.class, x); + x = resolver.resolveModel(Artifact.class, x, context); assertTrue(x == artifact); } diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java index 2782e9b318..c04d56cafe 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java @@ -23,8 +23,8 @@ import java.util.HashMap; import java.util.Map; import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * A test implementation of a model resolver, based on a map. @@ -35,10 +35,10 @@ public class TestModelResolver implements ModelResolver { private Map<Object, Object> map = new HashMap<Object, Object>(); - public TestModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public TestModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { Object resolved = map.get(unresolved); if (resolved != null) { // Return the resolved object @@ -48,11 +48,11 @@ public class TestModelResolver implements ModelResolver { return unresolved; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { map.put(resolved, resolved); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(resolved); } diff --git a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java index b72c476267..1d0ea5dc8a 100644 --- a/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java +++ b/java/sca/modules/contribution/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java @@ -33,14 +33,12 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.contribution.ContributionMetadata; 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; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -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.monitor.Problem; import org.junit.BeforeClass; import org.junit.Test; @@ -71,31 +69,25 @@ public class ContributionMetadataProcessorTestCase { private static XMLOutputFactory outputFactory; private static StAXArtifactProcessor<Object> staxProcessor; private static Monitor monitor; - + private static ProcessorContext context; + @BeforeClass public static void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); - + context = new ProcessorContext(extensionPoints); + monitor = context.getMonitor(); inputFactory = XMLInputFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); - - // 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, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } @Test public void testRead() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); - ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); + ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context); assertNotNull(contribution); assertEquals(2, contribution.getDeployables().size()); assertEquals(1, contribution.getAttributeExtensions().size()); @@ -111,7 +103,7 @@ public class ContributionMetadataProcessorTestCase { } catch (ContributionReadException e) { assertTrue(true); }*/ - staxProcessor.read(reader); + staxProcessor.read(reader, context); Problem problem = monitor.getLastProblem(); assertNotNull(problem); assertEquals("AttributeCompositeMissing", problem.getMessageId()); @@ -120,18 +112,18 @@ public class ContributionMetadataProcessorTestCase { @Test public void testWrite() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML)); - ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader); + ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context); validateContribution(contribution); //write the contribution metadata contents StringWriter stringWriter = new StringWriter(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter); - staxProcessor.write(contribution, writer); + staxProcessor.write(contribution, writer, context); stringWriter.close(); reader = inputFactory.createXMLStreamReader(new StringReader(stringWriter.toString())); - contribution = (ContributionMetadata)staxProcessor.read(reader); + contribution = (ContributionMetadata)staxProcessor.read(reader, context); validateContribution(contribution); } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java index c2fa113d5f..82f8ebabea 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointSerializerImpl.java @@ -30,6 +30,7 @@ import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; +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.ExtensionPointRegistry; @@ -37,12 +38,14 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.runtime.EndpointSerializer; public class EndpointSerializerImpl implements EndpointSerializer { + private ExtensionPointRegistry registry; private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXArtifactProcessor<Endpoint> processor; private StAXArtifactProcessor<EndpointReference> refProcessor; public EndpointSerializerImpl(ExtensionPointRegistry registry) { + this.registry =registry; FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); inputFactory = factories.getFactory(XMLInputFactory.class); outputFactory = factories.getFactory(XMLOutputFactory.class); @@ -55,7 +58,7 @@ public class EndpointSerializerImpl implements EndpointSerializer { public void read(Endpoint endpoint, String xml) throws IOException { try { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml)); - Endpoint result = processor.read(reader); + Endpoint result = processor.read(reader, new ProcessorContext(registry)); endpoint.setComponent(result.getComponent()); endpoint.setService(result.getService()); endpoint.setBinding(result.getBinding()); @@ -70,7 +73,7 @@ public class EndpointSerializerImpl implements EndpointSerializer { StringWriter sw = new StringWriter(); try { XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw); - processor.write(endpoint, writer); + processor.write(endpoint, writer, new ProcessorContext(registry)); writer.flush(); writer.close(); return sw.toString(); @@ -82,7 +85,7 @@ public class EndpointSerializerImpl implements EndpointSerializer { public void read(EndpointReference endpointReference, String xml) throws IOException { try { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml)); - EndpointReference result = refProcessor.read(reader); + EndpointReference result = refProcessor.read(reader, new ProcessorContext(registry)); reader.close(); endpointReference.setComponent(result.getComponent()); endpointReference.setReference(result.getReference()); @@ -97,7 +100,7 @@ public class EndpointSerializerImpl implements EndpointSerializer { StringWriter sw = new StringWriter(); try { XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw); - refProcessor.write(endpointReference, writer); + refProcessor.write(endpointReference, writer, new ProcessorContext(registry)); writer.flush(); writer.close(); return sw.toString(); diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java index 5daffab507..4d6a98ca5f 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/ReferenceParameterProcessor.java @@ -27,10 +27,10 @@ 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.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.runtime.ReferenceParameters; /** @@ -47,7 +47,7 @@ public class ReferenceParameterProcessor implements StAXArtifactProcessor<Refere * * @param modelFactories */ - public ReferenceParameterProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public ReferenceParameterProcessor(FactoryExtensionPoint modelFactories) { } /** @@ -58,18 +58,18 @@ public class ReferenceParameterProcessor implements StAXArtifactProcessor<Refere } /** - * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader) + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader, ProcessorContext) */ - public ReferenceParameters read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public ReferenceParameters read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { ReferenceParameters parameters = new ReferenceParametersImpl(); parameters.setCallbackID(reader.getAttributeValue(null, "callbackID")); return parameters; } /** - * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, javax.xml.stream.XMLStreamWriter) + * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, javax.xml.stream.XMLStreamWriter, ProcessorContext) */ - public void write(ReferenceParameters model, XMLStreamWriter writer) throws ContributionWriteException, + public void write(ReferenceParameters model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeStartElement(REFERENCE_PARAMETERS.getPrefix(), REFERENCE_PARAMETERS.getLocalPart(), @@ -90,9 +90,9 @@ public class ReferenceParameterProcessor implements StAXArtifactProcessor<Refere } /** - * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, org.apache.tuscany.sca.contribution.resolver.ModelResolver) + * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, org.apache.tuscany.sca.contribution.resolver.ModelResolver, ProcessorContext) */ - public void resolve(ReferenceParameters model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ReferenceParameters model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java index b0bbae0278..23126b5123 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java @@ -41,10 +41,12 @@ import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.context.CompositeContext; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; 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.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; @@ -326,7 +328,7 @@ public class ServiceReferenceImpl<B> implements ServiceReferenceExt<B> { public String toXMLString() throws IOException, XMLStreamException, ContributionWriteException{ StringWriter writer = new StringWriter(); XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(writer); - staxProcessor.write(endpointReference, streamWriter); + staxProcessor.write(endpointReference, streamWriter, new ProcessorContext(registry)); return writer.toString(); } @@ -365,7 +367,7 @@ public class ServiceReferenceImpl<B> implements ServiceReferenceExt<B> { streamReader = xmlInputFactory.createXMLStreamReader(reader); } - endpointReference = staxProcessor.read(streamReader); + endpointReference = staxProcessor.read(streamReader, new ProcessorContext(registry)); // ok to GC xmlReader = null; @@ -425,7 +427,8 @@ public class ServiceReferenceImpl<B> implements ServiceReferenceExt<B> { if (binding != null) { BindingBuilder bindingBuilder = builders.getBindingBuilder(binding.getType()); if (bindingBuilder != null) { - bindingBuilder.build(component, reference, endpointReference.getBinding(), null); + BuilderContext context = new BuilderContext(registry); + bindingBuilder.build(component, reference, endpointReference.getBinding(), context); } } diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java index 31fe4aa322..72a76a789e 100644 --- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java +++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java @@ -21,6 +21,8 @@ package org.apache.tuscany.sca.host.webapp; import java.io.IOException; import java.util.Enumeration; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.servlet.Filter; import javax.servlet.FilterConfig; @@ -33,7 +35,6 @@ import javax.servlet.http.HttpServletRequest; import org.apache.tuscany.sca.host.http.ServletHost; - /** * A Servlet filter that forwards service requests to the Servlets registered with * the Tuscany ServletHost. @@ -42,18 +43,29 @@ import org.apache.tuscany.sca.host.http.ServletHost; */ public class TuscanyServletFilter implements Filter { private static final long serialVersionUID = 1L; - + private Logger logger = Logger.getLogger(TuscanyServletFilter.class.getName()); + private transient ServletContext context; private transient ServletHost servletHost; + public TuscanyServletFilter() { + super(); + } + public void init(final FilterConfig config) throws ServletException { - context = config.getServletContext(); - for (Enumeration<String> e = config.getInitParameterNames(); e.hasMoreElements();) { - String name = e.nextElement(); - String value = config.getInitParameter(name); - context.setAttribute(name, value); + try { + context = config.getServletContext(); + for (Enumeration<String> e = config.getInitParameterNames(); e.hasMoreElements();) { + String name = e.nextElement(); + String value = config.getInitParameter(name); + context.setAttribute(name, value); + } + servletHost = ServletHostHelper.init(context); + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + context.log(e.getMessage(), e); + throw new ServletException(e); } - servletHost = ServletHostHelper.init(context); } public void destroy() { @@ -63,29 +75,34 @@ public class TuscanyServletFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain) throws IOException, ServletException { - - // Get the Servlet path - HttpServletRequest httpRequest = (HttpServletRequest)request; - String path = httpRequest.getPathInfo(); - if (path == null) { - path = httpRequest.getServletPath(); - } - if (path == null) { - path = "/"; - } - - // Get a request dispatcher for the Servlet mapped to that path - RequestDispatcher dispatcher = servletHost.getRequestDispatcher(path); - if (dispatcher != null) { - - // Let the dispatcher forward the request to the Servlet - dispatcher.forward(request, response); - - } else { - - // Proceed down the filter chain - chain.doFilter(request, response); - + try { + // Get the Servlet path + HttpServletRequest httpRequest = (HttpServletRequest)request; + String path = httpRequest.getPathInfo(); + if (path == null) { + path = httpRequest.getServletPath(); + } + if (path == null) { + path = "/"; + } + + // Get a request dispatcher for the Servlet mapped to that path + RequestDispatcher dispatcher = servletHost.getRequestDispatcher(path); + if (dispatcher != null) { + + // Let the dispatcher forward the request to the Servlet + dispatcher.forward(request, response); + + } else { + + // Proceed down the filter chain + chain.doFilter(request, response); + + } + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + context.log(e.getMessage(), e); + throw new ServletException(e); } } diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java index fbb1c0c39c..83860f59e5 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java @@ -38,6 +38,7 @@ 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.ContributionResolveException; +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.implementation.bpel.BPELProcessDefinition; @@ -58,27 +59,25 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class BPELDocumentModelResolver implements ModelResolver { - private WSDLFactory wsdlFactory; + private WSDLFactory wsdlFactory; private Contribution contribution; private Map<QName, BPELProcessDefinition> map = new HashMap<QName, BPELProcessDefinition>(); - private Monitor monitor; - - public BPELDocumentModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public BPELDocumentModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); this.contribution = contribution; } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { BPELProcessDefinition process = (BPELProcessDefinition)resolved; map.put(process.getName(), process); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(((BPELProcessDefinition)resolved).getName()); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { BPELProcessDefinition resolved = null; QName qname = ((BPELProcessDefinition)unresolved).getName(); @@ -92,7 +91,7 @@ public class BPELDocumentModelResolver implements ModelResolver { if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) { if (namespaceImport.getLocation() == null) { // Delegate the resolution to the import resolver - resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved); + resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } @@ -109,7 +108,7 @@ public class BPELDocumentModelResolver implements ModelResolver { for (String location : locations) { NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location); // Delegate the resolution to the namespace import resolver - resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved); + resolved = namespaceImport.getModelResolver().resolveModel(BPELProcessDefinition.class, (BPELProcessDefinition)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } @@ -121,7 +120,7 @@ public class BPELDocumentModelResolver implements ModelResolver { if(resolved.isUnresolved()) { try { - resolve(resolved); + resolve(resolved, context); } catch(Exception e) { //FIXME } @@ -134,7 +133,7 @@ public class BPELDocumentModelResolver implements ModelResolver { return (T)unresolved; } - public void resolve(BPELProcessDefinition unresolved) throws ContributionResolveException { + public void resolve(BPELProcessDefinition unresolved, ProcessorContext context) throws ContributionResolveException { // FIXME - serious resolving needs to happen here // Step 1 is to resolve the WSDL files referenced from this BPEL process @@ -150,12 +149,12 @@ public class BPELDocumentModelResolver implements ModelResolver { // callback interface. List<BPELImportElement> theImports = unresolved.getImports(); - Set<Definition> wsdlDefinitions = getImportedWSDLDefinitions( theImports, contribution.getModelResolver() ); + Set<Definition> wsdlDefinitions = getImportedWSDLDefinitions( theImports, contribution.getModelResolver(), context ); // Fetch the sets of partner links, port types and interfaces - List<BPELPartnerLinkTypeElement> thePLinkTypes = getPartnerLinkTypes( wsdlDefinitions ); + List<BPELPartnerLinkTypeElement> thePLinkTypes = getPartnerLinkTypes( wsdlDefinitions, context.getMonitor() ); Collection<WSDLInterface> theInterfaces = (Collection<WSDLInterface>)new ArrayList<WSDLInterface>(); - Collection<PortType> thePortTypes = getAllPortTypes( theImports, theInterfaces, contribution.getModelResolver() ); + Collection<PortType> thePortTypes = getAllPortTypes( theImports, theInterfaces, contribution.getModelResolver(), context ); // Store the Port Types and the Interfaces for later calculation of the component type... unresolved.getPortTypes().addAll(thePortTypes); @@ -167,7 +166,7 @@ public class BPELDocumentModelResolver implements ModelResolver { QName partnerLinkType = thePartnerLink.getPartnerLinkType(); BPELPartnerLinkTypeElement pLinkType = findPartnerLinkType(partnerLinkType, thePLinkTypes); if (pLinkType == null) { - error("PartnerLinkNoMatchingType", thePartnerLink, thePartnerLink.getName()); + error(context.getMonitor(), "PartnerLinkNoMatchingType", thePartnerLink, thePartnerLink.getName()); } else { thePartnerLink.setPartnerLinkType(pLinkType); } @@ -182,13 +181,13 @@ public class BPELDocumentModelResolver implements ModelResolver { * @param theImports - a list of the import statements * @return - a Set containing all the referenced WSDL definitions */ - private Set<Definition> getImportedWSDLDefinitions( List<BPELImportElement> theImports, ModelResolver resolver ) { + private Set<Definition> getImportedWSDLDefinitions( List<BPELImportElement> theImports, ModelResolver resolver, ProcessorContext context ) { Set<Definition> wsdlDefinitions = null; for (BPELImportElement theImport : theImports) { if (theImport.getImportType().equals(BPELProcessorConstants.WSDL_NS)) { // If the Import is a WSDL import, resolve the WSDL WSDLDefinition theWSDL = resolveWSDLDefinition( theImport.getLocation(), - theImport.getNamespace(), resolver ); + theImport.getNamespace(), resolver, context ); if( theWSDL != null ) { theImport.setWSDLDefinition( theWSDL ); @@ -210,9 +209,10 @@ public class BPELDocumentModelResolver implements ModelResolver { * @param wsdlLocation - a string containing the WSDL location * @param wsdlNamespace - a string containing the WSDL namespace * @param resolver - a model resolver + * @param context * @return - a WSDLDefinition object for the referenced WSDL, or null if the WSDL cannot be resolved */ - private WSDLDefinition resolveWSDLDefinition( String wsdlLocation, String wsdlNamespace, ModelResolver resolver ) { + private WSDLDefinition resolveWSDLDefinition( String wsdlLocation, String wsdlNamespace, ModelResolver resolver, ProcessorContext context ) { // Resolve the WSDL definition WSDLDefinition proxy = wsdlFactory.createWSDLDefinition(); @@ -221,11 +221,11 @@ public class BPELDocumentModelResolver implements ModelResolver { if (wsdlLocation != null) { proxy.setLocation(URI.create(wsdlLocation)); } - WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy); + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy, context); if (resolved != null && !resolved.isUnresolved()) { return resolved; } else { - error("CannotResolveWSDLReference", resolver, wsdlLocation, wsdlNamespace); + error(context.getMonitor(), "CannotResolveWSDLReference", resolver, wsdlLocation, wsdlNamespace); return null; } // end if } // end resolveWSDLDefinition @@ -238,7 +238,7 @@ public class BPELDocumentModelResolver implements ModelResolver { * @return - a List of PartnerLinkType elements */ @SuppressWarnings("unchecked") - private List<BPELPartnerLinkTypeElement> getPartnerLinkTypes( Set<Definition> wsdlDefinitions ) throws ContributionResolveException { + private List<BPELPartnerLinkTypeElement> getPartnerLinkTypes( Set<Definition> wsdlDefinitions, Monitor monitor ) throws ContributionResolveException { List<BPELPartnerLinkTypeElement> thePLinks = new ArrayList<BPELPartnerLinkTypeElement>(); @@ -268,7 +268,7 @@ public class BPELDocumentModelResolver implements ModelResolver { } // end for if (count == 0) { - error("PartnerLinkTypeNoRoles", theElement, pLinkElement.getName()); + error(monitor, "PartnerLinkTypeNoRoles", theElement, pLinkElement.getName()); throw new ContributionResolveException("partnerLinkType " + pLinkElement.getName() + " has no Roles defined"); } else thePLinks.add(pLinkElement); @@ -308,7 +308,9 @@ public class BPELDocumentModelResolver implements ModelResolver { */ @SuppressWarnings("unchecked") private Collection<PortType> getAllPortTypes(List<BPELImportElement> theImports, - Collection<WSDLInterface> theInterfaces, ModelResolver resolver) throws ContributionResolveException { + Collection<WSDLInterface> theInterfaces, + ModelResolver resolver, + ProcessorContext context) throws ContributionResolveException { Set<PortType> thePortTypes = new HashSet<PortType>(); for (BPELImportElement theImport : theImports) { @@ -335,15 +337,15 @@ public class BPELDocumentModelResolver implements ModelResolver { if (wsdlPortType != null) { // Introspect the WSDL portType and add the resulting WSDLInterface to the resolver try { - wsdlInterface = wsdlFactory.createWSDLInterface(wsdlPortType.getElement(), theWSDL, resolver); + wsdlInterface = wsdlFactory.createWSDLInterface(wsdlPortType.getElement(), theWSDL, resolver, context.getMonitor()); wsdlInterface.setWsdlDefinition(theWSDL); } catch (InvalidInterfaceException e) { ContributionResolveException ce = new ContributionResolveException("Unable to create WSDLInterface for portType " + portType.getQName(),e); - error("ContributionResolveException", resolver, ce); + error(context.getMonitor(), "ContributionResolveException", resolver, ce); throw ce; } // end try - resolver.addModel(wsdlInterface); + resolver.addModel(wsdlInterface, context); theInterfaces.add(wsdlInterface); } // end if } // end for @@ -361,7 +363,7 @@ public class BPELDocumentModelResolver implements ModelResolver { * @param message * @param model */ - private void warning(String message, Object model, Object... messageParameters) { + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -375,7 +377,7 @@ public class BPELDocumentModelResolver implements ModelResolver { * @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(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -389,7 +391,7 @@ public class BPELDocumentModelResolver implements ModelResolver { * @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(), "impl-bpel-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java index 06f801c30b..6b12f6666e 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java @@ -37,6 +37,7 @@ import org.apache.tuscany.sca.assembly.Property; 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.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -57,16 +58,14 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance(); - private final BPELFactory factory; - private WSDLFactory WSDLfactory; - private AssemblyFactory assemblyFactory; - private Monitor monitor; + private final BPELFactory factory; + private WSDLFactory WSDLfactory; + private AssemblyFactory assemblyFactory; - public BPELDocumentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.factory = modelFactories.getFactory(BPELFactory.class); - this.WSDLfactory = modelFactories.getFactory(WSDLFactory.class); - this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - this.monitor = monitor; + public BPELDocumentProcessor(FactoryExtensionPoint modelFactories) { + this.factory = modelFactories.getFactory(BPELFactory.class); + this.WSDLfactory = modelFactories.getFactory(WSDLFactory.class); + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); } public String getArtifactType() { @@ -84,24 +83,24 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * @param artifactURL - URL of the artifact containing the BPEL Process definition * @return BPELProcessDefinition - SCA model of the BPEL Process */ - public BPELProcessDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + public BPELProcessDefinition read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException { BPELProcessDefinition processDefinition = null; try { - processDefinition = readProcessDefinition(artifactURL); + processDefinition = readProcessDefinition(artifactURL, context.getMonitor()); processDefinition.setURI(artifactURI.toString()); processDefinition.setUnresolved(true); } catch (Exception e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", artifactURL, ce); + error(context.getMonitor(), "ContributionReadException", artifactURL, ce); } return processDefinition; } - public void resolve(BPELProcessDefinition model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(BPELProcessDefinition model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Delegate resolving to model resolver if (model != null || model.isUnresolved()) { - resolver.resolveModel(BPELProcessDefinition.class, model); + resolver.resolveModel(BPELProcessDefinition.class, model, context); } } // end resolve @@ -113,7 +112,7 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * @return * @throws Exception */ - private BPELProcessDefinition readProcessDefinition(URL doc) throws Exception { + private BPELProcessDefinition readProcessDefinition(URL doc, Monitor monitor) throws Exception { BPELProcessDefinition processDefinition = factory.createBPELProcessDefinition(); processDefinition.setUnresolved(true); processDefinition.setLocation(doc.toString()); @@ -145,12 +144,12 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements QName processName = new QName(getString(reader, BPELProcessorConstants.TARGET_NAMESPACE), getString(reader, BPELProcessorConstants.NAME_ELEMENT)); processDefinition.setName(processName); } else if (BPELProcessorConstants.PARTNERLINK_ELEMENT.equals(qname) || BPELProcessorConstants.PARTNERLINK_ELEMENT_20.equals(qname)) { - processDefinition.getPartnerLinks().add(processPartnerLinkElement(reader)); + processDefinition.getPartnerLinks().add(processPartnerLinkElement(reader, monitor)); } else if (BPELProcessorConstants.ONEVENT_ELEMENT.equals(qname) || BPELProcessorConstants.RECEIVE_ELEMENT.equals(qname) || BPELProcessorConstants.ONMESSAGE_ELEMENT.equals(qname) || BPELProcessorConstants.ONEVENT_ELEMENT_20.equals(qname) || BPELProcessorConstants.RECEIVE_ELEMENT_20.equals(qname) || BPELProcessorConstants.ONMESSAGE_ELEMENT_20.equals(qname)) { - processPartnerLinkAsService(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks()); + processPartnerLinkAsService(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks(), monitor); } else if (BPELProcessorConstants.INVOKE_ELEMENT.equals(qname) || BPELProcessorConstants.INVOKE_ELEMENT_20.equals(qname)) { - processPartnerLinkAsReference(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks()); + processPartnerLinkAsReference(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks(), monitor); } else if (BPELProcessorConstants.IMPORT_ELEMENT.equals(qname) || BPELProcessorConstants.IMPORT_ELEMENT_20.equals(qname)) { processDefinition.getImports().add(processImportElement(reader)); } else if (BPELProcessorConstants.VARIABLE_ELEMENT.equals(qname) || BPELProcessorConstants.VARIABLE_ELEMENT_20.equals(qname)) { @@ -217,7 +216,7 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * * @param reader */ - private BPELPartnerLinkElement processPartnerLinkElement(XMLStreamReader reader) throws ContributionReadException { + private BPELPartnerLinkElement processPartnerLinkElement(XMLStreamReader reader, Monitor monitor) throws ContributionReadException { BPELPartnerLinkElement partnerLink = new BPELPartnerLinkElement( reader.getAttributeValue(null, "name"), getQNameValue(reader, reader.getAttributeValue(null, "partnerLinkType")), reader.getAttributeValue(null, "myRole"), @@ -228,7 +227,7 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements String scaReference = reader.getAttributeValue(BPELProcessorConstants.SCA_BPEL_NS, "reference"); if ((scaService != null) && (scaReference != null)) { // It is incorrect to set both service & reference attributes - error("PartnerLinkHasBothAttr", partnerLink, reader.getAttributeValue(null, "name")); + error(monitor, "PartnerLinkHasBothAttr", partnerLink, reader.getAttributeValue(null, "name")); throw new ContributionReadException("BPEL PartnerLink " + reader.getAttributeValue(null, "name") + " has both sca:reference and sca:service attributes set"); } @@ -261,10 +260,10 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * @param partnerLinkName * @param partnerLinks */ - private void processPartnerLinkAsService(String partnerLinkName, List<BPELPartnerLinkElement> partnerLinks) { + private void processPartnerLinkAsService(String partnerLinkName, List<BPELPartnerLinkElement> partnerLinks, Monitor monitor) { BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName); if (partnerLink == null) { - warning("ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); + warning(monitor, "ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); } else { // Set the type of the partnerLink to "service" if not already // set... @@ -280,10 +279,10 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * @param partnerLinkName * @param partnerLinks */ - private void processPartnerLinkAsReference(String partnerLinkName, List<BPELPartnerLinkElement> partnerLinks) { + private void processPartnerLinkAsReference(String partnerLinkName, List<BPELPartnerLinkElement> partnerLinks, Monitor monitor) { BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName); if (partnerLink == null) { - warning("ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); + warning(monitor, "ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); } else { // Set the type of the partnerLink to "service" if not already // set... @@ -318,7 +317,7 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * @param message * @param model */ - private void warning(String message, Object model, Object... messageParameters) { + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "impl-bpel-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -332,7 +331,7 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * @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(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -346,7 +345,7 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements * @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(), "impl-bpel-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java index 0a3c713ae6..6a2d6310c0 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java @@ -23,9 +23,7 @@ import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; import java.net.URI; import java.net.URISyntaxException; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; import javax.wsdl.PortType; import javax.xml.namespace.QName; @@ -43,6 +41,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; @@ -76,13 +75,12 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple private AssemblyFactory assemblyFactory; private BPELFactory bpelFactory; private WSDLFactory wsdlFactory; - private Monitor monitor; - public BPELImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + + public BPELImplementationProcessor(FactoryExtensionPoint modelFactories) { this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); this.bpelFactory = modelFactories.getFactory(BPELFactory.class); - this.monitor = monitor; } public QName getArtifactType() { @@ -95,14 +93,14 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple return BPELImplementation.class; } - public BPELImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public BPELImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { assert IMPLEMENTATION_BPEL_QNAME.equals(reader.getName()); // Read an <implementation.bpel> element BPELImplementation implementation = null; // Read the process attribute. - QName process = getAttributeValueNS(reader, PROCESS); + QName process = getAttributeValueNS(reader, PROCESS, context.getMonitor()); if (process == null) { return implementation; } @@ -122,21 +120,21 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple return implementation; } - public void resolve(BPELImplementation implementation, ModelResolver resolver) throws ContributionResolveException { + public void resolve(BPELImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if( implementation != null && implementation.isUnresolved()) { implementation.setModelResolver(resolver); - BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(implementation, resolver); + BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(implementation, resolver, context); //resolveBPELImports(processDefinition, resolver); if(processDefinition.isUnresolved()) { - error("BPELProcessNotFound", implementation, processDefinition.getName()); + error(context.getMonitor(), "BPELProcessNotFound", implementation, processDefinition.getName()); } else { implementation.setProcessDefinition(processDefinition); // Get the component type from the process definition - generateComponentType( implementation ); + generateComponentType( implementation, context.getMonitor() ); //set current implementation resolved implementation.setUnresolved(false); @@ -146,7 +144,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple } // end resolve public void write( BPELImplementation bpelImplementation, - XMLStreamWriter writer ) throws ContributionWriteException, XMLStreamException { + XMLStreamWriter writer, ProcessorContext context ) throws ContributionWriteException, XMLStreamException { //FIXME Deal with policy processing... // Write <implementation.bpel process="..."/> // policyProcessor.writePolicyPrefixes(bpelImplementation, writer); @@ -161,16 +159,16 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple } // end write - private BPELProcessDefinition resolveBPELProcessDefinition(BPELImplementation impl, ModelResolver resolver) throws ContributionResolveException { + private BPELProcessDefinition resolveBPELProcessDefinition(BPELImplementation impl, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { QName processName = impl.getProcess(); BPELProcessDefinition processDefinition = this.bpelFactory.createBPELProcessDefinition(); processDefinition.setName(processName); processDefinition.setUnresolved(true); - return resolver.resolveModel(BPELProcessDefinition.class, processDefinition); + return resolver.resolveModel(BPELProcessDefinition.class, processDefinition, context); } // end resolveBPELProcessDefinition - private void resolveBPELImports(BPELProcessDefinition processDefinition, ModelResolver resolver) throws ContributionResolveException { + private void resolveBPELImports(BPELProcessDefinition processDefinition, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { for (BPELImportElement bpelImport : processDefinition.getImports()) { String namespace = bpelImport.getNamespace(); String location = bpelImport.getLocation(); @@ -182,7 +180,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple wsdl.setUnresolved(true); wsdl.setNamespace(bpelImport.getNamespace()); wsdl.setLocation(new URI(null, bpelImport.getLocation(), null)); - wsdl = resolver.resolveModel(WSDLDefinition.class, wsdl); + wsdl = resolver.resolveModel(WSDLDefinition.class, wsdl, context); if(! wsdl.isUnresolved()) { bpelImport.setWSDLDefinition(wsdl); @@ -207,7 +205,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple * @param impl * @throws ContributionResolveException */ - private void generateComponentType(BPELImplementation impl) throws ContributionResolveException { + private void generateComponentType(BPELImplementation impl, Monitor monitor) throws ContributionResolveException { // Create a ComponentType and mark it unresolved ComponentType componentType = assemblyFactory.createComponentType(); @@ -226,9 +224,9 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple if (pLink.isSCATyped()) { String scaName = pLink.getSCAName(); if (pLink.querySCAType().equals("reference")) { - componentType.getReferences().add(generateReference(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces())); + componentType.getReferences().add(generateReference(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces(), monitor)); } else { - componentType.getServices().add(generateService(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces())); + componentType.getServices().add(generateService(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces(), monitor)); } // end if } // end if } // end for @@ -249,7 +247,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple * @return */ private Reference generateReference( String name, PortType myRolePT, - PortType partnerRolePT, Collection<WSDLInterface> theInterfaces) throws ContributionResolveException { + PortType partnerRolePT, Collection<WSDLInterface> theInterfaces, Monitor monitor) throws ContributionResolveException { Reference reference = assemblyFactory.createReference(); WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); @@ -272,7 +270,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple // No interfaces mean an error if (callPT == null && callbackPT == null) { - error("MyRolePartnerRoleNull", theInterfaces); + error(monitor, "MyRolePartnerRoleNull", theInterfaces); } // end if // Set the name of the reference to the supplied name and the @@ -289,7 +287,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple callInterface = anInterface; } // end for if (callInterface == null) { - error("NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); + error(monitor, "NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); } else reference.getInterfaceContract().setInterface(callInterface); } // end if @@ -303,7 +301,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple callbackInterface = anInterface; } // end for if (callbackInterface == null) { - error("NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); + error(monitor, "NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); } else reference.getInterfaceContract().setCallbackInterface(callbackInterface); } // end if @@ -320,7 +318,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple * @return */ private Service generateService( String name, PortType myRolePT, - PortType partnerRolePT, Collection<WSDLInterface> theInterfaces ) + PortType partnerRolePT, Collection<WSDLInterface> theInterfaces, Monitor monitor ) throws ContributionResolveException { Service service = assemblyFactory.createService(); WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); @@ -347,7 +345,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple // No interfaces mean an error if (callPT == null && callbackPT == null) { - error("MyRolePartnerRoleNull", theInterfaces); + error(monitor, "MyRolePartnerRoleNull", theInterfaces); } // end if if (callPT != null) { @@ -358,7 +356,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple callInterface = anInterface; } // end for if (callInterface == null) { - error("NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); + error(monitor, "NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); } else service.getInterfaceContract().setInterface(callInterface); } // end if @@ -372,7 +370,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple callbackInterface = anInterface; } // end for if (callbackInterface == null) { - error("NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); + error(monitor, "NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); } else service.getInterfaceContract().setCallbackInterface(callbackInterface); } // end if @@ -398,10 +396,10 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple * * ie: {http://example.com/somenamespace}SomeName */ - private QName getAttributeValueNS(XMLStreamReader reader, String attribute) { + private QName getAttributeValueNS(XMLStreamReader reader, String attribute, Monitor monitor) { String fullValue = reader.getAttributeValue(null, attribute); if (fullValue == null) { - error("AttributeProcessMissing", reader); + error(monitor, "AttributeProcessMissing", reader); return null; } @@ -417,21 +415,21 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple // This exception happens if the attribute begins with '{' but // doesn't conform // to the XML Namespaces recommendation format - error("AttributeWithoutNamespace", reader, attribute, fullValue); + error(monitor, "AttributeWithoutNamespace", reader, attribute, fullValue); return null; } } // endif // Deal with the attribute in the local name + prefix format if (fullValue.indexOf(":") < 0) { - error("AttributeWithoutPrefix", reader, attribute, fullValue); + error(monitor, "AttributeWithoutPrefix", reader, attribute, fullValue); return null; } String prefix = fullValue.substring(0, fullValue.indexOf(":")); String name = fullValue.substring(fullValue.indexOf(":") + 1); String nsUri = reader.getNamespaceContext().getNamespaceURI(prefix); if (nsUri == null) { - error("AttributeUnrecognizedNamespace", reader, attribute, fullValue); + error(monitor, "AttributeUnrecognizedNamespace", reader, attribute, fullValue); return null; } return new QName(nsUri, name, prefix); @@ -444,7 +442,7 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple * @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(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); diff --git a/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java b/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java index e355b7adf9..1ef972342a 100644 --- a/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java +++ b/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java @@ -27,6 +27,7 @@ import javax.xml.namespace.QName; import junit.framework.TestCase; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +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.DefaultExtensionPointRegistry; @@ -39,18 +40,20 @@ public class BPELDocumentProcessorTestCase extends TestCase { protected static final String BPEL_PROCESS_FILE = "helloworld/helloworld.bpel"; private URLArtifactProcessor<Object> documentProcessor; + private ProcessorContext context; @Override protected 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); } public void testLoadBPELProcessDefinition() throws Exception { URI processURI = getClass().getClassLoader().getResource(BPEL_PROCESS_FILE).toURI(); URL processLocation = getClass().getClassLoader().getResource(BPEL_PROCESS_FILE); - BPELProcessDefinition bpelProcessDefinition = (BPELProcessDefinition)documentProcessor.read(null, processURI, processLocation); + BPELProcessDefinition bpelProcessDefinition = (BPELProcessDefinition)documentProcessor.read(null, processURI, processLocation, context); assertNotNull(bpelProcessDefinition); assertEquals(new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld", "HelloWorld"), bpelProcessDefinition.getName()); diff --git a/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java b/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java index 00a70fcb54..c56ab48854 100644 --- a/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java +++ b/java/sca/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java @@ -30,13 +30,11 @@ import junit.framework.TestCase; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; 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.monitor.Problem; /** @@ -62,21 +60,18 @@ public class BPELImplementationProcessorTestCase extends TestCase { private XMLInputFactory inputFactory; private StAXArtifactProcessor<Object> staxProcessor; - private Monitor monitor; + private ProcessorContext context; @Override protected void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); 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 = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } /** @@ -86,7 +81,7 @@ public class BPELImplementationProcessorTestCase extends TestCase { public void testLoadValidComposite() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); BPELImplementation implementation = (BPELImplementation)composite.getComponents().get(0).getImplementation(); assertNotNull(implementation); @@ -99,8 +94,8 @@ public class BPELImplementationProcessorTestCase extends TestCase { */ public void testLoadInvalidComposite() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID)); - staxProcessor.read(reader); - Problem problem = monitor.getLastProblem(); + staxProcessor.read(reader, context); + Problem problem = context.getMonitor().getLastProblem(); assertNotNull(problem); assertEquals("AttributeProcessMissing", problem.getMessageId()); } diff --git a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java index 173a37cd77..1653e935dc 100644 --- a/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java +++ b/java/sca/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java @@ -45,6 +45,7 @@ import org.apache.tuscany.sca.assembly.xml.PolicySubjectProcessor; 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.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -72,14 +73,13 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm private AssemblyFactory assemblyFactory; private PolicyFactory policyFactory; private PolicySubjectProcessor policyProcessor; - private Monitor monitor; + - public JavaImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public JavaImplementationProcessor(FactoryExtensionPoint modelFactories) { this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.javaFactory = modelFactories.getFactory(JavaImplementationFactory.class); this.policyProcessor = new PolicySubjectProcessor(policyFactory); - this.monitor = monitor; } /** @@ -89,7 +89,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm * @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(), @@ -109,7 +109,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm * @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(), @@ -122,7 +122,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm } } - public JavaImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JavaImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Read an <implementation.java> JavaImplementation javaImplementation = javaFactory.createJavaImplementation(); @@ -149,7 +149,7 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm return javaImplementation; } - public void write(JavaImplementation javaImplementation, XMLStreamWriter writer) throws ContributionWriteException, + public void write(JavaImplementation javaImplementation, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <implementation.java> @@ -163,15 +163,15 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm writer.writeEndElement(); } - public void resolve(JavaImplementation javaImplementation, ModelResolver resolver) + public void resolve(JavaImplementation javaImplementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - + Monitor monitor = context.getMonitor(); try { ClassReference classReference = new ClassReference(javaImplementation.getName()); - classReference = resolver.resolveModel(ClassReference.class, classReference); + classReference = resolver.resolveModel(ClassReference.class, classReference, context); Class<?> javaClass = classReference.getJavaClass(); if (javaClass == null) { - error("ClassNotFoundException", resolver, javaImplementation.getName()); + error(monitor, "ClassNotFoundException", resolver, javaImplementation.getName()); //throw new ContributionResolveException(new ClassNotFoundException(javaImplementation.getName())); return; } @@ -182,13 +182,13 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm javaFactory.createJavaImplementation(javaImplementation, javaImplementation.getJavaClass()); } catch (IntrospectionException e) { ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", javaFactory, ce); + error(monitor, "ContributionResolveException", javaFactory, ce); //throw ce; return; } javaImplementation.setUnresolved(false); - mergeComponentType(resolver, javaImplementation); + mergeComponentType(resolver, javaImplementation, context); // FIXME the introspector should always create at least one service if (javaImplementation.getServices().isEmpty()) { @@ -227,9 +227,9 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm * @param resolver * @param impl */ - private void mergeComponentType(ModelResolver resolver, JavaImplementation impl) { + private void mergeComponentType(ModelResolver resolver, JavaImplementation impl, ProcessorContext context) { // FIXME: Need to clarify how to merge - ComponentType componentType = getComponentType(resolver, impl); + ComponentType componentType = getComponentType(resolver, impl, context); if (componentType != null && !componentType.isUnresolved()) { Map<String, Reference> refMap = new HashMap<String, Reference>(); for (Reference ref : impl.getReferences()) { @@ -284,13 +284,13 @@ public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaIm } } - private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl) { + private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl, ProcessorContext context) { String className = impl.getJavaClass().getName(); String componentTypeURI = className.replace('.', '/') + ".componentType"; ComponentType componentType = assemblyFactory.createComponentType(); componentType.setUnresolved(true); componentType.setURI(componentTypeURI); - componentType = resolver.resolveModel(ComponentType.class, componentType); + componentType = resolver.resolveModel(ComponentType.class, componentType, context); if (!componentType.isUnresolved()) { return componentType; } diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java index 260b3d09a9..635b491b06 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java @@ -32,9 +32,11 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; 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; @@ -64,13 +66,17 @@ public class ReadTestCase { private static URLArtifactProcessor<Definitions> policyDefinitionsProcessor; private static CompositeBuilder compositeBuilder; private static Monitor monitor; + private static ProcessorContext context; + private static BuilderContext builderContext; @BeforeClass public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + builderContext = new BuilderContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); compositeBuilder = extensionPoints.getExtensionPoint(BuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); @@ -86,10 +92,10 @@ public class ReadTestCase { public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); - compositeBuilder.build(composite, null, monitor); + compositeBuilder.build(composite, builderContext); } @@ -100,17 +106,18 @@ public class ReadTestCase { URL url = getClass().getResource("definitions.xml"); URI uri = URI.create("definitions.xml"); - Definitions scaDefns = policyDefinitionsProcessor.read(null, uri, url); + Definitions scaDefns = policyDefinitionsProcessor.read(null, uri, url, context); InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); - staxProcessor.resolve(scaDefns, resolver); - staxProcessor.resolve(composite, resolver); + staxProcessor.resolve(scaDefns, resolver, context); + staxProcessor.resolve(composite, resolver, context); - compositeBuilder.build(composite, null, monitor); + builderContext.setDefinitions(scaDefns); + compositeBuilder.build(composite, builderContext); //intents are computed and aggregate intents from ancestor elements assertEquals(((PolicySubject)composite.getComponents().get(0)).getRequiredIntents().size(), 3); @@ -168,11 +175,11 @@ public class ReadTestCase { URL url = getClass().getResource("definitions_with_policysets.xml"); URI uri = URI.create("definitions_with_policysets.xml"); - Definitions policyDefinitions = policyDefinitionsProcessor.read(null, uri, url); + Definitions policyDefinitions = policyDefinitionsProcessor.read(null, uri, url, context); InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); for ( Component component : composite.getComponents() ) { @@ -181,10 +188,11 @@ public class ReadTestCase { } } - staxProcessor.resolve(policyDefinitions, resolver); - staxProcessor.resolve(composite, resolver); + staxProcessor.resolve(policyDefinitions, resolver, context); + staxProcessor.resolve(composite, resolver, context); - compositeBuilder.build(composite, null, monitor); + builderContext.setDefinitions(policyDefinitions); + compositeBuilder.build(composite, builderContext); //test for determination of policysets for implementation assertEquals(((PolicySubject)composite.getComponents().get(0)).getPolicySets().size(), 1); diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java index 085b21a652..6be50d138f 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java @@ -23,6 +23,7 @@ import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -43,7 +44,7 @@ public class TestModelResolver implements ModelResolver { this.classLoader = new WeakReference<ClassLoader>(classLoader); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { Object resolved = map.get(unresolved); if (resolved != null) { @@ -77,11 +78,11 @@ public class TestModelResolver implements ModelResolver { } } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { map.put(resolved, resolved); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(resolved); } diff --git a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java index c45f8ccaa7..fdd606c58e 100644 --- a/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java +++ b/java/sca/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java @@ -27,6 +27,7 @@ import javax.xml.stream.XMLOutputFactory; 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.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; @@ -44,24 +45,26 @@ public class WriteTestCase { private static StAXArtifactProcessor<Object> staxProcessor; private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; + 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(); outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); 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("Calculator.composite"); - Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); Assert.assertNotNull(composite); StringWriter sw = new StringWriter(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(sw)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(sw), context); System.out.println(sw.toString()); } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java index 7efb3f196a..ac05218fdf 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BindingDescriptionsProcessor.java @@ -29,13 +29,13 @@ import org.apache.tuscany.sca.assembly.Binding; 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; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.osgi.BindingDescriptions; import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory; -import org.apache.tuscany.sca.monitor.Monitor; /* <?xml version="1.0" encoding="UTF-8"?> @@ -45,20 +45,17 @@ import org.apache.tuscany.sca.monitor.Monitor; </bindings> */ public class BindingDescriptionsProcessor implements StAXArtifactProcessor<BindingDescriptions> { - private Monitor monitor; private StAXArtifactProcessor processor; private ServiceDescriptionsFactory factory; public BindingDescriptionsProcessor(ExtensionPointRegistry registry, - StAXArtifactProcessor processor, - Monitor monitor) { - this.monitor = monitor; + StAXArtifactProcessor processor) { this.processor = processor; this.factory = registry.getExtensionPoint(FactoryExtensionPoint.class).getFactory(ServiceDescriptionsFactory.class); } - public BindingDescriptions read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public BindingDescriptions read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { BindingDescriptions bindings = factory.createBindingDescriptions(); boolean exit = false; while (!exit) { @@ -69,7 +66,7 @@ public class BindingDescriptionsProcessor implements StAXArtifactProcessor<Bindi if (!"bindings".equals(name.getLocalPart())) { Object element = null; try { - element = processor.read(reader); + element = processor.read(reader, context); } catch (ContributionReadException e) { throw e; } @@ -98,11 +95,11 @@ public class BindingDescriptionsProcessor implements StAXArtifactProcessor<Bindi return BindingDescriptions.BINDINGS_QNAME; } - public void write(BindingDescriptions model, XMLStreamWriter writer) throws ContributionWriteException, + public void write(BindingDescriptions model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeStartElement(BindingDescriptions.OSGI_SD_NS, "bindings"); for (Binding binding : model) { - processor.write(model, writer); + processor.write(model, writer, context); } writer.writeEndElement(); } @@ -111,7 +108,7 @@ public class BindingDescriptionsProcessor implements StAXArtifactProcessor<Bindi return BindingDescriptions.class; } - public void resolve(BindingDescriptions model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(BindingDescriptions model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // TODO: To be implemented } } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java index 8dfded0c4e..ca6b0b70e1 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessor.java @@ -31,13 +31,13 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; 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.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.monitor.Monitor; /* <!-- A sample module-context.xml for OSGI RFC 124 (BluePrint Service) --> @@ -72,15 +72,13 @@ public class BluePrintComponentsProcessor implements StAXArtifactProcessor<Compo private AssemblyFactory factory; private JavaInterfaceFactory javaInterfaceFactory; - private Monitor monitor; - public BluePrintComponentsProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public BluePrintComponentsProcessor(FactoryExtensionPoint modelFactories) { this.factory = modelFactories.getFactory(AssemblyFactory.class); this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class); } - public ComponentType read(XMLStreamReader reader) throws XMLStreamException { + public ComponentType read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException { int event = reader.getEventType(); ComponentType componentType = factory.createComponentType(); while (true) { @@ -131,7 +129,7 @@ public class BluePrintComponentsProcessor implements StAXArtifactProcessor<Compo return COMPONENTS_QNAME; } - public void write(ComponentType model, XMLStreamWriter writer) throws ContributionWriteException, + public void write(ComponentType model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // TODO: To be implemented } @@ -140,7 +138,7 @@ public class BluePrintComponentsProcessor implements StAXArtifactProcessor<Compo return ComponentType.class; } - public void resolve(ComponentType model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ComponentType model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // TODO: To be implemented } } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java index e62c424a1a..860d3f6f45 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessor.java @@ -32,13 +32,13 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; 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.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.monitor.Monitor; /* <scr:component name="CalculatorComponent" @@ -66,15 +66,14 @@ public class OSGiComponentProcessor implements StAXArtifactProcessor<ComponentTy private AssemblyFactory factory; private JavaInterfaceFactory javaInterfaceFactory; - private Monitor monitor; + - public OSGiComponentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public OSGiComponentProcessor(FactoryExtensionPoint modelFactories) { this.factory = modelFactories.getFactory(AssemblyFactory.class); this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class); } - public ComponentType read(XMLStreamReader reader) throws XMLStreamException { + public ComponentType read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException { int event = reader.getEventType(); ComponentType componentType = factory.createComponentType(); while (true) { @@ -160,7 +159,7 @@ public class OSGiComponentProcessor implements StAXArtifactProcessor<ComponentTy return COMPONENT_QNAME; } - public void write(ComponentType model, XMLStreamWriter writer) throws ContributionWriteException, + public void write(ComponentType model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // TODO: To be implemented } @@ -169,7 +168,7 @@ public class OSGiComponentProcessor implements StAXArtifactProcessor<ComponentTy return ComponentType.class; } - public void resolve(ComponentType model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ComponentType model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // TODO: To be implemented } } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java index c3b293ab5d..3f9d22c3d6 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java @@ -41,6 +41,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.URLArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; @@ -83,20 +84,19 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm private ServiceDescriptionsFactory serviceDescriptionsFactory; private OSGiImplementationFactory osgiImplementationFactory; private JavaInterfaceFactory javaInterfaceFactory; - private Monitor monitor; + private ExtensionPointRegistry registry; private StAXArtifactProcessor artifactProcessor; - protected OSGiImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + protected OSGiImplementationProcessor(FactoryExtensionPoint modelFactories) { this.serviceDescriptionsFactory = modelFactories.getFactory(ServiceDescriptionsFactory.class); this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.osgiImplementationFactory = modelFactories.getFactory(OSGiImplementationFactory.class); this.javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class); } - public OSGiImplementationProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor, Monitor monitor) { - this(registry.getExtensionPoint(FactoryExtensionPoint.class), monitor); + public OSGiImplementationProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor) { + this(registry.getExtensionPoint(FactoryExtensionPoint.class)); this.artifactProcessor = processor; this.registry = registry; } @@ -108,7 +108,7 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm * @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,7 +129,7 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm return OSGiImplementation.class; } - public OSGiImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public OSGiImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { assert IMPLEMENTATION_OSGI.equals(reader.getName()); String bundleSymbolicName = reader.getAttributeValue(null, BUNDLE_SYMBOLICNAME); @@ -157,11 +157,11 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm return implementation; } - public void resolve(OSGiImplementation impl, ModelResolver resolver) throws ContributionResolveException { + public void resolve(OSGiImplementation impl, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (impl == null || !impl.isUnresolved()) return; - + Monitor monitor = context.getMonitor(); impl.setUnresolved(false); BundleContext bundleContext = OSGiImplementationActivator.getBundleContext(); @@ -186,14 +186,14 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm if (bundle != null) { impl.setBundle(bundle); } else { - error("CouldNotLocateOSGiBundle", impl, impl.getBundleSymbolicName()); + error(monitor, "CouldNotLocateOSGiBundle", impl, impl.getBundleSymbolicName()); //throw new ContributionResolveException("Could not locate OSGi bundle " + //impl.getBundleSymbolicName()); return; } try { - if (introspect(impl, resolver, bundle)) { + if (introspect(impl, resolver, context, bundle)) { return; } } catch (ContributionReadException e) { @@ -205,39 +205,39 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm // Try to find a bundle.componentType for the target bundle componentType.setURI("OSGI-INF/sca/" + bundle.getSymbolicName() + "/bundle.componentType"); componentType.setUnresolved(true); - componentType = resolver.resolveModel(ComponentType.class, componentType); + componentType = resolver.resolveModel(ComponentType.class, componentType, context); if (componentType.isUnresolved()) { // Create a new instance to prevent it being treated as reentry // See org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver.resolveModel(Class<T>, T) componentType = assemblyFactory.createComponentType(); // Try a generic one componentType.setURI(BUNDLE_COMPONENT_TYPE); - componentType = resolver.resolveModel(ComponentType.class, componentType); + componentType = resolver.resolveModel(ComponentType.class, componentType, context); } if (componentType.isUnresolved()) { // Try to derive it from the service descriptions - if (!deriveFromServiceDescriptions(impl, resolver)) { - error("MissingComponentTypeFile", impl, componentType.getURI()); + if (!deriveFromServiceDescriptions(impl, resolver, context)) { + error(monitor, "MissingComponentTypeFile", impl, componentType.getURI()); } //throw new ContributionResolveException("missing .componentType side file " + ctURI); return; } else { - mergeFromComponentType(impl, componentType, resolver); + mergeFromComponentType(impl, componentType, resolver, context); } } - private boolean deriveFromServiceDescriptions(OSGiImplementation impl, ModelResolver resolver) + private boolean deriveFromServiceDescriptions(OSGiImplementation impl, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // FIXME: How to find the RFC 119 service descriptions in the contribution and // derive the SCA component type from them? ServiceDescriptions descriptions = serviceDescriptionsFactory.createServiceDescriptions(); - descriptions = resolver.resolveModel(ServiceDescriptions.class, descriptions); + descriptions = resolver.resolveModel(ServiceDescriptions.class, descriptions, context); if (descriptions != null && !descriptions.isEmpty()) { ComponentType ct = assemblyFactory.createComponentType(); int index = 0; for (ServiceDescription ds : descriptions) { for (String i : ds.getInterfaces()) { - Class<?> cls = getJavaClass(resolver, i); + Class<?> cls = getJavaClass(resolver, i, context); JavaInterface javaInterface; try { javaInterface = javaInterfaceFactory.createJavaInterface(cls); @@ -257,26 +257,26 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm ct.getReferences().add(reference); } } - mergeFromComponentType(impl, ct, resolver); + mergeFromComponentType(impl, ct, resolver, context); return true; } return false; } - private void mergeFromComponentType(OSGiImplementation impl, ComponentType componentType, ModelResolver resolver) { + private void mergeFromComponentType(OSGiImplementation impl, ComponentType componentType, ModelResolver resolver, ProcessorContext context) { List<Service> services = componentType.getServices(); for (Service service : services) { Interface interfaze = service.getInterfaceContract().getInterface(); if (interfaze instanceof JavaInterface) { JavaInterface javaInterface = (JavaInterface)interfaze; if (javaInterface.getJavaClass() == null) { - javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName())); + javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName(), context)); } if (service.getInterfaceContract().getCallbackInterface() instanceof JavaInterface) { JavaInterface callbackInterface = (JavaInterface)service.getInterfaceContract().getCallbackInterface(); if (callbackInterface.getJavaClass() == null) { - callbackInterface.setJavaClass(getJavaClass(resolver, callbackInterface.getName())); + callbackInterface.setJavaClass(getJavaClass(resolver, callbackInterface.getName(), context)); } } @@ -290,7 +290,7 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm if (interfaze instanceof JavaInterface) { JavaInterface javaInterface = (JavaInterface)interfaze; if (javaInterface.getJavaClass() == null) { - javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName())); + javaInterface.setJavaClass(getJavaClass(resolver, javaInterface.getName(), context)); } impl.getReferences().add(reference); } else @@ -304,13 +304,13 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm impl.setConstrainingType(componentType.getConstrainingType()); } - private Class<?> getJavaClass(ModelResolver resolver, String className) { + private Class<?> getJavaClass(ModelResolver resolver, String className, ProcessorContext context) { ClassReference ref = new ClassReference(className); - ref = resolver.resolveModel(ClassReference.class, ref); + ref = resolver.resolveModel(ClassReference.class, ref, context); return ref.getJavaClass(); } - public void write(OSGiImplementation model, XMLStreamWriter writer) throws ContributionWriteException, + public void write(OSGiImplementation model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String ns = IMPLEMENTATION_OSGI.getNamespaceURI(); writer.writeStartElement(ns, IMPLEMENTATION_OSGI.getLocalPart()); @@ -321,7 +321,7 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm writer.writeEndElement(); } - private boolean introspect(OSGiImplementation implementation, ModelResolver resolver, Bundle bundle) + private boolean introspect(OSGiImplementation implementation, ModelResolver resolver, ProcessorContext context, Bundle bundle) throws ContributionReadException, ContributionResolveException { String componentTypeFile = (String)bundle.getHeaders().get(COMPONENT_TYPE_HEADER); if (componentTypeFile == null) { @@ -332,9 +332,9 @@ public class OSGiImplementationProcessor implements StAXArtifactProcessor<OSGiIm URLArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); URLArtifactProcessor<ComponentType> processor = processors.getProcessor(ComponentType.class); - ComponentType componentType = processor.read(null, URI.create(BUNDLE_COMPONENT_TYPE), url); - artifactProcessor.resolve(componentType, resolver); - mergeFromComponentType(implementation, componentType, resolver); + ComponentType componentType = processor.read(null, URI.create(BUNDLE_COMPONENT_TYPE), url, context); + artifactProcessor.resolve(componentType, resolver, context); + mergeFromComponentType(implementation, componentType, resolver, context); return true; } return false; diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java index 5a8f5c4694..9bd469df06 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiPropertyProcessor.java @@ -31,26 +31,25 @@ import javax.xml.stream.XMLStreamWriter; 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.implementation.osgi.OSGiImplementationFactory; import org.apache.tuscany.sca.implementation.osgi.OSGiProperty; -import org.apache.tuscany.sca.monitor.Monitor; /** * A processor for <tuscany:osgi.property> */ public class OSGiPropertyProcessor implements StAXArtifactProcessor<OSGiProperty> { private OSGiImplementationFactory factory; - private Monitor monitor; + - public OSGiPropertyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public OSGiPropertyProcessor(FactoryExtensionPoint modelFactories) { this.factory = modelFactories.getFactory(OSGiImplementationFactory.class); } - public OSGiProperty read(XMLStreamReader reader) throws XMLStreamException { + public OSGiProperty read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException { int event = reader.getEventType(); OSGiProperty prop = null; while (true) { @@ -88,7 +87,7 @@ public class OSGiPropertyProcessor implements StAXArtifactProcessor<OSGiProperty return PROPERTY_QNAME; } - public void write(OSGiProperty model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(OSGiProperty model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeStartElement(PROPERTY_QNAME.getNamespaceURI(), PROPERTY_QNAME.getLocalPart()); writer.writeAttribute(NAME, model.getName()); writer.writeCharacters(model.getValue()); @@ -99,7 +98,7 @@ public class OSGiPropertyProcessor implements StAXArtifactProcessor<OSGiProperty return OSGiProperty.class; } - public void resolve(OSGiProperty model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(OSGiProperty model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // TODO: To be implemented } } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java index b692531a38..5e83833a05 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsDocumentProcessor.java @@ -31,13 +31,13 @@ import javax.xml.stream.XMLStreamReader; 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.implementation.osgi.ServiceDescriptions; -import org.apache.tuscany.sca.monitor.Monitor; /** * The service descriptions document processor @@ -47,8 +47,7 @@ public class ServiceDescriptionsDocumentProcessor implements URLArtifactProcesso private StAXArtifactProcessor extensionProcessor; public ServiceDescriptionsDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor, - Monitor monitor) { + StAXArtifactProcessor staxProcessor) { super(); this.extensionProcessor = staxProcessor; this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); @@ -58,7 +57,7 @@ public class ServiceDescriptionsDocumentProcessor implements URLArtifactProcesso return "/OSGI-INF/remote-service/*.xml"; } - public ServiceDescriptions read(URL contributionURL, URI artifactURI, URL artifactURL) + public ServiceDescriptions read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException { InputStream is = null; try { @@ -71,7 +70,7 @@ public class ServiceDescriptionsDocumentProcessor implements URLArtifactProcesso } try { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Object result = extensionProcessor.read(reader); + Object result = extensionProcessor.read(reader, context); return (ServiceDescriptions)result; } catch (XMLStreamException e) { ContributionReadException ce = new ContributionReadException(e); @@ -93,7 +92,7 @@ public class ServiceDescriptionsDocumentProcessor implements URLArtifactProcesso return ServiceDescriptions.class; } - public void resolve(ServiceDescriptions model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ServiceDescriptions model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java index 15b31e97f9..cd62d5cfaf 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsModelResolver.java @@ -20,11 +20,11 @@ package org.apache.tuscany.sca.implementation.osgi.xml; import org.apache.tuscany.sca.contribution.Contribution; +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.implementation.osgi.ServiceDescriptions; import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory; -import org.apache.tuscany.sca.monitor.Monitor; /** * @@ -32,19 +32,19 @@ import org.apache.tuscany.sca.monitor.Monitor; public class ServiceDescriptionsModelResolver implements ModelResolver { private ServiceDescriptions serviceDescriptions; - public ServiceDescriptionsModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public ServiceDescriptionsModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { ServiceDescriptionsFactory factory = modelFactories.getFactory(ServiceDescriptionsFactory.class); this.serviceDescriptions = factory.createServiceDescriptions(); } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { // Merge the service descriptions if (resolved instanceof ServiceDescriptions) { serviceDescriptions.addAll((ServiceDescriptions)resolved); } } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { // Remove the service descriptions if (resolved instanceof ServiceDescriptions) { serviceDescriptions.removeAll((ServiceDescriptions)resolved); @@ -52,7 +52,7 @@ public class ServiceDescriptionsModelResolver implements ModelResolver { return resolved; } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { // Always return the aggregated service descriptions return modelClass.cast(serviceDescriptions); } diff --git a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java index 38e2730df8..fc6e44d8d6 100644 --- a/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java +++ b/java/sca/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsProcessor.java @@ -31,6 +31,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; @@ -38,7 +39,6 @@ import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.osgi.ServiceDescription; import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptions; import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory; -import org.apache.tuscany.sca.monitor.Monitor; /* <?xml version="1.0" encoding="UTF-8"?> @@ -65,18 +65,16 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl StAXArtifactProcessor<ServiceDescriptions> { private ServiceDescriptionsFactory factory; private StAXArtifactProcessor processor; - private Monitor monitor; + public ServiceDescriptionsProcessor(ExtensionPointRegistry registry, - StAXArtifactProcessor processor, - Monitor monitor) { - this.monitor = monitor; + StAXArtifactProcessor processor) { this.processor = processor; FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.factory = modelFactories.getFactory(ServiceDescriptionsFactory.class); } - public ServiceDescriptions read(XMLStreamReader reader) throws XMLStreamException, ContributionReadException { + public ServiceDescriptions read(XMLStreamReader reader, ProcessorContext context) throws XMLStreamException, ContributionReadException { int event = reader.getEventType(); ServiceDescriptions sds = factory.createServiceDescriptions(); ServiceDescription sd = null; @@ -130,7 +128,7 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl } else { name = reader.getName(); if (!ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME.equals(name)) { - Object ext = processor.read(reader); + Object ext = processor.read(reader, context); if (sd != null) { sd.getProperties().put(name.toString(), ext); } @@ -178,7 +176,7 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl return ServiceDescriptions.SERVICE_DESCRIPTIONS_QNAME; } - public void write(ServiceDescriptions model, XMLStreamWriter writer) throws ContributionWriteException, + public void write(ServiceDescriptions model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // TODO: To be implemented } @@ -187,7 +185,7 @@ public class ServiceDescriptionsProcessor extends BaseStAXArtifactProcessor impl return ServiceDescriptions.class; } - public void resolve(ServiceDescriptions model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(ServiceDescriptions model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // TODO: To be implemented } } diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java index 1865c27141..224467181b 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/BluePrintComponentsProcessorTestCase.java @@ -25,6 +25,7 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint; import org.junit.AfterClass; @@ -69,9 +70,8 @@ public class BluePrintComponentsProcessorTestCase { @Test public void testLoad() throws Exception { BluePrintComponentsProcessor processor = - new BluePrintComponentsProcessor(new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()), - null); - ComponentType ct = processor.read(reader); + new BluePrintComponentsProcessor(new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry())); + ComponentType ct = processor.read(reader, new ProcessorContext()); Assert.assertEquals(1, ct.getServices().size()); Assert.assertEquals(4, ct.getReferences().size()); } diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java index 3b26fdb999..ef49121c2c 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiComponentProcessorTestCase.java @@ -25,8 +25,10 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.DefaultFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -66,9 +68,10 @@ public class OSGiComponentProcessorTestCase { @Test public void testLoad() throws Exception { + ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); OSGiComponentProcessor processor = - new OSGiComponentProcessor(new DefaultFactoryExtensionPoint(new DefaultExtensionPointRegistry()), null); - ComponentType ct = processor.read(reader); + new OSGiComponentProcessor(new DefaultFactoryExtensionPoint(registry)); + ComponentType ct = processor.read(reader, new ProcessorContext(registry)); Assert.assertEquals(1, ct.getServices().size()); Assert.assertEquals(4, ct.getReferences().size()); } diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java index 8c85b9136d..6b59b498fc 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java @@ -36,6 +36,7 @@ import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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.ModelResolver; @@ -56,23 +57,25 @@ public class OSGiReadImplTestCase { private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; private static StAXArtifactProcessor<Object> staxProcessor; + 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(); outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } @Test public void testReadComposite() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); } @@ -80,12 +83,12 @@ public class OSGiReadImplTestCase { public void testReadAndResolveComposite() throws Exception { InputStream is = getClass().getClassLoader().getResourceAsStream("osgitest.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); is = getClass().getClassLoader().getResourceAsStream("OSGI-INF/sca/bundle.componentType"); reader = inputFactory.createXMLStreamReader(is); - ComponentType componentType = (ComponentType)staxProcessor.read(reader); + ComponentType componentType = (ComponentType)staxProcessor.read(reader, context); assertEquals(1, componentType.getServices().size()); Object prop1 = componentType.getServices().get(0).getExtensions().get(0); @@ -102,10 +105,10 @@ public class OSGiReadImplTestCase { assertEquals("prop2", osgiProp2.getName()); ModelResolver resolver = new TestModelResolver(getClass().getClassLoader()); - staxProcessor.resolve(componentType, resolver); - resolver.addModel(componentType); + staxProcessor.resolve(componentType, resolver, context); + resolver.addModel(componentType, context); - staxProcessor.resolve(composite, resolver); + staxProcessor.resolve(composite, resolver, context); } @Test @@ -121,14 +124,14 @@ public class OSGiReadImplTestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(is); reader.nextTag(); - OSGiImplementation osgiImpl = (OSGiImplementation)staxProcessor.read(reader); + OSGiImplementation osgiImpl = (OSGiImplementation)staxProcessor.read(reader, context); assertEquals(osgiImpl.getBundleSymbolicName(), "osgi.test"); assertEquals(osgiImpl.getBundleVersion(), "1.0.0"); StringWriter sw = new StringWriter(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw); - staxProcessor.write(osgiImpl, writer); + staxProcessor.write(osgiImpl, writer, context); writer.flush(); Assert.assertTrue(sw.toString().contains("bundleSymbolicName=\"osgi.test\" bundleVersion=\"1.0.0\"")); } diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java index e0284b9219..1b28373f5b 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/ServiceDescriptionsTestCase.java @@ -26,10 +26,10 @@ 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.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.osgi.ServiceDescription; import org.junit.AfterClass; import org.junit.Assert; @@ -71,26 +71,26 @@ public class ServiceDescriptionsTestCase { private static ServiceDescriptionsProcessor processor; private static XMLStreamReader reader; - /** - * @throws java.lang.Exception - */ + private static ProcessorContext context; + @BeforeClass - public static void setUpBeforeClass() throws Exception { - ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); XMLInputFactory factory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - StAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, factory, null, null); + StAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, factory, null); - processor = new ServiceDescriptionsProcessor(extensionPoints, staxProcessor, null); + processor = new ServiceDescriptionsProcessor(extensionPoints, staxProcessor); reader = factory.createXMLStreamReader(new StringReader(xml)); } @Test public void testLoad() throws Exception { - List<ServiceDescription> descriptions = processor.read(reader); + List<ServiceDescription> descriptions = processor.read(reader, context); Assert.assertEquals(2, descriptions.size()); System.out.println(descriptions); } diff --git a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java index 7cae6abda2..17fef8a05c 100644 --- a/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java +++ b/java/sca/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java @@ -26,6 +26,7 @@ import java.util.Map; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.implementation.osgi.impl.OSGiImplementationImpl; @@ -46,7 +47,7 @@ public class TestModelResolver implements ModelResolver { this.classLoader = new WeakReference<ClassLoader>(classLoader); } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { Object resolved = map.get(unresolved); if (resolved != null) { @@ -93,11 +94,11 @@ public class TestModelResolver implements ModelResolver { } } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { map.put(resolved, resolved); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(resolved); } diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationBuilder.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationBuilder.java index 434b705bd9..1a246fa03a 100644 --- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationBuilder.java +++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationBuilder.java @@ -22,15 +22,15 @@ package org.apache.tuscany.sca.implementation.spring; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.ImplementationBuilder; -import org.apache.tuscany.sca.monitor.Monitor; /** * */ public class SpringImplementationBuilder implements ImplementationBuilder<SpringImplementation> { - public void build(Component component, SpringImplementation implmentation, Monitor monitor) { + public void build(Component component, SpringImplementation implmentation, BuilderContext context) { implmentation.build(component); } diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java index 315b9cec8c..9195b6c9cc 100644 --- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java +++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java @@ -56,6 +56,7 @@ import org.apache.tuscany.sca.contribution.Artifact; 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.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.FactoryExtensionPoint; @@ -150,7 +151,7 @@ public class SpringXMLComponentTypeLoader { * Spring implementation * */ - public void load(SpringImplementation implementation, ModelResolver resolver) throws ContributionReadException { + public void load(SpringImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionReadException { //System.out.println("Spring TypeLoader - load method start"); ComponentType componentType = implementation.getComponentType(); /* Check that there is a component type object already set */ @@ -159,16 +160,16 @@ public class SpringXMLComponentTypeLoader { } if (componentType.isUnresolved()) { /* Fetch the location of the application-context file from the implementation */ - loadFromXML(implementation, resolver); + loadFromXML(implementation, resolver, context); if (!componentType.isUnresolved()) implementation.setUnresolved(false); } // end if //System.out.println("Spring TypeLoader - load method complete"); } // end method load - private Class<?> resolveClass(ModelResolver resolver, String className) throws ClassNotFoundException { + private Class<?> resolveClass(ModelResolver resolver, String className, ProcessorContext context) throws ClassNotFoundException { ClassReference classReference = new ClassReference(className); - classReference = resolver.resolveModel(ClassReference.class, classReference); + classReference = resolver.resolveModel(ClassReference.class, classReference, context); if (classReference.isUnresolved()) { throw new ClassNotFoundException(className); } @@ -183,7 +184,7 @@ public class SpringXMLComponentTypeLoader { * @param implementation SpringImplementation into which to load the component type information * @throws ContributionReadException Failed to read the contribution */ - private void loadFromXML(SpringImplementation implementation, ModelResolver resolver) throws ContributionReadException { + private void loadFromXML(SpringImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionReadException { XMLStreamReader reader; List<SpringBeanElement> beans = new ArrayList<SpringBeanElement>(); List<SpringSCAServiceElement> services = new ArrayList<SpringSCAServiceElement>(); @@ -195,10 +196,10 @@ public class SpringXMLComponentTypeLoader { String contextPath = implementation.getLocation(); try { - resource = resolveLocation(resolver, contextPath); + resource = resolveLocation(resolver, contextPath, context); contextResources = getApplicationContextResource(resource); - implementation.setClassLoader(new ContextClassLoader(resolver)); + implementation.setClassLoader(new ContextClassLoader(resolver, context)); implementation.setResource(contextResources); // The URI is used to uniquely identify the Implementation implementation.setURI(resource.toString()); @@ -210,7 +211,7 @@ public class SpringXMLComponentTypeLoader { List<SpringSCAPropertyElement> appCxtProperties = new ArrayList<SpringSCAPropertyElement>(); reader = xmlInputFactory.createXMLStreamReader(contextResource.openStream()); // Read the beans, services, references and properties for individual application context - readContextDefinition(resolver, reader, contextPath, appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties); + readContextDefinition(resolver, reader, contextPath, appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties, context); // Validate the beans from individual application context for uniqueness validateBeans(appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties); // Add all the validated beans to the generic list @@ -229,12 +230,12 @@ public class SpringXMLComponentTypeLoader { /* At this point, the complete application-context.xml file has been read and its contents */ /* stored in the lists of beans, services, references. These are now used to generate */ /* the implied componentType for the application context */ - generateComponentType(implementation, resolver, beans, services, references, scaproperties); + generateComponentType(implementation, resolver, beans, services, references, scaproperties, context); return; } // end method loadFromXML - private URL resolveLocation(ModelResolver resolver, String contextPath) throws MalformedURLException, + private URL resolveLocation(ModelResolver resolver, String contextPath, ProcessorContext context) throws MalformedURLException, ContributionReadException { URL resource = null; URI uri = URI.create(contextPath); @@ -242,7 +243,7 @@ public class SpringXMLComponentTypeLoader { Artifact artifact = contributionFactory.createArtifact(); artifact.setUnresolved(true); artifact.setURI(contextPath); - artifact = resolver.resolveModel(Artifact.class, artifact); + artifact = resolver.resolveModel(Artifact.class, artifact, context); if (!artifact.isUnresolved()) { resource = new URL(artifact.getLocation()); } else { @@ -258,10 +259,10 @@ public class SpringXMLComponentTypeLoader { * Method which returns the XMLStreamReader for the Spring application-context.xml file * specified in the location attribute */ - private XMLStreamReader getApplicationContextReader(ModelResolver resolver, String location) throws ContributionReadException { + private XMLStreamReader getApplicationContextReader(ModelResolver resolver, String location, ProcessorContext context) throws ContributionReadException { try { - URL resource = getApplicationContextResource(resolveLocation(resolver, location)).get(0); + URL resource = getApplicationContextResource(resolveLocation(resolver, location, context)).get(0); XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(resource.openStream()); return reader; @@ -275,6 +276,7 @@ public class SpringXMLComponentTypeLoader { /** * Method which reads the spring context definitions from Spring application-context.xml * file and identifies the defined beans, properties, services and references + * @param context */ private void readContextDefinition(ModelResolver resolver, XMLStreamReader reader, @@ -282,7 +284,7 @@ public class SpringXMLComponentTypeLoader { List<SpringBeanElement> beans, List<SpringSCAServiceElement> services, List<SpringSCAReferenceElement> references, - List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException { + List<SpringSCAPropertyElement> scaproperties, ProcessorContext context) throws ContributionReadException { SpringBeanElement bean = null; @@ -299,9 +301,9 @@ public class SpringXMLComponentTypeLoader { if (location != null) { // FIXME - need to find a right way of generating this path String resourcePath = contextPath.substring(0, contextPath.lastIndexOf("/")+1) + location; - XMLStreamReader ireader = getApplicationContextReader(resolver, resourcePath); + XMLStreamReader ireader = getApplicationContextReader(resolver, resourcePath, context); // Read the context definition for the identified imported resource - readContextDefinition(resolver, ireader, contextPath, beans, services, references, scaproperties); + readContextDefinition(resolver, ireader, contextPath, beans, services, references, scaproperties, context); } } else if (SpringImplementationConstants.SCA_SERVICE_ELEMENT.equals(qname)) { // The value of the @name attribute of an <sca:service/> subelement of a <beans/> @@ -538,7 +540,8 @@ public class SpringXMLComponentTypeLoader { List<SpringBeanElement> beans, List<SpringSCAServiceElement> services, List<SpringSCAReferenceElement> references, - List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException { + List<SpringSCAPropertyElement> scaproperties, + ProcessorContext context) throws ContributionReadException { /* * 1. Each sca:service becomes a service in the component type * 2. Each sca:reference becomes a reference in the component type @@ -558,7 +561,7 @@ public class SpringXMLComponentTypeLoader { Iterator<SpringSCAServiceElement> its = services.iterator(); while (its.hasNext()) { SpringSCAServiceElement serviceElement = its.next(); - Class<?> interfaze = resolveClass(resolver, serviceElement.getType()); + Class<?> interfaze = resolveClass(resolver, serviceElement.getType(), context); Service theService = createService(interfaze, serviceElement.getName()); // Spring allows duplication of bean definitions in multiple context scenario, // in such cases, the latest bean definition overrides the older ones, hence @@ -590,7 +593,7 @@ public class SpringXMLComponentTypeLoader { Iterator<SpringSCAReferenceElement> itr = references.iterator(); while (itr.hasNext()) { SpringSCAReferenceElement referenceElement = itr.next(); - Class<?> interfaze = resolveClass(resolver, referenceElement.getType()); + Class<?> interfaze = resolveClass(resolver, referenceElement.getType(), context); Reference theReference = createReference(interfaze, referenceElement.getName()); // Override the older bean definition with the latest ones // for the duplicate definitions found. @@ -647,7 +650,7 @@ public class SpringXMLComponentTypeLoader { // If its not a valid bean for service, ignore it if (!isvalidBeanForService(beanElement)) continue; // Load the Spring bean class - Class<?> beanClass = resolveClass(resolver, beanElement.getClassName()); + Class<?> beanClass = resolveClass(resolver, beanElement.getClassName(), context); // Introspect the bean beanIntrospector = new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, beanElement.getCustructorArgs()); @@ -674,7 +677,7 @@ public class SpringXMLComponentTypeLoader { if (beanElement.getProperties().isEmpty() && beanElement.getCustructorArgs().isEmpty()) continue; - Class<?> beanClass = resolveClass(resolver, beanElement.getClassName()); + Class<?> beanClass = resolveClass(resolver, beanElement.getClassName(), context); // Introspect the bean beanIntrospector = new SpringBeanIntrospector(assemblyFactory, javaFactory, policyFactory, beanElement.getCustructorArgs()); @@ -709,7 +712,7 @@ public class SpringXMLComponentTypeLoader { // The name of the reference in this case is the string in // the @ref attribute of the Spring property element, NOT the // name of the field in the Spring bean.... - Class<?> interfaze = resolveClass(resolver, (propertyMap.get(propertyElement.getName()).getType()).getName()); + Class<?> interfaze = resolveClass(resolver, (propertyMap.get(propertyElement.getName()).getType()).getName(), context); Reference theReference = createReference(interfaze, propertyRef); implementation.setUnresolvedBeanRef(propertyRef, theReference); } // end if @@ -725,7 +728,7 @@ public class SpringXMLComponentTypeLoader { if (propertyRefUnresolved(constructorArgRef, beans, references, scaproperties)) { for (JavaParameterImpl parameter : constructor.getParameters()) { String paramType = parameter.getType().getName(); - Class<?> interfaze = resolveClass(resolver, paramType); + Class<?> interfaze = resolveClass(resolver, paramType, context); // Create a component type reference/property if the constructor-arg element has a // type attribute OR index attribute declared... if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) || @@ -1113,22 +1116,24 @@ public class SpringXMLComponentTypeLoader { } private class ContextClassLoader extends ClassLoader { - public ContextClassLoader(ModelResolver resolver) { + public ContextClassLoader(ModelResolver resolver, ProcessorContext context) { super(); this.resolver = resolver; + this.context = context; } private ModelResolver resolver; + private ProcessorContext context; @Override protected Class<?> findClass(String name) throws ClassNotFoundException { - return SpringXMLComponentTypeLoader.this.resolveClass(resolver, name); + return SpringXMLComponentTypeLoader.this.resolveClass(resolver, name, context); } @Override protected URL findResource(String name) { try { - return resolveLocation(resolver, name); + return resolveLocation(resolver, name, context); } catch (Exception e) { return null; } diff --git a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java index ce8c6522f4..5d896ca726 100644 --- a/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java +++ b/java/sca/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringImplementationProcessor.java @@ -33,6 +33,7 @@ import org.apache.tuscany.sca.assembly.xml.PolicySubjectProcessor; 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; @@ -61,17 +62,16 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri private JavaInterfaceFactory javaFactory; private PolicyFactory policyFactory; private PolicySubjectProcessor policyProcessor; - private Monitor monitor; + private FactoryExtensionPoint factories; - public SpringImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public SpringImplementationProcessor(FactoryExtensionPoint modelFactories) { this.factories = modelFactories; this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.policyProcessor = new PolicySubjectProcessor(policyFactory); - this.monitor = monitor; } /** @@ -81,7 +81,7 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri * @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(), "impl-spring-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); @@ -95,7 +95,7 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri * @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(), "impl-spring-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -121,7 +121,7 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri * then the default behaviour is to build an application context using all the *.xml files * in the METAINF/spring directory. */ - public SpringImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public SpringImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Create the Spring implementation SpringImplementation springImplementation = null; @@ -134,7 +134,7 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri springImplementation.setUnresolved(true); processComponentType(springImplementation); } else { - error("LocationAttributeMissing", reader); + error(context.getMonitor(), "LocationAttributeMissing", reader); //throw new ContributionReadException(MSG_LOCATION_MISSING); } @@ -169,7 +169,7 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri * Write out the XML representation of the Spring implementation * <implementation.spring location="..." /> */ - public void write(SpringImplementation springImplementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(SpringImplementation springImplementation, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <implementation.spring> writer.writeStartElement(Constants.SCA11_NS, IMPLEMENTATION_SPRING); @@ -187,30 +187,31 @@ public class SpringImplementationProcessor implements StAXArtifactProcessor<Spri * Resolves the Spring implementation - loads the Spring application-context XML and * derives the spring implementation componentType from it */ - public void resolve(SpringImplementation springImplementation, ModelResolver resolver) + public void resolve(SpringImplementation springImplementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (springImplementation == null) return; + Monitor monitor = context.getMonitor(); /* Load the Spring component type by reading the Spring application context */ SpringXMLComponentTypeLoader springLoader = new SpringXMLComponentTypeLoader(factories, assemblyFactory, javaFactory, policyFactory, monitor); try { // Load the Spring Implementation information from its application context file... - springLoader.load(springImplementation, resolver); + springLoader.load(springImplementation, resolver, context); } catch (ContributionReadException e) { ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", resolver, ce); + error(monitor, "ContributionResolveException", resolver, ce); throw ce; } ComponentType ct = springImplementation.getComponentType(); if (ct.isUnresolved()) { // If the introspection fails to resolve, try to find a side file... - ComponentType componentType = resolver.resolveModel(ComponentType.class, ct); + ComponentType componentType = resolver.resolveModel(ComponentType.class, ct, context); if (componentType.isUnresolved()) { - error("UnableToResolveComponentType", resolver); + error(monitor, "UnableToResolveComponentType", resolver); //throw new ContributionResolveException("SpringArtifactProcessor: unable to resolve componentType for Spring component"); } else { springImplementation.setComponentType(componentType); diff --git a/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/impl/WebImplementationBuilder.java b/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/impl/WebImplementationBuilder.java index 540b2f77b9..41adb73f61 100644 --- a/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/impl/WebImplementationBuilder.java +++ b/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/impl/WebImplementationBuilder.java @@ -22,16 +22,16 @@ package org.apache.tuscany.sca.implementation.web.impl; import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.ImplementationBuilder; import org.apache.tuscany.sca.implementation.web.WebImplementation; -import org.apache.tuscany.sca.monitor.Monitor; /** * */ public class WebImplementationBuilder implements ImplementationBuilder<WebImplementation> { - public void build(Component component, WebImplementation implmentation, Monitor monitor) { + public void build(Component component, WebImplementation implmentation, BuilderContext context) { ((WebImplementationImpl)implmentation).build(component); } diff --git a/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/xml/WebImplementationProcessor.java b/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/xml/WebImplementationProcessor.java index 39e7a7a6f3..3723ec57f2 100644 --- a/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/xml/WebImplementationProcessor.java +++ b/java/sca/modules/implementation-web/src/main/java/org/apache/tuscany/sca/implementation/web/xml/WebImplementationProcessor.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.core.ExtensionPointRegistry; @@ -65,7 +66,7 @@ public class WebImplementationProcessor extends BaseStAXArtifactProcessor implem return WebImplementation.class; } - public WebImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WebImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Read an <implementation.web> element WebImplementation implementation = implementationFactory.createWebImplementation(); @@ -90,14 +91,14 @@ public class WebImplementationProcessor extends BaseStAXArtifactProcessor implem return implementation; } - public void resolve(WebImplementation implementation, ModelResolver resolver) throws ContributionResolveException { + public void resolve(WebImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { // Resolve the component type String uri = implementation.getURI(); if (uri != null) { ComponentType componentType = assemblyFactory.createComponentType(); componentType.setURI("web.componentType"); - componentType = resolver.resolveModel(ComponentType.class, componentType); + componentType = resolver.resolveModel(ComponentType.class, componentType, context); if (!componentType.isUnresolved()) { // Initialize the implementation's services, references and properties @@ -109,7 +110,7 @@ public class WebImplementationProcessor extends BaseStAXArtifactProcessor implem implementation.setUnresolved(false); } - public void write(WebImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(WebImplementation implementation, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write <implementation.web> writeStart(writer, IMPLEMENTATION_WEB.getNamespaceURI(), IMPLEMENTATION_WEB.getLocalPart(), diff --git a/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java b/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java index 32622dec39..d9460194e5 100644 --- a/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java +++ b/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/ReadTestCase.java @@ -29,6 +29,7 @@ import junit.framework.TestCase; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; @@ -41,19 +42,21 @@ public class ReadTestCase extends TestCase { private XMLInputFactory inputFactory; private StAXArtifactProcessor<Object> staxProcessor; + private ProcessorContext context; @Override public void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("TestWeb.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite) staxProcessor.read(reader); + Composite composite = (Composite) staxProcessor.read(reader, context); assertNotNull(composite); assertTrue(((WebImplementation) composite.getComponents().get(0).getImplementation()).getWebURI().equals("MyWebapp")); } diff --git a/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/WriteTestCase.java b/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/WriteTestCase.java index 7c872a784c..ebad994033 100644 --- a/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/WriteTestCase.java +++ b/java/sca/modules/implementation-web/src/test/java/org/apache/tuscany/sca/implementation/web/xml/WriteTestCase.java @@ -30,6 +30,7 @@ import junit.framework.TestCase; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; @@ -42,22 +43,24 @@ public class WriteTestCase extends TestCase { private XMLInputFactory inputFactory; private XMLOutputFactory outputFactory; private StAXArtifactProcessor<Object> staxProcessor; + private ProcessorContext context; @Override public void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } public void testReadWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("TestWeb.composite"); - Composite composite = (Composite) staxProcessor.read(inputFactory.createXMLStreamReader(is)); + Composite composite = (Composite) staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); assertTrue(bos.toString().contains("web-uri=\"MyWebapp\"")); diff --git a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java index d32db1be52..c01947fa76 100644 --- a/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java +++ b/java/sca/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java @@ -35,6 +35,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.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -68,11 +69,10 @@ import org.oasisopen.sca.annotation.Service; public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfaceContract>, JavaConstants { private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; private JavaInterfaceFactory javaFactory; - private Monitor monitor; + - public JavaInterfaceProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public JavaInterfaceProcessor(FactoryExtensionPoint modelFactories) { this.javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); - this.monitor = monitor; } /** @@ -82,11 +82,17 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa * @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(), "interface-javaxml-validation-messages", Severity.ERROR, model, message, ex); + Problem problem = + monitor.createProblem(this.getClass().getName(), + "interface-javaxml-validation-messages", + Severity.ERROR, + model, + message, + ex); monitor.problem(problem); - } + } } /** @@ -96,12 +102,18 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "interface-javaxml-validation-messages", Severity.ERROR, model, message,(Object[])messageParameters); - monitor.problem(problem); - } - } + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "interface-javaxml-validation-messages", + Severity.ERROR, + model, + message, + (Object[])messageParameters); + monitor.problem(problem); + } + } private JavaInterface createJavaInterface(String interfaceName) { JavaInterface javaInterface = javaFactory.createJavaInterface(); @@ -110,7 +122,7 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa return javaInterface; } - public JavaInterfaceContract read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JavaInterfaceContract read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Read an <interface.java> JavaInterfaceContract javaInterfaceContract = javaFactory.createJavaInterfaceContract(); @@ -141,7 +153,7 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa return javaInterfaceContract; } - public void write(JavaInterfaceContract javaInterfaceContract, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(JavaInterfaceContract javaInterfaceContract, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <interface.java> writer.writeStartElement(SCA11_NS, INTERFACE_JAVA); @@ -159,20 +171,20 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa writer.writeEndElement(); } - private JavaInterface resolveJavaInterface(JavaInterface javaInterface, ModelResolver resolver) throws ContributionResolveException { + private JavaInterface resolveJavaInterface(JavaInterface javaInterface, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (javaInterface != null && javaInterface.isUnresolved()) { - + Monitor monitor = context.getMonitor(); // Resolve the Java interface - javaInterface = resolver.resolveModel(JavaInterface.class, javaInterface); + javaInterface = resolver.resolveModel(JavaInterface.class, javaInterface, context); if (javaInterface.isUnresolved()) { // If the Java interface has never been resolved yet, do it now ClassReference classReference = new ClassReference(javaInterface.getName()); - classReference = resolver.resolveModel(ClassReference.class, classReference); + classReference = resolver.resolveModel(ClassReference.class, classReference, context); Class<?> javaClass = classReference.getJavaClass(); if (javaClass == null) { - error("ClassNotFoundException", resolver, javaInterface.getName()); + error(monitor, "ClassNotFoundException", resolver, javaInterface.getName()); return javaInterface; //throw new ContributionResolveException(new ClassNotFoundException(javaInterface.getName())); } @@ -185,7 +197,7 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa } catch (InvalidInterfaceException e) { ContributionResolveException ce = new ContributionResolveException("Resolving Java interface " + javaInterface.getName(), e); //error("ContributionResolveException", javaFactory, ce); - error("InvalidInterfaceException", javaFactory, e); + error(monitor, "InvalidInterfaceException", javaFactory, e); return javaInterface; //throw ce; } catch ( Exception e ) { @@ -194,25 +206,30 @@ public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfa // Cache the resolved interface javaInterface.setUnresolved(false); - resolver.addModel(javaInterface); + resolver.addModel(javaInterface, context); } } return javaInterface; } - public void resolve(JavaInterfaceContract javaInterfaceContract, ModelResolver resolver) throws ContributionResolveException { + public void resolve(JavaInterfaceContract javaInterfaceContract, ModelResolver resolver, ProcessorContext context) + throws ContributionResolveException { try { - // Resolve the interface and callback interface - JavaInterface javaInterface = resolveJavaInterface((JavaInterface)javaInterfaceContract.getInterface(), resolver); - javaInterfaceContract.setInterface(javaInterface); - - JavaInterface javaCallbackInterface = resolveJavaInterface((JavaInterface)javaInterfaceContract.getCallbackInterface(), resolver); - javaInterfaceContract.setCallbackInterface(javaCallbackInterface); + Monitor monitor = context.getMonitor(); + // Resolve the interface and callback interface + JavaInterface javaInterface = + resolveJavaInterface((JavaInterface)javaInterfaceContract.getInterface(), resolver, context); + javaInterfaceContract.setInterface(javaInterface); + + JavaInterface javaCallbackInterface = + resolveJavaInterface((JavaInterface)javaInterfaceContract.getCallbackInterface(), resolver, context); + javaInterfaceContract.setCallbackInterface(javaCallbackInterface); checkForbiddenAnnotations(javaInterfaceContract); } catch (Exception e) { - throw new ContributionResolveException( "Resolving Java Interface " + javaInterfaceContract.getInterface().toString(), e ); + throw new ContributionResolveException("Resolving Java Interface " + javaInterfaceContract.getInterface() + .toString(), e); } // end try } diff --git a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java index d63b3e0549..7c8ec0d679 100644 --- a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java +++ b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; @@ -49,21 +50,23 @@ public class ReadTestCase { private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; private static StAXArtifactProcessor<Object> staxProcessor; + 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 = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } @Test public void testReadComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - ComponentType componentType = (ComponentType)staxProcessor.read(reader); + ComponentType componentType = (ComponentType)staxProcessor.read(reader, context); assertNotNull(componentType); } @@ -71,7 +74,7 @@ public class ReadTestCase { public void testReadConstrainingType() 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); assertNotNull(constrainingType); } @@ -80,7 +83,7 @@ public class ReadTestCase { public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); } diff --git a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java index b21505936b..3c0864afe3 100644 --- a/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java +++ b/java/sca/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java @@ -32,6 +32,7 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; @@ -47,41 +48,43 @@ public class WriteTestCase { private static XMLInputFactory inputFactory; private static XMLOutputFactory outputFactory; private static StAXArtifactProcessor<Object> staxProcessor; + 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 = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } @Test public void testReadWriteComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); - ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(componentType); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos), context); } @Test public void testReadWriteConstrainingType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); - ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(constrainingType); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos), context); } @Test public void testReadWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); - Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); } } diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLFactory.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLFactory.java index 95985dcc28..4e331c1fa4 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLFactory.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLFactory.java @@ -22,6 +22,7 @@ import javax.wsdl.PortType; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.monitor.Monitor; /** * Factory for the WSDL model. @@ -43,7 +44,7 @@ public interface WSDLFactory { * @param portType the portType to inspect * @return a WSDLInterface corresponding to the WSDL portType */ - WSDLInterface createWSDLInterface(PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver) throws InvalidInterfaceException; + WSDLInterface createWSDLInterface(PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver, Monitor monitor) throws InvalidInterfaceException; /** * Creates the contents of a WSDL interface from a WSDL portType. @@ -51,7 +52,7 @@ public interface WSDLFactory { * @param portType the portType to inspect * @return a WSDLInterface corresponding to the WSDL portType */ - void createWSDLInterface(WSDLInterface wsdlInterface, PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver) throws InvalidInterfaceException; + void createWSDLInterface(WSDLInterface wsdlInterface, PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver, Monitor monitor) throws InvalidInterfaceException; /** * Creates a new WSDL definition. diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLFactoryImpl.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLFactoryImpl.java index e73edb5276..52c9984831 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLFactoryImpl.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLFactoryImpl.java @@ -23,14 +23,12 @@ import javax.wsdl.PortType; 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.core.UtilityExtensionPoint; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.MonitorFactory; /** * A factory for the WSDL model. @@ -43,12 +41,7 @@ public abstract class WSDLFactoryImpl implements WSDLFactory { public WSDLFactoryImpl(ExtensionPointRegistry registry) { FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - - Monitor monitor = monitorFactory.createMonitor(); - - introspector = new WSDLInterfaceIntrospectorImpl(modelFactories, this, monitor); + introspector = new WSDLInterfaceIntrospectorImpl(modelFactories, this); } // end constructor WSDLFactoryImpl(ExtensionPointRegistry registry) public WSDLInterface createWSDLInterface() { @@ -57,17 +50,19 @@ public abstract class WSDLFactoryImpl implements WSDLFactory { public WSDLInterface createWSDLInterface(PortType portType, WSDLDefinition wsdlDefinition, - ModelResolver resolver) throws InvalidInterfaceException { + ModelResolver resolver, + Monitor monitor) throws InvalidInterfaceException { WSDLInterface wsdlInterface = createWSDLInterface(); - introspector.introspectPortType(wsdlInterface, portType, wsdlDefinition, resolver); + introspector.introspectPortType(wsdlInterface, portType, wsdlDefinition, resolver, monitor); return wsdlInterface; } public void createWSDLInterface(WSDLInterface wsdlInterface, PortType portType, WSDLDefinition wsdlDefinition, - ModelResolver resolver) throws InvalidInterfaceException { - introspector.introspectPortType(wsdlInterface, portType, wsdlDefinition, resolver); + ModelResolver resolver, + Monitor monitor) throws InvalidInterfaceException { + introspector.introspectPortType(wsdlInterface, portType, wsdlDefinition, resolver, monitor); } public WSDLDefinition createWSDLDefinition() { diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceIntrospectorImpl.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceIntrospectorImpl.java index 343703a6d1..f863ff696d 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceIntrospectorImpl.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceIntrospectorImpl.java @@ -55,21 +55,19 @@ public class WSDLInterfaceIntrospectorImpl { private WSDLFactory wsdlFactory; private XSDFactory xsdFactory; private PolicyFactory policyFactory; - private Monitor monitor; - public WSDLInterfaceIntrospectorImpl(FactoryExtensionPoint modelFactories, WSDLFactory wsdlFactory, Monitor monitor) { + public WSDLInterfaceIntrospectorImpl(FactoryExtensionPoint modelFactories, WSDLFactory wsdlFactory) { this.xsdFactory = modelFactories.getFactory(XSDFactory.class); this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.wsdlFactory = wsdlFactory; - this.monitor = monitor; } // FIXME: Do we want to deal with document-literal wrapped style based on the JAX-WS Specification? - private List<Operation> introspectOperations(PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver) throws InvalidWSDLException { + private List<Operation> introspectOperations(PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver, Monitor monitor) throws InvalidWSDLException { List<Operation> operations = new ArrayList<Operation>(); for (Object o : portType.getOperations()) { javax.wsdl.Operation wsdlOp = (javax.wsdl.Operation)o; - Operation operation = getOperation(wsdlOp, wsdlDefinition, resolver, xsdFactory); + Operation operation = getOperation(wsdlOp, wsdlDefinition, resolver, xsdFactory, monitor); if(isEndConversation(wsdlOp)) { operation.setConversationSequence(ConversationSequence.CONVERSATION_END); } @@ -78,20 +76,21 @@ public class WSDLInterfaceIntrospectorImpl { return operations; } - public void introspectPortType(WSDLInterface wsdlInterface, PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver) throws InvalidWSDLException { + public void introspectPortType(WSDLInterface wsdlInterface, PortType portType, WSDLDefinition wsdlDefinition, ModelResolver resolver, Monitor monitor) throws InvalidWSDLException { processIntents(wsdlInterface, portType); - WSDLInterface callback = processCallbackAttribute( portType, resolver ); + WSDLInterface callback = processCallbackAttribute( portType, resolver, monitor ); wsdlInterface.setPortType(portType); wsdlInterface.setCallbackInterface(callback); - wsdlInterface.getOperations().addAll(introspectOperations(portType, wsdlDefinition, resolver)); + wsdlInterface.getOperations().addAll(introspectOperations(portType, wsdlDefinition, resolver, monitor)); wsdlInterface.setConversational(isConversational(portType)); } public static Operation getOperation(javax.wsdl.Operation wsdlOp, WSDLDefinition wsdlDefinition, ModelResolver resolver, - XSDFactory xsdFactory) throws InvalidWSDLException { - WSDLOperationIntrospectorImpl op = new WSDLOperationIntrospectorImpl(xsdFactory, wsdlOp, wsdlDefinition, null, resolver); + XSDFactory xsdFactory, + Monitor monitor) throws InvalidWSDLException { + WSDLOperationIntrospectorImpl op = new WSDLOperationIntrospectorImpl(xsdFactory, wsdlOp, wsdlDefinition, null, resolver, monitor); return op.getOperation(); } @@ -101,7 +100,7 @@ public class WSDLInterfaceIntrospectorImpl { * @param portType the portType * @return */ - private WSDLInterface processCallbackAttribute( PortType portType, ModelResolver resolver ) { + private WSDLInterface processCallbackAttribute( PortType portType, ModelResolver resolver, Monitor monitor ) { Object o = portType.getExtensionAttribute(CALLBACK_ATTRIBUTE); if(o != null && o instanceof QName) { WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface(); diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLOperationIntrospectorImpl.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLOperationIntrospectorImpl.java index 2df0f0c3a1..a223b5cbd7 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLOperationIntrospectorImpl.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLOperationIntrospectorImpl.java @@ -34,6 +34,7 @@ import javax.wsdl.Part; import javax.xml.XMLConstants; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.interfacedef.ConversationSequence; import org.apache.tuscany.sca.interfacedef.DataType; @@ -46,6 +47,7 @@ import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; import org.apache.tuscany.sca.interfacedef.util.XMLType; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; +import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.xsd.XSDFactory; import org.apache.tuscany.sca.xsd.XSDefinition; import org.apache.ws.commons.schema.XmlSchemaComplexType; @@ -68,6 +70,7 @@ public class WSDLOperationIntrospectorImpl { private XSDFactory xsdFactory; private ModelResolver resolver; + private ProcessorContext context; private WSDLDefinition wsdlDefinition; private javax.wsdl.Operation operation; private WSDLOperation operationModel; @@ -87,7 +90,8 @@ public class WSDLOperationIntrospectorImpl { javax.wsdl.Operation operation, WSDLDefinition wsdlDefinition, String dataBinding, - ModelResolver resolver) { + ModelResolver resolver, + Monitor monitor) { super(); this.xsdFactory = xsdFactory; this.operation = operation; @@ -95,6 +99,7 @@ public class WSDLOperationIntrospectorImpl { this.resolver = resolver; this.dataBinding = dataBinding; this.wrapper = new Wrapper(); + this.context = new ProcessorContext(monitor); } private Wrapper wrapper; @@ -235,7 +240,7 @@ public class WSDLOperationIntrospectorImpl { XSDefinition definition = xsdFactory.createXSDefinition(); definition.setUnresolved(true); definition.setNamespace(elementName.getNamespaceURI()); - definition = resolver.resolveModel(XSDefinition.class, definition); + definition = resolver.resolveModel(XSDefinition.class, definition, context); if (definition.getSchema() != null) { element = definition.getSchema().getElementByName(elementName); } @@ -249,7 +254,7 @@ public class WSDLOperationIntrospectorImpl { XSDefinition definition = xsdFactory.createXSDefinition(); definition.setUnresolved(true); definition.setNamespace(typeName.getNamespaceURI()); - definition = resolver.resolveModel(XSDefinition.class, definition); + definition = resolver.resolveModel(XSDefinition.class, definition, context); if (definition.getSchema() != null) { type = definition.getSchema().getTypeByName(typeName); } diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java index 10c909a548..8291ef74ed 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java @@ -34,6 +34,7 @@ import org.apache.tuscany.sca.common.xml.stax.StAXHelper; import org.apache.tuscany.sca.common.xml.stax.StAXHelper.Attribute; 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.resolver.ModelResolver; @@ -62,14 +63,13 @@ public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinitio private StAXHelper helper; private WSDLFactory factory; private XSDFactory xsdFactory; - private Monitor monitor; + - public WSDLDocumentProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor, Monitor monitor) { + public WSDLDocumentProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor) { FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.factory = modelFactories.getFactory(WSDLFactory.class); this.xsdFactory = modelFactories.getFactory(XSDFactory.class); this.inputFactory = modelFactories.getFactory(XMLInputFactory.class); - this.monitor = monitor; this.helper = StAXHelper.getInstance(registry); } @@ -80,29 +80,29 @@ public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinitio * @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(), "interface-wsdlxml-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); } } - public WSDLDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + public WSDLDefinition read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException { try { WSDLDefinition definition = indexRead(artifactURL); definition.setURI(artifactURI); return definition; } catch (Exception e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", artifactURL, ce); + error(context.getMonitor(), "ContributionReadException", artifactURL, ce); //throw ce; return null; } } - public void resolve(WSDLDefinition model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(WSDLDefinition model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (model == null) return; - + Monitor monitor = context.getMonitor(); Definition definition = model.getDefinition(); if (definition != null) { for (Object imports : definition.getImports().values()) { @@ -118,7 +118,7 @@ public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinitio WSDLDefinition proxy = factory.createWSDLDefinition(); proxy.setUnresolved(true); proxy.setNamespace(imp.getNamespaceURI()); - WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy); + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy, context); if (resolved != null && !resolved.isUnresolved()) { imp.setDefinition(resolved.getDefinition()); if (!model.getImportedDefinitions().contains(resolved)) { @@ -134,14 +134,14 @@ public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinitio if (uri.isAbsolute()) { WSDLDefinition resolved; try { - resolved = read(null, uri, uri.toURL()); + resolved = read(null, uri, uri.toURL(), context); imp.setDefinition(resolved.getDefinition()); if (!model.getImportedDefinitions().contains(resolved)) { model.getImportedDefinitions().add(resolved); } } catch (Exception e) { ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", resolver, ce); + error(monitor, "ContributionResolveException", resolver, ce); //throw ce; } } else { @@ -155,14 +155,14 @@ public class WSDLDocumentProcessor implements URLArtifactProcessor<WSDLDefinitio URI locationURI = baseURI.resolve(location); WSDLDefinition resolved; try { - resolved = read(null, locationURI, locationURI.toURL()); + resolved = read(null, locationURI, locationURI.toURL(), context); imp.setDefinition(resolved.getDefinition()); if (!model.getImportedDefinitions().contains(resolved)) { model.getImportedDefinitions().add(resolved); } } catch (Exception e) { ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", resolver, ce); + error(monitor, "ContributionResolveException", resolver, ce); //throw ce; } } diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java index 77565f0ae9..8c4a986525 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java @@ -30,6 +30,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.core.ExtensionPointRegistry; @@ -53,21 +54,15 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfaceContract>, WSDLConstants { private WSDLFactory wsdlFactory; - private Monitor monitor; + private InterfaceContractMapper interfaceContractMapper; -// public WSDLInterfaceProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { -// this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); -// this.monitor = monitor; -// } - - public WSDLInterfaceProcessor(ExtensionPointRegistry registry, Monitor monitor) { + public WSDLInterfaceProcessor(ExtensionPointRegistry registry) { FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.interfaceContractMapper = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(InterfaceContractMapper.class); this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); - this.monitor = monitor; } /** * Report a warning. @@ -76,7 +71,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa * @param message * @param model */ - private void warning(String message, Object model, Object... messageParameters) { + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = monitor.createProblem(this.getClass().getName(), "interface-wsdlxml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -90,7 +85,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa * @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(), "interface-wsdlxml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); @@ -104,7 +99,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa * @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(), "interface-wsdlxml-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); @@ -119,7 +114,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa */ private static String FRAGMENT_INTERFACE = "wsdl.interface"; private static String FRAGMENT_PORTTYPE = "wsdl.porttype"; - private WSDLInterface createWSDLInterface(String uri) throws ContributionReadException { + private WSDLInterface createWSDLInterface(String uri, Monitor monitor) throws ContributionReadException { WSDLInterface wsdlInterface = null; @@ -127,7 +122,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa // namespace#wsdl.interface(name) int index = uri.indexOf('#'); if (index == -1) { - error("InvalidWSDLInterfaceAttr", wsdlFactory, uri); + error(monitor, "InvalidWSDLInterfaceAttr", wsdlFactory, uri); //throw new ContributionReadException("Invalid WSDL interface attribute: " + uri); } else { // Read the URI and extract namespace and fragment @@ -143,7 +138,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa porttype = name.substring("wsdl.porttype(".length(), name.length() - 1); } // end if if( porttype == null ) { - error("InvalidWSDLInterfaceAttr", wsdlFactory, uri); + error(monitor, "InvalidWSDLInterfaceAttr", wsdlFactory, uri); return null; } // end if wsdlInterface = wsdlFactory.createWSDLInterface(); @@ -167,9 +162,10 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa * @param reader - XMLStreamReader holding the <interface.wsdl/> element * @return - the WSDLInterfaceContract */ - public WSDLInterfaceContract read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public WSDLInterfaceContract read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { // Read an <interface.wsdl> WSDLInterfaceContract wsdlInterfaceContract = wsdlFactory.createWSDLInterfaceContract(); + Monitor monitor = context.getMonitor(); // Read wsdlLocation String location = reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION); @@ -177,14 +173,14 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa String uri = reader.getAttributeValue(null, INTERFACE); if (uri != null) { - WSDLInterface wsdlInterface = createWSDLInterface(uri); + WSDLInterface wsdlInterface = createWSDLInterface(uri, monitor); if (wsdlInterface != null) wsdlInterfaceContract.setInterface(wsdlInterface); } uri = reader.getAttributeValue(null, CALLBACK_INTERFACE); if (uri != null) { - WSDLInterface wsdlCallbackInterface = createWSDLInterface(uri); + WSDLInterface wsdlCallbackInterface = createWSDLInterface(uri, monitor); if (wsdlCallbackInterface != null) wsdlInterfaceContract.setCallbackInterface(wsdlCallbackInterface); } @@ -209,7 +205,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa return wsdlInterfaceContract; } - public void write(WSDLInterfaceContract wsdlInterfaceContract, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(WSDLInterfaceContract wsdlInterfaceContract, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <interface.wsdl> writer.writeStartElement(WSDLConstants.SCA11_NS, INTERFACE_WSDL); @@ -236,12 +232,12 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa writer.writeEndElement(); } - private WSDLInterface resolveWSDLInterface(WSDLInterface wsdlInterface, ModelResolver resolver) throws ContributionResolveException { + private WSDLInterface resolveWSDLInterface(WSDLInterface wsdlInterface, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (wsdlInterface != null && wsdlInterface.isUnresolved()) { - + Monitor monitor = context.getMonitor(); // Resolve the WSDL interface - wsdlInterface = resolver.resolveModel(WSDLInterface.class, wsdlInterface); + wsdlInterface = resolver.resolveModel(WSDLInterface.class, wsdlInterface, context); if (wsdlInterface.isUnresolved()) { // If the WSDL interface has never been resolved yet, do it now @@ -249,7 +245,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); wsdlDefinition.setUnresolved(true); wsdlDefinition.setNamespace(wsdlInterface.getName().getNamespaceURI()); - WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition); + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition, context); if (!resolved.isUnresolved()) { wsdlDefinition.setDefinition(resolved.getDefinition()); wsdlDefinition.setLocation(resolved.getLocation()); @@ -263,24 +259,24 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa // WSDLInterface to the resolver try { wsdlDefinition.setDefinition(portType.getDefinition()); - wsdlInterface = wsdlFactory.createWSDLInterface(portType.getElement(), wsdlDefinition, resolver); + wsdlInterface = wsdlFactory.createWSDLInterface(portType.getElement(), wsdlDefinition, resolver, monitor); wsdlInterface.setWsdlDefinition(wsdlDefinition); - resolver.addModel(wsdlInterface); + resolver.addModel(wsdlInterface, context); } catch (InvalidInterfaceException e) { ContributionResolveException ce = new ContributionResolveException("Invalid interface when resolving " + portType.toString(), e); - error("ContributionResolveException", wsdlFactory, ce); + error(monitor, "ContributionResolveException", wsdlFactory, ce); //throw ce; } // end try } else { - warning("WsdlInterfaceDoesNotMatch", wsdlDefinition, wsdlInterface.getName()); + warning(monitor, "WsdlInterfaceDoesNotMatch", wsdlDefinition, wsdlInterface.getName()); } // end if } else { // If we get here, the WSDLDefinition is unresolved... ContributionResolveException ce = new ContributionResolveException("WSDLDefinition unresolved " + wsdlInterface.getName() ); - error("ContributionResolveException", wsdlFactory, ce); + error(monitor, "ContributionResolveException", wsdlFactory, ce); } // end if } // end if } // end if @@ -291,8 +287,9 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa Monitor monitor, WSDLFactory wsdlFactory) { if (wsdlInterface != null && wsdlInterface.isUnresolved()) { + ProcessorContext context = new ProcessorContext(monitor); // Resolve the WSDL interface - wsdlInterface = resolver.resolveModel(WSDLInterface.class, wsdlInterface); + wsdlInterface = resolver.resolveModel(WSDLInterface.class, wsdlInterface, context); if (wsdlInterface.isUnresolved()) { // If the WSDL interface has never been resolved yet, do it now @@ -300,7 +297,7 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); wsdlDefinition.setUnresolved(true); wsdlDefinition.setNamespace(wsdlInterface.getName().getNamespaceURI()); - WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition); + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition, context); if (!resolved.isUnresolved()) { wsdlDefinition.setDefinition(resolved.getDefinition()); wsdlDefinition.setLocation(resolved.getLocation()); @@ -314,9 +311,9 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa // WSDLInterface to the resolver try { wsdlDefinition.setDefinition(portType.getDefinition()); - wsdlInterface = wsdlFactory.createWSDLInterface(portType.getElement(), wsdlDefinition, resolver); + wsdlInterface = wsdlFactory.createWSDLInterface(portType.getElement(), wsdlDefinition, resolver, monitor); wsdlInterface.setWsdlDefinition(wsdlDefinition); - resolver.addModel(wsdlInterface); + resolver.addModel(wsdlInterface, context); } catch (InvalidInterfaceException e) { ContributionResolveException ce = new ContributionResolveException("Invalid interface when resolving " + portType.toString(), e); @@ -347,23 +344,23 @@ public class WSDLInterfaceProcessor implements StAXArtifactProcessor<WSDLInterfa /** * Resolve a WSDLInterfaceContract */ - public void resolve(WSDLInterfaceContract wsdlInterfaceContract, ModelResolver resolver) throws ContributionResolveException { - + public void resolve(WSDLInterfaceContract wsdlInterfaceContract, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + Monitor monitor = context.getMonitor(); // Resolve the interface and callback interface - WSDLInterface wsdlInterface = resolveWSDLInterface((WSDLInterface)wsdlInterfaceContract.getInterface(), resolver); + WSDLInterface wsdlInterface = resolveWSDLInterface((WSDLInterface)wsdlInterfaceContract.getInterface(), resolver, context); wsdlInterfaceContract.setInterface(wsdlInterface); // The forward interface (portType) may have a callback interface declared on it using an sca:callback attribute WSDLInterface intrinsicWSDLCallbackInterface = wsdlInterface.getCallbackInterface(); // There may be a callback interface explicitly declared on the <interface.wsdl .../> element - WSDLInterface wsdlCallbackInterface = resolveWSDLInterface((WSDLInterface)wsdlInterfaceContract.getCallbackInterface(), resolver); + WSDLInterface wsdlCallbackInterface = resolveWSDLInterface((WSDLInterface)wsdlInterfaceContract.getCallbackInterface(), resolver, context); if( intrinsicWSDLCallbackInterface != null ) { if( wsdlCallbackInterface != null ) { // If there is both a callback interface declared on the forward interface and also one declared on the // interface.wsdl element, then the two interfaces must match [ASM80011] if( !interfaceContractMapper.isEqual(intrinsicWSDLCallbackInterface, wsdlCallbackInterface) ) { - Monitor.error(monitor, WSDLInterfaceProcessor.class.getName(), + Monitor.error(context.getMonitor(), WSDLInterfaceProcessor.class.getName(), "interface-wsdlxml-validation-messages", "IncompatibleCallbacks", intrinsicWSDLCallbackInterface.getName().toString(), wsdlCallbackInterface.getName().toString() ); diff --git a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java index d7c933eecc..4351c2ac54 100644 --- a/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java +++ b/java/sca/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java @@ -58,11 +58,11 @@ import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionRuntimeException; +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.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.xsd.XSDFactory; import org.apache.tuscany.sca.xsd.XSDefinition; import org.w3c.dom.Attr; @@ -117,7 +117,7 @@ public class WSDLModelResolver implements ModelResolver { private ContributionFactory contributionFactory; private XSDFactory xsdFactory; - public WSDLModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public WSDLModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.contribution = contribution; this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); @@ -156,11 +156,13 @@ public class WSDLModelResolver implements ModelResolver { * Implementation of a WSDL locator. */ private class WSDLLocatorImpl implements WSDLLocator { + private ProcessorContext context; private InputStream inputStream; private URL base; private String latestImportURI; - public WSDLLocatorImpl(URL base, InputStream is) { + public WSDLLocatorImpl(ProcessorContext context, URL base, InputStream is) { + this.context = context; this.base = base; this.inputStream = is; } @@ -203,7 +205,7 @@ public class WSDLModelResolver implements ModelResolver { //use contribution resolution (this supports import/export) Artifact importedArtifact = - contribution.getModelResolver().resolveModel(Artifact.class, proxyArtifact); + contribution.getModelResolver().resolveModel(Artifact.class, proxyArtifact, context); if (importedArtifact.getLocation() != null) { //get the artifact URL url = new URL(importedArtifact.getLocation()); @@ -227,11 +229,11 @@ public class WSDLModelResolver implements ModelResolver { } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { WSDLDefinition definition = (WSDLDefinition)resolved; for (XSDefinition d : definition.getXmlSchemas()) { if (contribution != null) { - contribution.getModelResolver().addModel(d); + contribution.getModelResolver().addModel(d, context); } } List<WSDLDefinition> list = map.get(definition.getNamespace()); @@ -242,7 +244,7 @@ public class WSDLModelResolver implements ModelResolver { list.add(definition); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { WSDLDefinition definition = (WSDLDefinition)resolved; List<WSDLDefinition> list = map.get(definition.getNamespace()); if (list == null) { @@ -256,21 +258,22 @@ public class WSDLModelResolver implements ModelResolver { * Create a facade Definition which imports all the definitions * * @param definitions A list of the WSDL definitions under the same target namespace + * @param context * @return The aggregated WSDL definition */ @SuppressWarnings("unchecked") - private WSDLDefinition aggregate(List<WSDLDefinition> definitions) { + private WSDLDefinition aggregate(List<WSDLDefinition> definitions, ProcessorContext context) { if (definitions == null || definitions.size() == 0) { return null; } if (definitions.size() == 1) { WSDLDefinition d = definitions.get(0); - loadOnDemand(d); + loadOnDemand(d, context); return d; } WSDLDefinition aggregated = wsdlFactory.createWSDLDefinition(); for (WSDLDefinition d : definitions) { - loadOnDemand(d); + loadOnDemand(d, context); } Definition facade = wsdl4jFactory.newDefinition(); String ns = definitions.get(0).getNamespace(); @@ -299,7 +302,7 @@ public class WSDLModelResolver implements ModelResolver { return aggregated; } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { WSDLDefinition resolved = null; String namespace = ((WSDLDefinition)unresolved).getNamespace(); @@ -319,7 +322,7 @@ public class WSDLModelResolver implements ModelResolver { // Delegate the resolution to the namespace import resolver resolved = namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class, - (WSDLDefinition)unresolved); + (WSDLDefinition)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } @@ -335,7 +338,7 @@ public class WSDLModelResolver implements ModelResolver { // Delegate the resolution to the default import resolver resolved = import_.getModelResolver().resolveModel(WSDLDefinition.class, - (WSDLDefinition)unresolved); + (WSDLDefinition)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } @@ -348,7 +351,7 @@ public class WSDLModelResolver implements ModelResolver { // Delegate the resolution to the namespace import resolver resolved = namespaceImport.getModelResolver().resolveModel(WSDLDefinition.class, - (WSDLDefinition)unresolved); + (WSDLDefinition)unresolved, context); if (!resolved.isUnresolved()) { return modelClass.cast(resolved); } @@ -357,7 +360,7 @@ public class WSDLModelResolver implements ModelResolver { // Not found, lookup a definition for the given namespace, within contribution List<WSDLDefinition> list = map.get(namespace); - resolved = aggregate(list); + resolved = aggregate(list, context); if (resolved != null && !resolved.isUnresolved()) { return modelClass.cast(resolved); } @@ -368,12 +371,13 @@ public class WSDLModelResolver implements ModelResolver { /** * Load the WSDL definition on demand * @param def + * @param context */ - private void loadOnDemand(WSDLDefinition def) { + private void loadOnDemand(WSDLDefinition def, ProcessorContext context) { if (def.getDefinition() == null && def.getLocation() != null) { // Load the definition on-demand try { - loadDefinition(def); + loadDefinition(def, context); } catch (ContributionReadException e) { throw new RuntimeException(e); } @@ -386,9 +390,10 @@ public class WSDLModelResolver implements ModelResolver { * Load the WSDL definition and inline schemas * * @param wsdlDef + * @param context * @throws ContributionReadException */ - private void loadDefinition(WSDLDefinition wsdlDef) throws ContributionReadException { + private void loadDefinition(WSDLDefinition wsdlDef, ProcessorContext context) throws ContributionReadException { if (wsdlDef.getDefinition() != null || wsdlDef.getLocation() == null) { return; } @@ -403,7 +408,7 @@ public class WSDLModelResolver implements ModelResolver { // reader.setFeature("javax.wsdl.importDocuments", false); reader.setExtensionRegistry(wsdlExtensionRegistry); // use a custom registry - WSDLLocatorImpl locator = new WSDLLocatorImpl(artifactURL, is); + WSDLLocatorImpl locator = new WSDLLocatorImpl(context, artifactURL, is); Definition definition = reader.readWSDL(locator); wsdlDef.setDefinition(definition); @@ -415,7 +420,7 @@ public class WSDLModelResolver implements ModelResolver { WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); wsdlDefinition.setUnresolved(true); wsdlDefinition.setNamespace(entry.getKey()); - WSDLDefinition resolved = resolveModel(WSDLDefinition.class, wsdlDefinition); + WSDLDefinition resolved = resolveModel(WSDLDefinition.class, wsdlDefinition, context); if (!resolved.isUnresolved()) { for (javax.wsdl.Import imp : entry.getValue()) { if (resolved.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) { @@ -436,7 +441,7 @@ public class WSDLModelResolver implements ModelResolver { } //Read inline schemas - readInlineSchemas(wsdlDef, definition); + readInlineSchemas(wsdlDef, definition, context); } catch (WSDLException e) { throw new ContributionReadException(e); } catch (IOException e) { @@ -473,9 +478,10 @@ public class WSDLModelResolver implements ModelResolver { * Populate the inline schemas including those from the imported definitions * * @param definition + * @param context * @param schemaCollection */ - private void readInlineSchemas(WSDLDefinition wsdlDefinition, Definition definition) { + private void readInlineSchemas(WSDLDefinition wsdlDefinition, Definition definition, ProcessorContext context) { if (contribution == null) { // Check null for test cases return; @@ -501,7 +507,7 @@ public class WSDLModelResolver implements ModelResolver { xsDefinition.setDocument(doc); xsDefinition.setLocation(URI.create(doc.getDocumentURI() + "#" + index)); XSDefinition resolved = - contribution.getModelResolver().resolveModel(XSDefinition.class, xsDefinition); + contribution.getModelResolver().resolveModel(XSDefinition.class, xsDefinition, context); if (resolved != null && !resolved.isUnresolved()) { if (!wsdlDefinition.getXmlSchemas().contains(resolved)) { // Don't add resolved because it may be an aggregate that @@ -520,7 +526,7 @@ public class WSDLModelResolver implements ModelResolver { javax.wsdl.Import anImport = (javax.wsdl.Import)i; // Read inline schemas if (anImport.getDefinition() != null) { - readInlineSchemas(wsdlDefinition, anImport.getDefinition()); + readInlineSchemas(wsdlDefinition, anImport.getDefinition(), context); } } } diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java index 1fff109389..1e66f7c4e4 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java @@ -26,6 +26,7 @@ import java.util.List; import javax.wsdl.PortType; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.Operation; @@ -54,16 +55,17 @@ public class WSDLInterfaceIntrospectorTestCase extends AbstractWSDLTestCase { super.setUp(); URL url = getClass().getResource("../xml/stockquote.wsdl"); - definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); - resolver.addModel(definition); - definition = resolver.resolveModel(WSDLDefinition.class, definition); + ProcessorContext context = new ProcessorContext(); + definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url, context); + resolver.addModel(definition, context); + definition = resolver.resolveModel(WSDLDefinition.class, definition, context); portType = definition.getDefinition().getPortType(PORTTYPE_NAME); } @Test @SuppressWarnings("unchecked") public final void testIntrospectPortType() throws InvalidInterfaceException { - WSDLInterface contract = wsdlFactory.createWSDLInterface(portType, definition, resolver); + WSDLInterface contract = wsdlFactory.createWSDLInterface(portType, definition, resolver, null); Assert.assertEquals(contract.getName().getLocalPart(), "StockQuotePortType"); List<Operation> operations = contract.getOperations(); Assert.assertEquals(1, operations.size()); diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java index 338d24cbfd..c4549f8180 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java @@ -28,6 +28,7 @@ import java.util.List; import javax.wsdl.PortType; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.util.XMLType; @@ -52,12 +53,13 @@ public class WSDLOperationIntrospectorTestCase extends AbstractWSDLTestCase { @Test public final void testWrappedOperation() throws Exception { URL url = getClass().getResource("../xml/stockquote.wsdl"); - WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); - resolver.addModel(definition); - definition = resolver.resolveModel(WSDLDefinition.class, definition); + ProcessorContext context = new ProcessorContext(); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url, context); + resolver.addModel(definition, context); + definition = resolver.resolveModel(WSDLDefinition.class, definition, context); PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); - WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver); + WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver, context.getMonitor()); WSDLOperation op = (WSDLOperation) wi.getOperations().get(0); DataType<List<DataType>> inputType = op.getInputType(); @@ -82,13 +84,14 @@ public class WSDLOperationIntrospectorTestCase extends AbstractWSDLTestCase { @Test public final void testUnwrappedOperation() throws Exception { + ProcessorContext context = new ProcessorContext(); URL url = getClass().getResource("../xml/unwrapped-stockquote.wsdl"); - WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("unwrapped-stockquote.wsdl"), url); - resolver.addModel(definition); - definition = resolver.resolveModel(WSDLDefinition.class, definition); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("unwrapped-stockquote.wsdl"), url, context); + resolver.addModel(definition, context); + definition = resolver.resolveModel(WSDLDefinition.class, definition, context); PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); - WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver); + WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver, context.getMonitor()); WSDLOperation op = (WSDLOperation) wi.getOperations().get(1); Assert.assertFalse(op.isWrapperStyle()); Assert.assertEquals(1, op.getInputType().getLogical().size()); @@ -100,14 +103,15 @@ public class WSDLOperationIntrospectorTestCase extends AbstractWSDLTestCase { @Test public final void testInvalidWSDL() throws Exception { + ProcessorContext context = new ProcessorContext(); URL url = getClass().getResource("../xml/invalid-stockquote.wsdl"); - WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("invalid-stockquote.wsdl"), url); - resolver.addModel(definition); - definition = resolver.resolveModel(WSDLDefinition.class, definition); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("invalid-stockquote.wsdl"), url, context); + resolver.addModel(definition, context); + definition = resolver.resolveModel(WSDLDefinition.class, definition, context); PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); try { - WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver); + WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver, context.getMonitor()); WSDLOperation op = (WSDLOperation) wi.getOperations().get(0); op.isWrapperStyle(); diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java index 282144c635..4172eb2955 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLPolicyAnnotatedInterfaceIntrospectorTestCase.java @@ -25,6 +25,7 @@ import java.net.URL; import javax.wsdl.PortType; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.interfacedef.ConversationSequence; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; import org.apache.tuscany.sca.interfacedef.Operation; @@ -47,22 +48,24 @@ public class WSDLPolicyAnnotatedInterfaceIntrospectorTestCase extends AbstractWS private PortType portType; private WSDLDefinition definition; + private ProcessorContext context; + @Before @Override public void setUp() throws Exception { super.setUp(); - + context = new ProcessorContext(); URL url = getClass().getResource("/policy/stockquote_policy.wsdl"); - definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); - resolver.addModel(definition); - definition = resolver.resolveModel(WSDLDefinition.class, definition); + definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url, context); + resolver.addModel(definition, context); + definition = resolver.resolveModel(WSDLDefinition.class, definition, context); portType = definition.getDefinition().getPortType(PORTTYPE_NAME); } @Test public final void testIntrospectPortType() throws InvalidInterfaceException { - WSDLInterface contract = wsdlFactory.createWSDLInterface(portType, definition, resolver); + WSDLInterface contract = wsdlFactory.createWSDLInterface(portType, definition, resolver, context.getMonitor()); Assert.assertEquals(contract.getName().getLocalPart(), "StockQuotePortType"); Assert.assertTrue(contract.isConversational()); diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java index a974bdb89c..ea02d8c3d6 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java @@ -25,6 +25,7 @@ import java.net.URL; import javax.wsdl.PortType; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLOperation; @@ -42,12 +43,13 @@ public class WrapperStyleOperationTestCase extends AbstractWSDLTestCase { @Test public final void testWrappedOperation() throws Exception { + ProcessorContext context = new ProcessorContext(); URL url = getClass().getResource("../xml/stockquote.wsdl"); - WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url); - resolver.addModel(definition); - definition = resolver.resolveModel(WSDLDefinition.class, definition); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("stockquote.wsdl"), url, context); + resolver.addModel(definition, context); + definition = resolver.resolveModel(WSDLDefinition.class, definition, context); PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); - WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver); + WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver, context.getMonitor()); WSDLOperation op = (WSDLOperation) wi.getOperations().get(0); Assert.assertTrue(op.isWrapperStyle()); Assert.assertEquals(1, op.getWrapper().getInputChildElements().size()); @@ -56,12 +58,13 @@ public class WrapperStyleOperationTestCase extends AbstractWSDLTestCase { @Test public final void testUnwrappedOperation() throws Exception { + ProcessorContext context = new ProcessorContext(); URL url = getClass().getResource("../xml/unwrapped-stockquote.wsdl"); - WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("unwrapped-stockquote.wsdl"), url); - resolver.addModel(definition); - definition = resolver.resolveModel(WSDLDefinition.class, definition); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, new URI("unwrapped-stockquote.wsdl"), url, context); + resolver.addModel(definition, context); + definition = resolver.resolveModel(WSDLDefinition.class, definition, context); PortType portType = definition.getDefinition().getPortType(PORTTYPE_NAME); - WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver); + WSDLInterface wi = wsdlFactory.createWSDLInterface(portType, definition, resolver, context.getMonitor()); WSDLOperation op = (WSDLOperation) wi.getOperations().get(1); Assert.assertFalse(op.isWrapperStyle()); op = (WSDLOperation) wi.getOperations().get(2); diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/AbstractWSDLTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/AbstractWSDLTestCase.java index bfdc7e9347..143aa47d49 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/AbstractWSDLTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/AbstractWSDLTestCase.java @@ -31,7 +31,6 @@ import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.xsd.XSDFactory; import org.junit.Before; @@ -56,11 +55,11 @@ public abstract class AbstractWSDLTestCase { ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class); Contribution contribution = contributionFactory.createContribution(); ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - resolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, (Monitor)null); + resolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); contribution.setModelResolver(resolver); URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); } } diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java index ef30b0453f..08a5f159ba 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java @@ -31,10 +31,11 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -44,22 +45,25 @@ import org.junit.Test; */ public class ReadTestCase { - private XMLInputFactory inputFactory; - private StAXArtifactProcessor<Object> staxProcessor; + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor<Object> staxProcessor; - @Before - public void setUp() throws Exception { + private static ProcessorContext context; + + @BeforeClass + public static void setUp() throws Exception { DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); inputFactory = XMLInputFactory.newInstance(); StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); } @Test public void testReadComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - ComponentType componentType = (ComponentType)staxProcessor.read(reader); + ComponentType componentType = (ComponentType)staxProcessor.read(reader, context); assertNotNull(componentType); } @@ -67,7 +71,7 @@ public class ReadTestCase { public void testReadConstrainingType() 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); assertNotNull(constrainingType); } @@ -75,7 +79,7 @@ public class ReadTestCase { public void testReadComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); XMLStreamReader reader = inputFactory.createXMLStreamReader(is); - Composite composite = (Composite)staxProcessor.read(reader); + Composite composite = (Composite)staxProcessor.read(reader, context); assertNotNull(composite); } diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java index 4f85bb8f1c..513cb383e4 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java @@ -28,6 +28,7 @@ import java.util.List; import javax.wsdl.Import; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.junit.Assert; import org.junit.Test; @@ -39,22 +40,22 @@ public class WSDLDocumentProcessorTestCase extends AbstractWSDLTestCase { @Test public void testWSDL() throws Exception { - + ProcessorContext context = new ProcessorContext(); URL url = getClass().getResource("/wsdl/helloworld-service.wsdl"); - WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, URI.create("wsdl/helloworld-service.wsdl"), url); + WSDLDefinition definition = (WSDLDefinition)documentProcessor.read(null, URI.create("wsdl/helloworld-service.wsdl"), url, context); Assert.assertNull(definition.getDefinition()); Assert.assertEquals("http://helloworld", definition.getNamespace()); URL url1 = getClass().getResource("/wsdl/helloworld-interface.wsdl"); - WSDLDefinition definition1 = (WSDLDefinition)documentProcessor.read(null, URI.create("wsdl/helloworld-interface.wsdl"), url1); + WSDLDefinition definition1 = (WSDLDefinition)documentProcessor.read(null, URI.create("wsdl/helloworld-interface.wsdl"), url1, context); Assert.assertNull(definition1.getDefinition()); Assert.assertEquals("http://helloworld", definition1.getNamespace()); - resolver.addModel(definition); - resolver.addModel(definition1); - resolver.resolveModel(WSDLDefinition.class, definition); - resolver.resolveModel(WSDLDefinition.class, definition1); - WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, definition); + resolver.addModel(definition, context); + resolver.addModel(definition1, context); + resolver.resolveModel(WSDLDefinition.class, definition, context); + resolver.resolveModel(WSDLDefinition.class, definition1, context); + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, definition, context); List imports = (List)definition.getDefinition().getImports().get("http://helloworld"); Assert.assertNotNull(imports); Assert.assertNotNull(((Import)imports.get(0)).getDefinition()); diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java index 3c08409718..90054230ff 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java @@ -31,6 +31,7 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -39,7 +40,6 @@ import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; -import org.apache.tuscany.sca.monitor.Monitor; import org.junit.Before; import org.junit.Test; @@ -59,21 +59,21 @@ public class WSDLTestCase { public void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); contributionFactory = modelFactories.getFactory(ContributionFactory.class); Contribution contribution = contributionFactory.createContribution(); ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class); - resolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, (Monitor)null); + resolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); contribution.setModelResolver(resolver); - wsdlResolver = new WSDLModelResolver(contribution, modelFactories, null); + wsdlResolver = new WSDLModelResolver(contribution, modelFactories); } @Test public void testReadWSDLDocument() throws Exception { URL url = getClass().getResource("example.wsdl"); - WSDLDefinition definition = documentProcessor.read(null, new URI("example.wsdl"), url, WSDLDefinition.class); + WSDLDefinition definition = documentProcessor.read(null, new URI("example.wsdl"), url, null, WSDLDefinition.class); assertNotNull(definition); assertNull(definition.getDefinition()); assertEquals(definition.getNamespace(), "http://www.example.org"); @@ -85,10 +85,11 @@ public class WSDLTestCase { QName aPortType = new QName("http://helloworld", "HelloWorld"); URL url = getClass().getResource("test1.wsdl"); - WSDLDefinition test1Defn = documentProcessor.read(null, new URI("test1.wsdl"), url, WSDLDefinition.class); + WSDLDefinition test1Defn = documentProcessor.read(null, new URI("test1.wsdl"), url, null, WSDLDefinition.class); assertNotNull(test1Defn); - wsdlResolver.addModel(test1Defn); - test1Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test1Defn); + ProcessorContext context = new ProcessorContext(); + wsdlResolver.addModel(test1Defn, context); + test1Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test1Defn, context); //binding is a part of test1.wsdl assertNotNull(test1Defn.getDefinition().getBinding(aBinding)); //porttype is part of test2.wsdl @@ -100,22 +101,23 @@ public class WSDLTestCase { QName aBinding = new QName("http://helloworld", "HelloWorldSoapBinding"); QName aPortType = new QName("http://helloworld", "HelloWorld"); + ProcessorContext context = new ProcessorContext(); URL url = getClass().getResource("test2.wsdl"); - WSDLDefinition test2Defn = documentProcessor.read(null, new URI("test2.wsdl"), url, WSDLDefinition.class); + WSDLDefinition test2Defn = documentProcessor.read(null, new URI("test2.wsdl"), url, null, WSDLDefinition.class); assertNotNull(test2Defn); - wsdlResolver.addModel(test2Defn); - test2Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test2Defn); + wsdlResolver.addModel(test2Defn, context); + test2Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test2Defn, context); //bindings are a part of test1.wsdl so should not be found assertNull(test2Defn.getDefinition().getBinding(aBinding)); assertNotNull(test2Defn.getDefinition().getPortType(aPortType)); url = getClass().getResource("test1.wsdl"); - WSDLDefinition test1Defn = documentProcessor.read(null, new URI("test1.wsdl"), url, WSDLDefinition.class); + WSDLDefinition test1Defn = documentProcessor.read(null, new URI("test1.wsdl"), url, null, WSDLDefinition.class); assertNotNull(test1Defn); - wsdlResolver.addModel(test1Defn); + wsdlResolver.addModel(test1Defn, context); - test1Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test1Defn); + test1Defn = wsdlResolver.resolveModel(WSDLDefinition.class, test1Defn, context); assertNotNull(test1Defn.getDefinition().getPortType(aPortType)); assertNotNull(test1Defn.getDefinition().getBinding(aBinding)); diff --git a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WriteTestCase.java b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WriteTestCase.java index a11eb1017f..ee0a0617b6 100644 --- a/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WriteTestCase.java +++ b/java/sca/modules/interface-wsdl/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WriteTestCase.java @@ -32,10 +32,11 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; 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; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; /** @@ -45,44 +46,47 @@ import org.junit.Test; */ public class WriteTestCase { - private XMLInputFactory inputFactory; - private XMLOutputFactory outputFactory; - private StAXArtifactProcessor<Object> staxProcessor; + private static XMLInputFactory inputFactory; + private static XMLOutputFactory outputFactory; + private static StAXArtifactProcessor<Object> staxProcessor; - @Before - public void setUp() throws Exception { + 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 = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); - staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory); } @Test public void testReadWriteComponentType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); - ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(componentType); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos), context); } @Test public void testReadWriteConstrainingType() throws Exception { InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); - ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(constrainingType); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos), context); } @Test public void testReadWriteComposite() throws Exception { InputStream is = getClass().getResourceAsStream("Calculator.composite"); - Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is)); + Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is), context); assertNotNull(composite); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), context); } } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java index d6ae4c5bdb..a78bfb2c3b 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/AbstractDiscoveryService.java @@ -118,7 +118,7 @@ public abstract class AbstractDiscoveryService implements Discovery, LifeCycleLi props.put(PRODUCT_NAME, "Apache Tuscany SCA"); props.put(PRODUCT_VERSION, headers.get(Constants.BUNDLE_VERSION)); props.put(VENDOR_NAME, headers.get(Constants.BUNDLE_VENDOR)); - props.put(SUPPORTED_PROTOCOLS, new String[] {"local", "sca"}); + props.put(SUPPORTED_PROTOCOLS, new String[] {"local", "org.osgi.sca"}); return props; } @@ -194,14 +194,14 @@ public abstract class AbstractDiscoveryService implements Discovery, LifeCycleLi private void triggerCallbacks(EndpointListener listener, String matchedFilter, EndpointDescription sd, int type) { switch (type) { case ADDED: - listener.addEndpoint(sd, matchedFilter); + listener.endpointAdded(sd, matchedFilter); break; case REMOVED: - listener.removeEndpoint(sd); + listener.endpointRemoved(sd, matchedFilter); break; case MODIFIED: - listener.removeEndpoint(sd); - listener.addEndpoint(sd, matchedFilter); + listener.endpointRemoved(sd, matchedFilter); + listener.endpointAdded(sd, matchedFilter); break; } } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java index a82e4a3816..ae2d704015 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/DomainDiscoveryService.java @@ -78,7 +78,7 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements */ { // Notify the endpoint listeners - EndpointDescription description = createEndpointDescription(endpoint); + EndpointDescription description = createEndpointDescription(bundleContext, endpoint); endpointChanged(description, ADDED); } } @@ -90,7 +90,7 @@ public class DomainDiscoveryService extends AbstractDiscoveryService implements } else */ { - EndpointDescription description = createEndpointDescription(endpoint); + EndpointDescription description = createEndpointDescription(context, endpoint); endpointChanged(description, REMOVED); } } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java index 69ac7b4776..1c13cc90fc 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/discovery/impl/LocalDiscoveryService.java @@ -41,6 +41,7 @@ import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.common.xml.stax.StAXHelper; 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.FactoryExtensionPoint; @@ -51,6 +52,7 @@ import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants; +import org.apache.tuscany.sca.osgi.service.remoteadmin.impl.EndpointHelper; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -84,7 +86,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B } processor = new ExtensibleStAXArtifactProcessor(processors, staxHelper.getInputFactory(), - staxHelper.getOutputFactory(), monitor); + staxHelper.getOutputFactory()); processExistingBundles(); } @@ -154,11 +156,14 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B private EndpointDescription createEndpointDescription(ServiceDescription sd) { Map<String, Object> props = new HashMap<String, Object>(sd.getProperties()); props.put(Constants.OBJECTCLASS, sd.getInterfaces().toArray(new String[sd.getInterfaces().size()])); - if (!props.containsKey(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID)) { - props.put(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID, UUID.randomUUID().toString()); + if (!props.containsKey(RemoteConstants.SERVICE_REMOTE_ID)) { + props.put(RemoteConstants.SERVICE_REMOTE_ID, String.valueOf(System.currentTimeMillis())); } - if (!props.containsKey(RemoteConstants.ENDPOINT_URI)) { - props.put(RemoteConstants.ENDPOINT_URI, UUID.randomUUID().toString()); + if (!props.containsKey(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID)) { + props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, EndpointHelper.getFrameworkUUID(context)); + } + if (!props.containsKey(RemoteConstants.SERVICE_REMOTE_URI)) { + props.put(RemoteConstants.SERVICE_REMOTE_URI, UUID.randomUUID().toString()); } EndpointDescription sed = new EndpointDescription(props); @@ -194,7 +199,7 @@ public class LocalDiscoveryService extends AbstractDiscoveryService implements B try { XMLStreamReader reader = staxHelper.createXMLStreamReader(is); reader.nextTag(); - Object model = processor.read(reader); + Object model = processor.read(reader, new ProcessorContext(registry)); if (model instanceof ServiceDescriptions) { return (ServiceDescriptions)model; } else { diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointDescription.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointDescription.java index f2cef84036..0486f14517 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointDescription.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointDescription.java @@ -15,10 +15,9 @@ */ package org.apache.tuscany.sca.osgi.service.remoteadmin; -import java.io.Serializable; import java.util.Arrays; import java.util.Collections; -import java.util.Hashtable; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -39,59 +38,111 @@ import org.osgi.framework.Version; * property keys have been chosen to match filters that are created by client * bundles that need a service. * + * TODO Automatically calculate versions of interface packages? + * + * TODO Constructor that takes a class? + * + * TODO Skipping of service.exported.* properties? + * + * TODO qualified intents? + * + * + * * @Immutable * @version $Revision$ */ -public class EndpointDescription implements Serializable { - private static final long serialVersionUID = 1L; - private static Version nullVersion = new Version("0"); - final Map/* <String,Object> */properties = new Hashtable/* <String,Object> */(); - final List /* String */interfaces; - final String remoteServiceId; - final String uri; +public class EndpointDescription { + private final Map /* <String,Object> */properties = new HashMap/* + * <String , + * Object > + */(); + private final List /* String */interfaces; + private final long remoteServiceId; + private final String remoteFrameworkUUID; + private final String remoteUri; /** * Create an Endpoint Description based on a Map. * * @param properties - * @throws IllegalArgumentException - * When the properties are not proper for an Endpoint - * Description + * @throws IllegalArgumentException When the properties are not proper for + * an Endpoint Description */ - public EndpointDescription(Map/* <String,Object> */properties) - throws IllegalArgumentException { + public EndpointDescription(Map/* <String,Object> */properties) throws IllegalArgumentException { this.properties.putAll(properties); interfaces = verifyInterfacesProperty(); - remoteServiceId = verifyStringProperty(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID); - uri = verifyStringProperty(RemoteConstants.ENDPOINT_URI); + remoteServiceId = verifyLongProperty(RemoteConstants.SERVICE_REMOTE_ID); + remoteFrameworkUUID = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID); + remoteUri = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_URI); } /** - * Create an Endpoint Description based on a reference. + * Create an Endpoint Description based on a reference and optionally a map + * of additional properties. * - * @param ref A service reference that is exportable - * @throws IllegalArgumentException + * @param ref A service reference that can be exported + * @param properties Additional properties to add. Can be <code>null</code>. + * @throws IllegalArgumentException */ - public EndpointDescription(ServiceReference ref) - throws IllegalArgumentException { + public EndpointDescription(ServiceReference ref, Map /* <String,Object> */properties) + throws IllegalArgumentException { + if (properties != null) { + this.properties.putAll(properties); + } + String[] keys = ref.getPropertyKeys(); for (int i = 0; i > keys.length; i++) properties.put(keys[i], ref.getProperty(keys[i])); - + interfaces = verifyInterfacesProperty(); - remoteServiceId = verifyStringProperty(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID); - uri = verifyStringProperty(RemoteConstants.ENDPOINT_URI); + remoteServiceId = verifyLongProperty(RemoteConstants.SERVICE_REMOTE_ID); + remoteFrameworkUUID = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID); + remoteUri = verifyStringProperty(RemoteConstants.SERVICE_REMOTE_URI); + } + + /** + * Create an Endpoint Description based on the URI, the remote service ID + * and the interface names, and optionally service properties. + * + * @param uri The URI of the remote service. + * @param interfaceNames The names of the interfaces of the service to + * consider. + * @param remoteServiceId the remote service ID. + * @param properties Optionally service properties. + */ + public EndpointDescription(String uri, String[] interfaceNames, int remoteServiceId, Map properties) { + if (uri == null) { + throw new IllegalArgumentException("URI must not be null"); + } + if (interfaceNames == null) { + throw new IllegalArgumentException("Interfaces must not be null"); + } + this.remoteUri = uri; + this.interfaces = Arrays.asList(interfaceNames); + this.remoteServiceId = remoteServiceId; + this.remoteFrameworkUUID = (String)properties.get(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID); + if (properties != null) { + this.properties.putAll(properties); + } + if (interfaceNames != null) { + this.properties.put(Constants.OBJECTCLASS, interfaceNames); + } + this.properties.put(RemoteConstants.SERVICE_REMOTE_URI, uri); + if (remoteServiceId <= 0) { + this.properties.put(RemoteConstants.SERVICE_REMOTE_ID, new Integer(remoteServiceId)); + } } /** * Verify and obtain the interface list from the properties. + * * @return A list with the interface names. - * @throws IllegalArgumentException when + * @throws IllegalArgumentException when */ - protected List /* <String> */ verifyInterfacesProperty() { + private List /* <String> */verifyInterfacesProperty() { List l = null; Object objectClass = properties.get(Constants.OBJECTCLASS); @@ -100,16 +151,13 @@ public class EndpointDescription implements Serializable { else if (!(objectClass instanceof String[])) throw new IllegalArgumentException("objectClass must be a String[]"); else { - l = Collections.unmodifiableList(Arrays - .asList((String[]) objectClass)); + l = Collections.unmodifiableList(Arrays.asList((String[])objectClass)); for (Iterator i = l.iterator(); i.hasNext();) { - String interf = (String) i.next(); + String interf = (String)i.next(); try { getInterfaceVersion(interf); } catch (Exception e) { - throw new IllegalArgumentException( - "Improper version for interface " + interf - + " caused by " + e); + throw new IllegalArgumentException("Improper version for interface " + interf + " caused by " + e); } } } @@ -117,23 +165,47 @@ public class EndpointDescription implements Serializable { } /** - * Verify and obtain the a required String property. - * @param propName The name of the + * Verify and obtain a required String property. + * + * @param propName The name of the property + * @return The value of the property. + * @throws IllegalArgumentException when the property is not set or doesn't + * have the correct data type. + */ + private String verifyStringProperty(String propName) { + Object r = properties.get(propName); + if (r == null) { + throw new IllegalArgumentException("Required property not set: " + propName); + } + if (!(r instanceof String)) { + throw new IllegalArgumentException("Required property is not a string: " + propName); + } + return (String)r; + } + + /** + * Verify and obtain a required long property. + * + * @param propName The name of the property * @return The value of the property. - * @throws IllegalArgumentException when the property is not set or doesn't - * have the correct data type. + * @throws IllegalArgumentException when the property is not set or doesn't + * have the correct data type. */ - protected String verifyStringProperty(String propName) { + private long verifyLongProperty(String propName) { Object r = properties.get(propName); + long result; if (r == null) { - throw new IllegalArgumentException( - "Required property not set: " + propName); + throw new IllegalArgumentException("Required property not set: " + propName); } if (!(r instanceof String)) { - throw new IllegalArgumentException( - "Required property is not a string: " + propName); + throw new IllegalArgumentException("Required property is not a string: " + propName); + } + try { + result = Long.parseLong((String)r); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Required property cannot be parsed as a long: " + propName); } - return (String) r; + return result; } /** @@ -144,12 +216,12 @@ public class EndpointDescription implements Serializable { * URI must represent the same endpoint. * * The value of the URI is stored in the - * {@link RemoteConstants#ENDPOINT_URI} property. + * {@link RemoteConstants#SERVICE_REMOTE_URI} property. * - * @return The URI of the endpoint, never null. + * @return The URI of the endpoint, never <code>null</code>. */ - public String getURI() { - return uri; + public String getRemoteURI() { + return remoteUri; } /** @@ -179,55 +251,31 @@ public class EndpointDescription implements Serializable { * endpoint.version.com.acme.Foo * </pre> * - * @param name - * The name of the interface for which a version is requested + * @param name The name of the interface for which a version is requested * @return The version of the given interface or <code>null</code> if the * interface has no version in this Endpoint Description */ public Version getInterfaceVersion(String name) { - String v = (String) properties.get("endpoint.version." + name); + String v = (String)properties.get("endpoint.version." + name); if (v == null) { - return nullVersion; + return Version.emptyVersion; } else { return new Version(v); } } /** - * Returns the universally unique id for the service exported through this + * Returns the service id for the service exported through this * endpoint. * - * Each service in the OSGi service registry has a universally unique id. - * The UUID can be used to detect that two Endpoint Descriptions really - * refer to the same registered service instance in some remote framework. - * This UUID can be used to filter out duplicate ways of communicating with - * the same service. - * - * The service UUID is constructed from two properties. It is first the - * <code>org.osgi.framework.uuid</code> System property set by the - * framework or through configuration. This property must uniquely - * represents the UUID of a framework instance. This UUID must not contain - * any dots ('.' \u002E). This is suffixed with a dot and then the - * <code>service.id</code> service property of the service. - * - * For example: + * This is the service id under which the framework has registered the service. This + * field together with the Framework UUID is a globally unique id for a service. * - * <pre> - * 72dc5fd9-5f8f-4f8f-9821-9ebb433a5b72.121 - * </pre> - * - * If this Endpoint Description does not map to a remote OSGi service, for - * example some web service, then the Endpoint Description must not have a - * service UUID. If two endpoints have the same URI, then they must refer to - * the same OSGi service. - * - * Starting . is not an OSGi service. - * - * @return Unique id of a service or <code>null</code> if this Endpoint + * @return Service id of a service or 0 if this Endpoint * Description does not relate to an OSGi service * */ - public String getRemoteServiceID() { + public long getRemoteServiceID() { return remoteServiceId; } @@ -272,9 +320,21 @@ public class EndpointDescription implements Serializable { } /** + * Return the framework UUID, if present. + * + * The property the intents come from is + * {@link RemoteConstants#SERVICE_REMOTE_FRAMEWORK_UUID} + * + * @return Remote Framework UUID, or null if this endpoint is not associated with an OSGi service + */ + public String getRemoteFrameworkUUID() { + return remoteFrameworkUUID; + } + + /** * Returns all endpoint properties. * - * @return An immutable map referring to the properties of this Endpoint + * @return An unmodifiable map referring to the properties of this Endpoint * Description. */ public Map/* <String, Object> */getProperties() { @@ -283,12 +343,33 @@ public class EndpointDescription implements Serializable { } /** + * Answers if this Endpoint Description refers to the same service instance + * as the given Endpoint Description. + * + * Two Endpoint Descriptions point to the same service if they have the same + * URI or their framework UUIDs and remote service ids are equal. + * + * @param other The Endpoint Description to look at + * @return True if this endpoint description points to the same service as + * the other + */ + public boolean isSameService(EndpointDescription other) { + if (remoteUri.equals(other.remoteUri)) + return true; + + if (remoteFrameworkUUID == null) + return false; + + return remoteServiceId == other.remoteServiceId && remoteFrameworkUUID.equals(other.remoteFrameworkUUID); + } + + /** * Two endpoints are equal if their URIs are equal, the hash code is * therefore derived from the URI. */ public int hashCode() { // TODO - return getURI().hashCode(); + return getRemoteURI().hashCode(); } /** @@ -296,8 +377,9 @@ public class EndpointDescription implements Serializable { */ public boolean equals(Object other) { if (other instanceof EndpointDescription) { - return getURI().equals(((EndpointDescription) other).getURI()); + return getRemoteURI().equals(((EndpointDescription)other).getRemoteURI()); } return false; } + } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointListener.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointListener.java index e8e8f37e4a..33f9b143d8 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointListener.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointListener.java @@ -1,20 +1,19 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; - /** - * A whiteboard service that represents a listener for endpoints. + * A white board service that represents a listener for endpoints. * * An Endpoint Listener represents a participant in the distributed model that * is interested in Endpoint Descriptions. * - * This whiteboard service can be used in many different scenarios. However, the - * primary use case is to allow a remote controller to be informed of End Point + * This white board service can be used in many different scenarios. However, the + * primary use case is to allow a remote manager to be informed of End Point * Descriptions available in the network and inform the network about available * End Point Descriptions. * - * Both the network bundle and the controller bundle register a Endpoint - * Listener service. The controller informs the network bundle about End Points - * that it creates. The network bundles then uses a protocol like for example + * Both the network bundle and the manager bundle register an Endpoint + * Listener service. The manager informs the network bundle about End Points + * that it creates. The network bundles then uses a protocol like * SLP to announce these local end-points to the network. * * If the network bundle discovers a new Endpoint through its discovery @@ -36,7 +35,7 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; * (org.osgi.framework.uuid=72dc5fd9-5f8f-4f8f-9821-9ebb433a5b72) * </pre> * - * In the same vein, a controller that is only interested in remote Endpoint + * In the same vein, a manager that is only interested in remote Endpoint * Descriptions can use a filter like: * * <pre> @@ -47,7 +46,7 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; * can be found in the Framework properties. * * The Endpoint Listener's scope maps very well to the service hooks. A - * controller can just register all filters found from the Listener Hook as its + * manager can just register all filters found from the Listener Hook as its * scope. This will automatically provide it with all known endpoints that match * the given scope, without having to inspect the filter string. * @@ -67,44 +66,47 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; * @ThreadSafe */ public interface EndpointListener { - /** - * Specifies the interest of this listener with filters. This listener is - * only interested in Endpoint Descriptions where its properties match the - * given filter. The type of this property must be <code>String+</code>. - */ - String ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope"; + /** + * Specifies the interest of this listener with filters. This listener is + * only interested in Endpoint Descriptions where its properties match the + * given filter. The type of this property must be <code>String+</code>. + */ + String ENDPOINT_LISTENER_SCOPE = "endpoint.listener.scope"; - /** - * Register an endpoint with this listener. - * - * If the endpoint matches one of the filters registered with the - * {@link #ENDPOINT_LISTENER_SCOPE} service property then this filter should - * be given as the <code>matchedFilter</code> parameter. - * - * When this service is first registered or it is modified, it should - * receive all known endpoints matching the filter. - * - * @param endpoint - * The Endpoint Description to be published - * @param matchedFilter - * The filter from the {@link #ENDPOINT_LISTENER_SCOPE} that - * matched the endpoint, must not be <code>null</code>. - */ - void addEndpoint(EndpointDescription endpoint, String matchedFilter); + /** + * Register an endpoint with this listener. + * + * If the endpoint matches one of the filters registered with the + * {@link #ENDPOINT_LISTENER_SCOPE} service property then this filter should + * be given as the <code>matchedFilter</code> parameter. + * + * When this service is first registered or it is modified, it should + * receive all known endpoints matching the filter. + * + * @param endpoint + * The Endpoint Description to be published + * @param matchedFilter + * The filter from the {@link #ENDPOINT_LISTENER_SCOPE} that + * matched the endpoint, must not be <code>null</code>. + */ + void endpointAdded(EndpointDescription endpoint, String matchedFilter); - /** - * Remove the registration of an endpoint. - * - * If an endpoint that was registered with the {@link #addEndpoint} - * method is no longer available then this method should be called. This - * will remove the endpoint from the listener. - * - * It is not necessary to remove endpoints when the service is unregistered - * or modified in such a way that not all endpoints match the interest - * filter anymore. - * - * @param endpoint - * The Endpoint Description that is no longer valid. - */ - void removeEndpoint(EndpointDescription endpoint); + /** + * Remove the registration of an endpoint. + * + * If an endpoint that was registered with the {@link #endpointAdded(EndpointDescription, String)} + * method is no longer available then this method should be called. This + * will remove the endpoint from the listener. + * + * It is not necessary to remove endpoints when the service is unregistered + * or modified in such a way that not all endpoints match the interest + * filter anymore. + * + * @param endpoint + * The Endpoint Description that is no longer valid. + * @param matchedFilter + * The filter from the {@link #ENDPOINT_LISTENER_SCOPE} that + * matched the endpoint, must not be <code>null</code>. + */ + void endpointRemoved(EndpointDescription endpoint, String matchedFilter); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointPermission.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointPermission.java index f0c58d97c3..48a817b005 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointPermission.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/EndpointPermission.java @@ -18,11 +18,29 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; * limitations under the License. */ -import java.io.*; -import java.security.*; -import java.util.*; - -import org.osgi.framework.*; +import java.io.IOException; +import java.io.NotSerializableException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamField; +import java.security.BasicPermission; +import java.security.Permission; +import java.security.PermissionCollection; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.osgi.framework.Constants; +import org.osgi.framework.Filter; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; /** * A bundle's authority to register or get a service. @@ -42,641 +60,632 @@ import org.osgi.framework.*; */ public final class EndpointPermission extends BasicPermission { - static final long serialVersionUID = -7662148639076511574L; - /** - * The action string <code>get</code>. - */ - public final static String EXPORT = "export"; - /** - * The action string <code>register</code>. - */ - public final static String IMPORT = "import"; - - public final static String LISTENING = "listening"; - - private final static int ACTION_EXPORT = 0x00000001; - private final static int ACTION_IMPORT = 0x00000002; - private final static int ACTION_ALL = ACTION_EXPORT | ACTION_IMPORT; - final static int ACTION_NONE = 0; - - /** - * The actions mask. - */ - transient int action_mask; - - /** - * The actions in canonical form. - * - * @serial - */ - private volatile String actions = null; - - /** - * The service used by this EndpointPermission. Must be null if not - * constructed with a service. - */ - transient final EndpointDescription endpoint; - - /** - * The object classes for this EndpointPermission. Must be null if not - * constructed with a service. - */ - transient final String[] objectClass; - - /** - * If this EndpointPermission was constructed with a filter, this holds a - * Filter matching object used to evaluate the filter in implies. - */ - transient Filter filter; - - /** - * This dictionary holds the properties of the permission, used to match a - * filter in implies. This is not initialized until necessary, and then - * cached in this object. - */ - private transient volatile Dictionary properties; - - /** - * True if constructed with a name and the name is "*" or ends with ".*". - */ - private transient boolean wildcard; - - /** - * If constructed with a name and the name ends with ".*", this contains the - * name without the final "*". - */ - private transient String prefix; - - /** - * Create a new EndpointPermission. - * - * <p> - * The name of the service is specified as a fully qualified class name. - * Wildcards may be used. - * - * <pre> - * name ::= <class name> | <class name ending in ".*"> | * - * </pre> - * - * Examples: - * - * <pre> - * org.osgi.service.http.HttpService - * org.osgi.service.http.* - * * - * </pre> - * - * For the <code>get</code> action, the name can also be a filter - * expression. The filter gives access to the service properties as well as - * the following attributes: - * <ul> - * <li>signer - A Distinguished Name chain used to sign the bundle - * publishing the service. Wildcards in a DN are not matched according to - * the filter string rules, but according to the rules defined for a DN - * chain.</li> - * <li>location - The location of the bundle publishing the service.</li> - * <li>id - The bundle ID of the bundle publishing the service.</li> - * <li>name - The symbolic name of the bundle publishing the service.</li> - * </ul> - * Since the above attribute names may conflict with service property names - * used by a service, you can prefix an attribute name with '@' in the - * filter expression to match against the service property and not one of - * the above attributes. Filter attribute names are processed in a case - * sensitive manner unless the attribute references a service property. - * Service properties names are case insensitive. - * - * <p> - * There are two possible actions: <code>get</code> and - * <code>register</code>. The <code>get</code> permission allows the - * owner of this permission to obtain a service with this name. The - * <code>register</code> permission allows the bundle to register a - * service under that name. - * - * @param name - * The service class name - * @param actions - * <code>get</code>,<code>register</code> (canonical order) - * @throws IllegalArgumentException - * If the specified name is a filter expression and either the - * specified action is not <code>get</code> or the filter has - * an invalid syntax. - */ - public EndpointPermission(String name, String actions) { - this(name, parseActions(actions)); - if ((filter != null) && ((action_mask & ACTION_ALL) != ACTION_EXPORT)) { - throw new IllegalArgumentException( - "invalid action string for filter expression"); - } - } - - /** - * Creates a new requested <code>EndpointPermission</code> object to be - * used by code that must perform <code>checkPermission</code> for the - * <code>get</code> action. <code>EndpointPermission</code> objects - * created with this constructor cannot be added to a - * <code>EndpointPermission</code> permission collection. - * - * @param endpoint - * The requested service. - * @param actions - * The action <code>get</code>. - * @throws IllegalArgumentException - * If the specified action is not <code>get</code> or - * reference is <code>null</code>. - * @since 1.5 - */ - public EndpointPermission(EndpointDescription endpoint, String actions) { - super(createName(endpoint)); - setTransients(null, parseActions(actions)); - this.endpoint = endpoint; - this.objectClass = (String[]) endpoint.getProperties().get( - Constants.OBJECTCLASS); - if ((action_mask & ACTION_ALL) != ACTION_EXPORT) { - throw new IllegalArgumentException("invalid action string"); - } - } - - /** - * Create a permission name from a EndpointDescription TODO Needs work - * - * @param endpoint - * EndpointDescription to use to create permission name. - * @return permission name. - */ - private static String createName(EndpointDescription endpoint) { - if (endpoint == null) { - throw new IllegalArgumentException("reference must not be null"); - } - StringBuffer sb = new StringBuffer("(service.id="); - // TODO sb.append(endpoint.getProperty(Constants.SERVICE_ID)); - sb.append(")"); - return sb.toString(); - } - - /** - * Package private constructor used by EndpointPermissionCollection. - * - * @param name - * class name - * @param mask - * action mask - */ - EndpointPermission(String name, int mask) { - super(name); - setTransients(parseFilter(name), mask); - this.endpoint = null; - this.objectClass = null; - } - - /** - * Called by constructors and when deserialized. - * - * @param mask - * action mask - */ - private void setTransients(Filter f, int mask) { - if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) { - throw new IllegalArgumentException("invalid action string"); - } - action_mask = mask; - filter = f; - if (f == null) { - String name = getName(); - int l = name.length(); - /* if "*" or endsWith ".*" */ - wildcard = ((name.charAt(l - 1) == '*') && ((l == 1) || (name - .charAt(l - 2) == '.'))); - if (wildcard && (l > 1)) { - prefix = name.substring(0, l - 1); - } - } - } - - /** - * Parse action string into action mask. - * - * @param actions - * Action string. - * @return action mask. - */ - private static int parseActions(String actions) { - boolean seencomma = false; - - int mask = ACTION_NONE; - - if (actions == null) { - return mask; - } - - char[] a = actions.toCharArray(); - - int i = a.length - 1; - if (i < 0) - return mask; - - while (i != -1) { - char c; - - // skip whitespace - while ((i != -1) - && ((c = a[i]) == ' ' || c == '\r' || c == '\n' - || c == '\f' || c == '\t')) - i--; - - // check for the known strings - int matchlen; - - if (i >= 2 && (a[i - 2] == 'g' || a[i - 2] == 'G') - && (a[i - 1] == 'e' || a[i - 1] == 'E') - && (a[i] == 't' || a[i] == 'T')) { - matchlen = 3; - mask |= ACTION_EXPORT; - - } else if (i >= 7 && (a[i - 7] == 'r' || a[i - 7] == 'R') - && (a[i - 6] == 'e' || a[i - 6] == 'E') - && (a[i - 5] == 'g' || a[i - 5] == 'G') - && (a[i - 4] == 'i' || a[i - 4] == 'I') - && (a[i - 3] == 's' || a[i - 3] == 'S') - && (a[i - 2] == 't' || a[i - 2] == 'T') - && (a[i - 1] == 'e' || a[i - 1] == 'E') - && (a[i] == 'r' || a[i] == 'R')) { - matchlen = 8; - mask |= ACTION_IMPORT; - - } else { - // parse error - throw new IllegalArgumentException("invalid permission: " - + actions); - } - - // make sure we didn't just match the tail of a word - // like "ackbarfregister". Also, skip to the comma. - seencomma = false; - while (i >= matchlen && !seencomma) { - switch (a[i - matchlen]) { - case ',': - seencomma = true; - /* FALLTHROUGH */ - case ' ': - case '\r': - case '\n': - case '\f': - case '\t': - break; - default: - throw new IllegalArgumentException("invalid permission: " - + actions); - } - i--; - } - - // point i at the location of the comma minus one (or -1). - i -= matchlen; - } - - if (seencomma) { - throw new IllegalArgumentException("invalid permission: " + actions); - } - - return mask; - } - - /** - * Parse filter string into a Filter object. - * - * @param filterString - * The filter string to parse. - * @return a Filter for this bundle. If the specified filterString is not a - * filter expression, then <code>null</code> is returned. - * @throws IllegalArgumentException - * If the filter syntax is invalid. - */ - private static Filter parseFilter(String filterString) { - filterString = filterString.trim(); - if (filterString.charAt(0) != '(') { - return null; - } - - try { - return FrameworkUtil.createFilter(filterString); - } catch (InvalidSyntaxException e) { - IllegalArgumentException iae = new IllegalArgumentException( - "invalid filter"); - iae.initCause(e); - throw iae; - } - } - - /** - * Determines if a <code>EndpointPermission</code> object "implies" the - * specified permission. - * - * @param p - * The target permission to check. - * @return <code>true</code> if the specified permission is implied by - * this object; <code>false</code> otherwise. - */ - public boolean implies(Permission p) { - if (!(p instanceof EndpointPermission)) { - return false; - } - EndpointPermission requested = (EndpointPermission) p; - if (endpoint != null) { - return false; - } - // if requested permission has a filter, then it is an invalid argument - if (requested.filter != null) { - return false; - } - return implies0(requested, ACTION_NONE); - } - - /** - * Internal implies method. Used by the implies and the permission - * collection implies methods. - * - * @param requested - * The requested EndpointPermission which has already be - * validated as a proper argument. The requested - * EndpointPermission must not have a filter expression. - * @param effective - * The effective actions with which to start. - * @return <code>true</code> if the specified permission is implied by - * this object; <code>false</code> otherwise. - */ - boolean implies0(EndpointPermission requested, int effective) { - /* check actions first - much faster */ - effective |= action_mask; - final int desired = requested.action_mask; - if ((effective & desired) != desired) { - return false; - } - /* we have name of "*" */ - if (wildcard && (prefix == null)) { - return true; - } - /* if we have a filter */ - Filter f = filter; - if (f != null) { - return f.matchCase(requested.getProperties()); - } - /* if requested permission not created with EndpointDescription */ - String[] requestedNames = requested.objectClass; - if (requestedNames == null) { - return super.implies(requested); - } - /* requested permission created with EndpointDescription */ - if (wildcard) { - int pl = prefix.length(); - for (int i = 0, l = requestedNames.length; i < l; i++) { - String requestedName = requestedNames[i]; - if ((requestedName.length() > pl) - && requestedName.startsWith(prefix)) { - return true; - } - } - } else { - String name = getName(); - for (int i = 0, l = requestedNames.length; i < l; i++) { - if (requestedNames[i].equals(name)) { - return true; - } - } - } - return false; - } - - /** - * Returns the canonical string representation of the actions. Always - * returns present actions in the following order: <code>get</code>, - * <code>register</code>. - * - * @return The canonical string representation of the actions. - */ - public String getActions() { - String result = actions; - if (result == null) { - StringBuffer sb = new StringBuffer(); - boolean comma = false; - - int mask = action_mask; - if ((mask & ACTION_EXPORT) == ACTION_EXPORT) { - sb.append(EXPORT); - comma = true; - } - - if ((mask & ACTION_IMPORT) == ACTION_IMPORT) { - if (comma) - sb.append(','); - sb.append(IMPORT); - } - - actions = result = sb.toString(); - } - - return result; - } - - /** - * Returns a new <code>PermissionCollection</code> object for storing - * <code>EndpointPermission<code> objects. - * - * @return A new <code>PermissionCollection</code> object suitable for storing - * <code>EndpointPermission</code> objects. - */ - public PermissionCollection newPermissionCollection() { - return new EndpointPermissionCollection(); - } - - /** - * Determines the equality of two EndpointPermission objects. - * - * Checks that specified object has the same class name and action as this - * <code>EndpointPermission</code>. - * - * @param obj - * The object to test for equality. - * @return true if obj is a <code>EndpointPermission</code>, and has the - * same class name and actions as this - * <code>EndpointPermission</code> object; <code>false</code> - * otherwise. - */ - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - - if (!(obj instanceof EndpointPermission)) { - return false; - } - - EndpointPermission sp = (EndpointPermission) obj; - - return (action_mask == sp.action_mask) - && getName().equals(sp.getName()) - && ((endpoint == sp.endpoint) || ((endpoint != null) - && (sp.endpoint != null) && endpoint - .equals(sp.endpoint))); - } - - /** - * Returns the hash code value for this object. - * - * @return Hash code value for this object. - */ - public int hashCode() { - int h = 31 * 17 + getName().hashCode(); - h = 31 * h + getActions().hashCode(); - if (endpoint != null) { - h = 31 * h + endpoint.hashCode(); - } - return h; - } - - /** - * WriteObject is called to save the state of this permission to a stream. - * The actions are serialized, and the superclass takes care of the name. - */ - private synchronized void writeObject(java.io.ObjectOutputStream s) - throws IOException { - if (endpoint != null) { - throw new NotSerializableException("cannot serialize"); - } - // Write out the actions. The superclass takes care of the name - // call getActions to make sure actions field is initialized - if (actions == null) - getActions(); - s.defaultWriteObject(); - } - - /** - * readObject is called to restore the state of this permission from a - * stream. - */ - private synchronized void readObject(java.io.ObjectInputStream s) - throws IOException, ClassNotFoundException { - // Read in the action, then initialize the rest - s.defaultReadObject(); - setTransients(parseFilter(getName()), parseActions(actions)); - } - - /** - * Called by <code><@link EndpointPermission#implies(Permission)></code>. - * - * @return a dictionary of properties for this permission. - */ - private Dictionary/*<String,Object>*/ getProperties() { - Dictionary/*<String, Object>*/ result = properties; - if (result != null) { - return result; - } - if (endpoint == null) { - result = new Hashtable/*<String, Object>*/(1); - if (filter == null) { - result.put(Constants.OBJECTCLASS, new String[] { getName() }); - } - return properties = result; - } - final Map props = new HashMap(4); - // TODO needs work - /* - final Bundle bundle = endpoint.getBundle(); - if (bundle != null) { - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - props.put("id", new Long(bundle.getBundleId())); - props.put("location", bundle.getLocation()); - String name = bundle.getSymbolicName(); - if (name != null) { - props.put("name", name); - } - SignerProperty signer = new SignerProperty(bundle); - if (signer.isBundleSigned()) { - props.put("signer", signer); - } - return null; - } - }); - } - */ - return properties = new Properties(props, endpoint); - } - - private static class Properties extends Dictionary { - private final Map properties; - private final EndpointDescription service; - - Properties(Map properties, EndpointDescription service) { - this.properties = properties; - this.service = service; - } - - public Object get(Object k) { - if (!(k instanceof String)) { - return null; - } - String key = (String) k; - if (key.charAt(0) == '@') { - return service.getProperties().get(key.substring(1)); - } - Object value = properties.get(key); - if (value != null) { // fall back to service properties - return value; - } - return service.getProperties().get(key); - } - - public int size() { - return properties.size() + service.getProperties().size(); - } - - public boolean isEmpty() { - // we can return false because this must never be empty - return false; - } - - public Enumeration keys() { - Collection pk = properties.keySet(); - String spk[] = (String[]) service.getProperties().keySet().toArray(new String[service.getProperties().size()]); - List all = new ArrayList(pk.size() + spk.length); - all.addAll(pk); - add: for (int i = 0, length = spk.length; i < length; i++) { - String key = spk[i]; - for (Iterator iter = pk.iterator(); iter.hasNext();) { - if (key.equalsIgnoreCase((String) iter.next())) { - continue add; - } - } - all.add(key); - } - return Collections.enumeration(all); - } - - public Enumeration elements() { - Collection pk = properties.keySet(); - String spk[] = (String[])service.getProperties().keySet().toArray(new String[service.getProperties().size()]); - List all = new ArrayList(pk.size() + spk.length); - all.addAll(properties.values()); - add: for (int i = 0, length = spk.length; i < length; i++) { - String key = spk[i]; - for (Iterator iter = pk.iterator(); iter.hasNext();) { - if (key.equalsIgnoreCase((String) iter.next())) { - continue add; - } - } - all.add(service.getProperties().get(key)); - } - return Collections.enumeration(all); - } - - public Object put(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - public Object remove(Object key) { - throw new UnsupportedOperationException(); - } - } + static final long serialVersionUID = -7662148639076511574L; + /** + * The action string <code>get</code>. + */ + public final static String EXPORT = "export"; + /** + * The action string <code>register</code>. + */ + public final static String IMPORT = "import"; + + public final static String LISTENING = "listening"; + + public final static String READ = "listening"; + + private final static int ACTION_EXPORT = 0x00000001; + private final static int ACTION_IMPORT = 0x00000002; + private final static int ACTION_ALL = ACTION_EXPORT | ACTION_IMPORT; + final static int ACTION_NONE = 0; + + /** + * The actions mask. + */ + transient int action_mask; + + /** + * The actions in canonical form. + * + * @serial + */ + private volatile String actions = null; + + /** + * The service used by this EndpointPermission. Must be null if not + * constructed with a service. + */ + transient final EndpointDescription endpoint; + + /** + * The object classes for this EndpointPermission. Must be null if not + * constructed with a service. + */ + transient final String[] objectClass; + + /** + * If this EndpointPermission was constructed with a filter, this holds a + * Filter matching object used to evaluate the filter in implies. + */ + transient Filter filter; + + /** + * This dictionary holds the properties of the permission, used to match a + * filter in implies. This is not initialized until necessary, and then + * cached in this object. + */ + private transient volatile Dictionary properties; + + /** + * True if constructed with a name and the name is "*" or ends with ".*". + */ + private transient boolean wildcard; + + /** + * If constructed with a name and the name ends with ".*", this contains the + * name without the final "*". + */ + private transient String prefix; + + /** + * Create a new EndpointPermission. + * + * <p> + * The name of the service is specified as a fully qualified class name. + * Wildcards may be used. + * + * <pre> + * name ::= <class name> | <class name ending in ".*"> | * + * </pre> + * + * Examples: + * + * <pre> + * org.osgi.service.http.HttpService + * org.osgi.service.http.* + * * + * </pre> + * + * For the <code>get</code> action, the name can also be a filter + * expression. The filter gives access to the service properties as well as + * the following attributes: + * <ul> + * <li>signer - A Distinguished Name chain used to sign the bundle + * publishing the service. Wildcards in a DN are not matched according to + * the filter string rules, but according to the rules defined for a DN + * chain.</li> + * <li>location - The location of the bundle publishing the service.</li> + * <li>id - The bundle ID of the bundle publishing the service.</li> + * <li>name - The symbolic name of the bundle publishing the service.</li> + * </ul> + * Since the above attribute names may conflict with service property names + * used by a service, you can prefix an attribute name with '@' in the + * filter expression to match against the service property and not one of + * the above attributes. Filter attribute names are processed in a case + * sensitive manner unless the attribute references a service property. + * Service properties names are case insensitive. + * + * <p> + * There are two possible actions: <code>get</code> and + * <code>register</code>. The <code>get</code> permission allows the + * owner of this permission to obtain a service with this name. The + * <code>register</code> permission allows the bundle to register a + * service under that name. + * + * @param name + * The service class name + * @param actions + * <code>get</code>,<code>register</code> (canonical order) + * @throws IllegalArgumentException + * If the specified name is a filter expression and either the + * specified action is not <code>get</code> or the filter has + * an invalid syntax. + */ + public EndpointPermission(String name, String actions) { + this(name, parseActions(actions)); + if ((filter != null) && ((action_mask & ACTION_ALL) != ACTION_EXPORT)) { + throw new IllegalArgumentException("invalid action string for filter expression"); + } + } + + /** + * Creates a new requested <code>EndpointPermission</code> object to be + * used by code that must perform <code>checkPermission</code> for the + * <code>get</code> action. <code>EndpointPermission</code> objects + * created with this constructor cannot be added to a + * <code>EndpointPermission</code> permission collection. + * + * @param endpoint + * The requested service. + * @param actions + * The action <code>get</code>. + * @throws IllegalArgumentException + * If the specified action is not <code>get</code> or + * reference is <code>null</code>. + * @since 1.5 + */ + public EndpointPermission(EndpointDescription endpoint, String actions) { + super(createName(endpoint)); + setTransients(null, parseActions(actions)); + this.endpoint = endpoint; + this.objectClass = (String[])endpoint.getProperties().get(Constants.OBJECTCLASS); + if ((action_mask & ACTION_ALL) != ACTION_EXPORT) { + throw new IllegalArgumentException("invalid action string"); + } + } + + /** + * Create a permission name from a EndpointDescription TODO Needs work + * + * @param endpoint + * EndpointDescription to use to create permission name. + * @return permission name. + */ + private static String createName(EndpointDescription endpoint) { + if (endpoint == null) { + throw new IllegalArgumentException("reference must not be null"); + } + StringBuffer sb = new StringBuffer("(service.id="); + // TODO sb.append(endpoint.getProperty(Constants.SERVICE_ID)); + sb.append(")"); + return sb.toString(); + } + + /** + * Package private constructor used by EndpointPermissionCollection. + * + * @param name + * class name + * @param mask + * action mask + */ + EndpointPermission(String name, int mask) { + super(name); + setTransients(parseFilter(name), mask); + this.endpoint = null; + this.objectClass = null; + } + + /** + * Called by constructors and when deserialized. + * + * @param mask + * action mask + */ + private void setTransients(Filter f, int mask) { + if ((mask == ACTION_NONE) || ((mask & ACTION_ALL) != mask)) { + throw new IllegalArgumentException("invalid action string"); + } + action_mask = mask; + filter = f; + if (f == null) { + String name = getName(); + int l = name.length(); + /* if "*" or endsWith ".*" */ + wildcard = ((name.charAt(l - 1) == '*') && ((l == 1) || (name.charAt(l - 2) == '.'))); + if (wildcard && (l > 1)) { + prefix = name.substring(0, l - 1); + } + } + } + + /** + * Parse action string into action mask. + * + * @param actions + * Action string. + * @return action mask. + */ + private static int parseActions(String actions) { + boolean seencomma = false; + + int mask = ACTION_NONE; + + if (actions == null) { + return mask; + } + + char[] a = actions.toCharArray(); + + int i = a.length - 1; + if (i < 0) + return mask; + + while (i != -1) { + char c; + + // skip whitespace + while ((i != -1) && ((c = a[i]) == ' ' || c == '\r' || c == '\n' || c == '\f' || c == '\t')) + i--; + + // check for the known strings + int matchlen; + + if (i >= 2 && (a[i - 2] == 'g' || a[i - 2] == 'G') + && (a[i - 1] == 'e' || a[i - 1] == 'E') + && (a[i] == 't' || a[i] == 'T')) { + matchlen = 3; + mask |= ACTION_EXPORT; + + } else if (i >= 7 && (a[i - 7] == 'r' || a[i - 7] == 'R') + && (a[i - 6] == 'e' || a[i - 6] == 'E') + && (a[i - 5] == 'g' || a[i - 5] == 'G') + && (a[i - 4] == 'i' || a[i - 4] == 'I') + && (a[i - 3] == 's' || a[i - 3] == 'S') + && (a[i - 2] == 't' || a[i - 2] == 'T') + && (a[i - 1] == 'e' || a[i - 1] == 'E') + && (a[i] == 'r' || a[i] == 'R')) { + matchlen = 8; + mask |= ACTION_IMPORT; + + } else { + // parse error + throw new IllegalArgumentException("invalid permission: " + actions); + } + + // make sure we didn't just match the tail of a word + // like "ackbarfregister". Also, skip to the comma. + seencomma = false; + while (i >= matchlen && !seencomma) { + switch (a[i - matchlen]) { + case ',': + seencomma = true; + /* FALLTHROUGH */ + case ' ': + case '\r': + case '\n': + case '\f': + case '\t': + break; + default: + throw new IllegalArgumentException("invalid permission: " + actions); + } + i--; + } + + // point i at the location of the comma minus one (or -1). + i -= matchlen; + } + + if (seencomma) { + throw new IllegalArgumentException("invalid permission: " + actions); + } + + return mask; + } + + /** + * Parse filter string into a Filter object. + * + * @param filterString + * The filter string to parse. + * @return a Filter for this bundle. If the specified filterString is not a + * filter expression, then <code>null</code> is returned. + * @throws IllegalArgumentException + * If the filter syntax is invalid. + */ + private static Filter parseFilter(String filterString) { + filterString = filterString.trim(); + if (filterString.charAt(0) != '(') { + return null; + } + + try { + return FrameworkUtil.createFilter(filterString); + } catch (InvalidSyntaxException e) { + IllegalArgumentException iae = new IllegalArgumentException("invalid filter"); + iae.initCause(e); + throw iae; + } + } + + /** + * Determines if a <code>EndpointPermission</code> object "implies" the + * specified permission. + * + * @param p + * The target permission to check. + * @return <code>true</code> if the specified permission is implied by + * this object; <code>false</code> otherwise. + */ + public boolean implies(Permission p) { + if (!(p instanceof EndpointPermission)) { + return false; + } + EndpointPermission requested = (EndpointPermission)p; + if (endpoint != null) { + return false; + } + // if requested permission has a filter, then it is an invalid argument + if (requested.filter != null) { + return false; + } + return implies0(requested, ACTION_NONE); + } + + /** + * Internal implies method. Used by the implies and the permission + * collection implies methods. + * + * @param requested + * The requested EndpointPermission which has already be + * validated as a proper argument. The requested + * EndpointPermission must not have a filter expression. + * @param effective + * The effective actions with which to start. + * @return <code>true</code> if the specified permission is implied by + * this object; <code>false</code> otherwise. + */ + boolean implies0(EndpointPermission requested, int effective) { + /* check actions first - much faster */ + effective |= action_mask; + final int desired = requested.action_mask; + if ((effective & desired) != desired) { + return false; + } + /* we have name of "*" */ + if (wildcard && (prefix == null)) { + return true; + } + /* if we have a filter */ + Filter f = filter; + if (f != null) { + return f.matchCase(requested.getProperties()); + } + /* if requested permission not created with EndpointDescription */ + String[] requestedNames = requested.objectClass; + if (requestedNames == null) { + return super.implies(requested); + } + /* requested permission created with EndpointDescription */ + if (wildcard) { + int pl = prefix.length(); + for (int i = 0, l = requestedNames.length; i < l; i++) { + String requestedName = requestedNames[i]; + if ((requestedName.length() > pl) && requestedName.startsWith(prefix)) { + return true; + } + } + } else { + String name = getName(); + for (int i = 0, l = requestedNames.length; i < l; i++) { + if (requestedNames[i].equals(name)) { + return true; + } + } + } + return false; + } + + /** + * Returns the canonical string representation of the actions. Always + * returns present actions in the following order: <code>get</code>, + * <code>register</code>. + * + * @return The canonical string representation of the actions. + */ + public String getActions() { + String result = actions; + if (result == null) { + StringBuffer sb = new StringBuffer(); + boolean comma = false; + + int mask = action_mask; + if ((mask & ACTION_EXPORT) == ACTION_EXPORT) { + sb.append(EXPORT); + comma = true; + } + + if ((mask & ACTION_IMPORT) == ACTION_IMPORT) { + if (comma) + sb.append(','); + sb.append(IMPORT); + } + + actions = result = sb.toString(); + } + + return result; + } + + /** + * Returns a new <code>PermissionCollection</code> object for storing + * <code>EndpointPermission<code> objects. + * + * @return A new <code>PermissionCollection</code> object suitable for storing + * <code>EndpointPermission</code> objects. + */ + public PermissionCollection newPermissionCollection() { + return new EndpointPermissionCollection(); + } + + /** + * Determines the equality of two EndpointPermission objects. + * + * Checks that specified object has the same class name and action as this + * <code>EndpointPermission</code>. + * + * @param obj + * The object to test for equality. + * @return true if obj is a <code>EndpointPermission</code>, and has the + * same class name and actions as this + * <code>EndpointPermission</code> object; <code>false</code> + * otherwise. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + + if (!(obj instanceof EndpointPermission)) { + return false; + } + + EndpointPermission sp = (EndpointPermission)obj; + + return (action_mask == sp.action_mask) && getName().equals(sp.getName()) + && ((endpoint == sp.endpoint) || ((endpoint != null) && (sp.endpoint != null) && endpoint + .equals(sp.endpoint))); + } + + /** + * Returns the hash code value for this object. + * + * @return Hash code value for this object. + */ + public int hashCode() { + int h = 31 * 17 + getName().hashCode(); + h = 31 * h + getActions().hashCode(); + if (endpoint != null) { + h = 31 * h + endpoint.hashCode(); + } + return h; + } + + /** + * WriteObject is called to save the state of this permission to a stream. + * The actions are serialized, and the superclass takes care of the name. + */ + private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException { + if (endpoint != null) { + throw new NotSerializableException("cannot serialize"); + } + // Write out the actions. The superclass takes care of the name + // call getActions to make sure actions field is initialized + if (actions == null) + getActions(); + s.defaultWriteObject(); + } + + /** + * readObject is called to restore the state of this permission from a + * stream. + */ + private synchronized void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { + // Read in the action, then initialize the rest + s.defaultReadObject(); + setTransients(parseFilter(getName()), parseActions(actions)); + } + + /** + * Called by <code><@link EndpointPermission#implies(Permission)></code>. + * + * @return a dictionary of properties for this permission. + */ + private Dictionary/*<String,Object>*/getProperties() { + Dictionary/*<String, Object>*/result = properties; + if (result != null) { + return result; + } + if (endpoint == null) { + result = new Hashtable/*<String, Object>*/(1); + if (filter == null) { + result.put(Constants.OBJECTCLASS, new String[] {getName()}); + } + return properties = result; + } + final Map props = new HashMap(4); + // TODO needs work + /* + final Bundle bundle = endpoint.getBundle(); + if (bundle != null) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + props.put("id", new Long(bundle.getBundleId())); + props.put("location", bundle.getLocation()); + String name = bundle.getSymbolicName(); + if (name != null) { + props.put("name", name); + } + SignerProperty signer = new SignerProperty(bundle); + if (signer.isBundleSigned()) { + props.put("signer", signer); + } + return null; + } + }); + } + */ + return properties = new Properties(props, endpoint); + } + + private static class Properties extends Dictionary { + private final Map properties; + private final EndpointDescription service; + + Properties(Map properties, EndpointDescription service) { + this.properties = properties; + this.service = service; + } + + public Object get(Object k) { + if (!(k instanceof String)) { + return null; + } + String key = (String)k; + if (key.charAt(0) == '@') { + return service.getProperties().get(key.substring(1)); + } + Object value = properties.get(key); + if (value != null) { // fall back to service properties + return value; + } + return service.getProperties().get(key); + } + + public int size() { + return properties.size() + service.getProperties().size(); + } + + public boolean isEmpty() { + // we can return false because this must never be empty + return false; + } + + public Enumeration keys() { + Collection pk = properties.keySet(); + String spk[] = + (String[])service.getProperties().keySet().toArray(new String[service.getProperties().size()]); + List all = new ArrayList(pk.size() + spk.length); + all.addAll(pk); + add: for (int i = 0, length = spk.length; i < length; i++) { + String key = spk[i]; + for (Iterator iter = pk.iterator(); iter.hasNext();) { + if (key.equalsIgnoreCase((String)iter.next())) { + continue add; + } + } + all.add(key); + } + return Collections.enumeration(all); + } + + public Enumeration elements() { + Collection pk = properties.keySet(); + String spk[] = + (String[])service.getProperties().keySet().toArray(new String[service.getProperties().size()]); + List all = new ArrayList(pk.size() + spk.length); + all.addAll(properties.values()); + add: for (int i = 0, length = spk.length; i < length; i++) { + String key = spk[i]; + for (Iterator iter = pk.iterator(); iter.hasNext();) { + if (key.equalsIgnoreCase((String)iter.next())) { + continue add; + } + } + all.add(service.getProperties().get(key)); + } + return Collections.enumeration(all); + } + + public Object put(Object key, Object value) { + throw new UnsupportedOperationException(); + } + + public Object remove(Object key) { + throw new UnsupportedOperationException(); + } + } } /** @@ -687,253 +696,243 @@ public final class EndpointPermission extends BasicPermission { * @see java.security.PermissionCollection */ final class EndpointPermissionCollection extends PermissionCollection { - static final long serialVersionUID = 662615640374640621L; - /** - * Table of permissions. - * - * @GuardedBy this - */ - private transient Map permissions; - - /** - * Boolean saying if "*" is in the collection. - * - * @serial - * @GuardedBy this - */ - private boolean all_allowed; - - /** - * Table of permissions with filter expressions. - * - * @serial - * @GuardedBy this - */ - private Map filterPermissions; - - /** - * Creates an empty EndpointPermissions object. - */ - public EndpointPermissionCollection() { - permissions = new HashMap(); - all_allowed = false; - } - - /** - * Adds a permission to this permission collection. - * - * @param permission - * The Permission object to add. - * @throws IllegalArgumentException - * If the specified permission is not a EndpointPermission - * object. - * @throws SecurityException - * If this <code>EndpointPermissionCollection</code> object - * has been marked read-only. - */ - public void add(final Permission permission) { - if (!(permission instanceof EndpointPermission)) { - throw new IllegalArgumentException("invalid permission: " - + permission); - } - if (isReadOnly()) { - throw new SecurityException("attempt to add a Permission to a " - + "readonly PermissionCollection"); - } - - final EndpointPermission sp = (EndpointPermission) permission; - if (sp.endpoint != null) { - throw new IllegalArgumentException("cannot add to collection: " - + sp); - } - - final String name = sp.getName(); - final Filter f = sp.filter; - synchronized (this) { - /* select the bucket for the permission */ - Map pc; - if (f != null) { - pc = filterPermissions; - if (pc == null) { - filterPermissions = pc = new HashMap(); - } - } else { - pc = permissions; - } - final EndpointPermission existing = (EndpointPermission) pc - .get(name); - - if (existing != null) { - final int oldMask = existing.action_mask; - final int newMask = sp.action_mask; - if (oldMask != newMask) { - pc.put(name, - new EndpointPermission(name, oldMask | newMask)); - } - } else { - pc.put(name, sp); - } - - if (!all_allowed) { - if (name.equals("*")) { - all_allowed = true; - } - } - } - } - - /** - * Determines if a set of permissions implies the permissions expressed in - * <code>permission</code>. - * - * @param permission - * The Permission object to compare. - * @return <code>true</code> if <code>permission</code> is a proper - * subset of a permission in the set; <code>false</code> - * otherwise. - */ - public boolean implies(final Permission permission) { - if (!(permission instanceof EndpointPermission)) { - return false; - } - final EndpointPermission requested = (EndpointPermission) permission; - /* if requested permission has a filter, then it is an invalid argument */ - if (requested.filter != null) { - return false; - } - - int effective = EndpointPermission.ACTION_NONE; - Collection perms; - synchronized (this) { - final int desired = requested.action_mask; - /* short circuit if the "*" Permission was added */ - if (all_allowed) { - EndpointPermission sp = (EndpointPermission) permissions - .get("*"); - if (sp != null) { - effective |= sp.action_mask; - if ((effective & desired) == desired) { - return true; - } - } - } - - String[] requestedNames = requested.objectClass; - /* if requested permission not created with EndpointDescription */ - if (requestedNames == null) { - effective |= effective(requested.getName(), desired, effective); - if ((effective & desired) == desired) { - return true; - } - } - /* requested permission created with EndpointDescription */ - else { - for (int i = 0, l = requestedNames.length; i < l; i++) { - if ((effective(requestedNames[i], desired, effective) & desired) == desired) { - return true; - } - } - } - Map pc = filterPermissions; - if (pc == null) { - return false; - } - perms = pc.values(); - } - - /* iterate one by one over filteredPermissions */ - for (Iterator iter = perms.iterator(); iter.hasNext();) { - if (((EndpointPermission) iter.next()).implies0(requested, - effective)) { - return true; - } - } - return false; - } - - /** - * Consult permissions map to compute the effective permission for the - * requested permission name. - * - * @param requestedName - * The requested service name. - * @param desired - * The desired actions. - * @param effective - * The effective actions. - * @return The new effective actions. - */ - private int effective(String requestedName, final int desired, int effective) { - final Map pc = permissions; - EndpointPermission sp = (EndpointPermission) pc.get(requestedName); - // strategy: - // Check for full match first. Then work our way up the - // name looking for matches on a.b.* - if (sp != null) { - // we have a direct hit! - effective |= sp.action_mask; - if ((effective & desired) == desired) { - return effective; - } - } - // work our way up the tree... - int last; - int offset = requestedName.length() - 1; - while ((last = requestedName.lastIndexOf(".", offset)) != -1) { - requestedName = requestedName.substring(0, last + 1) + "*"; - sp = (EndpointPermission) pc.get(requestedName); - if (sp != null) { - effective |= sp.action_mask; - if ((effective & desired) == desired) { - return effective; - } - } - offset = last - 1; - } - /* - * we don't have to check for "*" as it was already checked before we - * were called. - */ - return effective; - } - - /** - * Returns an enumeration of all the <code>EndpointPermission</code> - * objects in the container. - * - * @return Enumeration of all the EndpointPermission objects. - */ - public synchronized Enumeration elements() { - List all = new ArrayList(permissions.values()); - Map pc = filterPermissions; - if (pc != null) { - all.addAll(pc.values()); - } - return Collections.enumeration(all); - } - - /* serialization logic */ - private static final ObjectStreamField[] serialPersistentFields = { - new ObjectStreamField("permissions", Hashtable.class), - new ObjectStreamField("all_allowed", Boolean.TYPE), - new ObjectStreamField("filterPermissions", HashMap.class) }; - - private synchronized void writeObject(ObjectOutputStream out) - throws IOException { - Hashtable hashtable = new Hashtable(permissions); - ObjectOutputStream.PutField pfields = out.putFields(); - pfields.put("permissions", hashtable); - pfields.put("all_allowed", all_allowed); - pfields.put("filterPermissions", filterPermissions); - out.writeFields(); - } - - private synchronized void readObject(java.io.ObjectInputStream in) - throws IOException, ClassNotFoundException { - ObjectInputStream.GetField gfields = in.readFields(); - Hashtable hashtable = (Hashtable) gfields.get("permissions", null); - permissions = new HashMap(hashtable); - all_allowed = gfields.get("all_allowed", false); - filterPermissions = (HashMap) gfields.get("filterPermissions", null); - } + static final long serialVersionUID = 662615640374640621L; + /** + * Table of permissions. + * + * @GuardedBy this + */ + private transient Map permissions; + + /** + * Boolean saying if "*" is in the collection. + * + * @serial + * @GuardedBy this + */ + private boolean all_allowed; + + /** + * Table of permissions with filter expressions. + * + * @serial + * @GuardedBy this + */ + private Map filterPermissions; + + /** + * Creates an empty EndpointPermissions object. + */ + public EndpointPermissionCollection() { + permissions = new HashMap(); + all_allowed = false; + } + + /** + * Adds a permission to this permission collection. + * + * @param permission + * The Permission object to add. + * @throws IllegalArgumentException + * If the specified permission is not a EndpointPermission + * object. + * @throws SecurityException + * If this <code>EndpointPermissionCollection</code> object + * has been marked read-only. + */ + public void add(final Permission permission) { + if (!(permission instanceof EndpointPermission)) { + throw new IllegalArgumentException("invalid permission: " + permission); + } + if (isReadOnly()) { + throw new SecurityException("attempt to add a Permission to a " + "readonly PermissionCollection"); + } + + final EndpointPermission sp = (EndpointPermission)permission; + if (sp.endpoint != null) { + throw new IllegalArgumentException("cannot add to collection: " + sp); + } + + final String name = sp.getName(); + final Filter f = sp.filter; + synchronized (this) { + /* select the bucket for the permission */ + Map pc; + if (f != null) { + pc = filterPermissions; + if (pc == null) { + filterPermissions = pc = new HashMap(); + } + } else { + pc = permissions; + } + final EndpointPermission existing = (EndpointPermission)pc.get(name); + + if (existing != null) { + final int oldMask = existing.action_mask; + final int newMask = sp.action_mask; + if (oldMask != newMask) { + pc.put(name, new EndpointPermission(name, oldMask | newMask)); + } + } else { + pc.put(name, sp); + } + + if (!all_allowed) { + if (name.equals("*")) { + all_allowed = true; + } + } + } + } + + /** + * Determines if a set of permissions implies the permissions expressed in + * <code>permission</code>. + * + * @param permission + * The Permission object to compare. + * @return <code>true</code> if <code>permission</code> is a proper + * subset of a permission in the set; <code>false</code> + * otherwise. + */ + public boolean implies(final Permission permission) { + if (!(permission instanceof EndpointPermission)) { + return false; + } + final EndpointPermission requested = (EndpointPermission)permission; + /* if requested permission has a filter, then it is an invalid argument */ + if (requested.filter != null) { + return false; + } + + int effective = EndpointPermission.ACTION_NONE; + Collection perms; + synchronized (this) { + final int desired = requested.action_mask; + /* short circuit if the "*" Permission was added */ + if (all_allowed) { + EndpointPermission sp = (EndpointPermission)permissions.get("*"); + if (sp != null) { + effective |= sp.action_mask; + if ((effective & desired) == desired) { + return true; + } + } + } + + String[] requestedNames = requested.objectClass; + /* if requested permission not created with EndpointDescription */ + if (requestedNames == null) { + effective |= effective(requested.getName(), desired, effective); + if ((effective & desired) == desired) { + return true; + } + } + /* requested permission created with EndpointDescription */ + else { + for (int i = 0, l = requestedNames.length; i < l; i++) { + if ((effective(requestedNames[i], desired, effective) & desired) == desired) { + return true; + } + } + } + Map pc = filterPermissions; + if (pc == null) { + return false; + } + perms = pc.values(); + } + + /* iterate one by one over filteredPermissions */ + for (Iterator iter = perms.iterator(); iter.hasNext();) { + if (((EndpointPermission)iter.next()).implies0(requested, effective)) { + return true; + } + } + return false; + } + + /** + * Consult permissions map to compute the effective permission for the + * requested permission name. + * + * @param requestedName + * The requested service name. + * @param desired + * The desired actions. + * @param effective + * The effective actions. + * @return The new effective actions. + */ + private int effective(String requestedName, final int desired, int effective) { + final Map pc = permissions; + EndpointPermission sp = (EndpointPermission)pc.get(requestedName); + // strategy: + // Check for full match first. Then work our way up the + // name looking for matches on a.b.* + if (sp != null) { + // we have a direct hit! + effective |= sp.action_mask; + if ((effective & desired) == desired) { + return effective; + } + } + // work our way up the tree... + int last; + int offset = requestedName.length() - 1; + while ((last = requestedName.lastIndexOf(".", offset)) != -1) { + requestedName = requestedName.substring(0, last + 1) + "*"; + sp = (EndpointPermission)pc.get(requestedName); + if (sp != null) { + effective |= sp.action_mask; + if ((effective & desired) == desired) { + return effective; + } + } + offset = last - 1; + } + /* + * we don't have to check for "*" as it was already checked before we + * were called. + */ + return effective; + } + + /** + * Returns an enumeration of all the <code>EndpointPermission</code> + * objects in the container. + * + * @return Enumeration of all the EndpointPermission objects. + */ + public synchronized Enumeration elements() { + List all = new ArrayList(permissions.values()); + Map pc = filterPermissions; + if (pc != null) { + all.addAll(pc.values()); + } + return Collections.enumeration(all); + } + + /* serialization logic */ + private static final ObjectStreamField[] serialPersistentFields = + {new ObjectStreamField("permissions", Hashtable.class), new ObjectStreamField("all_allowed", Boolean.TYPE), + new ObjectStreamField("filterPermissions", HashMap.class)}; + + private synchronized void writeObject(ObjectOutputStream out) throws IOException { + Hashtable hashtable = new Hashtable(permissions); + ObjectOutputStream.PutField pfields = out.putFields(); + pfields.put("permissions", hashtable); + pfields.put("all_allowed", all_allowed); + pfields.put("filterPermissions", filterPermissions); + out.writeFields(); + } + + private synchronized void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { + ObjectInputStream.GetField gfields = in.readFields(); + Hashtable hashtable = (Hashtable)gfields.get("permissions", null); + permissions = new HashMap(hashtable); + all_allowed = gfields.get("all_allowed", false); + filterPermissions = (HashMap)gfields.get("filterPermissions", null); + } } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ExportRegistration.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ExportRegistration.java index 4e98d633d8..0f1805131c 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ExportRegistration.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ExportRegistration.java @@ -1,13 +1,13 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; -import org.osgi.framework.*; +import org.osgi.framework.ServiceReference; /** * An Export Registration associates a service to a local endpoint. * * The Export Registration can be used to delete the endpoint associated with an - * this registration. It is created with the{@link RemoteAdmin#exportService(ServiceReference)} - * method. + * this registration. It is created with the + * {@link RemoteServiceAdmin#exportService(ServiceReference,java.util.Map)} method. * * When this Export Registration has been unregistered, the methods must all * return <code>null</code>. @@ -15,49 +15,47 @@ import org.osgi.framework.*; * @ThreadSafe */ public interface ExportRegistration { - /** - * Return the service being exported. - * - * @return The service being exported, must be <code>null</code> when this - * registration is unregistered. - * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} - */ - ServiceReference getExportedService() throws IllegalStateException; + /** + * Return the service being exported. + * + * @return The service being exported, must be <code>null</code> when this + * registration is unregistered. + * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} + */ + ServiceReference getExportedService() throws IllegalStateException; - /** - * Return the Endpoint Description that is created for this registration. - * - * @return the local Endpoint Description - * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} - */ - EndpointDescription getEndpointDescription(); + /** + * Return the Endpoint Description that is created for this registration. + * + * @return the local Endpoint Description + * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} + */ + EndpointDescription getEndpointDescription(); - /** - * Delete the local endpoint and disconnect any remote distribution - * providers. After this method returns, all the methods must return - * <code>null</code>. - * - * This method has no effect when the endpoint is already destroyed or being - * destroyed. - */ - void close(); + /** + * Delete the local endpoint and disconnect any remote distribution + * providers. After this method returns, all the methods must return + * <code>null</code>. + * + * This method has no effect when the endpoint is already destroyed or being + * destroyed. + */ + void close(); - /** - * Exception for any error during the import process. - * - * If the Remote Admin for some reasons is unable to create a registration, - * then it must return a <code>Throwable</code> from this method. In this - * case, all other methods must return on this interface must thrown an - * Illegal State Exception. If no error occurred, this method must return - * <code>null</code>. - * - * The error must be set before this Import Registration is returned. - * Asynchronously occurring errors must be reported to the log. - * - * future .... - * - * @return The exception that occurred during the creation of the - * registration or <code>null</code> if no exception occurred. - */ - Throwable getException(); + /** + * Exception for any error during the import process. + * + * If the Remote Admin for some reasons is unable to create a registration, + * then it must return a <code>Throwable</code> from this method. In this + * case, all other methods must return on this interface must throw an + * Illegal State Exception. If no error occurred, this method must return + * <code>null</code>. + * + * The error must be set before this Import Registration is returned. + * Asynchronously occurring errors must be reported to the log. + * + * @return The exception that occurred during the creation of the + * registration or <code>null</code> if no exception occurred. + */ + Throwable getException(); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ImportRegistration.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ImportRegistration.java index 1d55dbfc75..c943380068 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ImportRegistration.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/ImportRegistration.java @@ -1,59 +1,60 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; -import org.osgi.framework.*; +import org.osgi.framework.ServiceReference; /** * An Import Registration associates an active proxy service to a remote * endpoint. * * The Import Registration can be used to delete the proxy associated with an - * endpoint. It is created with the{@link RemoteAdmin#importService} + * endpoint. It is created with the{@link RemoteServiceAdmin#importService} * method. * * @ThreadSafe */ public interface ImportRegistration { - /** - * Answer the associated Service Reference for the proxy to the endpoint. - * - * @return A Service Reference to the proxy for the endpoint. - * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} - */ - ServiceReference getImportedService(); + /** + * Answer the associated Service Reference for the proxy to the endpoint. + * + * @return A Service Reference to the proxy for the endpoint. + * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} + */ + ServiceReference getImportedService(); - /** - * Answer the associated remote Endpoint Description. - * - * @return A Endpoint Description for the remote endpoint. - * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} - */ - EndpointDescription getImportedEndpointDescription(); + /** + * Answer the associated remote Endpoint Description. + * + * @return A Endpoint Description for the remote endpoint. + * @throws IllegalStateException Thrown when this object was not properly initialized, see {@link #getException()} + */ + EndpointDescription getImportedEndpointDescription(); - /** - * Unregister this Import Registration. This must close the connection - * to the end endpoint unregister the proxy. After this method returns, - * all other methods must return null. - * - * This method has no effect when the service is already unregistered or in the process off. - */ - void close(); - - - /** - * Exception for any error during the import process. - * - * If the Remote Admin for some reasons is unable to create a registration, - * then it must return a <code>Throwable</code> from this method. In this - * case, all other methods must return on this interface must thrown an - * Illegal State Exception. If no error occurred, this method must return - * <code>null</code>. - * - * The error must be set before this Import Registration is returned. - * Asynchronously occurring errors must be reported to the log. - * - * @return The exception that occurred during the creation of the - * registration or <code>null</code> if no exception occurred. - */ - Throwable getException(); + /** + * Unregister this Import Registration. This must close the connection + * to the end endpoint unregister the proxy. After this method returns, + * all other methods must return null. + * + * This method has no effect when the service is already unregistered or in the process off. + */ + void close(); + + /** + * Exception for any error during the import process. + * + * If the Remote Admin for some reasons is unable to create a registration, + * then it must return a <code>Throwable</code> from this method. In this + * case, all other methods must return on this interface must thrown an + * Illegal State Exception. If no error occurred, this method must return + * <code>null</code>. + * + * The error must be set before this Import Registration is returned. + * Asynchronously occurring errors must be reported to the log. + * + * TODO can we assume the proxy service is registered when getException==null? + * + * @return The exception that occurred during the creation of the + * registration or <code>null</code> if no exception occurred. + */ + Throwable getException(); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteAdminEvent.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteAdminEvent.java deleted file mode 100644 index 8bc0502b17..0000000000 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteAdminEvent.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.apache.tuscany.sca.osgi.service.remoteadmin; - -import org.osgi.framework.Bundle; - -/** - * - * Provides the event information for a Remote Admin event. - * - * @Immutable - */ -public class RemoteAdminEvent { - /** - * Add an import registration. The Remote Services Admin will call this - * method when it imports a service. When this service is registered, the - * Remote Service Admin must notify the listener of all existing Import - * Registrations. - * - */ - public static final int IMPORT_REGISTRATION = 1; - - /** - * Add an export registration. The Remote Services Admin will call this - * method when it exports a service. When this service is registered, the - * Remote Service Admin must notify the listener of all existing Export - * Registrations. - */ - public static final int EXPORT_REGISTRATION = 2; - - /** - * Remove an export registration. The Remote Services Admin will call this - * method when it removes the export of a service. - * - */ - public static final int EXPORT_UNREGISTRATION = 3; - - /** - * Remove an import registration. The Remote Services Admin will call this - * method when it removes the import of a service. - * - */ - public static final int IMPORT_UNREGISTRATION = 4; - - /** - * A fatal importing error occurred. The Import Registration has been - * closed. - */ - public static final int IMPORT_ERROR = 5; - - /** - * A fatal exporting error occurred. The Export Registration has been - * closed. - */ - public static final int EXPORT_ERROR = 6; - - /** - * A problematic situation occurred, the export is still active. - */ - public static final int EXPORT_WARNING = 7; - /** - * A problematic situation occurred, the import is still active. - */ - public static final int IMPORT_WARNING = 8; - - private ImportRegistration importRegistration; - private ExportRegistration exportRegistration; - private Throwable exception; - private int type; - private Bundle source; - - RemoteAdminEvent(int type, Bundle source, - ImportRegistration importRegistration, - ExportRegistration exportRegistration, Throwable exception) { - this.type = type; - this.source = source; - this.importRegistration = importRegistration; - this.exportRegistration = exportRegistration; - this.exception = exception; - } - - /** - * @return the importRegistration - */ - public ImportRegistration getImportRegistration() { - return importRegistration; - } - - /** - * @return the exportRegistration - */ - public ExportRegistration getExportRegistration() { - return exportRegistration; - } - - /** - * @return the exception - */ - public Throwable getException() { - return exception; - } - - /** - * @return the type - */ - public int getType() { - return type; - } - - /** - * @return the source - */ - public Bundle getSource() { - return source; - } -} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteConstants.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteConstants.java index 6207554c98..e45a600347 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteConstants.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteConstants.java @@ -3,155 +3,153 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; /** * Provide the definition of the constants used in the Remote Services API. * + * TODO Should some of the properties in chapter 13 go the framework constants? */ public class RemoteConstants { - private RemoteConstants() { - } + private RemoteConstants() { + } - /** - * The configuration types supported by this Distribution Provider. - * - * Services that are suitable for distribution list the configuration types - * that describe the configuration information for that service in the - * {@link #SERVICE_EXPORTED_CONFIGS} or {@link #SERVICE_IMPORTED_CONFIGS} - * property. - * - * A distribution provider must register a service that has this property - * and enumerate all configuration types that it supports. - * - * The type of this property <code>String+</code> - * - * @see #SERVICE_EXPORTED_CONFIGS - * @see #SERVICE_IMPORTED_CONFIGS - */ - public final static String REMOTE_CONFIGS_SUPPORTED = "remote.configs.supported"; + /** + * The configuration types supported by this Distribution Provider. + * + * Services that are suitable for distribution list the configuration types + * that describe the configuration information for that service in the + * {@link #SERVICE_EXPORTED_CONFIGS} or {@link #SERVICE_IMPORTED_CONFIGS} + * property. + * + * A distribution provider must register a service that has this property + * and enumerate all configuration types that it supports. + * + * The type of this property <code>String+</code> + * + * @see #SERVICE_EXPORTED_CONFIGS + * @see #SERVICE_IMPORTED_CONFIGS + */ + public final static String REMOTE_CONFIGS_SUPPORTED = "remote.configs.supported"; - /** - * Service property that lists the intents supported by the distribution - * provider. - * - * Each distribution provider must register a service that has this property - * and enumerate all the supported intents, having any qualified intents - * expanded. - * - * The value of this property is of type <code>String+</code>. - * - * @see #SERVICE_INTENTS - * @see #SERVICE_EXPORTED_INTENTS - * @see #SERVICE_EXPORTED_INTENTS_EXTRA - */ - public final static String REMOTE_INTENTS_SUPPORTED = "remote.intents.supported"; + /** + * Service property that lists the intents supported by the distribution + * provider. + * + * Each distribution provider must register a service that has this property + * and enumerate all the supported intents, having any qualified intents + * expanded. + * + * The value of this property is of type <code>String+</code>. + * + * @see #SERVICE_INTENTS + * @see #SERVICE_EXPORTED_INTENTS + * @see #SERVICE_EXPORTED_INTENTS_EXTRA + */ + public final static String REMOTE_INTENTS_SUPPORTED = "remote.intents.supported"; - /** - * Defines the interfaces under which this service can be exported. - * - * This list must be a subset of the types listed in the objectClass service - * property. The single value of an asterisk ('*' \u002A) indicates all - * interfaces in the registration's objectClass property (not classes). It - * is highly recommended to only export interfaces and not concrete classes - * due to the complexity of creating proxies for some type of classes. - * - * The value of this property is of type String+. - */ - public final static String SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces"; + /** + * Defines the interfaces under which this service can be exported. + * + * This list must be a subset of the types listed in the objectClass service + * property. The single value of an asterisk ('*' \u002A) indicates all + * interfaces in the registration's objectClass property (not classes). It + * is highly recommended to only export interfaces and not concrete classes + * due to the complexity of creating proxies for some type of classes. + * + * The value of this property is of type String+. + */ + public final static String SERVICE_EXPORTED_INTERFACES = "service.exported.interfaces"; - /** - * A list of intents that the distribution provider must implement to - * distribute the service. Intents listed in this property are reserved for - * intents that are critical for the code to function correctly, for - * example, ordering of messages. These intents should not be configurable. - * - * The value of this property is of type <code>String+</code>. - */ - public final static String SERVICE_EXPORTED_INTENTS = "service.exported.intents"; + /** + * A list of intents that the distribution provider must implement to + * distribute the service. Intents listed in this property are reserved for + * intents that are critical for the code to function correctly, for + * example, ordering of messages. These intents should not be configurable. + * + * The value of this property is of type <code>String+</code>. + */ + public final static String SERVICE_EXPORTED_INTENTS = "service.exported.intents"; - /** - * Extra intents configured in addition to the the intents specified in - * {@link #SERVICE_EXPORTED_INTENTS}. - * - * These intents are merged with the service.exported.intents and therefore - * have the same semantics. They are extra, so that the - * {@link #SERVICE_EXPORTED_INTENTS} can be set by the bundle developer and - * this property is then set by the administrator/deployer. Bundles should - * make this property configurable, for example through the Configuration - * Admin service. - * - * The value of this property is of type <code>String+</code>. - */ - public final static String SERVICE_EXPORTED_INTENTS_EXTRA = "service.exported.intents.extra"; + /** + * Extra intents configured in addition to the the intents specified in + * {@link #SERVICE_EXPORTED_INTENTS}. + * + * These intents are merged with the service.exported.intents and therefore + * have the same semantics. They are extra, so that the + * {@link #SERVICE_EXPORTED_INTENTS} can be set by the bundle developer and + * this property is then set by the administrator/deployer. Bundles should + * make this property configurable, for example through the Configuration + * Admin service. + * + * The value of this property is of type <code>String+</code>. + */ + public final static String SERVICE_EXPORTED_INTENTS_EXTRA = "service.exported.intents.extra"; - /** - * A list of configuration types that should be used to export the service. - * - * Configuration types can be <em>synonymous</em> or <em>alternatives</em>. - * In principle, a distribution provider should create an endpoint for each - * recognized configuration type, the deployer is responsible that synonyms - * do not clash. - * - * Each configuration type has an associated specification that describes - * how the configuration data for the exported service is represented in an - * OSGi framework. - * - * The value of this property is of type <code>String+</code>. - */ - public final static String SERVICE_EXPORTED_CONFIGS = "service.exported.configs"; + /** + * A list of configuration types that should be used to export the service. + * + * Configuration types can be <em>synonymous</em> or <em>alternatives</em>. + * In principle, a distribution provider should create an endpoint for each + * recognized configuration type, the deployer is responsible that synonyms + * do not clash. + * + * Each configuration type has an associated specification that describes + * how the configuration data for the exported service is represented in an + * OSGi framework. + * + * The value of this property is of type <code>String+</code>. + */ + public final static String SERVICE_EXPORTED_CONFIGS = "service.exported.configs"; - /** - * Must be set by a distribution provider to <code>true</code> when it - * registers the end-point proxy as an imported service. Can be used by a - * bundle to prevent it from getting an imported service. - * - * The value of this property is not defined, setting it is sufficient. - */ - public final static String SERVICE_IMPORTED = "service.imported"; + /** + * Must be set by a distribution provider to <code>true</code> when it + * registers the end-point proxy as an imported service. Can be used by a + * bundle to prevent it from getting an imported service. + * + * The value of this property is not defined, setting it is sufficient. + */ + public final static String SERVICE_IMPORTED = "service.imported"; - /** - * The configuration type used to import this services, as described in - * {@link #SERVICE_EXPORTED_CONFIGS}. Any associated properties for this - * configuration types must be properly mapped to the importing system. For - * example, a URL in these properties must point to a valid resource when - * used in the importing framework. Configuration types in this property - * must be synonymous. - * - * The value of this property is of type <code>String+</code>. - */ - public final String SERVICE_IMPORTED_CONFIGS = "service.imported.configs"; + /** + * The configuration type used to import this services, as described in + * {@link #SERVICE_EXPORTED_CONFIGS}. Any associated properties for this + * configuration types must be properly mapped to the importing system. For + * example, a URL in these properties must point to a valid resource when + * used in the importing framework. Configuration types in this property + * must be synonymous. + * + * The value of this property is of type <code>String+</code>. + */ + public final String SERVICE_IMPORTED_CONFIGS = "service.imported.configs"; - /** - * A list of intents that this service implements. This property has dual - * purpose. A bundle can use this service property to notify the - * distribution provider that these intents are already implemented by the - * exported service object. For an imported service, a distribution provider - * must use this property to convey the combined intents of the exporting - * service and the intents that the distribution providers add. To export a - * service, a distribution provider must recognize all these intents and - * expand any qualified intents. - * - * The value of this property is of type <code>String+</code>. - */ - public final static String SERVICE_INTENTS = "service.intents"; + /** + * A list of intents that this service implements. This property has dual + * purpose. A bundle can use this service property to notify the + * distribution provider that these intents are already implemented by the + * exported service object. For an imported service, a distribution provider + * must use this property to convey the combined intents of the exporting + * service and the intents that the distribution providers add. To export a + * service, a distribution provider must recognize all these intents and + * expand any qualified intents. + * + * The value of this property is of type <code>String+</code>. + */ + public final static String SERVICE_INTENTS = "service.intents"; + /** + * The property key for the endpoint URI. This is a unique id for an + * endpoint following the URI syntax. As far as this specification is + * concerned, this unique id is opaque. + */ + final public static String SERVICE_REMOTE_URI = "service.remote.uri"; - /** - * The property key for the endpoint URI. This is a unique id for an - * endpoint following the URI syntax. As far as this specification is - * concerned, this unique id is opaque. - */ - final public static String ENDPOINT_URI = "endpoint.uri"; + /** + * The property key for the endpoint service id. This is a unique id for a + * service based on the framework id '.' service id or another model. As far as this specification is + * concerned, this unique id is opaque. + */ + final public static String SERVICE_REMOTE_ID = "service.remote.id"; - /** - * The property key for the endpoint service id. This is a unique id for a - * service based on the framework id '.' service id or another model. As far as this specification is - * concerned, this unique id is opaque. - */ - final public static String ENDPOINT_REMOTE_SERVICE_ID = "endpoint.remote.service.id"; - - /** - * The key for a framework property that defines the UUID of the framework. - * - * The property must be set by the framework or through configuration before - * the VM is started or some bundle. The value must be a Universally Unique - * Id, it must not contain any dots ('.' \u002E). - */ - public final static String FRAMEWORK_UUID = "org.osgi.framework.uuid"; + /** + * The property key for the endpoint service id. This is a unique id for a + * service based on the framework id '.' service id or another model. As far as this specification is + * concerned, this unique id is opaque. + */ + final public static String SERVICE_REMOTE_FRAMEWORK_UUID = "service.remote.framework.id"; } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdmin.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdmin.java index 450f205d04..627780b46f 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdmin.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdmin.java @@ -10,85 +10,101 @@ import org.osgi.framework.ServiceReference; * A Remote Service Admin manages the import and export of services. * * A Distribution Provider can expose a control interface. This interface allows - * the a remote controller to control the export and import of services. + * the a remote manager to control the export and import of services. + * + * The API allows a remote manager to export a service, to import a service, and + * find out about the current imports and exports. + * * - * The API allows a remote controller to export a service, to import a service, - * and find out about the current imports and exports. * * @ThreadSafe */ public interface RemoteServiceAdmin { - /** - * Export a service to an endpoint. The Remote Service Admin must create an - * endpoint that can be used by other Distrbution Providers to connect to - * this Remote Service Admin and use the exported service. This method can - * return null if the service could not be exported. ### do we need - * exceptions? - * - * @param ref - * The Service Reference to export - * @return An Export Registration that combines the Endpoint Description and - * the Service Reference or - * <code>null</code> if the service could not be exported - * @throws IllegalArgumentException - * @throws UnsupportedOperationException - */ - List/*<ExportRegistration>*/ exportService(ServiceReference ref) throws IllegalArgumentException, UnsupportedOperationException; - - /** - * Export a service to a given endpoint. The Remote Service Admin must - * create an endpoint from the given description that can be used by other - * Distrbution Providers to connect to this Remote Service Admin and use the - * exported service. This method can return null if the service could not be - * exported because the endpoint could not be implemented by this Remote - * Service Admin. ### do we need exceptions? - * - * @param ref - * The Service Reference to export - * @param properties - * The properties to create a local endpoint that can be implemented by - * this Remote Service Admin. If this is null, the endpoint will - * be determined by the properties on the service, see - * {@link #exportService(ServiceReference)}. The properties are - * the same as given for an exported service. They are overlaid - * over any properties the service defines. - * @return An Export Registration that combines the Endpoint Description and - * the Service Reference or - * <code>null</code> if the service could not be exported - * @throws IllegalArgumentException - * @throws UnsupportedOperationException - */ - List/*<ExportRegistration>*/ exportService(ServiceReference ref, - Map/*<String,Object>*/ properties) throws IllegalArgumentException, UnsupportedOperationException; - + /** + * Export a service to a given endpoint. The Remote Service Admin must + * create an endpoint from the given description that can be used by other + * Distrbution Providers to connect to this Remote Service Admin and use the + * exported service. This method can return null if the service could not be + * exported because the endpoint could not be implemented by this Remote + * Service Admin. + * + * The properties on a Service Reference are case insensitive while the + * properties on a <code>properties</code> are case sensitive. A value in + * the <code>properties</code> must therefore override any case variant in + * the properties of the Service Reference. + * + * If an endpoint can not be created because no + * {@link EndpointPermission#EXPORT} can be obtained to export this service, + * then this endpoint must be ignored and no Export Registration must be + * included in the returned list. + * + * @param ref The Service Reference to export + * @param properties The properties to create a local endpoint that can be + * implemented by this Remote Service Admin. If this is null, the + * endpoint will be determined by the properties on the service. The + * properties are the same as given for an exported service. They are + * overlaid over any properties the service defines (case + * insensitive). This parameter can be <code>null</code>, this + * should be treated as an empty map. + * @return An Export Registration that combines the Endpoint Description and + * the Service Reference or <code>null</code> if the service could + * not be exported + * @throws IllegalArgumentException + * @throws UnsupportedOperationException + * + * TODO discuss case difference in properties + * + * TODO More exceptions? + * TODO Can you export ANY service by providing the proper properties? + */ + List/* <ExportRegistration> */exportService(ServiceReference ref, Map/* <String,Object> */properties) + throws IllegalArgumentException, UnsupportedOperationException; - /** - * Import a service from an endpoint. The Remote Service Admin must use the - * given endpoint to create a proxy. This method can return null if the - * service could not be imported. ### do we need exceptions? - * - * @param endpoint - * The Endpoint Description to be used for import - * @return An Import Registration that combines the Endpoint Description and - * the Service Reference or - * <code>null</code> if the endpoint could not be imported - */ - ImportRegistration importService(EndpointDescription endpoint); + /** + * Import a service from an endpoint. The Remote Service Admin must use the + * given endpoint to create a proxy. This method can return null if the + * service could not be imported. + * + * TODO if the import reg. is valid (getException==null), can we then assume the + * service is registered? + * + * If an endpoint can not be imported because no + * {@link EndpointPermission#IMPORT} can be obtained, then this endpoint + * must be ignored and no Import Registration must included in the returned + * list. + * + * @param endpoint The Endpoint Description to be used for import + * @return An Import Registration that combines the Endpoint Description and + * the Service Reference or <code>null</code> if the endpoint + * could not be imported + */ + ImportRegistration importService(EndpointDescription endpoint); - - /** - * Answer the currently active Export Registrations. - * - * @return A collection of Export Registrations that are currently active. - */ - Collection/*<? extends ExportRegistration>*/ getExportedServices(); + /** + * Answer the currently active Export Registrations. + * + * @return A collection of Export Registrations that are currently active. + * @throws SecurityException When the caller no + * {@link EndpointPermission#READ} could be obtained + * + * TODO I guess we must ensure these registrations cannot be closed? Only the owners should be able to close them, + * TODO should we make sure that the list contains the registration objects that the caller created? + */ + Collection/* <ExportRegistration> */getExportedServices(); - /** - * Answer the currently active Import Registrations. - * - * @return A collection of Import Registrations that are currently active. - */ - Collection/*<? extends ImportRegistration>*/ getImportedEndpoints(); + /** + * Answer the currently active Import Registrations. + * + * @throws SecurityException When the caller no EndpointPermission LIST + * could be obtained + * @return A collection of Import Registrations that are currently active. + * @throws SecurityException When the caller no + * {@link EndpointPermission#READ} could be obtained + * + * TODO I guess we must ensure these registrations cannot be closed? Only the owners should be able to close them, + * TODO should we make sure that the list contains the registration objects that the caller created? + */ + Collection/* <ImportRegistration> */getImportedEndpoints(); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdminEvent.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdminEvent.java new file mode 100644 index 0000000000..ad2e0c4057 --- /dev/null +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdminEvent.java @@ -0,0 +1,149 @@ +package org.apache.tuscany.sca.osgi.service.remoteadmin; + +import org.osgi.framework.Bundle; + +/** + * + * Provides the event information for a Remote Admin event. + * + * @Immutable + */ +public class RemoteServiceAdminEvent { + /** + * Add an import registration. The Remote Services Admin will call this + * method when it imports a service. When this service is registered, the + * Remote Service Admin must notify the listener of all existing Import + * Registrations. + * + */ + public static final int IMPORT_REGISTRATION = 1; + + /** + * Add an export registration. The Remote Services Admin will call this + * method when it exports a service. When this service is registered, the + * Remote Service Admin must notify the listener of all existing Export + * Registrations. + */ + public static final int EXPORT_REGISTRATION = 2; + + /** + * Remove an export registration. The Remote Services Admin will call this + * method when it removes the export of a service. + * + */ + public static final int EXPORT_UNREGISTRATION = 3; + + /** + * Remove an import registration. The Remote Services Admin will call this + * method when it removes the import of a service. + * + */ + public static final int IMPORT_UNREGISTRATION = 4; + + /** + * A fatal importing error occurred. The Import Registration has been + * closed. + */ + public static final int IMPORT_ERROR = 5; + + /** + * A fatal exporting error occurred. The Export Registration has been + * closed. + */ + public static final int EXPORT_ERROR = 6; + + /** + * A problematic situation occurred, the export is still active. + */ + public static final int EXPORT_WARNING = 7; + /** + * A problematic situation occurred, the import is still active. + */ + public static final int IMPORT_WARNING = 8; + + private final ImportRegistration importRegistration; + private final ExportRegistration exportRegistration; + private final Throwable exception; + private final int type; + private final Bundle source; + + /** + * Private constructor. + * + * @param type The event type + * @param source The source bundle, must not be <code>null</code>. + * @param importRegistration The importRegistration, can be <code>null</code>. + * @param exportRegistration The exportRegistration, can be <code>null</code>. + * @param exception Any exceptions encountered, can be <code>null</code> + */ + RemoteServiceAdminEvent(int type, + Bundle source, + ImportRegistration importRegistration, + ExportRegistration exportRegistration, + Throwable exception) { + this.type = type; + this.source = source; + this.importRegistration = importRegistration; + this.exportRegistration = exportRegistration; + this.exception = exception; + } + + /** + * Create a Remote Service Admin Event for an export issue. + * + * @param type The event type + * @param source The source bundle, must not be <code>null</code>. + * @param exportRegistration The exportRegistration, can not be <code>null</code>. + * @param exception Any exceptions encountered, can be <code>null</code> + */ + public RemoteServiceAdminEvent(int type, Bundle source, ExportRegistration exportRegistration, Throwable exception) { + this(type, source, null, exportRegistration, exception); + } + + /** + * Create a Remote Service Admin Event for an import issue. + * + * @param type The event type + * @param source The source bundle, must not be <code>null</code>. + * @param importRegistration The importRegistration, can not be <code>null</code>. + * @param exception Any exceptions encountered, can be <code>null</code> + */ + public RemoteServiceAdminEvent(int type, Bundle source, ImportRegistration importRegistration, Throwable exception) { + this(type, source, importRegistration, null, exception); + } + + /** + * @return the importRegistration or <code>null</code> + */ + public ImportRegistration getImportRegistration() { + return importRegistration; + } + + /** + * @return the exportRegistration or <code>null</code> + */ + public ExportRegistration getExportRegistration() { + return exportRegistration; + } + + /** + * @return the exception or <code>null</code> + */ + public Throwable getException() { + return exception; + } + + /** + * @return the type + */ + public int getType() { + return type; + } + + /** + * @return the source + */ + public Bundle getSource() { + return source; + } +} diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteAdminListener.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdminListener.java index 7aa5ae0abe..f653c323c0 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteAdminListener.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/RemoteServiceAdminListener.java @@ -7,9 +7,10 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin; * @ThreadSafe */ -public interface RemoteAdminListener { - /** - * @param event - */ - void remoteAdminEvent( RemoteAdminEvent event); +public interface RemoteServiceAdminListener { + /** + * Receive a Remote Service Admin event. + * @param event + */ + void remoteAdminEvent(RemoteServiceAdminEvent event); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java index e847680fda..a372b62a6c 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointHelper.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin.impl; +import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -30,17 +31,20 @@ import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants; +import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; /** * Implementation of {@link EndpointDescription} */ public class EndpointHelper { + private static final String FRAMEWORK_UUID = UUID.randomUUID().toString(); + private EndpointHelper() { } - public static EndpointDescription createEndpointDescription(Endpoint endpoint) { - return new EndpointDescription(getProperties(endpoint)); + public static EndpointDescription createEndpointDescription(BundleContext bundleContext, Endpoint endpoint) { + return new EndpointDescription(getProperties(bundleContext, endpoint)); } private static List<String> getInterfaces(Endpoint endpoint) { @@ -49,17 +53,32 @@ public class EndpointHelper { return Collections.singletonList(javaInterface.getName()); } - private static Map<String, Object> getProperties(Endpoint endpoint) { + private static Map<String, Object> getProperties(BundleContext bundleContext, Endpoint endpoint) { Map<String, Object> props = new HashMap<String, Object>(); - props.put(RemoteConstants.ENDPOINT_URI, endpoint.getURI()); - props.put(RemoteConstants.ENDPOINT_REMOTE_SERVICE_ID, UUID.randomUUID().toString()); - props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, new String[] {"sca"}); + + String uuid = getFrameworkUUID(bundleContext); + + props.put(RemoteConstants.SERVICE_REMOTE_FRAMEWORK_UUID, uuid); + props.put(RemoteConstants.SERVICE_REMOTE_URI, endpoint.getURI()); + props.put(RemoteConstants.SERVICE_REMOTE_ID, String.valueOf(System.currentTimeMillis())); + props.put(RemoteConstants.SERVICE_EXPORTED_CONFIGS, new String[] {"org.osgi.sca"}); props.put(Endpoint.class.getName(), endpoint); List<String> interfaces = getInterfaces(endpoint); props.put(Constants.OBJECTCLASS, interfaces.toArray(new String[interfaces.size()])); return props; } + public static String getFrameworkUUID(BundleContext bundleContext) { + String uuid = null; + if (bundleContext != null) { + URL url = bundleContext.getBundle(0).getEntry("/"); // bundleentry://0.fwk24942249/ + uuid = url.getHost(); + } else { + uuid = FRAMEWORK_UUID; + } + return uuid; + } + public static Endpoint getEndpoint(EndpointDescription endpointDescription) { return (Endpoint)endpointDescription.getProperties().get(Endpoint.class.getName()); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java index 289c0e22f2..6ce012ba2a 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/EndpointIntrospector.java @@ -60,6 +60,7 @@ import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ContributionFactory; 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.resolver.ExtensibleModelResolver; @@ -76,7 +77,6 @@ import org.apache.tuscany.sca.implementation.osgi.ServiceDescriptionsFactory; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; import org.apache.tuscany.sca.policy.Intent; @@ -102,7 +102,6 @@ public class EndpointIntrospector { private XMLOutputFactory xmlOutputFactory; private JavaInterfaceFactory javaInterfaceFactory; private StAXArtifactProcessor processor; - private Monitor monitor; /** * @param intentName @@ -145,10 +144,7 @@ public class EndpointIntrospector { registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); UtilityExtensionPoint utilities = this.registry.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); - if (monitorFactory != null) { - monitor = monitorFactory.createMonitor(); - } - processor = new ExtensibleStAXArtifactProcessor(processors, xmlInputFactory, xmlOutputFactory, monitor); + processor = new ExtensibleStAXArtifactProcessor(processors, xmlInputFactory, xmlOutputFactory); } private Intent getIntent(String intent) { @@ -285,7 +281,7 @@ public class EndpointIntrospector { contribution.setURI("urn:" + id); contribution.setLocation(bundle.getEntry("/").toString()); contribution.getDeployables().add(composite); - ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories, monitor); + ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories); contribution.setModelResolver(modelResolver); contribution.setUnresolved(true); return contribution; @@ -361,7 +357,7 @@ public class EndpointIntrospector { contribution.setURI("urn:" + id); contribution.setLocation(bundle.getEntry("/").toString()); contribution.getDeployables().add(composite); - ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories, monitor); + ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories); contribution.setModelResolver(modelResolver); contribution.setUnresolved(true); return contribution; @@ -409,7 +405,7 @@ public class EndpointIntrospector { contribution.setURI("urn:" + id); contribution.setLocation(bundle.getEntry("/").toString()); contribution.getDeployables().add(composite); - ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories, monitor); + ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, factories); contribution.setModelResolver(modelResolver); contribution.setUnresolved(true); return contribution; @@ -436,7 +432,7 @@ public class EndpointIntrospector { try { XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is); reader.nextTag(); - Object model = processor.read(reader); + Object model = processor.read(reader, new ProcessorContext(registry)); if (model instanceof BindingDescriptions) { return ((BindingDescriptions)model); } else { diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java index b2260de34d..bfe024e746 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/OSGiServiceExporter.java @@ -95,7 +95,7 @@ public class OSGiServiceExporter implements ServiceTrackerCustomizer, LifeCycleL Component component = contribution.getDeployables().get(0).getComponents().get(0); ComponentService service = component.getServices().get(0); for (Endpoint endpoint : service.getEndpoints()) { - EndpointDescription endpointDescription = createEndpointDescription(endpoint); + EndpointDescription endpointDescription = createEndpointDescription(context, endpoint); ExportRegistration exportRegistration = new ExportRegistrationImpl(node, reference, endpointDescription); exportedServices.add(exportRegistration); diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java index 3c4e0747f9..bc1cf86055 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteControllerImpl.java @@ -20,14 +20,6 @@ package org.apache.tuscany.sca.osgi.service.remoteadmin.impl; import static org.apache.tuscany.sca.implementation.osgi.OSGiProperty.SERVICE_EXPORTED_INTERFACES; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.EXPORT_ERROR; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.EXPORT_REGISTRATION; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.EXPORT_UNREGISTRATION; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.EXPORT_WARNING; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.IMPORT_ERROR; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.IMPORT_REGISTRATION; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.IMPORT_UNREGISTRATION; -import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent.IMPORT_WARNING; import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants.SERVICE_EXPORTED_CONFIGS; import static org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteConstants.SERVICE_IMPORTED; @@ -49,9 +41,9 @@ import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener; import org.apache.tuscany.sca.osgi.service.remoteadmin.ExportRegistration; import org.apache.tuscany.sca.osgi.service.remoteadmin.ImportRegistration; -import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent; -import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminListener; import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin; +import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdminEvent; +import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdminListener; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.Constants; @@ -66,7 +58,7 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; /** * Implementation of Remote Controller */ -public class RemoteControllerImpl implements ListenerHook, RemoteAdminListener, EndpointListener, +public class RemoteControllerImpl implements ListenerHook, RemoteServiceAdminListener, EndpointListener, ServiceTrackerCustomizer, LifeCycleListener /*, EventHook */{ private final static Logger logger = Logger.getLogger(RemoteControllerImpl.class.getName()); public final static String ENDPOINT_LOCAL = "service.local"; @@ -100,7 +92,7 @@ public class RemoteControllerImpl implements ListenerHook, RemoteAdminListener, + SERVICE_EXPORTED_INTERFACES + "=*) (" + SERVICE_EXPORTED_CONFIGS - + "=sca) )"; + + "=org.osgi.sca) )"; try { remotableServiceFilter = context.createFilter(filter); } catch (InvalidSyntaxException e) { @@ -112,7 +104,7 @@ public class RemoteControllerImpl implements ListenerHook, RemoteAdminListener, remoteAdmins.open(); // DO NOT register EventHook.class.getName() as it cannot report existing services - String interfaceNames[] = new String[] {ListenerHook.class.getName(), RemoteAdminListener.class.getName()}; + String interfaceNames[] = new String[] {ListenerHook.class.getName(), RemoteServiceAdminListener.class.getName()}; // The registration will trigger the added() method before registration is assigned registration = context.registerService(interfaceNames, this, null); @@ -185,7 +177,7 @@ public class RemoteControllerImpl implements ListenerHook, RemoteAdminListener, } else { for (Object ra : admins) { RemoteServiceAdmin remoteAdmin = (RemoteServiceAdmin)ra; - List<ExportRegistration> exportRegistrations = remoteAdmin.exportService(reference); + List<ExportRegistration> exportRegistrations = remoteAdmin.exportService(reference, null); if (exportRegistrations != null && !exportRegistrations.isEmpty()) { exportedServices.putValues(reference, exportRegistrations); } @@ -304,17 +296,17 @@ public class RemoteControllerImpl implements ListenerHook, RemoteAdminListener, /** * @see org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminListener#remoteAdminEvent(org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminEvent) */ - public void remoteAdminEvent(RemoteAdminEvent event) { + public void remoteAdminEvent(RemoteServiceAdminEvent event) { switch (event.getType()) { - case EXPORT_ERROR: - case EXPORT_REGISTRATION: - case EXPORT_UNREGISTRATION: - case EXPORT_WARNING: + case RemoteServiceAdminEvent.EXPORT_ERROR: + case RemoteServiceAdminEvent.EXPORT_REGISTRATION: + case RemoteServiceAdminEvent.EXPORT_UNREGISTRATION: + case RemoteServiceAdminEvent.EXPORT_WARNING: break; - case IMPORT_ERROR: - case IMPORT_REGISTRATION: - case IMPORT_UNREGISTRATION: - case IMPORT_WARNING: + case RemoteServiceAdminEvent.IMPORT_ERROR: + case RemoteServiceAdminEvent.IMPORT_REGISTRATION: + case RemoteServiceAdminEvent.IMPORT_UNREGISTRATION: + case RemoteServiceAdminEvent.IMPORT_WARNING: break; } } @@ -323,14 +315,14 @@ public class RemoteControllerImpl implements ListenerHook, RemoteAdminListener, * @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener#addEndpoint(org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription, * java.lang.String) */ - public void addEndpoint(EndpointDescription endpoint, String matchedFilter) { + public void endpointAdded(EndpointDescription endpoint, String matchedFilter) { importService(endpoint, matchedFilter); } /** * @see org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointListener#removeEndpoint(org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription) */ - public void removeEndpoint(EndpointDescription endpoint) { + public void endpointRemoved(EndpointDescription endpoint, String matchedFilter) { unimportService(endpoint); } diff --git a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteServiceAdminImpl.java b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteServiceAdminImpl.java index 1f2c03a5c6..4c92bab569 100644 --- a/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteServiceAdminImpl.java +++ b/java/sca/modules/node-impl-osgi/src/main/java/org/apache/tuscany/sca/osgi/service/remoteadmin/impl/RemoteServiceAdminImpl.java @@ -27,8 +27,8 @@ import java.util.Map; import org.apache.tuscany.sca.osgi.service.remoteadmin.EndpointDescription; import org.apache.tuscany.sca.osgi.service.remoteadmin.ExportRegistration; import org.apache.tuscany.sca.osgi.service.remoteadmin.ImportRegistration; -import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteAdminListener; import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdmin; +import org.apache.tuscany.sca.osgi.service.remoteadmin.RemoteServiceAdminListener; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -59,7 +59,7 @@ public class RemoteServiceAdminImpl implements RemoteServiceAdmin { exporter.start(); importer.start(); registration = context.registerService(RemoteServiceAdmin.class.getName(), this, null); - listeners = new ServiceTracker(this.context, RemoteAdminListener.class.getName(), null); + listeners = new ServiceTracker(this.context, RemoteServiceAdminListener.class.getName(), null); listeners.open(); } diff --git a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/OSGI-INF/remote-service/calculator-service-descriptions.xml b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/OSGI-INF/remote-service/calculator-service-descriptions.xml index da76d00024..0dc812c503 100644 --- a/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/OSGI-INF/remote-service/calculator-service-descriptions.xml +++ b/java/sca/modules/node-impl-osgi/src/test/resources/calculator/dosgi/OSGI-INF/remote-service/calculator-service-descriptions.xml @@ -23,7 +23,7 @@ <service-description> <provide interface="calculator.dosgi.operations.AddService" /> <property name="service.intents">sca:SOAP sca:HTTP</property> - <property name="osgi.remote.configuration.type">sca</property> + <property name="osgi.remote.configuration.type">org.osgi.sca</property> <property name="osgi.remote.configuration.sca.componentType"> OSGI-INF/sca/bundle.componentType </property> @@ -34,7 +34,7 @@ <service-description> <provide interface="calculator.dosgi.operations.SubtractService" /> <property name="service.intents">sca:SOAP sca:HTTP</property> - <property name="osgi.remote.configuration.type">sca</property> + <property name="osgi.remote.configuration.type">org.osgi.sca</property> <property name="osgi.remote.configuration.sca.componentType"> OSGI-INF/sca/bundle.componentType </property> @@ -45,7 +45,7 @@ <service-description> <provide interface="calculator.dosgi.operations.MultiplyService" /> <property name="service.intents">sca:SOAP sca:HTTP</property> - <property name="osgi.remote.configuration.type">sca</property> + <property name="osgi.remote.configuration.type">org.osgi.sca</property> <property name="osgi.remote.configuration.sca.componentType"> OSGI-INF/sca/bundle.componentType </property> @@ -56,7 +56,7 @@ <service-description> <provide interface="calculator.dosgi.operations.DivideService" /> <property name="service.intents">sca:SOAP sca:HTTP</property> - <property name="osgi.remote.configuration.type">sca</property> + <property name="osgi.remote.configuration.type">org.osgi.sca</property> <property name="osgi.remote.configuration.sca.componentType"> OSGI-INF/sca/bundle.componentType </property> diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java index 162670363a..d11eb317cf 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationATOMProcessor.java @@ -31,10 +31,10 @@ 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.monitor.Monitor; import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; import org.apache.tuscany.sca.node.configuration.NodeConfiguration; import org.apache.tuscany.sca.node.configuration.NodeConfigurationFactory; @@ -57,7 +57,7 @@ public class NodeConfigurationATOMProcessor extends BaseStAXArtifactProcessor im private NodeConfigurationFactory factory; - public NodeConfigurationATOMProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public NodeConfigurationATOMProcessor(FactoryExtensionPoint modelFactories) { this.factory = modelFactories.getFactory(NodeConfigurationFactory.class); } @@ -70,7 +70,7 @@ public class NodeConfigurationATOMProcessor extends BaseStAXArtifactProcessor im return NodeConfiguration.class; } - public NodeConfiguration read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public NodeConfiguration read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { NodeConfiguration config = factory.createNodeConfiguration(); @@ -151,10 +151,10 @@ public class NodeConfigurationATOMProcessor extends BaseStAXArtifactProcessor im return config; } - public void resolve(NodeConfiguration implementation, ModelResolver resolver) throws ContributionResolveException { + public void resolve(NodeConfiguration implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } - public void write(NodeConfiguration implementation, XMLStreamWriter writer) throws ContributionWriteException, + public void write(NodeConfiguration implementation, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { } } diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java index 59f4eda9a5..78f4fabb20 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessor.java @@ -35,11 +35,11 @@ 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; import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.node.configuration.BindingConfiguration; import org.apache.tuscany.sca.node.configuration.ContributionConfiguration; import org.apache.tuscany.sca.node.configuration.DeploymentComposite; @@ -68,8 +68,7 @@ public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implem private StAXHelper helper; public NodeConfigurationProcessor(ExtensionPointRegistry registry, - StAXArtifactProcessor processor, - Monitor monitor) { + StAXArtifactProcessor processor) { FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.nodeConfigurationFactory = modelFactories.getFactory(NodeConfigurationFactory.class); this.processor = processor; @@ -86,7 +85,7 @@ public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implem return NodeConfiguration.class; } - public NodeConfiguration read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public NodeConfiguration read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { NodeConfiguration node = null; ContributionConfiguration contribution = null; @@ -148,7 +147,7 @@ public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implem helper.save(reader, writer); composite.setContent(sw.toString()); } else { - node.getExtensions().add(processor.read(reader)); + node.getExtensions().add(processor.read(reader, context)); } break; @@ -174,10 +173,10 @@ public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implem return node; } - public void resolve(NodeConfiguration node, ModelResolver resolver) throws ContributionResolveException { + public void resolve(NodeConfiguration node, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } - public void write(NodeConfiguration node, XMLStreamWriter writer) throws ContributionWriteException, + public void write(NodeConfiguration node, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writeStart(writer, @@ -229,7 +228,7 @@ public class NodeConfigurationProcessor extends BaseStAXArtifactProcessor implem } for(Object o: node.getExtensions()) { - processor.write(o, writer); + processor.write(o, writer, context); } writeEnd(writer); diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java index 6182c5ca2d..92e2cb9254 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java @@ -52,9 +52,9 @@ import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.BuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.DeployedCompositeBuilder; import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.common.xml.stax.StAXHelper; import org.apache.tuscany.sca.contribution.Artifact; @@ -66,6 +66,7 @@ import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.processor.ContributionReadException; import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor; +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.URLArtifactProcessorExtensionPoint; @@ -177,7 +178,7 @@ public class NodeFactoryImpl extends NodeFactory { extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); StAXArtifactProcessor processor = processors.getProcessor(NodeConfiguration.class); reader.nextTag(); - NodeConfiguration config = (NodeConfiguration)processor.read(reader); + NodeConfiguration config = (NodeConfiguration)processor.read(reader, new ProcessorContext(extensionPoints)); xml.close(); if (base != null && config != null) { // Resolve the contribution location against the node.xml @@ -318,13 +319,13 @@ public class NodeFactoryImpl extends NodeFactory { } } - private boolean attachDeploymentComposite(Contribution contribution, Reader xml, String location, boolean attached) + private boolean attachDeploymentComposite(Contribution contribution, Reader xml, String location, boolean attached, ProcessorContext context) throws XMLStreamException, ContributionReadException { XMLStreamReader reader = inputFactory.createXMLStreamReader(xml); reader.nextTag(); // Read the composite model - Composite composite = (Composite)compositeProcessor.read(reader); + Composite composite = (Composite)compositeProcessor.read(reader, context); reader.close(); // Create an artifact for the deployment composite @@ -373,11 +374,11 @@ public class NodeFactoryImpl extends NodeFactory { * @param resolver - the ModelResolver to use * @throws ContributionResolveException */ - private void contributionsPreresolve( List<Contribution> contributions, ModelResolver resolver ) + private void contributionsPreresolve( List<Contribution> contributions, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { for( Contribution contribution : contributions ) { - contributionProcessor.preResolve(contribution, resolver); + contributionProcessor.preResolve(contribution, resolver, context); } // end for } // end method contributionsPreresolve @@ -475,7 +476,7 @@ public class NodeFactoryImpl extends NodeFactory { systemContribution = contributionFactory.createContribution(); systemContribution.setURI("http://tuscany.apache.org/SystemContribution"); systemContribution.setLocation("http://tuscany.apache.org/SystemContribution"); - ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories, monitor); + ModelResolver modelResolver = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories); systemContribution.setModelResolver(modelResolver); systemContribution.setUnresolved(true); @@ -500,11 +501,11 @@ public class NodeFactoryImpl extends NodeFactory { return new DefaultExtensionPointRegistry(); } - protected Composite configureNode(NodeConfiguration configuration, List<Contribution> contributions, Monitor monitor) + protected Composite configureNode(NodeConfiguration configuration, List<Contribution> contributions, ProcessorContext context) throws Throwable { if (contributions == null) { // Load contributions - contributions = loadContributions(configuration, monitor); + contributions = loadContributions(configuration, context); } // Build an aggregated SCA definitions model. Must be done before we try and // resolve any contributions or composites as they may depend on the full @@ -514,6 +515,7 @@ public class NodeFactoryImpl extends NodeFactory { // into the system contribution. In turn add a default import into // each contribution so that for unresolved items the resolution // processing will look in the system contribution + Monitor monitor = context.getMonitor(); for (Contribution contribution: contributions) { monitor.pushContext("Contribution: " + contribution.getURI()); // aggregate definitions @@ -537,16 +539,16 @@ public class NodeFactoryImpl extends NodeFactory { monitor.popContext(); } - ExtensibleModelResolver modelResolver = new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories, monitor); + ExtensibleModelResolver modelResolver = new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories); // now resolve and add the system contribution - contributionProcessor.resolve(systemContribution, modelResolver); + contributionProcessor.resolve(systemContribution, modelResolver, context); contributions.add(systemContribution); // TODO - Now we can calculate applicable policy sets for each composite // pre-resolve the contributions - contributionsPreresolve(contributions, modelResolver); + contributionsPreresolve(contributions, modelResolver, context); // Build the contribution dependencies Set<Contribution> resolved = new HashSet<Contribution>(); @@ -557,7 +559,7 @@ public class NodeFactoryImpl extends NodeFactory { for (Contribution dependency: contribution.getDependencies()) { if (!resolved.contains(dependency)) { resolved.add(dependency); - contributionProcessor.resolve(dependency, modelResolver); + contributionProcessor.resolve(dependency, modelResolver, context); } } } @@ -584,13 +586,14 @@ public class NodeFactoryImpl extends NodeFactory { } // build the top level composite - ((DeployedCompositeBuilder)compositeBuilder).build(domainComposite, systemDefinitions, bindingMap, monitor); + BuilderContext builderContext = new BuilderContext(systemDefinitions, bindingMap, monitor); + compositeBuilder.build(domainComposite, builderContext); analyzeProblems(monitor); return domainComposite; } - protected List<Contribution> loadContributions(NodeConfiguration configuration, Monitor monitor) throws Throwable { + protected List<Contribution> loadContributions(NodeConfiguration configuration, ProcessorContext context) throws Throwable { List<Contribution> contributions = new ArrayList<Contribution>(); // Load the specified contributions @@ -605,14 +608,14 @@ public class NodeFactoryImpl extends NodeFactory { // Load the contribution logger.log(Level.INFO, "Loading contribution: " + contributionURL); - Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL); + Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL, context); contributions.add(contribution); boolean attached = false; for (DeploymentComposite dc : contrib.getDeploymentComposites()) { if (dc.getContent() != null) { Reader xml = new StringReader(dc.getContent()); - attached = attachDeploymentComposite(contribution, xml, null, attached); + attached = attachDeploymentComposite(contribution, xml, null, attached, context); } else if (dc.getLocation() != null) { URI dcURI = createURI(dc.getLocation()); if (!dcURI.isAbsolute()) { @@ -639,11 +642,11 @@ public class NodeFactoryImpl extends NodeFactory { URL url = dcURI.toURL(); InputStream is = openStream(url); Reader xml = new InputStreamReader(is, "UTF-8"); - attached = attachDeploymentComposite(contribution, xml, url.toString(), attached); + attached = attachDeploymentComposite(contribution, xml, url.toString(), attached, context); } } } - analyzeProblems(monitor); + analyzeProblems(context.getMonitor()); } return contributions; } diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java index ab63c80b67..768d5a63d7 100644 --- a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -39,6 +39,7 @@ import org.apache.tuscany.sca.common.java.io.IOHelper; import org.apache.tuscany.sca.context.CompositeContext; import org.apache.tuscany.sca.context.ThreadMessageContext; import org.apache.tuscany.sca.contribution.Contribution; +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.ExtensionPointRegistry; @@ -125,10 +126,12 @@ public class NodeImpl implements Node, Client { Monitor monitor = manager.monitorFactory.createMonitor(); monitor.reset(); + ProcessorContext context = new ProcessorContext(monitor); + if (contributions == null) { - contributions = manager.loadContributions(configuration, monitor); + contributions = manager.loadContributions(configuration, context); } - domainComposite = manager.configureNode(configuration, contributions, monitor); + domainComposite = manager.configureNode(configuration, contributions, context); this.compositeContext = new CompositeContextImpl(manager.extensionPoints, endpointRegistry, domainComposite); @@ -334,7 +337,7 @@ public class NodeImpl implements Node, Client { .getFactory(XMLOutputFactory.class); try { - compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos)); + compositeProcessor.write(composite, outputFactory.createXMLStreamWriter(bos), new ProcessorContext(manager.extensionPoints)); } catch(Exception ex) { return ex.toString(); } diff --git a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java index ff0144db99..a10f2cccd4 100644 --- a/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java +++ b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/configuration/xml/NodeConfigurationProcessorTestCase.java @@ -27,6 +27,7 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +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; @@ -45,12 +46,13 @@ public class NodeConfigurationProcessorTestCase { private static FactoryExtensionPoint factories; private static StAXArtifactProcessor processor; - /** - * @throws java.lang.Exception - */ + private static ProcessorContext context; + @BeforeClass - public static void setUpBeforeClass() throws Exception { + public static void setUp() throws Exception { ExtensionPointRegistry registry = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(registry); + factories = new DefaultFactoryExtensionPoint(registry); StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); @@ -64,12 +66,12 @@ public class NodeConfigurationProcessorTestCase { XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(is); is.close(); reader.nextTag(); - NodeConfiguration config = (NodeConfiguration) processor.read(reader); + NodeConfiguration config = (NodeConfiguration) processor.read(reader, context); StringWriter sw = new StringWriter(); XMLOutputFactory xmlOutputFactory = factories.getFactory(XMLOutputFactory.class); xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); XMLStreamWriter writer = xmlOutputFactory.createXMLStreamWriter(sw); - processor.write(config, writer); + processor.write(config, writer, context); writer.flush(); System.out.println(sw.toString()); } diff --git a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyBuilder.java b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyBuilder.java index 8560b41f57..be9a05982f 100644 --- a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyBuilder.java +++ b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyBuilder.java @@ -28,9 +28,8 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.builder.BuilderContext; import org.apache.tuscany.sca.assembly.builder.PolicyBuilder; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.PolicyExpression; import org.apache.tuscany.sca.policy.PolicySet; import org.apache.tuscany.sca.policy.PolicySubject; @@ -40,17 +39,17 @@ import org.apache.tuscany.sca.policy.PolicySubject; */ public class JDKLoggingPolicyBuilder implements PolicyBuilder<JDKLoggingPolicy> { - public void build(Endpoint endpoint, Definitions definitions, Monitor monitor) { + public void build(Endpoint endpoint, BuilderContext context) { List<JDKLoggingPolicy> polices = getPolicies(endpoint); System.out.println(endpoint + ": " + polices); } - public void build(EndpointReference endpointReference, Definitions definitions, Monitor monitor) { + public void build(EndpointReference endpointReference, BuilderContext context) { List<JDKLoggingPolicy> polices = getPolicies(endpointReference); System.out.println(endpointReference + ": " + polices); } - public void build(Component component, Implementation implementation, Definitions definitions, Monitor monitor) { + public void build(Component component, Implementation implementation, BuilderContext context) { List<JDKLoggingPolicy> polices = getPolicies(implementation); System.out.println(implementation + ": " + polices); } diff --git a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java index 0254da7620..6ca5732e7a 100644 --- a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java +++ b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyProcessor.java @@ -31,10 +31,10 @@ 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.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * @@ -50,11 +50,11 @@ public class JDKLoggingPolicyProcessor implements StAXArtifactProcessor<JDKLoggi return JDK_LOGGING_POLICY_QNAME; } - public JDKLoggingPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public JDKLoggingPolicyProcessor(FactoryExtensionPoint modelFactories) { } - public JDKLoggingPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JDKLoggingPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { JDKLoggingPolicy policy = new JDKLoggingPolicy(); int event = reader.getEventType(); QName name = null; @@ -94,7 +94,7 @@ public class JDKLoggingPolicyProcessor implements StAXArtifactProcessor<JDKLoggi return policy; } - public void write(JDKLoggingPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + public void write(JDKLoggingPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -128,7 +128,7 @@ public class JDKLoggingPolicyProcessor implements StAXArtifactProcessor<JDKLoggi return JDKLoggingPolicy.class; } - public void resolve(JDKLoggingPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(JDKLoggingPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/policy-logging/src/test/java/org/apache/tuscany/sca/policy/logging/jdk/PolicyReadTestCase.java b/java/sca/modules/policy-logging/src/test/java/org/apache/tuscany/sca/policy/logging/jdk/PolicyReadTestCase.java index d5b1b9eedc..0000ec8c06 100644 --- a/java/sca/modules/policy-logging/src/test/java/org/apache/tuscany/sca/policy/logging/jdk/PolicyReadTestCase.java +++ b/java/sca/modules/policy-logging/src/test/java/org/apache/tuscany/sca/policy/logging/jdk/PolicyReadTestCase.java @@ -32,13 +32,16 @@ import javax.xml.stream.XMLStreamWriter; import junit.framework.TestCase; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; + /** * Test the reading of ws config params policy. * * @version $Rev$ $Date$ */ public class PolicyReadTestCase extends TestCase { - + private ProcessorContext context = new ProcessorContext(); + @Override public void setUp() throws Exception { } @@ -48,7 +51,7 @@ public class PolicyReadTestCase extends TestCase { } public void testPolicyReading() throws Exception { - JDKLoggingPolicyProcessor processor = new JDKLoggingPolicyProcessor(null, null); + JDKLoggingPolicyProcessor processor = new JDKLoggingPolicyProcessor(null); URL url = getClass().getResource("mock_policies.xml"); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); @@ -57,14 +60,14 @@ public class PolicyReadTestCase extends TestCase { XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); - JDKLoggingPolicy policy = processor.read(reader); + JDKLoggingPolicy policy = processor.read(reader, context); assertEquals(policy.getLoggerName(), "test.logger"); assertEquals(policy.getLogLevel(), Level.INFO ); assertEquals(policy.getResourceBundleName(), "Trace_Messages.properties"); } public void testPolicyWriting() throws Exception { - JDKLoggingPolicyProcessor processor = new JDKLoggingPolicyProcessor(null, null); + JDKLoggingPolicyProcessor processor = new JDKLoggingPolicyProcessor(null); JDKLoggingPolicy policy = new JDKLoggingPolicy(); policy.setLoggerName("test.logger"); @@ -74,14 +77,14 @@ public class PolicyReadTestCase extends TestCase { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter sw = new StringWriter(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw); - processor.write(policy, writer); + processor.write(policy, writer, context); writer.close(); XMLInputFactory inputFactory = XMLInputFactory.newInstance(); StringReader sr = new StringReader(sw.toString()); XMLStreamReader reader = inputFactory.createXMLStreamReader(sr); - policy = processor.read(reader); + policy = processor.read(reader, context); assertEquals(policy.getLoggerName(), "test.logger"); assertEquals(policy.getLogLevel(), Level.INFO ); assertEquals(policy.getResourceBundleName(), "Trace_Messages.properties"); diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java index 99a8508ba4..3df06c1e00 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authentication/basic/BasicAuthenticationPolicyProcessor.java @@ -29,10 +29,10 @@ 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.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; /** * @@ -45,11 +45,11 @@ public class BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor return BasicAuthenticationPolicy.BASIC_AUTHENTICATION_POLICY_QNAME; } - public BasicAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public BasicAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories) { } - public BasicAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public BasicAuthenticationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { BasicAuthenticationPolicy policy = new BasicAuthenticationPolicy(); int event = reader.getEventType(); QName name = null; @@ -85,7 +85,7 @@ public class BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor return policy; } - public void write(BasicAuthenticationPolicy policy, XMLStreamWriter writer) + public void write(BasicAuthenticationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -116,7 +116,7 @@ public class BasicAuthenticationPolicyProcessor implements StAXArtifactProcessor return BasicAuthenticationPolicy.class; } - public void resolve(BasicAuthenticationPolicy arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(BasicAuthenticationPolicy arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java index d78c0fc2e3..8a65a10560 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/authorization/AuthorizationPolicyProcessor.java @@ -31,6 +31,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.core.FactoryExtensionPoint; @@ -44,14 +45,12 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<AuthorizationPolicy> { private static final String ROLES = "roles"; - private Monitor monitor; public QName getArtifactType() { return AuthorizationPolicy.NAME; } - public AuthorizationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public AuthorizationPolicyProcessor(FactoryExtensionPoint modelFactories) { } /** @@ -61,14 +60,14 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho * @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(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } } - public AuthorizationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public AuthorizationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { AuthorizationPolicy policy = new AuthorizationPolicy(); int event = reader.getEventType(); QName start = reader.getName(); @@ -80,7 +79,7 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho policy.setAccessControl(AuthorizationPolicy.AcessControl.allow); String roleNames = reader.getAttributeValue(null, ROLES); if (roleNames == null) { - error("RequiredAttributeRolesMissing", reader); + error(context.getMonitor(), "RequiredAttributeRolesMissing", reader); //throw new IllegalArgumentException("Required attribute 'roles' is missing."); } else { StringTokenizer st = new StringTokenizer(roleNames); @@ -111,7 +110,7 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho } } - public void write(AuthorizationPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + public void write(AuthorizationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeStartElement(AuthorizationPolicy.NAME.getLocalPart()); @@ -136,7 +135,7 @@ public class AuthorizationPolicyProcessor implements StAXArtifactProcessor<Autho return AuthorizationPolicy.class; } - public void resolve(AuthorizationPolicy policy, ModelResolver resolver) throws ContributionResolveException { + public void resolve(AuthorizationPolicy policy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if ((policy.getAccessControl() == AuthorizationPolicy.AcessControl.allow) && (policy.getRoleNames().isEmpty())){ diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java index 0ccda91364..3c91b9fbcf 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/identity/SecurityIdentityPolicyProcessor.java @@ -29,6 +29,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.core.FactoryExtensionPoint; @@ -42,14 +43,12 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<SecurityIdentityPolicy> { private static final String ROLE = "role"; - private Monitor monitor; public QName getArtifactType() { return SecurityIdentityPolicy.NAME; } - public SecurityIdentityPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public SecurityIdentityPolicyProcessor(FactoryExtensionPoint modelFactories) { } /** @@ -59,14 +58,14 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se * @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(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } } - public SecurityIdentityPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public SecurityIdentityPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { SecurityIdentityPolicy policy = new SecurityIdentityPolicy(); int event = reader.getEventType(); QName start = reader.getName(); @@ -77,7 +76,7 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se if ("runAs".equals(ac)) { String roleName = reader.getAttributeValue(null, ROLE); if (roleName == null) { - error("RequiredAttributeRolesMissing", reader); + error(context.getMonitor(), "RequiredAttributeRolesMissing", reader); //throw new IllegalArgumentException("Required attribute 'roles' is missing."); } else { policy.setRunAsRole(roleName); @@ -103,7 +102,7 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se } } - public void write(SecurityIdentityPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + public void write(SecurityIdentityPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { writer.writeStartElement(SecurityIdentityPolicy.NAME.getLocalPart()); @@ -122,7 +121,7 @@ public class SecurityIdentityPolicyProcessor implements StAXArtifactProcessor<Se return SecurityIdentityPolicy.class; } - public void resolve(SecurityIdentityPolicy policy, ModelResolver resolver) throws ContributionResolveException { + public void resolve(SecurityIdentityPolicy policy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (policy.getRunAsRole() != null) //right now nothing to resolve diff --git a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java index 615e8bf5a3..b9ab68aa2f 100644 --- a/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java +++ b/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/jaas/JaasAuthenticationPolicyProcessor.java @@ -29,6 +29,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.ClassReference; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -47,14 +48,13 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< private static final String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; public static final QName CALLBACK_HANDLER_QNAME = new QName(SCA10_TUSCANY_NS, callbackHandler); public static final QName CONFIGURATION_QNAME = new QName(SCA10_TUSCANY_NS, "configurationName"); - private Monitor monitor; + public QName getArtifactType() { return JAAS_AUTHENTICATION_POLICY_QNAME; } - public JaasAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - this.monitor = monitor; + public JaasAuthenticationPolicyProcessor(FactoryExtensionPoint modelFactories) { } /** @@ -64,14 +64,14 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< * @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(), "policy-security-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); monitor.problem(problem); } } - public JaasAuthenticationPolicy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public JaasAuthenticationPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { JaasAuthenticationPolicy policy = new JaasAuthenticationPolicy(); int event = reader.getEventType(); QName name = null; @@ -113,7 +113,7 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< return policy; } - public void write(JaasAuthenticationPolicy policy, XMLStreamWriter writer) throws ContributionWriteException, + public void write(JaasAuthenticationPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { String prefix = "tuscany"; writer.writeStartElement(prefix, @@ -129,14 +129,14 @@ public class JaasAuthenticationPolicyProcessor implements StAXArtifactProcessor< return JaasAuthenticationPolicy.class; } - public void resolve(JaasAuthenticationPolicy policy, ModelResolver resolver) throws ContributionResolveException { + public void resolve(JaasAuthenticationPolicy policy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (policy.getCallbackHandlerClassName() != null) { ClassReference classReference = new ClassReference(policy.getCallbackHandlerClassName()); - classReference = resolver.resolveModel(ClassReference.class, classReference); + classReference = resolver.resolveModel(ClassReference.class, classReference, context); Class<?> callbackClass = classReference.getJavaClass(); if (callbackClass == null) { - error("ClassNotFoundException", resolver, policy.getCallbackHandlerClassName()); + error(context.getMonitor(), "ClassNotFoundException", resolver, policy.getCallbackHandlerClassName()); //throw new ContributionResolveException(new ClassNotFoundException(policy.getCallbackHandlerClassName())); } else { policy.setCallbackHandlerClass(callbackClass); diff --git a/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java b/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java index a1b790dbb4..0d8a5d5a9c 100644 --- a/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java +++ b/java/sca/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/PolicyProcessorTestCase.java @@ -31,6 +31,7 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamReader; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.policy.authorization.AuthorizationPolicy; import org.apache.tuscany.sca.policy.authorization.AuthorizationPolicyProcessor; @@ -59,12 +60,12 @@ public class PolicyProcessorTestCase { public void testRead() throws Exception { List<String> results = new ArrayList<String>(); Map<QName, StAXArtifactProcessor> processors = new HashMap<QName, StAXArtifactProcessor>(); - processors.put(AuthorizationPolicy.NAME, new AuthorizationPolicyProcessor(null,null)); - processors.put(SecurityIdentityPolicy.NAME, new SecurityIdentityPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "allow"), new AuthorizationPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "permitAll"), new AuthorizationPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "denyAll"), new AuthorizationPolicyProcessor(null,null)); - processors.put(new QName(SCA11_NS, "runAs"), new SecurityIdentityPolicyProcessor(null,null)); + processors.put(AuthorizationPolicy.NAME, new AuthorizationPolicyProcessor(null)); + processors.put(SecurityIdentityPolicy.NAME, new SecurityIdentityPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "allow"), new AuthorizationPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "permitAll"), new AuthorizationPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "denyAll"), new AuthorizationPolicyProcessor(null)); + processors.put(new QName(SCA11_NS, "runAs"), new SecurityIdentityPolicyProcessor(null)); InputStream is = getClass().getResourceAsStream("mock_policy_definitions.xml"); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader reader = factory.createXMLStreamReader(is); @@ -73,7 +74,7 @@ public class PolicyProcessorTestCase { if (event == XMLStreamConstants.START_ELEMENT) { if ("policySet".equals(reader.getName().getLocalPart())) { reader.nextTag(); - results.add(processors.get(reader.getName()).read(reader).toString()); + results.add(processors.get(reader.getName()).read(reader, new ProcessorContext()).toString()); } } if (reader.hasNext()) { diff --git a/java/sca/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java b/java/sca/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java index 96b5b5d713..760ce7c8da 100644 --- a/java/sca/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java +++ b/java/sca/modules/policy-xml-ws/src/main/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessor.java @@ -36,10 +36,10 @@ 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.monitor.Monitor; /** @@ -56,7 +56,7 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements StAX public WSPolicyProcessor() { } - public WSPolicyProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { + public WSPolicyProcessor(FactoryExtensionPoint modelFactories) { } public QName getArtifactType() { @@ -67,7 +67,7 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements StAX return org.apache.neethi.Policy.class; } - public org.apache.neethi.Policy read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + public org.apache.neethi.Policy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { org.apache.neethi.Policy wsPolicy = null; int event = reader.getEventType(); @@ -81,7 +81,7 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements StAX return wsPolicy; } - public void write(org.apache.neethi.Policy wsPolicy, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + public void write(org.apache.neethi.Policy wsPolicy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { // Write an <sca:policySet> writer.writeStartElement(WS_POLICY_NS, WS_POLICY); @@ -91,7 +91,7 @@ public class WSPolicyProcessor extends BaseStAXArtifactProcessor implements StAX writer.writeEndElement(); } - public void resolve(org.apache.neethi.Policy wsPolicy, ModelResolver resolver) throws ContributionResolveException { + public void resolve(org.apache.neethi.Policy wsPolicy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestModelResolver.java b/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestModelResolver.java index 57e3fe8d3a..8e904615c8 100644 --- a/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestModelResolver.java +++ b/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestModelResolver.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.policy.xml.ws; import java.util.HashMap; import java.util.Map; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; @@ -38,7 +39,7 @@ public class TestModelResolver implements ModelResolver { public TestModelResolver() { } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { Object resolved = map.get(unresolved); if (resolved != null) { @@ -52,11 +53,11 @@ public class TestModelResolver implements ModelResolver { } } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { map.put(resolved, resolved); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { return map.remove(resolved); } diff --git a/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestPolicyProcessor.java b/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestPolicyProcessor.java index 12a90f5c37..954ae00d42 100644 --- a/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/TestPolicyProcessor.java +++ b/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/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,11 +40,11 @@ public class TestPolicyProcessor implements StAXArtifactProcessor<Object> { return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment"); } - public Object read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException { + public Object read(XMLStreamReader arg0, ProcessorContext context) throws ContributionReadException, XMLStreamException { return new MockPolicyImplOne(); } - public void write(Object arg0, XMLStreamWriter arg1) throws ContributionWriteException, + public void write(Object arg0, XMLStreamWriter arg1, ProcessorContext context) throws ContributionWriteException, XMLStreamException { } @@ -52,7 +53,7 @@ public class TestPolicyProcessor implements StAXArtifactProcessor<Object> { return Object.class; } - public void resolve(Object arg0, ModelResolver arg1) throws ContributionResolveException { + public void resolve(Object arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException { } diff --git a/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessorTestCase.java b/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessorTestCase.java index 907a50984c..47cf0e5c2f 100644 --- a/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessorTestCase.java +++ b/java/sca/modules/policy-xml-ws/src/test/java/org/apache/tuscany/sca/policy/xml/ws/WSPolicyProcessorTestCase.java @@ -27,10 +27,10 @@ import javax.xml.namespace.QName; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamReader; -import org.apache.tuscany.sca.policy.xml.ws.WSPolicyProcessor; - import junit.framework.TestCase; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; + /** * Test reading SCA XML assembly documents. * @@ -93,7 +93,7 @@ public class WSPolicyProcessorTestCase extends TestCase { name = reader.getName(); if(WSPolicyProcessor.WS_POLICY_QNAME.equals(name)) { - artifact = processor.read(reader); + artifact = processor.read(reader, new ProcessorContext()); } break; diff --git a/java/sca/modules/scdl/src/main/java/org/apache/tuscany/sca/scdl/SCDLUtils.java b/java/sca/modules/scdl/src/main/java/org/apache/tuscany/sca/scdl/SCDLUtils.java index c2b0785cab..2f2fb04fb3 100644 --- a/java/sca/modules/scdl/src/main/java/org/apache/tuscany/sca/scdl/SCDLUtils.java +++ b/java/sca/modules/scdl/src/main/java/org/apache/tuscany/sca/scdl/SCDLUtils.java @@ -51,6 +51,7 @@ import org.apache.tuscany.sca.contribution.processor.ContributionResolveExceptio import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.contribution.processor.ExtendedURLArtifactProcessor;
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.URLArtifactProcessorExtensionPoint;
@@ -59,6 +60,7 @@ import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.definitions.Definitions;
@@ -71,53 +73,61 @@ import org.apache.tuscany.sca.monitor.Problem; public class SCDLUtils {
-// private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
+ // private static final String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1";
public static Composite readComposite(InputStream is) throws XMLStreamException, ContributionReadException {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ ProcessorContext context = new ProcessorContext(extensionPoints);
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
Monitor monitor = monitorFactory.createMonitor();
- StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
- StAXArtifactProcessor<Object> staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ StAXArtifactProcessor<Object> staxProcessor =
+ new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null);
XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
- Composite composite = (Composite)staxProcessor.read(reader);
-
+ Composite composite = (Composite)staxProcessor.read(reader, context);
+
List<Problem> ps = monitor.getProblems();
if (ps.size() > 0) {
throw new ContributionReadException(ps.get(0).toString());
}
-
+
return composite;
}
public static Contribution readContribution(String location) throws Exception {
-
+
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ ProcessorContext context = new ProcessorContext(extensionPoints);
extensionPoints.start();
-
+
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
Monitor monitor = monitorFactory.createMonitor();
- URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- ExtendedURLArtifactProcessor<Contribution> contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class);
-
+ URLArtifactProcessorExtensionPoint docProcessorExtensions =
+ extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ ExtendedURLArtifactProcessor<Contribution> contributionProcessor =
+ (ExtendedURLArtifactProcessor<Contribution>)docProcessorExtensions.getProcessor(Contribution.class);
+
File f = new File(location);
List<Contribution> contributions = new ArrayList<Contribution>();
- contributions.add(contributionProcessor.read(null, f.toURI(), f.toURI().toURL()));
+ contributions.add(contributionProcessor.read(null, f.toURI(), f.toURI().toURL(), context));
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
-// AssemblyFactory assemblyFactory = new RuntimeAssemblyFactory(extensionPoints);
-// modelFactories.addFactory(assemblyFactory);
+ // AssemblyFactory assemblyFactory = new RuntimeAssemblyFactory(extensionPoints);
+ // modelFactories.addFactory(assemblyFactory);
monitor = monitorFactory.createMonitor();
ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
- contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class);
+ contributionProcessor =
+ (ExtendedURLArtifactProcessor<Contribution>)docProcessorExtensions.getProcessor(Contribution.class);
- ModelResolverExtensionPoint modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
+ ModelResolverExtensionPoint modelResolvers =
+ extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
DefinitionsFactory definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class);
Definitions systemDefinitions = definitionsFactory.createDefinitions();
@@ -127,7 +137,8 @@ public class SCDLUtils { Contribution systemContribution = contributionFactory.createContribution();
systemContribution.setURI("http://tuscany.apache.org/SystemContribution");
systemContribution.setLocation("http://tuscany.apache.org/SystemContribution");
- ModelResolver modelResolverSys = new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories, monitor);
+ ModelResolver modelResolverSys =
+ new ExtensibleModelResolver(systemContribution, modelResolvers, modelFactories);
systemContribution.setModelResolver(modelResolverSys);
systemContribution.setUnresolved(true);
@@ -145,17 +156,18 @@ public class SCDLUtils { // definitions.xml picture
monitor.pushContext("Extension points definitions");
- DefinitionsExtensionPoint definitionsExtensionPoint = extensionPoints.getExtensionPoint(DefinitionsExtensionPoint.class);
- for(Definitions defs: definitionsExtensionPoint.getDefinitions()) {
+ DefinitionsExtensionPoint definitionsExtensionPoint =
+ extensionPoints.getExtensionPoint(DefinitionsExtensionPoint.class);
+ for (Definitions defs : definitionsExtensionPoint.getDefinitions()) {
DefinitionsUtil.aggregate(defs, systemDefinitions, monitor);
}
monitor.popContext();
-
+
// get all definitions.xml artifacts from contributions and aggregate
// into the system contribution. In turn add a default import into
// each contribution so that for unresolved items the resolution
// processing will look in the system contribution
- for (Contribution contribution: contributions) {
+ for (Contribution contribution : contributions) {
monitor.pushContext("Contribution: " + contribution.getURI());
// aggregate definitions
for (Artifact artifact : contribution.getArtifacts()) {
@@ -177,79 +189,81 @@ public class SCDLUtils { monitor.popContext();
}
- ExtensibleModelResolver modelResolver = new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories, monitor);
+ ExtensibleModelResolver modelResolver =
+ new ExtensibleModelResolver(new Contributions(contributions), modelResolvers, modelFactories);
- contributionProcessor.resolve(systemContribution, modelResolver);
+ contributionProcessor.resolve(systemContribution, modelResolver, context);
contributions.add(systemContribution);
// TODO - Now we can calculate applicable policy sets for each composite
// pre-resolve the contributions
- contributionsPreresolve(contributionProcessor, contributions, modelResolver);
+ contributionsPreresolve(contributionProcessor, contributions, modelResolver, context);
// Build the contribution dependencies
Set<Contribution> resolved = new HashSet<Contribution>();
- for (Contribution contribution: contributions) {
+ for (Contribution contribution : contributions) {
buildDependencies(contribution, contributions, monitor);
// Resolve contributions
- for (Contribution dependency: contribution.getDependencies()) {
+ for (Contribution dependency : contribution.getDependencies()) {
if (!resolved.contains(dependency)) {
resolved.add(dependency);
- contributionProcessor.resolve(dependency, modelResolver);
+ contributionProcessor.resolve(dependency, modelResolver, context);
}
}
}
-// // Create a top level composite to host our composite
-// // This is temporary to make the activator happy
-// AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
-//// AssemblyFactory assemblyFactory = new RuntimeAssemblyFactory(extensionPoints);
-//// modelFactories.addFactory(assemblyFactory);
-// Composite tempComposite = assemblyFactory.createComposite();
-// tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite"));
-// tempComposite.setURI(SCA11_TUSCANY_NS);
-//
-// for (Contribution contribution : contributions) {
-// for (Composite composite : contribution.getDeployables()) {
-// // Include the node composite in the top-level composite
-// tempComposite.getIncludes().add(composite);
-// }
-// }
-//
-//
-// CompositeActivator compositeActivator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(CompositeActivator.class);
-//
-// // get the top level composite for this node
-// compositeActivator.setDomainComposite(tempComposite);
-//
-// // Activate the composite
-// compositeActivator.activate(compositeActivator.getDomainComposite());
-//
-// // Start the composite
-// compositeActivator.start(compositeActivator.getDomainComposite());
-//
-//
-//// // TODO - EPR - create a binding map to pass down into the builders
-//// // for use during URI calculation.
-//// Map<QName, List<String>> bindingMap = new HashMap<QName, List<String>>();
-//// for (BindingConfiguration config : configuration.getBindings()) {
-//// bindingMap.put(config.getBindingType(), config.getBaseURIs());
-//// }
-//
-// CompositeBuilderExtensionPoint compositeBuilders = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class);
-// CompositeBuilder compositeBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
-// ((CompositeBuilderTmp)compositeBuilder).build(tempComposite, systemDefinitions, new HashMap<QName, List<String>>(), monitor);
-//// analyzeProblems();
-//
-//// endpointReferenceBuilder.buildtimeBuild(tempComposite);
-//// analyzeProblems();
-//
-//// return tempComposite;
-//// Composite xxx = configureNode(extensionPoints, cs, monitor);
- return contributions.get(0);
+ // // Create a top level composite to host our composite
+ // // This is temporary to make the activator happy
+ // AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ //// AssemblyFactory assemblyFactory = new RuntimeAssemblyFactory(extensionPoints);
+ //// modelFactories.addFactory(assemblyFactory);
+ // Composite tempComposite = assemblyFactory.createComposite();
+ // tempComposite.setName(new QName(SCA11_TUSCANY_NS, "_tempComposite"));
+ // tempComposite.setURI(SCA11_TUSCANY_NS);
+ //
+ // for (Contribution contribution : contributions) {
+ // for (Composite composite : contribution.getDeployables()) {
+ // // Include the node composite in the top-level composite
+ // tempComposite.getIncludes().add(composite);
+ // }
+ // }
+ //
+ //
+ // CompositeActivator compositeActivator = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class).getUtility(CompositeActivator.class);
+ //
+ // // get the top level composite for this node
+ // compositeActivator.setDomainComposite(tempComposite);
+ //
+ // // Activate the composite
+ // compositeActivator.activate(compositeActivator.getDomainComposite());
+ //
+ // // Start the composite
+ // compositeActivator.start(compositeActivator.getDomainComposite());
+ //
+ //
+ //// // TODO - EPR - create a binding map to pass down into the builders
+ //// // for use during URI calculation.
+ //// Map<QName, List<String>> bindingMap = new HashMap<QName, List<String>>();
+ //// for (BindingConfiguration config : configuration.getBindings()) {
+ //// bindingMap.put(config.getBindingType(), config.getBaseURIs());
+ //// }
+ //
+ // CompositeBuilderExtensionPoint compositeBuilders = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class);
+ // CompositeBuilder compositeBuilder = compositeBuilders.getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
+ // ((CompositeBuilderTmp)compositeBuilder).build(tempComposite, systemDefinitions, new HashMap<QName, List<String>>(), monitor);
+ //// analyzeProblems();
+ //
+ //// endpointReferenceBuilder.buildtimeBuild(tempComposite);
+ //// analyzeProblems();
+ //
+ //// return tempComposite;
+ //// Composite xxx = configureNode(extensionPoints, cs, monitor);
+ return contributions.get(0);
+
+ }
-}
/**
* Pre-resolve phase for contributions, to set up handling of imports and exports prior to full resolution
* @param contributionProcessor
@@ -257,11 +271,13 @@ public class SCDLUtils { * @param resolver - the ModelResolver to use
* @throws ContributionResolveException
*/
- private static void contributionsPreresolve( ExtendedURLArtifactProcessor<Contribution> contributionProcessor, List<Contribution> contributions, ModelResolver resolver )
- throws ContributionResolveException {
+ private static void contributionsPreresolve(ExtendedURLArtifactProcessor<Contribution> contributionProcessor,
+ List<Contribution> contributions,
+ ModelResolver resolver,
+ ProcessorContext context) throws ContributionResolveException {
- for( Contribution contribution : contributions ) {
- contributionProcessor.preResolve(contribution, resolver);
+ for (Contribution contribution : contributions) {
+ contributionProcessor.preResolve(contribution, resolver, context);
} // end for
} // end method contributionsPreresolve
@@ -279,23 +295,28 @@ public class SCDLUtils { contribution.getDependencies().addAll(dependencies);
}
+
/**
* Analyze a contribution and add its dependencies to the given dependency set.
*/
- private static void addContributionDependencies(Contribution contribution, List<Contribution> contributions, List<Contribution> dependencies, Set<Contribution> set, Monitor monitor) {
+ private static void addContributionDependencies(Contribution contribution,
+ List<Contribution> contributions,
+ List<Contribution> dependencies,
+ Set<Contribution> set,
+ Monitor monitor) {
// Go through the contribution imports
- for (Import import_: contribution.getImports()) {
+ for (Import import_ : contribution.getImports()) {
boolean resolved = false;
// Go through all contribution candidates and their exports
List<Export> matchingExports = new ArrayList<Export>();
- for (Contribution dependency: contributions) {
+ for (Contribution dependency : contributions) {
if (dependency == contribution) {
// Do not self import
continue;
}
- for (Export export: dependency.getExports()) {
+ for (Export export : dependency.getExports()) {
// If an export from a contribution matches the import in hand
// add that contribution to the dependency set
@@ -322,16 +343,17 @@ public class SCDLUtils { } else {
// Record import resolution issue
if (!(import_ instanceof DefaultImport)) {
- // Add the (empty) matchingExports List and report a warning
- import_.setModelResolver(new DefaultImportModelResolver(matchingExports));
-// warning(monitor, "UnresolvedImport", import_, import_);
+ // Add the (empty) matchingExports List and report a warning
+ import_.setModelResolver(new DefaultImportModelResolver(matchingExports));
+ // warning(monitor, "UnresolvedImport", import_, import_);
}
} // end if
}
}
-
- private static List<Contribution> loadContributions(DefaultExtensionPointRegistry extensionPoints, String s) throws MalformedURLException, ContributionReadException, XMLStreamException, IOException, UnsupportedEncodingException, Exception {
+ private static List<Contribution> loadContributions(ExtensionPointRegistry extensionPoints, String s, ProcessorContext context)
+ throws MalformedURLException, ContributionReadException, XMLStreamException, IOException,
+ UnsupportedEncodingException, Exception {
List<Contribution> contributions = new ArrayList<Contribution>();
URI contributionURI = createURI(s);
@@ -342,68 +364,77 @@ public class SCDLUtils { }
URL contributionURL = uri.toURL();
- URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
- ExtendedURLArtifactProcessor<Contribution> contributionProcessor = (ExtendedURLArtifactProcessor<Contribution>) docProcessorExtensions.getProcessor(Contribution.class);
-
- // Load the contribution
- Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL);
- contributions.add(contribution);
-
- boolean attached = false;
-// for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
-// if (dc.getContent() != null) {
-// Reader xml = new StringReader(dc.getContent());
-// attached = attachDeploymentComposite(extensionPoints, contribution, xml, null, attached);
-// } else if (dc.getLocation() != null) {
-// URI dcURI = createURI(dc.getLocation());
-// if (!dcURI.isAbsolute()) {
-// Composite composite = null;
-// // The location is pointing to an artifact within the contribution
-// for (Artifact a : contribution.getArtifacts()) {
-// if (dcURI.toString().equals(a.getURI())) {
-// composite = (Composite)a.getModel();
-// if (!attached) {
-// contribution.getDeployables().clear();
-// attached = true;
-// }
-// contribution.getDeployables().add(composite);
-// break;
-// }
-// }
-// if (composite == null) {
-// // Not found
-// throw new ServiceRuntimeException("Deployment composite " + dcURI
-// + " cannot be found within contribution "
-// + contribution.getLocation());
-// }
-// } else {
-// URL url = dcURI.toURL();
-// InputStream is = openStream(url);
-// Reader xml = new InputStreamReader(is, "UTF-8");
-// attached = attachDeploymentComposite(extensionPoints, contribution, xml, url.toString(), attached);
-// }
-// }
-//// analyzeProblems();
-// }
- return contributions;
-}
+ URLArtifactProcessorExtensionPoint docProcessorExtensions =
+ extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ ExtendedURLArtifactProcessor<Contribution> contributionProcessor =
+ (ExtendedURLArtifactProcessor<Contribution>)docProcessorExtensions.getProcessor(Contribution.class);
+
+ // Load the contribution
+ Contribution contribution = contributionProcessor.read(null, contributionURI, contributionURL, context);
+ contributions.add(contribution);
+
+ boolean attached = false;
+ // for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
+ // if (dc.getContent() != null) {
+ // Reader xml = new StringReader(dc.getContent());
+ // attached = attachDeploymentComposite(extensionPoints, contribution, xml, null, attached);
+ // } else if (dc.getLocation() != null) {
+ // URI dcURI = createURI(dc.getLocation());
+ // if (!dcURI.isAbsolute()) {
+ // Composite composite = null;
+ // // The location is pointing to an artifact within the contribution
+ // for (Artifact a : contribution.getArtifacts()) {
+ // if (dcURI.toString().equals(a.getURI())) {
+ // composite = (Composite)a.getModel();
+ // if (!attached) {
+ // contribution.getDeployables().clear();
+ // attached = true;
+ // }
+ // contribution.getDeployables().add(composite);
+ // break;
+ // }
+ // }
+ // if (composite == null) {
+ // // Not found
+ // throw new ServiceRuntimeException("Deployment composite " + dcURI
+ // + " cannot be found within contribution "
+ // + contribution.getLocation());
+ // }
+ // } else {
+ // URL url = dcURI.toURL();
+ // InputStream is = openStream(url);
+ // Reader xml = new InputStreamReader(is, "UTF-8");
+ // attached = attachDeploymentComposite(extensionPoints, contribution, xml, url.toString(), attached);
+ // }
+ // }
+ //// analyzeProblems();
+ // }
+ return contributions;
+ }
- private boolean attachDeploymentComposite(DefaultExtensionPointRegistry extensionPoints, Contribution contribution, Reader xml, String location, boolean attached) throws XMLStreamException, ContributionReadException {
+ private boolean attachDeploymentComposite(ExtensionPointRegistry extensionPoints,
+ Contribution contribution,
+ Reader xml,
+ String location,
+ boolean attached,
+ ProcessorContext context) throws XMLStreamException,
+ ContributionReadException {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader reader = inputFactory.createXMLStreamReader(xml);
reader.nextTag();
- StAXArtifactProcessorExtensionPoint xmlProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ StAXArtifactProcessorExtensionPoint xmlProcessors =
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
StAXArtifactProcessor<Composite> compositeProcessor = xmlProcessors.getProcessor(Composite.class);
-
+
// Read the composite model
- Composite composite = (Composite)compositeProcessor.read(reader);
+ Composite composite = (Composite)compositeProcessor.read(reader, context);
reader.close();
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
-
+
// Create an artifact for the deployment composite
Artifact artifact = contributionFactory.createArtifact();
String uri = composite.getName().getLocalPart() + ".composite";
diff --git a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessor.java b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessor.java index c7e07fbe60..1166567bcc 100644 --- a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessor.java +++ b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessor.java @@ -28,6 +28,7 @@ import javax.xml.stream.XMLInputFactory; import org.apache.tuscany.sca.common.xml.stax.StAXHelper; 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.resolver.ModelResolver; @@ -48,13 +49,12 @@ public class XSDDocumentProcessor implements URLArtifactProcessor<XSDefinition> private StAXHelper helper; private XSDFactory factory; private XMLInputFactory inputFactory; - private Monitor monitor; + - public XSDDocumentProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor, Monitor monitor) { + public XSDDocumentProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor processor) { FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.factory = modelFactories.getFactory(XSDFactory.class); this.inputFactory = modelFactories.getFactory(XMLInputFactory.class); - this.monitor = monitor; this.helper = StAXHelper.getInstance(registry); } @@ -65,24 +65,24 @@ public class XSDDocumentProcessor implements URLArtifactProcessor<XSDefinition> * @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(), "xsd-xml-validation-messages", Severity.ERROR, model, message, ex); monitor.problem(problem); } } - public XSDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + public XSDefinition read(URL contributionURL, URI artifactURI, URL artifactURL, ProcessorContext context) throws ContributionReadException { try { return indexRead(artifactURL); } catch (Exception e) { ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", artifactURL, ce); + error(context.getMonitor(), "ContributionReadException", artifactURL, ce); throw ce; } } - public void resolve(XSDefinition model, ModelResolver resolver) throws ContributionResolveException { + public void resolve(XSDefinition model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { } public String getArtifactType() { diff --git a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java index 15e4277f10..63ecf5d56f 100644 --- a/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java +++ b/java/sca/modules/xsd/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java @@ -36,9 +36,9 @@ import org.apache.tuscany.sca.contribution.DefaultImport; import org.apache.tuscany.sca.contribution.Import; import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; import org.apache.tuscany.sca.contribution.processor.ContributionRuntimeException; +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; import org.apache.tuscany.sca.xsd.DefaultXSDFactory; import org.apache.tuscany.sca.xsd.XSDFactory; import org.apache.tuscany.sca.xsd.XSDefinition; @@ -61,14 +61,13 @@ public class XSDModelResolver implements ModelResolver { private Map<String, List<XSDefinition>> map = new HashMap<String, List<XSDefinition>>(); private XmlSchemaCollection schemaCollection; - public XSDModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories, Monitor monitor) { + public XSDModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { this.contribution = contribution; this.schemaCollection = new XmlSchemaCollection(); - schemaCollection.setSchemaResolver(new URIResolverImpl(contribution)); this.factory = new DefaultXSDFactory(); } - public void addModel(Object resolved) { + public void addModel(Object resolved, ProcessorContext context) { XSDefinition definition = (XSDefinition)resolved; List<XSDefinition> list = map.get(definition.getNamespace()); if (list == null) { @@ -78,7 +77,7 @@ public class XSDModelResolver implements ModelResolver { list.add(definition); } - public Object removeModel(Object resolved) { + public Object removeModel(Object resolved, ProcessorContext context) { XSDefinition definition = (XSDefinition)resolved; List<XSDefinition> list = map.get(definition.getNamespace()); if (list == null) { @@ -88,8 +87,8 @@ public class XSDModelResolver implements ModelResolver { } } - public <T> T resolveModel(Class<T> modelClass, T unresolved) { - + public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { + schemaCollection.setSchemaResolver(new URIResolverImpl(contribution, context)); XSDefinition definition = (XSDefinition)unresolved; String namespace = definition.getNamespace(); XSDefinition resolved = null; @@ -233,9 +232,11 @@ public class XSDModelResolver implements ModelResolver { */ public static class URIResolverImpl implements URIResolver { private Contribution contribution; + private ProcessorContext context; - public URIResolverImpl(Contribution contribution) { + public URIResolverImpl(Contribution contribution, ProcessorContext context) { this.contribution = contribution; + this.context = context; } public org.xml.sax.InputSource resolveEntity(java.lang.String targetNamespace, @@ -265,7 +266,7 @@ public class XSDModelResolver implements ModelResolver { if (namespaceImport.getLocation() == null) { // Delegate the resolution to the namespace import resolver resolved = - namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved, context); if (!resolved.isUnresolved()) { return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL()); } @@ -279,7 +280,7 @@ public class XSDModelResolver implements ModelResolver { } else if (import_ instanceof DefaultImport) { // Delegate the resolution to the default import resolver resolved = - import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + import_.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved, context); if (!resolved.isUnresolved()) { return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL()); } @@ -291,7 +292,7 @@ public class XSDModelResolver implements ModelResolver { NamespaceImport namespaceImport = (NamespaceImport)locationMap.get(location); // Delegate the resolution to the namespace import resolver resolved = - namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved); + namespaceImport.getModelResolver().resolveModel(XSDefinition.class, (XSDefinition)unresolved, context); if (!resolved.isUnresolved()) { return XMLDocumentHelper.getInputSource(resolved.getLocation().toURL()); } diff --git a/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java b/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java index 3b57589072..e139625986 100644 --- a/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java +++ b/java/sca/modules/xsd/src/test/java/org/apache/tuscany/sca/xsd/xml/XSDDocumentProcessorTestCase.java @@ -27,6 +27,7 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +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.contribution.resolver.ModelResolver; @@ -56,32 +57,33 @@ public class XSDDocumentProcessorTestCase { public void setUp() throws Exception { ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); contributionFactory = modelFactories.getFactory(ContributionFactory.class); Contribution contribution = contributionFactory.createContribution(); - resolver = new XSDModelResolver(contribution, modelFactories, null); + resolver = new XSDModelResolver(contribution, modelFactories); } @Test public void testXSD() throws Exception { + ProcessorContext context = new ProcessorContext(); URL url = getClass().getResource("/xsd/greeting.xsd"); - XSDefinition definition = (XSDefinition)documentProcessor.read(null, URI.create("xsd/greeting.xsd"), url); + XSDefinition definition = (XSDefinition)documentProcessor.read(null, URI.create("xsd/greeting.xsd"), url, context); Assert.assertNull(definition.getSchema()); Assert.assertEquals("http://greeting", definition.getNamespace()); URL url1 = getClass().getResource("/xsd/name.xsd"); - XSDefinition definition1 = (XSDefinition)documentProcessor.read(null, URI.create("xsd/name.xsd"), url1); + XSDefinition definition1 = (XSDefinition)documentProcessor.read(null, URI.create("xsd/name.xsd"), url1, context); Assert.assertNull(definition1.getSchema()); Assert.assertEquals("http://greeting", definition1.getNamespace()); - resolver.addModel(definition); - XSDefinition resolved = resolver.resolveModel(XSDefinition.class, definition); + resolver.addModel(definition, context); + XSDefinition resolved = resolver.resolveModel(XSDefinition.class, definition, context); XmlSchemaObjectCollection collection = resolved.getSchema().getIncludes(); Assert.assertTrue(collection.getCount() == 1); XmlSchemaType type = ((XmlSchemaInclude)collection.getItem(0)).getSchema().getTypeByName(new QName("http://greeting", "Name")); Assert.assertNotNull(type); - resolver.addModel(definition1); - resolved = resolver.resolveModel(XSDefinition.class, definition); + resolver.addModel(definition1, context); + resolved = resolver.resolveModel(XSDefinition.class, definition, context); collection = resolved.getSchema().getIncludes(); Assert.assertTrue(collection.getCount() == 2); XmlSchemaType type1 = |