Source Code Cross Referenced for XPDLGenerator.java in  » Workflow-Engines » wfmopen-2.1.1 » xpdlgen » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » wfmopen 2.1.1 » xpdlgen 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the WfMOpen project.
003:         * Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
004:         * All rights reserved.
005:         *
006:         * This program is free software; you can redistribute it and/or modify
007:         * it under the terms of the GNU General Public License as published by
008:         * the Free Software Foundation; either version 2 of the License, or
009:         * (at your option) any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         * $Id: XPDLGenerator.java,v 1.4 2007/04/05 12:46:37 drmlipp Exp $
021:         *
022:         * $Log: XPDLGenerator.java,v $
023:         * Revision 1.4  2007/04/05 12:46:37  drmlipp
024:         * Adapted to JDOM 1.0.
025:         *
026:         * Revision 1.3  2007/03/27 21:59:44  mlipp
027:         * Fixed lots of checkstyle warnings.
028:         *
029:         * Revision 1.2  2006/09/29 12:32:13  drmlipp
030:         * Consistently using WfMOpen as projct name now.
031:         *
032:         * Revision 1.1.1.1  2003/06/30 20:07:00  drmlipp
033:         * Initial import
034:         *
035:         * Revision 1.4  2003/06/27 09:44:13  lipp
036:         * Fixed copyright/license information.
037:         *
038:         * Revision 1.3  2003/04/24 20:51:21  lipp
039:         * Fixed some warnings.
040:         *
041:         * Revision 1.2  2003/04/16 19:25:03  lipp
042:         * Adapted to jdk 1.4
043:         *
044:         * Revision 1.1  2002/11/25 14:36:22  huaiyang
045:         * initial.
046:         *
047:         * Revision 1.4  2002/11/25 14:11:35  huaiyang
048:         * Call xpdl generator with given parameter.
049:         *
050:         * Revision 1.3  2002/11/21 16:01:43  huaiyang
051:         * check in because of breaking up.
052:         *
053:         * Revision 1.2  2002/11/21 15:09:06  huaiyang
054:         * Add generating transitions.
055:         *
056:         * Revision 1.1  2002/11/21 13:41:51  huaiyang
057:         * testfile used for XPDLGenerator.
058:         *
059:         *
060:         */
061:        package xpdlgen;
062:
063:        import java.io.FileWriter;
064:        import java.io.IOException;
065:
066:        import java.util.Date;
067:
068:        import java.text.SimpleDateFormat;
069:
070:        import org.jdom.Document;
071:        import org.jdom.Element;
072:        import org.jdom.JDOMException;
073:        import org.jdom.Namespace;
074:        import org.jdom.output.Format;
075:        import org.jdom.output.XMLOutputter;
076:
077:        import de.danet.an.workflow.util.XPDLUtil;
078:
079:        /**
080:         * The <code>XPDLGenerator</code> provides functions for generating XPDL
081:         */
082:        public class XPDLGenerator {
083:
084:            private static SimpleDateFormat toDateTimeFormatter = null;
085:            // XPDLGenerator Object
086:            private static XPDLGenerator xpdlGen = null;
087:            // depth 
088:            private int depth;
089:            // joinMode 
090:            private String joinMode;
091:            // output directory 
092:            private String outputPath;
093:            // XPDL JDOM Element
094:            private Element xpdlElement = null;
095:            // namespace
096:            private Namespace ns;
097:
098:            /**
099:             * Generate a valid process definition.
100:             * @param depth the depth of the nested activities of a process
101:             * @param joinMode the mode of the join type.
102:             * @param outputPath the output path of the generated xpdl file.
103:             */
104:            public XPDLGenerator(int depth, String joinMode, String outputPath)
105:                    throws Exception {
106:                this .depth = depth;
107:                this .joinMode = joinMode;
108:                this .outputPath = outputPath;
109:                start();
110:            }
111:
112:            private void start() throws JDOMException, IOException {
113:                ns = Namespace.getNamespace(XPDLUtil.XPDL_NS);
114:                xpdlElement = new Element("Package");
115:                createPackageHeader(xpdlElement);
116:                createWorkflowProcess(xpdlElement);
117:                generateXPDL(xpdlElement);
118:            }
119:
120:            private void createPackageHeader(Element xpdlElem)
121:                    throws JDOMException {
122:                // create package element
123:                String xmlns_xpdl = "http://www.wfmc.org/2002/XPDL1.0";
124:                String xmlns_xsi = "http://www.w3.org/2001/XMLSchema-instance";
125:                String xmlns_vx = "http://www.an.danet.de/2002/XPDL-Extensions1.0";
126:                String xsi_schemaLocation = "http://www.wfmc.org/2002/XPDL1.0 http://www.wfmc.org/standards/docs/xpdl.xsd";
127:                String packageId = "xpdl";
128:                String packageName = "generatedXPDL";
129:                xpdlElem.addNamespaceDeclaration(ns);
130:                Namespace xpdlns = Namespace.getNamespace("xpdl", xmlns_xpdl);
131:                xpdlElem.addNamespaceDeclaration(xpdlns);
132:                Namespace vxns = Namespace.getNamespace("vx", xmlns_vx);
133:                xpdlElem.addNamespaceDeclaration(vxns);
134:                Namespace xsins = Namespace.getNamespace("xsi", xmlns_xsi);
135:                xpdlElem.setAttribute("schemaLocation", xsi_schemaLocation,
136:                        xsins);
137:                xpdlElem.setAttribute("Id", packageId);
138:                xpdlElem.setAttribute("Name", packageName);
139:                // create package header
140:                Element packageHeader = new Element("PackageHeader", ns);
141:                Element xpdlVersion = new Element("XPDLVersion", ns);
142:                xpdlVersion.addContent(XPDLUtil.XPDL_VERSION);
143:                packageHeader.addContent(xpdlVersion);
144:                Element vendor = new Element("Vendor", ns);
145:                vendor.addContent("Danet GmbH, GS AN");
146:                packageHeader.addContent(vendor);
147:                Element created = new Element("Created", ns);
148:                Date createDate = new Date();
149:                created.addContent(createDate.toString());
150:                packageHeader.addContent(created);
151:                xpdlElem.addContent(packageHeader);
152:            }
153:
154:            private void createWorkflowProcess(Element xpdlElem)
155:                    throws JDOMException {
156:                // create header of workflow process
157:                Element workflowProcesses = new Element("WorkflowProcesses", ns);
158:                Element workflowProcess = new Element("WorkflowProcess", ns);
159:                workflowProcess.setAttribute("Id", "1");
160:                workflowProcess.setAttribute("Name", "1");
161:                Element processHeader = new Element("ProcessHeader", ns);
162:                workflowProcess.addContent(processHeader);
163:                // createActivities
164:                createActivities(workflowProcess);
165:                // createTransitions
166:                createTransitions(workflowProcess);
167:                workflowProcesses.addContent(workflowProcess);
168:                xpdlElement.addContent(workflowProcesses);
169:            }
170:
171:            private void generateXPDL(Element xpdlElem) throws JDOMException,
172:                    IOException {
173:                FileWriter writer = new FileWriter(outputPath);
174:                //StringWriter writer = new StringWriter();
175:                Format format = Format.getPrettyFormat();
176:                format.setLineSeparator("\n");
177:                format.setEncoding("ISO-8859-1");
178:                XMLOutputter outputter = new XMLOutputter(format);
179:                Document doc = new Document(xpdlElem);
180:                outputter.output(doc, writer);
181:                //System.out.println(writer.toString());
182:                writer.close();
183:            }
184:
185:            private void createActivities(Element wfProc) throws JDOMException {
186:                Element activities = new Element("Activities", ns);
187:                wfProc.addContent(activities);
188:                for (int i = 1; i <= depth; i++) {
189:                    for (int j = 1; j <= i; j++) {
190:                        if ((i + j) > (depth + 1)) {
191:                            break;
192:                        }
193:                        String id = Integer.toString(i) + Integer.toString(j);
194:                        Element activity = createActivity(id);
195:                        activities.addContent(activity);
196:                        if (i == depth) {
197:                            break;
198:                        }
199:                    }
200:                }
201:            }
202:
203:            private Element createActivity(String id) throws JDOMException {
204:                Element activity = new Element("Activity", ns);
205:                activity.setAttribute("Id", id);
206:                activity.setAttribute("Name", id);
207:                Element implementation = new Element("Implementation", ns);
208:                implementation.addContent(new Element("No", ns));
209:                activity.addContent(implementation);
210:                Element startmode = new Element("StartMode", ns);
211:                startmode.addContent(new Element("Automatic", ns));
212:                activity.addContent(startmode);
213:                Element finishmode = new Element("FinishMode", ns);
214:                finishmode.addContent(new Element("Automatic", ns));
215:                activity.addContent(finishmode);
216:                Element transRestrics = createTransitionRestrictions();
217:                activity.addContent(transRestrics);
218:                return activity;
219:            }
220:
221:            private Element createTransitionRestrictions() throws JDOMException {
222:                Element transRestrics = new Element("TransitionRestrictions",
223:                        ns);
224:                Element transRestric = new Element("TransitionRestriction", ns);
225:                // Join Type
226:                Element join = new Element("Join", ns);
227:                join.setAttribute("Type", joinMode);
228:                transRestric.addContent(join);
229:                // Split Type = "AND"
230:                Element split = new Element("Split", ns);
231:                split.setAttribute("Type", "AND");
232:                transRestric.addContent(split);
233:                transRestrics.addContent(transRestric);
234:                return transRestrics;
235:            }
236:
237:            private void createTransitions(Element wfProc) throws JDOMException {
238:                Element trans = new Element("Transitions", ns);
239:                String toId1 = null;
240:                String toId2 = null;
241:                for (int i = 1; i <= depth; i++) {
242:                    for (int j = 1; j <= i; j++) {
243:                        if (((i + j) > (depth + 1)) || (i == depth)) {
244:                            break;
245:                        }
246:                        String fromId = Integer.toString(i)
247:                                + Integer.toString(j);
248:                        if ((i <= depth / 2) && ((i + j + 1) < (depth + 1))) {
249:                            toId1 = Integer.toString(i + 1)
250:                                    + Integer.toString(j);
251:                            if ((i + j + 1) < (depth + 1)) {
252:                                toId2 = Integer.toString(i + 1)
253:                                        + Integer.toString(j + 1);
254:                            }
255:                        } else {
256:                            if ((i + j) < (depth + 1)) {
257:                                toId1 = Integer.toString(i + 1)
258:                                        + Integer.toString(j);
259:                            }
260:                            if ((j - 1) > 0) {
261:                                toId2 = Integer.toString(i + 1)
262:                                        + Integer.toString(j - 1);
263:                            }
264:                        }
265:                        createTransition(trans, fromId + "To" + toId1, fromId,
266:                                toId1);
267:                        createTransition(trans, fromId + "To" + toId2, fromId,
268:                                toId2);
269:                        toId1 = null;
270:                        toId2 = null;
271:                    }
272:                }
273:                wfProc.addContent(trans);
274:            }
275:
276:            private void createTransition(Element transitions, String id,
277:                    String from, String to) throws JDOMException {
278:                if ((id == null) || (from == null) || (to == null)) {
279:                    return;
280:                }
281:                Element transition = new Element("Transition", ns);
282:                transition.setAttribute("Id", id);
283:                transition.setAttribute("From", from);
284:                transition.setAttribute("To", to);
285:                transitions.addContent(transition);
286:            }
287:
288:            /**
289:             * Main-Methode des XPDLGenerator. 
290:             * @param args arguments
291:             * @throws Exception any error occurred.
292:             */
293:            public static void main(String[] args) throws Exception {
294:                if (args.length != 3) {
295:                    System.out
296:                            .println("Usage: java de.danet.an.workflow.util.XPDLGenerator "
297:                                    + "<depth> <join mode> <output path>");
298:                    System.exit(-1);
299:                }
300:                xpdlGen = new XPDLGenerator(Integer.parseInt(args[0]), args[1],
301:                        args[2]);
302:            }
303:
304:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.