KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > util > BonitaServiceValue


1 /**
2 *
3 * Bonita
4 * Copyright (C) 1999 Bull S.A.
5 * Bull 68 route de versailles 78434 Louveciennes Cedex France
6 * Further information: bonita@objectweb.org
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 * USA
22 *
23 *
24 --------------------------------------------------------------------------
25 * $Id: BonitaServiceValue.java,v 1.3 2005/03/30 15:19:45 mvaldes Exp $
26 *
27 --------------------------------------------------------------------------
28 */

29 package hero.util;
30
31 import java.io.Serializable JavaDoc;
32
33 import hero.interfaces.BnEdgeLocal;
34 import hero.interfaces.BnNodeHookLocal;
35 import hero.interfaces.BnNodeInterHookLocal;
36 import hero.interfaces.BnNodePropertyLocal;
37 import hero.interfaces.BnProjectHookLocal;
38 import hero.interfaces.BnProjectInterHookLocal;
39 import hero.interfaces.BnProjectLocal;
40 import hero.interfaces.BnNodeLocal;
41 import hero.interfaces.BnProjectLocalHome;
42 import hero.util.values.BonitaEdgeValue;
43 import hero.util.values.BonitaHookValue;
44 import hero.util.values.BonitaInterHookValue;
45 import hero.util.values.BonitaNodeValue;
46 import hero.util.values.BonitaPerformerValue;
47 import hero.util.values.BonitaProjectValue;
48 import hero.util.values.BonitaPropertyValue;
49
50 import java.util.ArrayList JavaDoc;
51 import java.util.Collection JavaDoc;
52 import java.util.Iterator JavaDoc;
53
54 public final class BonitaServiceValue implements Serializable JavaDoc {
55     
56     public static BonitaNodeValue getNodeFromCache(BonitaProjectValue pv, String JavaDoc nodeName){
57         Collection JavaDoc nodes = pv.getNodes();
58         Iterator JavaDoc nodesC = nodes.iterator();
59         while (nodesC.hasNext())
60         {
61             BonitaNodeValue nValue = (BonitaNodeValue)nodesC.next();
62             if (nValue.getName().equals(nodeName))
63                 return nValue;
64         }
65         return null;
66     }
67     
68     public static BonitaNodeValue getNode(BnProjectLocal pl, String JavaDoc nodeName) throws HeroException
69     {
70         try {
71         BnNodeLocal nd = pl.getBnNode(nodeName);
72         return (BonitaServiceValue.generateNode(nd,pl));
73         
74     }catch (Exception JavaDoc e){throw new HeroException(e.getMessage());}
75     }
76     
77     public static BonitaNodeValue getNode(String JavaDoc projectName, String JavaDoc nodeName) throws HeroException
78     {
79         try {
80         BnProjectLocalHome ph = hero.interfaces.BnProjectUtil.getLocalHome();
81         BnProjectLocal pl = ph.findByName(projectName);
82         BnNodeLocal nd = pl.getBnNode(nodeName);
83         return (BonitaServiceValue.generateNode(nd,pl));
84         
85     }catch (Exception JavaDoc e){throw new HeroException(e.getMessage());}
86     }
87     
88     public static Collection JavaDoc getProjectHooks(BnProjectLocal pl) throws HeroException
89     {
90         Collection JavaDoc projectHooks = new ArrayList JavaDoc();
91         Collection JavaDoc hooks = pl.getBnHooks();
92         Iterator JavaDoc prHooks = hooks.iterator();
93         while (prHooks.hasNext())
94         {
95             BnProjectHookLocal ph = (BnProjectHookLocal)prHooks.next();
96             BonitaHookValue hook = new BonitaHookValue();
97             hook.setName(ph.getName());
98             hook.setEvent(ph.getEvent());
99             hook.setType(ph.getType());
100             projectHooks.add(hook);
101         }
102         return projectHooks;
103     }
104     
105     public static Collection JavaDoc getProjectInterHooks(BnProjectLocal pl) throws HeroException
106     {
107         Collection JavaDoc projectHooks = new ArrayList JavaDoc();
108         Collection JavaDoc hooks = pl.getBnInterHooks();
109         Iterator JavaDoc prHooks = hooks.iterator();
110         while (prHooks.hasNext())
111         {
112             BnProjectInterHookLocal ph = (BnProjectInterHookLocal)prHooks.next();
113             BonitaInterHookValue hook = new BonitaInterHookValue();
114             hook.setName(ph.getName());
115             hook.setEvent(ph.getEvent());
116             hook.setType(ph.getType());
117             hook.setScript(ph.getScript());
118             projectHooks.add(hook);
119         }
120         return projectHooks;
121     }
122     
123     public static BonitaNodeValue generateNode(BnNodeLocal nd, BnProjectLocal pl) throws HeroException
124     {
125      try{
126         BonitaNodeValue nv = new BonitaNodeValue();
127         
128         BonitaNodeValue node = new BonitaNodeValue();
129         node.setProjectName(pl.getName());
130         node.setName(nd.getName());
131         
132         // Node inEdges
133
Collection JavaDoc inEdges = nd.getInBnEdges();
134         Iterator JavaDoc inEdgesI = inEdges.iterator();
135         Collection JavaDoc nodeInEdges = new ArrayList JavaDoc();
136         while(inEdgesI.hasNext())
137         {
138             BnEdgeLocal el = (BnEdgeLocal)inEdgesI.next();
139             BonitaEdgeValue inEdge = new BonitaEdgeValue();
140             inEdge.setName(el.getName());
141             inEdge.setCondition(el.getCondition());
142             inEdge.setState(el.getState());
143             inEdge.setInNode(el.getInBnNode().getName());
144             inEdge.setOutNode(el.getOutBnNode().getName());
145             nodeInEdges.add(inEdge);
146         }
147         node.setInEdges(nodeInEdges);
148         
149         // Node outEdges
150
Collection JavaDoc outEdges = nd.getOutBnEdges();
151         Iterator JavaDoc outEdgesI = outEdges.iterator();
152         Collection JavaDoc nodeOutEdges = new ArrayList JavaDoc();
153         while(outEdgesI.hasNext())
154         {
155             BnEdgeLocal el = (BnEdgeLocal)outEdgesI.next();
156             BonitaEdgeValue outEdge = new BonitaEdgeValue();
157             outEdge.setName(el.getName());
158             outEdge.setCondition(el.getCondition());
159             outEdge.setState(el.getState());
160             outEdge.setInNode(el.getInBnNode().getName());
161             outEdge.setOutNode(el.getOutBnNode().getName());
162             nodeOutEdges.add(outEdge);
163         }
164         node.setOutEdges(nodeOutEdges);
165                 
166         // Node Hooks
167
Collection JavaDoc nodeHooks = pl.getBnNode(nd.getName()).getBnHooks();
168         Iterator JavaDoc nodeHooksI = nodeHooks.iterator();
169         Collection JavaDoc nodeHks = new ArrayList JavaDoc();
170         while(nodeHooksI.hasNext())
171         {
172             BnNodeHookLocal ph = (BnNodeHookLocal)nodeHooksI.next();
173             BonitaHookValue hook = new BonitaHookValue();
174             hook.setName(ph.getName());
175             hook.setEvent(ph.getEvent());
176             hook.setType(ph.getType());
177             nodeHks.add(hook);
178         }
179         node.setHooks(nodeHks);
180         
181         // Node InterHooks
182
Collection JavaDoc nodeInterHooks = pl.getBnNode(nd.getName()).getBnInterHooks();
183         Iterator JavaDoc nodeInterHooksI = nodeInterHooks.iterator();
184         Collection JavaDoc nodeInterHks = new ArrayList JavaDoc();
185         while(nodeInterHooksI.hasNext())
186         {
187             BnNodeInterHookLocal pih = (BnNodeInterHookLocal)nodeInterHooksI.next();
188             BonitaInterHookValue interHook = new BonitaInterHookValue();
189             interHook.setName(pih.getName());
190             interHook.setEvent(pih.getEvent());
191             interHook.setType(pih.getType());
192             interHook.setScript(pih.getScript());
193             nodeInterHks.add(interHook);
194         }
195         node.setInterHooks(nodeInterHks);
196         
197         return node;
198      }catch (Exception JavaDoc e){throw new HeroException(e.getMessage());}
199     }
200 }
201
Popular Tags