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: BonitaServiceValue.java,v 1.5 2006/08/17 15:30:54 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.util;
029:
030: import java.io.Serializable;
031:
032: import hero.interfaces.BnEdgeLocal;
033: import hero.interfaces.BnNodeHookLocal;
034: import hero.interfaces.BnNodeInterHookLocal;
035: import hero.interfaces.BnNodePropertyLocal;
036: import hero.interfaces.BnProjectHookLocal;
037: import hero.interfaces.BnProjectInterHookLocal;
038: import hero.interfaces.BnProjectLocal;
039: import hero.interfaces.BnNodeLocal;
040: import hero.interfaces.BnProjectLocalHome;
041: import hero.util.values.BonitaEdgeValue;
042: import hero.util.values.BonitaHookValue;
043: import hero.util.values.BonitaInterHookValue;
044: import hero.util.values.BonitaNodeValue;
045: import hero.util.values.BonitaPerformerValue;
046: import hero.util.values.BonitaProjectValue;
047: import hero.util.values.BonitaPropertyValue;
048: import hero.interfaces.Constants;
049:
050: import java.util.ArrayList;
051: import java.util.Collection;
052: import java.util.Iterator;
053:
054: public final class BonitaServiceValue implements Serializable {
055:
056: public static BonitaNodeValue getNodeFromCache(
057: BonitaProjectValue pv, String nodeName) {
058: Collection nodes = pv.getNodes();
059: Iterator nodesC = nodes.iterator();
060: while (nodesC.hasNext()) {
061: BonitaNodeValue nValue = (BonitaNodeValue) nodesC.next();
062: if (nValue.getName().equals(nodeName))
063: return nValue;
064: }
065: return null;
066: }
067:
068: public static BonitaNodeValue getNode(BnProjectLocal pl,
069: String nodeName) throws HeroException {
070: try {
071: BnNodeLocal nd = pl.getBnNode(nodeName);
072: return (BonitaServiceValue.generateNode(nd, pl));
073:
074: } catch (Exception e) {
075: throw new HeroException(e.getMessage());
076: }
077: }
078:
079: public static BonitaNodeValue getNode(String projectName,
080: String projectVersion, String nodeName)
081: throws HeroException {
082: try {
083: BnProjectLocalHome ph = hero.interfaces.BnProjectUtil
084: .getLocalHome();
085: BnProjectLocal pl = ph.findByNameVersion(projectName,
086: projectVersion);
087: BnNodeLocal nd = pl.getBnNode(nodeName);
088: return (BonitaServiceValue.generateNode(nd, pl));
089:
090: } catch (Exception e) {
091: throw new HeroException(e.getMessage());
092: }
093: }
094:
095: public static Collection getProjectHooks(BnProjectLocal pl)
096: throws HeroException {
097: Collection projectHooks = new ArrayList();
098: Collection hooks = pl.getBnHooks();
099: Iterator prHooks = hooks.iterator();
100: while (prHooks.hasNext()) {
101: BnProjectHookLocal ph = (BnProjectHookLocal) prHooks.next();
102: BonitaHookValue hook = new BonitaHookValue();
103: hook.setName(ph.getName());
104: hook.setEvent(ph.getEvent());
105: hook.setType(ph.getType());
106: projectHooks.add(hook);
107: }
108: return projectHooks;
109: }
110:
111: public static Collection getProjectInterHooks(BnProjectLocal pl)
112: throws HeroException {
113: Collection projectHooks = new ArrayList();
114: Collection hooks = pl.getBnInterHooks();
115: Iterator prHooks = hooks.iterator();
116: while (prHooks.hasNext()) {
117: BnProjectInterHookLocal ph = (BnProjectInterHookLocal) prHooks
118: .next();
119: BonitaInterHookValue hook = new BonitaInterHookValue();
120: hook.setName(ph.getName());
121: hook.setEvent(ph.getEvent());
122: hook.setType(ph.getType());
123: hook.setScript(ph.getScript());
124: projectHooks.add(hook);
125: }
126: return projectHooks;
127: }
128:
129: public static BonitaNodeValue generateNode(BnNodeLocal nd,
130: BnProjectLocal pl) throws HeroException {
131: try {
132: BonitaNodeValue nv = new BonitaNodeValue();
133:
134: BonitaNodeValue node = new BonitaNodeValue();
135: node.setProjectName(pl.getName());
136: node.setName(nd.getName());
137: node.setType(nd.getType());
138: if (nd.getType() == Constants.Nd.SUB_PROCESS_NODE)
139: node.setReference(nd.getReference());
140:
141: // Node inEdges
142: Collection inEdges = nd.getInBnEdges();
143: Iterator inEdgesI = inEdges.iterator();
144: Collection nodeInEdges = new ArrayList();
145: while (inEdgesI.hasNext()) {
146: BnEdgeLocal el = (BnEdgeLocal) inEdgesI.next();
147: BonitaEdgeValue inEdge = new BonitaEdgeValue();
148: inEdge.setName(el.getName());
149: inEdge.setCondition(el.getCondition());
150: inEdge.setState(el.getState());
151: inEdge.setInNode(el.getInBnNode().getName());
152: inEdge.setOutNode(el.getOutBnNode().getName());
153: nodeInEdges.add(inEdge);
154: }
155: node.setInEdges(nodeInEdges);
156:
157: // Node outEdges
158: Collection outEdges = nd.getOutBnEdges();
159: Iterator outEdgesI = outEdges.iterator();
160: Collection nodeOutEdges = new ArrayList();
161: while (outEdgesI.hasNext()) {
162: BnEdgeLocal el = (BnEdgeLocal) outEdgesI.next();
163: BonitaEdgeValue outEdge = new BonitaEdgeValue();
164: outEdge.setName(el.getName());
165: outEdge.setCondition(el.getCondition());
166: outEdge.setState(el.getState());
167: outEdge.setInNode(el.getInBnNode().getName());
168: outEdge.setOutNode(el.getOutBnNode().getName());
169: nodeOutEdges.add(outEdge);
170: }
171: node.setOutEdges(nodeOutEdges);
172:
173: // Node Hooks
174: Collection nodeHooks = pl.getBnNode(nd.getName())
175: .getBnHooks();
176: Iterator nodeHooksI = nodeHooks.iterator();
177: Collection nodeHks = new ArrayList();
178: while (nodeHooksI.hasNext()) {
179: BnNodeHookLocal ph = (BnNodeHookLocal) nodeHooksI
180: .next();
181: BonitaHookValue hook = new BonitaHookValue();
182: hook.setName(ph.getName());
183: hook.setEvent(ph.getEvent());
184: hook.setType(ph.getType());
185: nodeHks.add(hook);
186: }
187: node.setHooks(nodeHks);
188:
189: // Node InterHooks
190: Collection nodeInterHooks = pl.getBnNode(nd.getName())
191: .getBnInterHooks();
192: Iterator nodeInterHooksI = nodeInterHooks.iterator();
193: Collection nodeInterHks = new ArrayList();
194: while (nodeInterHooksI.hasNext()) {
195: BnNodeInterHookLocal pih = (BnNodeInterHookLocal) nodeInterHooksI
196: .next();
197: BonitaInterHookValue interHook = new BonitaInterHookValue();
198: interHook.setName(pih.getName());
199: interHook.setEvent(pih.getEvent());
200: interHook.setType(pih.getType());
201: interHook.setScript(pih.getScript());
202: nodeInterHks.add(interHook);
203: }
204: node.setInterHooks(nodeInterHks);
205:
206: return node;
207: } catch (Exception e) {
208: throw new HeroException(e.getMessage());
209: }
210: }
211: }
|