Source Code Cross Referenced for Dom4JXPDLSerializer.java in  » Workflow-Engines » obe-1.0 » org » obe » xpdl » serializer » dom4j » 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 » obe 1.0 » org.obe.xpdl.serializer.dom4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*--
0002:
0003:         Copyright (C) 2002-2005 Adrian Price.
0004:         All rights reserved.
0005:
0006:         Redistribution and use in source and binary forms, with or without
0007:         modification, are permitted provided that the following conditions
0008:         are met:
0009:
0010:         1. Redistributions of source code must retain the above copyright
0011:            notice, this list of conditions, and the following disclaimer.
0012:
0013:         2. Redistributions in binary form must reproduce the above copyright
0014:            notice, this list of conditions, and the disclaimer that follows
0015:            these conditions in the documentation and/or other materials
0016:            provided with the distribution.
0017:
0018:         3. The names "OBE" and "Open Business Engine" must not be used to
0019:         	endorse or promote products derived from this software without prior
0020:         	written permission.  For written permission, please contact
0021:         	adrianprice@sourceforge.net.
0022:
0023:         4. Products derived from this software may not be called "OBE" or
0024:         	"Open Business Engine", nor may "OBE" or "Open Business Engine"
0025:         	appear in their name, without prior written permission from
0026:         	Adrian Price (adrianprice@users.sourceforge.net).
0027:
0028:         THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
0029:         WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0030:         OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
0031:         DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
0032:         INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
0033:         (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
0034:         SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0035:         HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
0036:         STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
0037:         IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0038:         POSSIBILITY OF SUCH DAMAGE.
0039:
0040:         For more information on OBE, please see
0041:         <http://obe.sourceforge.net/>.
0042:
0043:         */
0044:
0045:        package org.obe.xpdl.serializer.dom4j;
0046:
0047:        import org.apache.commons.logging.Log;
0048:        import org.apache.commons.logging.LogFactory;
0049:        import org.dom4j.Document;
0050:        import org.dom4j.DocumentException;
0051:        import org.dom4j.DocumentFactory;
0052:        import org.dom4j.Element;
0053:        import org.dom4j.io.OutputFormat;
0054:        import org.dom4j.io.XMLWriter;
0055:        import org.obe.xpdl.XPDLMessages;
0056:        import org.obe.xpdl.model.activity.*;
0057:        import org.obe.xpdl.model.application.Application;
0058:        import org.obe.xpdl.model.condition.Condition;
0059:        import org.obe.xpdl.model.condition.ConditionType;
0060:        import org.obe.xpdl.model.condition.Xpression;
0061:        import org.obe.xpdl.model.data.*;
0062:        import org.obe.xpdl.model.ext.*;
0063:        import org.obe.xpdl.model.ext.Event;
0064:        import org.obe.xpdl.model.misc.*;
0065:        import org.obe.xpdl.model.participant.Participant;
0066:        import org.obe.xpdl.model.pkg.ExternalPackage;
0067:        import org.obe.xpdl.model.pkg.PackageHeader;
0068:        import org.obe.xpdl.model.pkg.XPDLPackage;
0069:        import org.obe.xpdl.model.transition.*;
0070:        import org.obe.xpdl.model.workflow.ProcessHeader;
0071:        import org.obe.xpdl.model.workflow.WorkflowProcess;
0072:        import org.obe.xpdl.parser.dom4j.DOM4JNames;
0073:        import org.obe.xpdl.serializer.ElementRequiredException;
0074:        import org.obe.xpdl.serializer.XPDLSerializer;
0075:        import org.obe.xpdl.serializer.XPDLSerializerException;
0076:
0077:        import java.awt.*;
0078:        import java.io.IOException;
0079:        import java.io.OutputStream;
0080:        import java.io.OutputStreamWriter;
0081:        import java.io.Writer;
0082:        import java.util.Date;
0083:        import java.util.Iterator;
0084:        import java.util.Map;
0085:
0086:        /**
0087:         * Implementation of the XPDLSerializer interface which uses the DOM4J library
0088:         * to serialize a package to an XPDL document.
0089:         *
0090:         * @author Anthony Eden
0091:         * @author Adrian Price
0092:         */
0093:        public class Dom4JXPDLSerializer implements  XPDLSerializer, DOM4JNames {
0094:            private static final String DEFAULT_XPDL_VERSION = "1.0";
0095:            private static final String DEFAULT_VENDOR = "obe.sourceforge.net";
0096:            private static final Log _logger = LogFactory
0097:                    .getLog(Dom4JXPDLSerializer.class);
0098:
0099:            public void serialize(XPDLPackage pkg, OutputStream out)
0100:                    throws IOException, XPDLSerializerException {
0101:
0102:                serialize(pkg, new OutputStreamWriter(out));
0103:            }
0104:
0105:            /**
0106:             * Serialize the package to the given output stream.
0107:             *
0108:             * @param pkg The Package
0109:             * @param out The OutputStream
0110:             * @throws IOException             Any I/O exception
0111:             * @throws XPDLSerializerException Any serializer Exception
0112:             */
0113:            public void serialize(XPDLPackage pkg, Writer out)
0114:                    throws IOException, XPDLSerializerException {
0115:
0116:                // Create the Document object
0117:                DocumentFactory df = DocumentFactory.getInstance();
0118:                Element pkgElement = df.createElement(PACKAGE, XPDL_NS_URI);
0119:                Document document = df.createDocument(pkgElement);
0120:
0121:                // Serialize the XPDLPackage
0122:                pkgElement.addAttribute(ID, pkg.getId());
0123:                pkgElement.addAttribute(NAME, pkg.getName());
0124:                //        pkgElement.add(new Namespace("", XPDL_NS_URI));
0125:                pkgElement.addNamespace("", XPDL_NS_URI);
0126:                pkgElement.addNamespace(XPDL_NS_PREFIX, XPDL_NS_URI);
0127:                pkgElement.addNamespace(XSD_NS_PREFIX, XSD_NS_URI);
0128:                pkgElement.addNamespace(XSI_NS_PREFIX, XSI_URI);
0129:                pkgElement.addNamespace(OBE_NS_PREFIX, OBE_NS_URI);
0130:                pkgElement.addAttribute(XSI_SCHEMA_LOCATION_QNAME,
0131:                        XPDL_SCHEMA_LOCATION);
0132:
0133:                // Store any additional XML namespace declarations, assuming there
0134:                // aren't any collisions in prefix usage (shouldn't be, since generally
0135:                // they'll all have been read from the document in the first place).
0136:                Map pkgNamespaces = pkg.getNamespaces();
0137:                for (Iterator iter = pkgNamespaces.entrySet().iterator(); iter
0138:                        .hasNext();) {
0139:                    Map.Entry ns = (Map.Entry) iter.next();
0140:                    String prefix = (String) ns.getKey();
0141:                    if (pkgElement.getNamespaceForPrefix(prefix) == null)
0142:                        pkgElement.addNamespace(prefix, (String) ns.getValue());
0143:                }
0144:
0145:                writePackageHeader(pkg.getPackageHeader(), pkgElement);
0146:                writeRedefinableHeader(pkg.getRedefinableHeader(), pkgElement);
0147:                writeConformanceClass(pkg.getConformanceClass(), pkgElement);
0148:                writeScript(pkg.getScript(), pkgElement);
0149:                writeExternalPackages(pkg.getExternalPackage(), pkgElement);
0150:                writeTypeDeclarations(pkg.getTypeDeclaration(), pkgElement);
0151:                writeParticipants(pkg.getParticipant(), pkgElement);
0152:                writeApplications(pkg.getApplication(), pkgElement);
0153:                writeDataFields(pkg.getDataField(), pkgElement);
0154:                writeWorkflowProcesses(pkg.getWorkflowProcess(), pkgElement);
0155:                writeExtendedAttributes(pkg.getExtendedAttributes(), pkgElement);
0156:
0157:                // OBE XPDL extensions.
0158:                writeExtendedAttribute(OBE_CALENDAR, pkg.getCalendar(),
0159:                        pkgElement);
0160:                writeAssignmentStrategy(pkg.getAssignmentStrategy(), pkgElement);
0161:                writeExtendedAttribute(OBE_COMPLETION_STRATEGY, pkg
0162:                        .getCompletionStrategy(), pkgElement);
0163:
0164:                // Write the document to the output stream.
0165:                OutputFormat format = new OutputFormat("    ", true);
0166:                XMLWriter writer = new XMLWriter(out, format);
0167:                writer.write(document);
0168:                out.flush();
0169:            }
0170:
0171:            protected void writePackageHeader(PackageHeader header,
0172:                    Element parent) throws XPDLSerializerException {
0173:
0174:                if (header == null)
0175:                    throw new ElementRequiredException(
0176:                            "Package header required");
0177:
0178:                Element headerElement = Util.addElement(parent, PACKAGE_HEADER);
0179:                Util.addElement(headerElement, XPDL_VERSION, header
0180:                        .getXPDLVersion(), DEFAULT_XPDL_VERSION);
0181:                Util.addElement(headerElement, VENDOR, header.getVendor(),
0182:                        DEFAULT_VENDOR);
0183:                Util.addElement(headerElement, CREATED, header.getCreated(),
0184:                        new Date());
0185:                Util.addElement(headerElement, DESCRIPTION, header
0186:                        .getDescription());
0187:                Util.addElement(headerElement, DOCUMENTATION, header
0188:                        .getDocumentation());
0189:                Util.addElement(headerElement, PRIORITY_UNIT, header
0190:                        .getPriorityUnit());
0191:                Util.addElement(headerElement, COST_UNIT, header.getCostUnit());
0192:            }
0193:
0194:            protected void writeRedefinableHeader(RedefinableHeader header,
0195:                    Element parent) {
0196:
0197:                if (header == null)
0198:                    return;
0199:
0200:                Element headerElement = Util.addElement(parent,
0201:                        REDEFINABLE_HEADER);
0202:
0203:                Util.addElement(headerElement, AUTHOR, header.getAuthor());
0204:                Util.addElement(headerElement, VERSION, header.getVersion());
0205:                Util.addElement(headerElement, CODEPAGE, header.getCodepage());
0206:                Util.addElement(headerElement, COUNTRYKEY, header
0207:                        .getCountrykey());
0208:
0209:                writeResponsibles(header.getResponsible(), headerElement);
0210:
0211:                PublicationStatus publicationStatus = header
0212:                        .getPublicationStatus();
0213:                if (publicationStatus != null) {
0214:                    headerElement.addAttribute(PUBLICATION_STATUS,
0215:                            publicationStatus.toString());
0216:                }
0217:            }
0218:
0219:            protected void writeConformanceClass(ConformanceClass cc,
0220:                    Element parent) {
0221:                if (cc == null) {
0222:                    _logger.debug("No conformance class specified");
0223:                    return;
0224:                }
0225:
0226:                _logger.debug("Writing conformance class: " + cc);
0227:                Element ccElement = Util.addElement(parent, CONFORMANCE_CLASS);
0228:                GraphConformance gc = cc.getGraphConformance();
0229:                if (gc != null)
0230:                    ccElement.addAttribute(GRAPH_CONFORMANCE, gc.toString());
0231:            }
0232:
0233:            protected void writeScript(Script script, Element parent) {
0234:                if (script == null) {
0235:                    _logger.debug("No script language specified");
0236:                    return;
0237:                }
0238:
0239:                Element scriptElement = Util.addElement(parent, SCRIPT);
0240:                scriptElement.addAttribute(TYPE, script.getType());
0241:                scriptElement.addAttribute(VERSION, script.getVersion());
0242:                scriptElement.addAttribute(GRAMMAR, script.getGrammar());
0243:            }
0244:
0245:            protected void writeExternalPackages(
0246:                    ExternalPackage[] externalPackages, Element parent)
0247:                    throws XPDLSerializerException {
0248:
0249:                if (externalPackages == null || externalPackages.length == 0)
0250:                    return;
0251:
0252:                Element externalPackagesElement = Util.addElement(parent,
0253:                        EXTERNAL_PACKAGES);
0254:                for (int i = 0; i < externalPackages.length; i++) {
0255:                    ExternalPackage externalPackage = externalPackages[i];
0256:                    Element externalPackageElement = Util.addElement(
0257:                            externalPackagesElement, EXTERNAL_PACKAGE);
0258:
0259:                    externalPackageElement.addAttribute(HREF, externalPackage
0260:                            .getHref());
0261:
0262:                    writeExtendedAttributes(externalPackage
0263:                            .getExtendedAttributes(), externalPackageElement);
0264:                }
0265:            }
0266:
0267:            protected void writeTypeDeclarations(
0268:                    TypeDeclaration[] typeDeclarations, Element parent)
0269:                    throws XPDLSerializerException {
0270:
0271:                if (typeDeclarations == null || typeDeclarations.length == 0)
0272:                    return;
0273:
0274:                Element typeDeclarationsElement = Util.addElement(parent,
0275:                        TYPE_DECLARATIONS);
0276:                for (int i = 0; i < typeDeclarations.length; i++) {
0277:                    TypeDeclaration typeDeclaration = typeDeclarations[i];
0278:                    Element typeDeclarationElement = Util.addElement(
0279:                            typeDeclarationsElement, TYPE_DECLARATION);
0280:
0281:                    typeDeclarationElement.addAttribute(ID, typeDeclaration
0282:                            .getId());
0283:                    typeDeclarationElement.addAttribute(NAME, typeDeclaration
0284:                            .getName());
0285:
0286:                    writeType(typeDeclaration.getType(), typeDeclarationElement);
0287:                    Util.addElement(typeDeclarationElement, DESCRIPTION,
0288:                            typeDeclaration.getDescription());
0289:                    writeExtendedAttributes(typeDeclaration
0290:                            .getExtendedAttributes(), typeDeclarationElement);
0291:                }
0292:            }
0293:
0294:            protected void writeParticipants(Participant[] participants,
0295:                    Element parent) throws XPDLSerializerException {
0296:
0297:                if (participants == null || participants.length == 0)
0298:                    return;
0299:
0300:                Element participantsElement = Util.addElement(parent,
0301:                        PARTICIPANTS);
0302:                for (int i = 0; i < participants.length; i++) {
0303:                    Participant participant = participants[i];
0304:                    Element participantElement = Util.addElement(
0305:                            participantsElement, PARTICIPANT);
0306:
0307:                    participantElement.addAttribute(ID, participant.getId());
0308:                    if (participant.getName() != null)
0309:                        participantElement.addAttribute(NAME, participant
0310:                                .getName());
0311:
0312:                    Element participantTypeElement = Util.addElement(
0313:                            participantElement, PARTICIPANT_TYPE);
0314:                    participantTypeElement.addAttribute(TYPE, participant
0315:                            .getParticipantType().toString());
0316:
0317:                    Util.addElement(participantElement, DESCRIPTION,
0318:                            participant.getDescription());
0319:
0320:                    ExternalReference extRef = participant
0321:                            .getExternalReference();
0322:                    if (extRef != null)
0323:                        writeExternalReference(extRef, participantElement);
0324:
0325:                    writeExtendedAttributes(
0326:                            participant.getExtendedAttributes(),
0327:                            participantElement);
0328:
0329:                    writeExtendedAttribute(OBE_CALENDAR, participant
0330:                            .getCalendar(), participantElement);
0331:                }
0332:            }
0333:
0334:            protected void writeApplications(Application[] applications,
0335:                    Element parent) throws XPDLSerializerException {
0336:
0337:                if (applications == null || applications.length == 0)
0338:                    return;
0339:
0340:                Element applicationsElement = Util.addElement(parent,
0341:                        APPLICATIONS);
0342:                for (int i = 0; i < applications.length; i++) {
0343:                    Application application = applications[i];
0344:                    Element applicationElement = Util.addElement(
0345:                            applicationsElement, APPLICATION);
0346:
0347:                    applicationElement.addAttribute(ID, application.getId());
0348:                    if (application.getName() != null)
0349:                        applicationElement.addAttribute(NAME, application
0350:                                .getName());
0351:
0352:                    if (application.getDescription() != null) {
0353:                        Util.addElement(applicationElement, DESCRIPTION,
0354:                                application.getDescription());
0355:                    }
0356:
0357:                    writeFormalParameters(application.getFormalParameter(),
0358:                            applicationElement);
0359:                    writeExternalReference(application.getExternalReference(),
0360:                            applicationElement);
0361:                    writeExtendedAttributes(
0362:                            application.getExtendedAttributes(),
0363:                            applicationElement);
0364:                }
0365:            }
0366:
0367:            protected void writeDataFields(DataField[] dataFields,
0368:                    Element parent) throws XPDLSerializerException {
0369:
0370:                if (dataFields == null || dataFields.length == 0)
0371:                    return;
0372:
0373:                Element dataFieldsElement = Util
0374:                        .addElement(parent, DATA_FIELDS);
0375:                for (int i = 0; i < dataFields.length; i++) {
0376:                    DataField dataField = dataFields[i];
0377:                    Element dataFieldElement = Util.addElement(
0378:                            dataFieldsElement, DATA_FIELD);
0379:
0380:                    dataFieldElement.addAttribute(ID, dataField.getId());
0381:                    if (dataField.getName() != null)
0382:                        dataFieldElement
0383:                                .addAttribute(NAME, dataField.getName());
0384:                    if (dataField.isArray()) {
0385:                        dataFieldElement.addAttribute(IS_ARRAY, String
0386:                                .valueOf(dataField.isArray()));
0387:                    }
0388:
0389:                    writeDataType(dataField.getDataType(), dataFieldElement);
0390:
0391:                    Util.addElement(dataFieldElement, INITIAL_VALUE, dataField
0392:                            .getInitialValue());
0393:
0394:                    if (dataField.isArray()) {
0395:                        Util.addElement(dataFieldElement, LENGTH, Integer
0396:                                .toString(dataField.getLength()));
0397:                    }
0398:
0399:                    Util.addElement(dataFieldElement, DESCRIPTION, dataField
0400:                            .getDescription());
0401:
0402:                    writeExtendedAttributes(dataField.getExtendedAttributes(),
0403:                            dataFieldElement);
0404:                }
0405:            }
0406:
0407:            protected void writeDataType(DataType dataType, Element parent)
0408:                    throws XPDLSerializerException {
0409:
0410:                if (dataType == null)
0411:                    return;
0412:
0413:                Element dataTypeElement = Util.addElement(parent, DATA_TYPE);
0414:                writeType(dataType.getType(), dataTypeElement);
0415:            }
0416:
0417:            protected void writeResponsibles(String[] responsibles,
0418:                    Element parent) {
0419:                if (responsibles == null || responsibles.length == 0)
0420:                    return;
0421:
0422:                Element responsiblesElement = Util.addElement(parent,
0423:                        RESPONSIBLES);
0424:                for (int i = 0; i < responsibles.length; i++)
0425:                    Util.addElement(responsiblesElement, RESPONSIBLE,
0426:                            responsibles[i]);
0427:            }
0428:
0429:            protected void writeType(Type type, Element parent)
0430:                    throws XPDLSerializerException {
0431:
0432:                Element typeElement;
0433:                if (type instanceof  BasicType) {
0434:                    typeElement = Util.addElement(parent, BASIC_TYPE);
0435:                    typeElement.addAttribute(TYPE, type.toString());
0436:                } else if (type instanceof  DeclaredType) {
0437:                    typeElement = Util.addElement(parent, DECLARED_TYPE);
0438:                    typeElement.addAttribute(ID, ((DeclaredType) type).getId());
0439:                } else if (type instanceof  SchemaType) {
0440:                    writeSchemaType((SchemaType) type, parent);
0441:                } else if (type instanceof  ExternalReference) {
0442:                    writeExternalReference((ExternalReference) type, parent);
0443:                } else if (type instanceof  RecordType) {
0444:                    typeElement = Util.addElement(parent, RECORD_TYPE);
0445:                    Element memberElement = Util
0446:                            .addElement(typeElement, MEMBER);
0447:                    RecordType recordType = (RecordType) type;
0448:                    for (int i = 0, n = recordType.getMember().length; i < n; i++)
0449:                        writeType(recordType.getMember(i), memberElement);
0450:                } else if (type instanceof  UnionType) {
0451:                    typeElement = Util.addElement(parent, UNION_TYPE);
0452:                    Element memberElement = Util
0453:                            .addElement(typeElement, MEMBER);
0454:                    UnionType unionType = (UnionType) type;
0455:                    for (int i = 0, n = unionType.getMember().length; i < n; i++)
0456:                        writeType(unionType.getMember(i), memberElement);
0457:                } else if (type instanceof  EnumerationType) {
0458:                    typeElement = Util.addElement(parent, ENUMERATION_TYPE);
0459:                    EnumerationType enumerationType = (EnumerationType) type;
0460:                    for (int i = 0; i < enumerationType.getValue().length; i++) {
0461:                        EnumerationValue value = enumerationType.getValue(i);
0462:                        Util.addElement(typeElement, ENUMERATION_VALUE, value
0463:                                .getName());
0464:                    }
0465:                } else if (type instanceof  ArrayType) {
0466:                    ArrayType arrayType = (ArrayType) type;
0467:                    typeElement = Util.addElement(parent, ARRAY_TYPE);
0468:                    writeType(arrayType.getType(), typeElement);
0469:                    typeElement.addAttribute(LOWER_INDEX, Integer
0470:                            .toString(arrayType.getLowerIndex()));
0471:                    typeElement.addAttribute(UPPER_INDEX, Integer
0472:                            .toString(arrayType.getUpperIndex()));
0473:                } else if (type instanceof  ListType) {
0474:                    typeElement = Util.addElement(parent, LIST_TYPE);
0475:                    writeType(((MultiValuedType) type).getType(), typeElement);
0476:                } else {
0477:                    throw new XPDLSerializerException("Unsupported data type: "
0478:                            + type.getClass().getName());
0479:                }
0480:            }
0481:
0482:            protected void writeSchemaType(SchemaType schemaType, Element parent)
0483:                    throws XPDLSerializerException {
0484:
0485:                try {
0486:                    Element schemaTypeElement = Util.addElement(parent,
0487:                            SCHEMA_TYPE);
0488:                    Util
0489:                            .importFromText(schemaType.getText(),
0490:                                    schemaTypeElement);
0491:                } catch (DocumentException e) {
0492:                    throw new XPDLSerializerException(e);
0493:                }
0494:            }
0495:
0496:            protected void writeWorkflowProcesses(
0497:                    WorkflowProcess[] workflowProcesses, Element parent)
0498:                    throws XPDLSerializerException {
0499:
0500:                if (workflowProcesses == null || workflowProcesses.length == 0)
0501:                    return;
0502:
0503:                Element wpsElement = Util
0504:                        .addElement(parent, WORKFLOW_PROCESSES);
0505:
0506:                for (int i = 0; i < workflowProcesses.length; i++)
0507:                    writeWorkflowProcess(workflowProcesses[i], wpsElement);
0508:            }
0509:
0510:            protected void writeWorkflowProcess(WorkflowProcess wp,
0511:                    Element parent) throws XPDLSerializerException {
0512:
0513:                Element wpElement = Util.addElement(parent, WORKFLOW_PROCESS);
0514:
0515:                wpElement.addAttribute(ID, wp.getId());
0516:                String name = wp.getName();
0517:                if (name != null)
0518:                    wpElement.addAttribute(NAME, name);
0519:                AccessLevel accessLevel = wp.getAccessLevel();
0520:                if (accessLevel != null)
0521:                    wpElement
0522:                            .addAttribute(ACCESS_LEVEL, accessLevel.toString());
0523:
0524:                ProcessHeader processHeader = wp.getProcessHeader();
0525:                if (processHeader == null)
0526:                    throw new ElementRequiredException(
0527:                            XPDLMessages.PROCESS_HEADER_REQUIRED);
0528:                writeProcessHeader(processHeader, wpElement);
0529:                writeRedefinableHeader(wp.getRedefinableHeader(), wpElement);
0530:                writeFormalParameters(wp.getFormalParameter(), wpElement);
0531:                writeDataFields(wp.getDataField(), wpElement);
0532:                writeParticipants(wp.getParticipant(), wpElement);
0533:                writeApplications(wp.getApplication(), wpElement);
0534:                writeActivitySets(wp.getActivitySet(), wpElement);
0535:                writeActivities(wp.getActivity(), wpElement);
0536:                writeTransitions(wp.getTransition(), wpElement);
0537:                writeExtendedAttributes(wp.getExtendedAttributes(), wpElement);
0538:
0539:                // OBE XPDL extensions.
0540:                writeExtendedAttribute(OBE_CALENDAR, wp.getCalendar(),
0541:                        wpElement);
0542:                writeAssignmentStrategy(wp.getAssignmentStrategy(), wpElement);
0543:                writeExtendedAttribute(OBE_COMPLETION_STRATEGY, wp
0544:                        .getCompletionStrategy(), wpElement);
0545:                writeTrigger(wp.getTrigger(), wpElement);
0546:            }
0547:
0548:            protected void writeActivitySets(ActivitySet[] activitySets,
0549:                    Element parent) throws XPDLSerializerException {
0550:
0551:                if (activitySets == null || activitySets.length == 0)
0552:                    return;
0553:
0554:                Element activitySetsElement = Util.addElement(parent,
0555:                        ACTIVITY_SETS);
0556:
0557:                for (int i = 0; i < activitySets.length; i++)
0558:                    writeActivitySet(activitySets[i], activitySetsElement);
0559:            }
0560:
0561:            protected void writeActivitySet(ActivitySet activitySet,
0562:                    Element parent) throws XPDLSerializerException {
0563:
0564:                Element activitySetElement = Util.addElement(parent,
0565:                        ACTIVITY_SET);
0566:
0567:                activitySetElement.addAttribute(ID, activitySet.getId());
0568:
0569:                writeActivities(activitySet.getActivity(), activitySetElement);
0570:                writeTransitions(activitySet.getTransition(),
0571:                        activitySetElement);
0572:            }
0573:
0574:            protected void writeActivities(Activity[] activities, Element parent)
0575:                    throws XPDLSerializerException {
0576:
0577:                if (activities == null || activities.length == 0)
0578:                    return;
0579:
0580:                Element activitiesElement = Util.addElement(parent, ACTIVITIES);
0581:
0582:                for (int i = 0; i < activities.length; i++)
0583:                    writeActivity(activities[i], activitiesElement);
0584:            }
0585:
0586:            protected void writeActivity(Activity activity, Element parent)
0587:                    throws XPDLSerializerException {
0588:
0589:                Element activityElement = Util.addElement(parent, ACTIVITY);
0590:
0591:                activityElement.addAttribute(ID, activity.getId());
0592:                activityElement.addAttribute(NAME, activity.getName());
0593:
0594:                Util.addElement(activityElement, DESCRIPTION, activity
0595:                        .getDescription());
0596:                Util.addElement(activityElement, LIMIT, activity.getLimit());
0597:
0598:                Implementation implementation = activity.getImplementation();
0599:                if (implementation != null) {
0600:                    Element implementationElement = Util.addElement(
0601:                            activityElement, IMPLEMENTATION);
0602:                    if (implementation instanceof  ToolSet) {
0603:                        ToolSet toolSet = (ToolSet) implementation;
0604:                        for (int i = 0, n = toolSet.getTool().length; i < n; i++) {
0605:                            Tool tool = toolSet.getTool(i);
0606:                            Element toolElement = Util.addElement(
0607:                                    implementationElement, TOOL);
0608:                            toolElement.addAttribute(ID, tool.getId());
0609:                            toolElement.addAttribute(TYPE, tool.getToolType()
0610:                                    .toString());
0611:                            writeActualParameters(tool.getActualParameter(),
0612:                                    toolElement);
0613:                            Util.addElement(toolElement, DESCRIPTION, tool
0614:                                    .getDescription());
0615:                            writeExtendedAttributes(tool
0616:                                    .getExtendedAttributes(), toolElement);
0617:                        }
0618:                    } else if (implementation instanceof  SubFlow) {
0619:                        SubFlow subFlow = (SubFlow) implementation;
0620:                        Element subFlowElement = Util.addElement(
0621:                                implementationElement, SUBFLOW);
0622:                        subFlowElement.addAttribute(ID, subFlow.getId());
0623:                        ExecutionType execution = subFlow.getExecution();
0624:                        if (execution != null) {
0625:                            subFlowElement.addAttribute(EXECUTION, execution
0626:                                    .toString());
0627:                        }
0628:                        writeActualParameters(subFlow.getActualParameter(),
0629:                                subFlowElement);
0630:                    } else if (implementation instanceof  NoImplementation) {
0631:                        Util.addElement(implementationElement, NO);
0632:                    } else {
0633:                        throw new XPDLSerializerException(
0634:                                "Unknown implementation type: "
0635:                                        + implementation.getClass());
0636:                    }
0637:                }
0638:
0639:                Route route = activity.getRoute();
0640:                if (route != null) {
0641:                    if (implementation != null) {
0642:                        throw new XPDLSerializerException(
0643:                                "Activity cannot contain both a route and an implementation");
0644:                    }
0645:
0646:                    Util.addElement(activityElement, ROUTE);
0647:                }
0648:
0649:                BlockActivity blockActivity = activity.getBlockActivity();
0650:                if (blockActivity != null) {
0651:                    if (implementation != null || route != null) {
0652:                        throw new XPDLSerializerException(
0653:                                "Activity cannot contain a route or an implementation as well as a BlockActivity");
0654:                    }
0655:
0656:                    Element baElement = activityElement
0657:                            .addElement(BLOCKACTIVITY);
0658:                    baElement.addAttribute(BLOCKID, blockActivity.getBlockId());
0659:                }
0660:
0661:                Util.addElement(activityElement, PERFORMER, activity
0662:                        .getPerformer());
0663:
0664:                AutomationMode startMode = activity.getStartMode();
0665:                if (startMode != null) {
0666:                    Element startModeElement = Util.addElement(activityElement,
0667:                            START_MODE);
0668:                    Util.addElement(startModeElement,
0669:                            startMode == AutomationMode.MANUAL ? MANUAL
0670:                                    : AUTOMATIC);
0671:                }
0672:
0673:                AutomationMode finishMode = activity.getFinishMode();
0674:                if (finishMode != null) {
0675:                    Element finishModeElement = Util.addElement(
0676:                            activityElement, FINISH_MODE);
0677:                    Util.addElement(finishModeElement,
0678:                            finishMode == AutomationMode.MANUAL ? MANUAL
0679:                                    : AUTOMATIC);
0680:                }
0681:
0682:                Util.addElement(activityElement, PRIORITY, activity
0683:                        .getPriority());
0684:
0685:                writeDeadlines(activity.getDeadline(), activityElement);
0686:                writeSimulationInformation(activity.getSimulationInformation(),
0687:                        activityElement);
0688:
0689:                Util.addElement(activityElement, ICON, activity.getIcon());
0690:                Util.addElement(activityElement, DOCUMENTATION, activity
0691:                        .getDocumentation());
0692:
0693:                writeTransitionRestrictions(
0694:                        activity.getTransitionRestriction(), activityElement);
0695:                writeExtendedAttributes(activity.getExtendedAttributes(),
0696:                        activityElement);
0697:
0698:                // OBE XPDL extensions.
0699:                writeAssignmentStrategy(activity.getAssignmentStrategy(),
0700:                        activityElement);
0701:                writeBounds(activity.getBounds(), activityElement);
0702:                writeExtendedAttribute(OBE_CALENDAR, activity.getCalendar(),
0703:                        activityElement);
0704:                writeExtendedAttribute(OBE_COMPLETION_STRATEGY, activity
0705:                        .getCompletionStrategy(), activityElement);
0706:                writeExtendedAttribute(OBE_TOOL_MODE, activity.getToolMode(),
0707:                        activityElement);
0708:                if (blockActivity != null)
0709:                    writeLoop(blockActivity.getLoop(), activityElement);
0710:            }
0711:
0712:            protected void writeBounds(Rectangle bounds, Element parent) {
0713:                if (bounds == null)
0714:                    return;
0715:
0716:                // For now, our parent element must be an ExtendedAttribute.
0717:                // Check whether the ExtendedAttributes element is already present.
0718:                // If not, add it now.
0719:                Element extAttrsElem = getExtendedAttributes(parent);
0720:                parent = Util.addElement(extAttrsElem, EXTENDED_ATTRIBUTE);
0721:                parent.addAttribute(NAME, OBE_BOUNDS);
0722:
0723:                Element boundsElement = parent.addElement(BOUNDS_QNAME);
0724:                boundsElement.addAttribute(X, String.valueOf(bounds.x));
0725:                boundsElement.addAttribute(Y, String.valueOf(bounds.y));
0726:                boundsElement.addAttribute(WIDTH, String.valueOf(bounds.width));
0727:                boundsElement.addAttribute(HEIGHT, String
0728:                        .valueOf(bounds.height));
0729:            }
0730:
0731:            protected void writeAssignmentStrategy(
0732:                    AssignmentStrategyDef strategy, Element parent) {
0733:
0734:                if (strategy == null)
0735:                    return;
0736:
0737:                // For now, our parent element must be an ExtendedAttribute.
0738:                // Check whether the ExtendedAttributes element is already present.
0739:                // If not, add it now.
0740:                Element extAttrsElem = getExtendedAttributes(parent);
0741:                parent = Util.addElement(extAttrsElem, EXTENDED_ATTRIBUTE);
0742:                parent.addAttribute(NAME, OBE_ASSIGNMENT_STRATEGY);
0743:
0744:                Element strategyElement = parent
0745:                        .addElement(ASSIGNMENT_STRATEGY_QNAME);
0746:                strategyElement.addAttribute(ID, strategy.getId());
0747:                strategyElement.addAttribute(EXPAND_GROUPS, String
0748:                        .valueOf(strategy.getExpandGroups()));
0749:            }
0750:
0751:            // This is an unused method that was an experiment in allowing repository
0752:            // metadata to be embedded in XPDL.
0753:            protected void writeMetaData(/*AbstractMetaData*/Object metadata,
0754:                    Element parent) {
0755:
0756:                if (metadata == null)
0757:                    return;
0758:
0759:                /*
0760:                 // For now, our parent element must be an ExtendedAttribute.
0761:                 // Check whether the ExtendedAttributes element is already present.
0762:                 // If not, add it now.
0763:                 Element extAttrsElem = getExtendedAttributes(parent);
0764:                 parent = Util.addElement(extAttrsElem, EXTENDED_ATTRIBUTE);
0765:                 parent.addAttribute(NAME, OBE_META_DATA);
0766:                 Element metaDataElement = parent.addElement(META_DATA_QNAME);
0767:
0768:                 // Marshall the *MetaData object into the meta-data element.
0769:                 Marshaller marshaller = new Marshaller(metaDataElement);
0770:                 marshaller.setMapping(mapping);
0771:                 //        marshaller.setRootElement("repository");
0772:                 //        if (getLogger().isDebugEnabled() && OBEConfig.isVerbose()) {
0773:                 //            marshaller.setMarshalListener(new MarshalListener() {
0774:                 //                public boolean preMarshal(Object obj) {
0775:                 //                    getLogger().debug("preMarshal(\"" + obj + "\")");
0776:                 //                    return true;
0777:                 //                }
0778:                 //
0779:                 //                public void postMarshal(Object obj) {
0780:                 //                    getLogger().debug("postMarshal(\"" + obj + "\")");
0781:                 //                }
0782:                 //            });
0783:                 //        }
0784:                 marshaller.marshal(metadata);
0785:                 */
0786:            }
0787:
0788:            protected void writeLoop(Loop loop, Element parent) {
0789:                if (loop == null)
0790:                    return;
0791:
0792:                // For now, our parent element must be an ExtendedAttribute.
0793:                // Check whether the ExtendedAttributes element is already present.
0794:                // If not, add it now.
0795:                Element extAttrsElem = getExtendedAttributes(parent);
0796:                parent = Util.addElement(extAttrsElem, EXTENDED_ATTRIBUTE);
0797:                parent.addAttribute(NAME, OBE_LOOP);
0798:
0799:                Element loopElement = parent.addElement(LOOP_QNAME);
0800:                LoopBody body = loop.getBody();
0801:                if (body instanceof  ForEach) {
0802:                    ForEach forEach = (ForEach) body;
0803:                    Element forEachElement = loopElement
0804:                            .addElement(FOREACH_QNAME);
0805:                    forEachElement.addAttribute(DATA_FIELD, forEach
0806:                            .getDataField());
0807:                    Element inElement = forEachElement.addElement(IN_QNAME);
0808:                    inElement.addText(forEach.getExpr());
0809:                } else if (body instanceof  Until) {
0810:                    Element untilElement = loopElement.addElement(UNTIL_QNAME);
0811:                    writeCondition(((Until) body).getCondition(), untilElement);
0812:                } else if (body instanceof  While) {
0813:                    Element whileElement = loopElement.addElement(WHILE_QNAME);
0814:                    writeCondition(((While) body).getCondition(), whileElement);
0815:                }
0816:            }
0817:
0818:            protected void writeTransitions(Transition[] transitions,
0819:                    Element parent) throws XPDLSerializerException {
0820:
0821:                if (transitions == null || transitions.length == 0)
0822:                    return;
0823:
0824:                Element transitionsElement = Util.addElement(parent,
0825:                        TRANSITIONS);
0826:
0827:                for (int i = 0; i < transitions.length; i++)
0828:                    writeTransition(transitions[i], transitionsElement);
0829:            }
0830:
0831:            protected void writeTransition(Transition transition, Element parent)
0832:                    throws XPDLSerializerException {
0833:
0834:                Element transitionElement = Util.addElement(parent, TRANSITION);
0835:
0836:                transitionElement.addAttribute(ID, transition.getId());
0837:                transitionElement.addAttribute(FROM, transition.getFrom());
0838:                transitionElement.addAttribute(TO, transition.getTo());
0839:
0840:                if (transition.getName() != null)
0841:                    transitionElement.addAttribute(NAME, transition.getName());
0842:
0843:                writeCondition(transition.getCondition(), transitionElement);
0844:
0845:                if (transition.getDescription() != null) {
0846:                    Util.addElement(transitionElement, DESCRIPTION, transition
0847:                            .getDescription());
0848:                }
0849:
0850:                writeExtendedAttributes(transition.getExtendedAttributes(),
0851:                        transitionElement);
0852:
0853:                // OBE XPDL extensions.
0854:                writeTrigger(transition.getEvent(), transitionElement);
0855:                writeExecutionType(transition.getExecution(), transitionElement);
0856:            }
0857:
0858:            protected void writeTrigger(Trigger trigger, Element parent)
0859:                    throws XPDLSerializerException {
0860:
0861:                if (trigger == null)
0862:                    return;
0863:
0864:                // For now, our parent element must be an ExtendedAttribute.
0865:                // Check whether the ExtendedAttributes element is already present.
0866:                // If not, add it now.
0867:                Element extendedAttributesElement = parent
0868:                        .element(EXTENDED_ATTRIBUTES);
0869:                if (extendedAttributesElement == null) {
0870:                    extendedAttributesElement = Util.addElement(parent,
0871:                            EXTENDED_ATTRIBUTES);
0872:                }
0873:                parent = Util.addElement(extendedAttributesElement,
0874:                        EXTENDED_ATTRIBUTE);
0875:
0876:                Element triggerElement;
0877:                if (trigger instanceof  Event) {
0878:                    triggerElement = writeEvent((Event) trigger, parent);
0879:                } else if (trigger instanceof  Timer) {
0880:                    triggerElement = writeTimer((Timer) trigger, parent);
0881:                } else {
0882:                    throw new IllegalArgumentException(
0883:                            "Unsupported trigger type: " + trigger);
0884:                }
0885:                triggerElement.addAttribute(ID, trigger.getId());
0886:                writeActualParameters(trigger.getActualParameter(),
0887:                        triggerElement);
0888:            }
0889:
0890:            protected Element writeEvent(Event event, Element parent) {
0891:                parent.addAttribute(NAME, OBE_EVENT);
0892:                Element eventElement = parent.addElement(EVENT_QNAME);
0893:                if (event.getPredicate() != null)
0894:                    eventElement.addAttribute(PREDICATE, event.getPredicate());
0895:                return eventElement;
0896:            }
0897:
0898:            protected Element writeTimer(Timer timer, Element parent) {
0899:                parent.addAttribute(NAME, OBE_TIMER);
0900:                Element timerElement = parent.addElement(TIMER_QNAME);
0901:                if (timer.getInterval() != null) {
0902:                    timerElement.addAttribute(INTERVAL, timer.getInterval()
0903:                            .toString());
0904:                }
0905:                if (timer.getCalendar() != null)
0906:                    timerElement.addAttribute(CALENDAR, timer.getCalendar());
0907:                if (timer.isRecoverable()) {
0908:                    timerElement.addAttribute(RECOVERABLE, String.valueOf(timer
0909:                            .isRecoverable()));
0910:                }
0911:                return timerElement;
0912:            }
0913:
0914:            protected void writeExecutionType(ExecutionType execType,
0915:                    Element parent) throws XPDLSerializerException {
0916:
0917:                if (execType == null)
0918:                    return;
0919:
0920:                // For now, our parent element must be an ExtendedAttribute.
0921:                // Check whether the ExtendedAttributes element is already present.
0922:                // If not, add it now.
0923:                Element extendedAttributesElement = parent
0924:                        .element(EXTENDED_ATTRIBUTES);
0925:                if (extendedAttributesElement == null) {
0926:                    extendedAttributesElement = Util.addElement(parent,
0927:                            EXTENDED_ATTRIBUTES);
0928:                }
0929:                parent = Util.addElement(extendedAttributesElement,
0930:                        EXTENDED_ATTRIBUTE);
0931:                parent.addAttribute(NAME, EXECUTION);
0932:                parent.addAttribute(VALUE, execType.toString());
0933:            }
0934:
0935:            protected void writeTransitionRestrictions(
0936:                    TransitionRestriction[] transitionRestrictions,
0937:                    Element parent) {
0938:
0939:                if (transitionRestrictions == null
0940:                        || transitionRestrictions.length == 0) {
0941:
0942:                    return;
0943:                }
0944:
0945:                Element transitionRestrictionsElement = Util.addElement(parent,
0946:                        TRANSITION_RESTRICTIONS);
0947:
0948:                for (int i = 0; i < transitionRestrictions.length; i++) {
0949:                    writeTransitionRestriction(transitionRestrictions[i],
0950:                            transitionRestrictionsElement);
0951:                }
0952:            }
0953:
0954:            protected void writeTransitionRestriction(
0955:                    TransitionRestriction transitionRestriction, Element parent) {
0956:                Element transitionRestrictionElement = Util.addElement(parent,
0957:                        TRANSITION_RESTRICTION);
0958:                writeJoin(transitionRestriction.getJoin(),
0959:                        transitionRestrictionElement);
0960:                writeSplit(transitionRestriction.getSplit(),
0961:                        transitionRestrictionElement);
0962:            }
0963:
0964:            protected void writeJoin(Join join, Element parent) {
0965:                if (join == null)
0966:                    return;
0967:
0968:                Element joinElement = Util.addElement(parent, JOIN);
0969:
0970:                JoinType joinType = join.getType();
0971:                if (joinType != null)
0972:                    joinElement.addAttribute(TYPE, joinType.toString());
0973:            }
0974:
0975:            protected void writeSplit(Split split, Element parent) {
0976:                if (split == null)
0977:                    return;
0978:
0979:                Element splitElement = Util.addElement(parent, SPLIT);
0980:
0981:                SplitType splitType = split.getType();
0982:                if (splitType != null)
0983:                    splitElement.addAttribute(TYPE, splitType.toString());
0984:
0985:                writeTransitionReferences(split.getTransitionReference(),
0986:                        splitElement);
0987:            }
0988:
0989:            protected void writeTransitionReferences(
0990:                    String[] transitionReferences, Element parent) {
0991:
0992:                if (transitionReferences == null
0993:                        || transitionReferences.length == 0)
0994:                    return;
0995:
0996:                Element transitionReferencesElement = Util.addElement(parent,
0997:                        TRANSITION_REFERENCES);
0998:
0999:                for (int i = 0; i < transitionReferences.length; i++) {
1000:                    Element transitionRefElement = Util.addElement(
1001:                            transitionReferencesElement, TRANSITION_REFERENCE);
1002:
1003:                    transitionRefElement.addAttribute(ID,
1004:                            transitionReferences[i]);
1005:                }
1006:            }
1007:
1008:            protected void writeProcessHeader(ProcessHeader header,
1009:                    Element parent) {
1010:                Element headerElement = Util.addElement(parent, PROCESS_HEADER);
1011:
1012:                DurationUnit durationUnit = header.getDurationUnit();
1013:                if (durationUnit != null)
1014:                    headerElement.addAttribute(DURATION_UNIT, durationUnit
1015:                            .toString());
1016:
1017:                Util.addElement(headerElement, CREATED, header.getCreated());
1018:                Util.addElement(headerElement, DESCRIPTION, header
1019:                        .getDescription());
1020:                Util.addElement(headerElement, PRIORITY, header.getPriority());
1021:                Util.addElement(headerElement, LIMIT, header.getLimit());
1022:                Util.addElement(headerElement, VALID_FROM, header
1023:                        .getValidFrom());
1024:                Util.addElement(headerElement, VALID_TO, header.getValidTo());
1025:                writeTimeEstimation(header.getTimeEstimation(), headerElement);
1026:            }
1027:
1028:            protected void writeDeadlines(Deadline[] deadlines, Element parent) {
1029:                if (deadlines == null || deadlines.length == 0) {
1030:                    _logger.debug("No Deadlines found");
1031:                    return;
1032:                }
1033:
1034:                for (int i = 0; i < deadlines.length; i++)
1035:                    writeDeadline(deadlines[i], parent);
1036:            }
1037:
1038:            protected void writeDeadline(Deadline deadline, Element parent) {
1039:                if (deadline == null) {
1040:                    _logger.debug("No Deadline found");
1041:                    return;
1042:                }
1043:
1044:                _logger.debug("Writing Deadline element");
1045:                Element deadlineElement = Util.addElement(parent, DEADLINE);
1046:                deadlineElement.addAttribute(EXECUTION, deadline
1047:                        .getExecutionType().toString());
1048:
1049:                Util.addElement(deadlineElement, DEADLINE_CONDITION, deadline
1050:                        .getDeadlineCondition());
1051:                Util.addElement(deadlineElement, EXCEPTION_NAME, deadline
1052:                        .getExceptionName());
1053:            }
1054:
1055:            protected void writeTimeEstimation(TimeEstimation timeEstimation,
1056:                    Element parent) {
1057:
1058:                if (timeEstimation == null)
1059:                    return;
1060:
1061:                Element timeEstimationElement = Util.addElement(parent,
1062:                        TIME_ESTIMATION);
1063:                Util.addElement(timeEstimationElement, WAITING_TIME,
1064:                        timeEstimation.getWaitingTime());
1065:                Util.addElement(timeEstimationElement, WORKING_TIME,
1066:                        timeEstimation.getWorkingTime());
1067:                Util.addElement(timeEstimationElement, DURATION, timeEstimation
1068:                        .getDuration());
1069:            }
1070:
1071:            protected void writeSimulationInformation(
1072:                    SimulationInformation simulationInfo, Element parent) {
1073:
1074:                if (simulationInfo == null)
1075:                    return;
1076:
1077:                Element simulationInfoElement = Util.addElement(parent,
1078:                        SIMULATION_INFORMATION);
1079:
1080:                Util.addElement(simulationInfoElement, COST, simulationInfo
1081:                        .getCost());
1082:
1083:                writeTimeEstimation(simulationInfo.getTimeEstimation(),
1084:                        simulationInfoElement);
1085:            }
1086:
1087:            protected void writeCondition(Condition condition, Element parent) {
1088:                if (condition == null)
1089:                    return;
1090:
1091:                Element conditionElement = parent.addElement(CONDITION);
1092:                ConditionType type = condition.getType();
1093:                if (type != null)
1094:                    conditionElement.addAttribute(TYPE, type.toString());
1095:                if (condition.getValue() != null)
1096:                    conditionElement.addText(condition.getValue());
1097:                for (int i = 0, n = condition.getXpression().length; i < n; i++) {
1098:                    Xpression xpression = condition.getXpression(i);
1099:                    Util.addElement(conditionElement, XPRESSION, xpression
1100:                            .getValue());
1101:                }
1102:            }
1103:
1104:            protected void writeExtendedAttributes(ExtendedAttributes extAttrs,
1105:                    Element parent) throws XPDLSerializerException {
1106:
1107:                if (extAttrs == null)
1108:                    return;
1109:
1110:                try {
1111:                    Util.importFromText(extAttrs.getText(), parent);
1112:                } catch (DocumentException e) {
1113:                    throw new XPDLSerializerException(e);
1114:                }
1115:            }
1116:
1117:            protected void writeFormalParameters(
1118:                    FormalParameter[] formalParameters, Element parent)
1119:                    throws XPDLSerializerException {
1120:
1121:                if (formalParameters == null || formalParameters.length == 0)
1122:                    return;
1123:
1124:                Element formalParametersElement = parent
1125:                        .addElement(FORMAL_PARAMETERS);
1126:                for (int i = 0; i < formalParameters.length; i++) {
1127:                    FormalParameter formalParameter = formalParameters[i];
1128:                    Element formalParameterElement = Util.addElement(
1129:                            formalParametersElement, FORMAL_PARAMETER);
1130:
1131:                    formalParameterElement.addAttribute(ID, formalParameter
1132:                            .getId());
1133:                    if (formalParameter.getIndex() != null) {
1134:                        formalParameterElement.addAttribute(INDEX,
1135:                                formalParameter.getIndex().toString());
1136:                    }
1137:                    if (formalParameter.getMode() != null) {
1138:                        formalParameterElement.addAttribute(MODE,
1139:                                formalParameter.getMode().toString());
1140:                    }
1141:
1142:                    writeType(formalParameter.getDataType().getType(), Util
1143:                            .addElement(formalParameterElement, DATA_TYPE));
1144:
1145:                    Util.addElement(formalParameterElement, DESCRIPTION,
1146:                            formalParameter.getDescription());
1147:                }
1148:            }
1149:
1150:            protected void writeActualParameters(
1151:                    ActualParameter[] actualParameters, Element parent)
1152:                    throws XPDLSerializerException {
1153:
1154:                if (actualParameters == null || actualParameters.length == 0)
1155:                    return;
1156:
1157:                Element actualParametersElement = Util.addElement(parent,
1158:                        ACTUAL_PARAMETERS);
1159:                for (int i = 0; i < actualParameters.length; i++) {
1160:                    Util.addElement(actualParametersElement, ACTUAL_PARAMETER,
1161:                            actualParameters[i].getText());
1162:                }
1163:            }
1164:
1165:            protected void writeExternalReference(
1166:                    ExternalReference externalReference, Element parent)
1167:                    throws XPDLSerializerException {
1168:
1169:                if (externalReference == null)
1170:                    return;
1171:
1172:                Element element = parent.addElement(EXTERNAL_REFERENCE);
1173:                element.addAttribute(LOCATION, externalReference.getLocation());
1174:                String xref = externalReference.getXref();
1175:                if (xref != null)
1176:                    element.addAttribute(XREF, xref);
1177:                String namespace = externalReference.getNamespace();
1178:                if (namespace != null)
1179:                    element.addAttribute(NAMESPACE, namespace);
1180:            }
1181:
1182:            protected Element getExtendedAttributes(Element parent) {
1183:                // Check whether the ExtendedAttributes element is already present.
1184:                // If not, add it now.
1185:                Element extAttrsElem = parent.element(EXTENDED_ATTRIBUTES);
1186:                if (extAttrsElem == null)
1187:                    extAttrsElem = Util.addElement(parent, EXTENDED_ATTRIBUTES);
1188:                return extAttrsElem;
1189:            }
1190:
1191:            protected void writeExtendedAttribute(String name, Object value,
1192:                    Element parent) {
1193:
1194:                if (value == null)
1195:                    return;
1196:
1197:                // For now, our parent element must be an ExtendedAttribute.
1198:                Element extAttrElem = Util.addElement(
1199:                        getExtendedAttributes(parent), EXTENDED_ATTRIBUTE);
1200:                extAttrElem.addAttribute(NAME, name);
1201:                extAttrElem.addAttribute(VALUE, value.toString());
1202:            }
1203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.