1 package cve.esecutori.components.automatonB; 2 3 import cve.esecutori.components.specificaLV.*; 4 5 import java.io.File ; 6 import java.io.IOException ; 7 import java.io.*; 8 import java.util.*; 9 10 import org.jdom.*; 11 import org.jdom.input.SAXBuilder; 12 import org.jdom.output.XMLOutputter; 13 14 import org.apache.log4j.Logger; 15 import cve.staticLayout.*; 16 17 25 class WippogSent extends WriteWippogSpe { 26 27 protected String nameRoot, nameRootTransition; 28 protected String fileSent; 29 private Element currentTra; 30 private Element root; 31 private Map scheletro; 32 33 38 public WippogSent(Map scheletro) { 39 Cve.errLog.debug(""); 40 root=new Element("WippogRules"); 41 document=new Document(root); 42 this.scheletro=scheletro; 43 } 44 45 46 47 51 protected void configSent () { 52 Cve.errLog.debug(""); 53 wippogDefines(); 54 wippogImport(); 55 wippogExport(); 56 } 57 58 64 protected void openTransition (String id,String descr) { 65 Cve.errLog.debug(""); 66 Element newTransition=new Element("Transition"); 67 if (id!=null) 68 newTransition.addAttribute("id",id); 69 if (descr!=null) 70 newTransition.addAttribute("description",descr); 71 currentTra=newTransition; 72 } 73 74 77 protected void closeTransition () { 78 Cve.errLog.debug(""); 79 Element root=document.getRootElement(); 80 root.addContent(currentTra); 81 } 82 83 86 protected void wippogDefines() { 87 Cve.errLog.debug(""); 88 Element newDefines=new Element("Defines"); 89 newDefines.addAttribute("description","Definizione dei tipi utilizzati"); 90 Set chiavi=scheletro.keySet(); 92 Iterator itChiavi=chiavi.iterator(); 93 while (itChiavi.hasNext()) { 94 String chiave=(String )itChiavi.next(); 95 Vector attributi=(Vector)scheletro.get(chiave); 96 Element item=new Element("ItemDefinition"); 97 item.addAttribute("typeName",chiave); 98 int i=0; 99 while (i<attributi.size()) { 100 Element parameter=new Element ("ParameterDefinition"); 101 parameter.addAttribute("name",(String )attributi.elementAt(i)); 102 parameter.addAttribute("type",(String )attributi.elementAt(i+1)); 103 i=i+2; 104 item.addContent(parameter); 105 } 106 newDefines.addContent(item); 107 } 108 Element itemL=new Element ("ItemDefinition"); 110 itemL.addAttribute("typeName","listaSel"); 111 Element parameter=new Element ("ParameterDefinition"); 112 parameter.addAttribute("name","lista"); 113 parameter.addAttribute("type","Listaid"); 114 itemL.addContent(parameter); 115 newDefines.addContent(itemL); 116 Element activityI=new Element("ItemDefinition"); 118 activityI.addAttribute("typeName","activity"); 119 Element parameter1=new Element ("ParameterDefinition"); 120 parameter1.addAttribute("name","eButton"); 121 parameter1.addAttribute("type","Listastringa"); 122 Element parameter2=new Element ("ParameterDefinition"); 123 parameter2.addAttribute("name","dButton"); 124 parameter2.addAttribute("type","Listastringa"); 125 Element parameter3=new Element ("ParameterDefinition"); 126 parameter3.addAttribute("name","idType"); 127 parameter3.addAttribute("type","Stringa"); 128 Element parameter4=new Element ("ParameterDefinition"); 129 parameter4.addAttribute("name","query"); 130 parameter4.addAttribute("type","Listastringa"); 131 Element parameter5=new Element ("ParameterDefinition"); 132 parameter5.addAttribute("name","generate"); 133 parameter5.addAttribute("type","Listastringa"); 134 Element parameter6=new Element ("ParameterDefinition"); 135 parameter6.addAttribute("name","idInstance"); 136 parameter6.addAttribute("type","Identificatore"); 137 activityI.addContent(parameter1); 138 activityI.addContent(parameter2); 139 activityI.addContent(parameter3); 140 activityI.addContent(parameter4); 141 activityI.addContent(parameter5); 142 activityI.addContent(parameter6); 143 newDefines.addContent(activityI); 144 Element itemCond=new Element ("ItemDefinition"); 146 itemCond.addAttribute("typeName","conditionRule"); 147 Element parameterC=new Element ("ParameterDefinition"); 148 parameterC.addAttribute("name","condition"); 149 parameterC.addAttribute("type","Booleano"); 150 itemCond.addContent(parameterC); 151 newDefines.addContent(itemCond); 152 160 161 root.addContent(newDefines); 162 } 163 164 167 protected void wippogExport() { 168 Cve.errLog.debug(""); 169 Element export=new Element("Exports"); 170 Element itemE=new Element("Item"); 171 itemE.addAttribute("typeName","conditionRule"); 172 export.addContent(itemE); 173 root.addContent(export); 174 } 175 176 179 protected void wippogImport() { 180 Cve.errLog.debug(""); 181 Element importW=new Element("Imports"); 182 Element itemIW=new Element("Item"); 183 itemIW.addAttribute("typeName","listaSel"); 184 Element itemLS=new Element("Item"); 185 itemLS.addAttribute("typeName","activity"); 186 importW.addContent(itemLS); 187 importW.addContent(itemIW); 188 root.addContent(importW); 189 } 190 191 197 protected void writeWhen (Collection pre) { 198 Cve.errLog.debug(""); 199 if (pre!=null){ 200 Element newWhen=new Element("When"); 201 Iterator itPre=pre.iterator(); 202 while (itPre.hasNext()){ 203 ElementAlphabet preEle=(ElementAlphabet)itPre.next(); 204 Element itemW=new Element ("Item"); 205 itemW.addAttribute("typeName",preEle.getName()); 206 207 210 Element parameterW=new Element ("Parameter"); 211 parameterW.addAttribute("name",preEle.getNameId()); 212 itemW.addContent(parameterW); 213 214 System.out.println(" @@@@WippogSent : writeWhen : Elemento: " + preEle.getName()); 216 if (preEle.getAttributeInAnt() != null) { 217 System.out.println(" @@@@WippogSent : writeWhen : Num parametri: "+ preEle.getAttributeInAnt().size()); 218 219 Iterator itAttrAnt = preEle.getAttributeInAnt().iterator(); 220 while (itAttrAnt.hasNext()) { 221 222 String appoPar = (String )itAttrAnt.next(); 223 224 if (appoPar.equals(preEle.getNameId())==false) { 226 227 Element parameterWI = new Element("Parameter"); 228 parameterWI.addAttribute("name",appoPar); 229 itemW.addContent(parameterWI); 231 } 232 } 233 } 234 newWhen.addContent(itemW); 235 } 236 currentTra.addContent(newWhen); 237 } 238 } 239 240 248 protected void writeIf (Collection pre,Collection condition) { 249 Cve.errLog.debug(""); 250 Element newIf=new Element("If"); 252 Iterator itPre=pre.iterator(); 253 while (itPre.hasNext()) { 254 ElementAlphabet preEle=(ElementAlphabet)itPre.next(); 255 Element exp=new Element ("Expression"); 256 Element var=new Element ("Var"); 257 var.addAttribute("name","lista"); 258 Element binary=new Element ("BinaryOp"); 259 binary.addAttribute("name","isIn"); 260 Element varId=new Element ("Var"); 261 varId.addAttribute("name",preEle.getNameId()); 262 binary.addContent(varId); 263 exp.addContent(var); 264 exp.addContent(binary); 265 newIf.addContent(exp); 266 } 267 if (condition!=null) { 269 Iterator itCond=condition.iterator(); 270 while (itCond.hasNext()){ 271 Element cond=(Element)itCond.next(); 272 newIf.addContent(cond); 273 } 274 } 275 currentTra.addContent(newIf); 276 } 277 278 284 protected void writeIfQuery(String idElement) { 285 Cve.errLog.debug(""); 286 Element newIf=new Element("If"); 287 Element exp=new Element ("Expression"); 288 Element var=new Element ("Var"); 289 var.addAttribute("name","idInstance"); 290 Element binary=new Element ("BinaryOp"); 291 binary.addAttribute("name","eq"); 292 Element varId=new Element ("Var"); 293 varId.addAttribute("name",idElement); 294 binary.addContent(varId); 295 exp.addContent(var); 296 exp.addContent(binary); 297 newIf.addContent(exp); 298 currentTra.addContent(newIf); 299 } 300 301 302 311 protected void writeProduce (Collection post,Collection pre,boolean free) { 312 Cve.errLog.debug(""); 313 if (post!=null){ 314 Element newPost=new Element("Produce"); 315 Iterator itPost=post.iterator(); 316 while (itPost.hasNext()) { 317 ElementAlphabet postEle=(ElementAlphabet)itPost.next(); 318 Element itemP=new Element ("Item"); 319 String nameElePost=postEle.getName(); 320 itemP.addAttribute("typeName",nameElePost); 321 if (!free) { 322 Iterator itPre=pre.iterator(); 324 while (itPre.hasNext()){ 325 ElementAlphabet preEle=(ElementAlphabet)itPre.next(); 326 String nameElePre=preEle.getName(); 327 if (nameElePre.equals(nameElePost)) { 328 Collection attributesAnt=(Collection)preEle.getAttributeInAnt(); 329 if (attributesAnt!=null){ 330 Iterator itAttrAnt=attributesAnt.iterator(); 332 while (itAttrAnt.hasNext()){ 333 String nameAttrAnt=(String )itAttrAnt.next(); 334 Element parameterP=new Element ("Parameter"); 335 parameterP.addAttribute("name",nameAttrAnt); 336 itemP.addContent(parameterP); 337 } 338 } 339 } 340 } Collection attributesCons=(Collection)postEle.getAttributeInCons(); 342 if (attributesCons!=null) { 343 Iterator itAttrCons=attributesCons.iterator(); 344 while (itAttrCons.hasNext()){ 345 String nameAttrCons=(String )itAttrCons.next(); 346 347 boolean esiste = false; 349 Iterator itPre2=pre.iterator(); 351 while (itPre2.hasNext()){ 352 ElementAlphabet preEle2=(ElementAlphabet)itPre2.next(); 353 String nameElePre2=preEle2.getName(); 354 if (nameElePre2.equals(nameElePost)) { 355 Collection attributesAnt=(Collection)preEle2.getAttributeInAnt(); 356 if (attributesAnt!=null){ 357 Iterator itAttrAnt=attributesAnt.iterator(); 359 while (itAttrAnt.hasNext()){ 360 String nameAttrAnt=(String )itAttrAnt.next(); 361 if (nameAttrCons.equals(nameAttrAnt)){ 362 esiste = true; 363 } 364 } 365 } 366 367 if (esiste == false){ 368 Element parameterP=new Element ("Parameter"); 369 parameterP.addAttribute("name",nameAttrCons); 370 itemP.addContent(parameterP); 371 } 372 } } } } } 378 newPost.addContent(itemP); 380 } 381 382 if (!free) { 383 Element itemSel=new Element("Item"); 385 itemSel.addAttribute("typeName","listaSel"); 386 Element parameterS1=new Element("Parameter"); 387 parameterS1.addAttribute("name","lista"); 388 itemSel.addContent(parameterS1); 389 newPost.addContent(itemSel); 390 } 391 currentTra.addContent(newPost); 392 } 393 } 394 395 401 protected void writeProduceQuery (Collection post) { 402 Cve.errLog.debug(""); 403 if (post!=null) { 404 Element newPost=new Element("Produce"); 405 Iterator itPost=post.iterator(); 406 while (itPost.hasNext()) { 407 ElementAlphabet postEle=(ElementAlphabet)itPost.next(); 408 Element itemP=new Element ("Item"); 409 String nameElePost=postEle.getName(); 410 itemP.addAttribute("typeName",postEle.getName()); 411 Element parameterW=new Element ("Parameter"); 412 parameterW.addAttribute("name",postEle.getNameId()); 413 itemP.addContent(parameterW); 414 newPost.addContent(itemP); 415 currentTra.addContent(newPost); 416 } 417 } 418 } 419 420 421 427 protected void writeOut (ElementRel eleRel,Collection out,boolean free) { 428 Cve.errLog.debug(""); 429 Element newOut=null; 431 if ((free)&&(out!=null)) { 432 newOut=new Element("Output"); 433 Iterator itOut=out.iterator(); 434 while (itOut.hasNext()) { 435 ElementAlphabet outEle=(ElementAlphabet)itOut.next(); 436 Element itemO=new Element ("Item"); 437 itemO.addAttribute("typeName",outEle.getName()); 438 newOut.addContent(itemO); 439 } 440 } else { newOut=new Element("Output"); 442 Element itemO=new Element ("Item"); 443 itemO.addAttribute("typeName","conditionRule"); 445 newOut.addContent(itemO); 446 } 447 if (newOut!=null) 448 currentTra.addContent(newOut); 449 } 450 451 458 protected void writeGet (ElementRel rel,Collection get,boolean free) { 459 Cve.errLog.debug(""); 460 Element newGet=null; 462 if ((free)&&(get!=null)){ 463 newGet=new Element("Get"); 464 Element itemA1=new Element("Item"); 465 itemA1.addAttribute("typeName","activity"); 466 Element parameterA1=new Element("Parameter"); 467 parameterA1.addAttribute("name","generate"); 468 Iterator itGet=get.iterator(); 469 while (itGet.hasNext()) { 470 ElementAlphabet getEle=(ElementAlphabet)itGet.next(); 471 parameterA1.addAttribute("value",getEle.getName()); 472 } 473 itemA1.addContent(parameterA1); 474 newGet.addContent(itemA1); 475 } else { newGet=new Element("Get"); 477 Element itemA1=new Element("Item"); 478 itemA1.addAttribute("typeName","activity"); 479 Element parameterA1=new Element("Parameter"); 480 parameterA1.addAttribute("name","generate"); 481 itemA1.addContent(parameterA1); 482 Element itemO=new Element ("Parameter"); 483 itemO.addAttribute("name","idType"); 484 itemO.addAttribute("value",rel.getName()); 485 itemA1.addContent(itemO); 486 newGet.addContent(itemA1); 487 Element itemSel=new Element("Item"); 489 itemSel.addAttribute("typeName","listaSel"); 490 Element parameterS1=new Element("Parameter"); 491 parameterS1.addAttribute("name","lista"); 492 itemSel.addContent(parameterS1); 493 newGet.addContent(itemSel); 494 } 495 if (newGet!=null) 496 currentTra.addContent(newGet); 497 } 498 499 504 protected void writeGetQuery (String idType){ 505 Cve.errLog.debug(""); 506 Element newGet=new Element("Get"); 507 Element itemA1=new Element("Item"); 508 itemA1.addAttribute("typeName","activity"); 509 Element parameterA1=new Element("Parameter"); 510 parameterA1.addAttribute("name","query"); 511 parameterA1.addAttribute("value",idType); 512 Element parameterA2=new Element("Parameter"); 513 parameterA2.addAttribute("name","idInstance"); 514 itemA1.addContent(parameterA1); 515 itemA1.addContent(parameterA2); 516 newGet.addContent(itemA1); 517 currentTra.addContent(newGet); 518 } 519 520 524 protected void writeProcess (Collection pro){ 525 Cve.errLog.debug(""); 526 Element newPro=new Element("Processes"); 527 Iterator itProcess=pro.iterator(); 529 while (itProcess.hasNext()){ 530 Element process=(Element)itProcess.next(); 531 newPro.addContent(process); 532 } 557 currentTra.addContent(newPro); 558 } 559 560 } 561 562 | Popular Tags |