From a3c48da9bb8971497d414f86e352123d95b9c3da Mon Sep 17 00:00:00 2001 From: lresende Date: Fri, 20 Nov 2009 23:53:35 +0000 Subject: Moving 2.x trunk git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@882795 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/implementation/bpel/BPELFactory.java | 42 ++ .../implementation/bpel/BPELImplementation.java | 109 +++++ .../implementation/bpel/BPELProcessDefinition.java | 114 ++++++ .../implementation/bpel/impl/BPELFactoryImpl.java | 44 ++ .../bpel/impl/BPELImplementationImpl.java | 152 +++++++ .../bpel/impl/BPELProcessDefinitionImpl.java | 128 ++++++ .../bpel/xml/BPELDocumentModelResolver.java | 401 ++++++++++++++++++ .../bpel/xml/BPELDocumentProcessor.java | 355 ++++++++++++++++ .../bpel/xml/BPELImplementationProcessor.java | 452 +++++++++++++++++++++ .../implementation/bpel/xml/BPELImportElement.java | 65 +++ .../bpel/xml/BPELPartnerLinkElement.java | 132 ++++++ .../bpel/xml/BPELPartnerLinkTypeElement.java | 118 ++++++ .../bpel/xml/BPELProcessorConstants.java | 61 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...sca.contribution.processor.URLArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 19 + ...che.tuscany.sca.implementation.bpel.BPELFactory | 19 + .../impl-bpel-validation-messages.properties | 34 ++ 18 files changed, 2283 insertions(+) create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory create mode 100644 sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties (limited to 'sca-java-2.x/trunk/modules/implementation-bpel/src/main') diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java new file mode 100644 index 0000000000..9f8f9c0e9a --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.bpel; + +/** + * A factory for the BPEL implementation model. + * + * @version $Rev$ $Date$ + */ +public interface BPELFactory { + + /** + * Creates a new BPEL implementation. + * + * @return + */ + BPELImplementation createBPELImplementation(); + + /** + * Creates a new BPEL Process Definition + * + * @return + */ + BPELProcessDefinition createBPELProcessDefinition(); +} diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java new file mode 100644 index 0000000000..db5d808f7a --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The model representing the BPEL implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public interface BPELImplementation extends Implementation { + QName TYPE = new QName(SCA11_NS, "implementation.bpel"); + /** + * 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 implementation. + * + * @return + */ + public ComponentType getComponentType(); + + /** + * Sets the componentType for this implementation + * + * @param componentType the component type to set + */ + public void setComponentType(ComponentType componentType); + + /** + * Returns the model resolver that can be used to resolve WSDLs and XSDs + * referenced by the BPEL process. + * + * @return + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver that can be used to resolve WSDLs and XSDs referenced + * by the BPEL process. + * + * @param modelResolver + */ + void setModelResolver(ModelResolver modelResolver); + + /** + * Gets the name of the partnerLink which corresponds to the SCA service with the supplied name + * This deals in particular with cases where the SCA service name is an alias which is not the + * same as the partnerLink name + * @param serviceName - the name of the SCA service + * @return + */ + String getServicePartnerlinkName( String serviceName ); + + /** + * Gets the name of the partnerLink which corresponds to the SCA reference with the supplied name + * This deals in particular with cases where the SCA reference name is an alias which is not the + * same as the partnerLink name + * @param referenceName - the name of the SCA reference + * @return + */ + String getReferencePartnerlinkName( String referenceName ); +} diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java new file mode 100644 index 0000000000..ac02b696cc --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.bpel; + +import java.util.List; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.Property; +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 model representing a BPEL process definition. + * + * @version $Rev$ $Date$ + */ +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 + */ + String getURI(); + + /** + * Set the BPEL process URI + * + * @param uri for the process + */ + void setURI(String uri); + + /** + * Get the URL for the process location + * + * @return + */ + String getLocation(); + + /** + * Set the URL for the process location + * + * @param url + */ + void setLocation(String location); + + /** + * Return the list of PartnerLinks for this process + * + * @return + */ + List getPartnerLinks(); + + /** + * Return the list of imports for this process + * + * @return + */ + List getImports(); + + /** + * Return the collection of associated port types + * + * @return + */ + public List getPortTypes() ; + + /** + * Return the collection of associated WSDL interfaces + * @return + */ + public List getInterfaces() ; + + /** + * Return a collection of (SCA) Properties associated with this process + * @return - a List of SCA Property objects + */ + public List getProperties(); +} diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java new file mode 100644 index 0000000000..bd98a4af95 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELFactoryImpl.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.bpel.impl; + +import org.apache.tuscany.sca.implementation.bpel.BPELFactory; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; + +/** + * A factory for the BPEL implementation model. + * + * @version $Rev$ $Date$ + */ +public class BPELFactoryImpl implements BPELFactory { + + public BPELFactoryImpl() { + } + + public BPELImplementation createBPELImplementation() { + return new BPELImplementationImpl(); + } + + public BPELProcessDefinition createBPELProcessDefinition() { + return new BPELProcessDefinitionImpl(); + } + +} diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java new file mode 100644 index 0000000000..67eb9bd047 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel.impl; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; +import org.apache.tuscany.sca.implementation.bpel.xml.BPELPartnerLinkElement; + +/** + * The model representing a BPEL implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +class BPELImplementationImpl extends ImplementationImpl implements BPELImplementation { + + private QName processName; + private BPELProcessDefinition processDefinition; + private ComponentType componentType; + private ModelResolver modelResolver; + + protected BPELImplementationImpl() { + super(TYPE); + } + + public QName getProcess() { + return processName; + } + + public void setProcess(QName processName) { + this.processName = processName; + } + + public BPELProcessDefinition getProcessDefinition() { + return this.processDefinition; + } + + public void setProcessDefinition(BPELProcessDefinition processDefinition) { + this.processDefinition = processDefinition; + } + + @Override + public String getURI() { + // The BPEL implementation does not have a URI + return null; + } + + @Override + public void setURI(String uri) { + // The BPEL implementation does not have a URI + } + + @Override + public List getProperties() { + return componentType.getProperties(); + } + + public ComponentType getComponentType() { + return componentType; + } + + public void setComponentType(ComponentType componentType) { + this.componentType = componentType; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + + @Override + public List getServices() { + return componentType.getServices(); + } + + @Override + public List getReferences() { + return componentType.getReferences(); + } + + @Override + public int hashCode() { + return String.valueOf(this.getProcess()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof BPELImplementation) { + if (getProcess() != null) { + return getProcess().equals(((BPELImplementation)obj).getProcess()); + } else { + return ((BPELImplementation)obj).getProcess() == null; + } + } else { + return false; + } + } + + public String getReferencePartnerlinkName(String referenceName) { + if( referenceName == null ) return null; + // Find the partnerLink which has its SCAName set to the supplied name + List partnerLinks = processDefinition.getPartnerLinks(); + for( BPELPartnerLinkElement partnerLink : partnerLinks ) { + if( referenceName.equals(partnerLink.getSCAName()) ) { + return partnerLink.getName(); + } // end if + } // end for + return null; + } // end method getReferencePartnerlinkName + + public String getServicePartnerlinkName(String serviceName) { + if( serviceName == null ) return null; + // Find the partnerLink which has its SCAName set to the supplied name + List partnerLinks = processDefinition.getPartnerLinks(); + for( BPELPartnerLinkElement partnerLink : partnerLinks ) { + if( serviceName.equals(partnerLink.getSCAName()) ) { + return partnerLink.getName(); + } // end if + } // end for + return null; + } // end method getServicePartnerlinkName +} diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java new file mode 100644 index 0000000000..5ef4a4c113 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.bpel.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Property; +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. + * + * @version $Rev$ $Date$ + */ +class BPELProcessDefinitionImpl implements BPELProcessDefinition { + private QName name; + private String uri; + private String location; + private boolean unresolved; + private List partnerLinks = new ArrayList(); + private List imports = new ArrayList(); + private List thePortTypes = new ArrayList(); + private List theInterfaces = new ArrayList(); + private List theProperties = new ArrayList(); + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + public List getPartnerLinks() { + return partnerLinks; + } + + public List getImports() { + return imports; + } + + public List getPortTypes() { + return thePortTypes; + } + + public List getInterfaces() { + return theInterfaces; + } + + @Override + public int hashCode() { + return String.valueOf(getName()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof BPELProcessDefinition) { + if (getName() != null) { + return getName().equals(((BPELProcessDefinition)obj).getName()); + } else { + return ((BPELProcessDefinition)obj).getName() == null; + } + } else { + return false; + } + } + + public List getProperties() { + return theProperties; + } // end method getProperties + + /** + * toString() method to produce a useful String to characterize this BPEL Process implementation during debugging + */ + public String toString() { + return "BPEL Process: " + name.toString(); + } +} // end class BPELProcessDefinitionImpl diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java new file mode 100644 index 0000000000..83860f59e5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentModelResolver.java @@ -0,0 +1,401 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.bpel.xml; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.wsdl.Definition; +import javax.wsdl.PortType; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +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; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.wsdl.BPELPartnerLinkTypeExt; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLObject; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * A Model Resolver for BPEL process models. + * + * @version $Rev$ $Date$ + */ +public class BPELDocumentModelResolver implements ModelResolver { + + private WSDLFactory wsdlFactory; + private Contribution contribution; + private Map map = new HashMap(); + + public BPELDocumentModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { + this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + this.contribution = contribution; + } + + public void addModel(Object resolved, ProcessorContext context) { + BPELProcessDefinition process = (BPELProcessDefinition)resolved; + map.put(process.getName(), process); + } + + public Object removeModel(Object resolved, ProcessorContext context) { + return map.remove(((BPELProcessDefinition)resolved).getName()); + } + + public T resolveModel(Class modelClass, T unresolved, ProcessorContext context) { + BPELProcessDefinition resolved = null; + QName qname = ((BPELProcessDefinition)unresolved).getName(); + + // Lookup a definition for the given namespace, from imports + List locations = new ArrayList(); + // Collection of namespace imports with location + Map locationMap = new HashMap(); + for (Import import_ : this.contribution.getImports()) { + if (import_ instanceof NamespaceImport) { + NamespaceImport namespaceImport = (NamespaceImport)import_; + 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, context); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } else { + // We might have multiple imports for the same namespace, + // need to search them in lexical order. + locations.add(namespaceImport.getLocation()); + } + } + } + } + // Search namespace imports with locations in lexical order + Collections.sort(locations); + 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, context); + if (!resolved.isUnresolved()) { + return modelClass.cast(resolved); + } + } + + + // Not found, Lookup a definition for the given namespace, within contribution + resolved = (BPELProcessDefinition) map.get(qname); + + if(resolved.isUnresolved()) { + try { + resolve(resolved, context); + } catch(Exception e) { + //FIXME + } + } + + if (resolved != null) { + return modelClass.cast(resolved); + } + + return (T)unresolved; + } + + 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 + // - one complexity here is that the WSDL definitions hold BPEL extension elements for + // the partnerLinkType declarations - and these must be used in later steps + // + // Step 2 is to take all the partnerLink definitions and establish the PortType being + // used, by tracing through the related partnerLinkType declarations - the PortType is + // effectively a definition of the interface used by the partnerLink. + // - another consideration here is that each partnerLink can involve 2 interfaces, one + // for the forward calls to the process, the other for calls from the process - depending + // on whether the partnerLink is a reference or a service, one of these interfaces is a + // callback interface. + + List theImports = unresolved.getImports(); + Set wsdlDefinitions = getImportedWSDLDefinitions( theImports, contribution.getModelResolver(), context ); + + // Fetch the sets of partner links, port types and interfaces + List thePLinkTypes = getPartnerLinkTypes( wsdlDefinitions, context.getMonitor() ); + Collection theInterfaces = (Collection)new ArrayList(); + Collection 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); + unresolved.getInterfaces().addAll(theInterfaces); + + // Now, for each partnerLink in the BPEL process, find the related partnerLinkType element + List thePartnerLinks = unresolved.getPartnerLinks(); + for (BPELPartnerLinkElement thePartnerLink : thePartnerLinks) { + QName partnerLinkType = thePartnerLink.getPartnerLinkType(); + BPELPartnerLinkTypeElement pLinkType = findPartnerLinkType(partnerLinkType, thePLinkTypes); + if (pLinkType == null) { + error(context.getMonitor(), "PartnerLinkNoMatchingType", thePartnerLink, thePartnerLink.getName()); + } else { + thePartnerLink.setPartnerLinkType(pLinkType); + } + } // end for + + unresolved.setUnresolved(false); + + } // end resolve + + /** + * Get all the WSDL definitions referenced through the import statements of the BPEL process + * @param theImports - a list of the import statements + * @return - a Set containing all the referenced WSDL definitions + */ + private Set getImportedWSDLDefinitions( List theImports, ModelResolver resolver, ProcessorContext context ) { + Set 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, context ); + if( theWSDL != null ) { + theImport.setWSDLDefinition( theWSDL ); + + // Find all the WSDL definitions matching the imported namespace + if( wsdlDefinitions == null ) { + wsdlDefinitions = new HashSet(); + } // end if + + wsdlDefinitions.add(theWSDL.getDefinition()); + } // end if + } // end if + } // end for + + return wsdlDefinitions; + } // end getImportedWSDLDefinitions + + /** + * Resolve a reference to a WSDL, given by a namespace and a location + * @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, ProcessorContext context ) { + + // Resolve the WSDL definition + WSDLDefinition proxy = wsdlFactory.createWSDLDefinition(); + proxy.setUnresolved(true); + proxy.setNamespace(wsdlNamespace); + if (wsdlLocation != null) { + proxy.setLocation(URI.create(wsdlLocation)); + } + WSDLDefinition resolved = resolver.resolveModel(WSDLDefinition.class, proxy, context); + if (resolved != null && !resolved.isUnresolved()) { + return resolved; + } else { + error(context.getMonitor(), "CannotResolveWSDLReference", resolver, wsdlLocation, wsdlNamespace); + return null; + } // end if + } // end resolveWSDLDefinition + + + /** + * Retrieve all the Partner Link types defined in the imported WSDL files + * + * @param wsdlDefinitions - the set of imported WSDL definitions + * @return - a List of PartnerLinkType elements + */ + @SuppressWarnings("unchecked") + private List getPartnerLinkTypes( Set wsdlDefinitions, Monitor monitor ) throws ContributionResolveException { + + List thePLinks = new ArrayList(); + + // The BPEL partnerLinkType elements are extension elements within the WSDL definitions + for (Definition wsdlDefinition: wsdlDefinitions) { + for (ExtensibilityElement theElement : (List)wsdlDefinition.getExtensibilityElements()) { + QName elementType = theElement.getElementType(); + if (elementType.equals(BPELProcessorConstants.LINKTYPE_ELEMENT) || elementType.equals(BPELProcessorConstants.LINKTYPE_ELEMENT_20)) { + BPELPartnerLinkTypeExt pLinkExt = (BPELPartnerLinkTypeExt)theElement; + + // Fetch the name of the partnerLinkType + QName qName = new QName(wsdlDefinition.getTargetNamespace(), pLinkExt.getName()); + 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( count > 1 ) break; + 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); + } else { + pLinkElement.setRole2(pLinkExt.getRoleName(i), pLinkExt.getRolePortType(i), pType); + } // end if + count++; + } // end for + + if (count == 0) { + error(monitor, "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 + + + /** + * 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 + * @return a BPELPartnerLinkTypeElement for the partnerLinkType or null if it cannot be + * found + */ + 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; + } // end for + return null; + } // end findPartnerLinkType + + + /** + * Returns all the portTypes referenced by the process. + * + * @param theImports + * @param theInterfaces + * @param resolver + * @return + * @throws ContributionResolveException + */ + @SuppressWarnings("unchecked") + private Collection getAllPortTypes(List theImports, + Collection theInterfaces, + ModelResolver resolver, + ProcessorContext context) throws ContributionResolveException { + + Set thePortTypes = new HashSet(); + for (BPELImportElement theImport : theImports) { + if (theImport.getImportType().equals(BPELProcessorConstants.WSDL_NS)) { + + // Find all the WSDL definitions matching the imported namespace + List wsdlDefinitions = new ArrayList(); + WSDLDefinition theWSDL = theImport.getWSDLDefinition(); + wsdlDefinitions.add(theWSDL.getDefinition()); + for (WSDLDefinition importedWSDL: theWSDL.getImportedDefinitions()) { + wsdlDefinitions.add(importedWSDL.getDefinition()); + } + for (Definition wsdlDefinition: wsdlDefinitions) { + + Collection portTypes = (Collection)wsdlDefinition.getPortTypes().values(); + + // Create WSDLInterface elements for each unique PortType found + for (PortType portType : portTypes) { + if( thePortTypes.contains(portType) ) continue; + thePortTypes.add( portType ); + + 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 { + 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(context.getMonitor(), "ContributionResolveException", resolver, ce); + throw ce; + } // end try + resolver.addModel(wsdlInterface, context); + theInterfaces.add(wsdlInterface); + } // end if + } // end for + } + } + } // end for + + return thePortTypes; + } // end getAllPortTypes + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + 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); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + 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); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + 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/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java new file mode 100644 index 0000000000..2c50ae98c3 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELDocumentProcessor.java @@ -0,0 +1,355 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.implementation.bpel.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +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; +import org.apache.tuscany.sca.implementation.bpel.BPELFactory; +import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * BPEL document processor responsible for reading a BPEL file and producing necessary model info about it + * + * Handles both BPEL 1.1 documents and BPEL 2.0 documents + * @version $Rev$ $Date$ + */ +public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements URLArtifactProcessor { + + private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + private final BPELFactory factory; + private WSDLFactory WSDLfactory; + private AssemblyFactory assemblyFactory; + + 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() { + return "*.bpel"; + } + + public Class getModelType() { + return BPELProcessDefinition.class; + } + + /** + * Read the BPEL Process definition file from the location identified by an artifact URL + * @param contributionURL - URL of the Contribution containing the Process definition + * @param artifactURI - URI of the artifact containing the BPEL Process definition + * @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, ProcessorContext context) throws ContributionReadException { + BPELProcessDefinition processDefinition = null; + try { + processDefinition = readProcessDefinition(artifactURL, context.getMonitor()); + processDefinition.setURI(artifactURI.toString()); + processDefinition.setUnresolved(true); + } catch (Exception e) { + ContributionReadException ce = new ContributionReadException(e); + error(context.getMonitor(), "ContributionReadException", artifactURL, ce); + } + + return processDefinition; + } + + 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, context); + } + + } // end resolve + + /** + * Read a process definition. + * + * @param doc + * @return + * @throws Exception + */ + private BPELProcessDefinition readProcessDefinition(URL doc, Monitor monitor) throws Exception { + BPELProcessDefinition processDefinition = factory.createBPELProcessDefinition(); + processDefinition.setUnresolved(true); + processDefinition.setLocation(doc.toString()); + + InputStream is = doc.openStream(); + 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 + */ + + // 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!!) + boolean completed = false; + while (!completed) { + switch (reader.next()) { + case START_ELEMENT: + QName qname = reader.getName(); + if (BPELProcessorConstants.PROCESS_ELEMENT.equals(qname) || BPELProcessorConstants.PROCESS_ELEMENT_20.equals(qname)) { + 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, 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(), monitor); + } else if (BPELProcessorConstants.INVOKE_ELEMENT.equals(qname) || BPELProcessorConstants.INVOKE_ELEMENT_20.equals(qname)) { + 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)) { + // deal with variables that are SCA properties through the presence of a sca-bpel:property="yes" attribute + Property aProperty = processVariableElement(reader); + if( aProperty != null ) { + processDefinition.getProperties().add( aProperty ); + } // end if + } // end if + break; + case END_ELEMENT: + qname = reader.getName(); + if (BPELProcessorConstants.PROCESS_ELEMENT.equals(qname) || BPELProcessorConstants.PROCESS_ELEMENT_20.equals(qname)) { + completed = true; + break; + } // end if + } // end switch + } // end while + } finally { + if (reader != null) + reader.close(); + is.close(); + } // end try + + return processDefinition; + } // end readProcessDefinition + + /** + * Processes a BPEL element and creates an SCA element if the variable is + * marked with sca-bpel:property="yes" + * A BPEL element can declare its type in one of 3 ways: + * 1. using @type attribute, which must reference an XSD declared type + * 2. using @element attribute, which must reference an XSD global element + * 3. using @message attribute, which must reference a WSDL defined message type + * @param reader - XMLStreamReader reading the BPEL process + * @throws ContributionReadException + */ + private Property processVariableElement( XMLStreamReader reader) throws ContributionReadException { + String scaProperty = reader.getAttributeValue(BPELProcessorConstants.SCA_BPEL_NS, "property"); + if( "yes".equals(scaProperty)) { + String varName = reader.getAttributeValue(null ,"name"); + String varType = reader.getAttributeValue(null, "type"); + String varElement = reader.getAttributeValue(null, "element"); + String varMessage = reader.getAttributeValue(null, "message"); + // Pass over this variable if there is no name, or if there is no type information + if( varName == null ) return null; + if( varType == null && varElement == null && varMessage == null ) return null; + QName typeQName = getQNameValue( reader, varType ); + QName elementQName = getQNameValue( reader, varElement ); + // TODO deal with properties declared with @message for typing + Property theProperty = assemblyFactory.createProperty(); + theProperty.setName(varName); + theProperty.setXSDType(typeQName); + theProperty.setXSDElement(elementQName); + return theProperty; + } // end if + return null; + + } // end processVariableElement + + /** + * Processes a partnerLink element from the BPEL process and creates a + * BPELPartnerLink object + * + * @param reader + */ + 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"), + reader.getAttributeValue(null, "partnerRole")); + + // See if there are any SCA extension attributes + String scaService = reader.getAttributeValue(BPELProcessorConstants.SCA_BPEL_NS, "service"); + String scaReference = reader.getAttributeValue(BPELProcessorConstants.SCA_BPEL_NS, "reference"); + if ((scaService != null) && (scaReference != null)) { + // It is incorrect to set both service & reference attributes + 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"); + } // end if + + // 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, Monitor monitor) { + BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName); + if (partnerLink == null) { + warning(monitor, "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, Monitor monitor) { + BPELPartnerLinkElement partnerLink = findPartnerLinkByName(partnerLinks, partnerLinkName); + if (partnerLink == null) { + warning(monitor, "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(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); + } + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + 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); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + 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/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java new file mode 100644 index 0000000000..47815f8377 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImplementationProcessor.java @@ -0,0 +1,452 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Collection; +import java.util.List; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.implementation.bpel.BPELFactory; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * Implements a StAX artifact processor for BPEL implementations. + * + * The artifact processor is responsible for processing + * elements in SCA assembly XML composite files and populating the BPEL + * implementation model, resolving its references to other artifacts in the SCA + * contribution, and optionally write the model back to SCA assembly XML. + * + * @version $Rev$ $Date$ + */ +public class BPELImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor { + private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; + private static final String PROCESS = "process"; + private static final String IMPLEMENTATION_BPEL = "implementation.bpel"; + private static final QName IMPLEMENTATION_BPEL_QNAME = new QName(SCA11_NS, IMPLEMENTATION_BPEL); + + private AssemblyFactory assemblyFactory; + private BPELFactory bpelFactory; + private WSDLFactory wsdlFactory; + + + public BPELImplementationProcessor(FactoryExtensionPoint modelFactories) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + this.bpelFactory = modelFactories.getFactory(BPELFactory.class); + } + + public QName getArtifactType() { + // Returns the QName of the XML element processed by this processor + return IMPLEMENTATION_BPEL_QNAME; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return BPELImplementation.class; + } + + public BPELImplementation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + assert IMPLEMENTATION_BPEL_QNAME.equals(reader.getName()); + + // Read an element + BPELImplementation implementation = null; + + // Read the process attribute. + QName process = getAttributeValueNS(reader, PROCESS, context.getMonitor()); + if (process == null) { + return implementation; + } + + // Create and initialize the BPEL implementation model + implementation = bpelFactory.createBPELImplementation(); + implementation.setProcess(process); + implementation.setUnresolved(true); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && IMPLEMENTATION_BPEL_QNAME.equals(reader.getName())) { + break; + } + } + + return implementation; + } + + public void resolve(BPELImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + + if( implementation != null && implementation.isUnresolved()) + { + implementation.setModelResolver(resolver); + + BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(implementation, resolver, context); + //resolveBPELImports(processDefinition, resolver); + if(processDefinition.isUnresolved()) { + error(context.getMonitor(), "BPELProcessNotFound", implementation, processDefinition.getName()); + } else { + implementation.setProcessDefinition(processDefinition); + + // Get the component type from the process definition + generateComponentType( implementation, context.getMonitor() ); + + //set current implementation resolved + implementation.setUnresolved(false); + } + } + + } // end resolve + + public void write( BPELImplementation bpelImplementation, + XMLStreamWriter writer, ProcessorContext context ) throws ContributionWriteException, XMLStreamException { + //FIXME Deal with policy processing... + // Write + // policyProcessor.writePolicyPrefixes(bpelImplementation, writer); + writer.writeStartElement(SCA11_NS, IMPLEMENTATION_BPEL); + // policyProcessor.writePolicyAttributes(bpelImplementation, writer); + + if (bpelImplementation.getProcess() != null) { + writer.writeAttribute(PROCESS, bpelImplementation.getProcess().toString() ); + } + + writer.writeEndElement(); + + } // end write + + 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, context); + } // end resolveBPELProcessDefinition + + private void resolveBPELImports(BPELProcessDefinition processDefinition, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { + for (BPELImportElement bpelImport : processDefinition.getImports()) { + String namespace = bpelImport.getNamespace(); + String location = bpelImport.getLocation(); + + WSDLDefinition wsdl = bpelImport.getWSDLDefinition(); + if (wsdl == null) { + try { + wsdl = wsdlFactory.createWSDLDefinition(); + wsdl.setUnresolved(true); + wsdl.setNamespace(bpelImport.getNamespace()); + wsdl.setLocation(new URI(null, bpelImport.getLocation(), null)); + wsdl = resolver.resolveModel(WSDLDefinition.class, wsdl, context); + + if(! wsdl.isUnresolved()) { + bpelImport.setWSDLDefinition(wsdl); + } else { + //error("BPELProcessNotFound", implementation, processDefinition.getName()); + } + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + } + } + + + /** + * Calculates the component type of the supplied implementation and attaches it to the + * implementation. + * + * @param impl + * @throws ContributionResolveException + */ + private void generateComponentType(BPELImplementation impl, Monitor monitor) 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 + // - 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(), monitor)); + } else { + componentType.getServices().add(generateService(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces(), monitor)); + } // end if + } // end if + } // end for + + // Each SCA Property in the process becomes a Property in the ComponentType + for( Property property : theProcess.getProperties() ) { + componentType.getProperties().add(property); + } // end for + + } // end getComponentType + + /** + * Create an SCA reference for a partnerLink + * @param name - name of the reference + * @param myRolePT - partner link type of myRole + * @param partnerRolePT - partner link type of partnerRole + * @param theInterfaces - list of WSDL interfaces associated with the BPEL process + * @return + */ + private Reference generateReference( String name, PortType myRolePT, + PortType partnerRolePT, Collection theInterfaces, Monitor monitor) 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 + PortType callPT = null; + PortType callbackPT = null; + if (partnerRolePT != null) { + callPT = partnerRolePT; + // If the 2 port types are not the same one, there is a callback... + if (myRolePT != null) { + if (!myRolePT.getQName().equals(partnerRolePT.getQName())) { + callbackPT = myRolePT; + } // end if + } // end if + } else if (myRolePT != null) { + callPT = myRolePT; + } // end if + + // No interfaces mean an error + if (callPT == null && callbackPT == null) { + error(monitor, "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) { + // 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; + } // end for + if (callInterface == null) { + error(monitor, "NoInterfaceForPortType", theInterfaces, callPT.getQName().toString()); + } else + reference.getInterfaceContract().setInterface(callInterface); + } // end if + + // 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) { + WSDLInterface callbackInterface = null; + for (WSDLInterface anInterface : theInterfaces) { + if (anInterface.getPortType().getQName().equals(callbackPT.getQName())) + callbackInterface = anInterface; + } // end for + if (callbackInterface == null) { + error(monitor, "NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); + } else + reference.getInterfaceContract().setCallbackInterface(callbackInterface); + } // end if + + return reference; + } // end generateReference + + /** + * Create an SCA service for a partnerLink + * @param name - name of the service + * @param myRolePT - partner link type of myRole + * @param partnerRolePT - partner link type of partnerRole + * @param theInterfaces - list of WSDL interfaces associated with the BPEL process + * @return + */ + private Service generateService( String name, PortType myRolePT, + PortType partnerRolePT, Collection theInterfaces, Monitor monitor ) + throws ContributionResolveException { + Service service = assemblyFactory.createService(); + WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); + service.setInterfaceContract(interfaceContract); + + // 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 + 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; + } // end if + + // No interfaces mean an error + if (callPT == null && callbackPT == null) { + error(monitor, "MyRolePartnerRoleNull", theInterfaces); + } // end if + + 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; + } // end for + if (callInterface == null) { + error(monitor, "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 is not the same as the port type for my role + if (callbackPT != null) { + WSDLInterface callbackInterface = null; + for (WSDLInterface anInterface : theInterfaces) { + if (anInterface.getPortType().getQName().equals(callbackPT.getQName())) + callbackInterface = anInterface; + } // end for + if (callbackInterface == null) { + error(monitor, "NoInterfaceForPortType", theInterfaces, callbackPT.getQName().toString()); + } else + service.getInterfaceContract().setCallbackInterface(callbackInterface); + } // end if + + return service; + } // end generateService + + /** + * Returns a QName from its string representation in a named attribute of an XML element + * supplied in an XMLStreamReader + * + * QName attributes of an XML element (such as BPEL process) is presented in one of + * two alternative formats: + * 1) In the form of a local name with a prefix, with the prefix referencing a namespace + * URI declaration elsewhere in the composite (typically on the composite element) + * + * ie: nms:SomeName + * xmlns:nms="http://example.com/somenamespace" + * + * 2) In the XML Namespaces recommendation format (see http://jclark.com/xml/xmlns.htm ) + * where the namespace URI and the local name are encoded into a single string, with the + * namespace URI enclosed between a pair of braces {...} + * + * ie: {http://example.com/somenamespace}SomeName + */ + private QName getAttributeValueNS(XMLStreamReader reader, String attribute, Monitor monitor) { + String fullValue = reader.getAttributeValue(null, attribute); + if (fullValue == null) { + error(monitor, "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(monitor, "AttributeWithoutNamespace", reader, attribute, fullValue); + return null; + } + } // endif + + // Deal with the attribute in the local name + prefix format + if (fullValue.indexOf(":") < 0) { + 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(monitor, "AttributeUnrecognizedNamespace", reader, attribute, fullValue); + return null; + } + return new QName(nsUri, name, prefix); + } + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + 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/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java new file mode 100644 index 0000000000..959d1ec5d5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELImportElement.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel.xml; + +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; + +/** + * Represents an element in a BPEL process + * - this has attributes: + * location + * importType + * namespace + * + * @version $Rev$ $Date$ + */ +public class BPELImportElement { + + private String location; + private String importType; + private String namespace; + private WSDLDefinition theWSDL = null; + + public BPELImportElement(String location, String importType, String namespace) { + this.location = location; + this.importType = importType; + this.namespace = namespace; + } + + public String getImportType() { + return importType; + } + + public String getLocation() { + return location; + } + + public String getNamespace() { + return namespace; + } + + public void setWSDLDefinition(WSDLDefinition theDefinition) { + theWSDL = theDefinition; + } + + public WSDLDefinition getWSDLDefinition() { + return theWSDL; + } + +} // end class BPELImportElement diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java new file mode 100644 index 0000000000..ea645e1304 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkElement.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel.xml; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +/** + * Represents a element in a BPEL process + * - this has attributes: + * name + * partnerLinkType + * myRole + * partnerRole + * - plus zero or more property elements as children + * + * The partnerlink may also be given an SCA Type - either of service or of reference - this must + * generally be calculated and set on the partnerLink by inspecting the BPEL process + * + * @version $Rev$ $Date$ + */ +public class BPELPartnerLinkElement { + + private String REFERENCE_TYPE = "reference"; + private String SERVICE_TYPE = "service"; + private String name; + private QName partnerLinkType; + private BPELPartnerLinkTypeElement pLinkType = null; + private String myRole; + private String partnerRole; + private String scaName; // Holds the SCA reference or service name + private String scaType = null; // Holds the SCA type = null | service | reference + + public BPELPartnerLinkElement(String name, + QName partnerLinkType, + String myRole, + String partnerRole ) { + this.name = name; + this.partnerLinkType = partnerLinkType; + this.myRole = myRole; + this.partnerRole = partnerRole; + + scaName = null; + } + + public QName getPartnerLinkType() { + return partnerLinkType; + } + + public void setPartnerLinkType( BPELPartnerLinkTypeElement pLinkType ) { + this.pLinkType = pLinkType; + } + + + public PortType getMyRolePortType() { + return getRolePortType( myRole ); + } + + public PortType getPartnerRolePortType() { + return getRolePortType( partnerRole ); + } + + private PortType getRolePortType( String theRole ) { + if (theRole == null || theRole.length() == 0) { + return null; + } // end if + if( pLinkType == null ) { + throw new IllegalStateException("BPELPartnerLinkElement: " + this.name + " has no Partner Link type object set"); + } // 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() { + return name; + } + + public String getMyRole() { + return myRole; + } + + public String getPartnerRole() { + return partnerRole; + } + + public void setSCAName( String name ) { + scaName = name; + } + + public String getSCAName() { + return scaName; + } + + public boolean isSCATyped() { + return ( !(scaType == null) ); + } + + public void setAsReference( String name ) { + scaType = REFERENCE_TYPE; + scaName = name; + } + + public void setAsService( String name ) { + scaType = SERVICE_TYPE; + scaName = name; + } + + public String querySCAType() { + return scaType; + } + +} // end class BPELPartnerLinkElement diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java new file mode 100644 index 0000000000..8786837e97 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELPartnerLinkTypeElement.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */package org.apache.tuscany.sca.implementation.bpel.xml; + + import javax.wsdl.PortType; +import javax.wsdl.extensions.ExtensibilityElement; +import javax.xml.namespace.QName; + +/** + * Represents a element related to a BPEL process + * - this has attributes: + * name + * Role1 name + * Role1 portType + * Role2 name + * Role2 portType + * + * - in the XML the 2 roles are child elements of the partnerLinkType element, but there + * seems little point in reflecting this back into this model - it is simpler to include + * both roles within the representation of the partnerLinkType itself + * + * @version $Rev$ $Date$ + */ +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 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; + } + + public void setElementType(QName elementType) { + this.elementType = elementType; + } + + public void setRequired(java.lang.Boolean required) { + this.required = required; + } + + /** + * toString method to return a description of this BPELPartnerLinkType useful for debugging + */ + public String toString() { + return "BPELPartnerLinkType: " + name.toString(); + } // end method toString + +} // end BPELPartnerLinkType diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java new file mode 100644 index 0000000000..952ba9fe78 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/xml/BPELProcessorConstants.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel.xml; + +import javax.xml.namespace.QName; + + +/** + * BPEL Constants + * + * @version $Rev$ $Date$ + */ +public class BPELProcessorConstants { + static final String SCA_BPEL_NS = "http://docs.oasis-open.org/ns/opencsa/sca-bpel/200801"; + static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/"; + + // BPEL 1.1 + static final String BPEL_NS = "http://schemas.xmlsoap.org/ws/2004/03/business-process/"; + static final String BPEL_PLINK_NS = "http://schemas.xmlsoap.org/ws/2004/03/partner-link/"; + final static String NAME_ELEMENT = "name"; + static final String LINKTYPE_NAME = "partnerLinkType"; + final static String TARGET_NAMESPACE = "targetNamespace"; + static final QName PROCESS_ELEMENT = new QName(BPEL_NS, "process"); + static final QName PARTNERLINK_ELEMENT = new QName(BPEL_NS, "partnerLink"); + static final QName ONEVENT_ELEMENT = new QName(BPEL_NS, "onEvent"); + static final QName RECEIVE_ELEMENT = new QName(BPEL_NS, "receive"); + static final QName ONMESSAGE_ELEMENT = new QName(BPEL_NS, "onMessage"); + static final QName INVOKE_ELEMENT = new QName(BPEL_NS, "invoke"); + static final QName IMPORT_ELEMENT = new QName(BPEL_NS, "import"); + static final QName VARIABLE_ELEMENT = new QName(BPEL_NS, "variable"); + static final QName LINKTYPE_ELEMENT = new QName(BPEL_PLINK_NS, LINKTYPE_NAME); + + // BPEL 2.0 + static final String BPEL_NS_20 = "http://docs.oasis-open.org/wsbpel/2.0/process/executable"; + static final String BPEL_PLINK_NS_20 = "http://docs.oasis-open.org/wsbpel/2.0/plnktype"; + static final QName PROCESS_ELEMENT_20 = new QName(BPEL_NS_20, "process"); + static final QName PARTNERLINK_ELEMENT_20 = new QName(BPEL_NS_20, "partnerLink"); + static final QName ONEVENT_ELEMENT_20 = new QName(BPEL_NS_20, "onEvent"); + static final QName RECEIVE_ELEMENT_20 = new QName(BPEL_NS_20, "receive"); + static final QName ONMESSAGE_ELEMENT_20 = new QName(BPEL_NS_20, "onMessage"); + static final QName INVOKE_ELEMENT_20 = new QName(BPEL_NS_20, "invoke"); + static final QName IMPORT_ELEMENT_20 = new QName(BPEL_NS_20, "import"); + static final QName VARIABLE_ELEMENT_20 = new QName(BPEL_NS_20, "variable"); + static final QName LINKTYPE_ELEMENT_20 = new QName(BPEL_PLINK_NS_20, LINKTYPE_NAME); +} diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..5b53ed1ee0 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.implementation.bpel.xml.BPELImplementationProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#implementation.bpel,model=org.apache.tuscany.sca.implementation.bpel.BPELImplementation diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor new file mode 100644 index 0000000000..1e11d2fc0c --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension +org.apache.tuscany.sca.implementation.bpel.xml.BPELDocumentProcessor;type=.bpel,model=org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..d5b5b15984 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.implementation.bpel.xml.BPELDocumentModelResolver;model=org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition + diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory new file mode 100644 index 0000000000..34af3316d5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.implementation.bpel.impl.BPELFactoryImpl + diff --git a/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties new file mode 100644 index 0000000000..b6d8bdc0f1 --- /dev/null +++ b/sca-java-2.x/trunk/modules/implementation-bpel/src/main/resources/impl-bpel-validation-messages.properties @@ -0,0 +1,34 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +CannotResolveWSDLReference = BPELDocumentProcessor:resolve - unable to resolve WSDL referenced by BPEL import WSDL location: {0} WSDLNamespace: {1} +ContributionReadException = ContributionReadException occured due to : +PartnerLinkNoMatchingType = PartnerLink {0} has no matching partner link type +PartnerLinkTypeNoRoles = PartnerLinkType {0} has no Roles defined +ContributionResolveException = ContributionResolveException occured due to : +PartnerLinkHasBothAttr = BPEL PartnerLink {0} has both sca:reference and sca:service attributes set +ReferencePartnerLinkNotInList = BPEL TypeLoader - element references partnerLink {0} not in the list +MyRolePartnerRoleNull = Error: myRole and partnerRole port types are both null +NoInterfaceForPortType = Interface not found for port type {0} +AttributeProcessMissing = Attribute 'process' is missing. +AttributeWithoutNamespace = Attribute {0} with value {1} in your composite should be of the form {namespaceURI}localname +AttributeWithoutPrefix = Attribute {0} with value {1} in your composite should be prefixed (process=\"prefix:name\"). +AttributeUnrecognizedNamespace = Attribute {0} with value {1} in your composite has un unrecognized namespace prefix. +BPELProcessNotFound = Can't find BPEL Process : {0} \ No newline at end of file -- cgit v1.2.3