From 9548ff6b107b61b2cad9ad367584977a52466b61 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 17 Aug 2008 06:31:07 +0000 Subject: Minor cleanup and code formatting to help readability. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@686584 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/implementation/bpel/BPELFactory.java | 1 + .../implementation/bpel/BPELImplementation.java | 14 +- .../implementation/bpel/BPELProcessDefinition.java | 43 +- .../implementation/bpel/DefaultBPELFactory.java | 11 +- .../bpel/impl/BPELDocumentProcessor.java | 608 ++++++++++----------- .../bpel/impl/BPELImplementationImpl.java | 18 +- .../bpel/impl/BPELImplementationProcessor.java | 370 ++++++------- .../bpel/impl/BPELProcessDefinitionImpl.java | 65 +-- .../implementation/bpel/xml/BPELImportElement.java | 24 +- .../bpel/xml/BPELPartnerLinkElement.java | 22 +- .../bpel/xml/BPELPartnerLinkTypeElement.java | 127 +++-- .../bpel/BPELImplementationProcessorTestCase.java | 6 - 12 files changed, 612 insertions(+), 697 deletions(-) (limited to 'java/sca') diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java index c47888de17..9f8f9c0e9a 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java @@ -35,6 +35,7 @@ public interface BPELFactory { /** * Creates a new BPEL Process Definition + * * @return */ BPELProcessDefinition createBPELProcessDefinition(); diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java index 53e160dd1c..5d90f7e18d 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java @@ -32,35 +32,43 @@ public interface BPELImplementation extends Implementation { /** * Get the BPEL process Name + * + * @return */ QName getProcess(); /** * Set the BPEL process Name + * * @param processName process QName */ void setProcess(QName processName); /** * Get the BPEL process definition + * * @return */ BPELProcessDefinition getProcessDefinition(); /** * Set the BPEL process definition + * * @param processDefinition */ void setProcessDefinition(BPELProcessDefinition processDefinition); /** - * Returns the componentType for this Spring implementation + * Returns the componentType for this implementation. + * + * @return */ public ComponentType getComponentType(); /** - * Sets the componentType for this Spring implementation - * @parma componentType the component type to set + * Sets the componentType for this implementation + * + * @param componentType the component type to set */ public void setComponentType(ComponentType componentType); } diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java index 61656e2533..3fde135357 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java @@ -19,25 +19,20 @@ package org.apache.tuscany.sca.implementation.bpel; -import java.util.List; -import java.util.Collection; - import java.net.URI; import java.net.URL; +import java.util.List; -import javax.xml.namespace.QName; import javax.wsdl.PortType; - -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Base; -import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement; import org.apache.tuscany.sca.implementation.bpel.xml.BPELImportElement; - - +import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; /** - * The BPEL process definition. + * The model representing a BPEL process definition. * * @version $Rev$ $Date$ */ @@ -45,70 +40,70 @@ public interface BPELProcessDefinition extends Base { /** * Get the BPEL process Name + * + * @return */ QName getName(); /** * Set the BPEL process Name + * * @param processName process QName */ void setName(QName name); /** * Get BPEL process URI + * * @return URI for the process */ URI getURI(); /** * Set the BPEL process URI + * * @param uri for the process */ void setURI(URI uri); /** * Get the URL for the process location + * * @return */ URL getLocation(); /** * Set the URL for the process location + * * @param url */ void setLocation(URL location); /** * Return the list of PartnerLinks for this process + * + * @return */ List getPartnerLinks(); /** * Return the list of imports for this process + * + * @return */ List getImports(); - /** - * Set the associated collection of port types - * @param thePortTypes - */ - public void setPortTypes( Collection thePortTypes ) ; - /** * Return the collection of associated port types + * * @return */ - public Collection getPortTypes() ; - - /** - * Set the associated collection of WSDL interfaces - * @param theInterfaces - */ - public void setInterfaces( Collection theInterfaces ) ; + public List getPortTypes() ; /** * Return the collection of associated WSDL interfaces * @return */ - public Collection getInterfaces() ; + public List getInterfaces() ; } diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java index d574f6e422..f5d5d98062 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java @@ -19,11 +19,9 @@ package org.apache.tuscany.sca.implementation.bpel; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.implementation.bpel.impl.BPELImplementationImpl; import org.apache.tuscany.sca.implementation.bpel.impl.BPELProcessDefinitionImpl; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; /** * A default factory for the BPEL implementation model. @@ -32,22 +30,15 @@ import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; */ public class DefaultBPELFactory implements BPELFactory { - private AssemblyFactory assemblyFactory; - private WSDLFactory wsdlFactory; - public DefaultBPELFactory(ModelFactoryExtensionPoint modelFactories) { - this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); } public BPELImplementation createBPELImplementation() { - return new BPELImplementationImpl(assemblyFactory, wsdlFactory); + return new BPELImplementationImpl(); } public BPELProcessDefinition createBPELProcessDefinition() { return new BPELProcessDefinitionImpl(); } - - } diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java index 0079272521..caf9e2371d 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java @@ -82,7 +82,6 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements private static final QName IMPORT_ELEMENT = new QName(BPEL_NS, "import"); private static final String LINKTYPE_NAME = "partnerLinkType"; private static final QName LINKTYPE_ELEMENT = new QName(BPEL_PLINK_NS, LINKTYPE_NAME); - public final static String NAME_ELEMENT = "name"; private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance(); @@ -97,49 +96,6 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements this.monitor = monitor; } - /** - * Report a warning. - * - * @param problems - * @param message - * @param model - */ - private void warning(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = new ProblemImpl(this.getClass().getName(), "impl-bpel-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 = new ProblemImpl(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - - /** - * Report a exception. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = new ProblemImpl(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } - } - - public String getArtifactType() { return "*.bpel"; } @@ -151,28 +107,21 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements public BPELProcessDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { BPELProcessDefinition processDefinition = null; try { - //for now we are just using process name - //and relying on componentType file for service definition - //so it's OK to set resolved for now - processDefinition = indexRead2(artifactURL); + // for now we are just using process name + // and relying on componentType file for service definition + // so it's OK to set resolved for now + processDefinition = readProcessDefinition(artifactURL); processDefinition.setURI(artifactURI); processDefinition.setUnresolved(false); } catch (Exception e) { - ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", artifactURL, ce); - //throw ce; + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", artifactURL, ce); } - + return processDefinition; } - /** - * Resolve the BPEL process - * - one of the things that needs doing is to pin down the WSDLs that are being used by - * the process, in particular the partnerLinkType and the related PortType definitions - */ - public void resolve(BPELProcessDefinition model, ModelResolver resolver) - throws ContributionResolveException { + public void resolve(BPELProcessDefinition model, ModelResolver resolver) throws ContributionResolveException { // FIXME - serious resolving needs to happen here // Step 1 is to resolve the WSDL files referenced from this BPEL process @@ -188,30 +137,29 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements // callback interface. List theImports = model.getImports(); - for ( BPELImportElement theImport : theImports ) { - // Deal with WSDL imports - if ( theImport.getImportType().equals("http://schemas.xmlsoap.org/wsdl/") ) { - String WSDLLocation = theImport.getLocation(); - String WSDLNamespace = theImport.getNamespace(); - - // Resolve the WSDL definition + for (BPELImportElement theImport : theImports) { + + // Deal with WSDL imports + if (theImport.getImportType().equals("http://schemas.xmlsoap.org/wsdl/")) { + String WSDLLocation = theImport.getLocation(); + String WSDLNamespace = theImport.getNamespace(); + + // Resolve the WSDL definition WSDLDefinition proxy = WSDLfactory.createWSDLDefinition(); proxy.setUnresolved(true); proxy.setNamespace(WSDLNamespace); - if ( WSDLLocation != null ) proxy.setLocation(URI.create(WSDLLocation)); + if (WSDLLocation != null) { + proxy.setLocation(URI.create(WSDLLocation)); + } WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy); if (resolved != null && !resolved.isUnresolved()) { - theImport.setWSDLDefinition( resolved ); + theImport.setWSDLDefinition(resolved); } else { error("CannotResolveWSDLReference", resolver, WSDLLocation, WSDLNamespace); - //throw new ContributionResolveException("BPELDocumentProcessor:resolve -" + - //" unable to resolve WSDL referenced by BPEL import" + - //"WSDL location: " + WSDLLocation + " WSDLNamespace: " + - //WSDLNamespace ); return; - } // end if - } // end if - } // end for + } // end if + } // end if + } // end for // Fetch the sets of partner links, port types and interfaces List thePLinkTypes = getPartnerLinkTypes( theImports ); @@ -219,157 +167,140 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements Collection thePortTypes = getAllPortTypes( theImports, theInterfaces, resolver ); // Store the Port Types and the Interfaces for later calculation of the component type... - model.setPortTypes(thePortTypes); - model.setInterfaces(theInterfaces); + model.getPortTypes().addAll(thePortTypes); + model.getInterfaces().addAll(theInterfaces); // Now, for each partnerLink in the BPEL process, find the related partnerLinkType // element - List thePartnerLinks = model.getPartnerLinks(); - for ( BPELPartnerLinkElement thePartnerLink : thePartnerLinks ) { - QName partnerLinkType = thePartnerLink.getPartnerLinkType(); - BPELPartnerLinkTypeElement pLinkType = - findPartnerLinkType( partnerLinkType, thePLinkTypes ); - if( pLinkType == null ) { - error("PartnerLinkNoMatchingType", thePartnerLink, thePartnerLink.getName()); - //throw new ContributionResolveException( "PartnerLink " - //+ thePartnerLink.getName() + " has no matching partner link type"); - } else - thePartnerLink.setPartnerLinkType(pLinkType); - } // end for + List thePartnerLinks = model.getPartnerLinks(); + for (BPELPartnerLinkElement thePartnerLink : thePartnerLinks) { + QName partnerLinkType = thePartnerLink.getPartnerLinkType(); + BPELPartnerLinkTypeElement pLinkType = findPartnerLinkType(partnerLinkType, thePLinkTypes); + if (pLinkType == null) { + error("PartnerLinkNoMatchingType", thePartnerLink, thePartnerLink.getName()); + } else + thePartnerLink.setPartnerLinkType(pLinkType); + } // end for } // end resolve - /* + /** * Retrieve all the Partner Link types defined in the imported WSDL files + * + * @param theImports */ - private List getPartnerLinkTypes( List theImports ) - throws ContributionResolveException { + private List getPartnerLinkTypes( List theImports) throws ContributionResolveException { - List thePLinks = - new ArrayList(); - - // We must find the partner link type elements from amongst the imported WSDLs - for ( BPELImportElement theImport : theImports ){ - WSDLDefinition theWSDL = theImport.getWSDLDefinition(); - Definition WSDLDefinition = theWSDL.getDefinition(); - // The BPEL partnerLinkType elements are extension elements within the WSDL - List extensibilityElements = WSDLDefinition.getExtensibilityElements(); - - for ( ExtensibilityElement theElement : extensibilityElements ) { - QName elementType = theElement.getElementType(); - if ( elementType.equals( LINKTYPE_ELEMENT ) ) { - BPELPartnerLinkTypeExt pLinkExt = (BPELPartnerLinkTypeExt)theElement; - // Fetch the name of the partnerLinkType - String name = pLinkExt.getName(); - QName qName = new QName( WSDLDefinition.getTargetNamespace(), name ); - BPELPartnerLinkTypeElement pLinkElement = new BPELPartnerLinkTypeElement( qName ); - - // The partnerLinkType must have one and may have 2 role child elements - int count = 0; - for( int i = 0; i < 2; i++ ) { - if(pLinkExt.getRoleName(i) == null ) continue; - PortType pType = WSDLDefinition.getPortType(pLinkExt.getRolePortType(i)); - if ( count == 0 ) { - pLinkElement.setRole1(pLinkExt.getRoleName(i), - pLinkExt.getRolePortType(i), - pType ); - count++; - } else if (count == 1) { - pLinkElement.setRole2(pLinkExt.getRoleName(i), - pLinkExt.getRolePortType(i), - pType ); - count++; - } else { - break; - } // end if - } // end for - if( count == 0 ) { - error("PartnerLinkTypeNoRoles", theElement, pLinkElement.getName()); - throw new ContributionResolveException( "partnerLinkType " + - pLinkElement.getName() +" has no Roles defined" ); - } else - thePLinks.add( pLinkElement ); - } // end if - - } // end for - } // end for - return thePLinks; + List thePLinks = new ArrayList(); + + // We must find the partner link type elements from amongst the imported + // WSDLs + for (BPELImportElement theImport : theImports) { + WSDLDefinition theWSDL = theImport.getWSDLDefinition(); + Definition WSDLDefinition = theWSDL.getDefinition(); + + // The BPEL partnerLinkType elements are extension elements within + // the WSDL + List extensibilityElements = WSDLDefinition.getExtensibilityElements(); + + for (ExtensibilityElement theElement : extensibilityElements) { + QName elementType = theElement.getElementType(); + if (elementType.equals(LINKTYPE_ELEMENT)) { + BPELPartnerLinkTypeExt pLinkExt = (BPELPartnerLinkTypeExt)theElement; + // Fetch the name of the partnerLinkType + String name = pLinkExt.getName(); + QName qName = new QName(WSDLDefinition.getTargetNamespace(), name); + BPELPartnerLinkTypeElement pLinkElement = new BPELPartnerLinkTypeElement(qName); + + // The partnerLinkType must have one and may have 2 role + // child elements + int count = 0; + for (int i = 0; i < 2; i++) { + if (pLinkExt.getRoleName(i) == null) + continue; + PortType pType = WSDLDefinition.getPortType(pLinkExt.getRolePortType(i)); + if (count == 0) { + pLinkElement.setRole1(pLinkExt.getRoleName(i), pLinkExt.getRolePortType(i), pType); + count++; + } else if (count == 1) { + pLinkElement.setRole2(pLinkExt.getRoleName(i), pLinkExt.getRolePortType(i), pType); + count++; + } else { + break; + } // end if + } // end for + + if (count == 0) { + error("PartnerLinkTypeNoRoles", theElement, pLinkElement.getName()); + throw new ContributionResolveException("partnerLinkType " + pLinkElement.getName() + " has no Roles defined"); + } else + thePLinks.add(pLinkElement); + } // end if + + } // end for + } // end for + return thePLinks; } // end getPartnerLinkTypes - - protected Collection getAllPortTypes( List theImports, - Collection theInterfaces, - ModelResolver resolver) - throws ContributionResolveException { - - Collection thePortTypes = (Collection)new ArrayList(); - for ( BPELImportElement theImport : theImports ){ - WSDLDefinition theWSDL = theImport.getWSDLDefinition(); - Definition wsdlDefinition = theWSDL.getDefinition(); - - Collection portTypes = (Collection)wsdlDefinition.getPortTypes().values(); - thePortTypes.addAll( portTypes ); - - // Create WSDLInterface elements for each PortType found - for( PortType portType : portTypes ) { - WSDLObject wsdlPortType = theWSDL.getWSDLObject(PortType.class, portType.getQName() ); - WSDLInterface wsdlInterface; - if (wsdlPortType != null) { + + /** + * Returns all the portTypes referenced by the process. + * + * @param theImports + * @param theInterfaces + * @param resolver + * @return + * @throws ContributionResolveException + */ + private Collection getAllPortTypes(List theImports, + Collection theInterfaces, ModelResolver resolver) throws ContributionResolveException { + + Collection thePortTypes = (Collection)new ArrayList(); + for (BPELImportElement theImport : theImports) { + WSDLDefinition theWSDL = theImport.getWSDLDefinition(); + Definition wsdlDefinition = theWSDL.getDefinition(); + + Collection portTypes = (Collection)wsdlDefinition.getPortTypes().values(); + thePortTypes.addAll(portTypes); + + // Create WSDLInterface elements for each PortType found + for (PortType portType : portTypes) { + WSDLObject wsdlPortType = theWSDL.getWSDLObject(PortType.class, portType.getQName()); + WSDLInterface wsdlInterface; + if (wsdlPortType != null) { // Introspect the WSDL portType and add the resulting // WSDLInterface to the resolver try { - theWSDL.setDefinition( wsdlPortType.getDefinition() ); - wsdlInterface = WSDLfactory.createWSDLInterface(wsdlPortType.getElement(), - theWSDL, resolver); + theWSDL.setDefinition(wsdlPortType.getDefinition()); + wsdlInterface = WSDLfactory.createWSDLInterface(wsdlPortType.getElement(), theWSDL, resolver); wsdlInterface.setWsdlDefinition(theWSDL); } catch (InvalidInterfaceException e) { - ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", resolver, ce); + ContributionResolveException ce = new ContributionResolveException(e); + error("ContributionResolveException", resolver, ce); throw ce; } // end try resolver.addModel(wsdlInterface); theInterfaces.add(wsdlInterface); } // end if } // end for - - //----------------------- - - } // end for - - return thePortTypes; + + // ----------------------- + + } // end for + + return thePortTypes; } // end getAllPortTypes /** - * Returns a QName from a string. - * @param definition - a WSDL Definition - * @param value - the String from which to form the QName in the form "pref:localName" - * @return - */ - protected QName getQNameValue(Definition definition, String value) { - if (value != null && definition != null) { - int index = value.indexOf(':'); - String prefix = index == -1 ? "" : value.substring(0, index); - String localName = index == -1 ? value : value.substring(index + 1); - String ns = definition.getNamespace(prefix); - if (ns == null) { - ns = ""; - } - return new QName(ns, localName, prefix); - } else { - return null; - } - } // end getQNameValue - - - /* - * Method which finds a partnerLinkType definition within the WSDLs imported by the BPEL + * Finds a partnerLinkType definition within the WSDLs imported by the BPEL * process. + * * @param partnerLinkTypeName - the name of the partnerLinkType * @param theImports a list of the WSDL import declarations - * @returns a BPELPartnerLinkTypeElement for the partnerLinkType or null if it cannot be + * @return a BPELPartnerLinkTypeElement for the partnerLinkType or null if it cannot be * found */ - private BPELPartnerLinkTypeElement findPartnerLinkType( QName partnerLinkTypeName, - List thePLinkTypes) { + private BPELPartnerLinkTypeElement findPartnerLinkType( QName partnerLinkTypeName, + List thePLinkTypes) { // We must find the partner link type element from amongst the imported WSDLs for ( BPELPartnerLinkTypeElement thePLinkType : thePLinkTypes ){ if( thePLinkType.getName().equals(partnerLinkTypeName) ) return thePLinkType; @@ -377,9 +308,15 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements return null; } // end findPartnerLinkType - - protected BPELProcessDefinition indexRead2(URL doc) throws Exception { + /** + * Read a process definition. + * + * @param doc + * @return + * @throws Exception + */ + private BPELProcessDefinition readProcessDefinition(URL doc) throws Exception { BPELProcessDefinition processDefinition = factory.createBPELProcessDefinition(); processDefinition.setUnresolved(true); processDefinition.setLocation(doc); @@ -388,137 +325,194 @@ public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements XMLStreamReader reader = null; try { reader = inputFactory.createXMLStreamReader(is); + /* - * The principle here is to look for partnerLink elements, which form either services - * or references. A partnerLink can be EITHER - the algorithm for deciding is: - * 1) Explicit marking with sca:reference or sca:service attribute - * 2) "first use" of the partnerLink by specific BPEL activity elements: - * , or elements imply a service - * implies a reference + * The principle here is to look for partnerLink elements, which + * form either services or references. A partnerLink can be EITHER - + * the algorithm for deciding is: 1) Explicit marking with + * sca:reference or sca:service attribute 2) "first use" of the + * partnerLink by specific BPEL activity elements: , + * or elements imply a service + * implies a reference */ + // TODO - need to handle elements as kind of "nested" processes - // - and scopes introduce the possibility of partnerLinks with the same name at - // different levels of scope.... (yuk!!) + // - and scopes introduce the possibility of partnerLinks with the + // same name at different levels of scope.... (yuk!!) boolean completed = false; while (!completed) { switch (reader.next()) { case START_ELEMENT: QName qname = reader.getName(); - //System.out.println("BPEL TypeLoader - found element with name: " + qname.toString()); - if (BPEL_PROCESS_DEFINITION.equals(qname) || - BPEL_EXECUTABLE_DEFINITION.equals(qname)) { - QName processName = new QName(getString(reader, org.apache.tuscany.sca.assembly.xml.Constants.TARGET_NAMESPACE), - getString(reader, NAME_ELEMENT)); + if (BPEL_PROCESS_DEFINITION.equals(qname) || BPEL_EXECUTABLE_DEFINITION.equals(qname)) { + QName processName = new QName(getString(reader, org.apache.tuscany.sca.assembly.xml.Constants.TARGET_NAMESPACE), getString(reader, NAME_ELEMENT)); processDefinition.setName(processName); - } else if (PARTNERLINK_ELEMENT.equals(qname)) { - processDefinition.getPartnerLinks().add(processPartnerLinkElement( reader )); - } else if (ONEVENT_ELEMENT.equals(qname) || - RECEIVE_ELEMENT.equals(qname) || - ONMESSAGE_ELEMENT.equals(qname) ) { - processPartnerLinkAsService( reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks() ); - } else if (INVOKE_ELEMENT.equals(qname)) { - processPartnerLinkAsReference( reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks() ); + } else if (PARTNERLINK_ELEMENT.equals(qname)) { + processDefinition.getPartnerLinks().add(processPartnerLinkElement(reader)); + } else if (ONEVENT_ELEMENT.equals(qname) || RECEIVE_ELEMENT.equals(qname) || ONMESSAGE_ELEMENT.equals(qname)) { + processPartnerLinkAsService(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks()); + } else if (INVOKE_ELEMENT.equals(qname)) { + processPartnerLinkAsReference(reader.getAttributeValue(null, "partnerLink"), processDefinition.getPartnerLinks()); } else if (IMPORT_ELEMENT.equals(qname)) { - processDefinition.getImports().add( processImportElement( reader ) ); + processDefinition.getImports().add(processImportElement(reader)); } // end if break; case END_ELEMENT: if (PROCESS_ELEMENT.equals(reader.getName())) { - //System.out.println("BPEL TypeLoader - finished read of process file"); completed = true; break; } // end if } // end switch } // end while } finally { - if(reader != null) reader.close(); + if (reader != null) + reader.close(); is.close(); } // end try - + return processDefinition; - } // end indexRead2 - - /* - * Processes a partnerLink element from the BPEL process and creates a - * BPELPartnerLink object - */ - private BPELPartnerLinkElement processPartnerLinkElement( XMLStreamReader reader ) - throws ContributionReadException { - BPELPartnerLinkElement partnerLink = new BPELPartnerLinkElement( - reader.getAttributeValue(null, "name"), - getQNameValue(reader, reader.getAttributeValue(null, "partnerLinkType") ), - reader.getAttributeValue(null, "myRole"), - reader.getAttributeValue(null, "partnerRole")); - // See if there are any SCA extension attributes - String scaService = reader.getAttributeValue( SCA_BPEL_NS, "service"); - String scaReference = reader.getAttributeValue( 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")); - throw new ContributionReadException( "BPEL PartnerLink " - + reader.getAttributeValue(null, "name") + - " has both sca:reference and sca:service attributes set" ); - } - // Set the SCA type and the related name, if present - if( scaService != null ) partnerLink.setAsService( scaService ); - else if ( scaReference != null ) partnerLink.setAsReference( scaReference ); - return partnerLink; - } // end processPartnerLinkElement - - /* - * Processes an element from the BPEL process and creates a - * BPELImportElement object - */ - private BPELImportElement processImportElement( XMLStreamReader reader ) { - return ( new BPELImportElement( reader.getAttributeValue(null, "location"), - reader.getAttributeValue(null, "importType"), - reader.getAttributeValue(null, "namespace") )); - } // end processImportElement - - /* - * Mark a named partnerLink as a Service, unless it is already marked as a Reference - */ - private void processPartnerLinkAsService( String partnerLinkName, - List partnerLinks ) { - BPELPartnerLinkElement partnerLink = findPartnerLinkByName( partnerLinks, partnerLinkName ); - if( partnerLink == null ) { - warning("ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); - } else { - // Set the type of the partnerLink to "service" if not already set... - if( !partnerLink.isSCATyped() ) partnerLink.setAsService( partnerLinkName ); - } // endif - } // end processPartnerLinkAsReference - - /* - * Mark a named partnerLink as a Reference, unless it is already marked as a Service - */ - private void processPartnerLinkAsReference( String partnerLinkName, - List partnerLinks ) { - BPELPartnerLinkElement partnerLink = findPartnerLinkByName( partnerLinks, partnerLinkName ); - if( partnerLink == null ) { - warning("ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); - } else { - // Set the type of the partnerLink to "service" if not already set... - if( !partnerLink.isSCATyped() ) partnerLink.setAsReference( partnerLinkName ); - } // endif - } // end processPartnerLinkAsReference - - /* - * Finds a PartnerLink by name from a List of PartnerLinks - * - * returns null if there is no partnerLink with a matching name - * - returns the PartnerLink with a matching name - */ - private BPELPartnerLinkElement findPartnerLinkByName( List partnerLinks, - String partnerLinkName ) { - // Scan the list looking for a partner link with the supplied name - Iterator it = partnerLinks.iterator(); - while( it.hasNext() ) { - BPELPartnerLinkElement thePartnerLink = it.next(); - if( thePartnerLink.getName().equals(partnerLinkName) ) return thePartnerLink; - } - return null; - } // end method findPartnerLinkByName + } // end readProcessDefinition + + /** + * Processes a partnerLink element from the BPEL process and creates a + * BPELPartnerLink object + * + * @param reader + */ + private BPELPartnerLinkElement processPartnerLinkElement(XMLStreamReader reader) throws ContributionReadException { + BPELPartnerLinkElement partnerLink = new BPELPartnerLinkElement( + reader.getAttributeValue(null, "name"), + getQNameValue(reader, reader.getAttributeValue(null, "partnerLinkType")), + reader.getAttributeValue(null, "myRole"), + reader.getAttributeValue(null, "partnerRole")); + + // See if there are any SCA extension attributes + String scaService = reader.getAttributeValue(SCA_BPEL_NS, "service"); + String scaReference = reader.getAttributeValue(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")); + throw new ContributionReadException("BPEL PartnerLink " + reader.getAttributeValue(null, "name") + " has both sca:reference and sca:service attributes set"); + } + + // Set the SCA type and the related name, if present + if (scaService != null) + partnerLink.setAsService(scaService); + else if (scaReference != null) + partnerLink.setAsReference(scaReference); + return partnerLink; + + } // end processPartnerLinkElement + + /** + * Processes an element from the BPEL process and creates a + * BPELImportElement object + * + * @param reader + */ + private BPELImportElement processImportElement(XMLStreamReader reader) { + return (new BPELImportElement(reader.getAttributeValue(null, "location"), + reader.getAttributeValue(null, "importType"), + reader.getAttributeValue(null, "namespace"))); + + } // end processImportElement + + /** + * Mark a named partnerLink as a Service, unless it is already marked as a + * Reference + * + * @param partnerLinkName + * @param partnerLinks + */ + private void processPartnerLinkAsService(String partnerLinkName, List partnerLinks) { + BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName); + if (partnerLink == null) { + warning("ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); + } else { + // Set the type of the partnerLink to "service" if not already + // set... + if (!partnerLink.isSCATyped()) + partnerLink.setAsService(partnerLinkName); + } // endif + } // end processPartnerLinkAsReference + + /** + * Mark a named partnerLink as a Reference, unless it is already marked as a + * Service + * + * @param partnerLinkName + * @param partnerLinks + */ + private void processPartnerLinkAsReference(String partnerLinkName, List partnerLinks) { + BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName); + if (partnerLink == null) { + warning("ReferencePartnerLinkNotInList", partnerLinkName, partnerLinkName); + } else { + // Set the type of the partnerLink to "service" if not already + // set... + if (!partnerLink.isSCATyped()) + partnerLink.setAsReference(partnerLinkName); + } // endif + } // end processPartnerLinkAsReference + + /** + * Finds a PartnerLink by name from a List of PartnerLinks returns null if + * there is no partnerLink with a matching name - returns the PartnerLink + * with a matching name + * + * @param partnerLinks + * @param partnerLinkName + */ + private BPELPartnerLinkElement findPartnerLinkByName(List partnerLinks, String partnerLinkName) { + // Scan the list looking for a partner link with the supplied name + Iterator it = partnerLinks.iterator(); + while (it.hasNext()) { + BPELPartnerLinkElement thePartnerLink = it.next(); + if (thePartnerLink.getName().equals(partnerLinkName)) + return thePartnerLink; + } + return null; + } // end method findPartnerLinkByName + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "impl-bpel-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 = new ProblemImpl(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(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/impl/BPELImplementationImpl.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java index 96d8a12a36..d4b9e872de 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java @@ -23,7 +23,6 @@ import java.util.List; import javax.xml.namespace.QName; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.ConstrainingType; import org.apache.tuscany.sca.assembly.Property; @@ -32,7 +31,6 @@ import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; /** * The model representing a BPEL implementation in an SCA assembly model. @@ -41,32 +39,30 @@ import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; */ public class BPELImplementationImpl extends ImplementationImpl implements BPELImplementation { - private QName _processName; - private BPELProcessDefinition _processDefinition; + private QName processName; + private BPELProcessDefinition processDefinition; private ComponentType componentType; /** * Constructs a new BPEL implementation. */ - public BPELImplementationImpl(AssemblyFactory assemblyFactory, - WSDLFactory wsdlFactory) { - + public BPELImplementationImpl() { } public QName getProcess() { - return _processName; + return processName; } public void setProcess(QName processName) { - _processName = processName; + this.processName = processName; } public BPELProcessDefinition getProcessDefinition() { - return this._processDefinition; + return this.processDefinition; } public void setProcessDefinition(BPELProcessDefinition processDefinition) { - this._processDefinition = processDefinition; + this.processDefinition = processDefinition; } @Override diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java index e047ae3cc7..3cabbd4a72 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java @@ -86,20 +86,6 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple this.monitor = monitor; } - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = new ProblemImpl(this.getClass().getName(), "impl-bpel-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - public QName getArtifactType() { // Returns the QName of the XML element processed by this processor return IMPLEMENTATION_BPEL_QNAME; @@ -137,43 +123,29 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple return implementation; } - public void resolve(BPELImplementation impl, ModelResolver resolver) throws ContributionResolveException { + public void resolve(BPELImplementation implementation, ModelResolver resolver) throws ContributionResolveException { - if( impl != null && impl.isUnresolved()) + if( implementation != null && implementation.isUnresolved()) { - BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(impl, resolver); + BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(implementation, resolver); if(processDefinition.isUnresolved()) { - error("BPELProcessNotFound", impl, processDefinition.getName()); - //throw new ContributionResolveException("Can't find BPEL Process : " + processDefinition.getName()); + error("BPELProcessNotFound", implementation, processDefinition.getName()); } else { - impl.setProcessDefinition(processDefinition); + implementation.setProcessDefinition(processDefinition); // Get the component type from the process definition - generateComponentType( impl ); + generateComponentType( implementation ); //resolve component type - mergeComponentType(resolver, impl); + mergeComponentType(resolver, implementation); //set current implementation resolved - impl.setUnresolved(false); + implementation.setUnresolved(false); } } } // end resolve - /* - * Write out the XML representation of the BPEL implementation - * - * - * One complexity here is that the value of the process attribute is a QName - * In this implementation, the QName is written out in XML Namespaces recommendation format, - * as described in the documentation of the getAttributeValueNS method: - * - * ie: {http://example.com/somenamespace}SomeName - * - * This may well NOT be the format in which the attribute was originally read from the - * composite file. - */ public void write( BPELImplementation bpelImplementation, XMLStreamWriter writer ) throws ContributionWriteException, XMLStreamException { //FIXME Deal with policy processing... @@ -199,43 +171,40 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple return resolver.resolveModel(BPELProcessDefinition.class, processDefinition); } // end resolveBPELProcessDefinition - // Calculates the component type of the supplied implementation and attaches it to the - // implementation - private void generateComponentType(BPELImplementation impl ) - throws ContributionResolveException { + /** + * Calculates the component type of the supplied implementation and attaches it to the + * implementation. + * + * @param impl + * @throws ContributionResolveException + */ + private void generateComponentType(BPELImplementation impl) throws ContributionResolveException { + // Create a ComponentType and mark it unresolved ComponentType componentType = assemblyFactory.createComponentType(); componentType.setUnresolved(true); impl.setComponentType(componentType); - - // Each partner link in the process represents either a service or a reference + + // Each partner link in the process represents either a service or a + // reference // - or both, in the sense of involving a callback BPELProcessDefinition theProcess = impl.getProcessDefinition(); List partnerLinks = theProcess.getPartnerLinks(); - - for( BPELPartnerLinkElement pLink : partnerLinks ) { - // check that the partner link has been designated as service or reference in SCA terms - if ( pLink.isSCATyped() ) { - String SCAName = pLink.getSCAName(); - if( pLink.querySCAType().equals("reference") ) { - componentType.getReferences().add( - generateReference( SCAName, - pLink.getMyRolePortType(), - pLink.getPartnerRolePortType(), - theProcess.getInterfaces() ) - ); - } else { - componentType.getServices().add( - generateService( SCAName, - pLink.getMyRolePortType(), - pLink.getPartnerRolePortType(), - theProcess.getInterfaces() ) - ); - } // end if - } // end if + + for (BPELPartnerLinkElement pLink : partnerLinks) { + + // check that the partner link has been designated as service or + // reference in SCA terms + if (pLink.isSCATyped()) { + String SCAName = pLink.getSCAName(); + if (pLink.querySCAType().equals("reference")) { + componentType.getReferences().add(generateReference(SCAName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces())); + } else { + componentType.getServices().add(generateService(SCAName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces())); + } // end if + } // end if } // end for - - + } // end getComponentType /** @@ -247,70 +216,69 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple * @return */ private Reference generateReference( String name, PortType myRolePT, - PortType partnerRolePT, Collection theInterfaces ) - throws ContributionResolveException { + PortType partnerRolePT, Collection theInterfaces) throws ContributionResolveException { + Reference reference = assemblyFactory.createReference(); WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); reference.setInterfaceContract(interfaceContract); - - // Establish whether there is just a call interface or a call + callback interface + + // Establish whether there is just a call interface or a call + callback + // interface PortType callPT = null; PortType callbackPT = null; - if( myRolePT != null ) { - callPT = myRolePT; - // If the 2 port types are not the same one, there is a callback... - if( partnerRolePT != null ) { - if( !myRolePT.getQName().equals(partnerRolePT.getQName()) ){ - callbackPT = partnerRolePT; - } // end if - } // end if - } else if ( partnerRolePT != null ) { - callPT = partnerRolePT; + if (myRolePT != null) { + callPT = myRolePT; + // If the 2 port types are not the same one, there is a callback... + if (partnerRolePT != null) { + if (!myRolePT.getQName().equals(partnerRolePT.getQName())) { + callbackPT = partnerRolePT; + } // end if + } // end if + } else if (partnerRolePT != null) { + callPT = partnerRolePT; } // end if - // No interfaces mean an error - throw an exception - if( callPT == null && callbackPT == null ) { - error("MyRolePartnerRoleNull", theInterfaces); - throw new ContributionResolveException("Error: myRole and partnerRole port types are both null"); - } // end if - - // Set the name of the reference to the supplied name and the multiplicity of the reference - // to 1..1 - // TODO: support other multiplicities + + // No interfaces mean an error + if (callPT == null && callbackPT == null) { + error("MyRolePartnerRoleNull", theInterfaces); + } // end if + + // Set the name of the reference to the supplied name and the + // multiplicity of the reference + // to 1..1 + // TODO: support other multiplicities reference.setName(name); reference.setMultiplicity(Multiplicity.ONE_ONE); - - if ( callPT != null ) { + + if (callPT != null) { // Set the call interface and, if present, the callback interface WSDLInterface callInterface = null; - for( WSDLInterface anInterface : theInterfaces ) { - if( anInterface.getPortType().getQName().equals(callPT.getQName())) callInterface = anInterface; + for (WSDLInterface anInterface : theInterfaces) { + if (anInterface.getPortType().getQName().equals(callPT.getQName())) + callInterface = anInterface; } // end for - // Throw an exception if no interface is found - if( callInterface == null ) { - error("NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); - throw new ContributionResolveException("Interface not found for port type " + - callPT.getQName().toString() ); + if (callInterface == null) { + error("NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); } else reference.getInterfaceContract().setInterface(callInterface); } - - // There is a callback if the partner role is not null and if the partner role port type + + // There is a callback if the partner role is not null and if the + // partner role port type // is not the same as the port type for my role - if ( callbackPT != null ) { + if (callbackPT != null) { WSDLInterface callbackInterface = null; - for( WSDLInterface anInterface : theInterfaces ) { - if( anInterface.getPortType().getQName().equals(callbackPT.getQName())) callbackInterface = anInterface; + for (WSDLInterface anInterface : theInterfaces) { + if (anInterface.getPortType().getQName().equals(callbackPT.getQName())) + callbackInterface = anInterface; } // end for - // Throw an exception if no interface is found - if( callbackInterface == null ) { - error("NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); - throw new ContributionResolveException("Interface not found for port type " + - callbackPT.getQName().toString() ); - } else + if (callbackInterface == null) { + error("NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); + } else reference.getInterfaceContract().setCallbackInterface(callbackInterface); } // end if - - return reference; + + return reference; } // end generateReference /** @@ -327,62 +295,60 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple Service service = assemblyFactory.createService(); WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); service.setInterfaceContract(interfaceContract); - - // Set the name of the service to the supplied name + + // Set the name of the service to the supplied name service.setName(name); - - // Establish whether there is just a call interface or a call + callback interface + + // Establish whether there is just a call interface or a call + callback + // interface PortType callPT = null; PortType callbackPT = null; - if( myRolePT != null ) { - callPT = myRolePT; - // If the 2 port types are not the same one, there is a callback... - if( partnerRolePT != null ) { - if( !myRolePT.getQName().equals(partnerRolePT.getQName()) ){ - callbackPT = partnerRolePT; - } // end if - } // end if - } else if ( partnerRolePT != null ) { - callPT = partnerRolePT; + if (myRolePT != null) { + callPT = myRolePT; + // If the 2 port types are not the same one, there is a callback... + if (partnerRolePT != null) { + if (!myRolePT.getQName().equals(partnerRolePT.getQName())) { + callbackPT = partnerRolePT; + } // end if + } // end if + } else if (partnerRolePT != null) { + callPT = partnerRolePT; } // end if - // No interfaces mean an error - throw an exception - if( callPT == null && callbackPT == null ) { - error("MyRolePartnerRoleNull", theInterfaces); - throw new ContributionResolveException("Error: myRole and partnerRole port types are both null"); + + // No interfaces mean an error + if (callPT == null && callbackPT == null) { + error("MyRolePartnerRoleNull", theInterfaces); } // end if - if ( callPT != null ) { + if (callPT != null) { // Set the call interface and, if present, the callback interface WSDLInterface callInterface = null; - for( WSDLInterface anInterface : theInterfaces ) { - if( anInterface.getPortType().getQName().equals(callPT.getQName())) callInterface = anInterface; + for (WSDLInterface anInterface : theInterfaces) { + if (anInterface.getPortType().getQName().equals(callPT.getQName())) + callInterface = anInterface; } // end for - // Throw an exception if no interface is found - if( callInterface == null ) { - error("NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); - throw new ContributionResolveException("Interface not found for port type " + - callPT.getQName().toString() ); + if (callInterface == null) { + error("NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); } else service.getInterfaceContract().setInterface(callInterface); } // end if - - // There is a callback if the partner role is not null and if the partner role port type + + // There is a callback if the partner role is not null and if the + // partner role port type // is not the same as the port type for my role - if ( callbackPT != null ) { + if (callbackPT != null) { WSDLInterface callbackInterface = null; - for( WSDLInterface anInterface : theInterfaces ) { - if( anInterface.getPortType().getQName().equals(callbackPT.getQName())) callbackInterface = anInterface; + for (WSDLInterface anInterface : theInterfaces) { + if (anInterface.getPortType().getQName().equals(callbackPT.getQName())) + callbackInterface = anInterface; } // end for - // Throw an exception if no interface is found - if( callbackInterface == null ) { - error("NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); - throw new ContributionResolveException("Interface not found for port type " + - callbackPT.getQName().toString() ); - } else + if (callbackInterface == null) { + error("NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); + } else service.getInterfaceContract().setCallbackInterface(callbackInterface); } // end if - - return service; + + return service; } // end generateService /** @@ -395,26 +361,30 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple * @param impl */ private void mergeComponentType(ModelResolver resolver, BPELImplementation impl) { - // Load the component type from a component type file, if any + + // Load the component type from a component type file, if any ComponentType componentType = getComponentType(resolver, impl); if (componentType != null && !componentType.isUnresolved()) { - - // References... + + // References... Map refMap = new HashMap(); for (Reference reference : componentType.getReferences()) { - reference.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); + reference.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); refMap.put(reference.getName(), reference); } // end for - // For the present, overwrite anything arising from the component type sidefile if + // For the present, overwrite anything arising from the component + // type sidefile if // equivalent services are defined in the implementation. - // TODO - a more careful merge must be done, using the implementation introspection data - // as the master but adding any additional and non-conflicting information from the + // TODO - a more careful merge must be done, using the + // implementation introspection data + // as the master but adding any additional and non-conflicting + // information from the // sidefile for (Reference ref : impl.getReferences()) { - ref.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); + ref.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); refMap.put(ref.getName(), ref); - } // end for + } // end for impl.getReferences().clear(); impl.getReferences().addAll(refMap.values()); @@ -422,18 +392,21 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple // Services..... Map serviceMap = new HashMap(); for (Service service : componentType.getServices()) { - service.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); + service.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); serviceMap.put(service.getName(), service); } // end for - - // For the present, overwrite anything arising from the component type sidefile if + + // For the present, overwrite anything arising from the component + // type sidefile if // equivalent services are defined in the implementation. - // TODO - a more careful merge must be done, using the implementation introspection data - // as the master but adding any additional and non-conflicting information from the + // TODO - a more careful merge must be done, using the + // implementation introspection data + // as the master but adding any additional and non-conflicting + // information from the // sidefile for (Service svc : impl.getServices()) { svc.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); - serviceMap.put(svc.getName(), svc); + serviceMap.put(svc.getName(), svc); } // end for impl.getServices().clear(); @@ -442,10 +415,11 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple // Properties Map propMap = new HashMap(); for (Property property : componentType.getProperties()) { - propMap.put(property.getName(), property); + propMap.put(property.getName(), property); } // end for - // A simple overwrite of any equivalent properties from the component type sidefile + // A simple overwrite of any equivalent properties from the + // component type sidefile for (Property prop : impl.getProperties()) { propMap.put(prop.getName(), prop); } @@ -495,44 +469,54 @@ public class BPELImplementationProcessor extends BaseStAXArtifactProcessor imple private QName getAttributeValueNS(XMLStreamReader reader, String attribute) { String fullValue = reader.getAttributeValue(null, attribute); if (fullValue == null) { - error("AttributeProcessMissing", reader); - return null; + error("AttributeProcessMissing", reader); + return null; } - + // Deal with the attribute in the XML Namespaces recommendation format - // - trim off any leading/trailing spaces and check that the first character is '{' - if( fullValue.trim().charAt(0) == '{' ) { - try { - // Attempt conversion to a QName object - QName theProcess = QName.valueOf( fullValue ); - return theProcess; - } catch ( IllegalArgumentException e ) { - // This exception happens if the attribute begins with '{' but doesn't conform - // to the XML Namespaces recommendation format - error("AttributeWithoutNamespace", reader, attribute, fullValue); - return null; - //throw new BPELProcessException("Attribute " + attribute + " with value " + fullValue + - //" in your composite should be of the form {namespaceURI}localname"); - } + // - trim off any leading/trailing spaces and check that the first + // character is '{' + if (fullValue.trim().charAt(0) == '{') { + try { + // Attempt conversion to a QName object + QName theProcess = QName.valueOf(fullValue); + return theProcess; + } catch (IllegalArgumentException e) { + // This exception happens if the attribute begins with '{' but + // doesn't conform + // to the XML Namespaces recommendation format + error("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); - return null; - //throw new BPELProcessException("Attribute " + attribute + " with value " + fullValue + - //" in your composite should be prefixed (process=\"prefix:name\")."); + error("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); - return null; - //throw new BPELProcessException("Attribute " + attribute + " with value " + fullValue + - //" in your composite has an unrecognized namespace prefix."); - } + error("AttributeUnrecognizedNamespace", reader, attribute, fullValue); + return null; + } return new QName(nsUri, name, prefix); } + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(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/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java index 83e70ec959..1372b94eee 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java @@ -23,16 +23,14 @@ import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.List; -import java.util.Collection; -import javax.xml.namespace.QName; import javax.wsdl.PortType; - -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import javax.xml.namespace.QName; import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; import org.apache.tuscany.sca.implementation.bpel.xml.BPELImportElement; import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; /** * The BPEL process definition implementation. @@ -40,14 +38,14 @@ import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement; * @version $Rev$ $Date$ */ public class BPELProcessDefinitionImpl implements BPELProcessDefinition { - private QName name; - private URI uri; - private URL location; + private QName name; + private URI uri; + private URL location; private boolean unresolved; private List partnerLinks = new ArrayList(); private List imports = new ArrayList(); - private Collection thePortTypes = null; - private Collection theInterfaces = null; + private List thePortTypes = new ArrayList(); + private List theInterfaces = new ArrayList(); public QName getName() { return name; @@ -81,65 +79,22 @@ public class BPELProcessDefinitionImpl implements BPELProcessDefinition { this.unresolved = undefined; } - /** - * Return the list of PartnerLinks for this process - * @return List the list of Partner Links - */ public List getPartnerLinks() { return partnerLinks; } - /** - * Return the list of imports for this process - * @return List the list of Import elements - */ public List getImports() { return imports; } - public void setPortTypes( Collection thePortTypes ) { - this.thePortTypes = thePortTypes; - } - - public Collection getPortTypes() { + public List getPortTypes() { return thePortTypes; } - /** - * Set the associated collection of WSDL interfaces - * @param theInterfaces - */ - public void setInterfaces( Collection theInterfaces ) { - this.theInterfaces = theInterfaces; - } // end setInterfaces - - /** - * Return the collection of associated WSDL interfaces - * @return - */ - public Collection getInterfaces() { + public List getInterfaces() { return theInterfaces; - } // end getInterfaces - - public void compile() { - /* - String bpelFile = reader.getAttributeValue(null, "file"); // FIXME: - - // Resolving the BPEL file and compiling it - URL bpelURL = getClass().getClassLoader().getResource(bpelFile); - if (bpelURL == null) - throw new ODEProcessException("Couldn't find referenced bpel file " + bpelFile); - BpelC bpelc = BpelC.newBpelCompiler(); - ByteArrayOutputStream compiledProcess = new ByteArrayOutputStream(); - bpelc.setOutputStream(compiledProcess); - try { - bpelc.compile(new File(bpelURL.getFile())); - } catch (IOException e) { - e.printStackTrace(); - } - */ } - + @Override public int hashCode() { return String.valueOf(getName()).hashCode(); diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java index 75a46f9bc3..bf0020323c 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java @@ -31,14 +31,12 @@ import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; */ public class BPELImportElement { - private String location; + private String location; private String importType; private String namespace; private WSDLDefinition theWSDL = null; - - public BPELImportElement( String location, - String importType, - String namespace ) { + + public BPELImportElement(String location, String importType, String namespace) { this.location = location; this.importType = importType; this.namespace = namespace; @@ -51,17 +49,17 @@ public class BPELImportElement { public String getLocation() { return location; } - + public String getNamespace() { - return namespace; + return namespace; } - - public void setWSDLDefinition( WSDLDefinition theDefinition) { - theWSDL = theDefinition; + + public void setWSDLDefinition(WSDLDefinition theDefinition) { + theWSDL = theDefinition; } - + public WSDLDefinition getWSDLDefinition() { - return theWSDL; + return theWSDL; } - + } // end class BPELImportElement diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java index 4ea0e5e49e..b7f5d1d3f2 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java @@ -40,8 +40,8 @@ public class BPELPartnerLinkElement { private String REFERENCE_TYPE = "reference"; private String SERVICE_TYPE = "service"; - private String name; - private QName partnerLinkType; + private String name; + private QName partnerLinkType; private BPELPartnerLinkTypeElement pLinkType = null; private String myRole; private String partnerRole; @@ -78,15 +78,15 @@ public class BPELPartnerLinkElement { } private PortType getRolePortType( String theRole ) { - if( theRole == null || theRole.length() == 0 ) { - return null; - } //end if - if ( theRole.equals( pLinkType.getRole1Name() ) ) { - return pLinkType.getRole1pType(); - } else if ( theRole.equals( pLinkType.getRole2Name() ) ) { - return pLinkType.getRole2pType(); - } // end if - return null; + if (theRole == null || theRole.length() == 0) { + return null; + } // end if + if (theRole.equals(pLinkType.getRole1Name())) { + return pLinkType.getRole1pType(); + } else if (theRole.equals(pLinkType.getRole2Name())) { + return pLinkType.getRole2pType(); + } // end if + return null; } // end getRolePortType public String getName() { diff --git a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java index e013215f5e..fdaf98a97f 100644 --- a/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java +++ b/java/sca/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java @@ -39,75 +39,74 @@ */ public class BPELPartnerLinkTypeElement implements ExtensibilityElement { - private QName name; - private String Role1name = null; - private QName Role1porttype = null; - private PortType Role1pType = null; - private String Role2name = null; - private QName Role2porttype = null; - private PortType Role2pType = null; + private QName name; + private String Role1name = null; + private QName Role1porttype = null; + private PortType Role1pType = null; + private String Role2name = null; + private QName Role2porttype = null; + private PortType Role2pType = null; + private QName elementType = null; + private Boolean required = false; + + public BPELPartnerLinkTypeElement(QName name) { + this.name = name; + } + + public QName getName() { + return name; + } + + public void setRole1(String name, QName portType, PortType pType) { + Role1name = name; + Role1porttype = portType; + Role1pType = pType; + } + + public void setRole2(String name, QName portType, PortType pType) { + Role2name = name; + Role2porttype = portType; + Role2pType = pType; + } + + public String getRole1Name() { + return Role1name; + } + + public String getRole2Name() { + return Role2name; + } + + public QName getRole1PortType() { + return Role1porttype; + } + + public QName getRole2PortType() { + return Role2porttype; + } + + public PortType getRole1pType() { + return Role1pType; + } + + public PortType getRole2pType() { + return Role2pType; + } + + public QName getElementType() { + return elementType; + } - - private QName elementType = null; - private Boolean required = false; - - public BPELPartnerLinkTypeElement( QName name ) { - this.name = name; - } - - public QName getName(){ - return name; - } - - public void setRole1( String name, QName portType, PortType pType ) { - Role1name = name; - Role1porttype = portType; - Role1pType = pType; - } - - public void setRole2( String name, QName portType, PortType pType ) { - Role2name = name; - Role2porttype = portType; - Role2pType = pType; - } - - public String getRole1Name() { - return Role1name; - } - public String getRole2Name() { - return Role2name; - } - - public QName getRole1PortType() { - return Role1porttype; - } - - public QName getRole2PortType() { - return Role2porttype; - } - - public PortType getRole1pType() { - return Role1pType; - } - - public PortType getRole2pType() { - return Role2pType; - } - - public QName getElementType() { - return elementType; - } - public Boolean getRequired() { - return required; + return required; } - + public void setElementType(QName elementType) { - this.elementType = elementType; + this.elementType = elementType; } - + public void setRequired(java.lang.Boolean required) { - this.required = required; + this.required = required; } - + } // end BPELPartnerLinkType 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 14500f6e14..9dd5306de1 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 @@ -103,12 +103,6 @@ public class BPELImplementationProcessorTestCase extends TestCase { */ public void testLoadInvalidComposite() throws Exception { XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE_INVALID)); - /*try { - staxProcessor.read(reader); - fail("InvalidException should have been thrown"); - } catch(Exception e) { - assertTrue(true); - }*/ staxProcessor.read(reader); Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem(); assertNotNull(problem); -- cgit v1.2.3