Source Code Cross Referenced for XPDLSessionImportBean.java in  » Workflow-Engines » bonita-v3.1 » hero » session » 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 » bonita v3.1 » hero.session 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package hero.session;
0002:
0003:        import javax.xml.parsers.DocumentBuilder;
0004:        import javax.xml.parsers.DocumentBuilderFactory;
0005:        import javax.xml.parsers.ParserConfigurationException;
0006:
0007:        import hero.interfaces.Constants.Nd;
0008:        import hero.interfaces.Constants.Pj;
0009:        import hero.interfaces.Constants.PerformerAssigment;
0010:        import hero.interfaces.Constants.Hook;
0011:        import hero.interfaces.Constants.Mapper;
0012:        import hero.interfaces.BnLdap;
0013:        import hero.interfaces.BnLdapHome;
0014:        import hero.interfaces.BnLdapUtil;
0015:        import hero.interfaces.BnProjectPropertyValue;
0016:        import hero.interfaces.BnUserLocalHome;
0017:        import hero.interfaces.BnRoleLocal;
0018:        import hero.interfaces.BnProjectLocalHome;
0019:        import hero.interfaces.ProjectSessionLocalHome;
0020:        import hero.interfaces.ProjectSessionLocal;
0021:
0022:        import hero.xpdl.XPDLDTDs;
0023:        import hero.xpdl.XPDLDataField;
0024:        import hero.xpdl.XPDLFormalParameter;
0025:        import hero.xpdl.XPDLHook;
0026:        import hero.xpdl.XPDLInitiatorMapper;
0027:        import hero.xpdl.XPDLSchemas;
0028:        import hero.xpdl.XPDLActivity;
0029:        import hero.xpdl.XPDLParticipant;
0030:        import hero.xpdl.XPDLApplication;
0031:        import hero.xpdl.XPDLTransition;
0032:        import hero.xpdl.XPDLWFProcess;
0033:        import hero.xpdl.XPDLConstants;
0034:        import hero.xpdl.BonitaTree;
0035:        import hero.xpdl.JEntityResolver;
0036:
0037:        import hero.util.EventConstants;
0038:        import hero.util.HeroException;
0039:        import hero.util.XPDLException;
0040:
0041:        import javax.ejb.CreateException;
0042:        import javax.ejb.SessionBean;
0043:        import javax.ejb.SessionContext;
0044:        import javax.naming.NamingException;
0045:
0046:        import org.w3c.dom.Attr;
0047:        import org.w3c.dom.Document;
0048:        import org.w3c.dom.Element;
0049:        import org.w3c.dom.NamedNodeMap;
0050:        import org.w3c.dom.Node;
0051:        import org.w3c.dom.NodeList;
0052:        import org.w3c.dom.Text;
0053:        import org.xml.sax.ErrorHandler;
0054:        import org.xml.sax.helpers.XMLFilterImpl;
0055:
0056:        import java.io.ByteArrayInputStream;
0057:        import java.io.File;
0058:        import java.io.InputStream;
0059:        import java.util.ArrayList;
0060:        import java.util.Collection;
0061:        import java.util.GregorianCalendar;
0062:        import java.util.HashSet;
0063:        import java.util.Hashtable;
0064:        import java.util.Iterator;
0065:        import java.util.Set;
0066:        import java.util.StringTokenizer;
0067:
0068:        /**
0069:         * Session Bean Template
0070:         *
0071:         * @ejb:bean name="XPDLSessionImport"
0072:         *           display-name="XPDLSessionImport Bean"
0073:         *           type="Stateless"
0074:         *           transaction-type="Container"
0075:         *           jndi-name="ejb/hero/XPDLSessionImport"
0076:         *           local-jndi-name="ejb/hero/XPDLSessionImport_L"
0077:         *
0078:         * @ejb:transaction type="Supports"
0079:         * @ejb.permission role-name="Admin,user,SuperAdmin"
0080:         * @jonas.bean
0081:         *      ejb-name="XPDLSessionImport"
0082:         *      jndi-name="ejb/hero/XPDLSessionImport"
0083:         *
0084:         *
0085:         **/
0086:
0087:        public class XPDLSessionImportBean implements  SessionBean,
0088:                XPDLConstants {
0089:
0090:            // -------------------------------------------------------------------------
0091:            // Members
0092:            // -------------------------------------------------------------------------
0093:
0094:            private SessionContext mContext;
0095:            private ProjectSessionLocalHome pHome;
0096:            private BnUserLocalHome userhome;
0097:
0098:            // -------------------------------------------------------------------------
0099:            // Methods
0100:            // -------------------------------------------------------------------------
0101:
0102:            /**
0103:             * getProjectWithVersion
0104:             *
0105:             * @ejb.permission unchecked="yes"
0106:             * @ejb:interface-method view-type="both"
0107:             * @ejb:transaction type="Required"
0108:             *
0109:             **/
0110:
0111:            public String openMainDocumentAndReturnProject(
0112:                    String xpdlRepository, String fileName, String xpdlString)
0113:                    throws XPDLException {
0114:                String projectWithVersion = openMainDocument(xpdlRepository,
0115:                        fileName, xpdlString, false);
0116:                return projectWithVersion;
0117:            }
0118:
0119:            /**
0120:             *        Parsing the xpdl file
0121:             * @param String xpdlRepository - The path of the repository
0122:             * @param String fileName  - The name the xpdl file
0123:             * @param String xpdlString - The xpdl file as string
0124:             * @param boolean traceDebug  - set debug trace
0125:             * @return projectWithVersion - the project name with the version
0126:             *
0127:             * @ejb.permission unchecked="yes"
0128:             * @ejb:interface-method view-type="both"
0129:             * @ejb:transaction type="Required"
0130:             *
0131:             **/
0132:
0133:            public String openMainDocument(String xpdlRepository,
0134:                    String fileName, String xpdlString, boolean traceDebug)
0135:                    throws XPDLException {
0136:                //debug
0137:                //System.out.println("openMainDocument: File = " + xpdlRepository + fileName );
0138:                //System.out.println("openMainDocument: xpdlFileName = " +     xpdlFileName);
0139:
0140:                Hashtable xpdlData;
0141:                Hashtable actMapping;
0142:                // Activity sets
0143:                Hashtable activitySetMapping;
0144:                // Participants : id / XPDLParticipant
0145:                Hashtable partMapping;
0146:                // For applications id / XPDLApplication
0147:                Hashtable appliMapping;
0148:                // DataFields : id / XPDLDataField
0149:                Hashtable dataFieldMapping;
0150:                // DataFields introduced to get same property order as FormEditor
0151:                ArrayList array_dataFieldKey;
0152:                // WF Process : id / XPDLWFProcess
0153:                Hashtable wfProcessMapping;
0154:                // For transitions
0155:                Hashtable transitionMapping;
0156:                // for process version
0157:                String projNameWithVersion = "";
0158:
0159:                xpdlData = new Hashtable();
0160:                actMapping = new Hashtable();
0161:                activitySetMapping = new Hashtable();
0162:                partMapping = new Hashtable();
0163:                appliMapping = new Hashtable();
0164:                dataFieldMapping = new Hashtable();
0165:                array_dataFieldKey = new ArrayList();
0166:                wfProcessMapping = new Hashtable();
0167:                transitionMapping = new Hashtable();
0168:
0169:                xpdlData.put("actMapping", actMapping);
0170:                xpdlData.put("activitySetMapping", activitySetMapping);
0171:                xpdlData.put("partMapping", partMapping);
0172:                xpdlData.put("appliMapping", appliMapping);
0173:                xpdlData.put("dataFieldMapping", dataFieldMapping);
0174:                xpdlData.put("array_dataFieldKey", array_dataFieldKey);
0175:                xpdlData.put("wfProcessMapping", wfProcessMapping);
0176:                xpdlData.put("transitionMapping", transitionMapping);
0177:                xpdlData.put("projNameWithVersion", projNameWithVersion);
0178:                openDocument(xpdlRepository, fileName, xpdlString, xpdlData);
0179:
0180:                //Call print debug if trace_debug == true
0181:                if (traceDebug == true)
0182:                    printHashTables(xpdlData);
0183:
0184:                return (String) xpdlData.get("projNameWithVersion");
0185:            }
0186:
0187:            private void openDocument(String xpdlRepository, String fileName,
0188:                    String xpdlString, Hashtable xpdlData) throws XPDLException {
0189:                DocumentBuilderFactory dbf = DocumentBuilderFactory
0190:                        .newInstance();
0191:                dbf.setValidating(true);
0192:                dbf
0193:                        .setAttribute(
0194:                                "http://apache.org/xml/features/dom/include-ignorable-whitespace",
0195:                                new Boolean(false));
0196:                dbf.setAttribute(
0197:                        "http://apache.org/xml/features/validation/schema",
0198:                        new Boolean(true));
0199:                dbf.setAttribute(
0200:                        "http://apache.org/xml/features/allow-java-encodings",
0201:                        new Boolean(true));
0202:                dbf.setNamespaceAware(true);
0203:
0204:                DocumentBuilder docBuilder = null;
0205:                try {
0206:                    docBuilder = dbf.newDocumentBuilder();
0207:                    ErrorHandler eh = new XMLFilterImpl();
0208:                    docBuilder.setErrorHandler(eh);
0209:                } catch (ParserConfigurationException pce) {
0210:                    throw new XPDLException(
0211:                            "Cannot build a document builder : "
0212:                                    + pce.getMessage(), pce);
0213:                }
0214:                JEntityResolver jer = new JEntityResolver();
0215:                jer.addSchemas(new XPDLSchemas());
0216:                jer.addDtds(new XPDLDTDs());
0217:                docBuilder.setEntityResolver(jer);
0218:
0219:                InputStream inputStream = (InputStream) new ByteArrayInputStream(
0220:                        xpdlString.getBytes());
0221:
0222:                Document document = null;
0223:                try {
0224:                    document = docBuilder.parse(inputStream);
0225:                } catch (Exception e) {
0226:                    throw new XPDLException("Cannot parse XPDL :"
0227:                            + e.getMessage(), e);
0228:                }
0229:
0230:                Element rootElement = document.getDocumentElement();
0231:                //NodeList LesFils = rootElement.getChildNodes();
0232:
0233:                if (rootElement.hasChildNodes()) {
0234:                    BonitaTree root = new BonitaTree(rootElement);
0235:                    BonitaTree external = getNode(root, EXTERNAL_PACKAGES);
0236:                    //External Packages definitions parsing
0237:                    if (external != null) {
0238:                        obtainExternalPackage(external, xpdlRepository,
0239:                                xpdlData);
0240:                    }
0241:
0242:                    //Get package definitions containing : Participants, Applications , DataFields
0243:                    // from the Package level
0244:                    obtainParticipant(getNode(root, PARTICIPANTS),
0245:                            PACKAGE_LEVEL, xpdlData);
0246:                    obtainApplication(getNode(root, APPLICATIONS),
0247:                            PACKAGE_LEVEL, xpdlData);
0248:                    //debug
0249:                    //System.out.println("****!!! Calling   obtainDataField in openDocument - projectName = PACKAGE"  );
0250:                    obtainDataField(getNode(root, DATAFIELDS), PACKAGE_LEVEL,
0251:                            xpdlData);
0252:
0253:                    //Workflow processes parsing
0254:                    obtainProject(root, xpdlData);
0255:                }
0256:
0257:            }
0258:
0259:            /*
0260:             *   Get all defined External Packages name
0261:             *   and call openDocument() for each of them
0262:             */
0263:            private void obtainExternalPackage(BonitaTree bonitaTree,
0264:                    String xpdlRepository, Hashtable xpdlData)
0265:                    throws XPDLException {
0266:
0267:                if ((bonitaTree.Noeud.getNodeName())
0268:                        .equalsIgnoreCase(EXTERNAL_PACKAGES)) {
0269:                    // debug
0270:                    //System.out.println("External Packages...");
0271:                    for (int j = 0; j < bonitaTree.NbFils; j++) {
0272:                        if ((bonitaTree.Fils[j].Noeud.getNodeName())
0273:                                .equalsIgnoreCase(EXTERNAL_PACKAGE)) {
0274:                            Element external = (Element) bonitaTree.Fils[j].Noeud;
0275:                            String href = external
0276:                                    .getAttribute(EXTERNAL_PACKAGE_HREF);
0277:                            String xpdl_file = "";
0278:                            //debug
0279:                            //System.out.println("External Package="+href);
0280:                            try {
0281:                                String filename = xpdlRepository
0282:                                        + File.separator + href;
0283:                                java.io.BufferedReader buff = new java.io.BufferedReader(
0284:                                        new java.io.FileReader(filename));
0285:                                String line = "";
0286:                                line = buff.readLine();
0287:                                while ((line = buff.readLine()) != null)
0288:                                    xpdl_file = xpdl_file + line;
0289:
0290:                            } catch (Exception e) {
0291:                                throw new XPDLException(
0292:                                        "Error buffering the XPDL file : "
0293:                                                + e.getMessage(), e);
0294:                            }
0295:                            // open the xpdl document
0296:                            openDocument(xpdlRepository, href, xpdl_file,
0297:                                    xpdlData);
0298:                        }
0299:                    }
0300:                }
0301:            }
0302:
0303:            /*
0304:             * Get all WorkFlow Processes and call createProject for all of them
0305:             */
0306:            private void obtainProject(BonitaTree n, Hashtable xpdlData)
0307:                    throws XPDLException {
0308:                BonitaTree completeTree = n;
0309:                n = getNode(n, WORKFLOW_PROCESSES);
0310:                if (n != null) {
0311:                    int type = n.Noeud.getNodeType();
0312:                    String projectName = "";
0313:
0314:                    if (type == Node.ELEMENT_NODE) {
0315:                        if ((n.Noeud.getNodeName())
0316:                                .equalsIgnoreCase(WORKFLOW_PROCESSES)) {
0317:                            for (int j = 0; j < n.NbFils; j++) {
0318:                                if ((n.Fils[j].Noeud.getNodeName())
0319:                                        .equalsIgnoreCase(WORKFLOW_PROCESS)) {
0320:                                    // search for Version of the Workflow Process
0321:                                    String projectVersion = null;
0322:                                    Text versionValue = null;
0323:                                    BonitaTree currentWf = n.Fils[j];
0324:                                    NodeList listWFProcessNode = currentWf.Noeud
0325:                                            .getChildNodes();
0326:                                    int size = listWFProcessNode.getLength();
0327:                                    // get RedefinableHeader tag
0328:                                    if (size > 0) {
0329:                                        Element elementRedefinableHeader = null;
0330:                                        for (int i = 0; i < size; i++) {
0331:                                            int ty = listWFProcessNode.item(i)
0332:                                                    .getNodeType();
0333:                                            String nodeName = listWFProcessNode
0334:                                                    .item(i).getNodeName();
0335:                                            if (ty == (Node.ELEMENT_NODE)
0336:                                                    && (WORKFLOW_PROCESS_REDEFINABLEHEADER
0337:                                                            .equals(nodeName))) {
0338:                                                //debug
0339:                                                //System.out.println("node name = " + listWFProcessNode.item(i).getNodeName() );
0340:                                                elementRedefinableHeader = (Element) listWFProcessNode
0341:                                                        .item(i);
0342:                                                NodeList listElementsVersion = null;
0343:                                                listElementsVersion = elementRedefinableHeader
0344:                                                        .getElementsByTagName(WORKFLOW_PROCESS_VERSION);
0345:                                                versionValue = (Text) listElementsVersion
0346:                                                        .item(0)
0347:                                                        .getFirstChild();
0348:                                            }
0349:                                        }
0350:                                        //if (versionValue.getNodeValue() != null){
0351:                                        if (versionValue != null) {
0352:                                            projectVersion = versionValue
0353:                                                    .getNodeValue();
0354:                                            //debug
0355:                                            //System.out.println("getCreateSubProject: version = " + projectVersion );
0356:                                        } else {
0357:                                            projectVersion = EventConstants.DEFAULTPROJECTVERSION;
0358:                                            //debug
0359:                                            //System.out.println("getCreateSubProject: version = DEFAULT = " + projectVersion );
0360:                                        }
0361:                                    }
0362:
0363:                                    //get project name
0364:                                    Element element = (Element) n.Fils[j].Noeud;
0365:                                    projectName = element
0366:                                            .getAttribute(WORKFLOW_PROCESS_NAME);
0367:                                    String projectId = element
0368:                                            .getAttribute(WORKFLOW_PROCESS_ID);
0369:
0370:                                    if (!projectExist(projectName,
0371:                                            projectVersion)) {
0372:                                        if (!(projectName.equalsIgnoreCase(""))) {
0373:
0374:                                            //Trace
0375:                                            System.out
0376:                                                    .println("*** Start of Workflow Process creation : "
0377:                                                            + projectName
0378:                                                                    .toUpperCase());
0379:
0380:                                            createProject(n.Fils[j],
0381:                                                    projectName,
0382:                                                    projectVersion, projectId,
0383:                                                    completeTree, xpdlData);
0384:                                            //Trace
0385:                                            System.out
0386:                                                    .println("*** End of Workflow Process creation : "
0387:                                                            + projectName
0388:                                                                    .toUpperCase());
0389:                                        }
0390:                                    } else {
0391:                                        // If this process is used as subprocess it may has been already created
0392:                                        ArrayList ar_pn = new ArrayList();
0393:                                        Hashtable wfProcessMapping = (Hashtable) xpdlData
0394:                                                .get("wfProcessMapping");
0395:                                        Object[] tab = wfProcessMapping
0396:                                                .keySet().toArray();
0397:                                        for (int k = 0; k < tab.length; k++) {
0398:                                            //debug
0399:                                            //System.out.print("   - " + tab[k].toString());
0400:                                            XPDLWFProcess xpdlWFProcess = (XPDLWFProcess) wfProcessMapping
0401:                                                    .get(tab[k]);
0402:                                            ar_pn.add(xpdlWFProcess.getName());
0403:                                        }
0404:                                        if (!ar_pn.contains(projectName)) {
0405:                                            throw new XPDLException(
0406:                                                    "Error: Project = "
0407:                                                            + projectName
0408:                                                            + " is already existing in the Bonita Workflow Engine. ");
0409:                                        }
0410:                                    }
0411:                                }
0412:                            }
0413:                        }
0414:                    }
0415:                }
0416:            }
0417:
0418:            /*
0419:             *    Obtain the WorkFlow Process (used as subproject)
0420:             *    Call createProject if this project does not exist
0421:             *    Note :   this method is not called at now!
0422:             */
0423:            private String getCreateSubProject(String id, BonitaTree root,
0424:                    Hashtable xpdlData) throws XPDLException {
0425:                BonitaTree project = getNode(root, WORKFLOW_PROCESSES);
0426:                int type = project.Noeud.getNodeType();
0427:
0428:                if (type == Node.ELEMENT_NODE) {
0429:                    if ((project.Noeud.getNodeName())
0430:                            .equalsIgnoreCase(WORKFLOW_PROCESSES)) {
0431:                        for (int j = 0; j < project.NbFils; j++) {
0432:                            if ((project.Fils[j].Noeud.getNodeName())
0433:                                    .equalsIgnoreCase(WORKFLOW_PROCESS)) {
0434:                                // search for Version of the Workflow Process
0435:                                String projectVersion = null;
0436:                                Text versionValue = null;
0437:                                BonitaTree currentWf = project.Fils[j];
0438:                                NodeList listWFProcessNode = currentWf.Noeud
0439:                                        .getChildNodes();
0440:                                int size = listWFProcessNode.getLength();
0441:                                // get RedefinableHeader tag
0442:                                if (size > 0) {
0443:                                    Element elementRedefinableHeader = null;
0444:                                    for (int i = 0; i < size; i++) {
0445:                                        int ty = listWFProcessNode.item(i)
0446:                                                .getNodeType();
0447:                                        String nodeName = listWFProcessNode
0448:                                                .item(i).getNodeName();
0449:                                        if (ty == (Node.ELEMENT_NODE)
0450:                                                && (WORKFLOW_PROCESS_REDEFINABLEHEADER
0451:                                                        .equals(nodeName))) {
0452:                                            //debug
0453:                                            //System.out.println("node name = " + listWFProcessNode.item(i).getNodeName( );
0454:                                            elementRedefinableHeader = (Element) listWFProcessNode
0455:                                                    .item(i);
0456:                                            NodeList listElementsVersion = null;
0457:                                            listElementsVersion = elementRedefinableHeader
0458:                                                    .getElementsByTagName(WORKFLOW_PROCESS_VERSION);
0459:                                            versionValue = (Text) listElementsVersion
0460:                                                    .item(0).getFirstChild();
0461:                                        }
0462:                                    }
0463:                                    if (versionValue.getNodeValue() != null) {
0464:                                        projectVersion = versionValue
0465:                                                .getNodeValue();
0466:                                        //debug
0467:                                        //System.out.println("getCreateSubProject: version = " + projectVersion );
0468:                                    } else {
0469:                                        projectVersion = EventConstants.DEFAULTPROJECTVERSION;
0470:                                        //debug
0471:                                        //System.out.println("getCreateSubProject: version = DEFAULT = " + projectVersion );
0472:                                    }
0473:                                }
0474:
0475:                                // get project name
0476:                                Element element = (Element) project.Fils[j].Noeud;
0477:                                if (element.getAttribute(WORKFLOW_PROCESS_ID)
0478:                                        .equalsIgnoreCase(id)) {
0479:                                    String projectName = element
0480:                                            .getAttribute(WORKFLOW_PROCESS_NAME);
0481:                                    String projectId = element
0482:                                            .getAttribute(WORKFLOW_PROCESS_ID);
0483:
0484:                                    if (!projectExist(projectName,
0485:                                            projectVersion)) {
0486:                                        if (!(projectName.equalsIgnoreCase(""))) {
0487:                                            // addSubProcessDefinition(completeTree,projectName);
0488:                                            //Trace
0489:                                            System.out
0490:                                                    .println("*** Start of Workflow Process creation (used as subprocess): "
0491:                                                            + projectName
0492:                                                                    .toUpperCase());
0493:                                            createProject(project.Fils[j],
0494:                                                    projectName,
0495:                                                    projectVersion, projectId,
0496:                                                    root, xpdlData);
0497:                                            //Trace
0498:                                            System.out
0499:                                                    .println("*** End of Workflow Process creation : "
0500:                                                            + projectName
0501:                                                                    .toUpperCase());
0502:                                        }
0503:                                    }
0504:                                    return (projectName);
0505:                                }
0506:                            }
0507:                        }
0508:                    }
0509:                }
0510:                return null;
0511:            }
0512:
0513:            /*
0514:             *   Create the Bonita Project with all Workflow Process definitions
0515:             *   This is the heart method of this file that call :
0516:             *      - obtainActivitySet, obtainCreateActivity, obtain transition
0517:             * 		- obtainCreateActivity, obtainActivityData
0518:             */
0519:            private void createProject(BonitaTree project, String projectName,
0520:                    String projectVersion, String projectId, BonitaTree root,
0521:                    Hashtable xpdlData) throws XPDLException {
0522:                // create and init project Bean object
0523:                ProjectSessionLocal p = null;
0524:                try {
0525:                    pHome = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
0526:                            .getLocalHome();
0527:                } catch (NamingException na) {
0528:                    throw new XPDLException(na.getMessage(), na);
0529:                }
0530:                try {
0531:                    p = pHome.create();
0532:                } catch (javax.ejb.CreateException cr) {
0533:                    throw new XPDLException(cr.getMessage(), cr);
0534:                }
0535:                try {
0536:                    if (projectVersion == null) {
0537:                        p.initModel(projectName);
0538:                        xpdlData.put("projNameWithVersion", projectName + "."
0539:                                + EventConstants.DEFAULTPROJECTVERSION);
0540:                        //this.projNameWithVersion = projectName + "." + EventConstants.DEFAULTPROJECTVERSION ;
0541:                    } else {
0542:                        p.initModelWithVersion(projectName, projectVersion);
0543:                        xpdlData.put("projNameWithVersion", projectName + "."
0544:                                + projectVersion);
0545:                        //this.projNameWithVersion = projectName + "." + projectVersion;
0546:                    }
0547:                } catch (HeroException he) {
0548:                    throw new XPDLException(he.getMessage(), he);
0549:                }
0550:
0551:                // Get Participants , Applications, DataFields defined into the WorkFlow Process
0552:                obtainParticipant(getNode(project, PARTICIPANTS), projectName,
0553:                        xpdlData);
0554:                obtainApplication(getNode(project, APPLICATIONS), projectName,
0555:                        xpdlData);
0556:                obtainDataField(getNode(project, DATAFIELDS), projectName,
0557:                        xpdlData);
0558:
0559:                // Add properties to Bonita project with obtained datafields
0560:                createProcessProperties(p, xpdlData);
0561:
0562:                // Get hooks defined as external attributes into the Workflow Process
0563:                XPDLWFProcess xpdlWFProcess = new XPDLWFProcess();
0564:                xpdlWFProcess.setName(projectName);
0565:
0566:                // set the hashtable for process
0567:                Hashtable wfProcessMapping = (Hashtable) xpdlData
0568:                        .get("wfProcessMapping");
0569:                wfProcessMapping.put(projectId, xpdlWFProcess);
0570:
0571:                // Obtain the process hooks
0572:                //xpdlWFProcess = obtainProcessHook(getFilsNode (project, EXTENDED_ATTRIBUTES), xpdlWFProcess);
0573:                if (project != null) {
0574:                    BonitaTree extAttrs = null;
0575:                    BonitaTree extAttr = null;
0576:
0577:                    // List childs of WFProcess BonitaTree to search EXTENDED_ATTRIBUTES element
0578:                    for (int j = 0; j < project.NbFils; j++) {
0579:
0580:                        if ((project.Fils[j].Noeud.getNodeName())
0581:                                .equalsIgnoreCase(EXTENDED_ATTRIBUTES)) {
0582:                            extAttrs = project.Fils[j];
0583:                            for (int i = 0; i < extAttrs.NbFils; i++) {
0584:                                extAttr = extAttrs.Fils[i];
0585:                                if ((extAttr.Noeud.getNodeName())
0586:                                        .equalsIgnoreCase(EXTENDED_ATTRIBUTE)) {
0587:                                    // detect if it's a hook
0588:                                    Element element = (Element) extAttr.Noeud;
0589:                                    if (element
0590:                                            .getAttribute(
0591:                                                    EXTENDED_ATTRIBUTE_NAME)
0592:                                            .equalsIgnoreCase(
0593:                                                    EXTENDED_ATTRIBUTE_NAME_HOOK)) {
0594:                                        // Obtain the hook if it exists from ExtAttr Bonita tree
0595:                                        XPDLHook xpdlHook = new XPDLHook();
0596:                                        obtainProcessHook(extAttr,
0597:                                                xpdlWFProcess, xpdlHook);
0598:                                    }
0599:                                    // detect if it's an Initiator Mapper
0600:                                    else if (element
0601:                                            .getAttribute(
0602:                                                    EXTENDED_ATTRIBUTE_NAME)
0603:                                            .equalsIgnoreCase(
0604:                                                    EXTENDED_ATTRIBUTE_NAME_INITIATORMAPPER)) {
0605:                                        // Obtain the hook if it exists from ExtAttr Bonita tree
0606:                                        XPDLInitiatorMapper xpdlInitiatorMapper = new XPDLInitiatorMapper();
0607:                                        obtainInitiatorMapper(extAttr,
0608:                                                xpdlWFProcess,
0609:                                                xpdlInitiatorMapper);
0610:                                    }
0611:
0612:                                }
0613:                            }
0614:                        }
0615:                    }
0616:                }
0617:
0618:                // Add hook to Bonita project
0619:                try {
0620:                    addProcessHook2(project, projectName, p, xpdlWFProcess);
0621:                } catch (HeroException he) {
0622:                    throw new XPDLException(he.getMessage(), he);
0623:                }
0624:
0625:                // Add Initiator Mapper to Bonita project
0626:                try {
0627:                    addProcessInitiatorMapper(project, projectName, p,
0628:                            xpdlWFProcess);
0629:                } catch (HeroException he) {
0630:                    throw new XPDLException(he.getMessage(), he);
0631:                }
0632:
0633:                // Get activitySet
0634:                boolean hasActivitySet = obtainActivitySet(getNode(project,
0635:                        ACTIVITYSETS), p, xpdlData);
0636:                if (hasActivitySet) {
0637:                    for (int k = 0; k < project.NbFils; k++) // Create activities located out of an activityset
0638:                    {
0639:                        if ((project.Fils[k].Noeud.getNodeName())
0640:                                .equalsIgnoreCase(ACTIVITIES))
0641:                            obtainCreateActivity(getNode(project.Fils[k],
0642:                                    ACTIVITIES), p, root, xpdlData);
0643:                        else if ((project.Fils[k].Noeud.getNodeName())
0644:                                .equalsIgnoreCase(TRANSITIONS))
0645:                            obtainTransition(getNode(project.Fils[k],
0646:                                    TRANSITIONS), p, false, null, xpdlData);
0647:                    }
0648:                } else // This workflow process does not have activitySets
0649:                // Get and add : Activities & Transitions
0650:                {
0651:                    obtainCreateActivity(getNode(project, ACTIVITIES), p, root,
0652:                            xpdlData);
0653:                    obtainTransition(getNode(project, TRANSITIONS), p, false,
0654:                            null, xpdlData);
0655:                }
0656:                // add iteration
0657:                Hashtable actMapping = (Hashtable) xpdlData.get("actMapping");
0658:                Object[] tab = actMapping.keySet().toArray();
0659:
0660:                for (int k = 0; k < tab.length; k++) {
0661:                    XPDLActivity xpdlActivity = (XPDLActivity) actMapping
0662:                            .get(tab[k]);
0663:
0664:                    if (xpdlActivity.getIteration().size() != 0) {
0665:                        try {
0666:                            Hashtable iteration = (Hashtable) xpdlActivity
0667:                                    .getIteration();
0668:                            Object[] tabIteration = iteration.keySet()
0669:                                    .toArray();
0670:                            for (int ite = 0; ite < tabIteration.length; ite++) {
0671:                                p.addIteration(xpdlActivity.getName(),
0672:                                        tabIteration[ite].toString(),
0673:                                        (String) iteration
0674:                                                .get(tabIteration[ite]));
0675:                            }
0676:                            //p.addIteration(xpdlActivity.getName(), xpdlActivity.getIterationTo(), xpdlActivity.getIterationCondition());
0677:                        } catch (HeroException he) {
0678:                            throw new XPDLException(
0679:                                    "Error setting iteration On activity = "
0680:                                            + xpdlActivity.getName()
0681:                                            + he.getMessage(), he);
0682:                        }
0683:                    }
0684:                }
0685:
0686:            }
0687:
0688:            /*
0689:             *    Create properties for Bonita project
0690:             *    defined in the Workflow Process or in the Package
0691:             */
0692:            private void createProcessProperties(ProjectSessionLocal p,
0693:                    Hashtable xpdlData) throws XPDLException {
0694:                String projectName = null;
0695:                try {
0696:                    projectName = p.getName();
0697:                } catch (HeroException he) {
0698:                    throw new XPDLException(he.getMessage(), he);
0699:                }
0700:                //Debug
0701:                //System.out.println("createProcessProperties");
0702:                //Modif Form Ed: Collection co = dataFieldMapping.values();
0703:                //System.out.println("*****> nb values = " + co.size());
0704:                //Modif Form Ed: Iterator it = co.iterator();
0705:                //Modif Form Ed: get the order of the key in dataFieldMapping
0706:                ArrayList array_dataFieldKey = (ArrayList) xpdlData
0707:                        .get("array_dataFieldKey");
0708:                Iterator it = array_dataFieldKey.iterator();
0709:
0710:                while (it.hasNext()) {
0711:                    //XPDLDataField xpdlDataField = (XPDLDataField)it.next();
0712:                    String key = (String) it.next();
0713:                    Hashtable dataFieldMapping = (Hashtable) xpdlData
0714:                            .get("dataFieldMapping");
0715:                    XPDLDataField xpdlDataField = (XPDLDataField) dataFieldMapping
0716:                            .get(key);
0717:
0718:                    // check the datafield definition level is package or the WFProcess
0719:                    String projectTarget = xpdlDataField.getProjectName();
0720:
0721:                    //Debug
0722:                    //System.out.println("createProcessProperties: xpdlDataField.getProjectName() = " + projectTarget);
0723:
0724:                    if (projectTarget.equals(projectName)
0725:                            || projectTarget.equals(PACKAGE_LEVEL)) {
0726:                        // check if the boolean PropertyActivity is false (not datafields for activities)
0727:                        if (!xpdlDataField.getPropertyActivity()) {
0728:                            // STRING Basic Type
0729:                            if (BASICTYPE.equalsIgnoreCase(xpdlDataField
0730:                                    .getDataType())) {
0731:                                if ("String".equalsIgnoreCase(xpdlDataField
0732:                                        .getBasicType())) {
0733:                                    try {
0734:                                        p
0735:                                                .setProperty(
0736:                                                        xpdlDataField.getName(),
0737:                                                        xpdlDataField
0738:                                                                .getInitialValue());
0739:                                    } catch (HeroException he) {
0740:                                        throw new XPDLException(
0741:                                                he.getMessage(), he);
0742:                                    }
0743:                                }
0744:                            }
0745:
0746:                            // For Enumeration type
0747:                            if (ENUMERATIONTYPE.equalsIgnoreCase(xpdlDataField
0748:                                    .getDataType())) {
0749:                                ArrayList ar = xpdlDataField.getEnumeration();
0750:                                ArrayList values = new ArrayList();
0751:                                Iterator it2 = ar.iterator();
0752:                                while (it2.hasNext()) {
0753:                                    String val = (String) it2.next();
0754:                                    values.add(val);
0755:                                }
0756:                                //Debug
0757:                                //System.out.println("createProcessProperties: create property Name = " + xpdlDataField.getName() + " Value = " + xpdlDataField.getInitialValue());
0758:                                try {
0759:                                    p.setPropertyPossibleValues(xpdlDataField
0760:                                            .getName(), values);
0761:                                    if (!"".equals(xpdlDataField
0762:                                            .getInitialValue()))
0763:                                        p
0764:                                                .setProperty(
0765:                                                        xpdlDataField.getName(),
0766:                                                        xpdlDataField
0767:                                                                .getInitialValue());
0768:                                } catch (HeroException he) {
0769:                                    throw new XPDLException(
0770:                                            "Error setting the initial value of: "
0771:                                                    + xpdlDataField.getName()
0772:                                                    + "  " + he.getMessage(),
0773:                                            he);
0774:                                }
0775:                            }
0776:                        }
0777:                    }
0778:                }
0779:            }
0780:
0781:            /*
0782:             *   Add Initiator Mapper to Bonita project if it exists in the Workflow Process definition
0783:             */
0784:            private void addProcessInitiatorMapper(BonitaTree tree,
0785:                    String projectName, ProjectSessionLocal p,
0786:                    XPDLWFProcess xpdlWFProcess) throws HeroException {
0787:                if (xpdlWFProcess.getInitiatorMapper() != null) {
0788:                    XPDLInitiatorMapper xpdlInitiatorMapper = xpdlWFProcess
0789:                            .getInitiatorMapper();
0790:                    String s_initType = xpdlInitiatorMapper
0791:                            .getInitiatorMapperType();
0792:                    int i_initType = 0;
0793:                    if (EXTENDED_ATTRIBUTE_VALUE_LDAP
0794:                            .equalsIgnoreCase(s_initType))
0795:                        i_initType = 0;
0796:                    if (EXTENDED_ATTRIBUTE_VALUE_CUSTUM
0797:                            .equalsIgnoreCase(s_initType))
0798:                        i_initType = 1;
0799:                    p.addInitiatorMapper(xpdlInitiatorMapper
0800:                            .getInitiatorMapperName(), i_initType);
0801:                }
0802:            }
0803:
0804:            /*
0805:             *   Add Process hook to Bonita project if it exists in the Workflow Process definition
0806:             *   Same hook events as Node hooks
0807:             *   replaced by the addProcessHook2  (When introduction of OnInstantiate event hook)
0808:             */
0809:            private void addProcessHook(BonitaTree tree, String projectName,
0810:                    ProjectSessionLocal p, XPDLWFProcess xpdlWFProcess)
0811:                    throws HeroException {
0812:                ArrayList ar = xpdlWFProcess.getXpdlHook();
0813:                Iterator it_phook = ar.iterator();
0814:                String hookName = "";
0815:                while (it_phook.hasNext()) {
0816:                    XPDLHook xpdlHook = (XPDLHook) it_phook.next();
0817:                    hookName = xpdlHook.getHookName();
0818:                    if (!"".equals(hookName)) {
0819:                        //debug
0820:                        //System.out.println(">>> Add Hook: Name = " + hookName + " EventName = " + xpdlHook.getHookEventName() + " Script = " + xpdlHook.getHookScript());
0821:
0822:                        String hookEventName = "";
0823:                        String hookEvent = "";
0824:
0825:                        if (!"".equals(xpdlHook.getHookEventName())) {
0826:                            hookEventName = xpdlHook.getHookEventName();
0827:
0828:                            if (Nd.BEFORESTART.equalsIgnoreCase(hookEventName))
0829:                                hookEvent = Nd.BEFORESTART;
0830:                            else if (Nd.AFTERSTART
0831:                                    .equalsIgnoreCase(hookEventName))
0832:                                hookEvent = Nd.AFTERSTART;
0833:                            else if (Nd.BEFORETERMINATE
0834:                                    .equalsIgnoreCase(hookEventName))
0835:                                hookEvent = Nd.BEFORETERMINATE;
0836:                            else if (Nd.AFTERTERMINATE
0837:                                    .equalsIgnoreCase(hookEventName))
0838:                                hookEvent = Nd.AFTERTERMINATE;
0839:                            else if (Nd.ONCANCEL
0840:                                    .equalsIgnoreCase(hookEventName))
0841:                                hookEvent = Nd.ONCANCEL;
0842:                            else if (Nd.ONREADY.equalsIgnoreCase(hookEventName))
0843:                                hookEvent = Nd.ONREADY;
0844:                            else
0845:                                throw new HeroException(
0846:                                        "Syntax Error in Extended Attribut with Name = hook - "
0847:                                                + hookEventName
0848:                                                + " is Unknown hookEvent");
0849:                        }
0850:
0851:                        // By default AFTERSTART if the ext. attribute has not the complex type
0852:                        // <HookEventName> afterStart </HookEventName>
0853:
0854:                        else {
0855:                            hookEvent = Nd.AFTERSTART;
0856:                        }
0857:                        if ("".equals(xpdlHook.getHookScript())) {
0858:                            // javaHook  with by default HookType = Constants.Hook.JAVA
0859:                            p.addHook(hookName, hookEvent, Hook.JAVA);
0860:                            //debug
0861:                            //System.out.println("Set JAVA Hook for Project : Name = " + xpdlWFProcess.getName() + " Hook Name = " + hookName + " Event = " + hookEvent );
0862:                        } else {
0863:                            // interHook  with by default HookType = Constants.Hook.BSINTERACTIVE
0864:                            String hookScript = "";
0865:                            hookScript = xpdlHook.getHookScript();
0866:
0867:                            String script = "import hero.interfaces.BnProjectLocal;\n"
0868:                                    + "import hero.interfaces.BnNodeLocal;\n"
0869:                                    //+ "afterStart (Object b,Object n) {\n\n\n"
0870:                                    + hookEvent
0871:                                    + " (Object b,Object n) {\n\n\n"
0872:                                    //+ "System.out.println(\"InteractiveBnNodee Hook test, node: \"+n.getName());"
0873:                                    + hookScript + "}";
0874:                            p.addInterHook(hookName, hookEvent,
0875:                                    Hook.BSINTERACTIVE, script);
0876:                            //debug
0877:                            //System.out.println("Set INTER Hook for Project : Name = " + xpdlWFProcess.getName() + " Hook Name = " + hookName
0878:                            //				+ " Event = " + hookEvent + " Script = \n" + script);
0879:                        }
0880:                    } else
0881:                        throw new HeroException("A hook within the project = "
0882:                                + projectName);
0883:                }
0884:            }
0885:
0886:            /*
0887:             *   Add Process hook to Bonita project if it exists in the Workflow Process definition
0888:             *   Replace addProcessHook when introduction of OnInstantiate event hook
0889:             */
0890:            private void addProcessHook2(BonitaTree tree, String projectName,
0891:                    ProjectSessionLocal p, XPDLWFProcess xpdlWFProcess)
0892:                    throws HeroException {
0893:                ArrayList ar = xpdlWFProcess.getXpdlHook();
0894:                Iterator it_phook = ar.iterator();
0895:                String hookName = "";
0896:                while (it_phook.hasNext()) {
0897:                    XPDLHook xpdlHook = (XPDLHook) it_phook.next();
0898:                    hookName = xpdlHook.getHookName();
0899:                    if (!"".equals(hookName)) {
0900:                        //debug
0901:                        //System.out.println(">>> Add Hook: Name = " + hookName + " EventName = " + xpdlHook.getHookEventName() + " Script = " + xpdlHook.getHookScript());
0902:
0903:                        String hookEventName = "";
0904:                        String hookEvent = "";
0905:
0906:                        if (!"".equals(xpdlHook.getHookEventName())) {
0907:                            hookEventName = xpdlHook.getHookEventName();
0908:
0909:                            if (Pj.ONINSTANTIATE
0910:                                    .equalsIgnoreCase(hookEventName)) {
0911:                                hookEvent = Pj.ONINSTANTIATE;
0912:                                //javaHook  with by default HookType = Constants.Hook.JAVA
0913:                                p.addHook(hookName, hookEvent, Hook.JAVA);
0914:                                //	debug
0915:                                //System.out.println("Set JAVA Hook for Project : Name = " + xpdlWFProcess.getName() + " Hook Name = " + hookName + " Event = " + hookEvent );
0916:                            }
0917:
0918:                            else
0919:                                throw new HeroException(
0920:                                        "Syntax Error in Extended Attribut onto Hook Process - "
0921:                                                + hookEventName
0922:                                                + " is Unknown hookEvent"
0923:                                                + " within project = "
0924:                                                + projectName);
0925:                        }
0926:
0927:                        // By default AFTERSTART if the ext. attribute has not the complex type
0928:                        // <HookEventName> afterStart </HookEventName>
0929:
0930:                        else {
0931:                            throw new HeroException(
0932:                                    "Missing Process Hook Event within the project = "
0933:                                            + projectName);
0934:                        }
0935:
0936:                    } else
0937:                        throw new HeroException(
0938:                                "Missing Process Hook Name within the project = "
0939:                                        + projectName);
0940:                }
0941:            }
0942:
0943:            /*
0944:             *  Obtain definition for Participants, Applications, DataFields
0945:             *   NO MORE USED !
0946:             */
0947:            private void addSubProcessDefinition(BonitaTree root,
0948:                    String projectName, Hashtable xpdlData) throws Exception {
0949:                try {
0950:                    pHome = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
0951:                            .getLocalHome();
0952:                } catch (NamingException be) {
0953:                    throw new HeroException(be.getMessage(), be);
0954:                }
0955:                ProjectSessionLocal p = pHome.create();
0956:                p.initModel(projectName);
0957:                obtainParticipant(getNode(root, PARTICIPANTS), projectName,
0958:                        xpdlData);
0959:                obtainApplication(getNode(root, APPLICATIONS), projectName,
0960:                        xpdlData);
0961:
0962:                //debug
0963:                //System.out.println("****!!! Calling   obtainDataField in addSubProcessDefinition - projectName = " + 	projectName );
0964:
0965:                obtainDataField(getNode(root, DATAFIELDS), projectName,
0966:                        xpdlData);
0967:            }
0968:
0969:            /*
0970:             *  Get activity Set definitions
0971:             */
0972:            private boolean obtainActivitySet(BonitaTree a,
0973:                    ProjectSessionLocal p, Hashtable xpdlData)
0974:                    throws XPDLException {
0975:                boolean hasActivitySet = false;
0976:                if (a != null) {
0977:                    if ((a.Noeud.getNodeName()).equalsIgnoreCase(ACTIVITYSETS)) {
0978:                        hasActivitySet = true;
0979:                        // For every existing ActivitySet
0980:                        for (int j = 0; j < a.NbFils; j++) {
0981:                            if ((a.Fils[j].Noeud.getNodeName())
0982:                                    .equalsIgnoreCase(ACTIVITYSET)) {
0983:                                Element actSet = (Element) a.Fils[j].Noeud;
0984:                                obtainCreateActivity(getNode(a.Fils[j],
0985:                                        ACTIVITIES), p, a, xpdlData);
0986:                                // the search of the first and last activity of the activitySet is performed in obtainTransition()
0987:                                // Then boolean is set to true and activitySet Id is provided to the method
0988:                                obtainTransition(
0989:                                        getNode(a.Fils[j], TRANSITIONS), p,
0990:                                        true, actSet
0991:                                                .getAttribute(ACTIVITYSETID),
0992:                                        xpdlData);
0993:                            }
0994:                        }
0995:                    }
0996:                }
0997:                return hasActivitySet;
0998:            }
0999:
1000:            /*
1001:             *   Search for the first element with the given name
1002:             *   according a deep search algo
1003:             */
1004:            private BonitaTree getNode(BonitaTree A, String name) {
1005:                if (A.Noeud.getNodeName().equalsIgnoreCase(name))
1006:                    return A;
1007:                if (A.NbFils > 0) {
1008:                    BonitaTree ReturnArbre = null;
1009:                    for (int i = 0; i < A.NbFils; i++) {
1010:                        ReturnArbre = getNode(A.Fils[i], name);
1011:                        if (ReturnArbre != null)
1012:                            return ReturnArbre;
1013:                    }
1014:                }
1015:                return null;
1016:            }
1017:
1018:            /*
1019:             *   Search for child element under the given tree
1020:             *
1021:             */
1022:            private BonitaTree getFilsNode(BonitaTree A, String name) {
1023:                if (A.Noeud.getNodeName().equalsIgnoreCase(name))
1024:                    return A;
1025:                if (A.NbFils > 0) {
1026:                    BonitaTree ReturnArbre = null;
1027:                    for (int i = 0; i < A.NbFils; i++) {
1028:                        if (A.Fils[i].Noeud.getNodeName()
1029:                                .equalsIgnoreCase(name)) {
1030:                            return (A.Fils[i]);
1031:                        }
1032:                    }
1033:                }
1034:                return null;
1035:            }
1036:
1037:            private boolean projectExist(String projName, String projVersion) {
1038:                try {
1039:                    BnProjectLocalHome pHome = (BnProjectLocalHome) hero.interfaces.BnProjectUtil
1040:                            .getLocalHome();
1041:                    // take care of the version
1042:                    pHome.findByNameVersion(projName, projVersion);
1043:                } catch (Exception be) {
1044:                    return false;
1045:                }
1046:                return true;
1047:            }
1048:
1049:            /**
1050:             * printHashTables
1051:             * Utility method set in the bean interface in order to get debug info
1052:             *
1053:             * @ejb.permission unchecked="yes"
1054:             * @ejb:interface-method view-type="both"
1055:             * @ejb:transaction type="Required"
1056:             *
1057:             **/
1058:
1059:            public void printHashTables(Hashtable xpdlData)
1060:                    throws XPDLException {
1061:                /*  For debug , print data of hash tables
1062:                 *
1063:                 * 	actMapping
1064:                 *  activitySetMapping
1065:                 *  partMapping
1066:                 *  appliMapping
1067:                 */
1068:
1069:                System.out.println("");
1070:                System.out
1071:                        .println("*-------- Debug informations ---------------------------");
1072:
1073:                // PROCESS
1074:                System.out
1075:                        .println("**** Hashtable for workflow Process: wfProcessMapping");
1076:                //TODO
1077:                Hashtable wfProcessMapping = (Hashtable) xpdlData
1078:                        .get("wfProcessMapping");
1079:                Object[] tab = wfProcessMapping.keySet().toArray();
1080:                for (int k = 0; k < tab.length; k++) {
1081:                    System.out.print("   - " + tab[k].toString());
1082:                    XPDLWFProcess xpdlWFProcess = (XPDLWFProcess) wfProcessMapping
1083:                            .get(tab[k]);
1084:                    // process name
1085:                    System.out.println(" " + xpdlWFProcess.getName());
1086:                    // process hooks
1087:                    ArrayList ar = xpdlWFProcess.getXpdlHook();
1088:                    Iterator it_phook = ar.iterator();
1089:                    while (it_phook.hasNext()) {
1090:                        XPDLHook xpdlHook = (XPDLHook) it_phook.next();
1091:                        System.out.println("     Hook: Name = "
1092:                                + xpdlHook.getHookName() + " EventName = "
1093:                                + xpdlHook.getHookEventName() + " Script = "
1094:                                + xpdlHook.getHookScript());
1095:                    }
1096:                    // process initiator mapper
1097:                    XPDLInitiatorMapper xpdlInitiatorMapper = xpdlWFProcess
1098:                            .getInitiatorMapper();
1099:                    if (xpdlInitiatorMapper != null) {
1100:                        System.out.println("     Initiator Mapper: Type = "
1101:                                + xpdlInitiatorMapper.getInitiatorMapperType()
1102:                                + " Name = "
1103:                                + xpdlInitiatorMapper.getInitiatorMapperName());
1104:                        System.out.println("");
1105:                    }
1106:                }
1107:
1108:                // ACTIVITY
1109:                System.out.println("**** HashMap for activities: actMapping");
1110:                //TODO
1111:                Hashtable actMapping = (Hashtable) xpdlData.get("actMapping");
1112:                tab = actMapping.keySet().toArray();
1113:                for (int k = 0; k < tab.length; k++) {
1114:                    System.out.print("   - Id=" + tab[k].toString());
1115:                    //System.out.println(" " +(String)actMapping.get(tab[k]));
1116:                    XPDLActivity xpdlActivity = (XPDLActivity) actMapping
1117:                            .get(tab[k]);
1118:                    // performer
1119:                    String performer = xpdlActivity.getPerformer();
1120:                    if ("".equals(performer))
1121:                        performer = "InitialRole";
1122:                    System.out.println("   Name = " + xpdlActivity.getName()
1123:                            + "  Performer = " + performer);
1124:                    // implementation
1125:                    String implementation = xpdlActivity.getImplementation();
1126:                    if ("".equals(implementation)) {
1127:                        System.out.println("   Name = "
1128:                                + xpdlActivity.getName()
1129:                                + "  Implementation = " + implementation);
1130:                    }
1131:                    // subflow version  (if subflow implementation)
1132:                    String subFlowVersion = xpdlActivity.getSubFlowVersion();
1133:                    if ("".equals(subFlowVersion)) {
1134:                        System.out.println("   Name = "
1135:                                + xpdlActivity.getName()
1136:                                + "  SubFlowVersion = " + subFlowVersion);
1137:                    }
1138:                    // Performer Assignment
1139:                    if (!"".equals(xpdlActivity.getPerformerAssignName())) {
1140:                        System.out
1141:                                .println("       . Performer Assignment: Name = "
1142:                                        + xpdlActivity.getPerformerAssignName()
1143:                                        + " Type = "
1144:                                        + xpdlActivity.getPerformerAssignType()
1145:                                        + " Property = "
1146:                                        + xpdlActivity
1147:                                                .getPerformerAssignProperty());
1148:                    }
1149:                    // array of properties and propagations
1150:                    if (!xpdlActivity.getProperties().isEmpty()) {
1151:                        Iterator it_proper = xpdlActivity.getProperties()
1152:                                .iterator();
1153:                        Iterator it_propag = xpdlActivity.getPropagations()
1154:                                .iterator();
1155:                        while (it_proper.hasNext() && it_propag.hasNext()) {
1156:                            System.out.print("       . Property: Name = "
1157:                                    + (String) it_proper.next());
1158:                            boolean b_propagation = ((Boolean) it_propag.next())
1159:                                    .booleanValue();
1160:                            if (b_propagation)
1161:                                System.out.println(" propagation = Yes ");
1162:                            else
1163:                                System.out.println(" propagation = No ");
1164:                        }
1165:
1166:                    }
1167:                    // Hooks
1168:                    ArrayList ar = xpdlActivity.getXpdlHook();
1169:                    Iterator it_ahook = ar.iterator();
1170:                    while (it_ahook.hasNext()) {
1171:                        XPDLHook xpdlHook = (XPDLHook) it_ahook.next();
1172:                        System.out.println("       . Hook: Name = "
1173:                                + xpdlHook.getHookName() + " EventName = "
1174:                                + xpdlHook.getHookEventName() + " Script = "
1175:                                + xpdlHook.getHookScript());
1176:                    }
1177:                    // Relative Deadlines
1178:                    ArrayList ar_dl = xpdlActivity.getRelativeTimeDeadline();
1179:                    if (ar_dl.size() != 0) {
1180:                        Iterator it_dl = ar_dl.iterator();
1181:                        while (it_dl.hasNext()) {
1182:                            Long condition = (Long) it_dl.next();
1183:                            System.out.println("       . Relative Deadline : "
1184:                                    + condition.longValue());
1185:                        }
1186:                    }
1187:                    // Fixed Deadlines
1188:                    ar_dl = xpdlActivity.getFixedTimeDeadline();
1189:                    if (ar_dl.size() != 0) {
1190:                        Iterator it_dl = ar_dl.iterator();
1191:                        while (it_dl.hasNext()) {
1192:                            Long condition = (Long) it_dl.next();
1193:                            System.out.println("       . Fixed Deadline : "
1194:                                    + condition.longValue());
1195:                        }
1196:                    }
1197:                    // ActualParameters
1198:                    ArrayList ar_ap = xpdlActivity.getActualParameter();
1199:                    if (ar_ap.size() != 0) {
1200:                        Iterator it_ap = ar_ap.iterator();
1201:                        while (it_ap.hasNext()) {
1202:                            String actualParameter = (String) it_ap.next();
1203:                            System.out.println("       . ActualParameter : "
1204:                                    + actualParameter);
1205:                        }
1206:                    }
1207:                    // Iteration
1208:                    // old iteration printing
1209:                    /*
1210:                    String iteration = xpdlActivity.getIterationName();
1211:                    if ( !"".equals(iteration) ) {
1212:                    	System.out.println("   Iteration Name = " + xpdlActivity.getName());
1213:                    	//System.out.println("   Activity Name (From) = " + xpdlActivity.getName());
1214:                    	System.out.println("   Iteration condition = " + xpdlActivity.getIterationCondition());
1215:                    	System.out.println("   Iteration To = " + xpdlActivity.getIterationTo());
1216:                    }
1217:                     */
1218:                    // new iteration printing
1219:                    if (xpdlActivity.getIteration().size() != 0) {
1220:
1221:                        Hashtable iteration = (Hashtable) xpdlActivity
1222:                                .getIteration();
1223:                        Object[] tabIteration = iteration.keySet().toArray();
1224:                        for (int ite = 0; ite < tabIteration.length; ite++) {
1225:                            System.out.println("   Iteration To = "
1226:                                    + tabIteration[ite].toString());
1227:                            System.out
1228:                                    .println("   Iteration condition = "
1229:                                            + (String) iteration
1230:                                                    .get(tabIteration[ite]));
1231:                        }
1232:                    }
1233:                }
1234:
1235:                // ActivitySet
1236:                System.out.println("");
1237:                System.out
1238:                        .println("**** Hashtable for activity Set: activitySetMapping");
1239:                //TODO
1240:                Hashtable activitySetMapping = (Hashtable) xpdlData
1241:                        .get("activitySetMapping");
1242:                tab = activitySetMapping.keySet().toArray();
1243:                for (int y = 0; y < tab.length; y++) {
1244:                    System.out.print("   - " + tab[y].toString());
1245:                    System.out.println(" "
1246:                            + (String) activitySetMapping.get(tab[y]));
1247:                }
1248:
1249:                // Transitions
1250:                System.out.println("");
1251:                System.out
1252:                        .println("**** Hashtable for transition: transitionMapping");
1253:                //TODO
1254:                Hashtable transitionMapping = (Hashtable) xpdlData
1255:                        .get("transitionMapping");
1256:                tab = transitionMapping.keySet().toArray();
1257:                for (int y = 0; y < tab.length; y++) {
1258:                    //id
1259:                    System.out.print("   - " + tab[y].toString());
1260:                    // name, to, from, condition
1261:                    XPDLTransition xpdlTransition = (XPDLTransition) transitionMapping
1262:                            .get(tab[y]);
1263:                    System.out.println("       From =  "
1264:                            + xpdlTransition.getFrom() + " To = "
1265:                            + xpdlTransition.getTo());
1266:                    System.out.println("       Name= "
1267:                            + xpdlTransition.getName() + " condition = "
1268:                            + xpdlTransition.getCondition());
1269:                }
1270:
1271:                // Participants
1272:                System.out.println("");
1273:                System.out
1274:                        .println("**** Hashtable for participant: partMapping");
1275:                //      TODO
1276:                Hashtable partMapping = (Hashtable) xpdlData.get("partMapping");
1277:                tab = partMapping.keySet().toArray();
1278:                for (int y = 0; y < tab.length; y++) {
1279:                    System.out.print("   - " + tab[y].toString());
1280:                    XPDLParticipant xpdlPart = (XPDLParticipant) partMapping
1281:                            .get(tab[y]);
1282:                    System.out.println("      Name= " + xpdlPart.getName()
1283:                            + " Type= " + xpdlPart.getType() + " RoleMapper= "
1284:                            + xpdlPart.getMapperName() + " RoleMapperType= "
1285:                            + xpdlPart.getMapperType());
1286:                    System.out
1287:                            .println("      For ProjectName (or all project) = "
1288:                                    + xpdlPart.getProjectName());
1289:                }
1290:
1291:                // Applications
1292:                System.out.println("");
1293:                System.out
1294:                        .println("**** Hashtable for Applications: appliMapping");
1295:                //      TODO
1296:                Hashtable appliMapping = (Hashtable) xpdlData
1297:                        .get("appliMapping");
1298:                tab = appliMapping.keySet().toArray();
1299:                for (int y = 0; y < tab.length; y++) {
1300:                    //application id
1301:                    System.out.print("   - " + tab[y].toString());
1302:                    XPDLApplication xpdlAppli = (XPDLApplication) appliMapping
1303:                            .get(tab[y]);
1304:                    // application name
1305:                    System.out.println("  Name= " + xpdlAppli.getName());
1306:                    // level package or project
1307:                    System.out
1308:                            .println("      For ProjectName (or all project) = "
1309:                                    + xpdlAppli.getProjectName());
1310:                    // formal parameters set in hash table (key = Index, value = Id of the formal param)
1311:                    ArrayList formalParams = xpdlAppli.getFormalParam();
1312:                    if (!formalParams.isEmpty()) {
1313:                        System.out.println("      FormalParameters :");
1314:                        Iterator it_fp = formalParams.iterator();
1315:                        while (it_fp.hasNext()) {
1316:                            XPDLFormalParameter xpdlFormalParam = (XPDLFormalParameter) it_fp
1317:                                    .next();
1318:                            System.out.print("      Id = "
1319:                                    + xpdlFormalParam.getId());
1320:                            System.out.print("\t\tIndex = "
1321:                                    + xpdlFormalParam.getIndex());
1322:                            System.out.println("\tMode = "
1323:                                    + xpdlFormalParam.getMode());
1324:                        }
1325:                    }
1326:                }
1327:
1328:                // DataFields
1329:                System.out
1330:                        .println("**** Hashtable for DataField: dataFieldMapping");
1331:                //      TODO
1332:                Hashtable dataFieldMapping = (Hashtable) xpdlData
1333:                        .get("dataFieldMapping");
1334:                tab = dataFieldMapping.keySet().toArray();
1335:                for (int y = 0; y < tab.length; y++) {
1336:                    System.out.println("   - " + tab[y].toString());
1337:                    XPDLDataField xpdlDataField = (XPDLDataField) dataFieldMapping
1338:                            .get(tab[y]);
1339:                    System.out.println("      Name= " + xpdlDataField.getName()
1340:                            + " DataType = " + xpdlDataField.getDataType()
1341:                            + " BasicType = " + xpdlDataField.getBasicType()
1342:                            + " InitialValue = "
1343:                            + xpdlDataField.getInitialValue());
1344:                    if (xpdlDataField.getPropertyActivity())
1345:                        System.out
1346:                                .println("      Property for activity = true");
1347:                    else
1348:                        System.out
1349:                                .println("      Property for activity = false");
1350:                    System.out
1351:                            .println("      For ProjectName(or all project) = "
1352:                                    + xpdlDataField.getProjectName());
1353:                    if ("EnumerationType".equals(xpdlDataField.getDataType())) {
1354:                        ArrayList ar_df = xpdlDataField.getEnumeration();
1355:                        Iterator it2 = ar_df.iterator();
1356:                        System.out.println("        Enumeration values:");
1357:                        while (it2.hasNext()) {
1358:                            String val = (String) it2.next();
1359:                            System.out.println("           . " + val);
1360:                        }
1361:                    }
1362:                }
1363:            }
1364:
1365:            /*
1366:             * Internal utility method used for dev.
1367:             */
1368:            private void printDomTree(BonitaTree Arb) {
1369:                int i = 0;
1370:                String type;
1371:                switch (Arb.Noeud.getNodeType()) {
1372:                case Node.ATTRIBUTE_NODE:
1373:                    type = "attribut";
1374:                    break;
1375:                case Node.CDATA_SECTION_NODE:
1376:                    type = "CDATA";
1377:                    break;
1378:                case Node.COMMENT_NODE:
1379:                    type = "comment";
1380:                    break;
1381:                case Node.DOCUMENT_FRAGMENT_NODE:
1382:                    type = "document fragment";
1383:                    break;
1384:                case Node.DOCUMENT_NODE:
1385:                    type = "document";
1386:                    break;
1387:                case Node.DOCUMENT_TYPE_NODE:
1388:                    type = "document type";
1389:                    break;
1390:                case Node.ELEMENT_NODE:
1391:                    type = "node";
1392:                    if (Arb.Noeud.hasAttributes()) {
1393:                        int length = Arb.Noeud.getAttributes().getLength();
1394:                        Attr attributes[] = new Attr[length];
1395:
1396:                        for (int j = 0; j < length; j++) {
1397:                            attributes[j] = (Attr) Arb.Noeud.getAttributes()
1398:                                    .item(j);
1399:                            System.out
1400:                                    .println("***************       Attr Name="
1401:                                            + attributes[j].getNodeName());
1402:                            System.out
1403:                                    .println("***************       Attr Value="
1404:                                            + attributes[j].getNodeValue());
1405:                            System.out
1406:                                    .println("----------------------------------------------------------");
1407:                        }
1408:                    }
1409:                    break;
1410:                case Node.ENTITY_NODE:
1411:                    type = "entity";
1412:                    break;
1413:                case Node.ENTITY_REFERENCE_NODE:
1414:                    type = "entity reference";
1415:                    break;
1416:                case Node.NOTATION_NODE:
1417:                    type = "notation";
1418:                    break;
1419:                case Node.PROCESSING_INSTRUCTION_NODE:
1420:                    type = "processing instruction";
1421:                    break;
1422:                case Node.TEXT_NODE:
1423:                    type = "text";
1424:                    break;
1425:                default:
1426:                    type = "none";
1427:                }
1428:                System.out.println("type : " + type);
1429:                System.out.println("noeud name  : " + Arb.Noeud.getNodeName());
1430:                System.out.println("value : " + Arb.Noeud.getNodeValue());
1431:
1432:                System.out.println("Nb Fils = " + Arb.NbFils);
1433:
1434:                if (Arb.NbFils > 0) {
1435:                    i = 0;
1436:                    while (i < Arb.NbFils) {
1437:                        printDomTree(Arb.Fils[i++]);
1438:                    }
1439:                }
1440:            }
1441:
1442:            /*
1443:             * To obtain the participant attribut definition
1444:             *    - Name
1445:             *    - Id
1446:             */
1447:
1448:            private void obtainParticipant(BonitaTree tree, String projectName,
1449:                    Hashtable xpdlData) throws XPDLException {
1450:                if (tree != null) {
1451:                    if ((tree.Noeud.getNodeName())
1452:                            .equalsIgnoreCase(PARTICIPANTS)) {
1453:                        for (int j = 0; j < tree.NbFils; j++) {
1454:                            if ((tree.Fils[j].Noeud.getNodeName())
1455:                                    .equalsIgnoreCase(PARTICIPANT)) {
1456:                                XPDLParticipant xpdlPart = new XPDLParticipant();
1457:                                Element ele = (Element) tree.Fils[j].Noeud;
1458:                                //set the participant Id
1459:                                xpdlPart
1460:                                        .setId(ele.getAttribute(PARTICIPANT_ID));
1461:
1462:                                //set the participant name
1463:                                if (!ele.getAttribute(PARTICIPANT_TYPE_TYPE)
1464:                                        .equalsIgnoreCase(
1465:                                                PARTICIPANT_TYPE_SYSTEM))
1466:                                    xpdlPart.setName(ele
1467:                                            .getAttribute(PARTICIPANT_NAME));
1468:                                else {
1469:                                    //partMapping.put(xpdlPart.getId(),"InitialRole");
1470:                                    xpdlPart.setName("InitialRole");
1471:                                }
1472:                                //set the level (WFProcess or package) in which application is accessible : not needed !
1473:                                xpdlPart.setProjectName(projectName);
1474:
1475:                                // Put the XPDLParticipant Bean in the HashMap
1476:                                Hashtable partMapping = (Hashtable) xpdlData
1477:                                        .get("partMapping");
1478:                                partMapping.put(xpdlPart.getId(), xpdlPart);
1479:
1480:                                if (!("".equalsIgnoreCase(xpdlPart.getName())))
1481:                                    // get and add data for package participants
1482:                                    obtainParticipantData(tree.Fils[j],
1483:                                            xpdlPart);
1484:                            }
1485:                        }
1486:                    }
1487:                }
1488:            }
1489:
1490:            /*
1491:             * To obtain the applications attribut definition
1492:             *    - Name
1493:             *    - Id
1494:             */
1495:
1496:            private void obtainApplication(BonitaTree tree, String projectName,
1497:                    Hashtable xpdlData) throws XPDLException {
1498:                if (tree != null) {
1499:                    if ((tree.Noeud.getNodeName())
1500:                            .equalsIgnoreCase(APPLICATIONS)) {
1501:                        for (int j = 0; j < tree.NbFils; j++) {
1502:                            if ((tree.Fils[j].Noeud.getNodeName())
1503:                                    .equalsIgnoreCase(APPLICATION)) {
1504:                                XPDLApplication xpdlAppli = new XPDLApplication();
1505:                                Element ele = (Element) tree.Fils[j].Noeud;
1506:                                //set the application Id
1507:                                xpdlAppli.setId(ele
1508:                                        .getAttribute(APPLICATION_ID));
1509:                                xpdlAppli.setName(ele
1510:                                        .getAttribute(APPLICATION_NAME));
1511:
1512:                                //set the level (WFProcess or package) in which application is accessible : not needed
1513:                                xpdlAppli.setProjectName(projectName);
1514:
1515:                                // Put the XPDLApplication in the HashMap
1516:                                Hashtable appliMapping = (Hashtable) xpdlData
1517:                                        .get("appliMapping");
1518:                                appliMapping.put(xpdlAppli.getId(), xpdlAppli);
1519:
1520:                                if (!"".equalsIgnoreCase(xpdlAppli.getName()))
1521:                                    // get and add data for package Applications
1522:                                    obtainApplicationData(tree.Fils[j],
1523:                                            xpdlAppli);
1524:                            }
1525:                        }
1526:                    }
1527:                }
1528:            }
1529:
1530:            /*
1531:             * To obtain the datafields attribut definition
1532:             *    - Name
1533:             *    - Id
1534:             */
1535:
1536:            private void obtainDataField(BonitaTree tree, String projectName,
1537:                    Hashtable xpdlData) {
1538:                if (tree != null) {
1539:                    if ((tree.Noeud.getNodeName()).equalsIgnoreCase(DATAFIELDS)) {
1540:                        for (int j = 0; j < tree.NbFils; j++) {
1541:                            if ((tree.Fils[j].Noeud.getNodeName())
1542:                                    .equalsIgnoreCase(DATAFIELD)) {
1543:                                XPDLDataField xpdlDataField = new XPDLDataField();
1544:                                Element ele = (Element) tree.Fils[j].Noeud;
1545:                                //set the dataField: Id, name, projectName or PACKAGE_LEVEL
1546:                                xpdlDataField.setId(ele
1547:                                        .getAttribute(DATAFIELD_ID));
1548:                                xpdlDataField.setName(ele
1549:                                        .getAttribute(DATAFIELD_NAME));
1550:
1551:                                //set the level (WFProcess or package) in which application is accessible
1552:                                if ("".equals(xpdlDataField.getProjectName()))
1553:                                    xpdlDataField.setProjectName(projectName);
1554:                                //debug
1555:                                //System.out.println("****!!!**** In obtainDataField - projectName = " + 	projectName + " datafield Name = " + xpdlDataField.getName());
1556:
1557:                                // Put the XPDLApplication in the HashMap
1558:                                //TODO
1559:                                Hashtable dataFieldMapping = (Hashtable) xpdlData
1560:                                        .get("dataFieldMapping");
1561:                                dataFieldMapping.put(xpdlDataField.getId(),
1562:                                        xpdlDataField);
1563:                                // Add the key in an ArrayList to get the same order as it is expected in the Form Ed.
1564:                                //TODO
1565:                                ArrayList array_dataFieldKey = (ArrayList) xpdlData
1566:                                        .get("array_dataFieldKey");
1567:                                array_dataFieldKey.add(xpdlDataField.getId());
1568:
1569:                                if (!"".equalsIgnoreCase(xpdlDataField
1570:                                        .getName()))
1571:                                    // get and add data for package Applications
1572:                                    obtainDataFieldData(tree.Fils[j],
1573:                                            xpdlDataField);
1574:                            }
1575:                        }
1576:                    }
1577:                }
1578:            }
1579:
1580:            /*
1581:             * To obtain participants definition:
1582:             *    - TYPE
1583:             *    - EXTENDED ATTRIBUTES
1584:             *    (But does not create role ou user in workflowProcess (this is done in activity when performer)
1585:             */
1586:            private void obtainParticipantData(BonitaTree n,
1587:                    XPDLParticipant xpdlPart) throws XPDLException {
1588:                int type = n.Noeud.getNodeType();
1589:                switch (type) {
1590:                case Node.ATTRIBUTE_NODE:
1591:                    break;
1592:
1593:                case Node.ELEMENT_NODE:
1594:                    if (n.Noeud.getNodeName()
1595:                            .equalsIgnoreCase(PARTICIPANT_TYPE)) {
1596:
1597:                        Element ele = (Element) n.Noeud;
1598:                        //TYPE of participant
1599:                        xpdlPart.setType(ele
1600:                                .getAttribute(PARTICIPANT_TYPE_TYPE));
1601:                    }
1602:
1603:                    // EXTENDED ATTRIBUTES on paticipant for RoleMappers and for support to JaWE connexion to LDAP
1604:                    if (n.Noeud.getNodeName().equalsIgnoreCase(
1605:                            EXTENDED_ATTRIBUTES)) {
1606:                        for (int j = 0; j < n.NbFils; j++) {
1607:                            if ((n.Fils[j].Noeud.getNodeName())
1608:                                    .equalsIgnoreCase(EXTENDED_ATTRIBUTE)) {
1609:                                Element ele = (Element) n.Fils[j].Noeud;
1610:                                if (ele.getAttribute(EXTENDED_ATTRIBUTE_NAME)
1611:                                        .equalsIgnoreCase(
1612:                                                EXTENDED_ATTRIBUTE_NAME_MAPPER)) {
1613:                                    // construct the name of the mapper based on the roleName
1614:                                    String mapperName = "mapper"
1615:                                            .concat(xpdlPart.getName());
1616:                                    xpdlPart.setMapperName(mapperName);
1617:                                    // LDAP
1618:                                    if (ele
1619:                                            .getAttribute(
1620:                                                    EXTENDED_ATTRIBUTE_VALUE)
1621:                                            .equalsIgnoreCase(
1622:                                                    EXTENDED_ATTRIBUTE_VALUE_LDAP))
1623:                                        xpdlPart
1624:                                                .setMapperType(EXTENDED_ATTRIBUTE_VALUE_LDAP);
1625:                                    // PROPERTIES
1626:                                    else if (ele
1627:                                            .getAttribute(
1628:                                                    EXTENDED_ATTRIBUTE_VALUE)
1629:                                            .equalsIgnoreCase(
1630:                                                    EXTENDED_ATTRIBUTE_VALUE_PROPERTIES))
1631:                                        xpdlPart
1632:                                                .setMapperType(EXTENDED_ATTRIBUTE_VALUE_PROPERTIES);
1633:                                    // CUSTOM
1634:                                    else if (ele
1635:                                            .getAttribute(
1636:                                                    EXTENDED_ATTRIBUTE_VALUE)
1637:                                            .equalsIgnoreCase(
1638:                                                    EXTENDED_ATTRIBUTE_VALUE_CUSTUM))
1639:                                        xpdlPart
1640:                                                .setMapperType(EXTENDED_ATTRIBUTE_VALUE_CUSTUM);
1641:                                }
1642:                                // Classname is required for the CUSTOM Mapper (No Error raised if this extended attribute is not set !!!!
1643:                                // TBD !!
1644:                                if (ele
1645:                                        .getAttribute(EXTENDED_ATTRIBUTE_NAME)
1646:                                        .equalsIgnoreCase(
1647:                                                EXTENDED_ATTRIBUTE_NAME_MAPPER_CLASSNAME)) {
1648:                                    xpdlPart
1649:                                            .setMapperClassName(ele
1650:                                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
1651:                                    // The mapper name is also the name of the Mapper class
1652:                                    xpdlPart
1653:                                            .setMapperName(ele
1654:                                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
1655:                                }
1656:                                //Extended attributs supporting JaWE connexion to Ldap
1657:                                if (ele.getAttribute(EXTENDED_ATTRIBUTE_NAME)
1658:                                        .equalsIgnoreCase(
1659:                                                EXTENDED_ATTRIBUTE_NAME_DN)) {
1660:                                    // Only Human type Partricipant needs to get uid from Dn (not Role type)
1661:                                    if (PARTICIPANT_TYPE_HUMAN
1662:                                            .equalsIgnoreCase(xpdlPart
1663:                                                    .getType())) {
1664:                                        //get uid providing the DN to the BnLdap Bean
1665:                                        BnLdapHome ldapHome = null;
1666:                                        BnLdap bnLdap = null;
1667:                                        String uid = "";
1668:                                        try {
1669:                                            ldapHome = BnLdapUtil.getHome();
1670:                                        } catch (NamingException na) {
1671:                                            throw new XPDLException(
1672:                                                    "Error creating BnLdap Home : "
1673:                                                            + na.getMessage(),
1674:                                                    na);
1675:                                        }
1676:                                        try {
1677:                                            bnLdap = ldapHome.create();
1678:                                        } catch (Exception e) {
1679:                                            throw new XPDLException(
1680:                                                    "Error creating BnLdap : "
1681:                                                            + e.getMessage(), e);
1682:                                        }
1683:                                        try {
1684:                                            uid = bnLdap
1685:                                                    .getUserIdFromPartialDn(ele
1686:                                                            .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
1687:                                        } catch (Exception e) {
1688:                                            throw new XPDLException(
1689:                                                    "Error getting uid with BnLdap Bean : "
1690:                                                            + e.getMessage(), e);
1691:                                        }
1692:                                        //replacing the participant full name by the got uid
1693:                                        xpdlPart.setName(uid);
1694:                                    }
1695:
1696:                                }
1697:                            }
1698:                        }
1699:                    }
1700:
1701:                    break;
1702:                case Node.TEXT_NODE:
1703:                    if ((n.Noeud.getNodeName())
1704:                            .equalsIgnoreCase(PARTICIPANT_DESCRIPTION))
1705:                        xpdlPart.setDescription(n.Noeud.getNodeValue());
1706:                    break;
1707:
1708:                default:
1709:                    break;
1710:                }
1711:
1712:                for (int k = 0; k < n.NbFils; k++) {
1713:                    obtainParticipantData(n.Fils[k], xpdlPart);
1714:                }
1715:                //return xpdlPart;
1716:            }
1717:
1718:            /*
1719:             *    Get activity definition and create the Bonita nodes with all components (deadlins, hooks, ....)
1720:             */
1721:            private void obtainCreateActivity(BonitaTree a,
1722:                    ProjectSessionLocal p, BonitaTree root, Hashtable xpdlData)
1723:                    throws XPDLException {
1724:
1725:                if (a != null) {
1726:                    BonitaTree activity_type = null;
1727:                    String Sub_Id;
1728:                    if ((a.Noeud.getNodeName()).equalsIgnoreCase(ACTIVITIES)) {
1729:                        for (int i = 0; i < a.NbFils; i++) {
1730:                            if ((a.Fils[i].Noeud.getNodeName())
1731:                                    .equalsIgnoreCase(ACTIVITY)) {
1732:                                XPDLActivity xpdlAct = new XPDLActivity();
1733:                                Element element = (Element) a.Fils[i].Noeud;
1734:                                // set Id and Name of the activity in xpdlAct Bean
1735:                                xpdlAct
1736:                                        .setId(element
1737:                                                .getAttribute(ACTIVITY_ID));
1738:                                xpdlAct.setName(element
1739:                                        .getAttribute(ACTIVITY_NAME));
1740:
1741:                                // store xpdlAct Bean in a global hashtable (to be used for addNode, addedge , .....)
1742:                                //TODO
1743:                                Hashtable actMapping = (Hashtable) xpdlData
1744:                                        .get("actMapping");
1745:                                actMapping.put(element
1746:                                        .getAttribute(ACTIVITY_ID), xpdlAct);
1747:
1748:                                //*****************
1749:                                // SUBFLOW Activity
1750:                                //*****************
1751:                                if ((activity_type = getNode(a.Fils[i],
1752:                                        IMPLEMENTATION_SUBFLOW)) != null) {
1753:                                    String projectName = null;
1754:                                    String defaultProjectName = null;
1755:                                    String projectId = null;
1756:                                    String projectVersion = null;
1757:                                    xpdlAct
1758:                                            .setImplementation(IMPLEMENTATION_SUBFLOW);
1759:                                    Element element2 = (Element) activity_type.Noeud;
1760:                                    defaultProjectName = element2
1761:                                            .getAttribute(SUBFLOW_ID);
1762:                                    /*  get the process name :
1763:                                     *      - either in the wfProcessMapping if it has been already found in an defined external package
1764:                                     *        (xpdl generated by other tools than proed and imported with bonita ant target:
1765:                                     *        ant import-xpdl -Duser=xxx -Dpasswd=yyy -Dxpdl=<xpdl full path>)
1766:                                     *      - or in the extended attribute from xpdl/proed
1767:                                     *        <ExtendedAttribute Name="SubFlowName" Value="My Subflow" />
1768:                                     *  By default projectName = projectId if it has not been found thru the 2 previous cases
1769:                                     */
1770:
1771:                                    // search if the subflow exists in the defined external package
1772:                                    projectId = element2
1773:                                            .getAttribute(SUBFLOW_ID);
1774:                                    //TODO
1775:                                    Hashtable wfProcessMapping = (Hashtable) xpdlData
1776:                                            .get("wfProcessMapping");
1777:                                    XPDLWFProcess xpdlWFProcess = (XPDLWFProcess) wfProcessMapping
1778:                                            .get(projectId);
1779:                                    if (xpdlWFProcess != null) {
1780:                                        projectName = xpdlWFProcess.getName();
1781:                                    }
1782:                                    // search if the name is defined in an extended attribut
1783:                                    else {
1784:                                        xpdlAct = obtainSubFlowName(a.Fils[i],
1785:                                                xpdlAct);
1786:                                        projectName = xpdlAct.getSubFlowName();
1787:                                    }
1788:                                    if ("".equals(projectName)) {
1789:                                        projectName = defaultProjectName;
1790:                                    }
1791:
1792:                                    // Search for sub-process definition inside this package and then create it
1793:                                    // With actual designer (proed), the definition of the sub-process is never in the same package
1794:                                    // as the main process (decision to be not full xpdl compliant with proed)
1795:                                    // But keep this fonction in the import code if this changes in the FUTUR
1796:                                    /*
1797:                                     * projectName = getCreateSubProject(Sub_Id,root);
1798:                                     */
1799:
1800:                                    // Get subflow version specified within an extended attribut
1801:                                    xpdlAct = obtainSubFlowVersion(a.Fils[i],
1802:                                            xpdlAct);
1803:                                    projectVersion = xpdlAct
1804:                                            .getSubFlowVersion();
1805:                                    //debug
1806:                                    //System.out.println("	******** SubFlowversion = " + projectVersion);
1807:                                    if (projectName != null
1808:                                            && projectVersion != null) {
1809:                                        if (projectExist(projectName,
1810:                                                projectVersion)) {
1811:
1812:                                            //get all the XPDL elements of this activity
1813:                                            xpdlAct = obtainActivityData(
1814:                                                    a.Fils[i], p, xpdlAct,
1815:                                                    xpdlData);
1816:                                            //debug
1817:                                            //System.out.println("Adding subflow : xpdlAct.getName() = " + xpdlAct.getName() + " projectName = " + projectName);
1818:                                            //if (projectName != null)
1819:                                            try {
1820:                                                p.addNodeSubProcess(xpdlAct
1821:                                                        .getName(),
1822:                                                        projectName,
1823:                                                        projectVersion);
1824:                                            } catch (HeroException he) {
1825:                                                he.printStackTrace();
1826:                                                throw new XPDLException(
1827:                                                        "Error adding SubProcess Node "
1828:                                                                + he
1829:                                                                        .getMessage()
1830:                                                                + " ", he);
1831:                                            }
1832:                                            /*
1833:                                            else {
1834:                                            // case projectName == null
1835:                                            	try {
1836:                                            		if (xpdlAct.getJoin().equalsIgnoreCase(MODE_TYPE_XOR))
1837:                                            			p.addNode(xpdlAct.getName(), Nd.OR_JOIN_AUTOMATIC_NODE);
1838:                                            		else p.addNode(xpdlAct.getName(), Nd.OR_JOIN_AUTOMATIC_NODE);
1839:
1840:                                            		//Set node non anticipable
1841:                                            		p.setNodeTraditional(xpdlAct.getName());
1842:                                            	} catch (HeroException he) {
1843:                                            		throw new XPDLException("Error adding SubProcess Node with projectName == null " + he.getMessage() + " ", he);
1844:                                            	}
1845:                                            }
1846:                                             */
1847:                                        }// end project exist
1848:                                        else {
1849:                                            // project has not been found in the engine database
1850:                                            // project is not searched into the the current or external packages !!
1851:                                            throw new XPDLException(
1852:                                                    "Error : the process = "
1853:                                                            + projectName
1854:                                                            + " with version = "
1855:                                                            + projectVersion
1856:                                                            + " used as sub process has not been found in the Workflow engine database");
1857:                                        }
1858:                                    }
1859:                                    // projectName or projectVersion is null
1860:                                    else {
1861:                                        throw new XPDLException(
1862:                                                "Error: Wrong SubProcess Id syntax");
1863:                                    }
1864:
1865:                                }
1866:
1867:                                //***************************
1868:                                // NO implementation Activity
1869:                                //***************************
1870:                                else if ((activity_type = getNode(a.Fils[i],
1871:                                        IMPLEMENTATION_NO)) != null) {
1872:                                    // get all the XPDL elements of this activity
1873:                                    xpdlAct = obtainActivityData(a.Fils[i], p,
1874:                                            xpdlAct, xpdlData);
1875:                                    xpdlAct
1876:                                            .setImplementation(IMPLEMENTATION_NO);
1877:
1878:                                    try {
1879:                                        if (xpdlAct.getMode().equalsIgnoreCase(
1880:                                                MANUAL)) {
1881:                                            if (xpdlAct.getJoin()
1882:                                                    .equalsIgnoreCase(
1883:                                                            MODE_TYPE_XOR))
1884:                                                p.addNode(xpdlAct.getName(),
1885:                                                        Nd.OR_JOIN_NODE);
1886:                                            else
1887:                                                p.addNode(xpdlAct.getName(),
1888:                                                        Nd.AND_JOIN_NODE);
1889:                                        } else if (xpdlAct.getMode()
1890:                                                .equalsIgnoreCase(AUTOMATIC)) {
1891:                                            if (xpdlAct.getJoin()
1892:                                                    .equalsIgnoreCase(
1893:                                                            MODE_TYPE_XOR))
1894:                                                p
1895:                                                        .addNode(
1896:                                                                xpdlAct
1897:                                                                        .getName(),
1898:                                                                Nd.OR_JOIN_AUTOMATIC_NODE);
1899:                                            else
1900:                                                p
1901:                                                        .addNode(
1902:                                                                xpdlAct
1903:                                                                        .getName(),
1904:                                                                Nd.AND_JOIN_AUTOMATIC_NODE);
1905:                                        }
1906:                                        // Set node non anticipable
1907:                                        p.setNodeTraditional(xpdlAct.getName());
1908:
1909:                                    } catch (HeroException he) {
1910:                                        throw new XPDLException(
1911:                                                he.getMessage(), he);
1912:                                    }
1913:                                    /*
1914:                                     *  Extended Bonita properties within activity
1915:                                     */
1916:
1917:                                    //debug
1918:                                    //System.out.println("Set the properties for Activity: " +	xpdlAct.getName());
1919:                                    /*  properties ListArray contains id of the datafield (key of the Hashtable)
1920:                                     * A remplacer par la création de l'un de ces type
1921:                                     */
1922:                                    if (!xpdlAct.getProperties().isEmpty()) {
1923:                                        // get also the collection the propagation
1924:                                        //debug
1925:                                        //System.out.println(" xpdlAct.getProperties() is not empty");
1926:                                        ArrayList ar_properties = xpdlAct
1927:                                                .getProperties();
1928:
1929:                                        //get also the collection the propagation
1930:                                        ArrayList ar_propagations = xpdlAct
1931:                                                .getPropagations();
1932:                                        Iterator it_propagate = ar_propagations
1933:                                                .iterator();
1934:
1935:                                        Iterator it_prop = ar_properties
1936:                                                .iterator();
1937:                                        while (it_prop.hasNext()
1938:                                                && it_propagate.hasNext()) {
1939:                                            // get the datafield with the Id
1940:                                            //TODO
1941:                                            Hashtable dataFieldMapping = (Hashtable) xpdlData
1942:                                                    .get("dataFieldMapping");
1943:                                            XPDLDataField xpdlDataField = (XPDLDataField) dataFieldMapping
1944:                                                    .get(it_prop.next());
1945:
1946:                                            // get the propagation value: true or false
1947:                                            boolean b_propagation = ((Boolean) it_propagate
1948:                                                    .next()).booleanValue();
1949:
1950:                                            // STRING
1951:                                            if (BASICTYPE
1952:                                                    .equalsIgnoreCase(xpdlDataField
1953:                                                            .getDataType())) {
1954:                                                if ("String"
1955:                                                        .equalsIgnoreCase(xpdlDataField
1956:                                                                .getBasicType())) {
1957:                                                    try {
1958:                                                        p
1959:                                                                .setNodeProperty(
1960:                                                                        xpdlAct
1961:                                                                                .getName(),
1962:                                                                        xpdlDataField
1963:                                                                                .getName(),
1964:                                                                        xpdlDataField
1965:                                                                                .getInitialValue(),
1966:                                                                        b_propagation);
1967:                                                    } catch (HeroException he) {
1968:                                                        throw new XPDLException(
1969:                                                                he.getMessage(),
1970:                                                                he);
1971:                                                    }
1972:                                                }
1973:                                            }
1974:                                            // ENUMERATION
1975:                                            if (ENUMERATIONTYPE
1976:                                                    .equalsIgnoreCase(xpdlDataField
1977:                                                            .getDataType())) {
1978:                                                ArrayList ar = xpdlDataField
1979:                                                        .getEnumeration();
1980:                                                ArrayList values = new ArrayList();
1981:                                                Iterator it2 = ar.iterator();
1982:                                                while (it2.hasNext()) {
1983:                                                    String val = (String) it2
1984:                                                            .next();
1985:                                                    values.add(val);
1986:                                                }
1987:                                                //Debug
1988:                                                //System.out.println("createNodeProperties: create property Name = " + xpdlDataField.getName() + " Value = " + xpdlDataField.getInitialValue());
1989:                                                //set the enum property
1990:                                                try {
1991:                                                    p
1992:                                                            .setNodePropertyPossibleValues(
1993:                                                                    xpdlAct
1994:                                                                            .getName(),
1995:                                                                    xpdlDataField
1996:                                                                            .getName(),
1997:                                                                    values);
1998:                                                    if (!""
1999:                                                            .equals(xpdlDataField
2000:                                                                    .getInitialValue()))
2001:                                                        p
2002:                                                                .setNodeProperty(
2003:                                                                        xpdlAct
2004:                                                                                .getName(),
2005:                                                                        xpdlDataField
2006:                                                                                .getName(),
2007:                                                                        xpdlDataField
2008:                                                                                .getInitialValue(),
2009:                                                                        b_propagation);
2010:                                                } catch (HeroException he) {
2011:                                                    throw new XPDLException(
2012:                                                            "Error setting the initial value of: "
2013:                                                                    + xpdlDataField
2014:                                                                            .getName()
2015:                                                                    + "  "
2016:                                                                    + he
2017:                                                                            .getMessage(),
2018:                                                            he);
2019:                                                }
2020:                                            }
2021:                                        }
2022:                                    }
2023:
2024:                                    /*   >>>>>>>>>>>>>>>>>>>>>
2025:                                     *   >>>>> DEADLINES <<<<<
2026:                                     *   <<<<<<<<<<<<<<<<<<<<<
2027:                                     */
2028:
2029:                                    if (xpdlAct.getDeadline()) {
2030:                                        // conditions could be either relative time:    in milliseconds (ex.: 60000)
2031:                                        //                   or fixed time:      yy/MM/dd/hh/mm/ss (ex. 2005/01/21/14/00/00)
2032:                                        // Separate the 2 types	of deadlines into 2 separate arraylists
2033:                                        ArrayList condition = xpdlAct
2034:                                                .getDeadlineCondition();
2035:                                        String regex = "/";
2036:                                        Iterator it = condition.iterator();
2037:                                        String[] tab;
2038:                                        while (it.hasNext()) {
2039:                                            String cond = (String) it.next();
2040:                                            tab = cond.split(regex);
2041:                                            if (tab.length > 1) {
2042:                                                int year = (new Integer(tab[0]))
2043:                                                        .intValue();
2044:                                                int month = (new Integer(tab[1]))
2045:                                                        .intValue();
2046:                                                int date = (new Integer(tab[2]))
2047:                                                        .intValue();
2048:                                                int hour = (new Integer(tab[3]))
2049:                                                        .intValue();
2050:                                                int minute = (new Integer(
2051:                                                        tab[4])).intValue();
2052:                                                int second = (new Integer(
2053:                                                        tab[5])).intValue();
2054:
2055:                                                GregorianCalendar gc = new GregorianCalendar(
2056:                                                        year, month, date,
2057:                                                        hour, minute, second);
2058:                                                long t = gc.getTimeInMillis();
2059:                                                String time_s = (new Long(t))
2060:                                                        .toString();
2061:                                                xpdlAct
2062:                                                        .setFixedTimeDeadline(time_s);
2063:                                                //debug
2064:                                                //System.out.println("Set Fixed time deadline with time = " + time_s );
2065:                                            } else if (tab.length == 1) {
2066:                                                xpdlAct
2067:                                                        .setRelativeTimeDeadline(cond);
2068:
2069:                                                //System.out.println("Set Relative deadline with time = " + cond);
2070:                                            } else {
2071:                                                //debug
2072:                                                //System.out.println("the following deadline condition is not correct: " + cond);
2073:                                                // raise exception ??
2074:                                            }
2075:                                        }
2076:                                        try {
2077:                                            // set Node relative deadline if it exists
2078:                                            ArrayList fixedTimeDeadlines = xpdlAct
2079:                                                    .getFixedTimeDeadline();
2080:                                            p.setNodeDeadlines(xpdlAct
2081:                                                    .getName(),
2082:                                                    fixedTimeDeadlines);
2083:                                            // set Node fixed deadline if it exists
2084:                                            ArrayList relativeTimeDeadlines = xpdlAct
2085:                                                    .getRelativeTimeDeadline();
2086:                                            p.setNodeRelativeDeadlines(xpdlAct
2087:                                                    .getName(),
2088:                                                    relativeTimeDeadlines);
2089:
2090:                                            //add Node Hook
2091:                                            String exception = xpdlAct
2092:                                                    .getExceptionName();
2093:                                            // Not used at now ArrayList execution =  xpdlAct.getDeadlineExecution();
2094:                                            p
2095:                                                    .addNodeHook(
2096:                                                            xpdlAct.getName(),
2097:                                                            exception,
2098:                                                            hero.interfaces.Constants.Nd.ONDEADLINE,
2099:                                                            Hook.JAVA);
2100:                                        } catch (HeroException he) {
2101:                                            throw new XPDLException(he
2102:                                                    .getMessage(), he);
2103:                                        }
2104:                                    } // end deadlines
2105:
2106:                                    /*   >>>>>>>>>>>>>>>>
2107:                                     *   >>>>> HOOK <<<<<
2108:                                     *   <<<<<<<<<<<<<<<<
2109:                                     */
2110:
2111:                                    ArrayList ar = xpdlAct.getXpdlHook();
2112:                                    Iterator it_phook = ar.iterator();
2113:                                    String hookName = "";
2114:                                    XPDLHook xpdlHook = null;
2115:                                    while (it_phook.hasNext()) {
2116:                                        xpdlHook = (XPDLHook) it_phook.next();
2117:                                        hookName = xpdlHook.getHookName();
2118:                                        if (!"".equals(hookName)) {
2119:                                            //debug
2120:                                            //System.out.println(">>> Add Hook to activity : " + xpdlAct.getName() + "  HookName = " + hookName + " EventName = " + xpdlHook.getHookEventName() + " Script = " + xpdlHook.getHookScript());
2121:
2122:                                            String hookEventName = "";
2123:                                            String hookEvent = "";
2124:
2125:                                            if (!"".equals(xpdlHook
2126:                                                    .getHookEventName())) {
2127:                                                hookEventName = xpdlHook
2128:                                                        .getHookEventName();
2129:
2130:                                                if (Nd.BEFORESTART
2131:                                                        .equalsIgnoreCase(hookEventName))
2132:                                                    hookEvent = Nd.BEFORESTART;
2133:                                                else if (Nd.AFTERSTART
2134:                                                        .equalsIgnoreCase(hookEventName))
2135:                                                    hookEvent = Nd.AFTERSTART;
2136:                                                else if (Nd.BEFORETERMINATE
2137:                                                        .equalsIgnoreCase(hookEventName))
2138:                                                    hookEvent = Nd.BEFORETERMINATE;
2139:                                                else if (Nd.AFTERTERMINATE
2140:                                                        .equalsIgnoreCase(hookEventName))
2141:                                                    hookEvent = Nd.AFTERTERMINATE;
2142:                                                else if (Nd.ONCANCEL
2143:                                                        .equalsIgnoreCase(hookEventName))
2144:                                                    hookEvent = Nd.ONCANCEL;
2145:                                                else if (Nd.ONREADY
2146:                                                        .equalsIgnoreCase(hookEventName))
2147:                                                    hookEvent = Nd.ONREADY;
2148:                                                else
2149:                                                    throw new XPDLException(
2150:                                                            "Syntax Error in Extended Attribut with Name = hook - "
2151:                                                                    + hookEventName
2152:                                                                    + " is Unknown hookEvent");
2153:                                            }
2154:
2155:                                            // By default AFTERSTART if the ext. attribute has not the complex type
2156:                                            // <HookEventName> afterStart </HookEventName>
2157:
2158:                                            else {
2159:                                                hookEvent = Nd.AFTERSTART;
2160:                                            }
2161:
2162:                                            if ("".equals(xpdlHook
2163:                                                    .getHookScript())) {
2164:                                                // javaHook  with by default HookType = Constants.Hook.JAVA
2165:                                                try {
2166:                                                    p
2167:                                                            .addNodeHook(
2168:                                                                    xpdlAct
2169:                                                                            .getName(),
2170:                                                                    xpdlHook
2171:                                                                            .getHookName(),
2172:                                                                    hookEventName,
2173:                                                                    Hook.JAVA);
2174:                                                } catch (HeroException he) {
2175:                                                    throw new XPDLException(he
2176:                                                            .getMessage(), he);
2177:                                                }
2178:                                                //debug
2179:                                                //System.out.println("Set JAVA Hook for Activity : Name = " + xpdlAct.getName() + " Hook Name = " + xpdlHook.getHookName() + " Event = " + hookEventName );
2180:                                            } else {
2181:                                                // interHook  with by default HookType = Constants.Hook.BSINTERACTIVE
2182:                                                String hookScript = "";
2183:                                                hookScript = xpdlHook
2184:                                                        .getHookScript();
2185:
2186:                                                String script = "import hero.interfaces.BnProjectLocal;\n"
2187:                                                        + "import hero.interfaces.BnNodeLocal;\n"
2188:                                                        //+ "afterStart (Object b,Object n) {\n\n\n"
2189:                                                        + hookEventName
2190:                                                        + " (Object b,Object n) {\n\n\n"
2191:                                                        //+ "System.out.println(\"InteractiveBnNodee Hook test, node: \"+n.getName());"
2192:                                                        + hookScript + "}";
2193:                                                try {
2194:                                                    p
2195:                                                            .addNodeInterHook(
2196:                                                                    xpdlAct
2197:                                                                            .getName(),
2198:                                                                    xpdlHook
2199:                                                                            .getHookName(),
2200:                                                                    hookEventName,
2201:                                                                    Hook.BSINTERACTIVE,
2202:                                                                    script);
2203:                                                } catch (HeroException he) {
2204:                                                    throw new XPDLException(he
2205:                                                            .getMessage(), he);
2206:                                                }
2207:                                                //debug
2208:                                                //System.out.println("Set INTER Hook for Activity : Name = " + xpdlAct.getName() + " Hook Name = " + xpdlHook.getHookName()
2209:                                                //		+ " Event = " + hookEventName + " Script = \n" + script);
2210:                                            }
2211:                                        } // end if
2212:                                        else
2213:                                            throw new XPDLException(
2214:                                                    "A Hook for activity : "
2215:                                                            + xpdlAct.getName()
2216:                                                            + " does not have HookName!");
2217:
2218:                                    } //end while
2219:
2220:                                    /*   >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2221:                                     *   >>>>> PERFORMER ASSIGNMENT <<<<<
2222:                                     *   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2223:                                     */
2224:                                    if (!"".equals(xpdlAct
2225:                                            .getPerformerAssignName())) {
2226:                                        String perfAssignType = xpdlAct
2227:                                                .getPerformerAssignType();
2228:                                        int pAType = PerformerAssigment.CALLBACK;
2229:                                        //debug
2230:                                        //System.out.println("obtainCreateActivity: perfAssignType = " + perfAssignType );
2231:
2232:                                        if (perfAssignType
2233:                                                .equalsIgnoreCase(PERFORMER_ASSIGN_PROPERTY))
2234:                                            pAType = PerformerAssigment.PROPERTIES;
2235:                                        else if (perfAssignType
2236:                                                .equalsIgnoreCase(PERFORMER_ASSIGN_CALLBACK))
2237:                                            pAType = PerformerAssigment.CALLBACK;
2238:                                        //debug
2239:                                        //System.out.println("obtainCreateActivity/addNodePerformerAssign : name = " + xpdlAct.getPerformerAssignName() + " type = "
2240:                                        //		+ pAType + " property = " + xpdlAct.getPerformerAssignProperty());
2241:                                        try {
2242:                                            p
2243:                                                    .addNodePerformerAssign(
2244:                                                            xpdlAct.getName(),
2245:                                                            xpdlAct
2246:                                                                    .getPerformerAssignName(),
2247:                                                            pAType,
2248:                                                            xpdlAct
2249:                                                                    .getPerformerAssignProperty());
2250:                                        } catch (HeroException he) {
2251:                                            throw new XPDLException(he
2252:                                                    .getMessage(), he);
2253:                                        }
2254:                                    }
2255:
2256:                                } // end NO
2257:
2258:                                //*****************
2259:                                //	TOOL Activity
2260:                                //*****************
2261:                                else if ((activity_type = getNode(a.Fils[i],
2262:                                        TOOL)) != null) {
2263:                                    Element tool = (Element) activity_type.Noeud;
2264:                                    String appId = tool
2265:                                            .getAttribute(APPLICATION_ID);
2266:
2267:                                    //get all the XPDL elements of this activity (and specifically: application Id, Actual to formal mapping)
2268:                                    xpdlAct = obtainActivityData(a.Fils[i], p,
2269:                                            xpdlAct, xpdlData);
2270:                                    xpdlAct
2271:                                            .setImplementation(IMPLEMENTATION_TOOL);
2272:
2273:                                    try {
2274:                                        if (xpdlAct.getJoin().equalsIgnoreCase(
2275:                                                MODE_TYPE_XOR))
2276:                                            p.addNode(xpdlAct.getName(),
2277:                                                    Nd.OR_JOIN_AUTOMATIC_NODE);
2278:                                        else
2279:                                            p.addNode(xpdlAct.getName(),
2280:                                                    Nd.AND_JOIN_AUTOMATIC_NODE);
2281:
2282:                                        // Set node non anticipable
2283:                                        p.setNodeTraditional(xpdlAct.getName());
2284:                                    } catch (HeroException he) {
2285:                                        throw new XPDLException(
2286:                                                he.getMessage(), he);
2287:                                    }
2288:                                    //TODO
2289:                                    Hashtable appliMapping = (Hashtable) xpdlData
2290:                                            .get("appliMapping");
2291:                                    XPDLApplication xpdlAppli = (XPDLApplication) appliMapping
2292:                                            .get(appId);
2293:                                    /*
2294:                                     * check the Application definition level is package or the given WFProcess
2295:                                     */
2296:                                    String projectTarget = xpdlAppli
2297:                                            .getProjectName();
2298:
2299:                                    String applicationId = xpdlAppli.getId();
2300:                                    String applicationNameMethode = xpdlAppli
2301:                                            .getName();
2302:                                    // get the application class by removing ".methode" from applicationNameMethode
2303:                                    int index = 1;
2304:                                    //Get applicationName from applicationNameMethode
2305:                                    String applicationName = "";
2306:                                    String[] tab;
2307:                                    tab = applicationNameMethode.split("\\.");
2308:                                    //debug
2309:                                    //System.out.println("Java static methode : " + applicationNameMethode);
2310:                                    for (int j = 0; j < tab.length - 1; j++) {
2311:                                        //debug
2312:                                        //System.out.println("tab[" + j + "]= " + tab[j] );
2313:                                        if (j != tab.length - 2)
2314:                                            applicationName = applicationName
2315:                                                    + tab[j] + ".";
2316:                                        else
2317:                                            applicationName = applicationName
2318:                                                    + tab[j];
2319:                                    }
2320:
2321:                                    //Get ActualParameters values and build the signature of the application with the these values
2322:                                    ArrayList ar_ap = xpdlAct
2323:                                            .getActualParameter();
2324:                                    String signature = "";
2325:                                    int nb = 0;
2326:                                    String actualParameterValue = null;
2327:                                    if (ar_ap.size() != 0) {
2328:                                        Iterator it_ap = ar_ap.iterator();
2329:                                        BnProjectPropertyValue bnProjectPropertyValue = null;
2330:                                        while (it_ap.hasNext()) {
2331:                                            String actualParameterId = (String) it_ap
2332:                                                    .next();
2333:                                            //System.out.println("       . ActualParameter : " + actualParameter);
2334:                                            // actual parameter Name
2335:                                            //TODO
2336:                                            Hashtable dataFieldMapping = (Hashtable) xpdlData
2337:                                                    .get("dataFieldMapping");
2338:                                            XPDLDataField xpdlDataFieldActualParam = (XPDLDataField) dataFieldMapping
2339:                                                    .get(actualParameterId);
2340:                                            String actualParameterName = xpdlDataFieldActualParam
2341:                                                    .getName();
2342:                                            //debug
2343:                                            //System.out.println("ObtainCreateActivity : actualParameterName = " + 	actualParameterName);
2344:
2345:                                            try {
2346:                                                bnProjectPropertyValue = p
2347:                                                        .getProperty(actualParameterName);
2348:                                            } catch (HeroException he) {
2349:                                                throw new XPDLException(
2350:                                                        "Error getting bnNodePropertyValue: "
2351:                                                                + he
2352:                                                                        .getMessage(),
2353:                                                        he);
2354:                                            }
2355:                                            try {
2356:                                                actualParameterValue = bnProjectPropertyValue
2357:                                                        .getTheValue();
2358:                                            } catch (Exception e) {
2359:                                                throw new XPDLException(
2360:                                                        "Error getting actualParameterValue for : "
2361:                                                                + actualParameterName
2362:                                                                + "  "
2363:                                                                + e
2364:                                                                        .getMessage(),
2365:                                                        e);
2366:                                            }
2367:                                            // Construct the signature of the application with the values of actualParameters
2368:                                            // ex. of signature got: "toto.titi@bull.net","essai","ceci est un essai"
2369:                                            // We have done the hypothesis:
2370:                                            //    - no check on dataType => risks at execution time
2371:                                            //    - the order of the formal parameters is the same as the actual one :
2372:                                            //      This is implicitly done by JaWE in the mapping screen
2373:                                            //      The Index , Id for Formal parameters has no role !!!
2374:                                            //    - We do not check the mode which is implicitly IN !!
2375:                                            if (nb == ar_ap.size() - 1)
2376:                                                signature = signature + "\""
2377:                                                        + actualParameterValue
2378:                                                        + "\"";
2379:                                            else {
2380:                                                signature = signature + "\""
2381:                                                        + actualParameterValue
2382:                                                        + "\"" + ",";
2383:                                                nb++;
2384:                                            }
2385:                                        }
2386:                                        //debug
2387:                                        //System.out.println("ObtainCreateActivity: application signature = " + signature );
2388:
2389:                                    }
2390:
2391:                                    String script = "import hero.interfaces.*;\n"
2392:                                            + "import hero.interfaces.BnNodeLocal;\n"
2393:                                            + "beforeTerminate (Object b,Object n) {\n"
2394:                                            + "import "
2395:                                            + applicationName
2396:                                            + ";\n";
2397:
2398:                                    // debug
2399:                                    //script = script + "System.out.println(\"interactive hook executed !!!\");\n";
2400:
2401:                                    script = script + applicationNameMethode
2402:                                            + "(" + signature + ");}";
2403:                                    try {
2404:                                        p.addNodeInterHook(xpdlAct.getName(),
2405:                                                "Hook_" + appId,
2406:                                                Nd.BEFORETERMINATE,
2407:                                                Hook.BSINTERACTIVE, script);
2408:                                    } catch (HeroException he) {
2409:                                        throw new XPDLException(
2410:                                                he.getMessage(), he);
2411:                                    }
2412:
2413:                                    //debug
2414:                                    // System.out.println("Set Tool for activity = " + xpdlAct.getName() + " InterHookName = Hook_" + appId);
2415:                                }
2416:
2417:                                //*****************
2418:                                // ROUTE Activity
2419:                                //*****************
2420:                                else if ((activity_type = getNode(a.Fils[i],
2421:                                        ROUTE)) != null) {
2422:                                    //get all the XPDL elements of this activity
2423:                                    xpdlAct = obtainActivityData(a.Fils[i], p,
2424:                                            xpdlAct, xpdlData);
2425:                                    try {
2426:                                        if (xpdlAct.getJoin().equalsIgnoreCase(
2427:                                                MODE_TYPE_XOR))
2428:                                            p.addNode(xpdlAct.getName(),
2429:                                                    Nd.OR_JOIN_AUTOMATIC_NODE);
2430:                                        else
2431:                                            p.addNode(xpdlAct.getName(),
2432:                                                    Nd.AND_JOIN_AUTOMATIC_NODE);
2433:
2434:                                        // Set node non anticipable
2435:                                        p.setNodeTraditional(xpdlAct.getName());
2436:                                    } catch (HeroException he) {
2437:                                        throw new XPDLException(
2438:                                                he.getMessage(), he);
2439:                                    }
2440:                                }
2441:
2442:                                //*****************
2443:                                //	BLOCK Activity
2444:                                //*****************
2445:
2446:                                else if ((activity_type = getNode(a.Fils[i],
2447:                                        BLOCK)) != null) {
2448:                                    try {
2449:                                        Element ele = (Element) activity_type.Noeud;
2450:                                        String blockId = ele
2451:                                                .getAttribute(BLOCK_ID);
2452:
2453:                                        //get all the XPDL elements of this activity
2454:                                        xpdlAct = obtainActivityData(a.Fils[i],
2455:                                                p, xpdlAct, xpdlData);
2456:
2457:                                        if (xpdlAct.getMode().equalsIgnoreCase(
2458:                                                MANUAL)) {
2459:                                            if (xpdlAct.getJoin()
2460:                                                    .equalsIgnoreCase(
2461:                                                            MODE_TYPE_XOR))
2462:                                                p.addNode(xpdlAct.getName(),
2463:                                                        Nd.OR_JOIN_NODE);
2464:                                            else
2465:                                                p.addNode(xpdlAct.getName(),
2466:                                                        Nd.AND_JOIN_NODE);
2467:                                        } else if (xpdlAct.getMode()
2468:                                                .equalsIgnoreCase(AUTOMATIC)) {
2469:                                            if (xpdlAct.getJoin()
2470:                                                    .equalsIgnoreCase(
2471:                                                            MODE_TYPE_XOR))
2472:                                                p
2473:                                                        .addNode(
2474:                                                                xpdlAct
2475:                                                                        .getName(),
2476:                                                                Nd.OR_JOIN_AUTOMATIC_NODE);
2477:                                            else
2478:                                                p
2479:                                                        .addNode(
2480:                                                                xpdlAct
2481:                                                                        .getName(),
2482:                                                                Nd.AND_JOIN_AUTOMATIC_NODE);
2483:                                        }
2484:                                        // Set node non anticipable
2485:                                        p.setNodeTraditional(xpdlAct.getName());
2486:
2487:                                        connectBlock(xpdlAct.getName(),
2488:                                                blockId, p, xpdlData);
2489:                                    } catch (HeroException he) {
2490:                                        throw new XPDLException(
2491:                                                he.getMessage(), he);
2492:                                    }
2493:                                }
2494:                                //****************************************
2495:                                //	Other attributs for all activity types:
2496:                                //     - description
2497:                                //     - performer & role mapper
2498:                                //     - iteration
2499:                                //****************************************
2500:
2501:                                // *******   set the description of the activity *********
2502:                                //p.setNodeDescription((String)actMapping.get(xpdlAct.getId()), xpdlAct.getDescription());
2503:                                try {
2504:                                    p.setNodeDescription(xpdlAct.getName(),
2505:                                            xpdlAct.getDescription());
2506:                                } catch (HeroException he) {
2507:                                    throw new XPDLException(he.getMessage(), he);
2508:                                }
2509:
2510:                                // set the PERFORMER of the activity if it exists
2511:                                String participant_type = null;
2512:                                if (!("".equalsIgnoreCase(xpdlAct
2513:                                        .getPerformer()))) {
2514:                                    //try {
2515:                                    //get XPDLParticipant Bean with the Id
2516:                                    //TODO
2517:                                    Hashtable partMapping = (Hashtable) xpdlData
2518:                                            .get("partMapping");
2519:                                    XPDLParticipant xpdlPart = (XPDLParticipant) partMapping
2520:                                            .get(xpdlAct.getPerformer());
2521:                                    // Get the participant type
2522:                                    if (xpdlPart != null) {
2523:                                        participant_type = xpdlPart.getType();
2524:                                    } else {
2525:                                        throw new XPDLException(
2526:                                                "Error: participant definition not defined for the performer = "
2527:                                                        + xpdlAct
2528:                                                                .getPerformer());
2529:                                    }
2530:
2531:                                    // performer == HUMAN  => add user to the project
2532:                                    // This will be also an role that will be added to the activity
2533:                                    if (participant_type
2534:                                            .equalsIgnoreCase(PARTICIPANT_TYPE_HUMAN)) {
2535:                                        // test if the user already exists in the project
2536:                                        try {
2537:                                            Collection co = p.getUsers();
2538:                                            Iterator it = co.iterator();
2539:                                            ArrayList ar = new ArrayList();
2540:                                            while (it.hasNext()) {
2541:                                                //BnUserLocal user = (BnUserLocal)it.next();
2542:                                                String userName = (String) it
2543:                                                        .next();
2544:                                                //ar.add(user.getName());
2545:                                                ar.add(userName);
2546:                                            }
2547:
2548:                                            if (!ar
2549:                                                    .contains(xpdlPart
2550:                                                            .getName())) {
2551:                                                p.addUser(xpdlPart.getName());
2552:                                            }
2553:                                        } catch (HeroException he) {
2554:                                            throw new XPDLException(he
2555:                                                    .getMessage(), he);
2556:                                        }
2557:                                    }
2558:
2559:                                    // performer == (ROLE || OU)
2560:                                    else if (participant_type
2561:                                            .equalsIgnoreCase(PARTICIPANT_TYPE_ROLE)
2562:                                            || participant_type
2563:                                                    .equalsIgnoreCase(PARTICIPANT_TYPE_ORGANIZATIONAL_UNIT)) {
2564:                                        try {
2565:                                            //test if the role already exists in the project
2566:                                            Collection co = p.getRoles();
2567:                                            Iterator it = co.iterator();
2568:                                            ArrayList ar = new ArrayList();
2569:                                            while (it.hasNext()) {
2570:                                                BnRoleLocal role = (BnRoleLocal) it
2571:                                                        .next();
2572:                                                ar.add(role.getName());
2573:                                            }
2574:                                            if (!ar
2575:                                                    .contains(xpdlPart
2576:                                                            .getName())) {
2577:                                                p
2578:                                                        .addRole(
2579:                                                                xpdlPart
2580:                                                                        .getName(),
2581:                                                                xpdlPart
2582:                                                                        .getDescription());
2583:                                            }
2584:                                        } catch (HeroException he) {
2585:                                            throw new XPDLException(he
2586:                                                    .getMessage(), he);
2587:                                        }
2588:                                        /*
2589:                                         *  adding role mapper if extended attributs for role mapping
2590:                                         */
2591:                                        if (!""
2592:                                                .equals(xpdlPart
2593:                                                        .getMapperName())) {
2594:                                            try {
2595:                                                if (xpdlPart
2596:                                                        .getMapperType()
2597:                                                        .equalsIgnoreCase(
2598:                                                                EXTENDED_ATTRIBUTE_VALUE_LDAP)) {
2599:                                                    p
2600:                                                            .addRoleMapper(
2601:                                                                    xpdlPart
2602:                                                                            .getName(),
2603:                                                                    xpdlPart
2604:                                                                            .getMapperName(),
2605:                                                                    Mapper.LDAP);
2606:                                                } else if (xpdlPart
2607:                                                        .getMapperType()
2608:                                                        .equalsIgnoreCase(
2609:                                                                EXTENDED_ATTRIBUTE_VALUE_PROPERTIES)) {
2610:                                                    p
2611:                                                            .addRoleMapper(
2612:                                                                    xpdlPart
2613:                                                                            .getName(),
2614:                                                                    xpdlPart
2615:                                                                            .getMapperName(),
2616:                                                                    Mapper.PROPERTIES);
2617:                                                } else if (xpdlPart
2618:                                                        .getMapperType()
2619:                                                        .equalsIgnoreCase(
2620:                                                                EXTENDED_ATTRIBUTE_VALUE_CUSTUM)) {
2621:                                                    //in this case MapperClassName = MapperName
2622:                                                    p
2623:                                                            .addRoleMapper(
2624:                                                                    xpdlPart
2625:                                                                            .getName(),
2626:                                                                    xpdlPart
2627:                                                                            .getMapperName(),
2628:                                                                    Mapper.CUSTOM);
2629:                                                }
2630:                                            } catch (HeroException he) {
2631:                                                throw new XPDLException(
2632:                                                        "Error setting RoleMappper for Role = "
2633:                                                                + xpdlPart
2634:                                                                        .getName()
2635:                                                                + " "
2636:                                                                + he
2637:                                                                        .getMessage(),
2638:                                                        he);
2639:                                            }
2640:                                        }
2641:                                    }
2642:                                    // set the role for the Node (activity) except for the Role : InitialRole (case of performer type = SYSTEM)
2643:                                    if (!participant_type
2644:                                            .equalsIgnoreCase(PARTICIPANT_TYPE_SYSTEM)) {
2645:                                        //debug
2646:                                        //System.out.println("Set the role: " + xpdlPart.getName() + " to activity: " + xpdlAct.getName());
2647:                                        try {
2648:                                            //p.setNodeRole((String)actMapping.get(xpdlAct.getId()), xpdlPart.getName() );
2649:                                            p.setNodeRole(xpdlAct.getName(),
2650:                                                    xpdlPart.getName());
2651:                                        } catch (HeroException he) {
2652:                                            throw new XPDLException(he
2653:                                                    .getMessage(), he);
2654:                                        }
2655:                                    }
2656:                                }// end set performer
2657:                            }
2658:                        }
2659:                    }
2660:                }
2661:            }
2662:
2663:            /*
2664:             * Connect Block Activity with its corresponding activity set
2665:             */
2666:            private void connectBlock(String name, String blockId,
2667:                    ProjectSessionLocal p, Hashtable xpdlData)
2668:                    throws HeroException {
2669:                try {
2670:                    //TODO
2671:                    Hashtable activitySetMapping = (Hashtable) xpdlData
2672:                            .get("activitySetMapping");
2673:                    String block = (String) activitySetMapping.get(blockId);
2674:                    int index = block.indexOf(ACT_SET_MAP_SEPARATOR);
2675:                    String actLast = block.substring(0, index);
2676:                    String actFirst = block.substring(index
2677:                            + ACT_SET_MAP_SEPARATOR_LENGTH);
2678:                    // Transition between block activity and the first one of the activitySet
2679:                    p.addEdge(name, actFirst);
2680:                    // add iteration between the last activity of the activitySet and the BlockActivity
2681:                    p.addIteration(actLast, name, "false");
2682:                } catch (HeroException he) {
2683:                    throw new HeroException("Error in connectBlock:  "
2684:                            + he.getMessage(), he);
2685:                }
2686:
2687:                catch (Exception e) {
2688:                    throw new HeroException("Error in connectBlock:  "
2689:                            + e.getMessage(), e);
2690:                }
2691:            }
2692:
2693:            /*
2694:             *   Obtain attributes for Application:
2695:             *      - Formal parameters
2696:             */
2697:            private XPDLApplication obtainApplicationData(BonitaTree n,
2698:                    XPDLApplication xpdlAppli) throws XPDLException {
2699:
2700:                int type = n.Noeud.getNodeType();
2701:                switch (type) {
2702:                case Node.ATTRIBUTE_NODE:
2703:                    break;
2704:
2705:                case Node.ELEMENT_NODE:
2706:                    if (n.Noeud.getNodeName().equalsIgnoreCase(
2707:                            FORMAL_PARAMETERS)) {
2708:                        for (int j = 0; j < n.NbFils; j++) {
2709:                            if ((n.Fils[j].Noeud.getNodeName())
2710:                                    .equalsIgnoreCase(FORMAL_PARAMETER)) {
2711:                                Element ele = (Element) n.Fils[j].Noeud;
2712:                                //set XPDLFormalParameter Bean into xpdlAppli Bean
2713:                                XPDLFormalParameter xpdlFormalParam = new XPDLFormalParameter();
2714:                                xpdlFormalParam.setId(ele
2715:                                        .getAttribute(FORMAL_PARAMETER_ID));
2716:                                xpdlFormalParam.setIndex(ele
2717:                                        .getAttribute(FORMAL_PARAMETER_INDEX));
2718:                                xpdlFormalParam.setMode(ele
2719:                                        .getAttribute(FORMAL_PARAMETER_MODE));
2720:                                xpdlAppli.setFormalParam(xpdlFormalParam);
2721:                            }
2722:                        }
2723:                    }
2724:                    break;
2725:
2726:                default:
2727:                    break;
2728:                }
2729:
2730:                for (int k = 0; k < n.NbFils; k++) {
2731:                    obtainApplicationData(n.Fils[k], xpdlAppli);
2732:                }
2733:                return xpdlAppli;
2734:            }
2735:
2736:            /*
2737:             *   Obtain attributes for DataField:
2738:             *      - dataType
2739:             * 		- basicType
2740:             * 		- initial value
2741:             */
2742:            private XPDLDataField obtainDataFieldData(BonitaTree n,
2743:                    XPDLDataField xpdlDataField) {
2744:                int type = n.Noeud.getNodeType();
2745:                switch (type) {
2746:                case Node.ATTRIBUTE_NODE:
2747:                    break;
2748:
2749:                case Node.ELEMENT_NODE:
2750:                    // get BasicType of Type STRING
2751:                    if ((n.Noeud.getNodeName().equalsIgnoreCase(BASICTYPE))) {
2752:                        xpdlDataField.setDataType(n.Noeud.getNodeName());
2753:                        Element ele = (Element) n.Noeud;
2754:                        xpdlDataField.setBasicType(ele
2755:                                .getAttribute(DATATYPE_TYPE));
2756:                    } else if ((n.Noeud.getNodeName()
2757:                            .equalsIgnoreCase(ENUMERATIONTYPE))) {
2758:                        // Get EnumerationType
2759:                        xpdlDataField.setDataType(n.Noeud.getNodeName());
2760:                        for (int j = 0; j < n.NbFils; j++) {
2761:                            if ((n.Fils[j].Noeud.getNodeName())
2762:                                    .equalsIgnoreCase(ENUMERATIONVALUE)) {
2763:                                Element ele = (Element) n.Fils[j].Noeud;
2764:                                xpdlDataField.setEnumeration(ele
2765:                                        .getAttribute(ENUMERATIONVALUENAME));
2766:                            }
2767:                        }
2768:                    } else if ((n.Noeud.getNodeName()
2769:                            .equalsIgnoreCase(EXTENDED_ATTRIBUTES))) {
2770:                        for (int j = 0; j < n.NbFils; j++) {
2771:                            if ((n.Fils[j].Noeud.getNodeName())
2772:                                    .equalsIgnoreCase(EXTENDED_ATTRIBUTE)) {
2773:                                Element ele = (Element) n.Fils[j].Noeud;
2774:                                // set the boolean "propertyActivity" to true (means this property is reserved for activity)
2775:                                if (ele
2776:                                        .getAttribute(EXTENDED_ATTRIBUTE_NAME)
2777:                                        .equalsIgnoreCase(
2778:                                                EXTENDED_ATTRIBUTE_NAME_PROPERTY_ACTIVITY)) {
2779:                                    //debug
2780:                                    //System.out.println("obtainDataFieldData: set activityproperty for property = " + xpdlDataField.getName() );
2781:                                    xpdlDataField.setPropertyActivity();
2782:                                }
2783:                            }
2784:                        }
2785:                    }
2786:                    break;
2787:
2788:                case Node.TEXT_NODE:
2789:                    // Get initial Value attribut
2790:                    if ((n.Noeud.getParentNode().getNodeName())
2791:                            .equalsIgnoreCase(INITIALVALUE)) {
2792:                        xpdlDataField.setInitialValue(n.Noeud.getNodeValue());
2793:
2794:                    }
2795:                    break;
2796:
2797:                default:
2798:                    break;
2799:                }
2800:
2801:                for (int k = 0; k < n.NbFils; k++) {
2802:                    obtainDataFieldData(n.Fils[k], xpdlDataField);
2803:                }
2804:                return xpdlDataField;
2805:            }
2806:
2807:            /*
2808:             *   Get the hook if it exists from External Attribute Bonita tree
2809:             *   giving the xpdlWFProcess bean
2810:             *
2811:             */
2812:            private XPDLWFProcess obtainProcessHook(BonitaTree n,
2813:                    XPDLWFProcess xpdlWFProcess, XPDLHook xpdlHook) {
2814:                int type = n.Noeud.getNodeType();
2815:                switch (type) {
2816:                case Node.ATTRIBUTE_NODE:
2817:                    break;
2818:                case Node.ELEMENT_NODE:
2819:
2820:                    // EXTENDED ATTRIBUTE : Properties & Hooks
2821:                    if (n.Noeud.getNodeName().equalsIgnoreCase(
2822:                            EXTENDED_ATTRIBUTE)) {
2823:                        Element element = (Element) n.Noeud;
2824:                        // Ex. for Process HOOKS
2825:                        /*
2826:                         *   based on :
2827:                         *    <ExtendedAttribute
2828:                         *             Name="hook" Value="hero.hook.TestHook">
2829:                         *    </ExtendedAttribute>
2830:                         *
2831:                         *    And optionaly other complexe type can be added:
2832:                         *        <HookEventName>
2833:                         *           BEFORETERMINATE
2834:                         *        </HookEventName>
2835:                         *
2836:                         * 	      <HookScript>
2837:                         *           System.out.println("interactive hook executed !!!");
2838:                         *        </HookScript>
2839:                         *
2840:                         */
2841:                        if (element.getAttribute(EXTENDED_ATTRIBUTE_NAME)
2842:                                .equalsIgnoreCase(EXTENDED_ATTRIBUTE_NAME_HOOK)) {
2843:                            //xpdlHook = new XPDLHook();
2844:                            xpdlHook.setHookName(element
2845:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
2846:                            xpdlWFProcess.setXpdlHook(xpdlHook);
2847:                            //debug
2848:                            //System.out.println("obtainProcessHook: Bonita Project = " + xpdlWFProcess.getName() + " extended attribut Name = Hook  Value =  "
2849:                            //	+ xpdlHook.getHookName());
2850:                        }
2851:
2852:                        else if (element
2853:                                .getAttribute(EXTENDED_ATTRIBUTE_NAME)
2854:                                .equalsIgnoreCase(
2855:                                        EXTENDED_ATTRIBUTE_NAME_INITIATORMAPPER)) {
2856:                            //xpdlHook = new XPDLHook();
2857:                            xpdlHook.setHookName(element
2858:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
2859:                            xpdlWFProcess.setXpdlHook(xpdlHook);
2860:
2861:                            //debug
2862:                            //System.out.println("obtainProcessHook: Bonita Project = " + xpdlWFProcess.getName() + " extended attribut Name = InitiatorMapper  Value =  "
2863:                            //	+ xpdlHook.getHookName());
2864:                        }
2865:
2866:                    }
2867:                    break;
2868:
2869:                case Node.TEXT_NODE:
2870:                    // Hook Event Name
2871:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
2872:                            HOOKEVENTNAME)) {
2873:                        xpdlHook.setHookEventName(n.Noeud.getNodeValue());
2874:                        //debug
2875:                        //System.out.println("obtainProcessHook: Bonita Project = " + xpdlWFProcess.getName() + " Hook EventName = " +  xpdlHook.getHookEventName());
2876:                    }
2877:                    // Hook Script
2878:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
2879:                            HOOKSCRIPT)) {
2880:                        xpdlHook.setHookScript(n.Noeud.getNodeValue());
2881:                        //debug
2882:                        //System.out.println("obtainProcessHook: Bonita Project = " + xpdlWFProcess.getName() + " Hook Script = \n" +  xpdlHook.getHookScript());
2883:                    }
2884:                    break;
2885:
2886:                default:
2887:                    break;
2888:                }
2889:                for (int i = 0; i < n.NbFils; i++) {
2890:                    obtainProcessHook(n.Fils[i], xpdlWFProcess, xpdlHook);
2891:                }
2892:                return xpdlWFProcess;
2893:            }
2894:
2895:            /*
2896:             *   Get the subflow version from External Attribute of the activity with
2897:             *   SubFlow implementation
2898:             *
2899:             */
2900:            private XPDLActivity obtainSubFlowVersion(BonitaTree n,
2901:                    XPDLActivity xpdlAct) {
2902:                int type = n.Noeud.getNodeType();
2903:                switch (type) {
2904:                case Node.ATTRIBUTE_NODE:
2905:                    break;
2906:                case Node.ELEMENT_NODE:
2907:
2908:                    // EXTENDED ATTRIBUTE
2909:                    //debug
2910:                    //System.out.println("**** obtainSubFlowVersion: node name = " + n.Noeud.getNodeName())	;
2911:
2912:                    if (n.Noeud.getNodeName().equalsIgnoreCase(
2913:                            EXTENDED_ATTRIBUTE)) {
2914:                        Element element = (Element) n.Noeud;
2915:                        // Ex. for subFlow version
2916:                        /*
2917:                         *   <ExtendedAttribute Name="SubFlowVersion" Value="1.0" />
2918:                         */
2919:                        if (element
2920:                                .getAttribute(EXTENDED_ATTRIBUTE_NAME)
2921:                                .equalsIgnoreCase(
2922:                                        EXTENDED_ATTRIBUTE_NAME_SUBFLOW_VERSION)) {
2923:                            xpdlAct.setSubFlowVersion(element
2924:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
2925:                            break;
2926:                        }
2927:
2928:                    }
2929:
2930:                default:
2931:                    break;
2932:                }
2933:                for (int i = 0; i < n.NbFils; i++) {
2934:                    obtainSubFlowVersion(n.Fils[i], xpdlAct);
2935:                }
2936:                return xpdlAct;
2937:            }
2938:
2939:            /*
2940:             *   Get the subflow name from External Attribute of the activity with
2941:             *   SubFlow implementation
2942:             *
2943:             */
2944:            private XPDLActivity obtainSubFlowName(BonitaTree n,
2945:                    XPDLActivity xpdlAct) {
2946:                int type = n.Noeud.getNodeType();
2947:                switch (type) {
2948:                case Node.ATTRIBUTE_NODE:
2949:                    break;
2950:                case Node.ELEMENT_NODE:
2951:                    // EXTENDED ATTRIBUTE
2952:                    if (n.Noeud.getNodeName().equalsIgnoreCase(
2953:                            EXTENDED_ATTRIBUTE)) {
2954:                        Element element = (Element) n.Noeud;
2955:                        // Ex. for subFlow name
2956:                        /*
2957:                         *   <ExtendedAttribute Name="SubFlowName" Value="childProcess" />
2958:                         */
2959:                        if (element.getAttribute(EXTENDED_ATTRIBUTE_NAME)
2960:                                .equalsIgnoreCase(
2961:                                        EXTENDED_ATTRIBUTE_NAME_SUBFLOW_NAME)) {
2962:                            xpdlAct.setSubFlowName(element
2963:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
2964:                            break;
2965:                        }
2966:                    }
2967:
2968:                default:
2969:                    break;
2970:                }
2971:                for (int i = 0; i < n.NbFils; i++) {
2972:                    obtainSubFlowName(n.Fils[i], xpdlAct);
2973:                }
2974:                return xpdlAct;
2975:            }
2976:
2977:            /*
2978:             *   Get the initiator Mapper if it exists from External Attribute Bonita tree
2979:             *   giving the xpdlWFProcess bean
2980:             *
2981:             */
2982:            private XPDLWFProcess obtainInitiatorMapper(BonitaTree n,
2983:                    XPDLWFProcess xpdlWFProcess,
2984:                    XPDLInitiatorMapper xpdlInitiatorMapper) {
2985:
2986:                int type = n.Noeud.getNodeType();
2987:                switch (type) {
2988:                case Node.ATTRIBUTE_NODE:
2989:                    break;
2990:                case Node.ELEMENT_NODE:
2991:
2992:                    // EXTENDED ATTRIBUTE : Properties & Hooks
2993:                    if (n.Noeud.getNodeName().equalsIgnoreCase(
2994:                            EXTENDED_ATTRIBUTE)) {
2995:                        Element element = (Element) n.Noeud;
2996:                        /*
2997:                         *  Ex. for Process Initiator Mapper
2998:                         *
2999:                         *  <ExtendedAttribute
3000:                         *          Name="initiatorMapper" Value="Custom" or "LDAP">
3001:                         *     <CustomInitiatorClass>
3002:                         *        hero.initiatorMapper.CustomGroupMembers
3003:                         *     </CustomInitiatorClass>
3004:                         *  </ExtendedAttribute>
3005:                         */
3006:
3007:                        if (element
3008:                                .getAttribute(EXTENDED_ATTRIBUTE_NAME)
3009:                                .equalsIgnoreCase(
3010:                                        EXTENDED_ATTRIBUTE_NAME_INITIATORMAPPER)) {
3011:                            xpdlInitiatorMapper.setInitiatorMapperType(element
3012:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
3013:                            xpdlWFProcess
3014:                                    .setInitiatorMapper(xpdlInitiatorMapper);
3015:
3016:                            //debug
3017:                            //System.out.println("obtainInitiatorMapper: Bonita Project = " + xpdlWFProcess.getName() + " extended attribut Name = InitiatorMapper  Value =  "
3018:                            //	+ xpdlInitiatorMapper.getInitiatorMapperType());
3019:                        }
3020:
3021:                    }
3022:                    break;
3023:
3024:                case Node.TEXT_NODE:
3025:                    //Initiator Mapper Name
3026:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3027:                            EXTENDED_ATTRIBUTE_INITIATOR_NAME)) {
3028:                        xpdlInitiatorMapper.setInitiatorMapperName(n.Noeud
3029:                                .getNodeValue());
3030:                        //debug
3031:                        //System.out.println("obtainInitiatorMapper: Bonita Project = " + xpdlWFProcess.getName() + " Initiator Mapper Name = " +  xpdlInitiatorMapper.getInitiatorMapperName());
3032:                    }
3033:                    break;
3034:
3035:                default:
3036:                    break;
3037:                }
3038:                for (int i = 0; i < n.NbFils; i++) {
3039:                    obtainInitiatorMapper(n.Fils[i], xpdlWFProcess,
3040:                            xpdlInitiatorMapper);
3041:                }
3042:                return xpdlWFProcess;
3043:            }
3044:
3045:            /*
3046:             *   Get activity definition
3047:             *   (Join, deadlines, ext. attrib (properties, hooks), start mode, description, performer)
3048:             */
3049:            private XPDLActivity obtainActivityData(BonitaTree n,
3050:                    ProjectSessionLocal p, XPDLActivity xpdlAct,
3051:                    Hashtable xpdlData) throws XPDLException {
3052:
3053:                int type = n.Noeud.getNodeType();
3054:                XPDLHook xpdlHook = null;
3055:                switch (type) {
3056:                case Node.ATTRIBUTE_NODE:
3057:                    break;
3058:                case Node.ELEMENT_NODE:
3059:                    // Split
3060:                    if ((n.Noeud.getNodeName().equalsIgnoreCase(ACTIVITY_SPLIT))) {
3061:                        Element element = (Element) n.Noeud;
3062:                        if (element.getAttribute(TYPE).equalsIgnoreCase(
3063:                                MODE_TYPE_XOR))
3064:                            xpdlAct.setSplit(MODE_TYPE_XOR);
3065:                        else if (element.getAttribute(TYPE).equalsIgnoreCase(
3066:                                MODE_TYPE_AND))
3067:                            xpdlAct.setSplit(MODE_TYPE_AND);
3068:                    }
3069:                    // Join
3070:                    else if (n.Noeud.getNodeName().equalsIgnoreCase(
3071:                            ACTIVITY_JOIN)) {
3072:                        Element element = (Element) n.Noeud;
3073:                        if (element.getAttribute(TYPE).equalsIgnoreCase(
3074:                                MODE_TYPE_XOR))
3075:                            xpdlAct.setJoin(MODE_TYPE_XOR);
3076:                        else if (element.getAttribute(TYPE).equalsIgnoreCase(
3077:                                MODE_TYPE_AND))
3078:                            xpdlAct.setJoin(MODE_TYPE_AND);
3079:                    }
3080:                    // deadlines Execution
3081:                    else if (n.Noeud.getNodeName().equalsIgnoreCase(
3082:                            ACTIVITYDEADLINE)) {
3083:                        xpdlAct.setDeadline(true);
3084:                        Element element = (Element) n.Noeud;
3085:                        if (element.getAttribute(DEADLINE_EXECUTION)
3086:                                .equalsIgnoreCase(ASYNCHR))
3087:                            xpdlAct.setDeadlineExecution(ASYNCHR);
3088:                        else if (element.getAttribute(DEADLINE_EXECUTION)
3089:                                .equalsIgnoreCase(SYNCHR))
3090:                            xpdlAct.setDeadlineExecution(SYNCHR);
3091:                    }
3092:                    // EXTENDED ATTRIBUTE
3093:                    else if (n.Noeud.getNodeName().equalsIgnoreCase(
3094:                            EXTENDED_ATTRIBUTE)) {
3095:                        Element element = (Element) n.Noeud;
3096:                        //	>>>>>>> Bonita PROPERTIES <<<<<<<<
3097:                        /*    based on:
3098:                         *       - extended attributes reference datafields attributes defined within the process
3099:                         *       (these datafields have an extended attributes indicating that the datafield is defined for activities)
3100:                         *       ex.:   <ExtendedAttribute Name="property" Value="datafield_wfp_for_act_4"
3101:                         * 				<Propagated Value="No" />
3102:                         * 				/ExtendedAttribute>
3103:                         *        (other possibility is: <Propagated Value="yes" /> )
3104:                         */
3105:                        if (element.getAttribute(EXTENDED_ATTRIBUTE_NAME)
3106:                                .equalsIgnoreCase(
3107:                                        EXTENDED_ATTRIBUTE_NAME_PROPERTY)) {
3108:                            xpdlAct.setProperties(element
3109:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
3110:                            //debug
3111:                            //System.out.println("obtainActivityData: Activity = " + xpdlAct.getName() + " extended attribut Name = Property  Value = "
3112:                            //	+ element.getAttribute(EXTENDED_ATTRIBUTE_VALUE));
3113:                        }
3114:                        // >>>>>>> Bonita HOOKS <<<<<<<<
3115:                        /*
3116:                         *   based on :
3117:                         *    <ExtendedAttribute Name="hook" Value="hero.hook.TestHook"> </ExtendedAttribute>
3118:                         *
3119:                         *    And furthermore other complexe type can be added:
3120:                         *        <HookEventName>BEFORETERMINATE</HookEventName>
3121:                         * 	      <HookScript>
3122:                         *           System.out.println("interactive hook executed !!!");
3123:                         *        </HookScript>
3124:                         */
3125:
3126:                        if (element.getAttribute(EXTENDED_ATTRIBUTE_NAME)
3127:                                .equalsIgnoreCase(EXTENDED_ATTRIBUTE_NAME_HOOK)) {
3128:                            // set the XPDLHook Bean the activity Bean
3129:                            xpdlHook = new XPDLHook();
3130:                            xpdlAct.setXpdlHook(xpdlHook);
3131:                            xpdlHook.setHookName(element
3132:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
3133:
3134:                            //	debug
3135:                            //System.out.println("obtainActivityData: Activity = " + xpdlAct.getName() + " extended attribut Name = Hook  Value =  "
3136:                            //+ element.getAttribute(EXTENDED_ATTRIBUTE_VALUE));
3137:                        }
3138:
3139:                        // >>>>>>> Bonita Iteration <<<<<<<<
3140:                        /*
3141:                         *   based on :
3142:                         *    <ExtendedAttribute Name="iteration" Value="data_process.equals("riri")"> </ExtendedAttribute>
3143:                         *
3144:                         *    complexe type must added:
3145:                         *        <from>activity_from</from>
3146:                         * 		  <to>activity_to</to>
3147:                         */
3148:
3149:                        if (element.getAttribute(EXTENDED_ATTRIBUTE_NAME)
3150:                                .equalsIgnoreCase(
3151:                                        EXTENDED_ATTRIBUTE_NAME_ITERATION)) {
3152:
3153:                            // indicate that iteration exists on the activity
3154:                            //xpdlAct.setIterationName("Iteration");
3155:
3156:                            // set the "From" parameter of the iteration
3157:                            //xpdlAct.setIterationFrom(xpdlAct.getName());
3158:                            // set the "Condition" parameter
3159:                            if ((element.getAttribute(EXTENDED_ATTRIBUTE_VALUE) != null)) {
3160:                                //record the iteration condition
3161:                                xpdlAct
3162:                                        .setTempIterationCondition(element
3163:                                                .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
3164:                            }
3165:                            //	debug
3166:                            //System.out.println("obtainActivityData: Iteration Activity From = " + xpdlAct.getName() + " Condition =  "
3167:                            // + element.getAttribute(EXTENDED_ATTRIBUTE_VALUE)) ;
3168:                        }
3169:
3170:                        //>>>>>>> Bonita Performer Assignment <<<<<<<<
3171:                        /*
3172:                         * <ExtendedAttribute Name="PerformerAssign" Value="property">
3173:                         * 		<Property>valideur</property>
3174:                         * </ExtendedAttribute>
3175:                         * or
3176:                         * <ExtendedAttribute Name="PerformerAssign" Value="Callback">
3177:                         * 		<Callback>hero.performAssignSelectActor</Callback>
3178:                         * </ExtendedAttribute>
3179:                         */
3180:                        if (element
3181:                                .getAttribute(EXTENDED_ATTRIBUTE_NAME)
3182:                                .equalsIgnoreCase(
3183:                                        EXTENDED_ATTRIBUTE_NAME_PERFORMER_ASSIGN)) {
3184:                            xpdlAct.setPerformerAssignType(element
3185:                                    .getAttribute(EXTENDED_ATTRIBUTE_VALUE));
3186:                        }
3187:
3188:                    } else {
3189:                        // MANUAL
3190:                        if (n.Noeud.getNodeName().equalsIgnoreCase(MANUAL)
3191:                                && n.Noeud.getParentNode().getNodeName()
3192:                                        .equalsIgnoreCase(STARTMODE))
3193:                            xpdlAct.setMode(MANUAL);
3194:                        // AUTOMATIC
3195:                        if (n.Noeud.getNodeName().equalsIgnoreCase(AUTOMATIC)
3196:                                && n.Noeud.getParentNode().getNodeName()
3197:                                        .equalsIgnoreCase(STARTMODE))
3198:                            xpdlAct.setMode(AUTOMATIC);
3199:                    }
3200:
3201:                    break;
3202:
3203:                case Node.TEXT_NODE:
3204:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3205:                            ACTIVITY_DESCRIPTION))
3206:                        xpdlAct.setDescription(n.Noeud.getNodeValue());
3207:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3208:                            ACTIVITY_PERFORMER))
3209:                        xpdlAct.setPerformer(n.Noeud.getNodeValue());
3210:                    // propagated property
3211:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3212:                            PROPAGATED_PROPERTY)) {
3213:                        //debug
3214:                        //System.out.println("obtainActivityData: Activity = " + xpdlAct.getName() + "obtained propagation attribut !!!!!!");
3215:                        if ("Yes".equalsIgnoreCase(n.Noeud.getNodeValue())) {
3216:                            xpdlAct.setPropagations(new Boolean(true));
3217:                            //debug
3218:                            //System.out.println("obtainActivityData: Activity = " + xpdlAct.getName() + "propagated = Yes !!!!!!");
3219:                        } else if ("No"
3220:                                .equalsIgnoreCase(n.Noeud.getNodeValue()))
3221:                            xpdlAct.setPropagations(new Boolean(false));
3222:                        else
3223:                            xpdlAct.setPropagations(new Boolean(false));
3224:                    }
3225:
3226:                    //deadline Condition
3227:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3228:                            DEADLINECONDITION))
3229:                        xpdlAct.setDeadlineCondition(n.Noeud.getNodeValue());
3230:                    //deadline Exception
3231:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3232:                            EXCEPTIONNAME))
3233:                        if (!"".equals(n.Noeud.getNodeValue()))
3234:                            xpdlAct.setExceptionName(n.Noeud.getNodeValue());
3235:                    // Hook Event Name
3236:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3237:                            HOOKEVENTNAME)) {
3238:                        // get the last element of xpdlHooks (ArrayList) and set HookEventName to the XPDLHook Bean
3239:                        xpdlHook = (XPDLHook) xpdlAct.getXpdlHook().get(
3240:                                xpdlAct.getXpdlHook().size() - 1);
3241:                        xpdlHook.setHookEventName(n.Noeud.getNodeValue());
3242:                        //debug
3243:                        //System.out.println("obtainActivityData: Activity = " + xpdlAct.getName() + " set hookEvent = "
3244:                        //+ xpdlHook.getHookEventName() + " for HookName = " + xpdlHook.getHookName());
3245:                    }
3246:                    // Hook Script
3247:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3248:                            HOOKSCRIPT)) {
3249:                        //get the last element of xpdlHooks (ArrayList) and set HookScript to the XPDLHook Bean
3250:                        xpdlHook = (XPDLHook) xpdlAct.getXpdlHook().get(
3251:                                xpdlAct.getXpdlHook().size() - 1);
3252:                        xpdlHook.setHookScript(n.Noeud.getNodeValue());
3253:                        //debug
3254:                        //System.out.println("obtainActivityData: Activity = " + xpdlAct.getName() + " set hookScript = "
3255:                        //+ xpdlHook.getHookScript() + " for HookName = " + xpdlHook.getHookName());
3256:                    }
3257:                    /*
3258:                    // Iteration From
3259:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(ITERATIONFROM))
3260:                    	xpdlAct.setIterationFrom(n.Noeud.getNodeValue());
3261:                     */
3262:                    // Iteration To
3263:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3264:                            ITERATIONTO)) {
3265:                        //xpdlAct.setIterationTo(n.Noeud.getNodeValue());
3266:                        // the new set  for iteration
3267:                        xpdlAct.setIteration(n.Noeud.getNodeValue(), xpdlAct
3268:                                .getTempIterationCondition());
3269:                        // debug
3270:                        //System.out.println("obtainActivityData:  iterationFrom = " + xpdlAct.getIterationFrom()
3271:                        //		+ " iterationTo = " + xpdlAct.getIterationTo());
3272:                    }
3273:
3274:                    // Performer Assignment Property
3275:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3276:                            PERFORMER_ASSIGN_PROPERTY)) {
3277:                        //property name
3278:                        xpdlAct.setPerformerAssignProperty(n.Noeud
3279:                                .getNodeValue());
3280:                        //build the performer assignment name
3281:                        xpdlAct.setPerformerAssignName("perf_assign_"
3282:                                + n.Noeud.getNodeValue());
3283:                    }
3284:
3285:                    // Performer Assignment Callback
3286:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3287:                            PERFORMER_ASSIGN_CALLBACK)) {
3288:                        xpdlAct.setPerformerAssignProperty("");
3289:                        xpdlAct.setPerformerAssignName(n.Noeud.getNodeValue());
3290:                    }
3291:
3292:                    // ActualParameters
3293:                    if (n.Noeud.getParentNode().getNodeName().equalsIgnoreCase(
3294:                            ACTUALPARAMETER)) {
3295:                        //property name
3296:                        xpdlAct.setActualParameter(n.Noeud.getNodeValue());
3297:                    }
3298:                    break;
3299:
3300:                default:
3301:                    break;
3302:                }
3303:                for (int i = 0; i < n.NbFils; i++) {
3304:                    obtainActivityData(n.Fils[i], p, xpdlAct, xpdlData);
3305:                }
3306:
3307:                return xpdlAct;
3308:
3309:            }
3310:
3311:            private void obtainTransition(BonitaTree a, ProjectSessionLocal p,
3312:                    boolean inActivitySet, String ActivitySetId,
3313:                    Hashtable xpdlData) throws XPDLException {
3314:                if (a != null) {
3315:                    String inst_mod = null;
3316:                    if ((a.Noeud.getNodeName()).equalsIgnoreCase(TRANSITIONS)) {
3317:                        //Set used in case we are into an activitySet to get the First and Last Activity
3318:                        Set setAll = new HashSet();
3319:                        Set setTo = new HashSet();
3320:                        Set setFrom = new HashSet();
3321:
3322:                        for (int j = 0; j < a.NbFils; j++) {
3323:                            if ((a.Fils[j].Noeud.getNodeName())
3324:                                    .equalsIgnoreCase(TRANSITION)) {
3325:                                XPDLTransition xpdlTransition = new XPDLTransition();
3326:                                String edgeTo = null;
3327:                                String edgeFrom = null;
3328:                                String edgeName = null;
3329:                                String condition = null;
3330:                                // get the attributs of the node: Transition in an NamedNodeMaps
3331:                                NamedNodeMap atts = a.Fils[j].Noeud
3332:                                        .getAttributes();
3333:
3334:                                for (int i = 0; i < atts.getLength(); i++) {
3335:                                    Node att = atts.item(i);
3336:                                    if (att.getNodeName().equalsIgnoreCase(
3337:                                            TRANSITION_NAME)) {
3338:                                        edgeName = att.getNodeValue();
3339:                                        xpdlTransition.setName(att
3340:                                                .getNodeValue());
3341:                                    }
3342:
3343:                                    else if (att.getNodeName()
3344:                                            .equalsIgnoreCase(TRANSITION_TO)) {
3345:                                        edgeTo = att.getNodeValue();
3346:                                        xpdlTransition
3347:                                                .setTo(att.getNodeValue());
3348:                                        if (inActivitySet) {
3349:                                            setTo.add(edgeTo);
3350:                                            setAll.add(edgeTo);
3351:                                        }
3352:                                    }
3353:
3354:                                    else if (att.getNodeName()
3355:                                            .equalsIgnoreCase(TRANSITION_FROM)) {
3356:                                        edgeFrom = att.getNodeValue();
3357:                                        xpdlTransition.setFrom(att
3358:                                                .getNodeValue());
3359:                                        if (inActivitySet) {
3360:                                            setFrom.add(edgeFrom);
3361:                                            setAll.add(edgeFrom);
3362:                                        }
3363:                                    }
3364:
3365:                                    else if (att.getNodeName()
3366:                                            .equalsIgnoreCase(TRANSITION_ID)) {
3367:                                        xpdlTransition
3368:                                                .setId(att.getNodeValue());
3369:                                    }
3370:                                }
3371:
3372:                                // get the Condition
3373:                                // For ex: <Condition Type="CONDITION">datafield_id_1.equals("tarte");</Condition>
3374:                                BonitaTree condTree = getNode(a.Fils[j],
3375:                                        TRANSITION_CONDITION);
3376:                                // Get of the condition set on the transition
3377:                                if (condTree != null) {
3378:                                    if (condTree.Noeud.hasChildNodes()) {
3379:                                        condition = condTree.Noeud
3380:                                                .getFirstChild().getNodeValue();
3381:                                        xpdlTransition.setCondition(condition);
3382:                                        // Trace
3383:                                        //System.out.println("Condition = " + condition);
3384:                                    }
3385:                                }
3386:                                //Add to TransitionMapping the XPDLTransition bean
3387:                                //TODO
3388:                                Hashtable transitionMapping = (Hashtable) xpdlData
3389:                                        .get("transitionMapping");
3390:                                transitionMapping.put(xpdlTransition.getId(),
3391:                                        xpdlTransition);
3392:
3393:                                if ((edgeFrom != null) && (edgeTo != null)) {
3394:                                    // Traces for transition
3395:                                    //System.out.println("InNode: "+edgeFrom);
3396:                                    //System.out.println("OutNode: "+edgeTo);
3397:                                    //System.out.println("");
3398:                                    // add transition into Bonita
3399:                                    //inst_mod=p.addEdge((String)actMapping.get(edgeFrom), (String)actMapping.get(edgeTo))
3400:                                    //TODO
3401:                                    Hashtable actMapping = (Hashtable) xpdlData
3402:                                            .get("actMapping");
3403:                                    XPDLActivity xpdlActivity = (XPDLActivity) actMapping
3404:                                            .get(edgeFrom);
3405:                                    String actNameFrom = xpdlActivity.getName();
3406:                                    xpdlActivity = (XPDLActivity) actMapping
3407:                                            .get(edgeTo);
3408:                                    String actNameTo = xpdlActivity.getName();
3409:                                    try {
3410:                                        inst_mod = p.addEdge(actNameFrom,
3411:                                                actNameTo);
3412:                                    } catch (HeroException he) {
3413:                                        throw new XPDLException(
3414:                                                "Error adding edge from activity: "
3415:                                                        + actNameFrom
3416:                                                        + " activity: "
3417:                                                        + actNameTo + " "
3418:                                                        + he.getMessage(), he);
3419:                                    }
3420:                                    try {
3421:                                        // add condition on the transition
3422:                                        if (condition != null) {
3423:                                            //set condition on the transition
3424:                                            p.setEdgeCondition(inst_mod,
3425:                                                    condition);
3426:                                        }
3427:                                    } catch (HeroException he) {
3428:                                        throw new XPDLException(
3429:                                                "Error setting edge condition from activity: "
3430:                                                        + actNameFrom
3431:                                                        + " activity: "
3432:                                                        + actNameTo + " "
3433:                                                        + he.getMessage(), he);
3434:                                    }
3435:                                }
3436:                            }
3437:                        }
3438:
3439:                        // set the activitySetMapping with the Sets if we are in Activity Set (ActivitySet == true)
3440:                        if (inActivitySet && (ActivitySetId != null)) {
3441:                            Set setAllTemp = new HashSet();
3442:                            String firstAct = null;
3443:                            String lastAct = null;
3444:
3445:                            // get the first Activity of the Activity Set
3446:                            setAllTemp.addAll(setAll);
3447:                            setAllTemp.removeAll(setTo);
3448:                            Iterator itTo = setAllTemp.iterator();
3449:                            while (itTo.hasNext()) {
3450:                                firstAct = (String) itTo.next();
3451:                            }
3452:                            if (firstAct == null) {
3453:                                throw new XPDLException(
3454:                                        "Error getting first activity of activitySet with Id = "
3455:                                                + ActivitySetId);
3456:                            }
3457:
3458:                            //get the last Activity of the Activity Set
3459:                            setAllTemp.addAll(setAll);
3460:                            setAllTemp.removeAll(setFrom);
3461:                            Iterator itFrom = setAllTemp.iterator();
3462:                            while (itFrom.hasNext()) {
3463:                                lastAct = (String) itFrom.next();
3464:                            }
3465:                            if (lastAct == null) {
3466:                                throw new XPDLException(
3467:                                        "Error getting last activity of activitySet with Id = "
3468:                                                + ActivitySetId);
3469:                            }
3470:                            //TODO
3471:                            Hashtable activitySetMapping = (Hashtable) xpdlData
3472:                                    .get("activitySetMapping");
3473:                            activitySetMapping.put(ActivitySetId, lastAct
3474:                                    + ACT_SET_MAP_SEPARATOR + firstAct);
3475:                            //debug
3476:                            //System.out.println("XPDLSessionBean:obtainTransition	: ActivitySetId = " + ActivitySetId + " lastAct = " + lastAct + " firstAct = " + firstAct);
3477:                        }
3478:                    }
3479:                }
3480:            }
3481:
3482:            /**
3483:             * Create the ArbreXPDLSession Bean
3484:             *
3485:             * @throws CreateException
3486:             *
3487:             * @ejb.permission unchecked="yes"
3488:             * @ejb:create-method view-type="both"
3489:             **/
3490:
3491:            public void ejbCreate() throws CreateException {
3492:            }
3493:
3494:            public void setSessionContext(final javax.ejb.SessionContext context) {
3495:                mContext = context;
3496:            }
3497:
3498:            public void ejbRemove() {
3499:            }
3500:
3501:            public void ejbActivate() {
3502:            }
3503:
3504:            public void ejbPassivate() {
3505:            }
3506:
3507:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.