1 29 package hero.util; 30 31 import java.io.Serializable ; 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 ; 51 import java.util.Collection ; 52 import java.util.Iterator ; 53 54 public final class BonitaServiceValue implements Serializable { 55 56 public static BonitaNodeValue getNodeFromCache(BonitaProjectValue pv, String nodeName){ 57 Collection nodes = pv.getNodes(); 58 Iterator 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 nodeName) throws HeroException 69 { 70 try { 71 BnNodeLocal nd = pl.getBnNode(nodeName); 72 return (BonitaServiceValue.generateNode(nd,pl)); 73 74 }catch (Exception e){throw new HeroException(e.getMessage());} 75 } 76 77 public static BonitaNodeValue getNode(String projectName, String 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 e){throw new HeroException(e.getMessage());} 86 } 87 88 public static Collection getProjectHooks(BnProjectLocal pl) throws HeroException 89 { 90 Collection projectHooks = new ArrayList (); 91 Collection hooks = pl.getBnHooks(); 92 Iterator 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 getProjectInterHooks(BnProjectLocal pl) throws HeroException 106 { 107 Collection projectHooks = new ArrayList (); 108 Collection hooks = pl.getBnInterHooks(); 109 Iterator 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 Collection inEdges = nd.getInBnEdges(); 134 Iterator inEdgesI = inEdges.iterator(); 135 Collection nodeInEdges = new ArrayList (); 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 Collection outEdges = nd.getOutBnEdges(); 151 Iterator outEdgesI = outEdges.iterator(); 152 Collection nodeOutEdges = new ArrayList (); 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 Collection nodeHooks = pl.getBnNode(nd.getName()).getBnHooks(); 168 Iterator nodeHooksI = nodeHooks.iterator(); 169 Collection nodeHks = new ArrayList (); 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 Collection nodeInterHooks = pl.getBnNode(nd.getName()).getBnInterHooks(); 183 Iterator nodeInterHooksI = nodeInterHooks.iterator(); 184 Collection nodeInterHks = new ArrayList (); 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 e){throw new HeroException(e.getMessage());} 199 } 200 } 201 | Popular Tags |