From 132aa8a77685ec92bc90c03f987650d275a7b639 Mon Sep 17 00:00:00 2001 From: lresende Date: Mon, 30 Sep 2013 06:59:11 +0000 Subject: 2.0.1 RC1 release tag git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1527464 13f79535-47bb-0310-9956-ffa450edef68 --- .../implementation/bpel/ode/BPELODEDeployFile.java | 233 +++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 sca-java-2.x/tags/2.0.1-RC1/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java') diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java b/sca-java-2.x/tags/2.0.1-RC1/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java new file mode 100644 index 0000000000..fe1e2d620b --- /dev/null +++ b/sca-java-2.x/tags/2.0.1-RC1/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/BPELODEDeployFile.java @@ -0,0 +1,233 @@ +/* + * 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.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.net.URI; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; + +/** + * A class that handles the deploy.xml file required for each BPEL process by the ODE runtime + * @author Mike Edwards + * + * An explanation of the structure of the ODE deploy file: + * + * + * + * + * true + * + * + * + * + * + * + * + * + * + * For SCA purposes: + * + * a) Each partner link in the BPEL process is declared using either a + * (for a service) or using a (for a reference). + * + * b) Each and must use the partnerLink name, as declared in the + * BPEL process. + * + * c) The and elements each have a single child element. + * The elements have name and port attributes. The NAME attribute MUST be set + * to the same name as the partnerLink and MUST be prefixed by a prefix which references + * the namespace "http://tuscany.apache.org" ("tus" in the example above). + * The port attribute can be set to any name (it must be present but it is not actually + * used for anything significant). + * + * When SCA loads a BPEL process to the ODE server, this file is read by the ODE server to + * characterize the process. When SCA interacts with ODE at later points - either when a + * service is being invoked or the process invokes a reference - it is the service @name + * attribute that identifies the service or reference involved. + * + * @version + */ +public class BPELODEDeployFile { + private final Log __log = LogFactory.getLog(getClass()); + + static final String DEPLOY_ELEMENT_START = ""; + static final String PROCESS_ENDELEMENT = ""; + static final String ACTIVE_ELEMENT = "true"; + static final String PROVIDE_ELEMENT_START = ""; + static final String PROVIDE_ENDELEMENT = ""; + static final String SERVICE_ELEMENT_START = ""; + static final String INVOKE_ELEMENT_START = ""; + static final String INVOKE_ENDELEMENT = ""; + + static final String DEPLOY_FILENAME = "deploy.xml"; + + private BPELImplementation implementation; + + /** + * Constructor - requires a BPELImplementation as a parameter + * The ODE deploy.xml file is for this supplied BPELImplementation + * @param theImplementation + */ + public BPELODEDeployFile( BPELImplementation theImplementation ) { + + implementation = theImplementation; + + } // end BPELODEDeployFile constructor + + /** + * Writes the deploy file into the same directory as the BPEL process file, with the name + * "deploy.xml" + */ + public void writeDeployfile() throws IOException { + + File theDirectory = getDirectory(); + + File deployFile = new File( theDirectory, DEPLOY_FILENAME ); + new FileOutputStream( deployFile ); + //if( !deployFile.canWrite() ) throw new IOException( "Unable to write to deploy file" + + // deployFile.getPath() ); + + // Create a stream for the data and write the data to the file + PrintStream theStream = new PrintStream( new FileOutputStream( deployFile ) ); + try { + constructDeployXML( theStream ); + if( theStream.checkError() ) throw new IOException(); + } catch (Exception e) { + throw new IOException( "Unable to write data to deploy file" + + deployFile.getPath() ); + } finally { + theStream.close(); + } // end try + + } // end writeDeployFile + + /** + * Creates the deploy.xml data and writes it to a supplied PrintStream + * @param stream + */ + public void constructDeployXML( PrintStream stream ) { + + // " ); + + // element + stream.println( PROCESS_ELEMENT_START + process.getLocalPart() + + PROCESS_ELEMENT_END ); + + // element + stream.println( ACTIVE_ELEMENT ); + + ComponentType componentType = implementation.getComponentType(); + List theServices = componentType.getServices(); + // Loop over the elements - one per service + for ( Service service : theServices ) { + String serviceName = service.getName(); + // Provide element... + stream.println( PROVIDE_ELEMENT_START + serviceName + PROVIDE_ELEMENT_END ); + // Child service element... + stream.println( SERVICE_ELEMENT_START + serviceName + + SERVICE_ELEMENT_PORT + serviceName + SERVICE_ELEMENT_END ); + stream.println( PROVIDE_ENDELEMENT ); + } // end for + + // Loop over the elements - one per reference + List theReferences = componentType.getReferences(); + for ( Reference reference : theReferences ) { + String referenceName = reference.getName(); + stream.println( INVOKE_ELEMENT_START + referenceName + INVOKE_ELEMENT_END ); + // Child service element... + stream.println( SERVICE_ELEMENT_START + referenceName + + SERVICE_ELEMENT_PORT + referenceName + SERVICE_ELEMENT_END ); + stream.println( INVOKE_ENDELEMENT ); + + } // end for + + // element + stream.println( PROCESS_ENDELEMENT ); + + // + stream.println( DEPLOY_ENDELEMENT ); + + } // end constructDeployXML + + /** + * Gets the directory containing the BPEL process + * @return + */ + private File getDirectory() { + File theDir = getBPELFile().getParentFile(); + return theDir; + } // end getDirectory + + /** + * Gets the File containing the BPEL process definition + * @return - the File object containing the BPEL process + */ + private File getBPELFile() { + try { + String location = this.implementation.getProcessDefinition().getLocation(); + URI locationURI; + if (location.indexOf('%') != -1) { + locationURI = URI.create(location); + } else { + locationURI = new URI(null, location, null); + } + + File theProcess = new File(locationURI); + return theProcess; + } catch( Exception e ) { + if(__log.isDebugEnabled()) { + __log.debug("Exception converting BPEL file URL to an URI: " + e ); + } + } // end try + return null; + } // end getBPELFile + + + +} // end class BPELODEDeployFile -- cgit v1.2.3