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/implementation-bpel/src | |
parent | d4cc9a0bdd43477858b8ac67b69a4cdd615ec741 (diff) |
This is to change the Monitor to be request scoped for most of the cases:
Refactor the ArtifactProcessor/ModelResolver to take a ProcessorContext that holds context such as Monitor, Contribution for the contribution/artifact processing methods
Refactor the Builder to take a BuilderContext that holds context such as Monitor, Definitions, Base binding mapping for the building methods
Change the processor/resolver/builder implementation classes to not cache the Monitor
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@825773 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-bpel/src')
5 files changed, 101 insertions, 104 deletions
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()); } |