From 3dd7e2c4da9c80b8182a2d04dc129a67aa7910df Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:06:58 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835121 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/implementation/bpel/BPEL.java | 35 ++++ .../implementation/bpel/BPELImplementation.java | 51 +++++ .../bpel/BPELImplementationFactory.java | 36 ++++ .../bpel/DefaultBPELImplementationFactory.java | 46 +++++ .../bpel/impl/BPELArtifactProcessor.java | 144 ++++++++++++++ .../bpel/impl/BPELImplementationImpl.java | 214 +++++++++++++++++++++ .../bpel/impl/ODEProcessException.java | 40 ++++ .../implementation/bpel/ode/EmbeddedODEServer.java | 151 +++++++++++++++ .../implementation/bpel/ode/GeronimoTxFactory.java | 43 +++++ .../bpel/ode/ODEInitializationException.java | 39 ++++ .../bpel/provider/BPELImplementationProvider.java | 75 ++++++++ .../BPELImplementationProviderFactory.java | 50 +++++ .../implementation/bpel/provider/BPELInvoker.java | 62 ++++++ 13 files changed, 986 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPEL.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java (limited to 'sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany') diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPEL.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPEL.java new file mode 100644 index 0000000000..c474c59d51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPEL.java @@ -0,0 +1,35 @@ +/* + * 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; + +/** + * The service interface of the single BPEL service provided by BPEL components. + * + * @version $Rev$ $Date$ + */ +public interface BPEL { + + /** + * Invoke a bpel process + * @param object + * @return object + */ + Object invokeProcess(Object object); + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java new file mode 100644 index 0000000000..9e3adefe5c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java @@ -0,0 +1,51 @@ +/* + * 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.Extensible; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.ode.bpel.iapi.ProcessConf; + +import javax.xml.namespace.QName; + +/** + * The model representing the BPEL implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public interface BPELImplementation extends Implementation, Extensible { + + /** + * Builds the process configuration used by ODE to get deployment and configuration + * level information about a process. + * @return + */ + ProcessConf getProcessConf(); + + /** + * Sets the implementation compiled process bytes + * @param compiledProcess serialized compiled process + */ + void setCompiledProcess(byte[] compiledProcess); + + /** + * @param processName process QName + */ + void setProcessName(QName processName); +} diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationFactory.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationFactory.java new file mode 100644 index 0000000000..9df99b6069 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationFactory.java @@ -0,0 +1,36 @@ +/* + * 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 BPELImplementationFactory { + + /** + * Creates a new CRUD implementation. + * + * @return + */ + BPELImplementation createBPELImplementation(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELImplementationFactory.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELImplementationFactory.java new file mode 100644 index 0000000000..28bc603c8b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELImplementationFactory.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; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.implementation.bpel.impl.BPELImplementationImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; + +/** + * A default factory for the BPEL implementation model. + * + * @version $Rev$ $Date$ + */ +public class DefaultBPELImplementationFactory implements BPELImplementationFactory { + + private AssemblyFactory assemblyFactory; + private WSDLFactory wsdlFactory; + + public DefaultBPELImplementationFactory(AssemblyFactory assemblyFactory, + WSDLFactory wsdlFactory) { + this.assemblyFactory = assemblyFactory; + this.wsdlFactory = wsdlFactory; + } + + public BPELImplementation createBPELImplementation() { + return new BPELImplementationImpl(assemblyFactory, wsdlFactory); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELArtifactProcessor.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELArtifactProcessor.java new file mode 100644 index 0000000000..1bb88496b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELArtifactProcessor.java @@ -0,0 +1,144 @@ +/* + * 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.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.ode.bpel.compiler.BpelC; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +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.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementationFactory; +import org.apache.tuscany.sca.implementation.bpel.DefaultBPELImplementationFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; + +/** + * 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 BPELArtifactProcessor implements StAXArtifactProcessor { + private static final QName IMPLEMENTATION_BPEL = new QName(Constants.SCA10_TUSCANY_NS, "implementation.bpel"); + + private BPELImplementationFactory bpelFactory; + + public BPELArtifactProcessor(ModelFactoryExtensionPoint modelFactories) { + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + WSDLFactory wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + this.bpelFactory = new DefaultBPELImplementationFactory(assemblyFactory, wsdlFactory); + } + + 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 { + assert IMPLEMENTATION_BPEL.equals(reader.getName()); + + // Read an element + try { + // Read the process attribute. + QName process = getAttributeValueNS(reader, "process"); + String bpelFile = reader.getAttributeValue(null, "file"); + + // 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(); + } + + // Create an initialize the BPEL implementation model + BPELImplementation implementation = bpelFactory.createBPELImplementation(); + implementation.setProcessName(process); + implementation.setCompiledProcess(compiledProcess.toByteArray()); + implementation.setUnresolved(false); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && IMPLEMENTATION_BPEL.equals(reader.getName())) { + break; + } + } + + return implementation; + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + } + + public void resolve(BPELImplementation impl, ModelResolver resolver) throws ContributionResolveException { + System.out.println("IN RESOLVE"); + if( impl != null && impl.isUnresolved()) { + + impl.setUnresolved(false); + } + + } + + public void write(BPELImplementation model, XMLStreamWriter outputSource) throws ContributionWriteException { + } + + 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/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java new file mode 100644 index 0000000000..81401f0c72 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.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.impl; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +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.Service; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.w3c.dom.Node; + +/** + * The model representing a BPEL implementation in an SCA assembly model. + * + * @version $Rev$ $Date$ + */ +public class BPELImplementationImpl implements BPELImplementation { + + private Service _bpelService; + private QName _processName; + private byte[] _compiledProcess; + private boolean unresolved; + + /** + * Constructs a new BPEL implementation. + */ + public BPELImplementationImpl(AssemblyFactory assemblyFactory, + WSDLFactory wsdlFactory) { + + _bpelService = assemblyFactory.createService(); + _bpelService.setName("BPEL"); +// WSDLInterface wsdlInterface; +// try { +// wsdlInterface = introspector.introspect(BPEL.class); +// } catch (InvalidInterfaceException e) { +// throw new IllegalArgumentException(e); +// } +// WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); +// interfaceContract.setInterface(wsdlInterface); +// _bpelService.setInterfaceContract(interfaceContract); + } + + public void setCompiledProcess(byte[] compiledProcess) { + _compiledProcess = compiledProcess; + } + + public void setProcessName(QName processName) { + _processName = processName; + } + + public ProcessConf getProcessConf() { + return null; + } + + public ConstrainingType getConstrainingType() { + // The sample BPEL implementation does not support constrainingTypes + return null; + } + + public List getProperties() { + // The sample BPEL implementation does not support properties + return Collections.emptyList(); + } + + public List getServices() { + // The sample BPEL implementation provides a single fixed CRUD service + return Collections.singletonList(_bpelService); + } + + public List getReferences() { + // The sample BPEL implementation does not support properties + return Collections.emptyList(); + } + + public String getURI() { + // The sample BPEL implementation does not have a URI + return null; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + // The sample BPEL implementation does not support constrainingTypes + } + + public void setURI(String uri) { + // The sample BPEL implementation does not have a URI + } + + + public List getExtensions() { + // The sample BPEL implementation does not support extensions + 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 new ByteArrayInputStream(_compiledProcess); + } + + public String getBpelDocument() { + return null; + } + + public URL getBaseURL() { + 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/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java new file mode 100644 index 0000000000..34743896b1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java @@ -0,0 +1,40 @@ +/* + * 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. + */ +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/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java new file mode 100644 index 0000000000..5846c90150 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java @@ -0,0 +1,151 @@ +/* + * 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.il.config.OdeConfigProperties; +import org.apache.ode.il.dbutil.Database; +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.memdao.BpelDAOConnectionFactoryImpl; +import org.apache.ode.bpel.scheduler.quartz.QuartzSchedulerImpl; +import org.apache.ode.bpel.iapi.Scheduler; + +import java.util.Properties; +import java.util.concurrent.Executors; +import java.util.concurrent.ExecutorService; +import java.io.File; +import java.net.URL; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.transaction.TransactionManager; + +/** + * + */ +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; + private ExecutorService _executor; + private Scheduler _scheduler; + + 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() { + 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 MessageExchangeContextImpl(this)); +// _bpelServer.setBindingContext(new BindingContextImpl(this, _store)); + _bpelServer.setScheduler(_scheduler); + if (_config.isDehydrationEnabled()) { + CountLRUDehydrationPolicy dehy = new CountLRUDehydrationPolicy(); + _bpelServer.setDehydrationPolicy(dehy); + } + _bpelServer.init(); + } + + protected Scheduler createScheduler() { + QuartzSchedulerImpl scheduler = new QuartzSchedulerImpl(); + scheduler.setExecutorService(_executor, 20); + scheduler.setTransactionManager(_txMgr); + scheduler.setDataSource(_db.getDataSource()); + scheduler.init(); + return scheduler; + } + + public boolean isInitialized() { + return _initialized; + } + + public BpelServerImpl getBpelServer() { + return _bpelServer; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java new file mode 100644 index 0000000000..d20dbe6ffc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.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 org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.transaction.TransactionManager; + +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/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java new file mode 100644 index 0000000000..bf8f55be3d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java @@ -0,0 +1,39 @@ +/* + * 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. + */ +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/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java new file mode 100644 index 0000000000..e95bb80438 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java @@ -0,0 +1,75 @@ +/* + * 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 org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +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 BPELImplementation implementation; + private EmbeddedODEServer odeServer; + + /** + * Constructs a new CRUD implementation. + */ + public BPELImplementationProvider(RuntimeComponent component, BPELImplementation implementation, + EmbeddedODEServer odeServer) { + this.component = component; + this.implementation = implementation; + this.odeServer = odeServer; + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + BPELInvoker invoker = new BPELInvoker(operation); + return invoker; + } + + public Invoker createCallbackInvoker(Operation operation) { + BPELInvoker invoker = new BPELInvoker(operation); + return invoker; + } + + public void start() { + System.out.println("Starting " + component.getName() + " " + component.getClass().getName()); + if (!odeServer.isInitialized()) odeServer.init(); + + odeServer.getBpelServer().register(implementation.getProcessConf()); + } + + public void stop() { + System.out.println("Stopping " + component.getName() + " " + component.getClass().getName()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java new file mode 100644 index 0000000000..33112dbc0c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java @@ -0,0 +1,50 @@ +/* + * 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 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.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + */ +public class BPELImplementationProviderFactory implements ImplementationProviderFactory { + + private EmbeddedODEServer odeServer; + + /** + * Constructs a new CRUD implementation. + * @param odeServer the server instance passed to the implementation provider + */ + public BPELImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { + this.odeServer = new EmbeddedODEServer(); + } + + public ImplementationProvider createImplementationProvider(RuntimeComponent component, BPELImplementation implementation) { + return new BPELImplementationProvider(component, implementation, odeServer); + } + + public Class getModelType() { + return BPELImplementation.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java new file mode 100644 index 0000000000..b786f00266 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.99/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.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.provider; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Implements a target invoker for CRUD 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 Operation operation; + + public BPELInvoker(Operation operation) { + this.operation = operation; + } + + 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 { + if (operation.getName().equals("invokeProcess")) { + return args[0]; + } else { + return null; + } + } + +} -- cgit v1.2.3