Author: Grid.Qian
Date: 2008-08-20 02:47:12 -0400 (Wed, 20 Aug 2008)
New Revision: 9806
Added:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java
Removed:
workspace/grid/org.jboss.tools.bpmn2jpdl/lib/commons-logging.jar
workspace/grid/org.jboss.tools.bpmn2jpdl/lib/jbpm-jpdl.jar
workspace/grid/org.jboss.tools.bpmn2jpdl/lib/jbpm.cfg.xml
workspace/grid/org.jboss.tools.bpmn2jpdl/lib/org/
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/.classpath
workspace/grid/org.jboss.tools.bpmn2jpdl/META-INF/MANIFEST.MF
workspace/grid/org.jboss.tools.bpmn2jpdl/build.properties
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/B2J.java
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/action/B2JAction.java
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2J.properties
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2JMessages.java
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/DomXmlWriter.java
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/TranslateHelper.java
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/util/B2JUtil.java
Log:
add graphical jpdl file translator
Modified: workspace/grid/org.jboss.tools.bpmn2jpdl/.classpath
===================================================================
--- workspace/grid/org.jboss.tools.bpmn2jpdl/.classpath 2008-08-19 23:45:02 UTC (rev
9805)
+++ workspace/grid/org.jboss.tools.bpmn2jpdl/.classpath 2008-08-20 06:47:12 UTC (rev
9806)
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry exported="true" kind="lib"
path="lib/"/>
- <classpathentry exported="true" kind="lib"
path="lib/commons-logging.jar"/>
<classpathentry exported="true" kind="lib"
path="lib/dom4j-1.6.1.jar"/>
- <classpathentry exported="true" kind="lib"
path="lib/jbpm-jpdl.jar"
sourcepath="D:/sources/jbpm/trunk/modules/jpdl"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
Modified: workspace/grid/org.jboss.tools.bpmn2jpdl/META-INF/MANIFEST.MF
===================================================================
--- workspace/grid/org.jboss.tools.bpmn2jpdl/META-INF/MANIFEST.MF 2008-08-19 23:45:02 UTC
(rev 9805)
+++ workspace/grid/org.jboss.tools.bpmn2jpdl/META-INF/MANIFEST.MF 2008-08-20 06:47:12 UTC
(rev 9806)
@@ -7,13 +7,10 @@
Bundle-Activator: org.jboss.tools.b2j.B2J
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
- org.eclipse.stp.bpmn;bundle-version="1.0.0",
org.jboss.tools.common;bundle-version="2.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Bundle-ClassPath: lib/jbpm-jpdl.jar,
- .,
- lib/dom4j-1.6.1.jar,
- lib/commons-logging.jar,
- lib/
+Bundle-ClassPath: .,
+ lib/dom4j-1.6.1.jar
Bundle-Vendor: %PLUGIN_PROVIDER
+Import-Package: org.eclipse.core.resources
Modified: workspace/grid/org.jboss.tools.bpmn2jpdl/build.properties
===================================================================
--- workspace/grid/org.jboss.tools.bpmn2jpdl/build.properties 2008-08-19 23:45:02 UTC (rev
9805)
+++ workspace/grid/org.jboss.tools.bpmn2jpdl/build.properties 2008-08-20 06:47:12 UTC (rev
9806)
@@ -3,8 +3,5 @@
bin.includes = META-INF/,\
.,\
plugin.xml,\
- lib/jbpm-jpdl.jar,\
- lib/dom4j-1.6.1.jar,\
- lib/commons-logging.jar,\
- lib/,\
- plugin.properties
+ plugin.properties,\
+ lib/dom4j-1.6.1.jar
Deleted: workspace/grid/org.jboss.tools.bpmn2jpdl/lib/commons-logging.jar
===================================================================
(Binary files differ)
Deleted: workspace/grid/org.jboss.tools.bpmn2jpdl/lib/jbpm-jpdl.jar
===================================================================
(Binary files differ)
Deleted: workspace/grid/org.jboss.tools.bpmn2jpdl/lib/jbpm.cfg.xml
===================================================================
--- workspace/grid/org.jboss.tools.bpmn2jpdl/lib/jbpm.cfg.xml 2008-08-19 23:45:02 UTC (rev
9805)
+++ workspace/grid/org.jboss.tools.bpmn2jpdl/lib/jbpm.cfg.xml 2008-08-20 06:47:12 UTC (rev
9806)
@@ -1,52 +0,0 @@
-<jbpm-configuration>
-
- <!--
- This configuration is used when there is no jbpm.cfg.xml file found in the
- root of the classpath. It is a very basic configuration without persistence
- and message services. Only the authorization service installed.
- You can parse and create processes, but when you try to use one of the
- unavailable services, you'll get an exception.
- -->
-
- <jbpm-context>
- <service name="persistence"
factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
- <service name="tx" factory="org.jbpm.tx.TxServiceFactory"
/>
- <service name="message"
factory="org.jbpm.msg.db.DbMessageServiceFactory" />
- <service name="scheduler"
factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
- <service name="logging"
factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
- <service name="authentication"
factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory"
/>
- </jbpm-context>
-
- <!-- configuration property used by persistence service impl
org.jbpm.persistence.db.DbPersistenceServiceFactory -->
- <string name="resource.hibernate.cfg.xml"
value="hibernate.cfg.xml" />
-
- <!-- configuration resource files pointing to default configuration files in
jbpm-{version}.jar -->
- <string name="resource.business.calendar"
value="org/jbpm/calendar/jbpm.business.calendar.properties" />
- <string name="resource.default.modules"
value="org/jbpm/graph/def/jbpm.default.modules.properties" />
- <string name="resource.converter"
value="org/jbpm/db/hibernate/jbpm.converter.properties" />
- <string name="resource.action.types"
value="org/jbpm/graph/action/action.types.xml" />
- <string name="resource.node.types"
value="org/jbpm/graph/node/node.types.xml" />
- <string name="resource.parsers"
value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
- <string name="resource.varmapping"
value="org/jbpm/context/exe/jbpm.varmapping.xml" />
- <string name="resource.mail.templates"
value="jbpm.mail.templates.xml" />
-
- <int name="jbpm.byte.block.size" value="1024"
singleton="true" />
- <bean name="jbpm.task.instance.factory"
class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl"
singleton="true" />
- <bean name="jbpm.variable.resolver"
class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true"
/>
- <string name="jbpm.mail.smtp.host" value="localhost" />
- <bean name="jbpm.mail.address.resolver"
class="org.jbpm.identity.mail.IdentityAddressResolver"
singleton="true" />
- <string name="jbpm.mail.from.address" value="jbpm@noreply"
/>
-
- <bean name="jbpm.job.executor"
class="org.jbpm.job.executor.JobExecutor">
- <field name="jbpmConfiguration"><ref
bean="jbpmConfiguration" /></field>
- <field name="name"><string value="JbpmJobExector"
/></field>
- <field name="nbrOfThreads"><int value="1"
/></field>
- <field name="idleInterval"><int value="5000"
/></field>
- <field name="maxIdleInterval"><int value="3600000"
/></field> <!-- 1 hour -->
- <field name="historyMaxSize"><int value="20"
/></field>
- <field name="maxLockTime"><int value="600000"
/></field> <!-- 10 minutes -->
- <field name="lockMonitorInterval"><int value="60000"
/></field> <!-- 1 minute -->
- <field name="lockBufferTime"><int value="5000"
/></field> <!-- 5 seconds -->
- </bean>
-
-</jbpm-configuration>
Modified: workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/B2J.java
===================================================================
--- workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/B2J.java 2008-08-19
23:45:02 UTC (rev 9805)
+++ workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/B2J.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.b2j;
import org.jboss.tools.common.log.BaseUIPlugin;
@@ -4,7 +15,9 @@
import org.osgi.framework.BundleContext;
/**
- * The activator class controls the plug-in life cycle
+ * @author Grid Qian
+ *
+ * this a plugin class
*/
public class B2J extends BaseUIPlugin {
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/action/B2JAction.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/action/B2JAction.java 2008-08-19
23:45:02 UTC (rev 9805)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/action/B2JAction.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,7 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.b2j.action;
-import java.io.InputStreamReader;
-
import org.dom4j.Document;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -14,32 +23,58 @@
import org.eclipse.ui.IWorkbenchPart;
import org.jboss.tools.b2j.messages.B2JMessages;
import org.jboss.tools.b2j.translate.BPMN2JPDL;
+import org.jboss.tools.b2j.translate.GraphicalFileGenerator;
+import org.jboss.tools.b2j.translate.TranslateHelper;
import org.jboss.tools.b2j.util.B2JUtil;
-import org.xml.sax.InputSource;
-public class B2JAction implements IObjectActionDelegate{
-
- //private IWorkbenchPart myPart;
+/**
+ * @author Grid Qian
+ *
+ * the popup menu action for bpmn ->jpdl
+ */
+public class B2JAction implements IObjectActionDelegate {
+
private IFile bpmnFile;
public void setActivePart(IAction arg0, IWorkbenchPart part) {
- //myPart = part;
+ // myPart = part;
}
public void run(IAction arg0) {
+ String bpmnFileName = bpmnFile.getName();
+ String bpmnFileParentPath = bpmnFile.getParent().getLocation()
+ .toOSString();
Document bpmnDocument = null;
try {
- bpmnDocument = B2JUtil.parse(new InputSource(new
InputStreamReader(bpmnFile.getContents())));
- } catch (CoreException e) {
- System.out.println(B2JMessages.Translate_Error_BpmnFile_CanNotRead + e.getMessage());
+ bpmnDocument = B2JUtil.parse(bpmnFileParentPath, bpmnFileName);
} catch (Exception e1) {
- System.out.println(B2JMessages.Translate_Error_BpmnFile_CanNotParse +
e1.getMessage());
+ System.out.println(B2JMessages.Translate_Error_BpmnFile_CanNotRead
+ + e1.getMessage());
}
- BPMN2JPDL translator = new
BPMN2JPDL(bpmnFile.getName(),bpmnFile.getParent().getLocation().toOSString(),bpmnDocument);
- translator.translateToFiles();
-
+ BPMN2JPDL translator = new BPMN2JPDL(bpmnFileName, bpmnFileParentPath,
+ bpmnDocument);
+ translator.translateToFiles();
+
+ // generate jpdl gpd file from *.bpmn_diagram
+ String bpmnDiagramFileName = TranslateHelper
+ .getBpmnDiagramName(bpmnFileName);
+ Document bpmnDiagramDocument = null;
try {
- ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE,
null);
+ bpmnDiagramDocument = B2JUtil.parse(bpmnFileParentPath,
+ bpmnDiagramFileName);
+ } catch (Exception e1) {
+ System.out
+ .println(B2JMessages.Translate_Error_BpmnDiagramFile_CanNotRead
+ + e1.getMessage());
+ }
+ GraphicalFileGenerator generator = new GraphicalFileGenerator(
+ bpmnDiagramDocument, translator.getMap(), bpmnFileParentPath,
+ bpmnFileName);
+ generator.translateToFiles();
+
+ try {
+ ResourcesPlugin.getWorkspace().getRoot().refreshLocal(
+ IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2J.properties
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2J.properties 2008-08-19
23:45:02 UTC (rev 9805)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2J.properties 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,22 +1,52 @@
Loop_Decision=Loop_Decition
-Loop_Decision_Description=this decision is for mocking bpmn loop activity
To=to
-Bpmn_Suffix=bpmn
-Workspace_Prefix=platform:/resource
+Space=
+Underline=_
+Folder_Name_Separator=.
+Dom_Element_Name=name
+Dom_Element_ID=id
+Width_Attribute_Name=width
+Height_Attribute_Name=height
+X_Attribute_Name=x
+Y_Attribute_Name=y
+Bpmn_Diagram_Name_Suffix=_diagram
+Bpmn_Pool_Element_Name=pools
+Bpmn_Vertice_Element_Name=vertices
+Bpmn_SequenceFlow_Element_Name=sequenceEdges
+Bpmn_Href_Attribute_Name=href
+Bpmn_XmiType_Attribute_Name=type
+Bpmn_ActivityType_Attribute_Name=activityType
+Bpmn_InFlow_Attribute_Name=incomingEdges
+Bpmn_Looping_Attribute_Name=looping
+Bpmn_FlowSource_Attribute_Name=source
+Bpmn_FlowTarget_Attribute_Name=target
+Bpmn_FlowDefault_Attribute_Name=isDefault
+Bpmn_Element_ID=iD
Jpdl_Suffix=jpdl
Jpdl_Process_Definition_Name=processdefinition.xml
Jpdl_32_Namespace_Url=urn:jbpm.org:jpdl-3.2
-Jpdl_Element_Name=name
-Jpdl_Process_Definition_Element=process-definition
+Jpdl_Process_Definition_Element_Name=process-definition
Jpdl_Transition_Element=transition
Jpdl_ProcessState_Element_Name=process-state
Jpdl_SubProcess_Element_Name=sub-process
-Folder_Name_Separator=.
-Translate_Error_JpdlWriter_Null=The JPDL Writer is null.
+Jpdl_Decision_Element_Name=decision
+Jpdl_Fork_Element_Name=fork
+Jpdl_Join_Element_Name=join
+Jpdl_Start_Element_Name=start-state
+Jpdl_State_Element_Name=state
+Jpdl_End_Element_Name=end-state
+Jpdl_Node_Element_Name=node
+Gpd_Definition_Name=gpd.xml
+Gpd_Layout_Element_Name=layoutConstraint
+Gpd_Element_Name=element
+Gpd_Process_Diagram_Name=process-diagram
+Gpd_Label_Element_Name=label
+Translate_Error_GpdFile_CanNotGenerate=Couldn't write gpd.xml:
+Translate_Error_GpdFile_CanNotWrite=Couldn't write gpd definition to a gpd.xml:
Translate_Error_JpdlProcess_Definition_Null=The JPDL process definition is null.
Translate_Error_JpdlFile_CanNotGenerate=Couldn't write process definition xml:
Translate_Error_JpdlFile_CanNotWrite=Couldn't write process definition to a jpdl
file:
-Translate_Error_BpmnFile_CanNotRead=Couldn't read bpmn file:
-Translate_Error_BpmnFile_CanNotParse=Couldn't parse bpmn file to a DOM document:
+Translate_Error_BpmnFile_CanNotRead=Couldn't read or parse bpmn file to a DOM
document:
+Translate_Error_BpmnDiagramFile_CanNotRead=Couldn't read or parse bpmn_diagram file
to a DOM document:
Translate_Warning_Bpmn_Element_Name= The bpmn element's name is null or same to
another element's name:
Translate_Warning_Bpmn_Element_Type=The type of this bpmn element is not translated to
corresponding jpdl element:
\ No newline at end of file
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2JMessages.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2JMessages.java 2008-08-19
23:45:02 UTC (rev 9805)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/messages/B2JMessages.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.b2j.messages;
import org.eclipse.osgi.util.NLS;
@@ -2,2 +13,5 @@
+/**
+ * @author Grid Qian
+ */
public class B2JMessages {
@@ -11,29 +25,58 @@
}
public static String Loop_Decision;
- public static String Loop_Decision_Description;
public static String To;
- public static String Bpmn_Suffix;
- public static String Workspace_Prefix;
public static String Folder_Name_Separator;
+ public static String Space;
+ public static String Underline;
+ public static String Bpmn_Diagram_Name_Suffix;
+ public static String Bpmn_Pool_Element_Name;
+ public static String Bpmn_Element_ID;
+ public static String Bpmn_Vertice_Element_Name;
+ public static String Bpmn_SequenceFlow_Element_Name;
+ public static String Bpmn_Looping_Attribute_Name;
+ public static String Bpmn_InFlow_Attribute_Name;
+ public static String Bpmn_XmiType_Attribute_Name;
+ public static String Bpmn_Href_Attribute_Name;
+ public static String Width_Attribute_Name;
+ public static String Height_Attribute_Name;
+ public static String X_Attribute_Name;
+ public static String Y_Attribute_Name;
+ public static String Bpmn_ActivityType_Attribute_Name;
+ public static String Bpmn_FlowSource_Attribute_Name;
+ public static String Bpmn_FlowTarget_Attribute_Name;
+ public static String Bpmn_FlowDefault_Attribute_Name;
public static String Jpdl_Suffix;
public static String Jpdl_Process_Definition_Name;
public static String Jpdl_ProcessState_Element_Name;
public static String Jpdl_SubProcess_Element_Name;
public static String Jpdl_32_Namespace_Url;
- public static String Jpdl_Process_Definition_Element;
+ public static String Jpdl_Process_Definition_Element_Name;
public static String Jpdl_Transition_Element;
- public static String Jpdl_Element_Name;
- public static String Translate_Error_JpdlWriter_Null;
+ public static String Jpdl_Decision_Element_Name;
+ public static String Jpdl_Fork_Element_Name;
+ public static String Jpdl_Join_Element_Name;
+ public static String Jpdl_Start_Element_Name;
+ public static String Jpdl_State_Element_Name;
+ public static String Jpdl_End_Element_Name;
+ public static String Jpdl_Node_Element_Name;
+ public static String Gpd_Definition_Name;
+ public static String Gpd_Layout_Element_Name;
+ public static String Gpd_Element_Name;
+ public static String Gpd_Process_Diagram_Name;
+ public static String Gpd_Label_Element_Name;
+ public static String Dom_Element_Name;
+ public static String Dom_Element_ID;
public static String Translate_Error_JpdlProcess_Definition_Null;
public static String Translate_Error_JpdlFile_CanNotWrite;
public static String Translate_Error_JpdlFile_CanNotGenerate;
+ public static String Translate_Error_GpdFile_CanNotGenerate;
+ public static String Translate_Error_GpdFile_CanNotWrite;
public static String Translate_Error_BpmnFile_CanNotRead;
- public static String Translate_Error_BpmnFile_CanNotParse;
+ public static String Translate_Error_BpmnDiagramFile_CanNotRead;
public static String Translate_Warning_Bpmn_Element_Name;
public static String Translate_Warning_Bpmn_Element_Type;
-
static {
NLS.initializeMessages(BUNDLE_NAME, B2JMessages.class);
}
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java 2008-08-19
23:45:02 UTC (rev 9805)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/BPMN2JPDL.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.b2j.translate;
import java.io.IOException;
@@ -11,12 +22,16 @@
import org.dom4j.Element;
import org.jboss.tools.b2j.B2J;
import org.jboss.tools.b2j.messages.B2JMessages;
-import org.jboss.tools.b2j.util.B2JUtil;
+/**
+ * @author Grid Qian
+ *
+ * this is a translator for bpmn ->jpdl
+ */
public class BPMN2JPDL {
String bpmnFileName;
- String bpmnFilePath;
+ String rootLocation;
Document bpmnDocument;
List<String> poolIDList;
List<Document> processDefs = new LinkedList<Document>();
@@ -44,6 +59,14 @@
this.warnings = warnings;
}
+ public Map<String, Element> getMap() {
+ return map;
+ }
+
+ public void setMap(Map<String, Element> map) {
+ this.map = map;
+ }
+
public BPMN2JPDL() {
}
@@ -55,7 +78,7 @@
public BPMN2JPDL(String bpmnFileName, String bpmnFilePath,
List<String> poolIDList, Document bpmnDocument) {
this.bpmnFileName = bpmnFileName;
- this.bpmnFilePath = bpmnFilePath;
+ this.rootLocation = bpmnFilePath;
this.poolIDList = poolIDList;
this.bpmnDocument = bpmnDocument;
}
@@ -96,8 +119,9 @@
}
try {
- B2JUtil.createJpdlFiles(bpmnFilePath, bpmnFileName,
- strForProcessDefs, jpdlFileNames);
+ TranslateHelper.createFiles(rootLocation, bpmnFileName,
+ strForProcessDefs, jpdlFileNames,
+ B2JMessages.Jpdl_Process_Definition_Name);
} catch (Exception e) {
errors.add(B2JMessages.Translate_Error_JpdlFile_CanNotWrite
+ e.getMessage());
@@ -126,13 +150,15 @@
Element diagram = bpmnDocument.getRootElement();
if (this.poolIDList == null || this.poolIDList.size() == 0) {
- for (Object pool : diagram.elements("pools")) {
+ for (Object pool : diagram
+ .elements(B2JMessages.Bpmn_Pool_Element_Name)) {
translateGraph((Element) pool);
}
} else {
- for (Object pool : diagram.elements("pools")) {
+ for (Object pool : diagram
+ .elements(B2JMessages.Bpmn_Pool_Element_Name)) {
if (this.poolIDList.contains(((Element) pool)
- .attributeValue("iD"))) {
+ .attributeValue(B2JMessages.Bpmn_Element_ID))) {
translateGraph((Element) pool);
}
}
@@ -143,16 +169,20 @@
* Translate a bpmn pool or subprocess to a jpdl process Dom tree
*/
private Element translateGraph(Element graph) {
- Document processDef = DomXmlWriter.createDomTree(true);
+ Document processDef = TranslateHelper.createJpdlDomTree(true);
Element processRoot = processDef.getRootElement();
- DomXmlWriter.addAttribute(processRoot, B2JMessages.Jpdl_Element_Name,
+ DomXmlWriter.addAttribute(processRoot, B2JMessages.Dom_Element_Name,
TranslateHelper.generateProcessName(graph));
processDef.setName(processRoot
- .attributeValue(B2JMessages.Jpdl_Element_Name));
+ .attributeValue(B2JMessages.Dom_Element_Name));
+ map.put(graph.attributeValue(B2JMessages.Dom_Element_ID)
+ + B2JMessages.Bpmn_Pool_Element_Name, processRoot);
+
for (Object activity : graph.elements()) {
- if ("vertices".equals(((Element) activity).getName())) {
+ if (B2JMessages.Bpmn_Vertice_Element_Name
+ .equals(((Element) activity).getName())) {
translateActivity(((Element) activity), processRoot);
}
}
@@ -166,16 +196,19 @@
* Translate a bpmn activity to a jpdl node according to activity type
*/
private void translateActivity(Element activity, Element processRoot) {
- String type = activity.attributeValue("type");
+ String type = activity
+ .attributeValue(B2JMessages.Bpmn_XmiType_Attribute_Name);
Element element = null;
// According to bpmn activity type, map to different jpdl node
// Some type can not be supported by this translation, we give
// a warining message for it.
if ("bpmn:Activity".equals(type)) {
- String activityType = activity.attributeValue("activityType");
+ String activityType = activity
+ .attributeValue(B2JMessages.Bpmn_ActivityType_Attribute_Name);
if (activityType == null) {
- element = DomXmlWriter.addElement(processRoot, "node");
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_Node_Element_Name);
} else if ("EventStartEmpty".equals(activityType)
|| "EventStartMessage".equals(activityType)
|| "EventStartRule".equals(activityType)
@@ -183,7 +216,8 @@
|| "EventStartLink".equals(activityType)
|| "EventStartMultiple".equals(activityType)
|| "EventStartSignal".equals(activityType)) {
- element = DomXmlWriter.addElement(processRoot, "start-state");
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_Start_Element_Name);
if (!"EventStartEmpty".equals(activityType)) {
warnings
.add(B2JMessages.Translate_Warning_Bpmn_Element_Type
@@ -200,7 +234,8 @@
|| "EventIntermediateLink".equals(activityType)
|| "EventIntermediateSignal".equals(activityType)) {
- element = DomXmlWriter.addElement(processRoot, "state");
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_State_Element_Name);
if (!"EventIntermediateEmpty".equals(activityType)) {
warnings
.add(B2JMessages.Translate_Warning_Bpmn_Element_Type
@@ -216,7 +251,8 @@
|| "EventEndCancel".equals(activityType)
|| "EventEndSignal".equals(activityType)) {
- element = DomXmlWriter.addElement(processRoot, "end-state");
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_End_Element_Name);
if (!"EventEndEmpty".equals(activityType)) {
warnings
.add(B2JMessages.Translate_Warning_Bpmn_Element_Type
@@ -225,7 +261,8 @@
} else if ("GatewayDataBasedExclusive".equals(activityType)
|| "GatewayEventBasedExclusive".equals(activityType)
|| "GatewayComplex".equals(activityType)) {
- element = DomXmlWriter.addElement(processRoot, "decision");
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_Decision_Element_Name);
if (!"GatewayDataBasedExclusive".equals(activityType)) {
warnings
.add(B2JMessages.Translate_Warning_Bpmn_Element_Type
@@ -233,12 +270,16 @@
}
} else if ("GatewayParallel".equals(activityType)
|| "GatewayDataBasedInclusive".equals(activityType)) {
- if (activity.attributeValue("incomingEdges") == null
- || activity.attributeValue("incomingEdges").split(" ").length
== 1) {
-
- element = DomXmlWriter.addElement(processRoot, "fork");
+ if (activity
+ .attributeValue(B2JMessages.Bpmn_InFlow_Attribute_Name) == null
+ || activity.attributeValue(
+ B2JMessages.Bpmn_InFlow_Attribute_Name).split(
+ B2JMessages.Space).length == 1) {
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_Fork_Element_Name);
} else {
- element = DomXmlWriter.addElement(processRoot, "join");
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_Join_Element_Name);
}
if (!"GatewayDataBasedInclusive".equals(activityType)) {
warnings
@@ -247,18 +288,20 @@
}
}
} else if ("bpmn:SubProcess".equals(type)) {
- element = DomXmlWriter.addElement(processRoot, "process-state");
+ element = DomXmlWriter.addElement(processRoot,
+ B2JMessages.Jpdl_ProcessState_Element_Name);
translateSubprocess(activity, element);
}
if (!TranslateHelper.check_mapElementName(activity, element)) {
warnings.add(B2JMessages.Translate_Warning_Bpmn_Element_Name
- + activity.attributeValue("iD"));
+ + activity.attributeValue(B2JMessages.Bpmn_Element_ID));
}
- map.put(activity.attributeValue("id"), element);
+ map.put(activity.attributeValue(B2JMessages.Dom_Element_ID), element);
// If bpmn activity is loop type, then create a structure to mock it.
- if ("true".equals(activity.attributeValue("looping"))) {
+ if ("true".equals(activity
+ .attributeValue(B2JMessages.Bpmn_Looping_Attribute_Name))) {
createMockLoop(activity, element);
}
}
@@ -271,15 +314,16 @@
Element processRoot = translateGraph(subProcess);
Element ele = DomXmlWriter.addElement(element,
B2JMessages.Jpdl_SubProcess_Element_Name);
- DomXmlWriter.addAttribute(ele, B2JMessages.Jpdl_Element_Name,
- processRoot.attributeValue(B2JMessages.Jpdl_Element_Name));
+ DomXmlWriter.mapAttribute(ele, B2JMessages.Dom_Element_Name,
+ processRoot);
}
/*
* Translate bpmn sequenceflows to jpdl transitions
*/
private void translateSequenceFlows(Element graph, Element processRoot) {
- for (Object edge : graph.elements("sequenceEdges")) {
+ for (Object edge : graph
+ .elements(B2JMessages.Bpmn_SequenceFlow_Element_Name)) {
translateSequenceFlow((Element) edge, processRoot);
}
}
@@ -289,24 +333,33 @@
*/
private void translateSequenceFlow(Element edge, Element processRoot) {
- Element source = map.get(edge.attributeValue("source"));
+ Element source = map.get(edge
+ .attributeValue(B2JMessages.Bpmn_FlowSource_Attribute_Name));
Element transition = null;
- if ("true".equals(edge.attributeValue("isDefault"))
- && source.element("transition") != null) {
+ if ("true".equals(edge
+ .attributeValue(B2JMessages.Bpmn_FlowDefault_Attribute_Name))
+ && source.element(B2JMessages.Jpdl_Transition_Element) != null) {
// move default transition to the first of transition list
- transition = DomXmlWriter.addElement(source, "transition", 0);
+ transition = DomXmlWriter.addElement(source,
+ B2JMessages.Jpdl_Transition_Element, 0);
} else {
- transition = DomXmlWriter.addElement(source, "transition");
+ transition = DomXmlWriter.addElement(source,
+ B2JMessages.Jpdl_Transition_Element);
}
if (!TranslateHelper.check_mapElementName(edge, transition)) {
warnings.add(B2JMessages.Translate_Warning_Bpmn_Element_Name
- + edge.attributeValue("iD"));
+ + edge.attributeValue(B2JMessages.Bpmn_Element_ID));
}
- transition.addAttribute(B2JMessages.To, map.get(
- edge.attributeValue("target")).attributeValue(
- B2JMessages.Jpdl_Element_Name));
+ transition
+ .addAttribute(
+ B2JMessages.To,
+ map
+ .get(
+ edge
+ .attributeValue(B2JMessages.Bpmn_FlowTarget_Attribute_Name))
+ .attributeValue(B2JMessages.Dom_Element_Name));
}
/*
@@ -316,26 +369,33 @@
// create a decision
Element decision = DomXmlWriter.addElement(element.getParent(),
- "decision");
- String name = activity.attributeValue(B2JMessages.Jpdl_Element_Name)
- + "_" + B2JMessages.Loop_Decision;
- DomXmlWriter
- .addAttribute(decision, B2JMessages.Jpdl_Element_Name, name);
- map.put(activity.attributeValue("id"), decision);
+ B2JMessages.Jpdl_Decision_Element_Name);
+ String name = activity.attributeValue(B2JMessages.Dom_Element_Name)
+ + B2JMessages.Underline + B2JMessages.Loop_Decision;
+ DomXmlWriter.addAttribute(decision, B2JMessages.Dom_Element_Name, name);
+ // use the decision to replace the activity in the map
+ map.put(activity.attributeValue(B2JMessages.Dom_Element_ID), decision);
+ // add the activity to map
+ map.put(activity.attributeValue(B2JMessages.Dom_Element_ID)
+ + B2JMessages.Bpmn_Vertice_Element_Name, element);
+
// create a transition from element to decision
- Element first = DomXmlWriter.addElement(element, "transition");
- first.addAttribute(B2JMessages.Jpdl_Element_Name, B2JMessages.To + " "
- + name);
+ Element first = DomXmlWriter.addElement(element,
+ B2JMessages.Jpdl_Transition_Element);
+ first.addAttribute(B2JMessages.Dom_Element_Name, B2JMessages.To
+ + B2JMessages.Space + name);
first.addAttribute(B2JMessages.To, decision
- .attributeValue(B2JMessages.Jpdl_Element_Name));
+ .attributeValue(B2JMessages.Dom_Element_Name));
// create a transition from decision to element
- Element second = DomXmlWriter.addElement(decision, "transition");
- second.addAttribute(B2JMessages.Jpdl_Element_Name, B2JMessages.To + " "
- + element.attributeValue(B2JMessages.Jpdl_Element_Name));
+ Element second = DomXmlWriter.addElement(decision,
+ B2JMessages.Jpdl_Transition_Element);
+ second.addAttribute(B2JMessages.Dom_Element_Name, B2JMessages.To
+ + B2JMessages.Space
+ + element.attributeValue(B2JMessages.Dom_Element_Name));
second.addAttribute(B2JMessages.To, element
- .attributeValue(B2JMessages.Jpdl_Element_Name));
+ .attributeValue(B2JMessages.Dom_Element_Name));
}
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/DomXmlWriter.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/DomXmlWriter.java 2008-08-19
23:45:02 UTC (rev 9805)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/DomXmlWriter.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,37 +1,33 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.b2j.translate;
import java.io.*;
-import java.util.*;
+import java.util.LinkedList;
+import java.util.List;
import org.dom4j.*;
import org.dom4j.io.*;
-import org.jboss.tools.b2j.messages.B2JMessages;
-import org.jbpm.graph.def.*;
-import org.jbpm.graph.node.*;
+/**
+ * @author Grid Qian
+ *
+ * this is for generating dom element or attribute
+ */
public class DomXmlWriter {
+ /*
+ * map a dom document to a string
+ */
public static String toString(Document document) throws IOException {
OutputFormat outputFormat = new OutputFormat(" ", true);
Writer writer = new StringWriter();
@@ -42,116 +38,52 @@
return writer.toString();
}
-
- public static Document createDomTree(boolean useNamespace) {
+ /*
+ * create a dom tree
+ */
+ public static Document createDomTree(boolean useNamespace, String url,
+ String rootElementName) {
Document document = DocumentHelper.createDocument();
Element root = null;
if (useNamespace) {
- Namespace jbpmNamespace = new Namespace(null,
- B2JMessages.Jpdl_32_Namespace_Url);
- root = document.addElement(
- B2JMessages.Jpdl_Process_Definition_Element, jbpmNamespace
- .getURI());
+ Namespace jbpmNamespace = new Namespace(null, url);
+ root = document.addElement(rootElementName, jbpmNamespace.getURI());
} else {
- root = document
- .addElement(B2JMessages.Jpdl_Process_Definition_Element);
+ root = document.addElement(rootElementName);
}
- // addAttribute(root, B2JMessages.Jpdl_Element_Name, processDefinition
- // .getName());
- //
- // // write the start-state
- // if (processDefinition.getStartState() != null) {
- // writeStartNode(root, (StartState) processDefinition.getStartState());
- // }
- //
- // // write the nodeMap
- // if ((processDefinition.getNodes() != null)
- // && (processDefinition.getNodes().size() > 0)) {
- // writeNodes(root, processDefinition.getNodes());
- // }
-
root.addText(System.getProperty("line.separator"));
return document;
}
- private void writeStartNode(Element element, StartState startState) {
- if (startState != null) {
- // writeNode(addElement(element, getTypeName(startState)),
- // startState);
- }
- }
-
- private void writeNodes(Element parentElement, Collection<?> nodes) {
- Iterator<?> iter = nodes.iterator();
- while (iter.hasNext()) {
- org.jbpm.graph.def.Node node = (org.jbpm.graph.def.Node) iter
- .next();
- if (!(node instanceof StartState)) {
- Element nodeElement = addElement(parentElement, ProcessFactory
- .getTypeName(node));
- node.write(nodeElement);
- // writeNode(nodeElement, node);
- }
- }
- }
-
- public static void writeNode(Element activity, Element node) {
- addAttribute(node, B2JMessages.Jpdl_Element_Name, activity.getName());
-
- // if
- // (B2JMessages.Jpdl_ProcessState_Element_Name.equals(getTypeName(node
- // ))) {
- // Element ele =
- // addElement(node,B2JMessages.Jpdl_SubProcess_Element_Name);
- // addAttribute(ele, B2JMessages.Jpdl_Element_Name,((ProcessState)
- // node).getSubProcessDefinition().getName());
- // }
- }
-
- private void writeTransitions(Element element, org.jbpm.graph.def.Node node) {
- if (node.getLeavingTransitionsMap() != null) {
- Iterator<?> iter = node.getLeavingTransitionsList().iterator();
- while (iter.hasNext()) {
- Transition transition = (Transition) iter.next();
- writeTransition(element
- .addElement(B2JMessages.Jpdl_Transition_Element),
- transition);
- }
- }
- }
-
- private void writeTransition(Element transitionElement,
- Transition transition) {
- if (transition.getTo() != null) {
- transitionElement.addAttribute(B2JMessages.To, transition.getTo()
- .getName());
- }
- if (transition.getName() != null) {
- transitionElement.addAttribute(B2JMessages.Jpdl_Element_Name,
- transition.getName());
- }
- }
-
+ /*
+ * add a new element to a dom element
+ */
public static Element addElement(Element element, String elementName) {
Element newElement = element.addElement(elementName);
return newElement;
}
+ /*
+ * add a new element to the location of a dom element
+ */
@SuppressWarnings("unchecked")
public static Element addElement(Element element, String elementName,
int location) {
Element newElement = null;
- if (element.elements("transtion") != null
- && element.elements("transtion").size() > location
+ if (element.elements(elementName) != null
+ && element.elements(elementName).size() > location
&& location >= 0) {
element = DocumentHelper.createElement(elementName);
- element.elements("transtion").add(location, newElement);
+ element.elements(elementName).add(location, newElement);
}
return newElement;
}
+ /*
+ * add a attribute to a dom element
+ */
public static void addAttribute(Element e, String attributeName,
String value) {
if (value != null) {
@@ -159,4 +91,25 @@
}
}
+ /*
+ * get a named element from a element (any depth)
+ */
+ public static List<Element> getElementsByName(Element element, String name) {
+ List<Element> list = new LinkedList<Element>();
+ for (Object ele : element.elements()) {
+ if (name.equals(((Element) ele).getName())) {
+ list.add((Element) ele);
+ }
+ list.addAll(getElementsByName((Element) ele, name));
+ }
+ return list;
+ }
+
+ /*
+ * set a element attribute using a same name attribute of other element
+ */
+ public static void mapAttribute(Element ele, String attrName, Element sourceEle){
+ DomXmlWriter.addAttribute(ele, attrName,sourceEle.attributeValue(attrName));
+ }
+
}
Added:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java
(rev 0)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/GraphicalFileGenerator.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -0,0 +1,233 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.b2j.translate;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.jboss.tools.b2j.B2J;
+import org.jboss.tools.b2j.messages.B2JMessages;
+
+/**
+ * @author Grid Qian
+ *
+ * this is a translator for bpmn_diagram to gpd of jpdl
+ */
+public class GraphicalFileGenerator {
+
+ String rootLocation;
+ String bpmnFileName;
+ Document document;
+
+ // gpd.xml documents list
+ List<Document> gpdDefs = new LinkedList<Document>();
+ // the pool of gpd.xml name
+ List<String> gpdPoolNames = new LinkedList<String>();
+ Map<String, Element> map = new HashMap<String, Element>();
+
+ // the warning messages when translate
+ List<String> warnings = new ArrayList<String>();
+
+ // the error messages when translate
+ List<String> errors = new ArrayList<String>();
+
+ public List<String> getErrors() {
+ return errors;
+ }
+
+ public void setErrors(List<String> errors) {
+ this.errors = errors;
+ }
+
+ public List<String> getWarnings() {
+ return warnings;
+ }
+
+ public void setWarnings(List<String> warnings) {
+ this.warnings = warnings;
+ }
+
+ public GraphicalFileGenerator(Document bpmnDiagramDocument,
+ Map<String, Element> map, String rootLocation, String bpmnFileName) {
+ this.rootLocation = rootLocation;
+ this.bpmnFileName = bpmnFileName;
+ this.document = bpmnDiagramDocument;
+ this.map = map;
+ }
+
+ /*
+ * translate a bpmn_diagram document to a gpd document string
+ */
+ public String[] translateToStrings() {
+ this.translateDiagram(this.document);
+ String[] strForProcessDefs = new String[gpdDefs.size()];
+ int i = 0;
+ for (Document def : gpdDefs) {
+ try {
+ strForProcessDefs[i] = DomXmlWriter.toString(def);
+ } catch (IOException e) {
+ this.errors
+ .add(B2JMessages.Translate_Error_GpdFile_CanNotGenerate
+ + e.getMessage());
+ }
+ i++;
+ }
+ return strForProcessDefs;
+ }
+
+ /*
+ * translate every gpd document string to a gpd file
+ */
+ public void translateToFiles() {
+ String[] strForGpdDefs = translateToStrings();
+ String[] gpdFileNames = new String[gpdDefs.size()];
+ int i = 0;
+ for (Document def : gpdDefs) {
+ gpdFileNames[i] = def.getRootElement().attributeValue(
+ B2JMessages.Dom_Element_Name);
+ i++;
+ }
+
+ try {
+ TranslateHelper.createFiles(rootLocation, bpmnFileName,
+ strForGpdDefs, gpdFileNames,
+ B2JMessages.Gpd_Definition_Name);
+ } catch (Exception e) {
+ errors.add(B2JMessages.Translate_Error_GpdFile_CanNotWrite
+ + e.getMessage());
+ }
+
+ if (errors.size() != 0) {
+ for (String str : errors) {
+ B2J.getDefault().logError(str);
+ }
+ }
+
+ if (warnings.size() != 0) {
+ for (String str : warnings) {
+ B2J.getDefault().logWarning(str);
+ }
+ }
+ }
+
+ /*
+ * translate the graphical bpmn_diagram document
+ */
+ private void translateDiagram(Document diagramDocument) {
+ Element rootElement = diagramDocument.getRootElement();
+ List<Element> eleList = DomXmlWriter.getElementsByName(rootElement,
+ B2JMessages.Gpd_Element_Name);
+
+ for (String bpmnID : map.keySet()) {
+ if (bpmnID != null) {
+ // when translate bpmn loop activity, we create a mock
+ // structure.
+ // For this reason, we need to give a (x,y) increment to avoid
+ // two element overlap
+ int xIncre = 0;
+ int yIncre = 0;
+ Element bpmnGpdEle = TranslateHelper.getDiagramLayoutElement(
+ bpmnID, eleList);
+ if (bpmnGpdEle == null
+ && bpmnID
+ .endsWith(B2JMessages.Bpmn_Vertice_Element_Name)) {
+ bpmnGpdEle = TranslateHelper.getDiagramLayoutElement(
+ TranslateHelper.getPureBpmnID(bpmnID,
+ B2JMessages.Bpmn_Vertice_Element_Name),
+ eleList);
+ xIncre = 50;
+ yIncre = 50;
+ }
+ if (bpmnGpdEle == null) {
+ continue;
+ }
+ translateGraphicalElement(TranslateHelper.getXY(bpmnGpdEle,
+ xIncre, yIncre), map.get(bpmnID), eleList);
+ }
+ }
+
+ }
+
+ private void translateGraphicalElement(String[] xy, Element jpdlEle,
+ List<Element> eleList) {
+ if (jpdlEle == null) {
+ return;
+ }
+
+ // if not translate, then translate the pool of the element
+ if (!gpdPoolNames.contains(jpdlEle.getParent().attributeValue(
+ B2JMessages.Dom_Element_Name))
+ && B2JMessages.Jpdl_Process_Definition_Element_Name
+ .equals(jpdlEle.getParent().getName())) {
+ translatePool(eleList, jpdlEle);
+ }
+
+ // translate the bpmn graphical element
+ Element poolEle = null;
+ for (Document doc : gpdDefs) {
+ if (doc.getRootElement().attributeValue(
+ B2JMessages.Dom_Element_Name).equals(
+ jpdlEle.getParent().attributeValue(
+ B2JMessages.Dom_Element_Name))) {
+ poolEle = doc.getRootElement();
+ }
+ }
+ Element pgdEle = TranslateHelper.createNode(poolEle,
+ B2JMessages.Jpdl_Node_Element_Name, jpdlEle);
+
+ TranslateHelper.mapXY(pgdEle, xy[0], xy[1]);
+
+ // translate the sequence flow of the element
+ for (Object ele : jpdlEle.elements(B2JMessages.Jpdl_Transition_Element)) {
+ TranslateHelper.createTransition(pgdEle,
+ B2JMessages.Jpdl_Transition_Element, (Element) ele);
+ }
+ }
+
+ private void translatePool(List<Element> eleList, Element jpdlEle) {
+ // get the bpmn pool id
+ String poolBpmnID = null;
+ for (String id : map.keySet()) {
+ if (map.get(id) == jpdlEle.getParent()) {
+ poolBpmnID = TranslateHelper.getPureBpmnID(id,
+ B2JMessages.Bpmn_Pool_Element_Name);
+ break;
+ }
+ }
+ // get the bpmn pool graphical element
+ if (poolBpmnID != null) {
+ Element poolBpmnGpdEle = TranslateHelper.getDiagramLayoutElement(
+ poolBpmnID, eleList);
+ Document processDiagramDef = DomXmlWriter.createDomTree(false,
+ null, B2JMessages.Gpd_Process_Diagram_Name);
+ Element poolEle = processDiagramDef.getRootElement();
+ DomXmlWriter.mapAttribute(poolEle, B2JMessages.Dom_Element_Name,
+ jpdlEle.getParent());
+ DomXmlWriter.mapAttribute(poolEle,
+ B2JMessages.Width_Attribute_Name, poolBpmnGpdEle);
+ DomXmlWriter.mapAttribute(poolEle,
+ B2JMessages.Height_Attribute_Name, poolBpmnGpdEle);
+
+ gpdDefs.add(processDiagramDef);
+ gpdPoolNames.add(poolEle
+ .attributeValue(B2JMessages.Dom_Element_Name));
+ }
+
+ }
+
+}
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/TranslateHelper.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/TranslateHelper.java 2008-08-19
23:45:02 UTC (rev 9805)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/translate/TranslateHelper.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,35 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.b2j.translate;
+import java.io.File;
+import java.io.IOException;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.dom4j.Document;
import org.dom4j.Element;
import org.jboss.tools.b2j.messages.B2JMessages;
+import org.jboss.tools.b2j.util.B2JUtil;
+/**
+ * @author Grid Qian
+ *
+ * this is a helper class for bpmn ->jpdl
+ */
public class TranslateHelper {
+ // the map for the bpmn element id : the corresponding generated element
static Map<String, Integer> nameMap = new HashMap<String, Integer>();
-
-
public static void setNameMap(Map<String, Integer> nameMap) {
TranslateHelper.nameMap = nameMap;
}
/*
+ * get the bpmn_diagram file name
+ */
+ public static String getBpmnDiagramName(String bpmnFileName) {
+ return bpmnFileName + B2JMessages.Bpmn_Diagram_Name_Suffix;
+ }
+
+ /*
+ * create a jpdl dom tree
+ */
+ public static Document createJpdlDomTree(boolean useNamespace) {
+ return DomXmlWriter.createDomTree(useNamespace,
+ B2JMessages.Jpdl_32_Namespace_Url,
+ B2JMessages.Jpdl_Process_Definition_Element_Name);
+
+ }
+
+ /*
+ * create translated files from dom strings
+ */
+ public static File[] createFiles(String parentFolder, String bpmnFileName,
+ String[] strsForGenerate, String[] fileFolders, String fileName)
+ throws IOException {
+ File jpdlFolder = B2JUtil.createFile(parentFolder,
+ B2JMessages.Jpdl_Suffix, null);
+ File diagramFolder = B2JUtil.createFile(jpdlFolder.getAbsolutePath(),
+ bpmnFileName, null);
+
+ File[] files = new File[strsForGenerate.length];
+ File processFolder = null;
+ int i = 0;
+ for (String str : strsForGenerate) {
+ processFolder = B2JUtil.createFile(diagramFolder.getAbsolutePath(),
+ fileFolders[i], null);
+ files[i] = B2JUtil.createFile(processFolder.getAbsolutePath(),
+ fileName, str);
+ i++;
+ }
+ return files;
+ }
+
+ /*
* generate a process definition name. the name is composed of the names
* from bpmn diagram to the element
*/
public static String generateProcessName(Element graph) {
if ("BpmnDiagram".equals(graph.getName())) {
- return graph.attributeValue("name");
+ return graph.attributeValue(B2JMessages.Dom_Element_Name);
} else {
String str = generateProcessName(graph.getParent());
if (str == null) {
- return graph.attributeValue("name");
+ return graph.attributeValue(B2JMessages.Dom_Element_Name);
} else {
return str + B2JMessages.Folder_Name_Separator
- + graph.attributeValue("name");
+ + graph.attributeValue(B2JMessages.Dom_Element_Name);
}
}
@@ -42,18 +103,20 @@
public static boolean check_mapElementName(Element graph, Element graphEle) {
boolean isOk = true;
- String name = graph.attributeValue(B2JMessages.Jpdl_Element_Name);
-
+ String name = graph.attributeValue(B2JMessages.Dom_Element_Name);
+
if (name == null || "".equals(name)) {
name = "jboss_autogen";
isOk = false;
}
Integer i = nameMap.get(name);
if (i == null) {
- DomXmlWriter.addAttribute(graphEle,B2JMessages.Jpdl_Element_Name, name);
+ DomXmlWriter.addAttribute(graphEle, B2JMessages.Dom_Element_Name,
+ name);
nameMap.put(name, new Integer("1"));
} else {
- DomXmlWriter.addAttribute(graphEle,B2JMessages.Jpdl_Element_Name, name + "_"
+ i);
+ DomXmlWriter.addAttribute(graphEle, B2JMessages.Dom_Element_Name,
+ name + "_" + i);
nameMap.put(name, ++i);
isOk = false;
}
@@ -62,4 +125,99 @@
}
+ /*
+ * get the layout element from bpmn_diagram file by id
+ */
+ public static Element getDiagramLayoutElement(String bpmnID,
+ List<Element> eleList) {
+ Element element = null;
+ for (Element ele : eleList) {
+ String str = ele
+ .attributeValue(B2JMessages.Bpmn_Href_Attribute_Name);
+ if (str != null && str.contains(bpmnID)) {
+ element = ele;
+ break;
+ }
+ }
+
+ if (element != null
+ && element.getParent().element(
+ B2JMessages.Gpd_Layout_Element_Name) != null) {
+ return element.getParent().element(
+ B2JMessages.Gpd_Layout_Element_Name);
+ }
+
+ return null;
+ }
+
+ /*
+ * create a graphical jpdl transition
+ */
+ public static Element createTransition(Element parentEle, String name,
+ Element jpdlEle) {
+ Element ele = DomXmlWriter.addElement(parentEle, name);
+ DomXmlWriter.mapAttribute(ele, B2JMessages.Dom_Element_Name, jpdlEle);
+
+ Element label = DomXmlWriter.addElement(ele,
+ B2JMessages.Gpd_Label_Element_Name);
+ TranslateHelper.mapXY(label, "5", "-10");
+ return ele;
+ }
+
+ /*
+ * create graphical jpdl element
+ */
+ private static Element createElement(Element parentEle, String name,
+ String width, String height) {
+ Element ele = DomXmlWriter.addElement(parentEle, name);
+ DomXmlWriter.addAttribute(ele, B2JMessages.Width_Attribute_Name, width);
+ DomXmlWriter.addAttribute(ele, B2JMessages.Height_Attribute_Name, height);
+ return ele;
+ }
+
+ /*
+ * create graphical jpdl node
+ */
+ public static Element createNode(Element rootEle, String name,
+ Element jpdlEle) {
+ Element ele = TranslateHelper.createElement(rootEle, name, "100",
"40");
+ DomXmlWriter.mapAttribute(ele, B2JMessages.Dom_Element_Name, jpdlEle);
+ return ele;
+ }
+
+ /*
+ * map bpmn x,y attribute to jpdl graphical element
+ */
+ public static void mapXY(Element pgdEle, String x, String y) {
+ DomXmlWriter.addAttribute(pgdEle, B2JMessages.X_Attribute_Name,
+ x == null ? "0" : x);
+ DomXmlWriter.addAttribute(pgdEle, B2JMessages.Y_Attribute_Name,
+ y == null ? "0" : y);
+
+ }
+
+ /*
+ * get a bpmn element id from a given string by subtract suffix for example
+ * bpmn pool has pools suffix a bpmn loop activity has vertices suffix
+ */
+ public static String getPureBpmnID(String bpmnID, String suffix) {
+ return bpmnID.substring(0, bpmnID.length() - suffix.length());
+ }
+
+ /*
+ * get (x,y) from a graphical element and add increments
+ */
+ public static String[] getXY(Element bpmnGpdEle, int xIncre, int yIncre) {
+ String xy[] = new String[2];
+ xy[0] = String.valueOf(Integer.parseInt(bpmnGpdEle
+ .attributeValue(B2JMessages.X_Attribute_Name) == null ? "0"
+ : bpmnGpdEle.attributeValue(B2JMessages.X_Attribute_Name))
+ + xIncre);
+ xy[1] = String.valueOf(Integer.parseInt(bpmnGpdEle
+ .attributeValue(B2JMessages.Y_Attribute_Name) == null ? "0"
+ : bpmnGpdEle.attributeValue(B2JMessages.Y_Attribute_Name))
+ + yIncre);
+ return xy;
+ }
+
}
Modified:
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/util/B2JUtil.java
===================================================================
---
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/util/B2JUtil.java 2008-08-19
23:45:02 UTC (rev 9805)
+++
workspace/grid/org.jboss.tools.bpmn2jpdl/src/org/jboss/tools/b2j/util/B2JUtil.java 2008-08-20
06:47:12 UTC (rev 9806)
@@ -1,10 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
package org.jboss.tools.b2j.util;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.PrintWriter;
import javax.xml.parsers.SAXParser;
@@ -12,13 +24,19 @@
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
-import org.jboss.tools.b2j.messages.B2JMessages;
import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
+/**
+ * @author Grid Qian
+ *
+ * this a util class
+ */
public class B2JUtil {
+ /*
+ * create a file
+ */
public static File createFile(String parentFolder, String fileName,
String inputStr) throws IOException {
File child = new File(parentFolder, fileName);
@@ -40,73 +58,68 @@
return child;
}
- public static File[] createJpdlFiles(String parentFolder,
- String bpmnFileName, String[] strForProcessDefs,
- String[] jpdlFileNames) throws IOException {
- File jpdlFolder = B2JUtil.createFile(parentFolder,
- B2JMessages.Jpdl_Suffix, null);
- File diagramFolder = B2JUtil.createFile(jpdlFolder.getAbsolutePath(),
- bpmnFileName, null);
+ /*
+ * get a sax input source
+ */
+ public static InputSource getInputSource(String parentFolder,
+ String fileName) throws FileNotFoundException {
+ return new InputSource(B2JUtil.getInputStream(parentFolder, fileName));
- File[] jpdlFiles = new File[strForProcessDefs.length];
- File processFolder = null;
- int i = 0;
- for (String str : strForProcessDefs) {
- processFolder = B2JUtil.createFile(diagramFolder.getAbsolutePath(),
- jpdlFileNames[i], null);
- jpdlFiles[i] = B2JUtil.createFile(processFolder.getAbsolutePath(),
- B2JMessages.Jpdl_Process_Definition_Name, str);
- i++;
- }
- return jpdlFiles;
}
- public static InputSource getInpuSource(String path, String name)
- throws FileNotFoundException {
- File file = new File(path, name);
- return new InputSource(new FileReader(file));
+ /*
+ * get a input stream
+ */
+ public static InputStream getInputStream(String parentFolder,
+ String fileName) throws FileNotFoundException {
+ File file = new File(parentFolder, fileName);
+ InputStream input = new FileInputStream(file);
+ return input;
}
- public static Document parse(InputSource inputSource) throws Exception {
+ /*
+ * parse a file to a dom document
+ */
+ public static Document parse(String parentFolder, String fileName)
+ throws Exception {
Document document = null;
SAXReader saxReader = createSaxReader();
- document = saxReader.read(inputSource);
+ document = saxReader.read(B2JUtil
+ .getInputSource(parentFolder, fileName));
return document;
}
+ /*
+ * create a sax reader
+ */
public static SAXReader createSaxReader() throws Exception {
XMLReader xmlReader = createXmlReader();
SAXReader saxReader = new SAXReader(xmlReader);
return saxReader;
}
+ /*
+ * create a sax xml reader
+ */
public static XMLReader createXmlReader() throws Exception {
SAXParser saxParser = createSaxParserFactory().newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
- try {
- saxParser.setProperty(
- "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
- "http://www.w3.org/2001/XMLSchema");
- } catch (SAXException e) {
- // log.warn(
- // "couldn't set xml parser property
'http://java.sun.com/xml/jaxp/properties/schemaLanguage' to
'http://www.w3.org/2001/XMLSchema'"
- // , e);
- }
+ saxParser.setProperty(
+ "http://java.sun.com/xml/jaxp/properties/schemaLanguage",
+ "http://www.w3.org/2001/XMLSchema");
- try {
- xmlReader.setFeature(
- "http://apache.org/xml/features/validation/dynamic", true);
- } catch (SAXException e) {
- // log.warn(
- // "couldn't set xml parser feature
'http://apache.org/xml/features/validation/dynamic'"
- // , e);
- }
+ xmlReader.setFeature(
+ "http://apache.org/xml/features/validation/dynamic", true);
+
return xmlReader;
}
+ /*
+ * create a sax parser factory
+ */
private static SAXParserFactory createSaxParserFactory() {
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setValidating(true);