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


001:        /**
002:         *
003:         * Bonita
004:         * Copyright (C) 1999 Bull S.A.
005:         * Bull 68 route de versailles  78434 Louveciennes Cedex France
006:         * Further information: bonita@objectweb.org
007:         *
008:         * This library is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU Lesser General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2.1 of the License, or any later version.
012:         *
013:         * This library is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
016:         * Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public
019:         * License along with this library; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
021:         * USA
022:         *
023:         *
024:        --------------------------------------------------------------------------
025:         * $Id: BonitaProjectLocator.java,v 1.11 2006/08/17 15:30:54 mvaldes Exp $
026:         *
027:        --------------------------------------------------------------------------
028:         */package hero.util;
029:
030:        import java.util.ArrayList;
031:        import java.util.Collection;
032:        import java.util.HashMap;
033:        import java.util.Iterator;
034:        import java.util.Map;
035:
036:        import hero.entity.OrEdgeState;
037:        import hero.interfaces.BnEdgeLocal;
038:        import hero.interfaces.BnIterationLocal;
039:        import hero.interfaces.BnNodeHookLocal;
040:        import hero.interfaces.BnNodeInterHookLocal;
041:        import hero.interfaces.BnNodeLocal;
042:        import hero.interfaces.BnNodePropertyLocal;
043:        import hero.interfaces.BnProjectHookLocal;
044:        import hero.interfaces.BnProjectInterHookLocal;
045:        import hero.interfaces.BnProjectLocal;
046:        import hero.interfaces.BnProjectLocalHome;
047:        import hero.interfaces.BnProjectPropertyLocal;
048:        import hero.interfaces.BnRoleLocal;
049:        import hero.interfaces.BnUserLocal;
050:        import hero.interfaces.BnUserLocalHome;
051:        import hero.util.values.BonitaConfigValue;
052:        import hero.util.values.BonitaEdgeValue;
053:        import hero.util.values.BonitaHookValue;
054:        import hero.util.values.BonitaInterHookValue;
055:        import hero.util.values.BonitaIterationValue;
056:        import hero.util.values.BonitaMapperValue;
057:        import hero.util.values.BonitaNodeValue;
058:        import hero.util.values.BonitaPerformerValue;
059:        import hero.util.values.BonitaProjectValue;
060:        import hero.util.values.BonitaPropertyValue;
061:        import hero.util.values.BonitaRoleValue;
062:        import hero.util.values.BonitaUserValue;
063:
064:        import javax.ejb.FinderException;
065:        import javax.naming.NamingException;
066:
067:        public class BonitaProjectLocator {
068:            private static BonitaProjectLocator bpl;
069:            private Map modelsCache;
070:
071:            private BonitaProjectLocator() {
072:                modelsCache = new HashMap();
073:            }
074:
075:            public synchronized static BonitaProjectLocator getInstance() {
076:                if (bpl == null) {
077:                    bpl = new BonitaProjectLocator();
078:                }
079:                return bpl;
080:            }
081:
082:            // Returns BonitaProjectValue for the given model
083:
084:            public synchronized BonitaProjectValue getModelValue(String model,
085:                    String version) throws BonitaServiceException {
086:                BonitaProjectValue pv = null;
087:                try {
088:                    KeyModelsCache keyMap = new KeyModelsCache(model, version);
089:                    if (modelsCache.containsKey(keyMap)) {
090:                        pv = (BonitaProjectValue) modelsCache.get(keyMap);
091:                    } else {
092:                        pv = generateProjectValue(model, version);
093:                        modelsCache.put(keyMap, pv);
094:                    }
095:                } catch (Exception ex) {
096:                    throw new BonitaServiceException(ex.getMessage());
097:                }
098:                return pv;
099:            }
100:
101:            // Clean the ModelValue object representing this model
102:            public synchronized void cleanModelValue(String model,
103:                    String version) throws BonitaServiceException {
104:                KeyModelsCache keyMap = new KeyModelsCache(model, version);
105:                if (modelsCache.containsKey(keyMap))
106:                    modelsCache.remove(keyMap);
107:            }
108:
109:            private BonitaProjectValue generateProjectValue(String projectName,
110:                    String projectVersion) throws BonitaServiceException {
111:                BnProjectLocalHome pHome = null;
112:                BnProjectLocal projectModel = null;
113:                BonitaProjectValue pv = null;
114:                try {
115:                    pHome = hero.interfaces.BnProjectUtil.getLocalHome();
116:                    projectModel = pHome.findByNameVersion(projectName,
117:                            projectVersion);
118:                } catch (javax.naming.NamingException ne) {
119:                    throw new BonitaServiceException(ne.getMessage());
120:                } catch (javax.ejb.FinderException fe) {
121:                    throw new BonitaServiceException(fe.getMessage());
122:                }
123:
124:                try {
125:                    pv = getProjectData(projectModel);
126:                } catch (HeroException he) {
127:                    throw new BonitaServiceException(he.getMessage());
128:                }
129:                return pv;
130:            }
131:
132:            private BonitaProjectValue getProjectData(
133:                    BnProjectLocal projectModel) throws HeroException {
134:                BonitaProjectValue pv = new BonitaProjectValue();
135:                pv.setName(projectModel.getName());
136:                //set version
137:                pv.setVersion(projectModel.getVersion());
138:                pv.setType(projectModel.getType());
139:                pv.setStatus(projectModel.getStatus());
140:
141:                // Project Iterations
142:                Collection iterations = projectModel.getBnIterations();
143:                Iterator iter = iterations.iterator();
144:                Collection iterPro = new ArrayList();
145:                while (iter.hasNext()) {
146:                    BnIterationLocal it = (BnIterationLocal) iter.next();
147:                    BonitaIterationValue iteration = new BonitaIterationValue();
148:                    iteration.setCondition(it.getCondition());
149:                    iteration.setFromNode(it.getFromNode());
150:                    iteration.setToNode(it.getToNode());
151:                    iterPro.add(iteration);
152:                }
153:                pv.setIterations(iterPro);
154:
155:                // Project Nodes
156:                Collection nodesPro = new ArrayList();
157:                Collection nodes = projectModel.getBnNodes();
158:                Iterator nodesI = nodes.iterator();
159:                while (nodesI.hasNext()) {
160:                    BnNodeLocal nd = (BnNodeLocal) nodesI.next();
161:                    BonitaNodeValue node = new BonitaNodeValue();
162:                    node.setProjectName(projectModel.getName());
163:                    node.setDescription(nd.getDescription());
164:                    node.setDeadlines(nd.getDeadlines());
165:                    node.setRelativeDeadlines(nd.getRelativeDeadlines());
166:                    node.setCreator(nd.getCreator());
167:                    node.setExecutor(nd.getExecutor());
168:                    node.setName(nd.getName());
169:                    node.setRole(nd.getBnRole().getName());
170:                    node.setType(nd.getType());
171:                    node.setReference(nd.getReference());
172:                    node.setProjectParent(nd.getBnProject().getParent());
173:                    node.setAnticipable(nd.getAnticipable());
174:
175:                    // Node inEdges
176:                    Collection inEdges = nd.getInBnEdges();
177:                    Iterator inEdgesI = inEdges.iterator();
178:                    Collection nodeInEdges = new ArrayList();
179:                    while (inEdgesI.hasNext()) {
180:                        BnEdgeLocal el = (BnEdgeLocal) inEdgesI.next();
181:                        BonitaEdgeValue inEdge = new BonitaEdgeValue();
182:                        inEdge.setName(el.getName());
183:                        inEdge.setCondition(el.getCondition());
184:                        inEdge.setState(el.getState());
185:                        inEdge.setInNode(el.getInBnNode().getName());
186:                        inEdge.setOutNode(el.getOutBnNode().getName());
187:                        nodeInEdges.add(inEdge);
188:                    }
189:                    node.setInEdges(nodeInEdges);
190:
191:                    // Node outEdges
192:                    Collection outEdges = nd.getOutBnEdges();
193:                    Iterator outEdgesI = outEdges.iterator();
194:                    Collection nodeOutEdges = new ArrayList();
195:                    while (outEdgesI.hasNext()) {
196:                        BnEdgeLocal el = (BnEdgeLocal) outEdgesI.next();
197:                        BonitaEdgeValue outEdge = new BonitaEdgeValue();
198:                        outEdge.setName(el.getName());
199:                        outEdge.setCondition(el.getCondition());
200:                        outEdge.setState(el.getState());
201:                        outEdge.setInNode(el.getInBnNode().getName());
202:                        outEdge.setOutNode(el.getOutBnNode().getName());
203:                        nodeOutEdges.add(outEdge);
204:                    }
205:                    node.setOutEdges(nodeOutEdges);
206:
207:                    // Node properties
208:                    Collection props = nd.getBnProperties();
209:                    Iterator propsI = props.iterator();
210:                    Collection nodeProps = new ArrayList();
211:                    while (propsI.hasNext()) {
212:                        BnNodePropertyLocal pl = (BnNodePropertyLocal) propsI
213:                                .next();
214:                        BonitaPropertyValue property = new BonitaPropertyValue();
215:                        property.setKey(pl.getTheKey());
216:                        property.setValue(pl.getTheValue());
217:                        property.setPropagate(pl.getPropagate());
218:                        //if (pl.getPossibleValues()!=null)
219:                        property.setPossibleValues(pl.getPossibleValues());
220:                        nodeProps.add(property);
221:                    }
222:                    node.setProperties(nodeProps);
223:                    BonitaPerformerValue performer = new BonitaPerformerValue();
224:                    performer.setNodeName(nd.getName());
225:                    if (nd.getBnNodePerformerAssign() != null) {
226:                        performer.setName(nd.getBnNodePerformerAssign()
227:                                .getName());
228:                        performer.setType(nd.getBnNodePerformerAssign()
229:                                .getType());
230:                        performer.setPropertyName(nd.getBnNodePerformerAssign()
231:                                .getPropertyName());
232:                        node.setPerformer(performer);
233:                    }
234:
235:                    // Node Hooks
236:                    Collection nodeHooks = projectModel.getBnNode(nd.getName())
237:                            .getBnHooks();
238:                    Iterator nodeHooksI = nodeHooks.iterator();
239:                    Collection nodeHks = new ArrayList();
240:                    while (nodeHooksI.hasNext()) {
241:                        BnNodeHookLocal ph = (BnNodeHookLocal) nodeHooksI
242:                                .next();
243:                        BonitaHookValue hook = new BonitaHookValue();
244:                        hook.setName(ph.getName());
245:                        hook.setEvent(ph.getEvent());
246:                        hook.setType(ph.getType());
247:                        nodeHks.add(hook);
248:                    }
249:                    node.setHooks(nodeHks);
250:
251:                    // Node InterHooks
252:                    Collection nodeInterHooks = projectModel.getBnNode(
253:                            nd.getName()).getBnInterHooks();
254:                    Iterator nodeInterHooksI = nodeInterHooks.iterator();
255:                    Collection nodeInterHks = new ArrayList();
256:                    while (nodeInterHooksI.hasNext()) {
257:                        BnNodeInterHookLocal pih = (BnNodeInterHookLocal) nodeInterHooksI
258:                                .next();
259:                        BonitaInterHookValue interHook = new BonitaInterHookValue();
260:                        interHook.setName(pih.getName());
261:                        interHook.setEvent(pih.getEvent());
262:                        interHook.setType(pih.getType());
263:                        interHook.setScript(pih.getScript());
264:                        nodeInterHks.add(interHook);
265:                    }
266:                    node.setInterHooks(nodeInterHks);
267:
268:                    nodesPro.add(node);
269:
270:                }
271:                pv.setNodes(nodesPro);
272:
273:                // Project Properties
274:                Collection projectProps = projectModel.getBnProperties();
275:                Iterator projectPropsI = projectProps.iterator();
276:                Collection projectPrs = new ArrayList();
277:                while (projectPropsI.hasNext()) {
278:                    BnProjectPropertyLocal pl = (BnProjectPropertyLocal) projectPropsI
279:                            .next();
280:                    BonitaPropertyValue property = new BonitaPropertyValue();
281:                    property.setKey(pl.getTheKey());
282:                    property.setValue(pl.getTheValue());
283:                    //if (pl.getPossibleValues()!=null)
284:                    property.setPossibleValues(pl.getPossibleValues());
285:                    projectPrs.add(property);
286:                }
287:                pv.setProperties(projectPrs);
288:
289:                // Project Hooks
290:                Collection projectHooks = projectModel.getBnHooks();
291:                Iterator projectHooksI = projectHooks.iterator();
292:                Collection projectHks = new ArrayList();
293:                while (projectHooksI.hasNext()) {
294:                    BnProjectHookLocal ph = (BnProjectHookLocal) projectHooksI
295:                            .next();
296:                    BonitaHookValue hook = new BonitaHookValue();
297:                    hook.setName(ph.getName());
298:                    hook.setEvent(ph.getEvent());
299:                    hook.setType(ph.getType());
300:                    projectHks.add(hook);
301:                }
302:                pv.setHooks(projectHks);
303:
304:                // Project InterHooks
305:                Collection projectInterHooks = projectModel.getBnInterHooks();
306:                Iterator projectInterHooksI = projectInterHooks.iterator();
307:                Collection projectInterHks = new ArrayList();
308:                while (projectInterHooksI.hasNext()) {
309:                    BnProjectInterHookLocal pih = (BnProjectInterHookLocal) projectInterHooksI
310:                            .next();
311:                    BonitaInterHookValue interHook = new BonitaInterHookValue();
312:                    interHook.setName(pih.getName());
313:                    interHook.setEvent(pih.getEvent());
314:                    interHook.setType(pih.getType());
315:                    interHook.setScript(pih.getScript());
316:                    projectInterHks.add(interHook);
317:                }
318:                pv.setInterHooks(projectInterHks);
319:
320:                // Project Roles
321:                Collection roles = projectModel.getBnRoles();
322:                Iterator rolesI = roles.iterator();
323:                Collection rolesP = new ArrayList();
324:                while (rolesI.hasNext()) {
325:                    BnRoleLocal rl = (BnRoleLocal) rolesI.next();
326:                    BonitaRoleValue role = new BonitaRoleValue();
327:                    role.setName(rl.getName());
328:                    role.setDescription(rl.getDescription());
329:
330:                    if (rl.getBnRoleMapper() != null) {
331:                        BonitaMapperValue mapper = new BonitaMapperValue();
332:                        mapper.setRoleName(rl.getName());
333:                        mapper.setName(rl.getBnRoleMapper().getName());
334:                        mapper.setType(rl.getBnRoleMapper().getType());
335:
336:                        role.setMapper(mapper);
337:                    }
338:
339:                    rolesP.add(role);
340:                }
341:                pv.setRoles(rolesP);
342:
343:                // Project
344:
345:                Collection users = projectModel.getBnUsers();
346:                Iterator usersI = users.iterator();
347:                Collection usersP = new ArrayList();
348:                while (usersI.hasNext()) {
349:                    BnUserLocal ul = (BnUserLocal) usersI.next();
350:                    BonitaUserValue user = new BonitaUserValue();
351:                    user.setName(ul.getName());
352:                    Collection userRoles = getUserRolesInProjectNames(
353:                            projectModel, ul.getName());
354:
355:                    Iterator uRolesI = userRoles.iterator();
356:                    Collection uRolesP = new ArrayList();
357:                    while (uRolesI.hasNext()) {
358:                        String roleName = (String) uRolesI.next();
359:                        uRolesP.add(roleName);
360:                    }
361:                    user.setRoles(uRolesP);
362:                    usersP.add(user);
363:                }
364:                pv.setUsers(usersP);
365:                return pv;
366:            }
367:
368:            private Collection getUserRolesInProjectNames(
369:                    BnProjectLocal mProject, String userName)
370:                    throws HeroException {
371:                BnUserLocalHome uHome;
372:                BnUserLocal user;
373:                ArrayList result = new ArrayList();
374:                try {
375:                    uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil
376:                            .getLocalHome();
377:                } catch (javax.naming.NamingException be) {
378:                    throw new HeroException(be.getMessage());
379:                }
380:                try {
381:                    user = uHome.findByName(userName);
382:                } catch (FinderException f) {
383:                    throw new HeroException("FinderException");
384:                }
385:                Collection userRoles = user.getBnRoles();
386:                Collection projectRoles = mProject.getBnRoles();
387:                for (Iterator i = userRoles.iterator(); i.hasNext();) {
388:                    BnRoleLocal ur = (BnRoleLocal) i.next();
389:                    for (Iterator j = projectRoles.iterator(); j.hasNext();) {
390:                        BnRoleLocal up = (BnRoleLocal) j.next();
391:                        if (ur.getId().equals(up.getId()))
392:                            result.add(ur.getBnRoleValue().getName());
393:                    }
394:                }
395:                return result;
396:            }
397:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.