Source Code Cross Referenced for Dom4JXPDLParser.java in  » Workflow-Engines » obe-1.0 » org » obe » xpdl » parser » 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.parser.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.parser.dom4j;
0046:
0047:        import org.apache.commons.logging.Log;
0048:        import org.apache.commons.logging.LogFactory;
0049:        import org.dom4j.*;
0050:        import org.dom4j.io.SAXReader;
0051:        import org.obe.XMLException;
0052:        import org.obe.xpdl.XPDLMessages;
0053:        import org.obe.xpdl.model.activity.*;
0054:        import org.obe.xpdl.model.application.Application;
0055:        import org.obe.xpdl.model.condition.Condition;
0056:        import org.obe.xpdl.model.condition.ConditionType;
0057:        import org.obe.xpdl.model.condition.Xpression;
0058:        import org.obe.xpdl.model.data.*;
0059:        import org.obe.xpdl.model.ext.*;
0060:        import org.obe.xpdl.model.ext.Event;
0061:        import org.obe.xpdl.model.misc.*;
0062:        import org.obe.xpdl.model.participant.Participant;
0063:        import org.obe.xpdl.model.participant.ParticipantType;
0064:        import org.obe.xpdl.model.pkg.ExternalPackage;
0065:        import org.obe.xpdl.model.pkg.PackageHeader;
0066:        import org.obe.xpdl.model.pkg.XPDLPackage;
0067:        import org.obe.xpdl.model.transition.*;
0068:        import org.obe.xpdl.model.workflow.ProcessHeader;
0069:        import org.obe.xpdl.model.workflow.WorkflowProcess;
0070:        import org.obe.xpdl.parser.ElementRequiredException;
0071:        import org.obe.xpdl.parser.XPDLParser;
0072:        import org.obe.xpdl.parser.XPDLParserException;
0073:        import org.xml.sax.EntityResolver;
0074:
0075:        import java.awt.*;
0076:        import java.beans.PropertyVetoException;
0077:        import java.io.IOException;
0078:        import java.io.InputStream;
0079:        import java.io.InputStreamReader;
0080:        import java.io.Reader;
0081:        import java.net.URL;
0082:        import java.util.HashMap;
0083:        import java.util.Iterator;
0084:        import java.util.List;
0085:        import java.util.Map;
0086:
0087:        /**
0088:         * An implementation of the XPDLParser interface, using DOM4J.
0089:         *
0090:         * @author Anthony Eden
0091:         * @author Adrian Price
0092:         */
0093:        public class Dom4JXPDLParser implements  XPDLParser, DOM4JNames {
0094:            private static Log _logger = LogFactory
0095:                    .getLog(Dom4JXPDLParser.class);
0096:
0097:            private static final DurationUnit defaultDurationUnit = DurationUnit.MINUTE;
0098:            private static final InstantiationType defaultInstantiationType = InstantiationType.ONCE;
0099:            private static final int DEFAULT_WIDTH = 140;
0100:            private static final int DEFAULT_HEIGHT = 50;
0101:            private EntityResolver entityResolver;
0102:            private static final String MSG_CREATED = "Created ";
0103:            private static final String APPLICATIONS_LOADED = " applications loaded";
0104:            private static final String IMPL_ROUTE_MUTEX = "Implementation and route element cannot be ";
0105:
0106:            /**
0107:             * Construct a new Dom4JXPDLParser.
0108:             */
0109:            public Dom4JXPDLParser() {
0110:            }
0111:
0112:            public Dom4JXPDLParser(EntityResolver entityResolver) {
0113:                this .entityResolver = entityResolver;
0114:            }
0115:
0116:            public XPDLPackage parse(InputStream in) throws IOException,
0117:                    XPDLParserException {
0118:
0119:                return parse(new InputStreamReader(in));
0120:            }
0121:
0122:            /**
0123:             * Parse the XPDL document which is provided by the given InputStream.
0124:             *
0125:             * @param in The XPDL character stream
0126:             * @return The Workflow Package
0127:             * @throws IOException         Any I/O Exception
0128:             * @throws XPDLParserException Any parser exception
0129:             */
0130:            public XPDLPackage parse(Reader in) throws IOException,
0131:                    XPDLParserException {
0132:                try {
0133:                    DocumentFactory docFactory = DocumentFactory.getInstance();
0134:                    SAXReader reader = new SAXReader(docFactory);
0135:                    if (entityResolver != null) {
0136:                        //                reader.getXMLReader().setProperty(, );
0137:                        reader.setEntityResolver(entityResolver);
0138:                        reader.setValidation(true);
0139:                    }
0140:                    Document document = reader.read(in);
0141:
0142:                    Element packageElement = document.getRootElement();
0143:
0144:                    // load the package header
0145:                    PackageHeader packageHeader = createPackageHeader(Util
0146:                            .child(packageElement, PACKAGE_HEADER));
0147:
0148:                    // construct the XPDLPackage
0149:                    XPDLPackage pkg = new XPDLPackage(packageElement
0150:                            .attributeValue(ID), packageElement
0151:                            .attributeValue(NAME), packageHeader);
0152:
0153:                    // Load the XML namespace declarations.
0154:                    Map pkgNamespaces = pkg.getNamespaces();
0155:                    List namespaces = packageElement.declaredNamespaces();
0156:                    for (int i = 0; i < namespaces.size(); i++) {
0157:                        Namespace ns = (Namespace) namespaces.get(i);
0158:                        String prefix = ns.getPrefix();
0159:                        if (prefix != null && prefix.length() != 0)
0160:                            pkgNamespaces.put(prefix, ns.getURI());
0161:                    }
0162:
0163:                    // load the redefinable header
0164:                    pkg.setRedefinableHeader(createRedefinableHeader(Util
0165:                            .child(packageElement, REDEFINABLE_HEADER)));
0166:
0167:                    // load the conformance class
0168:                    pkg.setConformanceClass(createConformanceClass(Util.child(
0169:                            packageElement, CONFORMANCE_CLASS)));
0170:
0171:                    pkg.setScript(createScript(Util.child(packageElement,
0172:                            SCRIPT)));
0173:
0174:                    loadExternalPackages(pkg, Util.child(packageElement,
0175:                            EXTERNAL_PACKAGES));
0176:
0177:                    loadTypeDeclarations(pkg, Util.child(packageElement,
0178:                            TYPE_DECLARATIONS));
0179:
0180:                    loadParticipants(pkg, Util.child(packageElement,
0181:                            PARTICIPANTS));
0182:
0183:                    loadApplications(pkg, Util.child(packageElement,
0184:                            APPLICATIONS));
0185:
0186:                    loadDataFields(pkg, Util.child(packageElement, DATA_FIELDS));
0187:
0188:                    loadWorkflowProcesses(pkg, Util.child(packageElement,
0189:                            WORKFLOW_PROCESSES));
0190:
0191:                    Map extAttrs = new HashMap();
0192:                    pkg.setExtendedAttributes(loadExtendedAttributes(
0193:                            packageElement, extAttrs));
0194:
0195:                    pkg.setCalendar((String) extAttrs.get(OBE_CALENDAR));
0196:
0197:                    pkg.setAssignmentStrategy((AssignmentStrategyDef) extAttrs
0198:                            .get(OBE_ASSIGNMENT_STRATEGY));
0199:
0200:                    pkg.setCompletionStrategy((String) extAttrs
0201:                            .get(OBE_COMPLETION_STRATEGY));
0202:
0203:                    return pkg;
0204:                } catch (DocumentException e) {
0205:                    throw new XPDLParserException(
0206:                            XPDLMessages.ERROR_PARSING_DOCUMENT, e);
0207:                } catch (PropertyVetoException e) {
0208:                    throw new XPDLParserException(
0209:                            XPDLMessages.ERROR_PARSING_DOCUMENT, e);
0210:                }
0211:            }
0212:
0213:            // Header-related configuration
0214:
0215:            /**
0216:             * Create the package header from the given element.  This method will throw
0217:             * an XPDLParserException if the XPDLPackage header element is null.
0218:             *
0219:             * @param element The package header element
0220:             * @throws XPDLParserException Thrown if the element is null
0221:             */
0222:            protected PackageHeader createPackageHeader(Element element)
0223:                    throws XPDLParserException {
0224:
0225:                if (element == null) {
0226:                    throw new ElementRequiredException(PACKAGE_HEADER,
0227:                            "Package header required but not found");
0228:                }
0229:
0230:                PackageHeader packageHeader = new PackageHeader();
0231:                packageHeader.setXPDLVersion(Util.elementAsString(element,
0232:                        XPDL_VERSION));
0233:                packageHeader.setVendor(Util.elementAsString(element, VENDOR));
0234:                packageHeader.setCreated(Util.elementAsDate(element, CREATED));
0235:                packageHeader.setDescription(Util.elementAsString(element,
0236:                        DESCRIPTION));
0237:                packageHeader.setDocumentation(Util.elementAsURL(element,
0238:                        DOCUMENTATION));
0239:                packageHeader.setPriorityUnit(Util.elementAsString(element,
0240:                        PRIORITY_UNIT));
0241:                packageHeader.setCostUnit(Util.elementAsString(element,
0242:                        COST_UNIT));
0243:
0244:                if (_logger.isDebugEnabled())
0245:                    _logger.debug(MSG_CREATED + packageHeader);
0246:
0247:                return packageHeader;
0248:            }
0249:
0250:            protected RedefinableHeader createRedefinableHeader(Element element)
0251:                    throws XPDLParserException, PropertyVetoException {
0252:
0253:                if (element == null) {
0254:                    _logger.debug("Redefinable header not found");
0255:                    return null;
0256:                }
0257:
0258:                RedefinableHeader redefinableHeader = new RedefinableHeader();
0259:                redefinableHeader.setAuthor(Util.elementAsString(element,
0260:                        AUTHOR));
0261:                redefinableHeader.setVersion(Util.elementAsString(element,
0262:                        VERSION));
0263:                redefinableHeader.setCodepage(Util.elementAsString(element,
0264:                        CODEPAGE));
0265:                redefinableHeader.setCountrykey(Util.elementAsString(element,
0266:                        COUNTRYKEY));
0267:
0268:                String pubStatusString = element
0269:                        .attributeValue(PUBLICATION_STATUS);
0270:                if (pubStatusString != null) {
0271:                    PublicationStatus publicationStatus = PublicationStatus
0272:                            .valueOf(pubStatusString);
0273:                    redefinableHeader.setPublicationStatus(publicationStatus);
0274:                }
0275:
0276:                loadResponsibles(redefinableHeader, Util.child(element,
0277:                        RESPONSIBLES));
0278:
0279:                if (_logger.isDebugEnabled())
0280:                    _logger.debug(MSG_CREATED + redefinableHeader);
0281:
0282:                return redefinableHeader;
0283:            }
0284:
0285:            /**
0286:             * Create a ConformanceClass object from the given element.
0287:             *
0288:             * @param element The ConformanceClass element
0289:             * @throws XPDLParserException Any parser exception
0290:             */
0291:            protected ConformanceClass createConformanceClass(Element element)
0292:                    throws XPDLParserException {
0293:
0294:                if (element == null) {
0295:                    _logger.debug("Conformance class header not found");
0296:                    return null;
0297:                }
0298:
0299:                ConformanceClass cc = new ConformanceClass();
0300:                GraphConformance gc = GraphConformance.valueOf(element
0301:                        .attributeValue(GRAPH_CONFORMANCE));
0302:                cc.setGraphConformance(gc);
0303:
0304:                if (_logger.isDebugEnabled())
0305:                    _logger.debug(MSG_CREATED + cc);
0306:
0307:                return cc;
0308:            }
0309:
0310:            /**
0311:             * Create a Script object from the given Element.
0312:             *
0313:             * @param element The Element
0314:             * @return the Script object
0315:             * @throws XPDLParserException
0316:             */
0317:            protected Script createScript(Element element)
0318:                    throws XPDLParserException {
0319:                if (element == null) {
0320:                    _logger.debug("Script not found");
0321:                    return null;
0322:                }
0323:
0324:                Script script = new Script(element.attributeValue(TYPE));
0325:
0326:                script.setVersion(element.attributeValue(VERSION));
0327:                script.setGrammar(element.attributeValue(GRAMMAR));
0328:
0329:                if (_logger.isDebugEnabled())
0330:                    _logger.debug(MSG_CREATED + script);
0331:
0332:                return script;
0333:            }
0334:
0335:            // External Packages
0336:
0337:            protected void loadExternalPackages(XPDLPackage pkg, Element element)
0338:                    throws XPDLParserException, PropertyVetoException {
0339:
0340:                if (element == null)
0341:                    return;
0342:
0343:                loadExternalPackages(pkg, Util.children(element,
0344:                        EXTERNAL_PACKAGE));
0345:            }
0346:
0347:            protected void loadExternalPackages(XPDLPackage pkg, List elements)
0348:                    throws XPDLParserException, PropertyVetoException {
0349:
0350:                Iterator iter = elements.iterator();
0351:                while (iter.hasNext()) {
0352:                    try {
0353:                        Element extPkgElem = (Element) iter.next();
0354:                        createExternalPackage(pkg, extPkgElem);
0355:                    } catch (XPDLParserException e) {
0356:                        _logger.error("Error loading external package", e);
0357:                    }
0358:                }
0359:
0360:                if (pkg.getExternalPackage().length == 0) {
0361:                    _logger
0362:                            .debug("External packages element present but no external packages found");
0363:                }
0364:            }
0365:
0366:            protected void createExternalPackage(XPDLPackage pkg,
0367:                    Element element) throws XPDLParserException,
0368:                    PropertyVetoException {
0369:
0370:                String href = element.attributeValue(HREF);
0371:                _logger.debug("Loading external package from " + href);
0372:
0373:                XPDLPackage p;
0374:                try {
0375:                    p = parse(new URL(href).openStream());
0376:                    _logger.debug("Loaded external package " + p.getId());
0377:                } catch (IOException e) {
0378:                    throw new XPDLParserException(
0379:                            "Error loading external package " + href, e);
0380:                }
0381:
0382:                ExternalPackage extPkg = new ExternalPackage(href, p);
0383:                extPkg.setExtendedAttributes(loadExtendedAttributes(null,
0384:                        element));
0385:
0386:                if (_logger.isDebugEnabled())
0387:                    _logger.debug(MSG_CREATED + extPkg);
0388:
0389:                pkg.add(extPkg);
0390:            }
0391:
0392:            // Responsibles
0393:
0394:            protected void loadResponsibles(RedefinableHeader header,
0395:                    Element element) throws PropertyVetoException {
0396:
0397:                if (element == null)
0398:                    return;
0399:
0400:                loadResponsibles(header, Util.children(element, RESPONSIBLE));
0401:            }
0402:
0403:            protected void loadResponsibles(RedefinableHeader header,
0404:                    List elements) throws PropertyVetoException {
0405:
0406:                Iterator iter = elements.iterator();
0407:                while (iter.hasNext()) {
0408:                    Element responsibleElement = (Element) iter.next();
0409:                    header.add(responsibleElement.getTextTrim());
0410:                }
0411:
0412:                if (header.getResponsible().length == 0) {
0413:                    _logger
0414:                            .debug("Responsibles element present but no responsibles found");
0415:                }
0416:            }
0417:
0418:            // Participant-related configuration
0419:
0420:            /**
0421:             * Load participants from the given Element.  The element should represent a
0422:             * collection of participants (which is identified by the "Participants"
0423:             * tag).
0424:             *
0425:             * @param resCntr
0426:             * @param element The "Participants" element
0427:             * @throws XPDLParserException
0428:             */
0429:            protected void loadParticipants(ResourceContainer resCntr,
0430:                    Element element) throws XPDLParserException,
0431:                    PropertyVetoException {
0432:
0433:                if (element == null)
0434:                    return;
0435:
0436:                loadParticipants(resCntr, Util.children(element, PARTICIPANT));
0437:            }
0438:
0439:            /**
0440:             * Load the participant objects from the given list of "Participant"
0441:             * elements.
0442:             *
0443:             * @param resCntr
0444:             * @param elements The list of "Participant" elements
0445:             * @throws XPDLParserException
0446:             */
0447:            protected void loadParticipants(ResourceContainer resCntr,
0448:                    List elements) throws XPDLParserException,
0449:                    PropertyVetoException {
0450:
0451:                Iterator iter = elements.iterator();
0452:                while (iter.hasNext()) {
0453:                    Element participantElement = (Element) iter.next();
0454:                    resCntr.add(createParticipant(participantElement));
0455:                }
0456:            }
0457:
0458:            protected Participant createParticipant(Element element)
0459:                    throws XPDLParserException, PropertyVetoException {
0460:
0461:                Element typeElement = Util.child(element, PARTICIPANT_TYPE);
0462:                if (typeElement == null) {
0463:                    throw new ElementRequiredException(PARTICIPANT_TYPE,
0464:                            "Participant type required");
0465:                }
0466:
0467:                String typeString = typeElement.attributeValue(TYPE);
0468:                if (typeString == null) {
0469:                    throw new ElementRequiredException(TYPE,
0470:                            "Participant type identifier required");
0471:                }
0472:
0473:                ParticipantType participantType = ParticipantType
0474:                        .valueOf(typeString);
0475:                if (participantType == null) {
0476:                    throw new XPDLParserException("Unknown participant type: "
0477:                            + typeString);
0478:                }
0479:
0480:                ExternalReference extRef = null;
0481:                Element extRefElement = Util.child(element, EXTERNAL_REFERENCE);
0482:                if (extRefElement != null)
0483:                    extRef = createExternalReference(extRefElement);
0484:
0485:                Participant participant = new Participant(element
0486:                        .attributeValue(ID), element.attributeValue(NAME),
0487:                        participantType, extRef);
0488:
0489:                participant.setDescription(Util.elementAsString(element,
0490:                        DESCRIPTION));
0491:
0492:                Map extAttrs = new HashMap();
0493:                participant.setExtendedAttributes(loadExtendedAttributes(
0494:                        element, extAttrs));
0495:
0496:                participant.setCalendar((String) extAttrs.get(OBE_CALENDAR));
0497:
0498:                if (_logger.isDebugEnabled())
0499:                    _logger.debug(MSG_CREATED + participant);
0500:
0501:                return participant;
0502:            }
0503:
0504:            // Application-related configuration
0505:
0506:            /**
0507:             * Load applications from the given Element.  The element should represent a
0508:             * collection of applications (which is identified by the "Applications"
0509:             * tag).
0510:             *
0511:             * @param resCntr
0512:             * @param element The "Applications" element
0513:             * @throws XPDLParserException
0514:             */
0515:            protected void loadApplications(ResourceContainer resCntr,
0516:                    Element element) throws XPDLParserException,
0517:                    PropertyVetoException {
0518:
0519:                if (element == null)
0520:                    return;
0521:
0522:                loadApplications(resCntr, Util.children(element, APPLICATION));
0523:            }
0524:
0525:            /**
0526:             * Load the applications objects from the given list of "Application"
0527:             * elements.
0528:             *
0529:             * @param resCntr
0530:             * @param elements The list of "Application" elements
0531:             * @throws XPDLParserException
0532:             */
0533:            protected void loadApplications(ResourceContainer resCntr,
0534:                    List elements) throws XPDLParserException,
0535:                    PropertyVetoException {
0536:
0537:                _logger.debug("Loading applications in container "
0538:                        + resCntr.getId() + "...");
0539:                Iterator iter = elements.iterator();
0540:                while (iter.hasNext()) {
0541:                    Element applicationElement = (Element) iter.next();
0542:                    resCntr.add(createApplication(resCntr, applicationElement));
0543:                }
0544:                _logger.debug(resCntr.getApplication().length
0545:                        + APPLICATIONS_LOADED);
0546:            }
0547:
0548:            protected Application createApplication(ResourceContainer resCntr,
0549:                    Element element) throws XPDLParserException,
0550:                    PropertyVetoException {
0551:
0552:                Application application = new Application(element
0553:                        .attributeValue(ID), element.attributeValue(NAME));
0554:
0555:                application.setDescription(Util.elementAsString(element,
0556:                        DESCRIPTION));
0557:
0558:                if (Util.child(element, FORMAL_PARAMETERS) != null) {
0559:                    loadFormalParameters(resCntr, application, Util.child(
0560:                            element, FORMAL_PARAMETERS));
0561:                } else if (Util.child(element, EXTERNAL_REFERENCE) != null) {
0562:                    application
0563:                            .setExternalReference(createExternalReference(Util
0564:                                    .child(element, EXTERNAL_REFERENCE)));
0565:                }
0566:
0567:                application.setExtendedAttributes(loadExtendedAttributes(
0568:                        resCntr, element));
0569:
0570:                if (_logger.isDebugEnabled())
0571:                    _logger.debug(MSG_CREATED + application);
0572:
0573:                return application;
0574:            }
0575:
0576:            protected AssignmentStrategyDef createAssignmentStrategy(
0577:                    Element element) throws XPDLParserException {
0578:
0579:                boolean expandGroups = Boolean.valueOf(
0580:                        element.attributeValue(EXPAND_GROUPS)).booleanValue();
0581:                AssignmentStrategyDef strategy = new AssignmentStrategyDef(
0582:                        element.attributeValue(ID), expandGroups);
0583:
0584:                _logger
0585:                        .debug("Created assignment strategy "
0586:                                + strategy.getId());
0587:
0588:                if (_logger.isDebugEnabled())
0589:                    _logger.debug(MSG_CREATED + strategy);
0590:
0591:                return strategy;
0592:            }
0593:
0594:            // WorkflowProcess related
0595:
0596:            /**
0597:             * Load workflow processes from the given Element.  The element should
0598:             * represent a collection of workflow process (which is identified by the
0599:             * "WorkflowProcesses" tag).
0600:             *
0601:             * @param element The "WorkflowProcesses" element
0602:             * @throws XPDLParserException
0603:             */
0604:            protected void loadWorkflowProcesses(XPDLPackage pkg,
0605:                    Element element) throws XPDLParserException,
0606:                    PropertyVetoException {
0607:
0608:                if (element == null)
0609:                    return;
0610:
0611:                loadWorkflowProcesses(pkg, Util.children(element,
0612:                        WORKFLOW_PROCESS));
0613:            }
0614:
0615:            /**
0616:             * Load the workflow process objects from the given list of
0617:             * "WorkflowProcess" elements.
0618:             *
0619:             * @param elements The list of "WorkflowProcess" elements
0620:             * @throws XPDLParserException
0621:             */
0622:            protected void loadWorkflowProcesses(XPDLPackage pkg, List elements)
0623:                    throws XPDLParserException, PropertyVetoException {
0624:
0625:                Iterator iter = elements.iterator();
0626:                while (iter.hasNext()) {
0627:                    Element workflowProcessElement = (Element) iter.next();
0628:                    pkg.add(createWorkflowProcess(pkg, workflowProcessElement));
0629:                }
0630:            }
0631:
0632:            protected WorkflowProcess createWorkflowProcess(XPDLPackage pkg,
0633:                    Element element) throws XPDLParserException,
0634:                    PropertyVetoException {
0635:
0636:                ProcessHeader processHeader = createProcessHeader(Util.child(
0637:                        element, PROCESS_HEADER));
0638:
0639:                WorkflowProcess wp = new WorkflowProcess(element
0640:                        .attributeValue(ID), element.attributeValue(NAME), pkg,
0641:                        processHeader);
0642:
0643:                wp.setRedefinableHeader(createRedefinableHeader(Util.child(
0644:                        element, REDEFINABLE_HEADER)));
0645:
0646:                wp.setAccessLevel(AccessLevel.valueOf(element
0647:                        .attributeValue(ACCESS_LEVEL)));
0648:
0649:                loadFormalParameters(pkg, wp, Util.child(element,
0650:                        FORMAL_PARAMETERS));
0651:
0652:                loadDataFields(wp, Util.child(element, DATA_FIELDS));
0653:
0654:                loadParticipants(wp, Util.child(element, PARTICIPANTS));
0655:
0656:                _logger.debug("Loading applications in process " + wp.getId()
0657:                        + "...");
0658:                loadApplications(wp, Util.child(element, APPLICATIONS));
0659:                _logger.debug(wp.getApplication().length + APPLICATIONS_LOADED);
0660:
0661:                _logger.debug("Loading activity sets in process " + wp.getId()
0662:                        + "...");
0663:                loadActivitySets(pkg, wp, Util.child(element, ACTIVITY_SETS));
0664:                _logger.debug(wp.getActivitySet().length
0665:                        + " activity sets loaded");
0666:
0667:                _logger.debug("Loading activities in process " + wp.getId()
0668:                        + "...");
0669:                loadActivities(pkg, wp, wp, Util.child(element, ACTIVITIES));
0670:                _logger.debug(wp.getActivity().length + " activities loaded");
0671:
0672:                _logger.debug("Loading transitions in process " + wp.getId()
0673:                        + "...");
0674:                loadTransitions(pkg, wp, Util.child(element, TRANSITIONS));
0675:                _logger
0676:                        .debug(wp.getTransition().length
0677:                                + " transitions loaded");
0678:
0679:                Map extAttrs = new HashMap();
0680:                wp.setExtendedAttributes(loadExtendedAttributes(element,
0681:                        extAttrs));
0682:
0683:                Event event = (Event) extAttrs.get(OBE_EVENT);
0684:                Timer timer = (Timer) extAttrs.get(OBE_TIMER);
0685:                if (event != null && timer != null) {
0686:                    throw new XPDLParserException(
0687:                            "WorkflowProcess: event and timer are mutually exclusive");
0688:                }
0689:                if (event != null)
0690:                    wp.setTrigger(event);
0691:                else if (timer != null)
0692:                    wp.setTrigger(timer);
0693:
0694:                wp.setAssignmentStrategy((AssignmentStrategyDef) extAttrs
0695:                        .get(OBE_ASSIGNMENT_STRATEGY));
0696:
0697:                wp.setCalendar((String) extAttrs.get(OBE_CALENDAR));
0698:
0699:                wp.setCompletionStrategy((String) extAttrs
0700:                        .get(OBE_COMPLETION_STRATEGY));
0701:
0702:                _logger.debug("Resolving references in process " + wp.getId()
0703:                        + "...");
0704:                wp.resolveReferences();
0705:
0706:                if (_logger.isDebugEnabled())
0707:                    _logger.debug(MSG_CREATED + wp);
0708:
0709:                return wp;
0710:            }
0711:
0712:            protected ProcessHeader createProcessHeader(Element element)
0713:                    throws XPDLParserException {
0714:
0715:                if (element == null) {
0716:                    throw new ElementRequiredException(PROCESS_HEADER,
0717:                            XPDLMessages.PROCESS_HEADER_REQUIRED);
0718:                }
0719:
0720:                ProcessHeader processHeader = new ProcessHeader();
0721:
0722:                // set the duration unit to use if no duration unit is specified
0723:                DurationUnit durationUnit = defaultDurationUnit;
0724:                String durationUnitString = element
0725:                        .attributeValue(DURATION_UNIT);
0726:                if (durationUnitString != null)
0727:                    durationUnit = DurationUnit.valueOf(durationUnitString);
0728:                processHeader.setDurationUnit(durationUnit);
0729:
0730:                // set header properties
0731:                processHeader.setCreated(Util.elementAsDate(element, CREATED));
0732:                processHeader.setPriority(Util.elementAsString(element,
0733:                        PRIORITY));
0734:                processHeader.setLimit(Util.elementAsDuration(element, LIMIT));
0735:                processHeader.setValidFrom(Util.elementAsDate(element,
0736:                        VALID_FROM));
0737:                processHeader.setValidTo(Util.elementAsDate(element, VALID_TO));
0738:                processHeader.setDescription(Util.elementAsString(element,
0739:                        DESCRIPTION));
0740:
0741:                processHeader.setTimeEstimation(createTimeEstimation(Util
0742:                        .child(element, TIME_ESTIMATION)));
0743:
0744:                if (_logger.isDebugEnabled())
0745:                    _logger.debug(MSG_CREATED + processHeader);
0746:
0747:                return processHeader;
0748:            }
0749:
0750:            // ActivitySet
0751:
0752:            /**
0753:             * Load activity sets from the given Element.  The element should represent
0754:             * a collection of activity sets (which is identified by the "ActivitySets"
0755:             * tag).
0756:             *
0757:             * @param pkg
0758:             * @param element The "ActivitySets" element
0759:             * @throws XPDLParserException
0760:             */
0761:            protected void loadActivitySets(XPDLPackage pkg,
0762:                    WorkflowProcess wp, Element element)
0763:                    throws XPDLParserException, PropertyVetoException {
0764:
0765:                if (element == null) {
0766:                    _logger.debug("ActivitySets element was null");
0767:                    return;
0768:                }
0769:
0770:                loadActivitySets(pkg, wp, Util.children(element, ACTIVITY_SET));
0771:            }
0772:
0773:            /**
0774:             * Load the activity set objects from the given list of "ActivitySet"
0775:             * elements.
0776:             *
0777:             * @param pkg
0778:             * @param elements The list of "Activity" elements
0779:             * @throws XPDLParserException
0780:             */
0781:            protected void loadActivitySets(XPDLPackage pkg,
0782:                    WorkflowProcess wp, List elements)
0783:                    throws XPDLParserException, PropertyVetoException {
0784:
0785:                Iterator iter = elements.iterator();
0786:                while (iter.hasNext()) {
0787:                    Element activitySetElement = (Element) iter.next();
0788:                    wp.add(createActivitySet(pkg, wp, activitySetElement));
0789:                }
0790:            }
0791:
0792:            protected ActivitySet createActivitySet(XPDLPackage pkg,
0793:                    WorkflowProcess wp, Element element)
0794:                    throws XPDLParserException, PropertyVetoException {
0795:
0796:                ActivitySet activitySet = new ActivitySet(element
0797:                        .attributeValue(ID));
0798:
0799:                loadActivities(pkg, wp, activitySet, Util.child(element,
0800:                        ACTIVITIES));
0801:                loadTransitions(pkg, activitySet, Util.child(element,
0802:                        TRANSITIONS));
0803:
0804:                if (_logger.isDebugEnabled())
0805:                    _logger.debug(MSG_CREATED + activitySet);
0806:
0807:                return activitySet;
0808:            }
0809:
0810:            // Activity Related
0811:
0812:            /**
0813:             * Load actvities from the given Element.  The element should represent a
0814:             * collection of activities (which is identified by the "Activities" tag).
0815:             *
0816:             * @param pkg
0817:             * @param graph   The list of activities
0818:             * @param element The "Activities" element
0819:             * @throws XPDLParserException
0820:             */
0821:            protected void loadActivities(XPDLPackage pkg, WorkflowProcess wp,
0822:                    Graph graph, Element element) throws XPDLParserException,
0823:                    PropertyVetoException {
0824:
0825:                if (element == null) {
0826:                    _logger.debug("Activities element was null");
0827:                    return;
0828:                }
0829:
0830:                loadActivities(pkg, wp, graph, Util.children(element, ACTIVITY));
0831:            }
0832:
0833:            /**
0834:             * Load the activity objects from the given list of "Activity" elements.
0835:             *
0836:             * @param pkg
0837:             * @param graph    The list of activites
0838:             * @param elements The list of "Activity" elements
0839:             * @throws XPDLParserException
0840:             */
0841:            protected void loadActivities(XPDLPackage pkg, WorkflowProcess wp,
0842:                    Graph graph, List elements) throws XPDLParserException,
0843:                    PropertyVetoException {
0844:
0845:                Iterator iter = elements.iterator();
0846:                while (iter.hasNext()) {
0847:                    Element activityElement = (Element) iter.next();
0848:                    graph.add(createActivity(pkg, wp, activityElement));
0849:                }
0850:            }
0851:
0852:            protected Activity createActivity(XPDLPackage pkg,
0853:                    WorkflowProcess wp, Element element)
0854:                    throws XPDLParserException, PropertyVetoException {
0855:
0856:                Activity activity = new Activity(element.attributeValue(ID),
0857:                        element.attributeValue(NAME), wp);
0858:
0859:                activity.setDescription(Util.elementAsString(element,
0860:                        DESCRIPTION));
0861:                activity.setLimit(Util.elementAsDuration(element, LIMIT));
0862:                activity.setPerformer(Util.elementAsString(element, PERFORMER));
0863:                activity.setPriority(Util.elementAsString(element, PRIORITY));
0864:                activity.setDocumentation(Util.elementAsURL(element,
0865:                        DOCUMENTATION));
0866:                activity.setIcon(Util.elementAsURL(element, ICON));
0867:                loadDeadlines(activity, Util.children(element, DEADLINE));
0868:                activity
0869:                        .setSimulationInformation(createSimulationInformation(Util
0870:                                .child(element, SIMULATION_INFORMATION)));
0871:
0872:                // Implementation
0873:                Element implementationElement = Util.child(element,
0874:                        IMPLEMENTATION);
0875:                if (implementationElement != null) {
0876:                    activity.setImplementation(createImplementation(pkg,
0877:                            implementationElement));
0878:                }
0879:
0880:                // Route (only if implementation not specified)
0881:                Element routeElement = Util.child(element, ROUTE);
0882:                if (routeElement != null) {
0883:                    if (implementationElement == null) {
0884:                        activity.setRoute(createRoute());
0885:                    } else {
0886:                        // TODO: perform validating parse to catch this error earlier.
0887:                        _logger.warn(IMPL_ROUTE_MUTEX
0888:                                + "defined together.  Ignoring route.");
0889:                    }
0890:                }
0891:
0892:                Element blockActivityElement = Util.child(element,
0893:                        BLOCKACTIVITY);
0894:                if (blockActivityElement != null) {
0895:                    if (implementationElement != null || routeElement != null) {
0896:                        // TODO: perform validating parse to catch this error earlier.
0897:                        _logger.warn(IMPL_ROUTE_MUTEX
0898:                                + "defined together.  Ignoring BlockActivity.");
0899:                    } else {
0900:                        activity
0901:                                .setBlockActivity(createBlockActivity(blockActivityElement));
0902:                    }
0903:                }
0904:
0905:                // TODO: perform validating parse to catch this error earlier.
0906:                if (implementationElement == null && routeElement == null
0907:                        && blockActivityElement == null) {
0908:
0909:                    throw new XPDLParserException(
0910:                            "Activity '"
0911:                                    + activity.getId()
0912:                                    + "' requires Implementation, Route or BlockActivity");
0913:                }
0914:
0915:                // Set the start mode if specified.
0916:                Element startModeElement = Util.child(element, START_MODE);
0917:                if (startModeElement != null) {
0918:                    activity
0919:                            .setStartMode(Util.child(startModeElement, MANUAL) != null ? AutomationMode.MANUAL
0920:                                    : AutomationMode.AUTOMATIC);
0921:                }
0922:
0923:                // Set the finish mode if specified.
0924:                Element finishModeElement = Util.child(element, FINISH_MODE);
0925:                if (finishModeElement != null) {
0926:                    activity
0927:                            .setFinishMode(Util
0928:                                    .child(finishModeElement, MANUAL) != null ? AutomationMode.MANUAL
0929:                                    : AutomationMode.AUTOMATIC);
0930:                }
0931:
0932:                loadTransitionRestrictions(activity, Util.child(element,
0933:                        TRANSITION_RESTRICTIONS));
0934:
0935:                Map extAttrs = new HashMap();
0936:                activity.setExtendedAttributes(loadExtendedAttributes(element,
0937:                        extAttrs));
0938:
0939:                activity.setAssignmentStrategy((AssignmentStrategyDef) extAttrs
0940:                        .get(OBE_ASSIGNMENT_STRATEGY));
0941:
0942:                activity.setBounds((Rectangle) extAttrs.get(OBE_BOUNDS));
0943:
0944:                activity.setCalendar((String) extAttrs.get(OBE_CALENDAR));
0945:
0946:                activity.setCompletionStrategy((String) extAttrs
0947:                        .get(OBE_COMPLETION_STRATEGY));
0948:
0949:                BlockActivity ba = activity.getBlockActivity();
0950:                if (ba != null)
0951:                    ba.setLoop((Loop) extAttrs.get(OBE_LOOP));
0952:
0953:                activity.setToolMode((ToolMode) extAttrs.get(OBE_TOOL_MODE));
0954:
0955:                if (_logger.isDebugEnabled())
0956:                    _logger.debug(MSG_CREATED + activity);
0957:
0958:                return activity;
0959:            }
0960:
0961:            protected void loadDeadlines(Activity activity, List elements)
0962:                    throws XPDLParserException, PropertyVetoException {
0963:
0964:                if (elements != null) {
0965:                    for (Iterator iter = elements.iterator(); iter.hasNext();) {
0966:                        Deadline deadline = createDeadline((Element) iter
0967:                                .next());
0968:                        if (deadline != null)
0969:                            activity.add(deadline);
0970:                    }
0971:                }
0972:            }
0973:
0974:            /**
0975:             * Create a Deadline object from the given Element.
0976:             *
0977:             * @param element The Element
0978:             * @return the Deadline object
0979:             * @throws XPDLParserException
0980:             */
0981:            protected Deadline createDeadline(Element element)
0982:                    throws XPDLParserException {
0983:
0984:                if (element == null) {
0985:                    _logger.debug("Deadline not found");
0986:                    return null;
0987:                }
0988:
0989:                _logger.debug("Creating Deadline object");
0990:                Deadline deadline = new Deadline(Util.elementAsString(element,
0991:                        DEADLINE_CONDITION), Util.elementAsString(element,
0992:                        EXCEPTION_NAME));
0993:                deadline.setExecutionType(ExecutionType.valueOf(element
0994:                        .attributeValue(EXECUTION)));
0995:
0996:                if (_logger.isDebugEnabled())
0997:                    _logger.debug(MSG_CREATED + deadline);
0998:
0999:                return deadline;
1000:            }
1001:
1002:            protected BlockActivity createBlockActivity(Element element) {
1003:                BlockActivity blockActivity = new BlockActivity();
1004:                blockActivity.setBlockId(element.attributeValue(BLOCKID));
1005:
1006:                if (_logger.isDebugEnabled())
1007:                    _logger.debug(MSG_CREATED + blockActivity);
1008:
1009:                return blockActivity;
1010:            }
1011:
1012:            protected Implementation createImplementation(XPDLPackage pkg,
1013:                    Element element) throws XPDLParserException,
1014:                    PropertyVetoException {
1015:
1016:                ToolSet toolSet = new ToolSet();
1017:
1018:                Iterator elements = element.elements().iterator();
1019:                while (elements.hasNext()) {
1020:                    Element implElement = (Element) elements.next();
1021:                    ImplementationType implType = ImplementationType
1022:                            .valueOf(implElement.getName());
1023:
1024:                    if (implType == null) {
1025:                        throw new XPDLParserException(
1026:                                "Illegal implementation type: "
1027:                                        + implElement.getName());
1028:                    }
1029:
1030:                    switch (implType.value()) {
1031:                    case ImplementationType.NO_INT:
1032:                        return new NoImplementation();
1033:                    case ImplementationType.SUBFLOW_INT:
1034:                        return createSubFlow(implElement);
1035:                    case ImplementationType.TOOLS_INT:
1036:                        toolSet.add(createTool(pkg, implElement));
1037:                        break;
1038:                    default:
1039:                        throw new XPDLParserException(
1040:                                "Unsupported implementation type: " + implType);
1041:                    }
1042:
1043:                }
1044:
1045:                return toolSet;
1046:            }
1047:
1048:            protected Route createRoute() {
1049:                Route route = new Route();
1050:                if (_logger.isDebugEnabled())
1051:                    _logger.debug(MSG_CREATED + route);
1052:
1053:                return route;
1054:            }
1055:
1056:            /*
1057:             protected AbstractMetaData createMetaData(Element element)
1058:             throws XPDLParserException, PropertyVetoException {
1059:
1060:             if (element == null)
1061:             throw new XPDLParserException("meta-data element missing");
1062:
1063:             Unmarshaller unmarshaller = new Unmarshaller(
1064:             RepositoryEntries.class, getClass().getClassLoader());
1065:             //        if (getLogger().isDebugEnabled() && OBEConfig.isVerbose()) {
1066:             //            unmarshaller.setUnmarshalListener(new UnmarshalListener() {
1067:             //                public void initialized(Object obj) {
1068:             //                    getLogger().debug("initialized(\"" + obj + "\")");
1069:             //                }
1070:             //
1071:             //                public void attributesProcessed(Object obj) {
1072:             //                    getLogger().debug("attributesProcessed(\"" + obj +
1073:             //                        "\")");
1074:             //                }
1075:             //
1076:             //                public void fieldAdded(String field, Object parent,
1077:             //                    Object child) {
1078:             //
1079:             //                    getLogger().debug("fieldAdded(\"" + field +
1080:             //                        "\", \"" + parent + "\", \"" + child + "\")");
1081:             //                }
1082:             //
1083:             //                public void unmarshalled(Object obj) {
1084:             //                    getLogger().debug("unmarshalled(\"" + obj + "\")");
1085:             //                }
1086:             //            });
1087:             //        }
1088:             unmarshaller.setValidation(false);
1089:             unmarshaller.setMapping(_mapping);
1090:             IDResolver idResolver = new IDResolver() {
1091:             Object resolve(String idref) {
1092:             return null;
1093:             }
1094:             };
1095:             unmarshaller.setIDResolver(idResolver);
1096:             AbstractMetaData metadata =
1097:             (AbstractMetaData)unmarshaller.unmarshal(element);
1098:
1099:             return metadata;
1100:             }
1101:             */
1102:
1103:            protected Loop createLoop(Element element)
1104:                    throws XPDLParserException, PropertyVetoException {
1105:
1106:                if (element == null)
1107:                    throw new XPDLParserException("obe:Loop element missing");
1108:                Loop loop = new Loop();
1109:                Element whileElement = element.element(WHILE_QNAME);
1110:                if (whileElement == null) {
1111:                    Element untilElement = element.element(UNTIL_QNAME);
1112:                    if (untilElement == null) {
1113:                        Element foreachElement = element.element(FOREACH_QNAME);
1114:                        if (foreachElement != null) {
1115:                            loop.setBody(createForEach(foreachElement));
1116:                        }
1117:                    } else {
1118:                        loop.setBody(createUntil(untilElement));
1119:                    }
1120:                } else {
1121:                    loop.setBody(createWhile(whileElement));
1122:                }
1123:                if (_logger.isDebugEnabled())
1124:                    _logger.debug(MSG_CREATED + loop);
1125:
1126:                return loop;
1127:            }
1128:
1129:            protected While createWhile(Element element)
1130:                    throws XPDLParserException, PropertyVetoException {
1131:
1132:                Element condElement = element.element(CONDITION_QNAME);
1133:                // TODO: validating parse will remove the need for this.
1134:                if (condElement == null)
1135:                    throw new XPDLParserException(
1136:                            "Missing Condition element in While");
1137:                While w = new While(createCondition(condElement));
1138:                if (_logger.isDebugEnabled())
1139:                    _logger.debug(MSG_CREATED + w);
1140:
1141:                return w;
1142:            }
1143:
1144:            protected Until createUntil(Element element)
1145:                    throws XPDLParserException, PropertyVetoException {
1146:
1147:                Element condElement = element.element(CONDITION_QNAME);
1148:                // TODO: validating parse will remove the need for this.
1149:                if (condElement == null)
1150:                    throw new XPDLParserException(
1151:                            "Missing Condition element in Until");
1152:                Until u = new Until(createCondition(condElement));
1153:                if (_logger.isDebugEnabled())
1154:                    _logger.debug(MSG_CREATED + u);
1155:
1156:                return u;
1157:            }
1158:
1159:            protected ForEach createForEach(Element element)
1160:                    throws XPDLParserException {
1161:                String dataField = element.attributeValue(DATA_FIELD);
1162:                Element exprElement = element.element(IN_QNAME);
1163:                // TODO: validating parse will remove the need for this.
1164:                if (exprElement == null)
1165:                    throw new XPDLParserException(
1166:                            "Missing In element in ForEach");
1167:                ForEach fe = new ForEach(dataField, exprElement.getTextTrim());
1168:                if (_logger.isDebugEnabled())
1169:                    _logger.debug(MSG_CREATED + fe);
1170:
1171:                return fe;
1172:            }
1173:
1174:            protected SubFlow createSubFlow(Element element)
1175:                    throws XPDLParserException, PropertyVetoException {
1176:
1177:                SubFlow subFlow = new SubFlow(element.attributeValue(ID));
1178:
1179:                String executionString = element.attributeValue(EXECUTION);
1180:                if (executionString != null)
1181:                    subFlow
1182:                            .setExecution(ExecutionType
1183:                                    .valueOf(executionString));
1184:
1185:                loadActualParameters(subFlow, Util.child(element,
1186:                        ACTUAL_PARAMETERS));
1187:
1188:                if (_logger.isDebugEnabled())
1189:                    _logger.debug(MSG_CREATED + subFlow);
1190:
1191:                return subFlow;
1192:            }
1193:
1194:            protected Tool createTool(XPDLPackage pkg, Element element)
1195:                    throws XPDLParserException, PropertyVetoException {
1196:
1197:                Tool tool = new Tool(element.attributeValue(ID));
1198:
1199:                tool.setDescription(Util.elementAsString(element, DESCRIPTION));
1200:
1201:                String typeString = element.attributeValue(TYPE);
1202:                if (typeString != null)
1203:                    tool.setToolType(ToolType.valueOf(typeString));
1204:
1205:                loadActualParameters(tool, Util.child(element,
1206:                        ACTUAL_PARAMETERS));
1207:
1208:                tool
1209:                        .setExtendedAttributes(loadExtendedAttributes(pkg,
1210:                                element));
1211:
1212:                if (_logger.isDebugEnabled())
1213:                    _logger.debug(MSG_CREATED + tool);
1214:
1215:                return tool;
1216:            }
1217:
1218:            // Deadline
1219:
1220:            protected SimulationInformation createSimulationInformation(
1221:                    Element element) throws XPDLParserException {
1222:
1223:                if (element == null)
1224:                    return null;
1225:
1226:                SimulationInformation simInfo = new SimulationInformation();
1227:
1228:                InstantiationType instantiationType = defaultInstantiationType;
1229:                String instantiationTypeString = element
1230:                        .attributeValue(INSTANTIATION_TYPE);
1231:                if (instantiationTypeString != null) {
1232:                    instantiationType = InstantiationType
1233:                            .valueOf(instantiationTypeString);
1234:                }
1235:
1236:                simInfo.setInstantiationType(instantiationType);
1237:                simInfo.setCost(Util.elementAsString(element, COST));
1238:                simInfo.setTimeEstimation(createTimeEstimation(Util.child(
1239:                        element, TIME_ESTIMATION)));
1240:
1241:                if (_logger.isDebugEnabled())
1242:                    _logger.debug(MSG_CREATED + simInfo);
1243:
1244:                return simInfo;
1245:            }
1246:
1247:            /**
1248:             * Create a TimeEstimation object.
1249:             *
1250:             * @param element The TimeEstimation Element
1251:             * @return The TimeEstimation object
1252:             * @throws XPDLParserException Parse error
1253:             */
1254:
1255:            protected TimeEstimation createTimeEstimation(Element element)
1256:                    throws XPDLParserException {
1257:
1258:                if (element == null)
1259:                    return null;
1260:
1261:                TimeEstimation timeEstimation = new TimeEstimation();
1262:                timeEstimation.setWaitingTime(Util.elementAsDuration(element,
1263:                        WAITING_TIME));
1264:                timeEstimation.setWorkingTime(Util.elementAsDuration(element,
1265:                        WORKING_TIME));
1266:                timeEstimation.setDuration(Util.elementAsDuration(element,
1267:                        DURATION));
1268:                if (_logger.isDebugEnabled())
1269:                    _logger.debug(MSG_CREATED + timeEstimation);
1270:
1271:                return timeEstimation;
1272:            }
1273:
1274:            public Condition createCondition(Element element)
1275:                    throws PropertyVetoException {
1276:
1277:                if (element == null)
1278:                    return null;
1279:
1280:                Condition condition = new Condition();
1281:
1282:                Iterator xpressionElements = Util.children(element, XPRESSION)
1283:                        .iterator();
1284:                while (xpressionElements.hasNext()) {
1285:                    Element xpressionElement = (Element) xpressionElements
1286:                            .next();
1287:                    condition.add(new Xpression(xpressionElement.getText()));
1288:                }
1289:
1290:                String typeString = element.attributeValue(TYPE);
1291:                if (typeString != null)
1292:                    condition.setType(ConditionType.valueOf(typeString));
1293:
1294:                condition.setValue(element.getText());
1295:
1296:                if (_logger.isDebugEnabled())
1297:                    _logger.debug(MSG_CREATED + condition);
1298:
1299:                return condition;
1300:            }
1301:
1302:            // Transitions
1303:
1304:            /**
1305:             * Load transitions from the given Element.  The element should represent a
1306:             * collection of transitions (which is identified by the "Transitions"
1307:             * tag).
1308:             *
1309:             * @param pkg
1310:             * @param graph   The list of transitions
1311:             * @param element The "Transitions" element
1312:             * @throws XPDLParserException
1313:             */
1314:            protected void loadTransitions(XPDLPackage pkg, Graph graph,
1315:                    Element element) throws XPDLParserException,
1316:                    PropertyVetoException {
1317:
1318:                if (element == null)
1319:                    return;
1320:
1321:                loadTransitions(pkg, graph, Util.children(element, TRANSITION));
1322:            }
1323:
1324:            /**
1325:             * Load the transition objects from the given list of "Transition"
1326:             * elements.
1327:             *
1328:             * @param pkg
1329:             * @param graph    The list of transitions
1330:             * @param elements The list of "Transition" elements
1331:             * @throws XPDLParserException
1332:             */
1333:            protected void loadTransitions(XPDLPackage pkg, Graph graph,
1334:                    List elements) throws XPDLParserException,
1335:                    PropertyVetoException {
1336:
1337:                Iterator iter = elements.iterator();
1338:                while (iter.hasNext()) {
1339:                    Element transitionElement = (Element) iter.next();
1340:                    graph.add(createTransition(pkg, transitionElement));
1341:                }
1342:            }
1343:
1344:            protected Transition createTransition(XPDLPackage pkg,
1345:                    Element element) throws XPDLParserException,
1346:                    PropertyVetoException {
1347:
1348:                Transition transition = new Transition(element
1349:                        .attributeValue(ID), element.attributeValue(NAME),
1350:                        element.attributeValue(FROM), element
1351:                                .attributeValue(TO));
1352:
1353:                transition.setDescription(Util.elementAsString(element,
1354:                        DESCRIPTION));
1355:                transition.setCondition(createCondition(Util.child(element,
1356:                        CONDITION)));
1357:
1358:                // Load extended attributes.
1359:                Map extAttrs = new HashMap();
1360:                transition.setExtendedAttributes(loadExtendedAttributes(
1361:                        element, extAttrs));
1362:
1363:                // For now, event transitions and execution type are described by
1364:                // extended attributes.
1365:                transition.setEvent((Event) extAttrs.get(OBE_EVENT));
1366:                transition.setExecutionType((ExecutionType) extAttrs
1367:                        .get(EXECUTION));
1368:
1369:                if (_logger.isDebugEnabled())
1370:                    _logger.debug(MSG_CREATED + transition);
1371:
1372:                return transition;
1373:            }
1374:
1375:            protected Event createEvent(Element eventElement)
1376:                    throws XPDLParserException, PropertyVetoException {
1377:
1378:                if (eventElement == null)
1379:                    throw new XPDLParserException("obe:Event element missing");
1380:
1381:                Event event = new Event(eventElement.attributeValue(ID),
1382:                        eventElement.attributeValue(COUNT), eventElement
1383:                                .attributeValue(PREDICATE));
1384:
1385:                Element actualParametersElem = eventElement
1386:                        .element(ACTUAL_PARAMETERS_QNAME);
1387:                if (actualParametersElem != null)
1388:                    loadActualParameters(event, actualParametersElem);
1389:
1390:                if (_logger.isDebugEnabled())
1391:                    _logger.debug(MSG_CREATED + event);
1392:
1393:                return event;
1394:            }
1395:
1396:            protected Timer createTimer(Element timerElement)
1397:                    throws XPDLParserException, PropertyVetoException {
1398:
1399:                if (timerElement == null)
1400:                    throw new XPDLParserException("obe:Timer element missing");
1401:
1402:                Timer timer = new Timer(timerElement.attributeValue(ID),
1403:                        timerElement.attributeValue(COUNT), timerElement
1404:                                .attributeValue(INTERVAL), timerElement
1405:                                .attributeValue(CALENDAR), timerElement
1406:                                .attributeValue(RECOVERABLE));
1407:
1408:                Element actualParametersElem = timerElement
1409:                        .element(ACTUAL_PARAMETERS_QNAME);
1410:                if (actualParametersElem != null)
1411:                    loadActualParameters(timer, actualParametersElem);
1412:
1413:                if (_logger.isDebugEnabled())
1414:                    _logger.debug(MSG_CREATED + timer);
1415:
1416:                return timer;
1417:            }
1418:
1419:            // Transition Restrictions
1420:
1421:            /**
1422:             * Load transition restrictions from the given Element.  The element should
1423:             * represent a collection of transition restrictions (which is identified by
1424:             * the "TransitionRestrictions" tag).
1425:             *
1426:             * @param activity The list of transition restrictions
1427:             * @param element  The "TransitionRestrictions" element
1428:             * @throws XPDLParserException
1429:             */
1430:            protected void loadTransitionRestrictions(Activity activity,
1431:                    Element element) throws XPDLParserException,
1432:                    PropertyVetoException {
1433:
1434:                if (element == null)
1435:                    return;
1436:
1437:                loadTransitionRestrictions(activity, Util.children(element,
1438:                        TRANSITION_RESTRICTION));
1439:            }
1440:
1441:            /**
1442:             * Load the transition restriction objects from the given list of
1443:             * "TransitionRestriction"  elements.
1444:             *
1445:             * @param activity The list of transition restriction
1446:             * @param elements The list of "TransitionRestriction" elements
1447:             * @throws XPDLParserException
1448:             */
1449:            protected void loadTransitionRestrictions(Activity activity,
1450:                    List elements) throws XPDLParserException,
1451:                    PropertyVetoException {
1452:
1453:                Iterator iter = elements.iterator();
1454:                while (iter.hasNext()) {
1455:                    Element transitionRestrictionElement = (Element) iter
1456:                            .next();
1457:                    activity
1458:                            .add(createTransitionRestriction(transitionRestrictionElement));
1459:                }
1460:            }
1461:
1462:            protected TransitionRestriction createTransitionRestriction(
1463:                    Element element) throws XPDLParserException,
1464:                    PropertyVetoException {
1465:
1466:                _logger.debug("Loading transition restriction");
1467:
1468:                TransitionRestriction transitionRestriction = new TransitionRestriction();
1469:
1470:                transitionRestriction.setJoin(createJoin(Util.child(element,
1471:                        JOIN)));
1472:                transitionRestriction.setSplit(createSplit(Util.child(element,
1473:                        SPLIT)));
1474:
1475:                if (_logger.isDebugEnabled())
1476:                    _logger.debug(MSG_CREATED + transitionRestriction);
1477:
1478:                return transitionRestriction;
1479:            }
1480:
1481:            public Join createJoin(Element element) {
1482:                if (element == null)
1483:                    return null;
1484:
1485:                Join join = new Join();
1486:
1487:                String typeString = element.attributeValue(TYPE);
1488:                if (typeString != null)
1489:                    join.setType(JoinType.valueOf(typeString));
1490:
1491:                if (_logger.isDebugEnabled())
1492:                    _logger.debug(MSG_CREATED + join);
1493:
1494:                return join;
1495:            }
1496:
1497:            public Split createSplit(Element element)
1498:                    throws XPDLParserException, PropertyVetoException {
1499:
1500:                if (element == null)
1501:                    return null;
1502:
1503:                Split split = new Split();
1504:
1505:                String typeString = element.attributeValue(TYPE);
1506:                if (typeString == null) {
1507:                    throw new XPDLParserException("Unsupported split type: "
1508:                            + typeString);
1509:                }
1510:                split.setType(SplitType.valueOf(typeString));
1511:
1512:                loadTransitionReferences(split, Util.child(element,
1513:                        TRANSITION_REFERENCES));
1514:
1515:                if (_logger.isDebugEnabled())
1516:                    _logger.debug(MSG_CREATED + split);
1517:
1518:                return split;
1519:            }
1520:
1521:            // Transition References
1522:
1523:            /**
1524:             * Load transition references from the given Element.  The element should
1525:             * represent a collection of transition references (which is identified by
1526:             * the "TransitionRefs" tag).
1527:             *
1528:             * @param split   The list of transition references
1529:             * @param element The "TransitionRefs" element
1530:             * @throws XPDLParserException
1531:             */
1532:            protected void loadTransitionReferences(Split split, Element element)
1533:                    throws XPDLParserException, PropertyVetoException {
1534:
1535:                if (element == null)
1536:                    return;
1537:
1538:                loadTransitionReferences(split, Util.children(element,
1539:                        TRANSITION_REFERENCE));
1540:            }
1541:
1542:            /**
1543:             * Load the transition references objects from the given list of
1544:             * "TransitionRef" elements.
1545:             *
1546:             * @param split    The list of transition references
1547:             * @param elements The list of "TransitionRef" elements
1548:             * @throws XPDLParserException
1549:             */
1550:            protected void loadTransitionReferences(Split split, List elements)
1551:                    throws XPDLParserException, PropertyVetoException {
1552:
1553:                Iterator iter = elements.iterator();
1554:                while (iter.hasNext()) {
1555:                    Element transitionRefElement = (Element) iter.next();
1556:                    split.add(transitionRefElement.attributeValue(ID));
1557:                }
1558:            }
1559:
1560:            // Formal Parameters
1561:
1562:            /**
1563:             * Load formal parameters from the given Element.  The element should
1564:             * represent a collection of formal parameters (which is identified by the
1565:             * "FormalParameters" tag).
1566:             *
1567:             * @param resCntr
1568:             * @param invokable The list of formal parameters
1569:             * @param element   The "FormalParameters" element
1570:             * @throws XPDLParserException
1571:             */
1572:            protected void loadFormalParameters(ResourceContainer resCntr,
1573:                    Invokable invokable, Element element)
1574:                    throws XPDLParserException, PropertyVetoException {
1575:
1576:                if (element == null)
1577:                    return;
1578:
1579:                loadFormalParameters(resCntr, invokable, Util.children(element,
1580:                        FORMAL_PARAMETER));
1581:            }
1582:
1583:            /**
1584:             * Load the formal parameters objects from the given list of
1585:             * "FormalParameter" elements.
1586:             *
1587:             * @param resCntr
1588:             * @param invokable The list of formal parameters
1589:             * @param elements  The list of "FormalParameter" elements
1590:             * @throws XPDLParserException
1591:             */
1592:            protected void loadFormalParameters(ResourceContainer resCntr,
1593:                    Invokable invokable, List elements)
1594:                    throws XPDLParserException, PropertyVetoException {
1595:
1596:                Iterator iter = elements.iterator();
1597:                while (iter.hasNext()) {
1598:                    Element fpElem = (Element) iter.next();
1599:                    invokable.add(createFormalParameter(resCntr, fpElem));
1600:                }
1601:            }
1602:
1603:            protected FormalParameter createFormalParameter(
1604:                    ResourceContainer resCntr, Element element)
1605:                    throws XPDLParserException, PropertyVetoException {
1606:
1607:                DataType dataType = createDataType(resCntr, Util.child(element,
1608:                        DATA_TYPE));
1609:                if (dataType == null) {
1610:                    throw new ElementRequiredException(DATA_TYPE,
1611:                            XPDLMessages.DATA_TYPE_REQUIRED);
1612:                }
1613:
1614:                FormalParameter param = new FormalParameter(element
1615:                        .attributeValue(ID), element.attributeValue(INDEX),
1616:                        element.attributeValue(MODE), dataType, Util
1617:                                .elementAsString(element, DESCRIPTION));
1618:
1619:                if (_logger.isDebugEnabled())
1620:                    _logger.debug(MSG_CREATED + param);
1621:
1622:                return param;
1623:            }
1624:
1625:            // Actual Parameters
1626:
1627:            /**
1628:             * Load actual parameters from the given Element.  The element should
1629:             * represent a collection of actual parameters (which is identified by the
1630:             * "ActualParameters" tag).
1631:             *
1632:             * @param invocation The list of actual parameters
1633:             * @param element    The "ActualParameters" element
1634:             * @throws XPDLParserException
1635:             */
1636:            protected void loadActualParameters(Invocation invocation,
1637:                    Element element) throws XPDLParserException,
1638:                    PropertyVetoException {
1639:
1640:                if (element == null)
1641:                    return;
1642:
1643:                loadActualParameters(invocation, Util.children(element,
1644:                        ACTUAL_PARAMETER));
1645:            }
1646:
1647:            /**
1648:             * Load the actual parameters objects from the given list of
1649:             * "ActualParameter" elements.
1650:             *
1651:             * @param invocation The list of actual parameters
1652:             * @param elements   The list of "ActualParameter" elements
1653:             * @throws XPDLParserException
1654:             */
1655:            protected void loadActualParameters(Invocation invocation,
1656:                    List elements) throws XPDLParserException,
1657:                    PropertyVetoException {
1658:
1659:                Iterator iter = elements.iterator();
1660:                while (iter.hasNext()) {
1661:                    Element actualParameterElement = (Element) iter.next();
1662:                    invocation
1663:                            .add(createActualParameter(actualParameterElement));
1664:                }
1665:            }
1666:
1667:            protected ActualParameter createActualParameter(Element element)
1668:                    throws XPDLParserException {
1669:
1670:                ActualParameter actualParm = new ActualParameter(element
1671:                        .getText());
1672:                if (_logger.isDebugEnabled())
1673:                    _logger.debug(MSG_CREATED + actualParm);
1674:
1675:                return actualParm;
1676:            }
1677:
1678:            // DataType
1679:
1680:            protected DataType createDataType(ResourceContainer resCntr,
1681:                    Element element) throws XPDLParserException,
1682:                    PropertyVetoException {
1683:
1684:                DataType dataType = new DataType(createType(resCntr, element));
1685:                if (_logger.isDebugEnabled())
1686:                    _logger.debug(MSG_CREATED + dataType);
1687:
1688:                return dataType;
1689:            }
1690:
1691:            protected Type createType(ResourceContainer resCntr, Element parent)
1692:                    throws XPDLParserException, PropertyVetoException {
1693:
1694:                List list = parent.elements();
1695:                if (list.size() < 1)
1696:                    throw new ElementRequiredException(TYPE,
1697:                            XPDLMessages.TYPE_REQUIRED);
1698:
1699:                Type type = null;
1700:
1701:                Element typeElement = (Element) list.get(0);
1702:                String typeName = typeElement.getName();
1703:                if (typeName.equals(BASIC_TYPE)) {
1704:                    type = BasicType.valueOf(typeElement.attributeValue(TYPE));
1705:                } else if (typeName.equals(DECLARED_TYPE)) {
1706:                    XPDLPackage pkg = resCntr instanceof  XPDLPackage ? (XPDLPackage) resCntr
1707:                            : ((WorkflowProcess) resCntr).getPackage();
1708:                    String refid = typeElement.attributeValue(ID);
1709:                    for (int i = 0, n = pkg.getTypeDeclaration().length; i < n; i++) {
1710:                        TypeDeclaration typeDecl = pkg.getTypeDeclaration(i);
1711:                        if (typeDecl.getId().equals(refid)) {
1712:                            type = new DeclaredType(typeDecl);
1713:                            break;
1714:                        }
1715:                    }
1716:                    if (type == null) {
1717:                        throw new XPDLParserException(
1718:                                "Undefined TypeDeclaration reference: " + refid);
1719:                    }
1720:                } else if (typeName.equals(SCHEMA_TYPE)) {
1721:                    type = createSchemaType(typeElement);
1722:                } else if (typeName.equals(EXTERNAL_REFERENCE)) {
1723:                    return createExternalReference(typeElement);
1724:                } else if (typeName.equals(RECORD_TYPE)) {
1725:                    RecordType recType = new RecordType();
1726:                    loadMembers(resCntr, Util.children(typeElement, MEMBER),
1727:                            recType);
1728:                    type = recType;
1729:                } else if (typeName.equals(UNION_TYPE)) {
1730:                    UnionType unionType = new UnionType();
1731:                    loadMembers(resCntr, Util.children(typeElement, MEMBER),
1732:                            unionType);
1733:                    type = unionType;
1734:                } else if (typeName.equals(ENUMERATION_TYPE)) {
1735:                    EnumerationType enumType = new EnumerationType();
1736:                    loadEnumerationValues(Util.children(typeElement,
1737:                            ENUMERATION_VALUE), enumType);
1738:                    type = enumType;
1739:                } else if (typeName.equals(ARRAY_TYPE)) {
1740:                    type = new ArrayType(createType(resCntr, typeElement),
1741:                            typeElement.attributeValue(LOWER_INDEX),
1742:                            typeElement.attributeValue(UPPER_INDEX));
1743:                } else if (typeName.equals(LIST_TYPE)) {
1744:                    type = new ListType(createType(resCntr, typeElement));
1745:                }
1746:                if (type == null) {
1747:                    throw new XPDLParserException("Illegal type name: "
1748:                            + typeName);
1749:                }
1750:
1751:                if (_logger.isDebugEnabled())
1752:                    _logger.debug("Created Type: " + type);
1753:
1754:                return type;
1755:            }
1756:
1757:            protected SchemaType createSchemaType(Element typeElement)
1758:                    throws XPDLParserException {
1759:
1760:                SchemaType schemaType = new SchemaType();
1761:                List list = typeElement.elements();
1762:                if (!list.isEmpty()) {
1763:                    if (list.size() > 1)
1764:                        _logger
1765:                                .warn("Additional SchemaType child elements ignored");
1766:                    try {
1767:                        schemaType.setText(Util.exportToText((Element) list
1768:                                .get(0)));
1769:                    } catch (XMLException e) {
1770:                        throw new XPDLParserException(e);
1771:                    }
1772:                }
1773:                return schemaType;
1774:            }
1775:
1776:            protected void loadMembers(ResourceContainer resCntr,
1777:                    List elements, ComplexType complexType)
1778:                    throws XPDLParserException, PropertyVetoException {
1779:
1780:                Iterator memberElements = elements.iterator();
1781:                while (memberElements.hasNext()) {
1782:                    Element memberElement = (Element) memberElements.next();
1783:                    Type type = createType(resCntr, memberElement);
1784:                    complexType.add(type);
1785:                }
1786:            }
1787:
1788:            protected void loadEnumerationValues(List elements,
1789:                    EnumerationType type) throws XPDLParserException,
1790:                    PropertyVetoException {
1791:
1792:                Iterator valueElements = elements.iterator();
1793:                while (valueElements.hasNext()) {
1794:                    Element valueElement = (Element) valueElements.next();
1795:                    type.add(new EnumerationValue(valueElement
1796:                            .attributeValue(NAME)));
1797:                }
1798:            }
1799:
1800:            // Type Declarations
1801:
1802:            /**
1803:             * Load type declarations from the given Element.  The element should
1804:             * represent a collection of type declarations (which is identified by the
1805:             * "TypeDeclarations" tag).
1806:             *
1807:             * @param pkg
1808:             * @param element The "TypeDeclarations" element
1809:             * @throws XPDLParserException
1810:             */
1811:            protected void loadTypeDeclarations(XPDLPackage pkg, Element element)
1812:                    throws XPDLParserException, PropertyVetoException {
1813:
1814:                if (element == null)
1815:                    return;
1816:
1817:                loadTypeDeclarations(pkg, Util.children(element,
1818:                        TYPE_DECLARATION));
1819:            }
1820:
1821:            /**
1822:             * Load the type declaration objects from the given list of
1823:             * "TypeDeclaration" elements.
1824:             *
1825:             * @param pkg
1826:             * @param elements The list of "TypeDeclaration" elements
1827:             * @throws XPDLParserException
1828:             */
1829:            protected void loadTypeDeclarations(XPDLPackage pkg, List elements)
1830:                    throws XPDLParserException, PropertyVetoException {
1831:
1832:                Iterator iter = elements.iterator();
1833:                while (iter.hasNext()) {
1834:                    Element typeDeclElem = (Element) iter.next();
1835:                    pkg.add(createTypeDeclaration(pkg, typeDeclElem));
1836:                }
1837:            }
1838:
1839:            protected TypeDeclaration createTypeDeclaration(XPDLPackage pkg,
1840:                    Element element) throws XPDLParserException,
1841:                    PropertyVetoException {
1842:
1843:                Type type = createType(pkg, element);
1844:
1845:                TypeDeclaration typeDeclaration = new TypeDeclaration(element
1846:                        .attributeValue(ID), element.attributeValue(NAME), type);
1847:
1848:                typeDeclaration.setDescription(Util.elementAsString(element,
1849:                        DESCRIPTION));
1850:
1851:                typeDeclaration.setExtendedAttributes(loadExtendedAttributes(
1852:                        pkg, element));
1853:
1854:                return typeDeclaration;
1855:            }
1856:
1857:            // Data Fields
1858:
1859:            /**
1860:             * Load data fields from the given Element.  The element should represent a
1861:             * collection of data fields (which is identified by the "DataFields" tag).
1862:             *
1863:             * @param resCntr
1864:             * @param element The "DataFields" element
1865:             * @throws XPDLParserException
1866:             */
1867:            protected void loadDataFields(ResourceContainer resCntr,
1868:                    Element element) throws XPDLParserException,
1869:                    PropertyVetoException {
1870:
1871:                if (element == null)
1872:                    return;
1873:
1874:                loadDataFields(resCntr, Util.children(element, DATA_FIELD));
1875:            }
1876:
1877:            /**
1878:             * Load the data field objects from the given list of "DataField" elements.
1879:             *
1880:             * @param resCntr
1881:             * @param elements The list of "DataField" elements
1882:             * @throws XPDLParserException
1883:             */
1884:            protected void loadDataFields(ResourceContainer resCntr,
1885:                    List elements) throws XPDLParserException,
1886:                    PropertyVetoException {
1887:
1888:                Iterator iter = elements.iterator();
1889:                while (iter.hasNext()) {
1890:                    Element dataFieldElement = (Element) iter.next();
1891:                    resCntr.add(createDataField(resCntr, dataFieldElement));
1892:                }
1893:
1894:                _logger.debug("Data fields size after load: "
1895:                        + resCntr.getDataField().length);
1896:            }
1897:
1898:            protected DataField createDataField(ResourceContainer resCntr,
1899:                    Element element) throws XPDLParserException,
1900:                    PropertyVetoException {
1901:
1902:                DataType dataType = createDataType(resCntr, Util.child(element,
1903:                        DATA_TYPE));
1904:                if (dataType == null)
1905:                    throw new ElementRequiredException(DATA_TYPE,
1906:                            XPDLMessages.DATA_TYPE_REQUIRED);
1907:
1908:                DataField dataField = new DataField(element.attributeValue(ID),
1909:                        element.attributeValue(NAME), dataType);
1910:
1911:                String isArrayString = element.attributeValue(IS_ARRAY);
1912:                dataField.setArray(Boolean.valueOf(isArrayString)
1913:                        .booleanValue());
1914:                dataField.setDescription(Util.elementAsString(element,
1915:                        DESCRIPTION));
1916:                dataField.setInitialValue(Util.elementAsString(element,
1917:                        INITIAL_VALUE));
1918:                dataField.setLength(Util.elementAsInteger(element, LENGTH));
1919:                dataField.setExtendedAttributes(loadExtendedAttributes(resCntr,
1920:                        element));
1921:
1922:                if (_logger.isDebugEnabled())
1923:                    _logger.debug(MSG_CREATED + dataField);
1924:
1925:                return dataField;
1926:            }
1927:
1928:            // External Reference
1929:
1930:            /**
1931:             * Create an ExternalReference object from the given Element.
1932:             *
1933:             * @param element The "ExternalReference" element
1934:             * @return The ExternalReference object
1935:             * @throws XPDLParserException
1936:             */
1937:            protected ExternalReference createExternalReference(Element element)
1938:                    throws XPDLParserException {
1939:
1940:                ExternalReference externalReference = new ExternalReference(
1941:                        element.attributeValue(LOCATION), element
1942:                                .attributeValue(XREF), element
1943:                                .attributeValue(NAMESPACE));
1944:
1945:                if (_logger.isDebugEnabled())
1946:                    _logger.debug(MSG_CREATED + externalReference);
1947:
1948:                return externalReference;
1949:            }
1950:
1951:            // External Attributes
1952:
1953:            /**
1954:             * Load extended attributes from the given parent.  If the element has a
1955:             * child &lt;ExtendedAttributes&gt; element, the latter's child
1956:             * &lt;ExtendedAttribute&gt; elements recognized by OBE are parsed into the
1957:             * <code>extendedAttributes</code> map and removed from their parent. Any
1958:             * remaining 3rd party elements are detached and added to a new document,
1959:             * which becomes the method's return value.
1960:             *
1961:             * @param resCntr
1962:             * @param parent  The parent element.
1963:             * @return A DOM document containing any 3rd party attributes (can be
1964:             *         <code>null</code>).
1965:             * @throws XPDLParserException
1966:             */
1967:            protected ExtendedAttributes loadExtendedAttributes(
1968:                    ResourceContainer resCntr, Element parent)
1969:                    throws XPDLParserException, PropertyVetoException {
1970:
1971:                return loadExtendedAttributes(parent, null);
1972:            }
1973:
1974:            /**
1975:             * Load extended attributes from the given parent.  If the element has a
1976:             * child &lt;ExtendedAttributes&gt; element, the latter's child
1977:             * &lt;ExtendedAttribute&gt; elements recognized by OBE are parsed into the
1978:             * <code>extendedAttributes</code> map and removed from their parent. Any
1979:             * remaining 3rd party elements are detached and added to a new document,
1980:             * which becomes the method's return value.
1981:             *
1982:             * @param parent        The parent element.
1983:             * @param obeExtAttrMap Map of parsed OBE extended attributes.
1984:             * @return A DOM document containing any 3rd party attributes (can be
1985:             *         <code>null</code>).
1986:             * @throws XPDLParserException
1987:             */
1988:            protected ExtendedAttributes loadExtendedAttributes(Element parent,
1989:                    Map obeExtAttrMap) throws XPDLParserException,
1990:                    PropertyVetoException {
1991:
1992:                Element extAttrsElem = Util.child(parent, EXTENDED_ATTRIBUTES);
1993:                if (extAttrsElem == null)
1994:                    return null;
1995:
1996:                List elements = Util.children(extAttrsElem, EXTENDED_ATTRIBUTE);
1997:                if (elements.isEmpty())
1998:                    return null;
1999:
2000:                if (_logger.isDebugEnabled()) {
2001:                    _logger.debug("Loading extended attributes [size="
2002:                            + elements.size() + ']');
2003:                }
2004:
2005:                for (Iterator iter = elements.iterator(); iter.hasNext();) {
2006:                    Element element = (Element) iter.next();
2007:                    String name = element.attributeValue(NAME);
2008:                    Object value;
2009:                    if (name.equals(OBE_ASSIGNMENT_STRATEGY)) {
2010:                        Element strategyElement = Util.detach(element,
2011:                                ASSIGNMENT_STRATEGY_QNAME);
2012:                        value = createAssignmentStrategy(strategyElement);
2013:                    } else if (name.equals(OBE_BOUNDS)) {
2014:                        Element boundsElement = Util.detach(element,
2015:                                BOUNDS_QNAME);
2016:                        value = createBounds(boundsElement);
2017:                    } else if (name.equals(OBE_CALENDAR)) {
2018:                        element.detach();
2019:                        value = element.attributeValue(VALUE);
2020:                    } else if (name.equals(OBE_COMPLETION_STRATEGY)) {
2021:                        element.detach();
2022:                        value = element.attributeValue(VALUE);
2023:                    } else if (name.equals(OBE_EVENT)) {
2024:                        Element eventElement = Util
2025:                                .detach(element, EVENT_QNAME);
2026:                        value = createEvent(eventElement);
2027:                    } else if (name.equals(OBE_TIMER)) {
2028:                        Element timerElement = Util
2029:                                .detach(element, TIMER_QNAME);
2030:                        value = createTimer(timerElement);
2031:                    } else if (name.equals(EXECUTION)) {
2032:                        element.detach();
2033:                        String tag = element.attributeValue(VALUE);
2034:                        value = ExecutionType.valueOf(tag);
2035:                    } else if (name.equals(OBE_LOOP)) {
2036:                        Element loopElement = Util.detach(element, LOOP_QNAME);
2037:                        value = createLoop(loopElement);
2038:                    } else if (name.equals(OBE_TOOL_MODE)) {
2039:                        element.detach();
2040:                        value = ToolMode.valueOf(element.attributeValue(VALUE));
2041:                    } else {
2042:                        // Don't put 3rd party ext attrs into our map.
2043:                        continue;
2044:                    }
2045:                    iter.remove();
2046:                    if (obeExtAttrMap != null) {
2047:                        obeExtAttrMap.put(name, value);
2048:
2049:                        if (_logger.isDebugEnabled()) {
2050:                            _logger.debug("Added OBE extended attribute ["
2051:                                    + name + '=' + value + ']');
2052:                        }
2053:                    }
2054:                }
2055:                ExtendedAttributes extAttrs = null;
2056:                try {
2057:                    // If anything remains after removing the OBE extended attributes,
2058:                    // they are 3rd party extended attributes and must be extracted into
2059:                    // an ExtendedAttributes object.
2060:                    if (!elements.isEmpty()) {
2061:                        // Ensure that the ExtendedAttributes element is in the XPDL
2062:                        // namespace, either explicitly with the correct QName, or
2063:                        // implicitly by a default namespace declaration.  This step is
2064:                        // necessary because some tools, such as the Cape Visions XPDL
2065:                        // Visio plugin, use a default namespace which we'd otherwise
2066:                        // lose when exporting the extended attributes element to its
2067:                        // own 'doclet' within the ExtendedAttributes object.
2068:                        if ("".equals(extAttrsElem.getNamespaceURI())) {
2069:                            boolean foundDefaultXPDLNS = false;
2070:                            List namespaces = extAttrsElem.declaredNamespaces();
2071:                            for (int i = 0, n = namespaces.size(); i < n; i++) {
2072:                                Namespace ns = (Namespace) namespaces.get(i);
2073:                                if ("".equals(ns.getPrefix())
2074:                                        && ns.getURI().equals(XPDL_NS_URI)) {
2075:
2076:                                    foundDefaultXPDLNS = true;
2077:                                    break;
2078:                                }
2079:                            }
2080:                            if (!foundDefaultXPDLNS)
2081:                                namespaces.add(new Namespace("", XPDL_NS_URI));
2082:                        }
2083:                        extAttrs = new ExtendedAttributes(Util
2084:                                .exportToText(extAttrsElem));
2085:
2086:                        if (_logger.isDebugEnabled())
2087:                            _logger.debug(MSG_CREATED + extAttrs);
2088:                    }
2089:                } catch (XMLException e) {
2090:                    throw new XPDLParserException(e);
2091:                }
2092:
2093:                return extAttrs;
2094:            }
2095:
2096:            protected Rectangle createBounds(Element boundsElement) {
2097:                Rectangle rect = null;
2098:
2099:                if (boundsElement != null) {
2100:                    Integer x = parseIntAttribute(boundsElement, X);
2101:                    Integer y = parseIntAttribute(boundsElement, Y);
2102:                    Integer width = parseIntAttribute(boundsElement, WIDTH);
2103:                    Integer height = parseIntAttribute(boundsElement, HEIGHT);
2104:
2105:                    if (x != null && y != null) {
2106:                        if (width == null)
2107:                            width = new Integer(DEFAULT_WIDTH);
2108:                        if (height == null)
2109:                            height = new Integer(DEFAULT_HEIGHT);
2110:                        rect = new Rectangle(x.intValue(), y.intValue(), width
2111:                                .intValue(), height.intValue());
2112:
2113:                        if (_logger.isDebugEnabled())
2114:                            _logger.debug(MSG_CREATED + rect);
2115:                    } else {
2116:                        _logger
2117:                                .warn("Incomplete obe:Bounds specification ignored");
2118:                    }
2119:                }
2120:
2121:                return rect;
2122:            }
2123:
2124:            protected Integer parseIntAttribute(Element element,
2125:                    String attribute) {
2126:                String s = element.attributeValue(attribute);
2127:                return s == null || s.length() == 0 ? null : Integer.valueOf(s);
2128:            }
2129:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.