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 import org.w3c.dom.*; 18 import javax.xml.parsers.DocumentBuilderFactory ; 19 import javax.xml.parsers.DocumentBuilder ; 20 21 25 public class WorkflowProcesses extends XMLCollection { 26 27 private ArrayList externalProcesses=new ArrayList(); 28 29 34 public WorkflowProcesses (Package p) { 35 super(p); 36 } 37 38 public boolean isMine (WorkflowProcess wp) { 39 return refCollectionElements.contains(wp); 40 } 41 42 49 public XMLElement generateNewElement() { 50 WorkflowProcess wp=new WorkflowProcess(this,(Package )myOwner); 51 wp.setRequired(true); 52 return wp; 53 } 54 55 67 public WorkflowProcess getWorkflowProcess(String ID) { 68 WorkflowProcess wp=(WorkflowProcess)super.getCollectionElement(ID); 69 if (wp==null) { 71 String extID; 72 Iterator it=externalProcesses.iterator(); 73 while (it.hasNext()) { 74 WorkflowProcess wptmp=(WorkflowProcess)it.next(); 75 extID=wptmp.getID(); 76 if (extID.equals(ID)) { 77 wp=wptmp; 78 break; 79 } 80 } 81 } 82 return wp; 83 } 84 85 89 public Collection getTableElements () { 90 ArrayList chos=new ArrayList(refCollectionElements); 93 return chos; 94 } 95 96 102 public Collection getChoosable () { 103 ArrayList chos=new ArrayList(refCollectionElements); 104 Iterator i=externalProcesses.iterator(); 105 while (i.hasNext()) { 106 WorkflowProcess wp=(WorkflowProcess)i.next(); 107 if (getCollectionElement(wp.getID())==null) { 108 chos.add(wp); 109 } 110 } 111 return chos; 112 } 113 114 118 public boolean canRemoveElement (XMLElement el) { 119 boolean remove=true; 120 WorkflowProcess toRemove=(WorkflowProcess)el; 121 Iterator it=refCollectionElements.iterator(); 122 while (it.hasNext()) { 123 WorkflowProcess wp=(WorkflowProcess)it.next(); 124 if (wp!=toRemove) { 126 Activities acts=(Activities)wp.get("Activities"); 127 remove=acts.canRemoveWorkflow(toRemove); 128 if (!remove) { 129 break; 130 } 131 ActivitySets actsts=(ActivitySets)wp.get("ActivitySets"); 132 remove=actsts.canRemoveWorkflow(toRemove); 133 if (!remove) { 134 break; 135 } 136 } 137 } 138 return remove; 139 } 140 141 public Collection getExternalWorkflowProcesses () { 142 return externalProcesses; 143 } 144 145 public WorkflowProcess createCopyOfWorkflowProcess (WorkflowProcess wp,boolean localCopy) { 146 if (wp==null) return null; 147 148 Package mine=(Package )myOwner; 149 Package ext=wp.getPackage(); 150 151 Document document=null; 152 try { 153 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 154 DocumentBuilder dbuilder = dbf.newDocumentBuilder(); 155 document = dbuilder.newDocument(); 156 } catch (Exception ex) {} 157 ext.toXML(document); 158 159 160 WorkflowProcess copyOfWP=(WorkflowProcess)generateNewElement(); 161 String ID=copyOfWP.getID(); 162 163 NodeList nl=document.getElementsByTagName("WorkflowProcess"); 164 Node wantedWorkflowNode=null; 165 if (nl.getLength()>0) { 166 String extID=wp.getID(); 167 for (int i=0; i<nl.getLength(); i++) { 168 Node n=nl.item(i); 169 String IDOfNode=XMLUtil.getID(n); 170 if (IDOfNode.equals(extID)) { 171 wantedWorkflowNode=n; 172 break; 173 } 174 } 175 } else { 176 return null; 177 } 178 179 if (wantedWorkflowNode==null) return null; 180 copyOfWP.readFromXML(wantedWorkflowNode); 182 183 if(!localCopy) { 184 TypeDeclarations mineTD=(TypeDeclarations)mine.get("TypeDeclarations"); 187 TypeDeclarations extTD=(TypeDeclarations)ext.get("TypeDeclarations"); 188 TypeDeclarations tmpTD=new TypeDeclarations((Package )myOwner); 189 nl=document.getElementsByTagName("TypeDeclarations"); 193 if (nl.getLength()>0) { 194 Node n=nl.item(0); 195 tmpTD.fromXML(n); 196 } 197 Iterator it=tmpTD.toCollection().iterator(); 201 while (it.hasNext()) { 202 TypeDeclaration td=(TypeDeclaration)it.next(); 203 if (mineTD.getDeclaredType(td.getID())==null) { 204 mineTD.toCollection().add(td); 205 } 206 } 207 208 DataFields extDF=(DataFields)ext.get("DataFields"); 212 DataFields copyDF=(DataFields)copyOfWP.get("DataFields"); 213 DataFields tmpDF=new DataFields((Package )myOwner); 214 nl=document.getElementsByTagName("DataFields"); 219 if (nl.getLength()>0) { 220 Node n=nl.item(0); 221 tmpDF.fromXML(n); 222 } 223 copyDF.toCollection().addAll(tmpDF.toCollection()); 225 } 226 227 copyOfWP.afterImporting(); 229 230 copyOfWP.set("Id",ID); 232 if (localCopy) { 233 copyOfWP.set("Name", 234 XMLUtil.getLanguageDependentString("CopyOfKey")+ 235 " "+copyOfWP.get("Name").toString()); 236 } 237 238 refCollectionElements.add(copyOfWP); 240 return copyOfWP; 241 } 242 245 protected void insertFromExternal(Package ep) { 246 WorkflowProcesses externalWPs=(WorkflowProcesses)ep. 247 get("WorkflowProcesses"); 248 Iterator it=externalWPs.refCollectionElements.iterator(); 251 while (it.hasNext()) { 252 WorkflowProcess wp=(WorkflowProcess)it.next(); 253 if (!externalProcesses.contains(wp)) { 254 externalProcesses.add(wp); 255 } 256 } 257 260 } 261 262 265 protected void removeFromExternal(Package ep) { 266 WorkflowProcesses externalWPs=(WorkflowProcesses)ep. 267 get("WorkflowProcesses"); 268 269 Iterator it=externalWPs.toCollection().iterator(); 270 while (it.hasNext()) { 271 WorkflowProcess wp=(WorkflowProcess)it.next(); 272 externalProcesses.remove(wp); 273 } 274 } 275 276 public int[] getInvisibleTableFieldOrdinals () { 277 int[] itfo=new int[10]; 278 itfo[0]=3; 279 itfo[1]=4; 280 itfo[2]=5; 281 itfo[3]=6; 282 itfo[4]=7; 283 itfo[5]=8; 284 itfo[6]=9; 285 itfo[7]=10; 286 itfo[8]=11; 287 itfo[9]=12; 288 return itfo; 289 } 290 291 294 public XMLPanel getPanel () { 295 isReadOnly=true; 296 return super.getPanel(); 297 } 298 299 public void refreshCollection (Set elementsToAddOrRemove,boolean append) { 300 super.refreshCollection(elementsToAddOrRemove,append); 301 if (append) { 302 Iterator it=refCollectionElements.iterator(); 303 while (it.hasNext()) { 304 WorkflowProcess wp=(WorkflowProcess)it.next(); 305 if (isMine(wp)) { 306 wp.setIDPrefixForCollections(); 307 } 308 } 309 } 310 } 311 312 315 public void decrementID () { 316 super.decrementID(); 317 } 318 319 322 protected void updateID (String someID) { 323 super.updateID(someID); 324 } 325 326 } 327 | Popular Tags |