[savara-commits] savara SVN: r139 - in tools/eclipse/trunk/plugins/org.pi4soa.bpmn: META-INF and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Dec 11 11:38:45 EST 2009


Author: objectiser
Date: 2009-12-11 11:38:45 -0500 (Fri, 11 Dec 2009)
New Revision: 139

Added:
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.classpath
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.cvsignore
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.project
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/META-INF/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/META-INF/MANIFEST.MF
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/build.properties
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/plugin.xml
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/Activator.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/ExportBPMNWizard.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/FolderSelectionPage.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNConfiguration.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerationException.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerator.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNModelFactory.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNNotationFactory.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/DefaultBPMNConfiguration.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/AbstractBPMNActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNDiagram.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNPool.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ChoiceActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ConditionalActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/JunctionActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ParallelActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/PerformActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ReceiveActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SequenceActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SimpleActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhenActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhileActivity.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/gmf/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/gmf/GMFBPMNNotationFactoryImpl.java
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/stp/
   tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/stp/STPBPMNModelFactoryImpl.java
Log:
Temporary inclusion of the pi4soa based bpmn generation from choreography. This will eventually be replaced by a more generic BPMN2 process model generator, which will work from choreography or BPMN2 choreography models.

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.classpath
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.classpath	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.classpath	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+	<classpathentry kind="output" path="classes"/>
+</classpath>

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.cvsignore
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.cvsignore	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.cvsignore	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1 @@
+classes

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.project
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.project	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/.project	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>org.pi4soa.bpmn</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.ManifestBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.pde.SchemaBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.pde.PluginNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/META-INF/MANIFEST.MF
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/META-INF/MANIFEST.MF	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/META-INF/MANIFEST.MF	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,17 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: pi4soa BPMN Plug-in
+Bundle-SymbolicName: org.pi4soa.bpmn;singleton:=true
+Bundle-Version: 3.0.0.qualifier
+Bundle-Activator: org.pi4soa.bpmn.eclipse.Activator
+Bundle-Vendor: www.pi4soa.org
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.pi4soa.service,
+ org.pi4soa.cdl,
+ org.eclipse.stp.bpmn,
+ org.eclipse.gmf.runtime.notation,
+ org.eclipse.core.resources,
+ org.pi4soa.common
+Eclipse-LazyStart: true

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/build.properties
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/build.properties	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/build.properties	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,5 @@
+source.. = src/java/
+output.. = classes/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/plugin.xml
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/plugin.xml	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/plugin.xml	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+   <extension
+         point="org.eclipse.ui.exportWizards">
+     <wizard
+           class="org.pi4soa.bpmn.eclipse.ExportBPMNWizard"
+           name="BPMN"
+           id="org.pi4soa.bpmn.exportbpmnwizard"/>
+   </extension>
+
+</plugin>

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/Activator.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/Activator.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/Activator.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,50 @@
+package org.pi4soa.bpmn.eclipse;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+	// The plug-in ID
+	public static final String PLUGIN_ID = "org.pi4soa.bpmn";
+
+	// The shared instance
+	private static Activator plugin;
+	
+	/**
+	 * The constructor
+	 */
+	public Activator() {
+		plugin = this;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+	 */
+	public void stop(BundleContext context) throws Exception {
+		plugin = null;
+		super.stop(context);
+	}
+
+	/**
+	 * Returns the shared instance
+	 *
+	 * @return the shared instance
+	 */
+	public static Activator getDefault() {
+		return plugin;
+	}
+
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/ExportBPMNWizard.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/ExportBPMNWizard.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/ExportBPMNWizard.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Feb 1, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.eclipse;
+
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.pi4soa.bpmn.generation.BPMNGenerator;
+import org.pi4soa.bpmn.generation.DefaultBPMNConfiguration;
+import org.pi4soa.cdl.CDLDefinitions;
+import org.pi4soa.cdl.ParticipantType;
+import org.pi4soa.common.resource.FileSystemArtifactManager;
+import org.pi4soa.common.resource.eclipse.ResourceUtil;
+import org.pi4soa.service.ServiceDefinitions;
+import org.pi4soa.service.behavior.ServiceDescription;
+import org.pi4soa.service.behavior.projection.BehaviorProjection;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IExportWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.core.resources.*;
+
+
+/**
+ * This class implements the Eclipse ExportWizrd for exporting
+ * a CDL object model to a BPMN representation.
+ */
+public class ExportBPMNWizard extends Wizard implements IExportWizard {
+
+	/**
+     * This method is invoked when the 'finish' button is
+     * pressed on the export wizard.
+     */
+	public boolean performFinish() {
+		boolean ret=true;
+		
+		// Export CDL's service endpoint projections to folder
+		if (m_cdlFile != null) {
+			
+			// Load the CDL object model
+			try {
+				org.pi4soa.cdl.Package cdlpack=
+					org.pi4soa.cdl.eclipse.Activator.getPackage(m_cdlFile);
+			
+				BPMNGenerator generator=new BPMNGenerator();
+				
+				generator.generate(cdlpack, null,
+						m_selectionPage.getFolderName(),
+						new DefaultBPMNConfiguration());
+
+			} catch(Exception e) {
+			    
+			    // Record error message on wizard page
+				m_selectionPage.setErrorMessage("Failed to export Choreography to BPMN: "+e);
+				
+				logger.log(Level.SEVERE,
+						"Failed to export Choreography to BPMN", e);
+				ret = false;
+			}
+		}
+		
+		return(ret);
+	}
+
+	/**
+	 * This method is used to initialize the export wizard.
+	 * 
+	 * @param workbench The workbench
+	 * @param selection The selected item(s)
+	 */
+	public void init(IWorkbench workbench, IStructuredSelection selection) {
+	    String errMesg=null;
+	    
+	    // Create the selection page
+		m_selectionPage = new FolderSelectionPage(PAGE_NAME,
+		        "Select a folder as the destination for "+
+		        "the exported BPMN");
+		
+	    // Check that a single CDL file has been selected
+		if (selection != null) {
+		    
+		    // Check element is a file
+		    if (selection.getFirstElement() instanceof IFile) {
+			
+		        m_cdlFile = (IFile)selection.getFirstElement();
+			
+		        // Check the file extension is valid
+		        if (m_cdlFile.getFileExtension().equals(
+		        		CDLDefinitions.CDL_FILE_EXTENSION)) {
+		            
+		            // Make sure there are no markers associated
+		            // with the resource
+		        	if (ResourceUtil.hasErrors(m_cdlFile)) {
+					    errMesg = RESOURCE_ERROR;		        		
+		        	}
+				} else {
+				    errMesg = RESOURCE_NOT_CDL_ERROR;
+				}
+			} else {
+			    errMesg = RESOURCE_NOT_FILE_ERROR;
+		    }
+		} else {
+		    errMesg = RESOURCE_NOT_SELECTED_ERROR;
+		}
+		
+		// Check if an error should be reported
+		if (errMesg != null) {
+		    m_selectionPage.setErrorMessage(errMesg);
+		}
+	}
+
+	/**
+	 * This method configures the pages associated with
+	 * the CDL export wizard.
+	 */
+	public void addPages() {
+		addPage(m_selectionPage);
+	}
+	
+    private static Logger logger = Logger.getLogger("org.pi4soa.bpmn.eclipse");
+	private IFile m_cdlFile=null;
+	private FolderSelectionPage m_selectionPage=null;
+	
+    private static final String BEHAVIOR_EXTENSION = ServiceDefinitions.SERVICE_ENDPOINT_FILE_EXTENSION;
+	
+	private static String PAGE_NAME="Export BPMN";
+	private static String RESOURCE_NOT_SELECTED_ERROR="A resource has not been selected";
+	private static String RESOURCE_NOT_FILE_ERROR="The selected resource is not a file";
+	private static String RESOURCE_NOT_CDL_ERROR="The selected file is not a valid CDL object model";
+	private static String RESOURCE_ERROR="Invalid CDL cannot be exported as BPMN";
+}
\ No newline at end of file

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/FolderSelectionPage.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/FolderSelectionPage.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/eclipse/FolderSelectionPage.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,169 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Feb 1, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.eclipse;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * This class represents the wizard page for selecting
+ * a folder.
+ */
+class FolderSelectionPage extends org.eclipse.jface.wizard.WizardPage {
+
+	/**
+	 * Constructor for the folder selection page.
+	 * 
+	 * @param pageName The page name
+	 * @param description The description
+	 */
+	public FolderSelectionPage(String pageName,
+	        String description) {
+		super(pageName);
+		setTitle(pageName);
+		setDescription(description);
+		setPageComplete(false);
+	}
+
+	/**
+	 * Create the control for the selection page.
+	 * 
+	 * @param parent The parent component
+	 */
+	public void createControl(Composite parent) {
+	    
+	    // Identify the shell
+		m_shell = parent.getShell();
+		
+		// Create the composite component
+		Composite composite = new Composite(parent, SWT.NONE);
+		composite.setLayout(new GridLayout());
+		composite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL));
+		
+		// Create the text field for entering the
+		// path to the folder
+		m_text = new Text(composite, SWT.SINGLE | SWT.BORDER);
+		m_text.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
+				    
+		// Ensure there is no error before setting up the
+		// text listener
+		if (getErrorMessage() == null) {
+			m_text.addModifyListener(new ModifyListener() {
+			    
+				public void modifyText(ModifyEvent e) {
+					String errMesg=null;
+					
+					try {
+					    // Setup file associated with entered
+					    // name
+					    java.io.File file=
+					        new java.io.File(m_text.getText());
+						
+					  	// Check that the folder exists
+						if (file.exists() == false) {
+							errMesg = "The folder does not exist";
+						} else if (file.isDirectory() == false) {
+							errMesg = "A folder should be selected";
+						}
+					} catch(Exception e2) {
+						// Ignore
+					}
+					
+					// Check if error has been found
+					if (errMesg != null) {
+						setErrorMessage(errMesg);
+						setPageComplete(false);
+					} else {
+						setErrorMessage(null);
+						setPageComplete(true);
+					}
+				}
+			});
+		}		
+
+		// Create a 'browse' button
+		m_button=new Button(composite, 0);
+		
+		m_button.setText("Browse");
+		m_button.setToolTipText("Browse file system to locate destination folder");
+		
+		m_button.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
+			public void widgetSelected(SelectionEvent evt) {
+				DirectoryDialog dialog=new DirectoryDialog(m_shell);
+
+				String filename=dialog.open();
+				
+				if (filename != null) {
+					
+					filename = preProcessFilename(filename);
+					m_text.setText(filename);
+				}
+			}
+			
+			public void widgetDefaultSelected(SelectionEvent evt) {					
+			}
+		});
+		
+		if (getErrorMessage() != null) {
+			m_button.setEnabled(false);
+			m_text.setEnabled(false);
+			m_text.setEditable(false);
+		}
+		
+		setControl(composite);
+	}
+		
+	/**
+	 * This method preprocesses the filename before it is
+	 * used.
+	 * 
+	 * @param filename The original filename
+	 * @return The pre-processed filename
+	 */
+	protected String preProcessFilename(String filename) {
+		return(filename);
+	}
+	
+	/**
+	 * This method returns the folder path that has been
+	 * entered by the user.
+	 * 
+	 * @return The folder name
+	 */
+	public String getFolderName() {
+	    if (m_text == null) {
+	        return(null);
+	    }
+	    return(m_text.getText());
+	}
+	
+	private Text m_text=null;
+	private Shell m_shell=null;
+	private Button m_button=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNConfiguration.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNConfiguration.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNConfiguration.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation;
+
+/**
+ * This interface represents the configuration information used
+ * by the BPMN projection to determine what model components and
+ * features should be included.
+ *
+ */
+public interface BPMNConfiguration {
+
+	/**
+	 * This method returns the UML export format to be used. The list
+	 * of valid export formats is available using the
+	 * #UMLGenerator.getExportFormats() method.
+	 * 
+	 * @return The export format, or null if the default is being used.
+	 */
+	public String getExportFormat();
+	
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerationException.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerationException.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerationException.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation;
+
+/**
+ * This class represents a BPMN generation exception.
+ *
+ */
+public class BPMNGenerationException extends Exception {
+
+	private static final long serialVersionUID = -8580109779260853013L;
+
+	/**
+	 * This constructor initializes the UML generation exception
+	 * with a message.
+	 * 
+	 * @param mesg The message
+	 */
+	public BPMNGenerationException(String mesg) {
+		super(mesg);
+	}
+	
+	/**
+	 * This constructor initializes the UML generation exception
+	 * with a message and associated exception.
+	 * 
+	 * @param mesg The message
+	 * @param t The associated exception
+	 */
+	public BPMNGenerationException(String mesg, Throwable t) {
+		super(mesg, t);
+	}
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerator.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerator.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNGenerator.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,945 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation;
+
+import java.util.logging.Logger;
+
+import org.pi4soa.bpmn.generation.components.*;
+import org.pi4soa.cdl.CDLManager;
+import org.pi4soa.service.behavior.ActivityType;
+import org.pi4soa.service.behavior.Assign;
+import org.pi4soa.service.behavior.AtomicUnit;
+import org.pi4soa.service.behavior.BehaviorDescription;
+import org.pi4soa.service.behavior.BehaviorVisitor;
+import org.pi4soa.service.behavior.Choice;
+import org.pi4soa.service.behavior.CompletionHandler;
+import org.pi4soa.service.behavior.Conditional;
+import org.pi4soa.service.behavior.ExceptionHandler;
+import org.pi4soa.service.behavior.Finalize;
+import org.pi4soa.service.behavior.Parallel;
+import org.pi4soa.service.behavior.Perform;
+import org.pi4soa.service.behavior.RaiseException;
+import org.pi4soa.service.behavior.Receive;
+import org.pi4soa.service.behavior.RepetitionType;
+import org.pi4soa.service.behavior.Send;
+import org.pi4soa.service.behavior.Sequence;
+import org.pi4soa.service.behavior.ServiceDescription;
+import org.pi4soa.service.behavior.StructuralType;
+import org.pi4soa.service.behavior.TimedUnit;
+import org.pi4soa.service.behavior.Unobservable;
+import org.pi4soa.service.behavior.VariableDeclaration;
+import org.pi4soa.service.behavior.When;
+import org.pi4soa.service.behavior.While;
+import org.pi4soa.service.behavior.projection.BehaviorProjection;
+import org.pi4soa.service.session.internal.LookaheadElement;
+import org.pi4soa.service.session.internal.Predicate;
+
+/**
+ * This class provides the functionality for converting a
+ * choreography description into a BPMN representation.
+ *
+ */
+public class BPMNGenerator {
+
+	public static void main(String[] args) {
+		
+		// Check for optional parameters
+		int pos=0;
+		int num=args.length;
+		String[] participant=null;
+		
+		for (; pos < num && args[pos].charAt(0) == '-'; pos++) {
+			String option=args[pos].substring(1);
+			if (option.equals("p")) {
+				if (participant != null) {
+					System.err.println("Cannot specify participant more than once");
+					System.exit(1);
+				} else if (pos+1 >= num) {
+					System.err.println("Participant not defined");
+					System.exit(1);
+				} else {
+					pos++;
+					participant = new String[]{args[pos]};
+				}
+			} else {
+				System.err.println("Unknown option "+args[pos]);
+				System.err.println(USAGE_MESSAGE);
+				System.exit(1);
+			}
+		}
+		
+		// Check parameters
+		if (num - pos != 2) {
+			System.err.println(USAGE_MESSAGE);
+			System.exit(1);
+		}
+		
+		String choreographyFile=args[pos];
+		String outputFolder=args[pos+1];
+		org.pi4soa.cdl.Package choreography=null;
+		
+		// Load the choreography
+		try {
+			choreography = CDLManager.load(choreographyFile);
+			
+		} catch(Exception e) {
+			System.err.println("Failed to load choreography: "+e);
+			e.printStackTrace();
+			System.exit(1);
+		}
+		
+		try {
+			BPMNGenerator generator=new BPMNGenerator();
+			
+			generator.generate(choreography, participant, outputFolder,
+					new DefaultBPMNConfiguration());
+			
+		} catch(Exception e) {
+			System.err.println("Failed to generate UML: "+e);
+			e.printStackTrace();
+			System.exit(3);
+		}
+	}
+	
+	/**
+	 * This is the constructor for the UML generator.
+	 * 
+	 */
+	public BPMNGenerator() {
+	}
+	
+	/**
+	 * This method generates the UML representation for the
+	 * supplied choreography. If the optional participant
+	 * is specified, then only the UML representation for
+	 * that participant will be generated, otherwise all
+	 * participants associated with the choreography will be
+	 * generated.
+	 * 
+	 * @param choreography The choreography
+	 * @param participants The optional participant names
+	 * @param folder The folder where the model/diagrams will
+	 * 					be stored
+	 * @param config The UML configuration
+	 * @exception BPMNGenerationException Failed to generate
+	 */
+	public void generate(org.pi4soa.cdl.Package choreography,
+					String[] participants, String folder,
+					BPMNConfiguration config) throws BPMNGenerationException {
+	
+		if (participants == null) {
+			java.util.List pTypes=
+				choreography.getTypeDefinitions().getParticipantTypes();
+			
+			participants = new String[pTypes.size()];
+			
+			for (int i=0; i < pTypes.size(); i++) {
+				participants[i] = ((org.pi4soa.cdl.ParticipantType)pTypes.
+							get(i)).getName();
+			}
+		}
+
+		// Create the model
+		org.pi4soa.bpmn.generation.BPMNModelFactory model=null;
+		org.pi4soa.bpmn.generation.BPMNNotationFactory notation=null;
+		
+		try {
+			model = new org.pi4soa.bpmn.generation.stp.STPBPMNModelFactoryImpl();
+			notation = new org.pi4soa.bpmn.generation.gmf.GMFBPMNNotationFactoryImpl();
+			
+			generateModel(model, notation, choreography, config, folder);
+
+		} catch(Exception e) {
+			throw new BPMNGenerationException("Failed to generate UML model", e);
+		}
+		
+		/*
+		if (diagrams.size() > 0) {
+			Object diagram=diagrams.get(0);
+			
+			try {
+				
+				// Output the UML2 model to the supplied stream
+				final org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl xmi =
+					new org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl();
+				xmi.getContents().add(diagram);
+				
+				xmi.doSave(ostream, xmi.getDefaultLoadOptions());
+				
+				ostream.close();
+				
+			} catch(Exception e) {
+				throw new BPMNGenerationException("Failed to convert to XMI", e);
+			}
+		}
+		*/
+		// Just need to store as EMF based file
+		/*
+		try {
+			java.io.ByteArrayOutputStream bs=new java.io.ByteArrayOutputStream();
+			
+			// Output the UML2 model to the supplied stream
+			final org.eclipse.emf.ecore.xmi.impl.EMOFResourceImpl xmi =
+				new org.eclipse.emf.ecore.xmi.impl.EMOFResourceImpl();
+			xmi.getContents().add(model);
+			
+			xmi.doSave(bs, xmi.getDefaultLoadOptions());
+			
+			bs.close();
+			
+			UMLExportFormatter formatter=getExportFormatter(config.getExportFormat());
+			if (formatter != null) {
+				formatter.export(bs, ostream);
+			} else {
+				throw new UMLException("Unable to find UML export formatter for '"+
+						config.getExportFormat()+"'");
+			}
+				
+		} catch(UMLException UMLex) {
+			throw UMLex;
+			
+		} catch(Exception e) {
+			throw new UMLException("Failed to convert to XMI", e);
+		}
+		*/
+	}
+	
+	/**
+	 * This method generates the model information associated
+	 * with the supplied choreography description.
+	 * 
+	 * @param model The model
+	 * @param cdlpack The choreography description
+	 * @param config The MDA configuration
+	 * @return The list of diagrams
+	 * @throws BPMNGenerationException Failed to generate model
+	 */
+	public void generateModel(BPMNModelFactory model, 
+			BPMNNotationFactory notation, org.pi4soa.cdl.Package cdlpack,
+					BPMNConfiguration config, String folder) throws BPMNGenerationException {
+		try {
+			java.util.List participants=cdlpack.getTypeDefinitions().getParticipantTypes();
+			
+			BPMNModelVisitor visitor=
+				new BPMNModelVisitor(org.pi4soa.common.xml.XMLUtils.getLocalname(
+						cdlpack.getName()),
+						model, notation, folder);
+			
+			for (int i=0; i < participants.size(); i++) {
+				org.pi4soa.cdl.ParticipantType partType=
+							(org.pi4soa.cdl.ParticipantType)
+							cdlpack.getTypeDefinitions().getParticipantTypes().get(i);
+					
+				org.pi4soa.service.behavior.ServiceDescription sdesc=
+					BehaviorProjection.projectServiceDescription(cdlpack,
+							partType, null);
+			
+				visitor.setParticipant(partType.getName());
+				
+				sdesc.visit(visitor);
+			}
+			
+			visitor.completeModels();
+			
+		} catch(Exception e) {
+			throw new BPMNGenerationException("Failed to generate BPMN model", e);
+		}
+	}
+	
+    private static Logger logger = Logger.getLogger("org.pi4soa.bpmn.generation");
+
+    private static final String USAGE_MESSAGE = "Usage: BPMNGenerator [-p Participant] " +
+							"ChoreographyFile OutputFolder";
+
+    // NOTE: Currently uses the Activity Model constructs
+	public class BPMNModelVisitor implements BehaviorVisitor {
+		
+		/**
+		 * The constructor the BPMN model visitor.
+		 * 
+		 */
+		public BPMNModelVisitor(String choreoName,
+				BPMNModelFactory model, BPMNNotationFactory notation,
+					String folder) {
+			m_choreoName = choreoName;
+			m_modelFactory = model;
+			m_notationFactory = notation;
+			m_folder = folder;
+		}
+		
+		/**
+		 * This method sets the name associated with the participant
+		 * being projected.
+		 * 
+		 * @param participant The participant
+		 */
+		public void setParticipant(String participant) {
+			m_participant = participant;
+		}
+		
+		/**
+		 * This method visits the abstract activity. This will be
+		 * performed after performing the specific visit method
+		 * for the real type, but before performing the visit
+		 * on any other activities that may be contained within
+		 * this activity type.
+		 * 
+		 * @param elem The activity type
+		 */
+		public void activityType(ActivityType elem) {
+			
+		}
+		
+		/**
+		 * This method visits the assign activity.
+		 * 
+		 * @param elem The assign
+		 */
+		public void assign(Assign elem) {
+			
+			BPMNActivity umls=getBPMNActivity();
+			if (umls != null) {
+				new SimpleActivity(elem,
+						umls, m_modelFactory, m_notationFactory);
+			}
+		}
+		
+		/**
+		 * This method starts visiting the atomic unit element.
+		 * 
+		 * @param elem The atomic unit
+		 */
+		public void atomicUnitStart(AtomicUnit elem) {
+			
+		}
+		
+		/**
+		 * This method ends visiting the atomic unit element.
+		 * 
+		 * @param elem The atomic unit
+		 */
+		public void atomicUnitEnd(AtomicUnit elem) {
+			
+		}
+		
+		/**
+		 * This method starts visiting the behavior description element.
+		 * 
+		 * @param elem The behavior description
+		 */
+		public void behaviorDescriptionStart(BehaviorDescription elem) {
+			
+			try {
+				BPMNDiagram diagram=getBPMNModel(elem, m_folder);
+				
+				String participant=m_participant;
+				
+				if (org.pi4soa.common.util.NamesUtil.isSet(elem.getParticipant())) {
+					participant += " ["+elem.getParticipant()+"]";
+				}
+				
+				BPMNPool pool=diagram.createPool(participant);
+				
+				//diagram.initialize(elem);
+				
+				pushBPMNActivity(pool);
+			} catch(Exception e) {
+				logger.severe("Failed to get state machine " +
+						"for behavior '"+elem+"': "+e);
+			}
+		}
+		
+		/**
+		 * This method ends visiting the behavior description element.
+		 * 
+		 * @param elem The behavior description
+		 */
+		public void behaviorDescriptionEnd(BehaviorDescription elem) {
+
+			BPMNActivity umls=getBPMNActivity();
+			
+			if (umls != null) {
+				umls.childrenComplete();
+			}
+
+			popUMLActivity();
+		}
+		
+		/**
+		 * This method starts visiting the choice element.
+		 * 
+		 * @param elem The choice
+		 */
+		public void choiceStart(Choice elem) {
+			
+			try {
+				pushBPMNActivity(new ChoiceActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+				
+			} catch(Exception e) {
+				logger.severe("Failed to create choice state: "+e);
+			}
+		}
+		
+		/**
+		 * This method ends visiting the choice element.
+		 * 
+		 * @param elem The choice
+		 */
+		public void choiceEnd(Choice elem) {
+			
+			popUMLActivity();
+		}
+		
+		/**
+		 * This method starts visiting the completion handler element.
+		 * 
+		 * @param elem The completion handler
+		 */
+		public void completionHandlerStart(CompletionHandler elem) {
+			
+			/*
+			try {
+				BPMNActivity bdstate=getBPMNModel(elem, m_folder);
+					
+				pushBPMNActivity(bdstate);
+			} catch(Exception e) {
+				logger.severe("Failed to get state machine for " +
+						"completion handler '"+elem+"': "+e);
+			}
+			*/
+		}
+		
+		/**
+		 * This method ends visiting the completion handler element.
+		 * 
+		 * @param elem The completion handler
+		 */
+		public void completionHandlerEnd(CompletionHandler elem) {
+			
+			/*
+			BPMNActivity umls=getBPMNActivity();
+			
+			if (umls != null) {
+				umls.childrenComplete();
+			}
+
+			popUMLActivity();
+			*/
+		}
+		
+		/**
+		 * This method starts visiting the conditional element.
+		 * 
+		 * @param elem The conditional
+		 */
+		public void conditionalStart(Conditional elem) {
+			
+			try {
+				pushBPMNActivity(new ConditionalActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+				
+				pushBPMNActivity(new SequenceActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+				
+			} catch(Exception e) {
+				logger.severe("Failed to create conditional state: "+e);
+			}
+		}
+		
+		/**
+		 * This method ends visiting the conditional element.
+		 * 
+		 * @param elem The conditional
+		 */
+		public void conditionalEnd(Conditional elem) {
+			
+			popUMLActivity();
+			popUMLActivity();
+		}
+		
+		/**
+		 * This method starts visiting the exception handler element.
+		 * 
+		 * @param elem The exception handler
+		 */
+		public void exceptionHandlerStart(ExceptionHandler elem) {
+			
+			/*
+			try {
+				BPMNActivity bdstate=getBPMNModel(elem);
+					
+				pushBPMNActivity(bdstate);
+			} catch(Exception e) {
+				logger.severe("Failed to get state machine for " +
+						"exception handler '"+elem+"': "+e);
+			}
+			*/
+		}
+		
+		/**
+		 * This method ends visiting the exception handler element.
+		 * 
+		 * @param elem The exception handler
+		 */
+		public void exceptionHandlerEnd(ExceptionHandler elem) {
+			
+			/*
+			BPMNActivity umls=getBPMNActivity();
+			
+			if (umls != null) {
+				umls.childrenComplete();
+			}
+
+			popUMLActivity();
+			*/
+		}
+		
+		/**
+		 * This method visits the finalize activity.
+		 * 
+		 * @param elem The finalize
+		 */
+		public void finalize(Finalize elem) {
+			
+			BPMNActivity umls=getBPMNActivity();
+			if (umls != null) {
+				SimpleActivity state=new SimpleActivity(elem,
+						umls, m_modelFactory, m_notationFactory);
+				
+				/*
+				try {
+					StateMachineState subMachine=
+						getStateMachineState(elem.getCompletionHandler());
+					state.setSubStateMachine(subMachine);
+				} catch(Exception e) {
+					logger.severe("Failed to get state machine: "+e);
+				}
+				*/
+			}
+		}
+		
+		/**
+		 * This method starts visiting the parallel element.
+		 * 
+		 * @param elem The parallel
+		 */
+		public void parallelStart(Parallel elem) {
+			
+			try {
+				pushBPMNActivity(new ParallelActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+				
+			} catch(Exception e) {
+				logger.severe("Failed to create parallel state: "+e);
+			}
+		}
+		
+		/**
+		 * This method ends visiting the parallel element.
+		 * 
+		 * @param elem The parallel
+		 */
+		public void parallelEnd(Parallel elem) {
+			
+			popUMLActivity();
+		}
+		
+		/**
+		 * This method visits the perform activity.
+		 * 
+		 * @param elem The perform
+		 */
+		public void perform(Perform elem) {
+			
+			BPMNActivity umls=getBPMNActivity();
+			if (umls != null) {
+				PerformActivity state=new PerformActivity(elem,
+						umls, m_modelFactory, m_notationFactory);
+				
+				if (elem instanceof LookaheadElement) {
+					LookaheadElement lookahead=(LookaheadElement)elem;
+					boolean f_send=false;
+					boolean f_receive=false;
+					
+					java.util.Iterator iter=lookahead.getPreConditions().iterator();
+					while (iter.hasNext()) {
+						Predicate pred=(Predicate)iter.next();
+						
+						if (pred.isMessagePredicate()) {
+							
+							if (pred.isReceiveLookaheadPredicate()) {
+								f_receive = true;
+							} else {
+								f_send = true;
+							}
+						}
+					}
+					
+					if (f_send && !f_receive) {
+						umls.getBPMNDiagram().registerInitiatingPerform(elem, state);
+					} else if (!f_send && f_receive) {
+						umls.getBPMNDiagram().registerInitiatedPerform(elem, state);
+					}
+				}
+			}
+		}
+		
+		/**
+		 * This method visits the raise exception activity.
+		 * 
+		 * @param elem The raise exception
+		 */
+		public void raiseException(RaiseException elem) {
+			
+			BPMNActivity umls=getBPMNActivity();
+			if (umls != null) {
+				new SimpleActivity(elem, umls, m_modelFactory, m_notationFactory);
+			}
+		}
+		
+		/**
+		 * This method visits the receive activity.
+		 * 
+		 * @param elem The receive
+		 */
+		public void receive(Receive elem) {
+			
+			BPMNActivity umls=getBPMNActivity();
+			if (umls != null) {
+				ReceiveActivity sa=
+					new ReceiveActivity(elem, umls, m_modelFactory, m_notationFactory);
+				
+				// Register the receive to enable links to be established
+				// with an appropriate send
+				BPMNDiagram amodel=umls.getBPMNDiagram();		
+				amodel.registerReceiveActivity(elem, sa);
+			}
+		}
+		
+		/**
+		 * This method starts visiting the repetition type abstract element.
+		 * 
+		 * @param elem The repetition type
+		 */
+		public void repetitionTypeStart(RepetitionType elem) {
+			
+		}
+		
+		/**
+		 * This method ends visiting the repetition type abstract element.
+		 * 
+		 * @param elem The repetition type
+		 */
+		public void repetitionTypeEnd(RepetitionType elem) {
+			
+		}
+		
+		/**
+		 * This method visits the send activity.
+		 * 
+		 * @param elem The send
+		 */
+		public void send(Send elem) {
+			
+			BPMNActivity umls=getBPMNActivity();
+			if (umls != null) {
+				SimpleActivity sa=
+					new SimpleActivity(elem, umls, m_modelFactory, m_notationFactory);
+				
+				// Register the send to enable links to be established
+				// with an appropriate receive
+				BPMNDiagram amodel=umls.getBPMNDiagram();		
+				amodel.registerSendActivity(elem, sa);
+			}
+		}
+		
+		/**
+		 * This method starts visiting the sequence element.
+		 * 
+		 * @param elem The sequence
+		 */
+		public void sequenceStart(Sequence elem) {
+			
+			try {
+				pushBPMNActivity(new SequenceActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+				
+			} catch(Exception e) {
+				logger.severe("Failed to create sequence state: "+e);
+			}
+		}
+		
+		/**
+		 * This method ends visiting the sequence element.
+		 * 
+		 * @param elem The sequence
+		 */
+		public void sequenceEnd(Sequence elem) {
+			
+			popUMLActivity();
+		}
+		
+		/**
+		 * This method starts visiting the service description element.
+		 * 
+		 * @param elem The service description
+		 */
+		public void serviceDescriptionStart(ServiceDescription elem) {
+			
+		}
+		
+		/**
+		 * This method ends visiting the service description element.
+		 * 
+		 * @param elem The service description
+		 */
+		public void serviceDescriptionEnd(ServiceDescription elem) {
+			
+		}
+		
+		/**
+		 * This method starts visiting the structural type abstract element.
+		 * 
+		 * @param elem The structural type
+		 */
+		public void structuralTypeStart(StructuralType elem) {
+			
+		}
+		
+		/**
+		 * This method ends visiting the structural type abstract element.
+		 * 
+		 * @param elem The structural type
+		 */
+		public void structuralTypeEnd(StructuralType elem) {
+			
+			/*
+			BPMNActivity umls=getBPMNActivity();
+			
+			if (umls != null) {
+				umls.childrenComplete();
+			}
+			*/
+		}
+		
+		/**
+		 * This method starts visiting the timed unit element.
+		 * 
+		 * @param elem The timed unit
+		 */
+		public void timedUnitStart(TimedUnit elem) {
+			
+		}
+		
+		/**
+		 * This method ends visiting the timed unit element.
+		 * 
+		 * @param elem The timed unit
+		 */
+		public void timedUnitEnd(TimedUnit elem) {
+			
+		}
+		
+		/**
+		 * This method visits the unobservable activity.
+		 * 
+		 * @param elem The unobservable
+		 */
+		public void unobservable(Unobservable elem) {
+			
+			BPMNActivity umls=getBPMNActivity();
+			if (umls != null) {
+				new SimpleActivity(elem, umls, m_modelFactory, m_notationFactory);
+			}
+		}
+		
+		/**
+		 * This method visits the variable declaration activity.
+		 * 
+		 * @param elem The variable declaration
+		 */
+		public void variableDeclaration(VariableDeclaration elem) {
+			
+		}
+		
+		/**
+		 * This method starts visiting the when element.
+		 * 
+		 * @param elem The when
+		 */
+		public void whenStart(When elem) {
+			
+			try {
+				pushBPMNActivity(new WhenActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+					
+				pushBPMNActivity(new SequenceActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+			} catch(Exception e) {
+				logger.severe("Failed to create when Activity: "+e);
+			}
+		}
+		
+		/**
+		 * This method ends visiting the when element.
+		 * 
+		 * @param elem The when
+		 */
+		public void whenEnd(When elem) {
+			
+			popUMLActivity();
+			popUMLActivity();
+		}
+
+		/**
+		 * This method starts visiting the while element.
+		 * 
+		 * @param elem The while
+		 */
+		public void whileStart(While elem) {
+			
+			try {
+				pushBPMNActivity(new WhileActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+				
+				pushBPMNActivity(new SequenceActivity(elem,
+						getBPMNActivity(), m_modelFactory, m_notationFactory));
+				
+			} catch(Exception e) {
+				logger.severe("Failed to create while Activity: "+e);
+			}
+		}
+		
+		/**
+		 * This method ends visiting the while element.
+		 * 
+		 * @param elem The while
+		 */
+		public void whileEnd(While elem) {
+			
+			popUMLActivity();
+			
+			popUMLActivity();
+		}
+		
+		/**
+		 * This method returns a Activity machine Activity for the supplied
+		 * behavior type. If one already exists, then it will be
+		 * returned, otherwise one will be created.
+		 * 
+		 * @param elem The behavior type
+		 * @return The Activity machine state
+		 */
+		protected BPMNDiagram getBPMNModel(
+					BehaviorDescription elem, String folder) throws BPMNGenerationException {
+			String name=BPMNDiagram.getName(elem);
+			
+			BPMNDiagram ret=(BPMNDiagram)
+						m_activityModels.get(name);
+			
+			if (ret == null) {
+				ret = new BPMNDiagram(m_choreoName, name,
+						null, m_modelFactory, m_notationFactory, folder);
+				
+				m_activityModels.put(name, ret);
+			}
+			
+			// Create activity partition for service
+			/*
+			org.eclipse.uml2.uml.ActivityPartition partition = 
+				(org.eclipse.uml2.uml.ActivityPartition)
+				ret.getTopLevelActivity().createGroup(
+						UMLPackage.eINSTANCE.getActivityPartition());
+			partition.setName(org.pi4soa.common.xml.XMLUtils.getLocalname(
+					elem.getServiceDescription().getName()));
+			ret.setCurrentPartition(partition);
+			*/
+			
+			return(ret);
+		}
+		
+		/**
+		 * This method pushes the supplied UML activity
+		 * onto a stack.
+		 * 
+		 * @param sms The activity
+		 */
+		protected void pushBPMNActivity(BPMNActivity umls) {
+			m_umlActivityStack.insertElementAt(umls, 0);
+		}
+		
+		/**
+		 * This method returns the UML activity found at the
+		 * top of the stack.
+		 * 
+		 * @return The activity
+		 */
+		protected BPMNActivity getBPMNActivity() {
+			BPMNActivity ret=null;
+			
+			if (m_umlActivityStack.size() > 0) {
+				ret = (BPMNActivity)m_umlActivityStack.get(0);
+			}
+			
+			return(ret);
+		}
+		
+		/**
+		 * This method returns the UML activity from the
+		 * top of the stack.
+		 *
+		 */
+		protected void popUMLActivity() {
+			BPMNActivity umls=getBPMNActivity();
+			
+			if (umls != null) {
+				umls.childrenComplete();
+			}
+			
+			if (m_umlActivityStack.size() > 0) {
+				m_umlActivityStack.remove(0);
+			}
+		}
+		
+		/**
+		 * This method completes the construction of the activity
+		 * models.
+		 *
+		 */
+		public void completeModels() throws BPMNGenerationException {
+			java.util.Enumeration iter=m_activityModels.elements();
+			
+			while (iter.hasMoreElements()) {
+				BPMNDiagram amodel=(BPMNDiagram)iter.nextElement();
+				
+				amodel.completeModel();
+			}
+		}
+		
+		private BPMNModelFactory m_modelFactory=null;
+		private BPMNNotationFactory m_notationFactory=null;
+		private String m_folder=null;
+		private String m_choreoName=null;
+		private String m_participant=null;
+	    private java.util.Vector m_umlActivityStack=new java.util.Vector();
+	    private java.util.Hashtable m_activityModels=new java.util.Hashtable();
+	}
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNModelFactory.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNModelFactory.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNModelFactory.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2005-6 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * 26 Jan 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation;
+
+import org.pi4soa.service.behavior.ActivityType;
+
+public interface BPMNModelFactory {
+
+	public String getFileExtension();
+	
+	public void saveModel(String fileName, Object diagram)
+						throws BPMNGenerationException;
+	
+	public Object createDiagram();
+	
+	public Object createPool(Object diagram, String name);
+	
+	public Object createInitialNode(Object container);
+	
+	public Object createSimpleTask(Object container, ActivityType activity);
+	
+	public Object createDataBasedXORGateway(Object container);
+	
+	public Object createEventBasedXORGateway(Object container);
+	
+	public Object createANDGateway(Object container);
+	
+	public Object createFinalNode(Object container);
+	
+	public Object createControlLink(Object container,
+			Object fromNode, Object toNode,
+			String conditionalExpression);
+	
+	public Object createMessageLink(Object container,
+			Object fromNode, Object toNode,
+			org.pi4soa.service.behavior.Receive receive);
+	
+	public Object setLinkExpression(Object link, String expression);
+	
+	public boolean isDecision(Object node);
+	
+	/**
+	 * This method determines if the supplied node is a join. This
+	 * is true, if the node is a data or event based gateway,
+	 * and as incoming edges. This is based on the fact that only
+	 * a join gateway, at the point this method is invoked, would
+	 * have incoming links, otherwise any other gateway would be
+	 * assumed to be the initial gateway in a conditional grouping
+	 * construct.
+	 * 
+	 * @param node
+	 * @return Whether the node is a join
+	 */
+	public boolean isJoin(Object node);
+	
+	public boolean isTerminal(Object node);
+	
+	public void setLabel(Object entity, String label);
+	
+	public Object getSource(Object link);
+	
+	public void setSource(Object link, Object node);
+	
+	public Object getTarget(Object link);
+	
+	public void setTarget(Object link, Object node);
+	
+	public java.util.List getInboundControlLinks(Object node);
+	
+	public java.util.List getOutboundControlLinks(Object node);
+	
+	public java.util.List getInboundMessageLinks(Object node);
+	
+	public java.util.List getOutboundMessageLinks(Object node);
+	
+	public void delete(Object entity);
+	
+	public boolean isDeleted(Object entity);
+	
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNNotationFactory.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNNotationFactory.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/BPMNNotationFactory.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005-6 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * 30 Jan 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation;
+
+
+public interface BPMNNotationFactory {
+
+	public String getFileExtension();
+	
+	public void saveNotation(String modelFileName, Object diagramModel,
+			String notationFileName, Object diagramNotation)
+							throws BPMNGenerationException;
+
+	public Object createDiagram(BPMNModelFactory factory,
+			Object diagramModel, int x, int y, int width, int height);
+	
+	public Object createPool(BPMNModelFactory factory,
+				Object poolModel, Object diagramNotation,
+				int x, int y, int width, int height);
+	
+	public Object createTask(BPMNModelFactory factory,
+			Object taskModel, Object parentNotation,
+					int x, int y, int width, int height);
+	
+	public Object createJunction(BPMNModelFactory factory,
+			Object junctionModel, Object parentNotation,
+					int x, int y, int width, int height);
+		
+	public Object createMessageLink(BPMNModelFactory factory,
+			Object linkModel, Object diagramNotation);
+	
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/DefaultBPMNConfiguration.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/DefaultBPMNConfiguration.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/DefaultBPMNConfiguration.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation;
+
+/**
+ * This class provides the default implementation for the
+ * BPMN configuration interface.
+ *
+ */
+public class DefaultBPMNConfiguration implements BPMNConfiguration {
+
+	/**
+	 * This is the default constructor.
+	 *
+	 */
+	public DefaultBPMNConfiguration() {
+	}
+	
+	/**
+	 * This method returns the UML export format to be used. The list
+	 * of valid export formats is available using the
+	 * #UMLGenerator.getExportFormats() method.
+	 * 
+	 * @return The export format, or null if the default is being used.
+	 */
+	public String getExportFormat() {
+		return(m_exportFormat);
+	}
+	
+	/**
+	 * This method sets the export format.
+	 * 
+	 * @param format The export format
+	 */
+	public void setExportFormat(String format) {
+		m_exportFormat = format;
+	}
+	
+	private String m_exportFormat=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/AbstractBPMNActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/AbstractBPMNActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/AbstractBPMNActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,317 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+public abstract class AbstractBPMNActivity implements BPMNActivity {
+
+	/**
+	 * This is the constructor for the default BPMN activity.
+	 * 
+	 * @param parent The parent
+	 */
+	public AbstractBPMNActivity(BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation) {
+		m_parent = parent;
+		m_modelFactory = model;
+		m_notationFactory = notation;
+		
+		if (parent instanceof AbstractBPMNActivity) {
+			((AbstractBPMNActivity)parent).addChildState(this);
+		}
+	}
+	
+	/**
+	 * This method returns the parent BPMN activity.
+	 * 
+	 * @return The parent
+	 */
+	public BPMNActivity getParent() {
+		return(m_parent);
+	}
+	
+	/**
+	 * This method returns the container associated with the
+	 * activity.
+	 * 
+	 * @return The container
+	 */
+	public Object getContainer() {
+		return(m_parent.getContainer());
+	}
+	
+	/**
+	 * This method returns the model.
+	 * 
+	 * @return The model
+	 */
+	protected org.pi4soa.bpmn.generation.BPMNModelFactory getModelFactory() {
+		return(m_modelFactory);
+	}
+	
+	/**
+	 * This method returns the notation factory.
+	 * 
+	 * @return The notation factory
+	 */
+	protected org.pi4soa.bpmn.generation.BPMNNotationFactory getNotationFactory() {
+		return(m_notationFactory);
+	}
+	
+	/**
+	 * This method adds a child BPMN state.
+	 * 
+	 * @param child The child BPMN state
+	 */
+	protected void addChildState(BPMNActivity child) {
+		m_childStates.add(child);
+	}
+	
+	/**
+	 * This method returns the list of child states.
+	 * 
+	 * @return The child states
+	 */
+	protected java.util.Vector getChildStates() {
+		return(m_childStates);
+	}
+	
+	/**
+	 * This method indicates that the BPMN state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+	}
+	
+	/**
+	 * This method returns the containing BPMN diagram.
+	 * 
+	 * @return The BPMN diagram
+	 */
+	public BPMNDiagram getBPMNDiagram() {
+		BPMNDiagram ret=null;
+		
+		if (m_parent != null) {
+			ret = m_parent.getBPMNDiagram();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the BPMN Activity Model.
+	 * 
+	 * @return The activity model
+	 */
+	/*
+	public Activity getTopLevelActivity() {
+		Activity ret=null;
+		
+		if (m_parent != null) {
+			ret = m_parent.getTopLevelActivity();
+		}
+		
+		return(ret);
+	}
+	*/
+	
+	/**
+	 * This method returns the BPMN Activity Partition.
+	 * 
+	 * @return The activity model
+	 */
+	/*
+	public ActivityPartition getActivityPartition() {
+		ActivityPartition ret=null;
+		
+		if (m_parent != null) {
+			ret = m_parent.getActivityPartition();
+		}
+		
+		return(ret);
+	}
+	*/
+	
+	/**
+	 * This method causes a transition to be established from
+	 * the supplied BPMN state to the current state, applying
+	 * any relevant information (such as event triggers
+	 * or conditios) to the transition as appropriate.
+	 * 
+	 * @param fromNode The source node
+	 * @param expression The optional conditional expression
+	 * @return The edge
+	 */
+	public Object transitionFrom(BPMNActivity fromNode,
+					String conditionalExpression) {
+		Object ret=getModelFactory().createControlLink(getContainer(),
+				fromNode.getEndNode(),
+				getStartNode(), conditionalExpression);
+		
+		/*
+		Activity activity=getTopLevelActivity();
+		ActivityEdge ret=(ActivityEdge)
+				activity.createEdge(null, UMLPackage.eINSTANCE.getControlFlow());
+		ret.getInPartitions().add(getActivityPartition());
+		
+		ret.setSource(fromNode.getEndNode());
+		ret.setTarget(getStartNode());
+		*/
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method joins a list of sequential child BPMN states with transitions.
+	 * 
+	 * @param children The list of child BPMN states
+	 */
+	public void transitionSequentialNodes() {
+		int width=0;
+		int height=0;
+		
+		if (getChildStates().size() > 0) {
+			BPMNActivity v1=(BPMNActivity)getChildStates().get(0);
+			width += v1.getWidth();
+			height = v1.getHeight();
+		}
+		
+		for (int i=1; i < getChildStates().size(); i++) {
+			BPMNActivity v1=(BPMNActivity)getChildStates().get(i-1);
+			BPMNActivity v2=(BPMNActivity)getChildStates().get(i);
+			
+			width += v2.getWidth();
+			
+			width += HORIZONTAL_GAP; // Gap
+			
+			if (height < v2.getHeight()) {
+				height = v2.getHeight();
+			}
+
+			Object endNode=v1.getEndNode();
+			
+			if (v1.canDeleteEndNode() &&
+					(getModelFactory().isJoin(endNode) || // instanceof org.eclipse.uml2.uml.MergeNode ||
+					getModelFactory().isTerminal(endNode))) { // instanceof org.eclipse.uml2.uml.FlowFinalNode) {
+
+				// Move the incoming transitions from the junction
+				// to the next state
+				java.util.List list=getModelFactory().getInboundControlLinks(endNode);
+				for (int j=list.size()-1; j >= 0; j--) {
+					Object transition=list.get(j);
+					
+					getModelFactory().setTarget(transition, v2.getStartNode());
+					//transition.setTarget(v2.getStartNode());
+				}
+				
+				// Remove Junction
+				getModelFactory().delete(endNode);
+				
+			} else {
+				v2.transitionFrom(v1, null);
+			}
+		}
+		
+		//height += VERTICAL_GAP; // Gap
+		
+		setWidth(width);
+		setHeight(height);
+//System.out.println("THIS: children="+m_childStates.size()+
+//		" this="+this+" width="+width+" height="+height);		
+	}
+	
+	public int getX() {
+		return(m_x);
+	}
+	
+	public void setX(int x) {
+//System.out.println("SETX: this="+this+" x="+x);		
+		m_x = x;
+	}
+
+	public int getY() {
+		return(m_y);
+	}
+	
+	public void setY(int y) {
+//System.out.println("SETY: this="+this+" y="+y);		
+		m_y = y;
+	}
+
+	public int getWidth() {
+		return(m_width);
+	}
+	
+	public void setWidth(int width) {
+		m_width = width;
+	}
+
+	public int getHeight() {
+		return(m_height);
+	}
+	
+	public void setHeight(int height) {
+		m_height = height;
+	}
+
+	public void adjustWidth(int width) {
+		float percentChange=width/getWidth();
+		
+		//setWidth(width);
+		
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			int cur=act.getWidth();
+			int newWidth=(int)((float)cur * percentChange);
+			
+			act.adjustWidth(newWidth);
+			
+			int change=act.getWidth()-cur;
+			
+			setWidth(getWidth()+change);
+		}
+	}
+	
+	public void calculatePosition(int x, int y) {
+		setX(x);
+		setY(y);
+	}
+
+	public void draw(Object parent) {
+	}
+	
+	public boolean canDeleteEndNode() {
+		return(true);
+	}
+	
+	public static final int VERTICAL_GAP = 40;
+	public static final int HORIZONTAL_GAP = 50;
+	
+	private BPMNActivity m_parent=null;
+	private org.pi4soa.bpmn.generation.BPMNModelFactory m_modelFactory=null;
+	private org.pi4soa.bpmn.generation.BPMNNotationFactory m_notationFactory=null;
+	private java.util.Vector m_childStates=new java.util.Vector();
+	private int m_x=0;
+	private int m_y=0;
+	private int m_width=0;
+	private int m_height=0;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+/**
+ * This interface represents the generic capabilities of a state
+ * managing component in the CDL to BPMN transformation.
+ *
+ */
+public interface BPMNActivity {
+
+	/**
+	 * This method returns the parent BPMN activity.
+	 * 
+	 * @return The parent
+	 */
+	public BPMNActivity getParent();
+	
+	/**
+	 * This method returns the container object associated
+	 * with this activity.
+	 * 
+	 * @return The container
+	 */
+	public Object getContainer();
+		
+	/**
+	 * This method indicates that the BPMN state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete();
+	
+	/**
+	 * This method returns the BPMN top level Activity.
+	 * 
+	 * @return The top level activity
+	 */
+	//public Activity getTopLevelActivity();
+	
+	/**
+	 * This method returns the containing ActivityModel.
+	 * 
+	 * @return The activity model
+	 */
+	public BPMNDiagram getBPMNDiagram();
+	
+	/**
+	 * This method returns the BPMN Activity Partition.
+	 * 
+	 * @return The activity model
+	 */
+	//public ActivityPartition getActivityPartition();
+	
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode();
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this BPMN activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode();
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState();
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState();
+	
+	/**
+	 * This method causes a transition to be established from
+	 * the supplied BPMN state to the current state, applying
+	 * any relevant information (such as event triggers
+	 * or conditios) to the transition as appropriate.
+	 * 
+	 * @param fromNode The source node
+	 * @param expression The optional conditional expression
+	 * @return The edge
+	 */
+	public Object transitionFrom(BPMNActivity fromNode, String expression);
+	
+	public int getX();
+	
+	public void setX(int x);
+
+	public int getY();
+	
+	public void setY(int y);
+
+	public int getWidth();
+	
+	public void setWidth(int width);
+
+	public int getHeight();
+	
+	public void setHeight(int height);
+	
+	public void adjustWidth(int width);
+	
+	public void calculatePosition(int x, int y);
+	
+	public void draw(Object parent);
+	
+	public boolean canDeleteEndNode();
+	
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNDiagram.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNDiagram.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNDiagram.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,465 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+import org.pi4soa.common.util.NamesUtil;
+import org.pi4soa.service.behavior.BehaviorDescription;
+import org.pi4soa.service.behavior.BehaviorType;
+import org.pi4soa.service.behavior.CompletionHandler;
+import org.pi4soa.service.behavior.ExceptionHandler;
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+
+/**
+ * This class represents the state information associated with
+ * the construction of a BPMN Activity model.
+ *
+ */
+public class BPMNDiagram extends AbstractBPMNActivity {
+
+	/**
+	 * This is the constructor for the activity model.
+	 * 
+	 * @param choreoName The choreography name
+	 * @param diagramName The diagram name
+	 * @param parent The parent activity
+	 * @param model The model factory
+	 * @param folder The output folder
+	 * @exception BPMNGenerationException Failed to construct activity model
+	 */
+	public BPMNDiagram(String choreoName, String diagramName,
+			BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation,
+			String folder) throws BPMNGenerationException {
+		super(parent, model, notation);
+		
+		m_name = choreoName+"_"+diagramName;
+		
+		m_diagram = model.createDiagram();
+		m_folder = folder;
+	}
+	
+	/**
+	 * This method returns the container associated with the
+	 * activity.
+	 * 
+	 * @return The container
+	 */
+	public Object getContainer() {
+		return(m_container);
+	}
+	
+	/**
+	 * This method sets the container associated with the
+	 * BPMN model.
+	 * 
+	 * @param container The container
+	 */
+	public BPMNPool createPool(String participant) {
+		BPMNPool ret=new BPMNPool(m_diagram, participant,
+					this, getModelFactory(), getNotationFactory());
+		
+		if (m_pools.containsKey(participant)) {
+			m_duplicatePools.add(ret);
+		} else {
+			m_pools.put(participant, ret);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the state machine name to be used for the
+	 * supplied behavior type.
+	 * 
+	 * @param elem The behavior type
+	 * @return The name
+	 */
+	public static String getName(BehaviorType elem) {
+		String ret=elem.getName();
+		
+		if (elem instanceof BehaviorDescription) {
+			ret = ((BehaviorDescription)elem).getName();
+			
+			if (org.pi4soa.common.util.NamesUtil.isSet(
+					((BehaviorDescription)elem).getParticipant()) &&
+				ret.endsWith("_"+((BehaviorDescription)elem).getParticipant())) {
+				
+				ret = ret.substring(0, ret.length()-
+						((BehaviorDescription)elem).getParticipant().length()-1);
+			}
+
+		} else if (elem instanceof CompletionHandler) {
+			ret = getName(((CompletionHandler)elem).
+					getEnclosingBehaviorDescription())+"["+
+					ret+"]";
+
+		} else if (elem instanceof ExceptionHandler) {
+			String excType=((ExceptionHandler)elem).getExceptionType();
+			if (NamesUtil.isSet(excType) == false) {
+				excType = "default";
+			}
+			
+			ret = getName(((ExceptionHandler)elem).
+					getEnclosingBehaviorDescription())+"[exception="+
+					excType+"]";
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method determines whether the supplied behavior type
+	 * should result in a root entry/exit point from the
+	 * state machine.
+	 * 
+	 * @param elem The behavior type
+	 * @return Whether it is a root
+	 */
+	protected boolean isRoot(BehaviorType elem) {
+		boolean ret=false;
+		
+		if (elem instanceof BehaviorDescription &&
+				((BehaviorDescription)elem).isRoot()) {
+			ret = true;
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the containing ActivityModel.
+	 * 
+	 * @return The activity model
+	 */
+	public BPMNDiagram getBPMNDiagram() {
+		return(this);
+	}
+	
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this BPMN activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		//return(m_initialState.getStartNode());
+		return(null);
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this BPMN activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		//return(m_finalState.getEndNode());
+		return(null);
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		return(null);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		return(null);
+	}
+	
+	/**
+	 * This method registers a send activity against the BPMN representation.
+	 * 
+	 * @param send The send activity
+	 * @param activity The BPMN representation
+	 */
+	public void registerSendActivity(org.pi4soa.service.behavior.Send send,
+						BPMNActivity activity) {
+		if (isPoolDuplicate(activity) == false) {
+			m_sendActivities.put(send, activity);
+		}
+	}
+		
+	/**
+	 * This method registers a receive activity against the BPMN representation.
+	 * 
+	 * @param recv The receive activity
+	 * @param activity The BPMN representation
+	 */
+	public void registerReceiveActivity(org.pi4soa.service.behavior.Receive recv,
+						BPMNActivity activity) {
+		if (isPoolDuplicate(activity) == false) {
+			m_receiveActivities.put(recv.getGlobalDescriptionURI(), activity);
+		}
+	}
+	
+	/**
+	 * This method registers an initiating perform activity
+	 * against the BPMN representation.
+	 * 
+	 * @param perform The perform activity
+	 * @param activity The BPMN representation
+	 */
+	public void registerInitiatingPerform(org.pi4soa.service.behavior.Perform perform,
+						BPMNActivity activity) {
+		m_initiatingPerforms.put(perform.getGlobalDescriptionURI(), activity);
+	}
+		
+	/**
+	 * This method registers an initiated perform activity
+	 * against the BPMN representation.
+	 * 
+	 * @param perform The perform activity
+	 * @param activity The BPMN representation
+	 */
+	public void registerInitiatedPerform(org.pi4soa.service.behavior.Perform perform,
+						BPMNActivity activity) {
+		m_initiatedPerforms.put(perform.getGlobalDescriptionURI(), activity);
+	}
+	
+	/**
+	 * This method determines if the supplied activity is
+	 * associated with a duplicate pool that will be deleted.
+	 * 
+	 * @param activity The activity
+	 * @return Whether the activity is associated with a
+	 * 					duplicate pool
+	 */
+	protected boolean isPoolDuplicate(BPMNActivity activity) {
+		boolean ret=false;
+		
+		while (activity != null && (activity instanceof BPMNPool)
+							== false) {
+			activity = activity.getParent();
+		}
+		
+		if (activity != null) {
+			ret = m_duplicatePools.contains(activity);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method completes the generation of the model.
+	 *
+	 */
+	public void completeModel() throws BPMNGenerationException {
+		java.util.Enumeration iter=m_sendActivities.keys();
+		java.util.Vector messageLinks=new java.util.Vector();
+		
+		while (iter.hasMoreElements()) {
+			org.pi4soa.service.behavior.Send send=
+				(org.pi4soa.service.behavior.Send)iter.nextElement();
+
+			BPMNActivity sendActivity=(BPMNActivity)
+							m_sendActivities.get(send);
+			ReceiveActivity receiveActivity=(ReceiveActivity)
+							m_receiveActivities.get(send.getGlobalDescriptionURI());
+			
+			if (sendActivity != null && receiveActivity != null) {
+				
+				if (m_sendReceiveAsControlLink) {
+				
+					if (m_controlFromSendOnly) {
+						// Break links to the receive node, as control will
+						// be from the sending participant
+						receiveActivity.breakLinks();
+					}
+					
+					// Create control flow between the activities
+					/*
+					Activity activity=getTopLevelActivity();
+					ActivityEdge ret=(ActivityEdge)
+							activity.createEdge(null, UMLPackage.eINSTANCE.getControlFlow());
+					
+					ret.setSource(sendActivity.getEndNode());
+					ret.setTarget(receiveActivity.getStartNode());
+					
+					ret.setName(send.getOperationName());
+					*/
+					messageLinks.add(getModelFactory().
+							createMessageLink(m_diagram,
+							sendActivity.getEndNode(),
+							receiveActivity.getStartNode(),
+							receiveActivity.getReceive()));
+					
+					// Check if the receive and send activities have a link to the
+					// same node, in which case remove the link from the send
+					checkForRedundantTargetLinks(sendActivity, receiveActivity);
+				}
+			}
+		}
+		
+		// Process initiating and initiated performs
+		/* GPB: COMMENT OUT PERFORM LINKS FOR NOW
+		iter = m_initiatingPerforms.keys();
+		
+		while (iter.hasMoreElements()) {
+			String key=(String)iter.nextElement();
+
+			PerformActivity initiatingPerform=(PerformActivity)
+					m_initiatingPerforms.get(key);
+			PerformActivity initiatedPerform=(PerformActivity)
+					m_initiatedPerforms.get(key);
+			
+			if (initiatingPerform != null && initiatedPerform != null) {
+				
+				if (m_performedAsControlLink) {
+					
+					if (m_controlFromInitiatingPerformOnly) {
+						// Break links to the receive node, as control will
+						// be from the initiating participant
+						initiatedPerform.breakLinks();
+					}
+					
+					// Create control flow between the activities
+					Activity activity=getTopLevelActivity();
+					
+					ActivityEdge ret=(ActivityEdge)
+							activity.createEdge(null, UMLPackage.eINSTANCE.getControlFlow());
+					
+					ret.setSource(initiatingPerform.getEndNode());
+					ret.setTarget(initiatedPerform.getStartNode());
+					
+					// Check if the initiating and initiated performs have a link to the
+					// same node, in which case remove the link from the initiating/
+					checkForRedundantTargetLinks(initiatingPerform, initiatedPerform);
+					
+				}
+				
+				if (m_performedAsDependencyLink) {
+					initiatingPerform.getEndNode().createDependency(
+							initiatedPerform.getStartNode());
+				}
+			}
+		}		
+		*/
+		
+		// Delete duplicate pools
+		for (int i=0; i < m_duplicatePools.size(); i++) {
+			BPMNPool pool=(BPMNPool)m_duplicatePools.get(i);
+			getModelFactory().delete(pool.getContainer());
+			getChildStates().remove(pool);
+		}
+		
+		// Draw diagram
+		int cury=0;
+		
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNPool pool=(BPMNPool)getChildStates().get(i);
+			
+			pool.calculatePosition(0, cury);
+			
+			cury += (pool.getHeight()+100);
+		}
+		
+		getModelFactory().saveModel(m_folder+
+				java.io.File.separator+m_name+"."+
+				getModelFactory().getFileExtension(), m_diagram);
+		
+		// Construct notation
+		Object diagramNotation=getNotationFactory().createDiagram(getModelFactory(), m_diagram,
+					getX(), getY(), getWidth(), getHeight());
+		
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNPool pool=(BPMNPool)getChildStates().get(i);
+
+			pool.draw(diagramNotation);	
+		}
+		
+		/* GPB: 25/4/08
+		 * Don't generate message links, as diagram infers them
+		 * anyway - and in the latest version the link positions
+		 * the label incorrectly. If using the default message
+		 * link is an issue, then need to investigate how to
+		 * get label positioned correctly.
+		for (int i=0; i < messageLinks.size(); i++) {
+			Object mesglink=messageLinks.get(i);
+			
+			getNotationFactory().createMessageLink(getModelFactory(),
+								mesglink, diagramNotation);
+		}
+		*/
+
+		getNotationFactory().saveNotation(m_folder+
+				java.io.File.separator+m_name+"."+
+				getModelFactory().getFileExtension(), m_diagram,
+				m_folder+java.io.File.separator+m_name+"."+
+				getNotationFactory().getFileExtension(), diagramNotation);
+	}
+	
+	protected void checkForRedundantTargetLinks(BPMNActivity source, BPMNActivity target) {
+		
+		// Check if the target and source activities have a link to the
+		// same node, in which case remove the link from the source
+		java.util.List outgoing1=getModelFactory().getOutboundControlLinks(target.getStartNode());
+		
+		for (int i=0; i < outgoing1.size(); i++) {
+			Object ae1=outgoing1.get(i);
+			
+			java.util.List outgoing2=getModelFactory().getOutboundControlLinks(source.getStartNode());
+			boolean f_found=false;
+			
+			for (int j=0; f_found==false && j < outgoing2.size(); j++){ 
+				Object ae2=outgoing2.get(j);
+				
+				if (getModelFactory().getTarget(ae1) == 
+							getModelFactory().getTarget(ae2)) {
+					f_found = true;
+					
+					getModelFactory().delete(ae2);
+				}
+			}
+		}
+	}
+		
+	//private boolean m_completed=false;
+	private String m_name=null;
+	private Object m_diagram=null;
+	private String m_folder=null;
+	private Object m_container=null;
+	//private java.util.Hashtable m_pools=new java.util.Hashtable();
+    //private BPMNActivity m_initialState=null;
+    //private BPMNActivity m_finalState=null;
+    private java.util.Hashtable m_sendActivities=new java.util.Hashtable();
+    private java.util.Hashtable m_receiveActivities=new java.util.Hashtable();
+    private java.util.Hashtable m_initiatingPerforms=new java.util.Hashtable();
+    private java.util.Hashtable m_initiatedPerforms=new java.util.Hashtable();
+    
+    private java.util.Hashtable m_pools=new java.util.Hashtable();
+    private java.util.Vector m_duplicatePools=new java.util.Vector();
+    
+    private boolean m_sendReceiveAsControlLink=true;
+    private boolean m_controlFromSendOnly=false;
+    
+    //private boolean m_performedAsControlLink=true;
+    //private boolean m_performedAsDependencyLink=false;
+    //private boolean m_controlFromInitiatingPerformOnly=false;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNPool.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNPool.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/BPMNPool.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2005-6 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * 29 Jan 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+import org.pi4soa.service.behavior.BehaviorDescription;
+import org.pi4soa.service.behavior.Choice;
+
+public class BPMNPool extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the pool state.
+	 * 
+	 * @param diagram The diagram
+	 * @param name The pool name
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public BPMNPool(Object diagram, String name,
+			BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation) {
+		super(parent, model, notation);
+		
+		initialize(diagram, name);
+	}
+	
+	/**
+	 * This method performs the initialization of the 
+	 * activity model.
+	 * 
+	 * @param diagram The diagram
+	 * @param name The pool name
+	 */
+	public void initialize(Object diagram, String name) {
+		
+		m_pool = getModelFactory().createPool(diagram, name);
+		
+		/*
+		m_activityModel = (org.eclipse.uml2.uml.Activity)
+			servicePackage.createPackagedElement(null,
+				UMLPackage.eINSTANCE.getActivity());
+	
+		m_activityModel.setName(getName(elem));
+		*/
+
+		// Create initial state
+		/*
+		org.eclipse.uml2.uml.InitialNode initialState=
+				(org.eclipse.uml2.uml.InitialNode)
+				m_activityModel.createNode(null, UMLPackage.eINSTANCE.getInitialNode());
+		
+		m_initialState = new SimpleActivity(initialState, this);
+		*/
+		m_initialState = new JunctionActivity(getModelFactory().createInitialNode(getContainer()),
+				this, getModelFactory(), getNotationFactory());
+		
+		// Create final state
+		/*
+		org.eclipse.uml2.uml.FlowFinalNode finalState=
+					(org.eclipse.uml2.uml.FlowFinalNode)
+				m_activityModel.createNode(null, UMLPackage.eINSTANCE.getFlowFinalNode());
+		
+		m_finalState = new SimpleActivity(finalState, this);
+		*/
+		m_finalState = new JunctionActivity(getModelFactory().createFinalNode(getContainer()),
+				this, getModelFactory(), getNotationFactory());
+		
+	}
+	
+	/**
+	 * This method returns the container associated with the
+	 * activity.
+	 * 
+	 * @return The container
+	 */
+	public Object getContainer() {
+		return(m_pool);
+	}
+		
+	public Object getStartNode() {
+		return(m_initialState.getStartNode());
+	}
+	
+	public Object getEndNode() {
+		return(m_finalState.getEndNode());
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		return(m_initialState);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		return(m_finalState);
+	}
+	
+	/**
+	 * This method indicates that the BPMN state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+		
+		if (m_completed == false) {
+			
+			// Move the final state to the end of the list
+			if (getChildStates().remove(m_finalState)) {
+				getChildStates().add(m_finalState);
+			}
+			
+			// Join the child state vertex with transitions
+			transitionSequentialNodes();
+			
+			// Add padding
+			setHeight(getHeight()+(VERTICAL_GAP*2));
+			
+			m_completed = true;
+		}
+	}
+	
+	public void calculatePosition(int x, int y) {
+		int curx=0;
+		int midy=(getHeight()/2);
+		
+		setX(x);
+		setY(y+VERTICAL_GAP);
+		
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.calculatePosition(curx, midy-(act.getHeight()/2));
+			
+			curx += (act.getWidth()+HORIZONTAL_GAP);
+		}
+	}
+	
+	public void draw(Object parent) {
+		
+		// Construct notation
+		Object notation=getNotationFactory().createPool(getModelFactory(), m_pool,
+				parent, getX(), getY(), getWidth(), getHeight());
+		
+		//m_initialState.draw(notation);
+		//m_finalState.draw(notation);
+		
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.draw(notation);
+		}
+	}
+	
+	private boolean m_completed=false;
+	private Object m_pool=null;
+	private BPMNActivity m_initialState=null;
+	private BPMNActivity m_finalState=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ChoiceActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ChoiceActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ChoiceActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,320 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+import org.pi4soa.service.behavior.Choice;
+import org.pi4soa.bpmn.generation.*;
+
+/**
+ * This class represents a selection of states within a
+ * BPMN state machine.
+ *
+ */
+public class ChoiceActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the choice state.
+	 * 
+	 * @param choice The choice
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public ChoiceActivity(Choice choice, BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation)
+						throws BPMNGenerationException {
+		super(parent, model, notation);
+		
+		initialize(choice);		
+	}
+
+	/**
+	 * This method performs the initialization of the 
+	 * choice state.
+	 * 
+	 * @param elem The choice
+	 * @throws BPMNGenerationException Failed to initialize
+	 */
+	protected void initialize(Choice elem) throws BPMNGenerationException {
+		
+		// Get region
+		//Activity region=getTopLevelActivity();
+	
+		// Determine if choice is event based, or data based
+		boolean dataBased=true;
+		
+		java.util.List children=elem.getActivityTypes();
+		for (int i=0; i < children.size(); i++) {
+			org.pi4soa.service.behavior.ActivityType act=
+				(org.pi4soa.service.behavior.ActivityType)children.get(i);
+			
+			if (act instanceof org.pi4soa.service.behavior.StructuralType) {
+				org.pi4soa.service.behavior.StructuralType st=
+					(org.pi4soa.service.behavior.StructuralType)act;
+				
+				if ((st.isConditionalGroupingConstruct() == false ||
+						(st.isConditionalGroupingConstruct() &&
+						st.isConditionObservable() == false)) &&
+						st.isPredicateExtensionRequired() == false) {
+					dataBased = false;
+				}
+				
+				/*
+				String expr=null;
+				
+				if (st instanceof org.pi4soa.service.behavior.Conditional) {
+					expr = ((org.pi4soa.service.behavior.Conditional)st).getExpression();
+				} else if (st instanceof org.pi4soa.service.behavior.While) {
+					expr = ((org.pi4soa.service.behavior.While)st).getExpression();
+				} else if (st instanceof org.pi4soa.service.behavior.When) {
+					expr = ((org.pi4soa.service.behavior.When)st).getExpression();
+				}
+				
+				if (expr != null && expr.trim().length() == 0) {
+					expr = "";
+				}
+				
+				m_expressions.add(expr);
+				*/
+			}
+		}
+		
+		// If not data-based, then clear list of expressions
+		/*
+		if (dataBased == false) {
+			m_expressions.clear();
+		}
+		*/
+		
+		// Create choice state
+		Object choiceState=null;
+		
+		if (dataBased) {
+			choiceState=getModelFactory().createDataBasedXORGateway(getContainer());
+		} else {
+			choiceState=getModelFactory().createEventBasedXORGateway(getContainer());
+		}
+		
+			//region.createNode(null, UMLPackage.eINSTANCE.getDecisionNode());
+		//choiceState.getInPartitions().add(getActivityPartition());
+		
+		m_choiceState = new JunctionActivity(choiceState, this,
+				getModelFactory(), getNotationFactory());
+		
+		// Create junction state
+		Object junctionState=null;
+		
+		if (dataBased) {
+			junctionState=getModelFactory().createDataBasedXORGateway(getContainer());
+		} else {
+			junctionState=getModelFactory().createEventBasedXORGateway(getContainer());
+		}
+
+		//region.createNode(null, UMLPackage.eINSTANCE.getMergeNode());
+		//junctionState.getInPartitions().add(getActivityPartition());
+
+		m_junctionState = new JunctionActivity(junctionState, this,
+				getModelFactory(), getNotationFactory());
+	}
+	
+	/**
+	 * This method indicates that the BPMN state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+		
+		if (m_completed == false) {
+			int width=m_choiceState.getWidth()+m_junctionState.getWidth()+
+						(2 * HORIZONTAL_GAP);
+			int height=0;
+								
+			// Move the junction state to the end of the list
+			if (getChildStates().remove(m_junctionState)) {
+				getChildStates().add(m_junctionState);
+			}
+			
+			// Join the child state vertex with transitions
+			int maxwidth=0;
+			
+			for (int i=1; i < getChildStates().size()-1; i++) {
+				BPMNActivity umls=(BPMNActivity)getChildStates().get(i);
+				
+				height += umls.getHeight();
+				
+				if (i != 1) {
+					height += VERTICAL_GAP;
+				}
+				
+				if (umls.getWidth() > maxwidth) {
+					maxwidth = umls.getWidth();
+				}
+				
+				/*
+				String expr=null;
+				
+				if (m_expressions.size() > 0) {
+					expr = (String)m_expressions.get(i-1);
+					
+					if (expr != null && expr.length() == 0) {
+						expr = null;
+					}
+				}
+				*/
+				
+				umls.transitionFrom(m_choiceState, null);
+				
+				// Check if state is a junction
+				Object endNode=umls.getEndNode();
+				
+				/*
+				if (umls.getEndState().canDeleteEndNode() &&
+						(getModelFactory().isJoin(endNode) || // instanceof org.eclipse.uml2.uml.MergeNode ||
+						getModelFactory().isTerminal(endNode))) { // instanceof org.eclipse.uml2.uml.FlowFinalNode) {
+
+					// Move the incoming transitions from the junction
+					// to the next state
+					java.util.List list=getModelFactory().getInboundControlLinks(endNode);
+					for (int j=list.size()-1; j >= 0; j--) {
+						Object transition=list.get(j);
+						
+						getModelFactory().setTarget(transition, m_junctionState.getStartNode());
+						//transition.setTarget(m_junctionState.getStartNode());
+					}
+					
+					// Remove the junction
+					//endNode.destroy();
+					getModelFactory().delete(endNode);
+				} else {
+				*/
+					m_junctionState.transitionFrom(umls, null);
+				//}
+			}
+			
+			width += maxwidth;
+			
+			if (height < m_choiceState.getHeight()) {
+				height = m_choiceState.getHeight();
+			}
+			
+			if (height < m_junctionState.getHeight()) {
+				height = m_junctionState.getHeight();
+			}
+			
+			setWidth(width);
+			setHeight(height);
+			
+			adjustWidth(width);
+			
+			m_completed = true;
+		}
+	}
+	
+	public void calculatePosition(int x, int y) {
+		int cury=y;
+		int midx=x+(getWidth()/2);
+		int midy=y+(getHeight()/2);
+		
+		setX(x);
+		setY(y);
+		
+		for (int i=1; i < getChildStates().size()-1; i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.calculatePosition(midx-(act.getWidth()/2), cury);
+			//midy-(act.getHeight()/2));
+
+			cury += (act.getHeight()+VERTICAL_GAP);
+		}
+		
+		m_choiceState.calculatePosition(x, midy-(m_choiceState.getHeight()/2));
+		m_junctionState.calculatePosition(x+getWidth()-
+				m_junctionState.getWidth(),
+				midy-(m_junctionState.getHeight()/2));
+	}
+	
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this BPMN activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		return(m_choiceState.getStartNode());
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this BPMN activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		return(m_junctionState.getEndNode());
+	}
+		
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		return(m_choiceState);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		return(m_junctionState);
+	}
+	
+	public void adjustWidth(int width) {
+		
+		int extrawidth=m_choiceState.getWidth()+m_junctionState.getWidth()+
+						(2 * HORIZONTAL_GAP);
+		
+		setWidth(width);
+		
+		// Adjust child widths
+		for (int i=1; i < getChildStates().size()-1; i++) {
+			BPMNActivity umls=(BPMNActivity)getChildStates().get(i);
+			
+			umls.adjustWidth(width-extrawidth);
+		}
+	}
+	
+	public void draw(Object parent) {
+		
+		// Construct notation
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.draw(parent);
+		}
+	}
+	
+	private boolean m_completed=false;
+    private BPMNActivity m_choiceState=null;
+    private BPMNActivity m_junctionState=null;
+    //private java.util.Vector m_expressions=new java.util.Vector();
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ConditionalActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ConditionalActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ConditionalActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,362 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+import org.pi4soa.service.behavior.Choice;
+import org.pi4soa.service.behavior.Conditional;
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+
+/**
+ * This class represents a conditional decision within a
+ * BPMN state machine.
+ *
+ */
+public class ConditionalActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the conditional state.
+	 * 
+	 * @param conditional The conditional
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public ConditionalActivity(Conditional conditional,
+					BPMNActivity parent,
+					org.pi4soa.bpmn.generation.BPMNModelFactory model,
+					org.pi4soa.bpmn.generation.BPMNNotationFactory notation)
+						throws BPMNGenerationException {
+		super(parent, model, notation);
+		
+		initialize(conditional);		
+	}
+
+	/**
+	 * This method performs the initialization of the 
+	 * conditional state.
+	 * 
+	 * @param elem The conditional
+	 * @throws BPMNGenerationException Failed to initialize
+	 */
+	protected void initialize(Conditional elem) throws BPMNGenerationException {
+		m_choiceElement = (elem.getParent() instanceof Choice);
+		
+		// TODO: condition expression causes problem when used as
+		// name
+		m_conditionalDescription = elem.getName();
+		
+		if (org.pi4soa.common.util.NamesUtil.isSet(elem.getExpression())) {
+			m_conditionalExpression = elem.getExpression();
+		}
+		
+		if (isChoiceElement() == false) {
+			
+			// Get region
+			/*
+			Activity region=getTopLevelActivity();
+			
+			// Create choice state
+			ActivityNode choiceState = region.createNode(null,
+						UMLPackage.eINSTANCE.getDecisionNode());
+			choiceState.getInPartitions().add(getActivityPartition());
+			*/
+			Object choiceState=getModelFactory().createDataBasedXORGateway(getContainer());
+			
+			m_choiceState = new JunctionActivity(choiceState, this,
+					getModelFactory(), getNotationFactory());
+			
+			// Create junction state
+			/*
+			ActivityNode junctionState = region.createNode(null,
+					UMLPackage.eINSTANCE.getMergeNode());
+			junctionState.getInPartitions().add(getActivityPartition());
+			 */
+			Object junctionState=getModelFactory().createDataBasedXORGateway(getContainer());
+			
+			m_junctionState = new JunctionActivity(junctionState, this,
+					getModelFactory(), getNotationFactory());
+		}
+	}
+	
+	/**
+	 * This method determines whether the conditional is a
+	 * choice element.
+	 * 
+	 * @return Whether a choice element
+	 */
+	protected boolean isChoiceElement() {
+		return(m_choiceElement);
+	}
+	
+	/**
+	 * This method indicates that the UML state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+		
+		if (m_completed == false) {
+			
+			if (isChoiceElement() == false) {
+				
+				// Move the junction state to the end of the list
+				if (getChildStates().remove(m_junctionState)) {
+					getChildStates().add(m_junctionState);
+				}
+			}
+			
+			// Join the child state vertex with transitions
+			transitionSequentialNodes();
+			
+			if (isChoiceElement() == false) {
+				
+				// Place the condition on the outgoing transition
+				// from the choice state, before adding the alternate
+				// 'false' path
+				java.util.List list=getModelFactory().getOutboundControlLinks(m_choiceState.getEndNode());
+
+				if (list.size() > 0) {
+					Object outgoing=list.get(0);
+
+					/*
+					org.eclipse.uml2.uml.OpaqueExpression expr=
+						(org.eclipse.uml2.uml.OpaqueExpression)
+						outgoing.createGuard("expression", null,
+							UMLPackage.eINSTANCE.getOpaqueExpression());
+					*/
+					
+					if (m_conditionalExpression != null) {
+						//expr.getBodies().add(m_conditionalExpression);
+						getModelFactory().setLinkExpression(outgoing,
+								m_conditionalExpression);
+					} else {
+						//expr.getBodies().add("<non-observable>");								
+						getModelFactory().setLinkExpression(outgoing,
+								"<non-observable>");
+					}
+				}
+				
+				// Have direct transition from choice to junction
+				// to represent the 'false' path
+				Object transition=
+						m_junctionState.transitionFrom(m_choiceState,
+								"false()");
+				//transition.setName("false");
+				
+				/*
+				org.eclipse.uml2.uml.OpaqueExpression expr=
+					(org.eclipse.uml2.uml.OpaqueExpression)
+					transition.createGuard("expression", null,
+						UMLPackage.eINSTANCE.getOpaqueExpression());
+					
+				expr.getBodies().add("false()");
+				*/
+			}
+						
+			if (isChoiceElement() == false) {
+				int width=0;
+				int height=0;
+				
+				// Calculate extra width
+				/*
+				width = m_junctionState.getWidth()+
+						(HORIZONTAL_GAP*2)+
+						m_choiceState.getWidth();
+				*/
+				
+				height = m_choiceState.getHeight();
+				
+				if (height < m_junctionState.getHeight()) {
+					height = m_junctionState.getHeight();
+				}
+				
+				height += (VERTICAL_GAP*2);
+				
+				setWidth(getWidth()+width);
+				setHeight(getHeight()+height);
+			}
+			
+			m_completed = true;
+		}
+	}
+	
+	/**
+	 * This method causes a transition to be established from
+	 * the supplied BPMN state to the current state, applying
+	 * any relevant information (such as event triggers
+	 * or conditions) to the transition as appropriate.
+	 * 
+	 * @param fromVertex The source vertex
+	 * @return The transition
+	 */
+	public Object transitionFrom(BPMNActivity fromVertex,
+			String conditionalExpression) {
+		Object ret=null;
+		
+		if (isChoiceElement()) {
+			String expr=m_conditionalExpression;
+			
+			if (expr == null) {
+				expr = "<non-observable>";
+			}
+			
+			ret = super.transitionFrom(fromVertex, expr);
+		} else {
+			ret = super.transitionFrom(fromVertex, conditionalExpression);
+		}
+
+		if (ret != null && m_conditionalDescription != null) {
+			String name=m_conditionalDescription.replace(' ', '_');
+			getModelFactory().setLabel(ret, name);
+		}
+		
+		return(ret);
+	}
+
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this BPMN activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		Object ret=null;
+		
+		if (isChoiceElement() == false) {
+			ret = m_choiceState.getStartNode();
+			
+		} else if (getChildStates().size() > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(0);
+			ret = state.getStartNode();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this BPMN activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		Object ret=null;
+		int len=0;
+		
+		if (isChoiceElement() == false) {
+			ret = m_junctionState.getEndNode();
+			
+		} else if ((len=getChildStates().size()) > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(len-1);
+			ret = state.getEndNode();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		BPMNActivity ret=null;
+		
+		if (isChoiceElement() == false) {
+			ret = m_choiceState;
+			
+		} else if (getChildStates().size() > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(0);
+			ret = state;
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		BPMNActivity ret=null;
+		int len=0;
+		
+		if (isChoiceElement() == false) {
+			ret = m_junctionState;
+			
+		} else if ((len=getChildStates().size()) > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(len-1);
+			ret = state;
+		}
+		
+		return(ret);
+	}
+	
+	public void calculatePosition(int x, int y) {
+		if (isChoiceElement()) {
+			
+			for (int i=0; i < getChildStates().size(); i++) {
+				BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+				
+				if (act instanceof SequenceActivity) {
+					act.calculatePosition(x, y);
+				}
+			}
+			
+		} else {
+			int junctionY=y+getHeight()-VERTICAL_GAP;
+			//int junctionY=y+(getHeight()/2);
+			
+			m_choiceState.calculatePosition(x, junctionY-
+					(m_choiceState.getHeight()/2));
+			m_junctionState.calculatePosition(x+getWidth()-
+					m_junctionState.getWidth(), junctionY-
+					(m_junctionState.getHeight()/2));
+			
+			for (int i=0; i < getChildStates().size(); i++) {
+				BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+				
+				if (act instanceof SequenceActivity) {
+					act.calculatePosition(x+
+								m_choiceState.getWidth()+
+								HORIZONTAL_GAP, y);
+				}
+			}
+		}
+	}
+	
+	public void draw(Object parent) {
+		
+		// Construct notation
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.draw(parent);
+		}
+	}
+	
+	private boolean m_completed=false;
+	private boolean m_choiceElement=false;
+	
+    private BPMNActivity m_choiceState=null;
+    private BPMNActivity m_junctionState=null;
+    private String m_conditionalDescription=null;
+    private String m_conditionalExpression=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/JunctionActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/JunctionActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/JunctionActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+/**
+ * This class represents a junction within a
+ * BPMN process.
+ *
+ */
+public class JunctionActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the junction activity.
+	 * 
+	 * @param node The junction node
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public JunctionActivity(Object node,
+			BPMNActivity parent, org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation) {
+		super(parent, model, notation);
+		
+		m_node = node;
+		
+	}
+	
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		return(m_node);
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		return(m_node);
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		return(this);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		return(this);
+	}
+	
+	public int getWidth() {
+		return(30);
+	}
+	
+	public int getHeight() {
+		return(30);
+	}
+	
+	public void draw(Object parent) {
+		
+		if (getModelFactory().isDeleted(m_node) == false) {
+			getNotationFactory().createJunction(getModelFactory(),
+					m_node, parent, getX(), getY(), getWidth(), getHeight());
+		}
+	}
+	
+	private Object m_node=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ParallelActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ParallelActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ParallelActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,252 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+import org.pi4soa.service.behavior.Parallel;
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+
+/**
+ * This class represents a parallel grouping of states within a
+ * UML state machine.
+ *
+ */
+public class ParallelActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the parallel state.
+	 * 
+	 * @param parallel The parallel
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public ParallelActivity(Parallel parallel, BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation)
+						throws BPMNGenerationException {
+		super(parent, model, notation);
+		
+		initialize(parallel);		
+	}
+
+	/**
+	 * This method performs the initialization of the 
+	 * parallel state.
+	 * 
+	 * @param elem The parallel
+	 * @throws BPMNGenerationException Failed to initialize
+	 */
+	protected void initialize(Parallel elem) throws BPMNGenerationException {
+		
+		// Get region
+		/*
+		Activity region=getTopLevelActivity();
+		
+		// Create parallel state
+		ActivityNode parallelState = region.createNode(null,
+				UMLPackage.eINSTANCE.getForkNode());
+		parallelState.getInPartitions().add(getActivityPartition());
+		*/
+		Object parallelState=getModelFactory().createANDGateway(getContainer());
+		
+		m_forkState = new JunctionActivity(parallelState, this,
+				getModelFactory(), getNotationFactory());
+		
+		// Create join state
+		/*
+		ActivityNode joinState = region.createNode(null,
+				UMLPackage.eINSTANCE.getJoinNode());
+		joinState.getInPartitions().add(getActivityPartition());
+		*/
+		
+		Object joinState=getModelFactory().createANDGateway(getContainer());
+		
+		m_joinState = new JunctionActivity(joinState, this,
+				getModelFactory(), getNotationFactory());
+	}
+	
+	/**
+	 * This method indicates that the UML state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+		
+		if (m_completed == false) {
+			int width=m_forkState.getWidth()+m_joinState.getWidth()+
+							(2 * HORIZONTAL_GAP);
+			int height=0;
+			
+			// Move the junction state to the end of the list
+			if (getChildStates().remove(m_joinState)) {
+				getChildStates().add(m_joinState);
+			}
+			
+			// Join the child state vertex with transitions
+			int maxwidth=0;
+
+			for (int i=1; i < getChildStates().size()-1; i++) {
+				BPMNActivity umls=(BPMNActivity)getChildStates().get(i);
+				
+				height += (umls.getHeight()+VERTICAL_GAP);
+				
+				if (umls.getWidth() > maxwidth) {
+					maxwidth = umls.getWidth();
+				}
+
+				umls.transitionFrom(m_forkState, null);
+				
+				// Check if state is a junction
+				Object endNode=umls.getEndNode();
+				
+				/* Do not remove endpoint junctions from
+				 * parallel elements, as this can cause issues
+				 * with layout
+				if (getModelFactory().isJoin(endNode) || // instanceof org.eclipse.uml2.uml.MergeNode ||
+						getModelFactory().isTerminal(endNode)) { // instanceof org.eclipse.uml2.uml.FlowFinalNode) {
+
+					// Move the incoming transitions from the junction
+					// to the next state
+					java.util.List list=getModelFactory().getInboundControlLinks(endNode);
+					for (int j=list.size()-1; j >= 0; j--) {
+						Object transition=list.get(j);
+						
+						getModelFactory().setTarget(transition,
+								m_joinState.getStartNode());
+					}
+					
+					// Remove the junction
+					getModelFactory().delete(endNode);
+				} else {
+				*/
+					m_joinState.transitionFrom(umls, null);
+				//}
+			}
+			
+			width += maxwidth;
+			
+			if (height >= HORIZONTAL_GAP) {
+				height -= HORIZONTAL_GAP;
+			}
+			
+			if (height < m_forkState.getHeight()) {
+				height = m_forkState.getHeight();
+			}
+			
+			if (height < m_joinState.getHeight()) {
+				height = m_joinState.getHeight();
+			}
+			
+			setWidth(width);
+			setHeight(height);
+
+			adjustWidth(width);
+			
+			m_completed = true;
+		}
+	}
+	
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		return(m_forkState.getStartNode());
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		return(m_joinState.getEndNode());
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		return(m_forkState);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		return(m_joinState);
+	}
+	
+	public void adjustWidth(int width) {
+		int extrawidth=m_forkState.getWidth()+m_joinState.getWidth()+
+						(2 * HORIZONTAL_GAP);
+		
+		setWidth(width);
+		
+		// Adjust child widths
+		for (int i=1; i < getChildStates().size()-1; i++) {
+			BPMNActivity umls=(BPMNActivity)getChildStates().get(i);
+			
+			umls.adjustWidth(width-extrawidth);
+		}
+	}
+	
+	public void calculatePosition(int x, int y) {
+		int cury=y;
+		int midx=x+(getWidth()/2);
+		int midy=y+(getHeight()/2);
+		
+		setX(x);
+		setY(y);
+		
+		for (int i=1; i < getChildStates().size()-1; i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.calculatePosition(midx-(act.getWidth()/2), cury);
+			//midy-(act.getHeight()/2));
+
+			cury += (act.getHeight()+VERTICAL_GAP);
+		}
+		
+		m_forkState.calculatePosition(x, midy);
+		m_joinState.calculatePosition(x+getWidth()-
+				m_joinState.getWidth(), midy);
+	}
+	
+	public void draw(Object parent) {
+		
+		// Construct notation
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.draw(parent);
+		}
+	}
+
+	private boolean m_completed=false;
+    private BPMNActivity m_forkState=null;
+    private BPMNActivity m_joinState=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/PerformActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/PerformActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/PerformActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+/**
+ * This class represents the BPMN activity node for a Perform activity.
+ * 
+ */
+public class PerformActivity extends SimpleActivity {
+
+	/**
+	 * This constructor initializes the receive state.
+	 * 
+	 * @param act The behavioral activity
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public PerformActivity(org.pi4soa.service.behavior.ActivityType act,
+			BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation) {
+		super(act, parent, model, notation);
+	}
+	
+	/**
+	 * This method causes the receive activity to break any
+	 * existing control links, including removing preceeding
+	 * nodes that only have these links as their outgoing
+	 * links.
+	 *
+	 */
+	public void breakLinks() {
+		Object node=getStartNode();
+		
+		java.util.List list=getModelFactory().getInboundControlLinks(node);
+		
+		for (int i=list.size()-1; i >= 0; i--) {
+			Object edge=list.get(i);
+			
+			tidyUpEdge(edge);
+		}
+ 	}
+	
+	/**
+	 * This method tidies up an activity edge, recursively being
+	 * called if its source node only has a single incoming
+	 * activity edge.
+	 * 
+	 * @param edge The activity edge
+	 */
+	protected void tidyUpEdge(Object edge) {
+		
+		// Check if source node has only a single incoming link
+		// and if so, then remove the node
+		Object sourceNode=getModelFactory().getSource(edge);
+		
+		getModelFactory().delete(edge);
+		
+		// If has less than 2 incoming links and no
+		// outgoing link, then tidyup node and links recursively
+		if (getModelFactory().getInboundControlLinks(sourceNode).size() <= 1 &&
+				getModelFactory().getOutboundControlLinks(sourceNode).size() == 0 &&
+				(getModelFactory().isDecision(sourceNode) ||	// was decision node
+					getModelFactory().isJoin(sourceNode))) {	// was merge node
+			if (getModelFactory().getInboundControlLinks(sourceNode).size() == 1) {
+				Object actedge=getModelFactory().
+						getInboundControlLinks(sourceNode).get(0);
+				
+				tidyUpEdge(actedge);
+			}
+			
+			getModelFactory().delete(sourceNode);
+		}
+	}
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ReceiveActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ReceiveActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/ReceiveActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+/**
+ * This class represents the UML activity node for a Receive activity.
+ * 
+ */
+public class ReceiveActivity extends SimpleActivity {
+
+	/**
+	 * This constructor initializes the receive state.
+	 * 
+	 * @param act The behavioral activity
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public ReceiveActivity(org.pi4soa.service.behavior.Receive act,
+			BPMNActivity parent, org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation) {
+		super(act, parent, model, notation);
+		
+		m_receive = act;
+	}
+	
+	/**
+	 * This method returns the behavioral receive activity.
+	 * 
+	 * @return The receive activity
+	 */
+	public org.pi4soa.service.behavior.Receive getReceive() {
+		return(m_receive);
+	}
+	
+	/**
+	 * This method causes the receive activity to break any
+	 * existing control links, including removing preceeding
+	 * nodes that only have these links as their outgoing
+	 * links.
+	 *
+	 */
+	public void breakLinks() {
+		Object node=getStartNode();
+		
+		java.util.List list=getModelFactory().getInboundControlLinks(node);
+		
+		for (int i=list.size()-1; i >= 0; i--) {
+			Object edge=list.get(i);
+			
+			tidyUpEdge(edge);
+		}
+ 	}
+	
+	/**
+	 * This method tidies up an activity edge, recursively being
+	 * called if its source node only has a single incoming
+	 * activity edge.
+	 * 
+	 * @param edge The activity edge
+	 */
+	protected void tidyUpEdge(Object edge) {
+		
+		// Check if source node has only a single incoming link
+		// and if so, then remove the node
+		Object sourceNode=getModelFactory().getSource(edge);
+		
+		getModelFactory().delete(edge);
+		
+		// If has less than 2 incoming links and no
+		// outgoing link, then tidyup node and links recursively
+		if (getModelFactory().getInboundControlLinks(sourceNode).size() <= 1 &&
+				getModelFactory().getOutboundControlLinks(sourceNode).size() == 0 &&
+				(getModelFactory().isDecision(sourceNode) ||	// was decision node
+					getModelFactory().isJoin(sourceNode))) {	// was merge node
+			if (getModelFactory().getInboundControlLinks(sourceNode).size() == 1) {
+				Object actedge=getModelFactory().
+						getInboundControlLinks(sourceNode).get(0);
+				
+				tidyUpEdge(actedge);
+			}
+			
+			getModelFactory().delete(sourceNode);
+		}
+	}
+	
+	private org.pi4soa.service.behavior.Receive m_receive=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SequenceActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SequenceActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SequenceActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,186 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+//import org.pi4soa.service.behavior.Sequence;
+
+/**
+ * This class represents a sequence of states within a
+ * UML state machine.
+ *
+ */
+public class SequenceActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the sequence state.
+	 * 
+	 * @param sequence The sequence
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public SequenceActivity(org.pi4soa.service.behavior.ActivityType sequence, 
+			BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation) {
+		super(parent, model, notation);
+		
+		//addChildState(new SimpleState(null, this));
+		//addChildState(new SimpleState(null, this));
+	}
+
+	/**
+	 * This method indicates that the UML state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+		
+		if (m_completed == false) {
+			
+			// Join the child state vertex with transitions
+			/*
+			for (int i=1; i < getChildStates().size(); i++) {
+				UMLState v1=(UMLState)getChildStates().get(i-1);
+				UMLState v2=(UMLState)getChildStates().get(i);
+				
+				v2.transitionFrom(v1);
+			}
+			*/
+			transitionSequentialNodes();
+			
+			m_completed = true;
+		}
+	}
+	
+	public void calculatePosition(int x, int y) {
+		int curx=x;
+		int midy=y+(getHeight()/2);
+		
+		setX(x);
+		setY(y);
+		
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.calculatePosition(curx, midy-(act.getHeight()/2));
+			
+			curx += (act.getWidth()+HORIZONTAL_GAP);
+		}
+	}
+	
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		Object ret=null;
+		
+		if (getChildStates().size() > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(0);
+			ret = state.getStartNode();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		Object ret=null;
+		int len=0;
+		
+		if ((len=getChildStates().size()) > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(len-1);
+			ret = state.getEndNode();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		BPMNActivity ret=null;
+		
+		if (getChildStates().size() > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(0);
+			ret = state;
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		BPMNActivity ret=null;
+		int len=0;
+		
+		if ((len=getChildStates().size()) > 0) {
+			BPMNActivity state=(BPMNActivity)getChildStates().get(len-1);
+			ret = state.getEndState();
+		}
+		
+		return(ret);
+	}
+	
+	public void adjustWidth(int width) {
+		float percentChange=((float)width)/((float)getWidth());
+		
+		//setWidth(width);
+		
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			int cur=act.getWidth();
+			int newWidth=(int)((float)cur * percentChange);
+			
+			act.adjustWidth(newWidth);
+			
+			int change=act.getWidth()-cur;
+			
+			setWidth(getWidth()+change);
+		}
+	}
+	
+	public void draw(Object parent) {
+		
+		// Construct notation
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.draw(parent);
+		}
+	}
+	
+	private boolean m_completed=false;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SimpleActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SimpleActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/SimpleActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+/**
+ * This class represents a simple task within a
+ * BPMN process.
+ *
+ */
+public class SimpleActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the simple activity.
+	 * 
+	 * @param act The behavioral activity
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public SimpleActivity(org.pi4soa.service.behavior.ActivityType act,
+			BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation) {
+		super(parent, model, notation);
+		
+		// Create a state
+		/*
+		Activity region=getTopLevelActivity();
+		
+		if (region != null) {
+			m_node = (ActivityNode)
+				region.createNode(null, UMLPackage.eINSTANCE.getCallBehaviorAction());
+			m_node.getInPartitions().add(getActivityPartition());
+			
+			if (label != null) {
+				m_node.setName(label);
+			}
+		}
+		*/
+		m_node = model.createSimpleTask(getContainer(), act);
+		
+	}
+	
+	/**
+	 * Internal constructor which can be used to wrap a vertex.
+	 * 
+	 * @param vertex The vertex
+	 * @param parent The parent state
+	 */
+	/*
+	protected SimpleActivity(org.eclipse.uml2.uml.ActivityNode node, BPMNActivity parent) {
+		super(parent);
+		
+		m_node = node;
+	}
+	*/
+	
+	/**
+	 * This method sets the association between this state and
+	 * the sub-state machine that it represents.
+	 * 
+	 * @param subMachine The sub state machine
+	 */
+	/*
+	public void setSubStateMachine(ActivityModel subMachine) {
+		
+		((State)m_node).setSubmachine(subMachine.getStateMachine());
+	}
+	*/
+
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		return(m_node);
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		return(m_node);
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		return(this);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		return(this);
+	}
+	
+	public int getWidth() {
+		return(m_width);
+	}
+	
+	public int getHeight() {
+		return(60);
+	}
+	
+	public void adjustWidth(int width) {
+		m_width = width;
+	}
+	
+	public void draw(Object parent) {
+		getNotationFactory().createTask(getModelFactory(),
+				m_node, parent, getX(), getY(), getWidth(), getHeight());
+	}
+	
+	private Object m_node=null;
+	private int m_width=110;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhenActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhenActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhenActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,387 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+import org.pi4soa.service.behavior.When;
+
+/**
+ * This class represents a when activity within a
+ * UML state machine.
+ *
+ */
+public class WhenActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the when state.
+	 * 
+	 * @param when The when
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public WhenActivity(When when, BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation)
+					throws BPMNGenerationException {
+		super(parent, model, notation);
+		
+		initialize(when);		
+	}
+
+	/**
+	 * This method performs the initialization of the 
+	 * when's state.
+	 * 
+	 * @param elem The when
+	 * @throws BPMNGenerationException Failed to initialize
+	 */
+	protected void initialize(When elem) throws BPMNGenerationException {
+		
+		if (org.pi4soa.common.util.NamesUtil.isSet(elem.getExpression())) {
+			m_conditionalExpression = elem.getExpression();
+		}
+
+		if (org.pi4soa.common.util.NamesUtil.isSet(elem.getReEvaluateExpression())) {
+			m_repeatExpression = elem.getReEvaluateExpression();
+		}
+				
+		// Get region
+		/*
+		Activity region=getTopLevelActivity();
+		
+		ActivityNode initialState = region.createNode(null,
+				UMLPackage.eINSTANCE.getCallBehaviorAction());
+		initialState.setName(UMLGenerationUtil.processName("When "+elem.getName()));
+		initialState.getInPartitions().add(getActivityPartition());
+		m_initialState = new SimpleActivity(initialState, this);
+		*/
+
+		m_initialState = new SimpleActivity(elem, this, getModelFactory(),
+				getNotationFactory());
+
+		// Only create end choice if there is a possibility of repeating
+		if (m_repeatExpression != null) {
+			/*
+			ActivityNode endChoiceState = region.createNode(null,
+					UMLPackage.eINSTANCE.getDecisionNode());
+			endChoiceState.getInPartitions().add(getActivityPartition());
+			
+			m_endChoiceState = new SimpleActivity(endChoiceState, this);
+			*/
+			
+			Object endChoiceState=getModelFactory().createDataBasedXORGateway(getContainer());
+			
+			m_endChoiceState = new JunctionActivity(endChoiceState, this,
+					getModelFactory(), getNotationFactory());
+
+			// Create junction state
+			Object junctionState=getModelFactory().createFinalNode(getContainer());
+			
+			m_junctionState = new JunctionActivity(junctionState, this,
+					getModelFactory(), getNotationFactory());
+		}
+	}
+	
+	/**
+	 * This method indicates that the UML state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+		
+		if (m_completed == false) {
+			
+			// Move the end choice state to the end of the list
+			if (m_endChoiceState != null &&
+					getChildStates().remove(m_endChoiceState)) {
+				getChildStates().add(m_endChoiceState);
+			}
+			
+			// Move the junction state to the end of the list
+			boolean junctionRemoved=false;
+			
+			if (m_junctionState != null) {
+				junctionRemoved = getChildStates().remove(m_junctionState);
+			}
+
+			// If no repeat condition, then include junction before
+			// setting up sequential transitions
+			if (junctionRemoved && m_repeatExpression == null) {
+				getChildStates().add(m_junctionState);				
+			}
+			
+			// Join the child state vertex with transitions
+			// Don't join the endChoice and junction states here
+			transitionSequentialNodes();
+			
+			/*
+			java.util.List list=m_initialState.getEndNode().getOutgoings();
+			
+			if (list.size() > 0) {
+				ActivityEdge transition=(ActivityEdge)list.get(0);
+				
+				org.eclipse.uml2.uml.OpaqueExpression expr=
+					(org.eclipse.uml2.uml.OpaqueExpression)
+					transition.createGuard("expression", null,
+							UMLPackage.eINSTANCE.getOpaqueExpression());
+				
+				if (m_conditionalExpression != null) {
+					expr.getBodies().add(m_conditionalExpression);
+				} else {
+					expr.getBodies().add("<non-observable>");				
+				}
+			}
+			*/
+			java.util.List list=getModelFactory().getOutboundControlLinks(m_initialState.getEndNode());
+
+			if (list.size() > 0) {
+				Object outgoing=list.get(0);
+
+				if (m_conditionalExpression != null) {
+					getModelFactory().setLinkExpression(outgoing,
+							m_conditionalExpression);
+				} else {
+					getModelFactory().setLinkExpression(outgoing,
+							"<non-observable>");
+				}
+			}
+			
+			// Junction is re-added after setting up the sequential transitions,
+			// so that it is not sequentially transitioned - only transition
+			// to the junction state based on an appropriate condition
+			// evaluation
+			if (junctionRemoved && m_repeatExpression != null) {
+				getChildStates().add(m_junctionState);				
+			}
+			
+			// Transition from end choice state to start vertex
+			// to represent the loop back
+			if (m_repeatExpression != null) {
+				/*
+				ActivityEdge loopback=
+					m_initialState.transitionFrom(m_endChoiceState);
+				
+				org.eclipse.uml2.uml.OpaqueExpression expr=
+					(org.eclipse.uml2.uml.OpaqueExpression)
+					loopback.createGuard("expression", null,
+						UMLPackage.eINSTANCE.getOpaqueExpression());
+				
+				expr.getBodies().add(m_repeatExpression);
+				*/
+				m_initialState.transitionFrom(m_endChoiceState,
+							m_repeatExpression);				
+								
+				// Transition from end choice state to junction, to
+				// represent the situation where the loopback does
+				// not occur
+				/*
+				ActivityEdge whenEnd=
+					m_junctionState.transitionFrom(m_endChoiceState);
+	
+				expr = (org.eclipse.uml2.uml.OpaqueExpression)
+						whenEnd.createGuard("expression", null,
+						UMLPackage.eINSTANCE.getOpaqueExpression());
+				
+				expr.getBodies().add("false()");
+				*/
+				m_junctionState.transitionFrom(m_endChoiceState,
+						"false()");
+			}
+			
+			int width=0;
+			int height=0;
+			
+			// Calculate extra width
+			if (m_junctionState != null) {
+				width = m_junctionState.getWidth()+HORIZONTAL_GAP;
+			
+				height = m_initialState.getHeight();
+				
+				if (m_junctionState != null &&
+						height < m_junctionState.getHeight()) {
+					height = m_junctionState.getHeight();
+				}
+				
+				height += (VERTICAL_GAP*2);
+				
+				if (m_endChoiceState != null) {
+					height += m_endChoiceState.getHeight()+VERTICAL_GAP;
+				}
+				
+				setWidth(getWidth()+width);
+				setHeight(getHeight()+height);
+			}
+
+			m_completed = true;
+		}
+	}
+	
+	public void calculatePosition(int x, int y) {
+		
+		if (m_junctionState == null) {
+			int curx=x;
+			int midy=y+(getHeight()/2);
+			
+			setX(x);
+			setY(y);
+			
+			for (int i=0; i < getChildStates().size(); i++) {
+				BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+				
+				act.calculatePosition(curx, midy-(act.getHeight()/2));
+				
+				curx += (act.getWidth()+HORIZONTAL_GAP);
+			}
+		} else {
+		/*
+		if (isChoiceElement()) {
+			
+			for (int i=0; i < getChildStates().size(); i++) {
+				BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+				
+				if (act instanceof SequenceActivity) {
+					act.calculatePosition(x, y);
+				}
+			}
+			
+		} else {
+		*/
+			int junctionY=y+getHeight()-VERTICAL_GAP;
+			//int junctionY=y+(getHeight()/2);
+			int extraY=0;
+			
+			m_initialState.calculatePosition(x, junctionY-
+					(m_initialState.getHeight()/2));
+			
+			if (m_junctionState != null) {
+				m_junctionState.calculatePosition(x+getWidth()-
+						m_junctionState.getWidth(), junctionY-
+						(m_junctionState.getHeight()/2));
+			}
+			
+			if (m_endChoiceState != null) {
+				m_endChoiceState.calculatePosition(x+getWidth()-
+//						m_junctionState.getWidth(), y);
+						m_junctionState.getWidth()-
+						HORIZONTAL_GAP, junctionY-
+						(m_junctionState.getHeight()/2));
+				//extraY = m_endChoiceState.getHeight()+VERTICAL_GAP;
+			}
+			
+			for (int i=0; i < getChildStates().size(); i++) {
+				BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+				
+				if (act instanceof SequenceActivity) {
+					act.calculatePosition(x+
+								m_initialState.getWidth()+
+								HORIZONTAL_GAP, y+extraY);
+				}
+			}
+		}
+	}
+	
+	public void draw(Object parent) {
+		
+		// Construct notation
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.draw(parent);
+		}
+	}
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		Object ret=null;
+		BPMNActivity state=getStartState();
+		
+		if (state != null) {
+			ret = state.getStartNode();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		BPMNActivity ret=null;
+		
+		if (getChildStates().size() > 0) {
+			ret = (BPMNActivity)getChildStates().get(0);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		BPMNActivity ret=null;
+		
+		if (m_junctionState != null) {
+			ret = m_junctionState;
+		} else if (getChildStates().size() > 0) {
+			BPMNActivity act=(BPMNActivity)
+					getChildStates().get(getChildStates().size()-1);
+			ret = act;
+		}
+		
+		return(ret);
+	}
+
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		Object ret=null;
+		
+		if (m_junctionState != null) {
+			ret = m_junctionState.getEndNode();
+		} else if (getChildStates().size() > 0) {
+			BPMNActivity act=(BPMNActivity)
+					getChildStates().get(getChildStates().size()-1);
+			ret = act.getEndNode();
+		}
+		
+		return(ret);
+	}
+	
+	private boolean m_completed=false;
+	
+    private BPMNActivity m_initialState=null;
+    private BPMNActivity m_endChoiceState=null;
+    private BPMNActivity m_junctionState=null;
+    private String m_conditionalExpression=null;    
+    private String m_repeatExpression=null;    
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhileActivity.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhileActivity.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/components/WhileActivity.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,472 @@
+/*
+ * Copyright 2005-7 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * Jan 25, 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.components;
+
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+import org.pi4soa.service.behavior.Choice;
+import org.pi4soa.service.behavior.While;
+
+/**
+ * This class represents a while repetition within a
+ * UML state machine.
+ *
+ */
+public class WhileActivity extends AbstractBPMNActivity {
+
+	/**
+	 * This constructor initializes the while state.
+	 * 
+	 * @param while The while
+	 * @param parent The parent BPMN state
+	 * @param model The BPMN model
+	 */
+	public WhileActivity(While whileElem, BPMNActivity parent,
+			org.pi4soa.bpmn.generation.BPMNModelFactory model,
+			org.pi4soa.bpmn.generation.BPMNNotationFactory notation)
+					throws BPMNGenerationException {
+		super(parent, model, notation);
+		
+		initialize(whileElem);		
+	}
+
+	/**
+	 * This method performs the initialization of the 
+	 * whiles state.
+	 * 
+	 * @param elem The while
+	 * @throws BPMNGenerationException Failed to initialize
+	 */
+	protected void initialize(While elem) throws BPMNGenerationException {
+		m_choiceElement = (elem.getParent() instanceof Choice);
+
+		m_conditionalDescription = elem.getName();
+		
+		if (org.pi4soa.common.util.NamesUtil.isSet(elem.getExpression())) {
+			m_conditionalExpression = elem.getExpression();
+		}
+
+		if (org.pi4soa.common.util.NamesUtil.isSet(elem.getReEvaluateExpression()) &&
+				elem.getReEvaluateExpression().equals("true()") == false) {
+			m_repeatExpression = elem.getReEvaluateExpression();
+			
+			if (isChoiceElement() && m_conditionalExpression != null) {
+				m_repeatExpression += " and "+m_conditionalExpression;
+			}
+		} else if (isChoiceElement() && m_conditionalExpression != null) {
+			m_repeatExpression = m_conditionalExpression;
+		}
+		
+		// Get region
+		//Activity region=getTopLevelActivity();
+		
+		if (isChoiceElement() == false) {
+			
+			// Create choice state
+			/*
+			ActivityNode choiceState = region.createNode(null,
+					UMLPackage.eINSTANCE.getDecisionNode());
+			choiceState.getInPartitions().add(getActivityPartition());
+			
+			m_initialChoiceState = new SimpleActivity(choiceState, this);
+			*/
+			Object choiceState=getModelFactory().createDataBasedXORGateway(getContainer());
+			
+			m_initialChoiceState = new JunctionActivity(choiceState, this,
+					getModelFactory(), getNotationFactory());
+		}
+				
+		if (m_repeatExpression != null) {
+			/*
+			ActivityNode endChoiceState = region.createNode(null,
+					UMLPackage.eINSTANCE.getDecisionNode());
+			endChoiceState.getInPartitions().add(getActivityPartition());
+			
+			m_endChoiceState = new SimpleActivity(endChoiceState, this);
+			*/
+			Object endChoiceState=getModelFactory().createDataBasedXORGateway(getContainer());
+			
+			m_endChoiceState = new JunctionActivity(endChoiceState, this,
+					getModelFactory(), getNotationFactory());
+		}
+
+		// Create junction state
+		/*
+		ActivityNode junctionState = region.createNode(null,
+				UMLPackage.eINSTANCE.getMergeNode());
+		junctionState.getInPartitions().add(getActivityPartition());
+		
+		m_junctionState = new SimpleActivity(junctionState, this);
+		*/
+		Object junctionState=getModelFactory().createDataBasedXORGateway(getContainer());
+		
+		m_junctionState = new JunctionActivity(junctionState, this,
+				getModelFactory(), getNotationFactory());
+	}
+	
+	/**
+	 * This method determines whether the conditional is a
+	 * choice element.
+	 * 
+	 * @return Whether a choice element
+	 */
+	protected boolean isChoiceElement() {
+		return(m_choiceElement);
+	}
+	
+	/**
+	 * This method indicates that the UML state for the
+	 * child nodes is complete.
+	 *
+	 */
+	public void childrenComplete() {
+		
+		if (m_completed == false) {
+			
+			// Move the end choice state to the end of the list
+			if (m_endChoiceState != null &&
+					getChildStates().remove(m_endChoiceState)) {
+				getChildStates().add(m_endChoiceState);
+			}
+			
+			// Move the junction state to the end of the list
+			boolean junctionRemoved=getChildStates().remove(m_junctionState);
+			
+			// Join the child state vertex with transitions
+			// Don't join the endChoice and junction states here
+			transitionSequentialNodes();
+			
+			// Label the expression on the choice outgoing link
+			/*
+			java.util.List list=
+				m_initialChoiceState.getEndNode().getOutgoings();
+			if (list != null && list.size() > 0) {
+				ActivityEdge t=(ActivityEdge)list.get(0);
+				
+				if (t != null && m_conditionalDescription != null) {
+					String name=m_conditionalDescription.replace(' ', '_');
+					t.setName(name);
+					
+					org.eclipse.uml2.uml.OpaqueExpression expr=
+						(org.eclipse.uml2.uml.OpaqueExpression)
+						t.createGuard("expression", null,
+							UMLPackage.eINSTANCE.getOpaqueExpression());
+						
+					if (m_conditionalExpression != null) {
+						expr.getBodies().add(m_conditionalExpression);
+					} else {
+						expr.getBodies().add("<non-observable>");
+					}
+				}
+			}
+			*/
+			
+			if (m_initialChoiceState != null) {
+				java.util.List list=getModelFactory().getOutboundControlLinks(m_initialChoiceState.getEndNode());
+	
+				if (list.size() > 0) {
+					Object outgoing=list.get(0);
+	
+					if (m_conditionalExpression != null) {
+						getModelFactory().setLinkExpression(outgoing,
+								m_conditionalExpression);
+					} else {
+						getModelFactory().setLinkExpression(outgoing,
+								"<non-observable>");
+					}
+				}
+			}
+			
+			// Junction is re-added after setting up the sequential transitions,
+			// so that it is not sequentially transitioned - only transition
+			// to the junction state based on an appropriate condition
+			// evaluation
+			BPMNActivity lastState=(BPMNActivity)getChildStates().
+								get(getChildStates().size()-1);
+			
+			if (junctionRemoved) {
+				getChildStates().add(m_junctionState);				
+			}
+
+			if (isChoiceElement() == false) {
+				
+				// Have direct transition from choice to junction
+				// to represent the 'false' path
+				/*
+				ActivityEdge transition=
+						m_junctionState.transitionFrom(m_initialChoiceState);
+				//transition.setName("false");
+			
+				org.eclipse.uml2.uml.OpaqueExpression expr=
+					(org.eclipse.uml2.uml.OpaqueExpression)
+					transition.createGuard("expression", null,
+						UMLPackage.eINSTANCE.getOpaqueExpression());
+				
+				expr.getBodies().add("false()");
+				*/
+				m_junctionState.transitionFrom(m_initialChoiceState,
+						"false()");
+			}
+			
+			if (m_repeatExpression != null) {
+				// Transition from end choice state to start vertex
+				// to represent the loop back
+				/*
+				ActivityEdge loopback=
+					getStartState().transitionFrom(m_endChoiceState);
+				
+				if (loopback != null && m_repeatExpression != null) {
+					org.eclipse.uml2.uml.OpaqueExpression expr=
+						(org.eclipse.uml2.uml.OpaqueExpression)
+						loopback.createGuard("expression", null,
+							UMLPackage.eINSTANCE.getOpaqueExpression());
+					
+					expr.getBodies().add(m_repeatExpression);
+				}
+				*/
+				
+				getStartState().transitionFrom(m_endChoiceState,
+						m_repeatExpression != null?
+							m_repeatExpression:"<non-observable>");
+				
+				// Transition from end choice state to junction, to
+				// represent the situation where the loopback does
+				// not occur
+				/*
+				ActivityEdge whileEnd=
+					m_junctionState.transitionFrom(m_endChoiceState);
+				
+				org.eclipse.uml2.uml.OpaqueExpression expr=
+					(org.eclipse.uml2.uml.OpaqueExpression)
+					whileEnd.createGuard("expression", null,
+						UMLPackage.eINSTANCE.getOpaqueExpression());
+				
+				expr.getBodies().add("false()");
+				*/
+				m_junctionState.transitionFrom(m_endChoiceState,
+						"false()");
+			} else {
+				// Establish transition from last state to initial choice
+				//m_initialChoiceState.transitionFrom(lastState, null);
+				getStartState().transitionFrom(lastState, null);
+				
+				if (isChoiceElement()) {
+					m_junctionState.transitionFrom(lastState,
+								"false()");
+				}
+			}
+			
+			if (isChoiceElement() == false) {
+				int width=0;
+				int height=0;
+				
+				// Calculate extra width
+				width = m_initialChoiceState.getWidth()+HORIZONTAL_GAP+
+						m_junctionState.getWidth()+HORIZONTAL_GAP;
+				
+				height = m_initialChoiceState.getHeight();
+				
+				if (height < m_junctionState.getHeight()) {
+					height = m_junctionState.getHeight();
+				}
+				
+				height += (VERTICAL_GAP*2);
+				
+				if (m_endChoiceState != null) {
+					height += m_endChoiceState.getHeight()+VERTICAL_GAP;
+				}
+				
+				setWidth(getWidth()+width);
+				setHeight(getHeight()+height);
+			} else {
+				
+				int width=0;
+				int height=0;
+				
+				// Calculate extra width
+				width = m_junctionState.getWidth()+HORIZONTAL_GAP;
+				
+				setWidth(getWidth()+width);
+			}
+			
+			m_completed = true;
+		}
+	}
+	
+	public void calculatePosition(int x, int y) {
+		int junctionY=y+getHeight()-VERTICAL_GAP;
+		
+		if (isChoiceElement()) {
+			
+			for (int i=0; i < getChildStates().size(); i++) {
+				BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+				
+				if (act instanceof SequenceActivity) {
+					act.calculatePosition(x, y);
+				}
+			}
+			
+			m_junctionState.calculatePosition(x+getWidth()-
+					m_junctionState.getWidth(), junctionY-
+					(m_junctionState.getHeight()/2));
+			
+			if (m_endChoiceState != null) {
+				m_endChoiceState.calculatePosition(x+getWidth()-
+					m_junctionState.getWidth()-HORIZONTAL_GAP-
+					m_endChoiceState.getWidth(),
+					junctionY-m_endChoiceState.getHeight()-
+					(VERTICAL_GAP/2));
+				//extraY = m_endChoiceState.getHeight()+VERTICAL_GAP;
+			}
+			
+		} else {
+			//int junctionY=y+(getHeight()/2);
+			int extraY=0;
+			
+			m_initialChoiceState.calculatePosition(x, junctionY-
+					(m_initialChoiceState.getHeight()/2));
+			m_junctionState.calculatePosition(x+getWidth()-
+					m_junctionState.getWidth(), junctionY-
+					(m_junctionState.getHeight()/2));
+			
+			if (m_endChoiceState != null) {
+				m_endChoiceState.calculatePosition(x+getWidth()-
+					m_junctionState.getWidth()-HORIZONTAL_GAP-
+					m_endChoiceState.getWidth(),
+					junctionY-m_endChoiceState.getHeight()-
+					(VERTICAL_GAP/2));
+				//extraY = m_endChoiceState.getHeight()+VERTICAL_GAP;
+			}
+			
+			SequenceActivity seq=null;
+			
+			for (int i=0; i < getChildStates().size(); i++) {
+				BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+				
+				if (act instanceof SequenceActivity) {
+					seq = (SequenceActivity)act;
+					
+					//act.calculatePosition(x+
+					//		m_initialChoiceState.getWidth()+
+					//		HORIZONTAL_GAP, y+extraY);
+					int gap=(VERTICAL_GAP/4);
+					
+					if (m_endChoiceState != null) {
+						gap = VERTICAL_GAP;
+					}
+					
+					act.calculatePosition(x+
+							m_initialChoiceState.getWidth()+
+							HORIZONTAL_GAP, junctionY-
+							act.getHeight()-gap);
+				}
+			}
+			
+			// If a normal expression, then move the end
+			// node of the last child, to help with layout
+			if (m_endChoiceState == null && seq.getChildStates().size() > 0) {
+				BPMNActivity lastState=(BPMNActivity)seq.getEndState();
+				
+				lastState.calculatePosition(x+getWidth()-
+						lastState.getWidth()-HORIZONTAL_GAP-
+						m_junctionState.getWidth(),
+						junctionY-lastState.getHeight()-
+						(VERTICAL_GAP/2));
+			}
+		}
+	}
+	
+	public void draw(Object parent) {
+		
+		// Construct notation
+		for (int i=0; i < getChildStates().size(); i++) {
+			BPMNActivity act=(BPMNActivity)getChildStates().get(i);
+			
+			act.draw(parent);
+		}
+	}
+
+	/**
+	 * This method returns the start node for the activites
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The starting node
+	 */
+	public Object getStartNode() {
+		Object ret=null;
+		BPMNActivity state=getStartState();
+		
+		if (state != null) {
+			ret = state.getStartNode();
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the start state.
+	 * 
+	 * @return The start state
+	 */
+	public BPMNActivity getStartState() {
+		BPMNActivity ret=null;
+		
+		if (isChoiceElement() == false) {
+			ret = m_initialChoiceState;
+			
+		} else if (getChildStates().size() > 0) {
+			ret = (BPMNActivity)getChildStates().get(0);
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method returns the end state.
+	 * 
+	 * @return The end state
+	 */
+	public BPMNActivity getEndState() {
+		return(m_junctionState);
+	}
+	
+	/**
+	 * This method returns the end node for the activities
+	 * represented by this UML activity implementation.
+	 * 
+	 * @return The ending node
+	 */
+	public Object getEndNode() {
+		return(m_junctionState.getEndNode());
+	}
+	
+	public boolean canDeleteEndNode() {
+		return(false);
+	}
+	
+	private boolean m_completed=false;
+	private boolean m_choiceElement=false;
+	
+    private BPMNActivity m_initialChoiceState=null;
+    private BPMNActivity m_endChoiceState=null;
+    private BPMNActivity m_junctionState=null;
+    private String m_conditionalDescription=null;
+    private String m_conditionalExpression=null;
+    private String m_repeatExpression=null;
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/gmf/GMFBPMNNotationFactoryImpl.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/gmf/GMFBPMNNotationFactoryImpl.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/gmf/GMFBPMNNotationFactoryImpl.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,341 @@
+/*
+ * Copyright 2005-6 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * 30 Jan 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.gmf;
+
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+import org.pi4soa.bpmn.generation.BPMNModelFactory;
+import org.pi4soa.bpmn.generation.BPMNNotationFactory;
+import org.eclipse.gmf.runtime.notation.*;
+
+public class GMFBPMNNotationFactoryImpl implements BPMNNotationFactory {
+
+	public String getFileExtension() {
+		return("bpmn_diagram");
+	}
+	
+	public void saveNotation(String modelFileName, Object diagramModel,
+			String notationFileName, Object diagramNotation)
+						throws BPMNGenerationException {
+		try {
+			int pos=notationFileName.lastIndexOf(java.io.File.separator);
+			
+			((Diagram)diagramNotation).setName(notationFileName.substring(pos+1));
+									
+			org.eclipse.emf.ecore.resource.ResourceSet resourceSet =
+						new org.eclipse.emf.ecore.resource.impl.ResourceSetImpl();
+
+//			 Register XML resource factory
+			resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn_diagram", 
+					new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
+			resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn", 
+					new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
+			
+			resourceSet.getPackageRegistry().put(NotationPackage.eINSTANCE.getNsURI(), NotationPackage.eINSTANCE);
+			resourceSet.getPackageRegistry().put(org.eclipse.stp.bpmn.BpmnPackage.eINSTANCE.getNsURI(), org.eclipse.stp.bpmn.BpmnPackage.eINSTANCE);
+
+			org.eclipse.emf.ecore.resource.Resource modelResource =
+				resourceSet.createResource(org.eclipse.emf.common.util.URI.createFileURI(modelFileName));
+			
+			if (modelResource instanceof org.eclipse.emf.ecore.xmi.XMLResource) {
+				setXMIId((org.eclipse.emf.ecore.xmi.XMLResource)modelResource,
+							(org.eclipse.stp.bpmn.BpmnDiagram)diagramModel);
+			}
+			
+			modelResource.getContents().add((org.eclipse.emf.ecore.EObject)diagramModel);
+			
+			org.eclipse.emf.ecore.resource.Resource notationResource =
+				resourceSet.createResource(org.eclipse.emf.common.util.URI.createFileURI(notationFileName));
+			
+			if (notationResource instanceof org.eclipse.emf.ecore.xmi.XMLResource) {
+				setXMIId((org.eclipse.emf.ecore.xmi.XMLResource)notationResource,
+							(org.eclipse.emf.ecore.EObject)diagramNotation);
+			}
+			
+			notationResource.getContents().add((org.eclipse.emf.ecore.EObject)diagramNotation);
+			
+			/*
+			org.eclipse.emf.ecore.resource.Resource resource =
+					((Diagram)diagramNotation).eResource();
+			resource.setURI(org.eclipse.emf.common.util.URI.createFileURI(fileName));
+			*/
+			
+			org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl xmi =
+				new org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl();
+			java.util.Map options=xmi.getDefaultSaveOptions();
+			
+			options.put(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE);
+			//options.put(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl.OPTION_RECORD_ANY_TYPE_NAMESPACE_DECLARATIONS, Boolean.TRUE);
+			notationResource.save(options);
+			modelResource.save(options);
+
+			
+/*			
+			// Output the UML2 model to the supplied stream
+			final org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl xmi =
+				new org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl();
+			xmi.setURI(org.eclipse.emf.common.util.URI.createFileURI(fileName));
+			
+			xmi.getResourceSet();
+			
+			org.eclipse.emf.ecore.resource.impl.ResourceSetImpl set=
+				new org.eclipse.emf.ecore.resource.impl.ResourceSetImpl();
+			
+			org.eclipse.stp.bpmn.BpmnPackage.eINSTANCE.getActivity();
+			
+			System.out.println("Registry for '"+org.eclipse.stp.bpmn.BpmnPackage.eNS_URI
+					+": "+xmi.getResourceSet().getPackageRegistry().getEPackage(org.eclipse.stp.bpmn.BpmnPackage.eNS_URI));
+
+			xmi.getContents().add(diagramNotation);
+			
+			xmi.doSave(ostream, xmi.getDefaultLoadOptions());
+*/			
+			//ostream.close();
+			
+		} catch(Exception e) {
+			throw new BPMNGenerationException("Failed to convert to XMI", e);
+		}
+	}
+
+	public Object createDiagram(BPMNModelFactory factory, Object diagramModel,
+			int x, int y, int width, int height) {
+		Diagram ret=NotationFactory.eINSTANCE.createDiagram();
+		
+		ret.setType("Bpmn");
+		ret.setMeasurementUnit(MeasurementUnit.PIXEL_LITERAL);
+		ret.setElement((org.eclipse.emf.ecore.EObject)diagramModel);
+	
+		ret.getStyles().add(NotationFactory.eINSTANCE.createPageStyle());
+		ret.getStyles().add(NotationFactory.eINSTANCE.createGuideStyle());
+		ret.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
+		
+		/*
+		try {
+		org.eclipse.emf.ecore.resource.ResourceSet resourceSet =
+			new org.eclipse.emf.ecore.resource.impl.ResourceSetImpl();
+
+// Register XML resource factory
+resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn_diagram", 
+						new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
+
+resourceSet.getPackageRegistry().put(NotationPackage.eINSTANCE.getNsURI(), NotationPackage.eINSTANCE);
+resourceSet.getPackageRegistry().put(org.eclipse.stp.bpmn.BpmnPackage.eINSTANCE.getNsURI(), org.eclipse.stp.bpmn.BpmnPackage.eINSTANCE);
+
+org.eclipse.emf.ecore.resource.Resource resource =
+	resourceSet.createResource(org.eclipse.emf.common.util.URI.createFileURI("test.xmi"));
+// add the root object to the resource
+resource.getContents().add(ret);
+		} catch(Exception e) {
+			e.printStackTrace();
+		}
+		*/
+
+		return(ret);
+	}
+
+	public Object createPool(BPMNModelFactory factory, Object poolModel,
+			Object diagramNotation, int x, int y, int width, int height) {
+		Node ret=NotationFactory.eINSTANCE.createNode();
+		
+		ret.setElement((org.eclipse.emf.ecore.EObject)poolModel);
+		ret.setType("1001");
+		
+		Bounds bounds=NotationFactory.eINSTANCE.createBounds();
+		bounds.setHeight(height);
+		bounds.setWidth(width+100);
+		bounds.setX(x);
+		bounds.setY(y);
+		
+		ret.setLayoutConstraint(bounds);
+		
+		FontStyle font=NotationFactory.eINSTANCE.createFontStyle();
+		font.setFontName("Ariel");
+		ret.getStyles().add(font);
+		ret.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
+		
+		FillStyle fill=NotationFactory.eINSTANCE.createFillStyle();
+		fill.setFillColor(16771304);
+		ret.getStyles().add(fill);
+		
+		LineStyle line=NotationFactory.eINSTANCE.createLineStyle();
+		line.setLineColor(11119017);
+		ret.getStyles().add(line);
+		
+		Node nameNode=NotationFactory.eINSTANCE.createNode();
+		nameNode.setType("4008");
+		ret.insertChild(nameNode);
+		
+		Node lineNode=NotationFactory.eINSTANCE.createNode();
+		lineNode.setType("5001");
+		ret.getStyles().add(NotationFactory.eINSTANCE.createDrawerStyle());
+		ret.getStyles().add(NotationFactory.eINSTANCE.createSortingStyle());
+		ret.getStyles().add(NotationFactory.eINSTANCE.createFilteringStyle());
+		ret.insertChild(lineNode);
+		
+		((Diagram)diagramNotation).insertChild(ret);	
+		
+		return(lineNode);
+	}
+
+	public Object createTask(BPMNModelFactory factory,
+			Object taskModel, Object parentNotation,
+					int x, int y, int width, int height) {
+		Node ret=NotationFactory.eINSTANCE.createNode();
+		
+		ret.setElement((org.eclipse.emf.ecore.EObject)taskModel);
+		ret.setType("2001");
+		
+		Bounds bounds=NotationFactory.eINSTANCE.createBounds();
+		bounds.setHeight(height);
+		bounds.setWidth(width);
+		bounds.setX(x);
+		bounds.setY(y);
+		
+		ret.setLayoutConstraint(bounds);
+		
+		FontStyle font=NotationFactory.eINSTANCE.createFontStyle();
+		font.setFontName("Ariel");
+		ret.getStyles().add(font);
+		ret.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
+		
+		FillStyle fill=NotationFactory.eINSTANCE.createFillStyle();
+		fill.setFillColor(16771304);
+		ret.getStyles().add(fill);
+		
+		LineStyle line=NotationFactory.eINSTANCE.createLineStyle();
+		line.setLineColor(11119017);
+		ret.getStyles().add(line);
+		
+		Node nameNode=NotationFactory.eINSTANCE.createNode();
+		nameNode.setType("4001");
+		ret.insertChild(nameNode);
+		
+		((Node)parentNotation).insertChild(ret);	
+		
+		m_taskViews.put(taskModel, ret);
+		
+		return(ret);
+	}
+	
+
+	public Object createJunction(BPMNModelFactory factory,
+			Object junctionModel, Object parentNotation,
+					int x, int y, int width, int height) {
+		Node ret=NotationFactory.eINSTANCE.createNode();
+		
+		ret.setElement((org.eclipse.emf.ecore.EObject)junctionModel);
+		ret.setType("2001");
+		
+		Bounds bounds=NotationFactory.eINSTANCE.createBounds();
+		bounds.setHeight(height);
+		bounds.setWidth(width);
+		bounds.setX(x);
+		bounds.setY(y);
+		
+		ret.setLayoutConstraint(bounds);
+		
+		FontStyle font=NotationFactory.eINSTANCE.createFontStyle();
+		font.setFontName("Ariel");
+		ret.getStyles().add(font);
+		ret.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
+		
+		FillStyle fill=NotationFactory.eINSTANCE.createFillStyle();
+		fill.setFillColor(16771304);
+		ret.getStyles().add(fill);
+		
+		LineStyle line=NotationFactory.eINSTANCE.createLineStyle();
+		line.setLineColor(11119017);
+		ret.getStyles().add(line);
+		
+		Node nameNode=NotationFactory.eINSTANCE.createNode();
+		nameNode.setType("4001");
+		ret.insertChild(nameNode);
+		
+		((Node)parentNotation).insertChild(ret);	
+		
+		return(ret);
+	}
+	
+	public Object createMessageLink(BPMNModelFactory factory,
+						Object linkModel, Object diagramNotation) {
+		Edge ret=NotationFactory.eINSTANCE.createEdge();
+		
+		Object source=factory.getSource(linkModel);
+		if (source != null) {
+			ret.setSource(getTaskView(source));
+		}
+		
+		Object target=factory.getTarget(linkModel);
+		if (target != null) {
+			ret.setTarget(getTaskView(target));
+		}
+		
+		ret.setElement((org.eclipse.emf.ecore.EObject)linkModel);
+		ret.setType("3002");
+		
+		Node nameNode=NotationFactory.eINSTANCE.createNode();
+		nameNode.setType("4007");
+		ret.insertChild(nameNode);
+
+		Location layout=NotationFactory.eINSTANCE.createLocation();
+		layout.setY(40);
+		nameNode.setLayoutConstraint(layout);
+				
+		ret.getStyles().add(NotationFactory.eINSTANCE.createRoutingStyle());
+		
+		FontStyle font=NotationFactory.eINSTANCE.createFontStyle();
+		font.setFontName("Ariel");
+		ret.getStyles().add(font);
+		ret.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
+		
+		RelativeBendpoints bendpoints=NotationFactory.eINSTANCE.createRelativeBendpoints();
+		//bendpoints.setPoints(arg0);
+		ret.setBendpoints(bendpoints);
+		
+		((Diagram)diagramNotation).insertEdge(ret);	
+
+		return(ret);
+	}
+	
+	protected View getTaskView(Object modelObject) {
+		View ret=(View)m_taskViews.get(modelObject);
+		
+		return(ret);
+	}
+	
+	protected void setXMIId(org.eclipse.emf.ecore.xmi.XMLResource res,
+					org.eclipse.emf.ecore.EObject eobj) {
+		
+		if (eobj instanceof org.eclipse.stp.bpmn.Identifiable) {
+			res.setID((org.eclipse.stp.bpmn.Identifiable)eobj,
+					((org.eclipse.stp.bpmn.Identifiable)eobj).getID());
+		} else if (eobj instanceof org.eclipse.gmf.runtime.notation.View) {
+			res.setID((org.eclipse.gmf.runtime.notation.View)eobj,
+					"_"+System.currentTimeMillis()+"_"+((org.eclipse.gmf.runtime.notation.View)eobj).hashCode());
+		}
+		
+		java.util.List children=eobj.eContents();
+		
+		for (int i=0; i < children.size(); i++) {
+			setXMIId(res, (org.eclipse.emf.ecore.EObject)children.get(i));
+		}
+	}
+	
+	private java.util.Hashtable m_taskViews=new java.util.Hashtable();
+}

Added: tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/stp/STPBPMNModelFactoryImpl.java
===================================================================
--- tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/stp/STPBPMNModelFactoryImpl.java	                        (rev 0)
+++ tools/eclipse/trunk/plugins/org.pi4soa.bpmn/src/java/org/pi4soa/bpmn/generation/stp/STPBPMNModelFactoryImpl.java	2009-12-11 16:38:45 UTC (rev 139)
@@ -0,0 +1,462 @@
+/*
+ * Copyright 2005-6 Pi4 Technologies Ltd
+ *
+ * Licensed 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.
+ *
+ *
+ * Change History:
+ * 26 Jan 2007 : Initial version created by gary
+ */
+package org.pi4soa.bpmn.generation.stp;
+
+import org.eclipse.stp.bpmn.*;
+import org.pi4soa.bpmn.generation.BPMNGenerationException;
+
+public class STPBPMNModelFactoryImpl implements org.pi4soa.bpmn.generation.BPMNModelFactory {
+
+	public String getFileExtension() {
+		return("bpmn");
+	}
+	
+	public void saveModel(String fileName, Object diagram)
+						throws BPMNGenerationException {
+		
+		/*
+		try {
+			org.eclipse.stp.bpmn.BpmnPackage.eINSTANCE.getActivity();
+			
+			java.io.FileOutputStream ostream=
+				new java.io.FileOutputStream(fileName);
+						
+			// Output the UML2 model to the supplied stream
+			final org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl xmi =
+				new org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl();
+			xmi.setURI(org.eclipse.emf.common.util.URI.createFileURI(fileName));
+			xmi.getContents().add(diagram);
+			
+			xmi.doSave(ostream, xmi.getDefaultLoadOptions());
+			
+			ostream.close();
+			
+		} catch(Exception e) {
+			throw new BPMNGenerationException("Failed to convert to XMI", e);
+		}
+		*/
+	}
+	
+	public Object createDiagram() {
+		BpmnDiagram ret=BpmnFactory.eINSTANCE.createBpmnDiagram();
+		return(ret);
+	}
+	
+	public Object createPool(Object diagram, String name) {
+		Pool ret = BpmnFactory.eINSTANCE.createPool();
+		ret.setName(name);
+		
+		if (diagram instanceof BpmnDiagram) {
+			((BpmnDiagram)diagram).getPools().add(ret);
+		}
+		
+		return(ret);
+	}
+	
+	public Object createInitialNode(Object container) {
+		org.eclipse.stp.bpmn.Activity ret=
+			org.eclipse.stp.bpmn.BpmnFactory.eINSTANCE.createActivity();
+		
+		ret.setActivityType(ActivityType.EVENT_START_EMPTY_LITERAL);
+		
+		if (container instanceof Graph) {
+			((Graph)container).getVertices().add(ret);
+		}
+		
+		return(ret);
+	}
+	
+	public Object createSimpleTask(Object container,
+			org.pi4soa.service.behavior.ActivityType activity) {
+		org.eclipse.stp.bpmn.Activity ret=
+			org.eclipse.stp.bpmn.BpmnFactory.eINSTANCE.createActivity();
+		
+		ret.setActivityType(ActivityType.TASK_LITERAL);
+		
+		String label=activity.getName();
+		
+		Class[] intf=activity.getClass().getInterfaces();
+		for (int i=0; i < intf.length; i++) {
+			if (intf[i].getName().startsWith("org.pi4soa.service.behavior")) {
+				int index=intf[i].getName().lastIndexOf('.');
+				label = intf[i].getName().substring(index+1);
+				
+				if (activity instanceof org.pi4soa.service.behavior.Perform) {
+					label += " "+((org.pi4soa.service.behavior.Perform)
+							activity).getBehaviorDescription().getName();
+				} else if (activity.getName() != null) {
+					label += " "+activity.getName();
+				}
+			}
+		}
+
+		ret.setName(label);
+		
+		if (container instanceof Graph) {
+			((Graph)container).getVertices().add(ret);
+		}
+		
+		return(ret);
+	}
+	
+	public Object createControlLink(Object container,
+			Object fromNode, Object toNode,
+						String conditionalExpression) {
+		org.eclipse.stp.bpmn.SequenceEdge ret=
+			org.eclipse.stp.bpmn.BpmnFactory.eINSTANCE.createSequenceEdge();
+		
+		if (fromNode instanceof Vertex) {
+			ret.setSource((Vertex)fromNode);
+		}
+		
+		if (toNode instanceof Vertex) {
+			ret.setTarget((Vertex)toNode);
+		}
+		
+		if (conditionalExpression != null) {
+			ret.setName(conditionalExpression);
+		}
+		
+		if (container instanceof Graph) {
+			((Graph)container).getSequenceEdges().add(ret);
+		}
+		
+		return(ret);
+	}
+
+	public Object createMessageLink(Object container,
+			Object fromNode, Object toNode,
+			org.pi4soa.service.behavior.Receive receive) {
+		MessagingEdge ret=BpmnFactory.eINSTANCE.createMessagingEdge();
+		
+		if (fromNode instanceof Activity) {
+			ret.setSource((Activity)fromNode);
+		}
+		
+		if (toNode instanceof Activity) {
+			ret.setTarget((Activity)toNode);
+		}
+		
+		String name=receive.getOperationName();
+		String mesgType=null;
+		
+		if (receive.getMessageDefinition() != null &&
+				receive.getMessageDefinition().getInformationType() != null) {
+			mesgType = receive.getMessageDefinition().getInformationType().getType();			
+			
+			if (mesgType == null) {
+				mesgType = receive.getMessageDefinition().getInformationType().getElement();
+			}
+		}
+		
+		if (mesgType != null) {
+			mesgType = org.pi4soa.common.xml.XMLUtils.getLocalname(mesgType);
+		}
+
+		if (name == null) {
+			name = mesgType;
+		} else if (mesgType != null) {
+			name += "("+mesgType+")";
+		} else {
+			name += "()";
+		}
+		
+		if (name != null) {
+			ret.setName(name);
+		}
+		
+		if (container instanceof BpmnDiagram) {
+			((BpmnDiagram)container).getMessages().add(ret);
+		} else if (container instanceof Pool) {
+			((Pool)container).getBpmnDiagram().getMessages().add(ret);
+		}
+		
+		return(ret);
+	}
+
+	public Object setLinkExpression(Object link, String expression) {
+		
+		if (expression != null &&
+				link instanceof org.eclipse.stp.bpmn.SequenceEdge) {
+			org.eclipse.stp.bpmn.SequenceEdge edge=
+				(org.eclipse.stp.bpmn.SequenceEdge)link;
+			
+			edge.setName(expression);
+		}
+		
+		return(link);
+	}
+	
+	public Object createDataBasedXORGateway(Object container) {
+		org.eclipse.stp.bpmn.Activity ret=
+			org.eclipse.stp.bpmn.BpmnFactory.eINSTANCE.createActivity();
+		
+		ret.setActivityType(ActivityType.GATEWAY_DATA_BASED_EXCLUSIVE_LITERAL);
+		
+		if (container instanceof Graph) {
+			((Graph)container).getVertices().add(ret);
+		}
+		
+		return(ret);
+	}
+	
+	public Object createEventBasedXORGateway(Object container) {
+		org.eclipse.stp.bpmn.Activity ret=
+			org.eclipse.stp.bpmn.BpmnFactory.eINSTANCE.createActivity();
+		
+		ret.setActivityType(ActivityType.GATEWAY_EVENT_BASED_EXCLUSIVE_LITERAL);
+		
+		if (container instanceof Graph) {
+			((Graph)container).getVertices().add(ret);
+		}
+		
+		return(ret);
+	}
+	
+	public Object createANDGateway(Object container) {
+		org.eclipse.stp.bpmn.Activity ret=
+			org.eclipse.stp.bpmn.BpmnFactory.eINSTANCE.createActivity();
+		
+		ret.setActivityType(ActivityType.GATEWAY_PARALLEL_LITERAL);
+		
+		if (container instanceof Graph) {
+			((Graph)container).getVertices().add(ret);
+		}
+		
+		return(ret);
+	}
+	
+	public Object createFinalNode(Object container) {
+		org.eclipse.stp.bpmn.Activity ret=
+			org.eclipse.stp.bpmn.BpmnFactory.eINSTANCE.createActivity();
+		
+		ret.setActivityType(ActivityType.EVENT_END_EMPTY_LITERAL);
+		
+		if (container instanceof Graph) {
+			((Graph)container).getVertices().add(ret);
+		}
+		
+		return(ret);
+	}
+	
+	public boolean isDecision(Object node) {
+		boolean ret=false;
+		
+		if (node instanceof org.eclipse.stp.bpmn.Activity &&
+				(((org.eclipse.stp.bpmn.Activity)node).getActivityType()
+					== ActivityType.GATEWAY_DATA_BASED_EXCLUSIVE_LITERAL ||
+					((org.eclipse.stp.bpmn.Activity)node).getActivityType()
+					== ActivityType.GATEWAY_EVENT_BASED_EXCLUSIVE_LITERAL)) {
+			ret = true;
+		}
+		
+		return(ret);
+	}
+	
+	/**
+	 * This method determines if the supplied node is a join. This
+	 * is true, if the node is a data or event based gateway,
+	 * and as incoming edges. This is based on the fact that only
+	 * a join gateway, at the point this method is invoked, would
+	 * have incoming links, otherwise any other gateway would be
+	 * assumed to be the initial gateway in a conditional grouping
+	 * construct.
+	 * 
+	 * @param node
+	 * @return Whether the node is a join
+	 */
+	public boolean isJoin(Object node) {
+		boolean ret=false;
+		
+		if (node instanceof org.eclipse.stp.bpmn.Activity &&
+				(((org.eclipse.stp.bpmn.Activity)node).getActivityType()
+					== ActivityType.GATEWAY_DATA_BASED_EXCLUSIVE_LITERAL ||
+					((org.eclipse.stp.bpmn.Activity)node).getActivityType()
+					== ActivityType.GATEWAY_EVENT_BASED_EXCLUSIVE_LITERAL) &&
+				((org.eclipse.stp.bpmn.Activity)node).getIncomingEdges().size() > 0) {
+			ret = true;
+		}
+		
+		return(ret);
+	}
+	
+	public boolean isTerminal(Object node) {
+		boolean ret=false;
+		
+		if (node instanceof org.eclipse.stp.bpmn.Activity &&
+				((org.eclipse.stp.bpmn.Activity)node).getActivityType()
+					== ActivityType.EVENT_END_EMPTY_LITERAL) {
+			ret = true;
+		}
+		
+		return(ret);
+	}
+	
+	public void setLabel(Object entity, String label) {
+		if (entity instanceof Activity) {
+			((Activity)entity).setName(label);
+		}
+	}
+	
+	public Object getSource(Object link) {
+		Object ret=null;
+		
+		if (link instanceof SequenceEdge) {
+			ret = ((SequenceEdge)link).getSource();
+		} else if (link instanceof MessagingEdge) {
+			ret = ((MessagingEdge)link).getSource();
+		}
+		
+		return(ret);
+	}
+	
+	public void setSource(Object link, Object node) {
+		if (link instanceof SequenceEdge && node instanceof Vertex) {
+			((SequenceEdge)link).setSource((Vertex)node);
+		} else if (link instanceof MessagingEdge &&
+						node instanceof Activity) {
+			((MessagingEdge)link).setSource((Activity)node);
+		}
+	}
+	
+	public Object getTarget(Object link) {
+		Object ret=null;
+		
+		if (link instanceof SequenceEdge) {
+			ret = ((SequenceEdge)link).getTarget();
+		} else if (link instanceof MessagingEdge) {
+			ret = ((MessagingEdge)link).getTarget();
+		}
+		
+		return(ret);
+	}
+	
+	public void setTarget(Object link, Object node) {
+		if (link instanceof SequenceEdge && node instanceof Vertex) {
+			((SequenceEdge)link).setTarget((Vertex)node);
+		} else if (link instanceof MessagingEdge &&
+						node instanceof Activity) {
+			((MessagingEdge)link).setTarget((Activity)node);
+		}
+	}
+	
+	public java.util.List getInboundControlLinks(Object node) {
+		java.util.List ret=null;
+		
+		if (node instanceof Vertex) {
+			ret = ((Vertex)node).getIncomingEdges();
+		}
+		
+		return(ret);
+	}
+	
+	public java.util.List getOutboundControlLinks(Object node) {
+		java.util.List ret=null;
+		
+		if (node instanceof Vertex) {
+			ret = ((Vertex)node).getOutgoingEdges();
+		}
+		
+		return(ret);
+	}
+	
+	public java.util.List getInboundMessageLinks(Object node) {
+		java.util.List ret=null;
+		
+		if (node instanceof Activity) {
+			ret = ((Activity)node).getIncomingMessages();
+		}
+		
+		return(ret);
+	}
+	
+	public java.util.List getOutboundMessageLinks(Object node) {
+		java.util.List ret=null;
+		
+		if (node instanceof Activity) {
+			ret = ((Activity)node).getOutgoingMessages();
+		}
+		
+		return(ret);
+	}
+	
+	public void delete(Object entity) {
+//System.out.println("DELETE: "+entity);
+		
+		if (entity instanceof Vertex) {
+			Vertex node=(Vertex)entity;
+			
+			if (node.getGraph() != null) {
+				node.getGraph().getVertices().remove(node);
+			}
+			
+			for (int i=node.getIncomingEdges().size()-1; i >= 0; i--) {
+				SequenceEdge edge=(SequenceEdge)node.getIncomingEdges().get(i);
+				delete(edge);
+			}
+			
+			for (int i=node.getOutgoingEdges().size()-1; i >= 0; i--) {
+				SequenceEdge edge=(SequenceEdge)node.getOutgoingEdges().get(i);
+				delete(edge);
+			}
+		} else if (entity instanceof SequenceEdge) {
+			SequenceEdge edge=(SequenceEdge)entity;
+			
+			edge.setSource(null);
+			edge.setTarget(null);
+			
+			if (edge.getGraph() != null) {
+				edge.getGraph().getSequenceEdges().remove(edge);
+			}
+		} else if (entity instanceof Pool) {
+			Pool pool=(Pool)entity;
+			
+			if (pool.getBpmnDiagram() != null) {
+				pool.getBpmnDiagram().getPools().remove(pool);
+			}
+		}
+	}
+
+	public boolean isDeleted(Object entity) {
+		boolean ret=false;
+		
+		if (entity instanceof Vertex) {
+			Vertex node=(Vertex)entity;
+			
+			if (node.getGraph() == null) {
+				ret = true;
+			}
+		} else if (entity instanceof SequenceEdge) {
+			SequenceEdge edge=(SequenceEdge)entity;
+			
+			if (edge.getGraph() == null) {
+				ret = true;
+			}
+		} else if (entity instanceof Pool) {
+			Pool pool=(Pool)entity;
+			
+			if (pool.getBpmnDiagram() != null) {
+				ret = true;
+			}
+		}
+		
+		return(ret);
+	}
+}



More information about the savara-commits mailing list