1 10 11 package org.enhydra.jawe.xml.elements; 12 13 import org.enhydra.jawe.xml.*; 14 import org.enhydra.jawe.xml.panels.*; 15 16 import java.util.*; 17 18 24 public class Transitions extends XMLCollection { 25 31 public Transitions (XMLComplexElement wpOrAs) { 32 super(wpOrAs); 33 } 34 35 41 public XMLElement generateNewElement() { 42 Transition t=new Transition(this); 43 t.setRequired(true); 44 return t; 45 } 46 47 48 64 public Set getTransitions (String ID,int st) { 65 Set trans=new HashSet(); 66 Transition t; 67 Iterator it=refCollectionElements.iterator(); 68 while (it.hasNext()) { 69 t=(Transition)it.next(); 70 if (st<=0) { 71 try { 73 if (t.getFrom().get("Id").toString().equals(ID)) { 74 trans.add(t); 75 } 76 } catch (Exception ex) {} 77 } 78 if (st>=0) { 79 try { 81 if (t.getTo().get("Id").toString().equals(ID)) { 82 trans.add(t); 83 } 84 } catch (Exception ex) {} 85 } 86 } 87 return trans; 88 } 89 90 97 public Transition getTransition (String ID) { 98 return (Transition)super.getCollectionElement(ID); 99 } 100 101 105 protected boolean canRemoveDataFieldOrFormalParameter (XMLCollectionElement toRemove) { 106 String IDToCheck=toRemove.getID(); 107 Transition t; 108 Condition c; 109 Xpression x; 110 String tcx; 111 int foundAt; 112 char prev, next; 113 boolean prevOK, nextOK; 114 115 Iterator it=refCollectionElements.iterator(); 116 while (it.hasNext()) { 117 t=(Transition)it.next(); 118 c=(Condition)t.get("Condition"); 119 x=(Xpression)c.get("Xpression"); 120 tcx=x.toString(); 121 foundAt=tcx.indexOf(IDToCheck); 122 if (foundAt!=-1) { 125 if (foundAt==0) { 127 prevOK=true; 128 } else { 129 prev=tcx.charAt(foundAt-1); 130 prevOK=!XMLCollection.isIdValid(String.valueOf(prev)); 131 } 132 133 if (foundAt+IDToCheck.length()==tcx.length()) { 135 nextOK=true; 136 } else { 137 next=tcx.charAt(foundAt+IDToCheck.length()); 138 nextOK=!XMLCollection.isIdValid(String.valueOf(next)); 139 } 140 141 if (prevOK && nextOK) { 143 return false; 144 } 145 } 146 } 147 return true; 148 } 149 150 public int[] getInvisibleTableFieldOrdinals () { 151 int[] itfo=new int[4]; 152 itfo[0]=2; 153 itfo[1]=3; 154 itfo[2]=5; 155 itfo[3]=6; 156 return itfo; 157 } 158 159 163 protected void afterImporting () { 164 Iterator it=refCollectionElements.iterator(); 165 while (it.hasNext()) { 166 Transition t=(Transition)it.next(); 167 t.afterImporting(); 168 } 169 } 170 171 public XMLPanel getPanel () { 173 isReadOnly=true; 174 controlledPanel=new XMLTablePanel(this,"",false,false); 175 controlPanel=new XMLTableControlPanel(this,"",true,false); 176 return new XMLGroupPanel(this,new XMLPanel[]{ 177 controlledPanel,controlPanel},toLabel(),XMLPanel.BOX_LAYOUT, 178 false,true); 179 } 180 181 public Object toValue () { 182 return String.valueOf(refCollectionElements.size()); 183 } 184 185 public WorkflowProcess getWorkflowProcess () { 186 Object own=getOwner(); 187 if (own instanceof ActivitySet) { 188 return ((ActivitySet)own).getOwnerProcess(); 189 } else { 190 return (WorkflowProcess)own; 191 } 192 } 193 194 199 public void refreshCollection (Set elementsToAddOrRemove,boolean append) { 200 if (append) { 201 for (Iterator it=elementsToAddOrRemove.iterator(); it.hasNext();) { 202 Transition t=(Transition)it.next(); 203 if (t.getCollection() != this){ 205 decrementID(); 206 t.get("Id").setValue(this.generateID()); 207 } 208 t.setCollection(this); 209 refCollectionElements.add(t); 210 } 211 } else { 212 refCollectionElements.removeAll(elementsToAddOrRemove); 213 } 214 } 215 216 217 220 public void decrementID () { 221 getWorkflowProcess().decrementTransitionId(); 222 } 223 224 public long getCurrentID () { 225 return getWorkflowProcess().getCurrentTransitionId(); 226 } 227 228 public String generateID () { 229 if (IDPrefix==null) IDPrefix=""; 230 String ID; 231 do { 232 ID=IDPrefix+new Long (getWorkflowProcess().getNextTransitionId()).toString(); 233 } while (getWorkflowProcess().getTransition(ID)!=null); 234 return ID; 235 } 236 237 protected void resetID () { 238 getWorkflowProcess().resetTransitionId(); 239 } 240 241 protected void updateID (String someID) { 242 try { 244 long val; 245 if (someID.startsWith(IDPrefix)) { 246 String ID=someID.substring(IDPrefix.length(),someID.length()); 247 val=Long.parseLong(ID); 248 if (val>getWorkflowProcess().getCurrentTransitionId()) { 249 getWorkflowProcess().setCurrentTransitionId(val); 250 } 251 } 252 } catch (Exception ex) { 254 return; 255 } 256 } 257 258 } 259 | Popular Tags |