From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/implementation/bpel/BPELFactory.java | 41 ++++ .../implementation/bpel/BPELImplementation.java | 54 +++++ .../implementation/bpel/BPELProcessDefinition.java | 58 ++++++ .../implementation/bpel/DefaultBPELFactory.java | 53 +++++ .../bpel/impl/BPELDocumentProcessor.java | 131 ++++++++++++ .../bpel/impl/BPELImplementationImpl.java | 194 +++++++++++++++++ .../bpel/impl/BPELImplementationProcessor.java | 225 ++++++++++++++++++++ .../bpel/impl/BPELProcessDefinitionImpl.java | 100 +++++++++ .../bpel/impl/ODEProcessException.java | 42 ++++ .../implementation/bpel/ode/EmbeddedODEServer.java | 232 +++++++++++++++++++++ .../implementation/bpel/ode/GeronimoTxFactory.java | 48 +++++ .../implementation/bpel/ode/ODEBindingContext.java | 62 ++++++ .../sca/implementation/bpel/ode/ODEDeployment.java | 43 ++++ .../bpel/ode/ODEInitializationException.java | 41 ++++ .../bpel/ode/ODEMessageExchangeContext.java | 46 ++++ .../bpel/ode/ODEShutdownException.java | 41 ++++ .../bpel/provider/BPELImplementationProvider.java | 117 +++++++++++ .../BPELImplementationProviderFactory.java | 61 ++++++ .../implementation/bpel/provider/BPELInvoker.java | 214 +++++++++++++++++++ 19 files changed, 1803 insertions(+) create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java create mode 100644 branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java (limited to 'branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java') diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java new file mode 100644 index 0000000000..2fb422c1b5 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java @@ -0,0 +1,41 @@ +/* + * 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/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java new file mode 100644 index 0000000000..e18fabc484 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java @@ -0,0 +1,54 @@ +/* + * 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.Implementation; + +/** + * The model representing the BPEL implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public interface BPELImplementation extends Implementation { + + /** + * Get the BPEL process Name + */ + 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); +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java new file mode 100644 index 0000000000..f52436255a --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java @@ -0,0 +1,58 @@ +/* + * 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.net.URL; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Base; + + +/** + * The BPEL process definition. + * + * @version $Rev$ $Date$ + */ +public interface BPELProcessDefinition extends Base { + + /** + * Get the BPEL process Name + */ + public QName getName(); + + /** + * Set the BPEL process Name + * @param processName process QName + */ + public void setName(QName name); + + /** + * Get the URI for the process location + * @return + */ + URL getLocation(); + + /** + * Set the URI for the process location + * @param url + */ + void setLocation(URL location); +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java new file mode 100644 index 0000000000..a0e9fd9c06 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java @@ -0,0 +1,53 @@ +/* + * 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 org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.implementation.bpel.impl.BPELImplementationImpl; +import org.apache.tuscany.sca.implementation.bpel.impl.BPELProcessDefinitionImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; + +/** + * A default factory for the BPEL implementation model. + * + * @version $Rev$ $Date$ + */ +public class DefaultBPELFactory implements BPELFactory { + + private AssemblyFactory assemblyFactory; + private WSDLFactory wsdlFactory; + + public DefaultBPELFactory(ModelFactoryExtensionPoint modelFactories) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + } + + public BPELImplementation createBPELImplementation() { + return new BPELImplementationImpl(assemblyFactory, wsdlFactory); + } + + public BPELProcessDefinition createBPELProcessDefinition() { + return new BPELProcessDefinitionImpl(); + } + + + +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java new file mode 100644 index 0000000000..352cff0425 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java @@ -0,0 +1,131 @@ +/* + * 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.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.implementation.bpel.BPELFactory; +import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; + +/** + * BPEL document processor responsible for reading a BPEL file and producing necessary model info about it + * + * @version $Rev$ $Date$ + */ +public class BPELDocumentProcessor extends BaseStAXArtifactProcessor implements URLArtifactProcessor { + public final static QName BPEL_PROCESS_DEFINITION = new QName("http://schemas.xmlsoap.org/ws/2004/03/business-process/", "process"); + public final static String NAME_ELEMENT = "name"; + + private final static XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + private final BPELFactory factory; + + public BPELDocumentProcessor(ModelFactoryExtensionPoint modelFactories) { + this.factory = modelFactories.getFactory(BPELFactory.class); + } + + public String getArtifactType() { + return "*.bpel"; + } + + public Class getModelType() { + return BPELProcessDefinition.class; + } + + public BPELProcessDefinition read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + BPELProcessDefinition processDefinition = null; + try { + //for now we are just using process name + //and relying on componentType file for service definition + //so it's ok to set resolved for now + processDefinition = indexRead(artifactURL); + processDefinition.setUnresolved(false); + } catch (Exception e) { + throw new ContributionReadException(e); + } + + return processDefinition; + } + + + public void resolve(BPELProcessDefinition model, ModelResolver resolver) throws ContributionResolveException { + // TODO Auto-generated method stub + } + + /** + * Read the namespace for the WSDL definition and inline schemas + * + * @param doc + * @return + * @throws IOException + * @throws XMLStreamException + */ + protected BPELProcessDefinition indexRead(URL doc) throws Exception { + BPELProcessDefinition processDefinition = factory.createBPELProcessDefinition(); + processDefinition.setUnresolved(true); + processDefinition.setLocation(doc); + + InputStream is = doc.openStream(); + XMLStreamReader reader = null; + try { + reader = inputFactory.createXMLStreamReader(is); + int eventType = reader.getEventType(); + while (true) { + if (eventType == XMLStreamConstants.START_ELEMENT) { + QName elementName = reader.getName(); + if (BPEL_PROCESS_DEFINITION.equals(elementName)) { + QName processName = new QName(getString(reader, org.apache.tuscany.sca.assembly.xml.Constants.TARGET_NAMESPACE), getString(reader, NAME_ELEMENT)); + processDefinition.setName(processName); + break; + } + } + if (reader.hasNext()) { + eventType = reader.next(); + } else { + break; + } + } + } finally { + if(reader != null) { + reader.close(); + } + is.close(); + } + + return processDefinition; + } + + +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java new file mode 100644 index 0000000000..ef27c7e121 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java @@ -0,0 +1,194 @@ +/* + * 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.io.File; +import java.io.InputStream; +import java.net.URI; +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.xml.namespace.QName; + +import org.apache.ode.bpel.evt.BpelEvent; +import org.apache.ode.bpel.iapi.Endpoint; +import org.apache.ode.bpel.iapi.ProcessConf; +import org.apache.ode.bpel.iapi.ProcessState; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.impl.ComponentTypeImpl; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.w3c.dom.Node; + +/** + * The model representing a BPEL implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public class BPELImplementationImpl extends ComponentTypeImpl implements BPELImplementation { + + private QName _processName; + private BPELProcessDefinition _processDefinition; + + private boolean unresolved; + + /** + * Constructs a new BPEL implementation. + */ + public BPELImplementationImpl(AssemblyFactory assemblyFactory, + WSDLFactory wsdlFactory) { + + } + + public QName getProcess() { + return _processName; + } + + public void setProcess(QName processName) { + _processName = processName; + } + + public BPELProcessDefinition getProcessDefinition() { + return this._processDefinition; + } + + public void setProcessDefinition(BPELProcessDefinition processDefinition) { + this._processDefinition = processDefinition; + } + + @Override + public String getURI() { + // The sample BPEL implementation does not have a URI + return null; + } + + @Override + public void setURI(String uri) { + // The sample BPEL implementation does not have a URI + } + + @Override + public ConstrainingType getConstrainingType() { + // The sample BPEL implementation does not support constrainingTypes + return null; + } + + @Override + public List getProperties() { + // The sample BPEL implementation does not support properties + return Collections.emptyList(); + } + + + @Override + public List getReferences() { + // The sample BPEL implementation does not support properties + return Collections.emptyList(); + } + + public boolean isUnresolved() { + return this.unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + private class ProcessConfImpl implements ProcessConf { + public QName getProcessId() { + return _processName; + } + + public QName getType() { + return _processName; + } + + public long getVersion() { + // TODO Versioniong? + return 0; + } + + public boolean isTransient() { + return false; + } + + public InputStream getCBPInputStream() { + return null; //new ByteArrayInputStream(_compiledProcess); + } + + public String getBpelDocument() { + return null; + } + + public URI getBaseURI() { + return null; + } + + public Date getDeployDate() { + return null; + } + + public String getDeployer() { + return null; + } + + public ProcessState getState() { + return null; + } + + public List getFiles() { + return null; + } + + public Map getProperties() { + return null; + } + + public String getPackage() { + return null; + } + + public Definition getDefinitionForService(QName qName) { + return null; + } + + public Definition getDefinitionForPortType(QName qName) { + return null; + } + + public Map getProvideEndpoints() { + return null; + } + + public Map getInvokeEndpoints() { + return null; + } + + public boolean isEventEnabled(List strings, BpelEvent.TYPE type) { + return true; + } + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java new file mode 100644 index 0000000000..6816f500b3 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java @@ -0,0 +1,225 @@ +/* + * 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 static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.util.HashMap; +import java.util.Map; + +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.Property; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +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.implementation.bpel.DefaultBPELFactory; + +/** + * 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 QName IMPLEMENTATION_BPEL = new QName(Constants.SCA10_NS, "implementation.bpel"); + + private AssemblyFactory assemblyFactory; + private BPELFactory bpelFactory; + + public BPELImplementationProcessor(ModelFactoryExtensionPoint modelFactories) { + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + this.bpelFactory = new DefaultBPELFactory(modelFactories); + } + + public QName getArtifactType() { + // Returns the qname of the XML element processed by this processor + return IMPLEMENTATION_BPEL; + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return BPELImplementation.class; + } + + public BPELImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + assert IMPLEMENTATION_BPEL.equals(reader.getName()); + + // Read an element + + // Read the process attribute. + QName process = getAttributeValueNS(reader, "process"); + + + // Create an initialize the BPEL implementation model + BPELImplementation implementation = bpelFactory.createBPELImplementation(); + implementation.setProcess(process); + //FIXME:lresende + //implementation.setCompiledProcess(compiledProcess.toByteArray()); + implementation.setUnresolved(true); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && IMPLEMENTATION_BPEL.equals(reader.getName())) { + break; + } + } + + return implementation; + } + + public void resolve(BPELImplementation impl, ModelResolver resolver) throws ContributionResolveException { + if( impl != null && impl.isUnresolved()) { + BPELProcessDefinition processDefinition = resolveBPELProcessDefinition(impl, resolver); + if(processDefinition.isUnresolved()) { + throw new ContributionResolveException("Can't find BPEL Process : " + processDefinition.getName()); + } + + impl.setProcessDefinition(processDefinition); + + //resolve component type + mergeComponentType(resolver, impl); + + //set current implementation resolved + impl.setUnresolved(false); + } + + } + + public void write(BPELImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException { + //FIXME Implement + } + + private BPELProcessDefinition resolveBPELProcessDefinition(BPELImplementation impl, ModelResolver resolver) throws ContributionResolveException { + QName processName = impl.getProcess(); + BPELProcessDefinition processDefinition = this.bpelFactory.createBPELProcessDefinition(); + processDefinition.setName(processName); + processDefinition.setUnresolved(true); + + return resolver.resolveModel(BPELProcessDefinition.class, processDefinition); + } + + + /** + * Merge the componentType from introspection and external file + * @param resolver + * @param impl + */ + private void mergeComponentType(ModelResolver resolver, BPELImplementation impl) { + // FIXME: Need to clarify how to merge + ComponentType componentType = getComponentType(resolver, impl); + if (componentType != null && !componentType.isUnresolved()) { + /* + Map refMap = new HashMap(); + for (Reference ref : impl.getReferences()) { + refMap.put(ref.getName(), ref); + } + for (Reference reference : componentType.getReferences()) { + refMap.put(reference.getName(), reference); + } + impl.getReferences().clear(); + impl.getReferences().addAll(refMap.values()); + + // Try to match references by type + Map refMembers = impl.getReferenceMembers(); + for (Reference ref : impl.getReferences()) { + if (ref.getInterfaceContract() != null) { + Interface i = ref.getInterfaceContract().getInterface(); + if (i instanceof JavaInterface) { + Class type = ((JavaInterface)i).getJavaClass(); + if (!refMembers.containsKey(ref.getName())) { + JavaElementImpl e = getMemeber(impl, ref.getName(), type); + if (e != null) { + refMembers.put(ref.getName(), e); + } + } + } + } + }*/ + + Map serviceMap = new HashMap(); + for (Service svc : impl.getServices()) { + if(svc != null) { + serviceMap.put(svc.getName(), svc); + } + } + for (Service service : componentType.getServices()) { + //set default dataBinding to DOM + service.getInterfaceContract().getInterface().resetDataBinding(DOMDataBinding.NAME); + + serviceMap.put(service.getName(), service); + } + impl.getServices().clear(); + impl.getServices().addAll(serviceMap.values()); + + Map propMap = new HashMap(); + for (Property prop : impl.getProperties()) { + propMap.put(prop.getName(), prop); + } + } + } + + + private ComponentType getComponentType(ModelResolver resolver, BPELImplementation impl) { + String bpelName = impl.getProcess().getLocalPart().toLowerCase(); + String componentTypeURI = bpelName.replace('.', '/') + ".componentType"; + ComponentType componentType = assemblyFactory.createComponentType(); + componentType.setUnresolved(true); + componentType.setURI(componentTypeURI); + componentType = resolver.resolveModel(ComponentType.class, componentType); + if (!componentType.isUnresolved()) { + return componentType; + } + return null; + } + + private QName getAttributeValueNS(XMLStreamReader reader, String attribute) { + String fullValue = reader.getAttributeValue(null, "process"); + if (fullValue.indexOf(":") < 0) + throw new ODEProcessException("Attribute " + attribute + " with value " + fullValue + + " in your composite should be prefixed (process=\"prefix:name\")."); + String prefix = fullValue.substring(0, fullValue.indexOf(":")); + String name = fullValue.substring(fullValue.indexOf(":") + 1); + String nsUri = reader.getNamespaceContext().getNamespaceURI(prefix); + if (nsUri == null) + throw new ODEProcessException("Attribute " + attribute + " with value " + fullValue + + " in your composite has un unrecognized namespace prefix."); + return new QName(nsUri, name, prefix); + } + +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java new file mode 100644 index 0000000000..5c0b00adbc --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java @@ -0,0 +1,100 @@ +/* + * 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.net.URL; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.implementation.bpel.BPELProcessDefinition; + +/** + * The BPEL process definition implementation. + * + * @version $Rev$ $Date$ + */ +public class BPELProcessDefinitionImpl implements BPELProcessDefinition { + private QName name; + private URL location; + private boolean unresolved; + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public URL getLocation() { + return this.location; + } + + public void setLocation(URL location) { + this.location = location; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + public void compile() { + /* + String bpelFile = reader.getAttributeValue(null, "file"); // FIXME: + + // Resolving the BPEL file and compiling it + URL bpelURL = getClass().getClassLoader().getResource(bpelFile); + if (bpelURL == null) + throw new ODEProcessException("Couldn't find referenced bpel file " + bpelFile); + BpelC bpelc = BpelC.newBpelCompiler(); + ByteArrayOutputStream compiledProcess = new ByteArrayOutputStream(); + bpelc.setOutputStream(compiledProcess); + try { + bpelc.compile(new File(bpelURL.getFile())); + } catch (IOException e) { + e.printStackTrace(); + } + */ + } + + @Override + public int hashCode() { + return String.valueOf(getName()).hashCode(); + } + + @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; + } + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java new file mode 100644 index 0000000000..017e3d85ef --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.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.impl; + +/** + * Thrown when a process can't be compiled properly or when its descriptors + * are invalid. + * + * @version $Rev$ $Date$ + */ +public class ODEProcessException extends RuntimeException { + private static final long serialVersionUID = 1047893235216756186L; + + public ODEProcessException(String message) { + super(message); + } + + public ODEProcessException(String message, Throwable cause) { + super(message, cause); + } + + public ODEProcessException(Throwable cause) { + super(cause); + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java new file mode 100644 index 0000000000..61f1b94871 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java @@ -0,0 +1,232 @@ +/* + * 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.ode; + +import java.io.File; +import java.net.URL; +import java.util.Collection; +import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import javax.transaction.TransactionManager; +import javax.xml.namespace.QName; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.ode.bpel.dao.BpelDAOConnectionFactoryJDBC; +import org.apache.ode.bpel.engine.BpelServerImpl; +import org.apache.ode.bpel.engine.CountLRUDehydrationPolicy; +import org.apache.ode.bpel.iapi.ProcessConf; +import org.apache.ode.bpel.iapi.ProcessStore; +import org.apache.ode.bpel.iapi.ProcessStoreEvent; +import org.apache.ode.bpel.iapi.ProcessStoreListener; +import org.apache.ode.bpel.iapi.Scheduler; +import org.apache.ode.bpel.memdao.BpelDAOConnectionFactoryImpl; +import org.apache.ode.il.config.OdeConfigProperties; +import org.apache.ode.il.dbutil.Database; +import org.apache.ode.scheduler.simple.JdbcDelegate; +import org.apache.ode.scheduler.simple.SimpleScheduler; +import org.apache.ode.store.ProcessStoreImpl; +import org.apache.ode.utils.GUID; + +/** + * Embedded ODE process server + * + * @version $Rev$ $Date$ + */ +public class EmbeddedODEServer { + protected final Log __log = LogFactory.getLog(getClass()); + + private boolean _initialized; + + private OdeConfigProperties _config; + + private TransactionManager _txMgr; + + private Database _db; + + private File _workRoot; + + private BpelDAOConnectionFactoryJDBC _daoCF; + + private BpelServerImpl _bpelServer; + + protected ProcessStore store; + + private ExecutorService _executor; + + private Scheduler _scheduler; + + + public EmbeddedODEServer(TransactionManager txMgr) { + _txMgr = txMgr; + } + + public void init() throws ODEInitializationException { + _config = new OdeConfigProperties(new Properties(), "ode-sca"); + + // Setting work root as the directory containing our database (wherever in the classpath) + URL dbLocation = getClass().getClassLoader().getResource("jpadb"); + if (dbLocation == null) + throw new ODEInitializationException("Couldn't find database in the classpath"); + _workRoot = new File(dbLocation.getFile()).getParentFile(); + + initTxMgr(); + initPersistence(); + initBpelServer(); + + try { + _bpelServer.start(); + } catch (Exception ex) { + String errmsg = "An error occured during the ODE BPEL server startup."; + __log.error(errmsg, ex); + throw new ODEInitializationException(errmsg, ex); + } + + __log.info("ODE BPEL server started."); + _initialized = true; + } + + private void initTxMgr() { + if(_txMgr == null) { + try { + GeronimoTxFactory txFactory = new GeronimoTxFactory(); + _txMgr = txFactory.getTransactionManager(); + } catch (Exception e) { + __log.fatal("Couldn't initialize a transaction manager using Geronimo's transaction factory.", e); + throw new ODEInitializationException("Couldn't initialize a transaction manager using " + "Geronimo's transaction factory.", e); + } + } + } + + private void initPersistence() { + _db = new Database(_config); + _db.setTransactionManager(_txMgr); + _db.setWorkRoot(_workRoot); + + try { + _db.start(); + _daoCF = _db.createDaoCF(); + } catch (Exception ex) { + String errmsg = "Error while configuring ODE persistence."; + __log.error(errmsg, ex); + throw new ODEInitializationException(errmsg, ex); + } + } + + private void initBpelServer() { + if (__log.isDebugEnabled()) { + __log.debug("ODE initializing"); + } + if (_config.getThreadPoolMaxSize() == 0) + _executor = Executors.newCachedThreadPool(); + else + _executor = Executors.newFixedThreadPool(_config.getThreadPoolMaxSize()); + + _bpelServer = new BpelServerImpl(); + _scheduler = createScheduler(); + _scheduler.setJobProcessor(_bpelServer); + + _bpelServer.setDaoConnectionFactory(_daoCF); + _bpelServer.setInMemDaoConnectionFactory(new BpelDAOConnectionFactoryImpl(_scheduler)); + // _bpelServer.setEndpointReferenceContext(new EndpointReferenceContextImpl(this)); + _bpelServer.setMessageExchangeContext(new ODEMessageExchangeContext(this)); + _bpelServer.setBindingContext(new ODEBindingContext(this)); + _bpelServer.setScheduler(_scheduler); + if (_config.isDehydrationEnabled()) { + CountLRUDehydrationPolicy dehy = new CountLRUDehydrationPolicy(); + _bpelServer.setDehydrationPolicy(dehy); + } + + store = new ProcessStoreImpl(_db.getDataSource(), "jpa", true); + store.registerListener(new ProcessStoreListener() { + public void onProcessStoreEvent(ProcessStoreEvent event) { + // bounce the process + _bpelServer.unregister(event.pid); + if (event.type != ProcessStoreEvent.Type.UNDEPLOYED) { + ProcessConf conf = (ProcessConf) store.getProcessConfiguration(event.pid); + // Test processes always run with in-mem DAOs + // conf.setTransient(true); //FIXME: what should we use for ProcessConfImpl + _bpelServer.register(conf); + } + } + }); + + _bpelServer.init(); + } + + public void stop() throws ODEShutdownException { + try { + _bpelServer.stop(); + } catch (Exception ex) { + String errmsg = "An error occured during the ODE BPEL server shutdown."; + __log.error(errmsg, ex); + throw new ODEInitializationException(errmsg, ex); + } + } + + protected Scheduler createScheduler() { + SimpleScheduler scheduler = new SimpleScheduler(new GUID().toString(),new JdbcDelegate(_db.getDataSource())); + scheduler.setTransactionManager(_txMgr); + + return scheduler; + } + + public boolean isInitialized() { + return _initialized; + } + + public BpelServerImpl getBpelServer() { + return _bpelServer; + } + + public Scheduler getScheduler() { + return _scheduler; + } + + public void deploy(ODEDeployment d) { + Collection procs; + + try { + procs = store.deploy(d.deployDir); + + // _deployed.add(d); + } catch (Exception ex) { + System.out.println(d + "DEPLOY: Unexpected exception: " + ex.getMessage()); + return; + } + + try { + for (QName procName : procs) { + ProcessConf conf = (ProcessConf) store.getProcessConfiguration(procName); + // Test processes always run with in-mem DAOs + //conf.setTransient(true); //FIXME: what should we use for ProcessConfImpl + _bpelServer.register(conf); + } + } catch (Exception ex) { + System.out.println(d + "REGISTER: Unexpected exception: " + ex.getMessage()); + } + } + + public void undeploy(ODEDeployment d) { + //TODO + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java new file mode 100644 index 0000000000..bf2f29c585 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java @@ -0,0 +1,48 @@ +/* + * 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.ode; + +import javax.transaction.TransactionManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Geronimo transaction factory + * + * @version $Rev$ $Date$ + */ +public class GeronimoTxFactory { + private static final Log __log = LogFactory.getLog(GeronimoTxFactory.class); + + /* Public no-arg contructor is required */ + public GeronimoTxFactory() { + } + + public TransactionManager getTransactionManager() { + __log.info("Using embedded Geronimo transaction manager"); + try { + Object obj = new org.apache.geronimo.transaction.manager.GeronimoTransactionManager(); + return (TransactionManager) obj; + } catch (Exception except) { + throw new IllegalStateException("Unable to instantiate Geronimo Transaction Manager", except); + } + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java new file mode 100644 index 0000000000..9ac0b03d67 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java @@ -0,0 +1,62 @@ +/* + * 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.ode; + +import javax.wsdl.PortType; +import javax.xml.namespace.QName; + +import org.apache.ode.bpel.iapi.BindingContext; +import org.apache.ode.bpel.iapi.Endpoint; +import org.apache.ode.bpel.iapi.EndpointReference; +import org.apache.ode.bpel.iapi.PartnerRoleChannel; +import org.w3c.dom.Document; + +/** + * @author Matthieu Riou + */ +public class ODEBindingContext implements BindingContext { + + private EmbeddedODEServer _server; + + public ODEBindingContext(EmbeddedODEServer _server) { + this._server = _server; + } + + public EndpointReference activateMyRoleEndpoint(QName pid, Endpoint endpoint) { + return new TuscanyEPR(); + } + + public void deactivateMyRoleEndpoint(Endpoint endpoint) { + // TODO + } + + public PartnerRoleChannel createPartnerRoleChannel(QName qName, PortType portType, Endpoint endpoint) { + // TODO + return null; + } + + // TODO This should hold something that makes sense for Tuscany so that the process has + // an address that makes sense from the outside world perspective + private class TuscanyEPR implements EndpointReference { + public Document toXML() { + return null; + } + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java new file mode 100644 index 0000000000..2677f38c88 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java @@ -0,0 +1,43 @@ +/* + * 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.ode; + +import java.io.File; + +/** + * Deployment information + * + * @version $Rev$ $Date$ + */ +public class ODEDeployment { + /** The directory containing the deploy.xml and artefacts. */ + public File deployDir; + + /** If non-null the type of exception we expect to get when we deploy. */ + public Class expectedException = null; + + public ODEDeployment(File deployDir) { + this.deployDir = deployDir; + } + + public String toString() { + return "Deployment#" + deployDir; + } +} \ No newline at end of file diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java new file mode 100644 index 0000000000..3241dce387 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java @@ -0,0 +1,41 @@ +/* + * 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.ode; + +/** + * Thrown when ODE failed to initialize one if its needed resources. + * + * @version $Rev$ $Date$ + */ +public class ODEInitializationException extends RuntimeException { + private static final long serialVersionUID = -2869674556330744215L; + + public ODEInitializationException(Throwable cause) { + super(cause); + } + + public ODEInitializationException(String message) { + super(message); + } + + public ODEInitializationException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java new file mode 100644 index 0000000000..24384162e9 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java @@ -0,0 +1,46 @@ +/* + * 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.ode; + +import org.apache.ode.bpel.iapi.BpelEngineException; +import org.apache.ode.bpel.iapi.ContextException; +import org.apache.ode.bpel.iapi.MessageExchangeContext; +import org.apache.ode.bpel.iapi.MyRoleMessageExchange; +import org.apache.ode.bpel.iapi.PartnerRoleMessageExchange; + +/** + * @author Matthieu Riou + */ +public class ODEMessageExchangeContext implements MessageExchangeContext { + private EmbeddedODEServer _server; + + public ODEMessageExchangeContext(EmbeddedODEServer _server) { + this._server = _server; + } + + public void invokePartner(PartnerRoleMessageExchange partnerRoleMessageExchange) throws ContextException { + // TODO necessary to invoke an external service + } + + public void onAsyncReply(MyRoleMessageExchange myRoleMessageExchange) throws BpelEngineException { + // TODO necessary to get the reply when is returned asynchronously (in a different thread) + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java new file mode 100644 index 0000000000..a928379ba9 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java @@ -0,0 +1,41 @@ +/* + * 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.ode; + +/** + * Thrown when ODE failed to shutdown. + * + * @version $Rev$ $Date$ + */ +public class ODEShutdownException extends RuntimeException { + private static final long serialVersionUID = -2869674556330744215L; + + public ODEShutdownException(Throwable cause) { + super(cause); + } + + public ODEShutdownException(String message) { + super(message); + } + + public ODEShutdownException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java new file mode 100644 index 0000000000..12624ac324 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java @@ -0,0 +1,117 @@ +/* + * 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.provider; + +import java.io.File; +import java.net.URL; + +import javax.transaction.TransactionManager; + +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment; +import org.apache.tuscany.sca.implementation.bpel.ode.ODEInitializationException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + * The sample CRUD implementation is not a full blown implementation, it only + * supports a subset of what a component implementation can support: - a single + * fixed service (as opposed to a list of services typed by different + * interfaces) - a directory attribute used to specify where a CRUD component is + * going to persist resources - no references or properties - no policy intents + * or policy sets + */ +public class BPELImplementationProvider implements ImplementationProvider { + + private RuntimeComponent component; + + private EmbeddedODEServer odeServer; + private TransactionManager txMgr; + + private BPELImplementation implementation; + + /** + * Constructs a new BPEL Implementation. + */ + public BPELImplementationProvider(RuntimeComponent component, + BPELImplementation implementation, + EmbeddedODEServer odeServer, + TransactionManager txMgr) { + this.component = component; + this.implementation = implementation; + this.odeServer = odeServer; + this.txMgr = txMgr; + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + BPELInvoker invoker = new BPELInvoker(operation, odeServer, txMgr); + return invoker; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + System.out.println("Starting " + component.getName() + " " + component.getClass().getName()); + + try { + if (!odeServer.isInitialized()) { + // start ode server + odeServer.init(); + } + + URL deployURL = this.implementation.getProcessDefinition().getLocation(); + + File deploymentDir = new File(deployURL.toURI().getPath()).getParentFile(); + System.out.println("Deploying : " + deploymentDir.toString()); + System.out.println(deploymentDir); + + // deploy the process + if (odeServer.isInitialized()) { + try { + txMgr.begin(); + odeServer.deploy(new ODEDeployment(deploymentDir)); + txMgr.commit(); + } catch (Exception e) { + e.printStackTrace(); + txMgr.rollback(); + } + } + + } catch (ODEInitializationException inite) { + throw new RuntimeException("BPEL Component Type Implementation : Error initializing embedded ODE server " + inite.getMessage(), inite); + } catch(Exception e) { + throw new RuntimeException("BPEl Component Type Implementation initialization failure : " + e.getMessage(), e); + } + + // FIXME:lresende + // odeServer.getBpelServer().register(implementation.getProcessConf()); + } + + public void stop() { + System.out.println("Stopping " + component.getName() + " " + component.getClass().getName()); + } + +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java new file mode 100644 index 0000000000..cc485e7ad9 --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.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.provider; + +import javax.transaction.TransactionManager; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.implementation.bpel.ode.GeronimoTxFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * BPEL Implementation provider factory + * + * We use the provider factory to instantiate a ODE server that is going to be injected in all BPEL components + */ +public class BPELImplementationProviderFactory implements ImplementationProviderFactory { + + private EmbeddedODEServer odeServer; + private TransactionManager txMgr; + + /** + * Default constructor receiving an extension point + * @param extensionPoints + */ + public BPELImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { + GeronimoTxFactory txFactory = new GeronimoTxFactory(); + txMgr = txFactory.getTransactionManager(); + this.odeServer = new EmbeddedODEServer(txMgr); + } + + /** + * Creates a new BPEL Implementation and inject the EmbeddedODEServer + */ + public ImplementationProvider createImplementationProvider(RuntimeComponent component, BPELImplementation implementation) { + return new BPELImplementationProvider(component, implementation, odeServer, txMgr); + } + + public Class getModelType() { + return BPELImplementation.class; + } +} diff --git a/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java new file mode 100644 index 0000000000..112c7e2f3d --- /dev/null +++ b/branches/sca-java-1.0.1/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java @@ -0,0 +1,214 @@ +/* + * 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.provider; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.Future; + +import javax.transaction.SystemException; +import javax.transaction.TransactionManager; +import javax.wsdl.Part; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.ode.bpel.iapi.MyRoleMessageExchange; +import org.apache.ode.bpel.iapi.MessageExchange.Status; +import org.apache.ode.utils.DOMUtils; +import org.apache.ode.utils.GUID; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Implements a target invoker for BPEL component implementations. + * + * The target invoker is responsible for dispatching invocations to the particular + * component implementation logic. In this example we are simply delegating the + * CRUD operation invocations to the corresponding methods on our fake + * resource manager. + */ +public class BPELInvoker implements Invoker { + private EmbeddedODEServer odeServer; + private TransactionManager txMgr; + + private Operation operation; + private QName bpelServiceName; + private String bpelOperationName; + private Part bpelOperationInputPart; + private Part bpelOperationOutputPart; + + public BPELInvoker(Operation operation, EmbeddedODEServer odeServer, TransactionManager txMgr) { + this.operation = operation; + this.odeServer = odeServer; + this.txMgr = txMgr; + + initializeInvocation(); + } + + + private void initializeInvocation() { + + this.bpelOperationName = operation.getName(); + + Interface interfaze = operation.getInterface(); + if(interfaze instanceof WSDLInterface){ + WSDLInterface wsdlInterface = null; + wsdlInterface = (WSDLInterface) interfaze; + + Service serviceDefinition = (Service) wsdlInterface.getWsdlDefinition().getDefinition().getServices().values().iterator().next(); + bpelServiceName = serviceDefinition.getQName(); + + bpelOperationInputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getInput().getMessage().getParts().values().iterator().next(); + bpelOperationOutputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getOutput().getMessage().getParts().values().iterator().next(); + } + } + + public Message invoke(Message msg) { + try { + Object[] args = msg.getBody(); + Object resp = doTheWork(args); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } + return msg; + } + + public Object doTheWork(Object[] args) throws InvocationTargetException { + Element response = null; + + if(! (operation.getInterface() instanceof WSDLInterface)) { + throw new InvocationTargetException(null,"Unsupported service contract"); + } + + org.apache.ode.bpel.iapi.MyRoleMessageExchange mex = null; + Future onhold = null; + + //Process the BPEL process invocation + try { + txMgr.begin(); + mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(), + bpelServiceName, + bpelOperationName); + onhold = mex.invoke(createInvocationMessage(mex, args)); + + txMgr.commit(); + } catch (Exception e) { + try { + txMgr.rollback(); + } catch (SystemException se) { + + } + throw new InvocationTargetException(e, "Error invoking BPEL process : " + e.getMessage()); + } + + + // Waiting until the reply is ready in case the engine needs to continue in a different thread + if (onhold != null) { + try { + onhold.get(); + } catch (Exception e) { + throw new InvocationTargetException(e,"Error invoking BPEL process : " + e.getMessage()); + } + } + + //Process the BPEL invocation response + try { + txMgr.begin(); + // Reloading the mex in the current transaction, otherwise we can't + // be sure we have the "freshest" one. + mex = (MyRoleMessageExchange)odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId()); + + Status status = mex.getStatus(); + System.out.println("Status: " + status.name()); + Element invocationResponse = mex.getResponse().getMessage(); + System.out.println("Response: " + DOMUtils.domToString(invocationResponse)); + + //process the method invocation result + response = processResponse(invocationResponse); + + txMgr.commit(); + // end of transaction two + } catch (Exception e) { + try { + txMgr.rollback(); + } catch (SystemException se) { + + } + throw new InvocationTargetException(e, "Error retrieving BPEL process invocation status : " + e + .getMessage()); + } + + + return response; + } + + /** + * Create BPEL Invocation message + * + * BPEL invocation message like : + * + * + * Hello + * + * + * @param args + * @return + */ + private org.apache.ode.bpel.iapi.Message createInvocationMessage(org.apache.ode.bpel.iapi.MyRoleMessageExchange mex, Object[] args) { + Document dom = DOMUtils.newDocument(); + + Element contentMessage = dom.createElement("message"); + Element contentPart = dom.createElement(bpelOperationInputPart.getName()); + Element contentInvocation = (Element) args[0]; + + contentPart.appendChild(dom.importNode(contentInvocation, false)); + contentMessage.appendChild(contentPart); + dom.appendChild(contentMessage); + + System.out.println("::message:: " + DOMUtils.domToString(dom.getDocumentElement())); + + org.apache.ode.bpel.iapi.Message request = mex.createMessage(new QName("", "")); + request.setMessage(dom.getDocumentElement()); + + return request; + } + + /** + * Process BPEL response + * + * + * + * World + * + * + * + * @param response + * @return + */ + private Element processResponse(Element response) { + return (Element) DOMUtils.findChildByName(response, new QName("",bpelOperationOutputPart.getName())); + } +} -- cgit v1.2.3