1 package hero.entity; 2 import hero.interfaces.Constants; 3 import hero.interfaces.BnEdgeLocal; 4 import hero.interfaces.BnNodeLocal; 5 import hero.util.BonitaProjectLocator; 6 import hero.util.BonitaServiceException; 7 import hero.util.BonitaServiceValue; 8 import hero.util.HeroException; 9 import hero.util.values.BonitaEdgeValue; 10 import hero.util.values.BonitaProjectValue; 11 12 import java.util.*; 13 import org.apache.log4j.Category; 14 15 16 38 39 public class AndEdgeState extends EdgeState implements java.io.Serializable { 40 41 private static AndEdgeState nd; 42 43 public AndEdgeState() { 44 } 45 46 public static AndEdgeState getInstance() { 47 if (nd==null) { 48 nd=new AndEdgeState(); 49 } 50 return nd; 51 } 52 53 public int state(BnNodeLocal node) { 54 BonitaProjectValue currentProject=null; 55 Collection edges = new ArrayList(); 56 Collection edgesModel = new ArrayList(); 57 58 try{ 59 edges = BonitaServiceValue.getNode(node.getBnProject(),node.getName()).getInEdges(); 60 }catch (Exception e) {e.printStackTrace();} 61 62 String nodeName = node.getName(); 64 if (isInstance(node.getName())) 65 nodeName = getModel(nodeName); 66 67 try{ 68 edgesModel = BonitaServiceValue.getNode(node.getBnProject().getModel().getName(),nodeName).getInEdges(); 69 }catch (Exception e) {edgesModel=new ArrayList();} 70 if (edges.size() != edgesModel.size() && !edgesModel.isEmpty()) 71 edges = concatEdges(edges, edgesModel); 72 73 Iterator i = edges.iterator(); 74 int result=Constants.Nd.ACTIVE; 75 while (i.hasNext()) { 76 BonitaEdgeValue edge = (BonitaEdgeValue)i.next(); 77 if (edge.getState()==Constants.Ed.INITIAL) { 78 result=Constants.Nd.EDGEINITIAL; 79 break; 80 } 81 if ((edge.getState() == Constants.Ed.ANTICIPATING)) 82 result=Constants.Nd.ANTACTIVE; 83 if ((edge.getState() == Constants.Ed.DEAD)) 84 { 85 result=Constants.Nd.CANCEL; 86 break; 87 } 88 } 89 return result; 90 } 91 92 private String getModel(String instanceName) { 93 int i = instanceName.indexOf("_instance"); 94 return (instanceName.substring(0, i)); 95 } 96 97 private boolean isInstance(String name) { 98 return (name.matches(".*_instance.*")); 99 } 100 101 private Collection concatEdges(Collection edges, Collection edgesModel) { 102 Collection result = new ArrayList(); 103 Iterator ed = edgesModel.iterator(); 104 while (ed.hasNext()) 105 { 106 boolean found = false; 107 BonitaEdgeValue el = (BonitaEdgeValue)ed.next(); 108 String nodeName = el.getInNode(); 109 Iterator instEdges = edges.iterator(); 110 while(instEdges.hasNext()) 111 { 112 BonitaEdgeValue insEd = (BonitaEdgeValue)instEdges.next(); 113 String node = insEd.getInNode(); 114 if (this.isInstance(node)) 115 node = this.getModel(node); 116 if (nodeName.equals(node)) 117 { 118 result.add(insEd); 119 found = true; 120 break; 121 } 122 } 123 if (!found) 124 result.add(el); 125 } 126 return result; 127 } 128 } 129 130 131 132 133 134 135 136 137 138 139 140 | Popular Tags |