1 6 package cve.esecutori.components.automatonB; 7 8 import java.io.File ; 9 import java.io.IOException ; 10 import java.io.*; 11 import java.util.*; 12 13 import org.jdom.*; 14 import org.jdom.input.SAXBuilder; 15 import org.jdom.output.XMLOutputter; 16 17 import cve.staticLayout.*; 18 import cve.esecutori.components.specificaLV.*; 19 20 import org.apache.log4j.Logger; 21 22 32 public class WippogAut extends WriteWippogSpe { 33 34 37 private int contTrans=1; 38 private Element root; 39 private ISpecifica specifica; 40 private Collection free; 41 private Collection relations; 42 private Vector scheletro; 43 private Collection elementAlf; 44 private String notazioneStato="_Sel"; 45 46 50 WippogAut(ISpecifica spe) { 51 specifica=spe; 52 free=spe.getFreeCreation(); 53 relations=spe.getRelation(); 54 elementAlf=spe.getElementAlf(); 55 57 root=new Element("WippogRules"); 58 document=new Document(root); 59 } 60 61 63 64 65 69 void configAut (String fileAlf,String fileSent){ 70 Cve.errLog.debug(""); 71 Element alphabet=new Element("Alphabet"); 73 74 File alf = new File (fileAlf); 76 String alfName = alf.getName(); 77 alphabet.addAttribute("name",alfName); 79 80 Element sentence=new Element("Sentence"); 81 82 File sent = new File (fileSent); 84 String sentName = sent.getName(); 85 86 sentence.addAttribute("name",sentName); 88 89 root.addContent(alphabet); 90 root.addContent(sentence); 91 wippogDefines(); 92 wippogImport(); 93 wippogExport(); 94 } 95 96 99 protected void wippogDefines(){ 100 Cve.errLog.debug(""); 101 Element newDefines=new Element("Defines"); 103 newDefines.addAttribute("description","Definizione dei tipi"); 104 Element itemS=new Element ("ItemDefinition"); 106 itemS.addAttribute("typeName","state"); 107 Element parameterS=new Element ("ParameterDefinition"); 108 parameterS.addAttribute("name","current"); 109 parameterS.addAttribute("type","Stringa"); 110 itemS.addContent(parameterS); 111 newDefines.addContent(itemS); 112 125 Element itemL=new Element ("ItemDefinition"); 127 itemL.addAttribute("typeName","listaSel"); 128 Element parameter=new Element ("ParameterDefinition"); 129 parameter.addAttribute("name","lista"); 130 parameter.addAttribute("type","Listaid"); 131 itemL.addContent(parameter); 132 newDefines.addContent(itemL); 133 Element activityI=new Element("ItemDefinition"); 135 activityI.addAttribute("typeName","activity"); 136 Element parameter1=new Element ("ParameterDefinition"); 137 parameter1.addAttribute("name","eButton"); 138 parameter1.addAttribute("type","Listastringa"); 139 Element parameter2=new Element ("ParameterDefinition"); 140 parameter2.addAttribute("name","dButton"); 141 parameter2.addAttribute("type","Listastringa"); 142 Element parameter3=new Element ("ParameterDefinition"); 143 parameter3.addAttribute("name","idType"); 144 parameter3.addAttribute("type","Stringa"); 145 Element parameter4=new Element ("ParameterDefinition"); 146 parameter4.addAttribute("name","query"); 147 parameter4.addAttribute("type","Listastringa"); 148 Element parameter5=new Element ("ParameterDefinition"); 149 parameter5.addAttribute("name","generate"); 150 parameter5.addAttribute("type","Listastringa"); 151 Element parameter6=new Element ("ParameterDefinition"); 152 parameter6.addAttribute("name","idInstance"); 153 parameter6.addAttribute("type","Identificatore"); 154 activityI.addContent(parameter1); 155 activityI.addContent(parameter2); 156 activityI.addContent(parameter3); 157 activityI.addContent(parameter4); 158 activityI.addContent(parameter5); 159 activityI.addContent(parameter6); 160 newDefines.addContent(activityI); 161 Element itemIn=new Element ("ItemDefinition"); 163 itemIn.addAttribute("typeName","init"); 164 newDefines.addContent(itemIn); 165 Element itemCond=new Element ("ItemDefinition"); 167 itemCond.addAttribute("typeName","conditionRule"); 168 Element parameterC=new Element ("ParameterDefinition"); 169 parameterC.addAttribute("name","condition"); 170 parameterC.addAttribute("type","Booleano"); 171 itemCond.addContent(parameterC); 172 newDefines.addContent(itemCond); 173 Element itemA=new Element ("ItemDefinition"); 175 itemA.addAttribute("typeName","action"); 176 Element parameter1A=new Element ("ParameterDefinition"); 177 parameter1A.addAttribute("name","select"); 178 parameter1A.addAttribute("type","Stringa"); 179 Element parameter2A=new Element ("ParameterDefinition"); 180 parameter2A.addAttribute("name","deselect"); 181 parameter2A.addAttribute("type","Stringa"); 182 Element parameter3A=new Element ("ParameterDefinition"); 183 parameter3A.addAttribute("name","trigger"); 184 parameter3A.addAttribute("type","Listastringa"); 185 Element parameter4A=new Element ("ParameterDefinition"); 186 parameter4A.addAttribute("name","triggerR"); 187 parameter4A.addAttribute("type","Listastringa"); 188 Element parameter5A=new Element ("ParameterDefinition"); 189 parameter5A.addAttribute("name","query"); 190 parameter5A.addAttribute("type","Listastringa"); 191 Element parameter6A=new Element ("ParameterDefinition"); 192 parameter6A.addAttribute("name","modify"); 193 parameter6A.addAttribute("type","Listastringa"); 194 Element parameter7A=new Element ("ParameterDefinition"); 195 parameter7A.addAttribute("name","idInstance"); 196 parameter7A.addAttribute("type","Identificatore"); 197 Element parameter8A=new Element ("ParameterDefinition"); 198 parameter8A.addAttribute("name","idType"); 199 parameter8A.addAttribute("type","Stringa"); 200 itemA.addContent(parameter1A); 201 itemA.addContent(parameter2A); 202 itemA.addContent(parameter3A); 203 itemA.addContent(parameter4A); 204 itemA.addContent(parameter5A); 205 itemA.addContent(parameter6A); 206 itemA.addContent(parameter7A); 207 itemA.addContent(parameter8A); 208 newDefines.addContent(itemA); 209 root.addContent(newDefines); 210 } 211 212 215 protected void wippogExport(){ 216 Cve.errLog.debug(""); 217 Element export=new Element("Exports"); 218 Element itemE=new Element("Item"); 219 itemE.addAttribute("typeName","activity"); 220 Element itemLS=new Element("Item"); 221 itemLS.addAttribute("typeName","listaSel"); 222 export.addContent(itemE); 223 export.addContent(itemLS); 224 root.addContent(export); 225 } 226 227 230 protected void wippogImport(){ 231 Cve.errLog.debug(""); 232 Element importW=new Element("Imports"); 233 Element itemIW=new Element("Item"); 234 itemIW.addAttribute("typeName","conditionRule"); 235 importW.addContent(itemIW); 236 root.addContent(importW); 237 } 238 239 243 protected void transInitA (){ 244 Cve.errLog.debug(""); 245 Element newTransition=new Element("Transition"); 246 newTransition.addAttribute("id","start"); 247 newTransition.addAttribute("description","Transizione di start"); 248 249 Element newProduce=new Element("Produce"); 251 Element itemS=new Element ("Item"); 253 itemS.addAttribute("typeName","state"); 254 Element parameterS=new Element ("Parameter"); 255 parameterS.addAttribute("name","current"); 256 parameterS.addAttribute("value","Start"); 257 itemS.addContent(parameterS); 258 newProduce.addContent(itemS); 259 Element itemL=new Element ("Item"); 261 itemL.addAttribute("typeName","listaSel"); 262 newProduce.addContent(itemL); 263 Element activityI=new Element("Item"); 265 activityI.addAttribute("typeName","activity"); 266 String disable=""; 267 int count=0; 268 Iterator itRel=relations.iterator(); 269 while ( itRel.hasNext() ){ 270 String name=((ElementAlphabet)itRel.next()).getName(); 271 if (count==0) 272 disable=disable+name; 273 else 274 disable=disable+","+name; 275 count++; 276 } 277 Element parameterAC=new Element ("Parameter"); 278 parameterAC.addAttribute("name","dButton"); 279 parameterAC.addAttribute("value",disable); 280 activityI.addContent(parameterAC); 281 newProduce.addContent(activityI); 282 Element action=new Element("Item"); 284 action.addAttribute("typeName","action"); 285 newProduce.addContent(action); 286 newTransition.addContent(newProduce); 287 288 Element newGet=new Element("Get"); 290 Element ite=new Element("Item"); 291 ite.addAttribute("typeName","init"); 292 newGet.addContent(ite); 293 newTransition.addContent(newGet); 294 295 root.addContent(newTransition); 296 } 297 298 307 protected void transitionA (String stateSource, String stateTarget,String input,Collection activityValue,Collection activityName, Collection get){ 308 Cve.errLog.debug(""); 309 Element newTransition=new Element("Transition"); 310 boolean activityB=false; String appA="",tipo="",app="",nomeTipo=""; 312 if (contTrans==1) 314 transInitA (); 315 contTrans++; 316 if ((get!=null)&&(get.size()>0)) { 318 Iterator itG=get.iterator(); 319 tipo=(String )itG.next(); 320 } if ((stateSource.equals(stateTarget))){ 322 app= " "+stateSource+ " Trigger " + tipo+" " ; 323 } else{ 324 app= " "+stateSource+ " TO " + stateTarget+" " ; 325 } 326 newTransition.addAttribute("id","id"+contTrans); 327 newTransition.addAttribute("description",app); 328 329 Element newWhen=new Element("When"); 331 if (!(stateSource.equals(stateTarget))){ 333 Element itemW=new Element ("Item"); 334 itemW.addAttribute("typeName","state"); 335 Element parameterW=new Element ("Parameter"); 337 parameterW.addAttribute("name","current"); 338 parameterW.addAttribute("value",stateSource); 339 itemW.addContent(parameterW); 340 newWhen.addContent(itemW); 341 Element itemWA=new Element ("Item"); 342 itemWA.addAttribute("typeName","activity"); 343 newWhen.addContent(itemWA); 344 } 345 if (input.equals("conditionT")){ 347 Element itemW=new Element ("Item"); 348 itemW.addAttribute("typeName","state"); 349 Element parW=new Element ("Parameter"); 351 parW.addAttribute("name","current"); 352 parW.addAttribute("value",stateSource); 353 itemW.addContent(parW); 354 Element itemW1=new Element ("Item"); 355 itemW1.addAttribute("typeName","activity"); 356 newWhen.addContent(itemW); 357 newWhen.addContent(itemW1); 358 } 359 Element itemW1=new Element ("Item"); 361 itemW1.addAttribute("typeName","listaSel"); 362 Element parameterLS=new Element ("Parameter"); 363 parameterLS.addAttribute("name","lista"); 364 itemW1.addContent(parameterLS); 365 newWhen.addContent(itemW1); 366 367 newTransition.addContent(newWhen); 368 369 Element newProcess=new Element("Processes"); 371 if (!(stateSource.equals(stateTarget)) ) { 372 if (input.equals("select")||input.equals("deselect")){ 376 Element assL=new Element("Assignment"); 377 Element var1L=new Element("Var"); 378 var1L.addAttribute("name","lista1"); 379 Element exp=new Element("Expression"); 380 Element var2L=new Element("Var"); 381 var2L.addAttribute("name","lista"); 382 Element op=new Element("BinaryOp"); 383 if (input.equals("deselect")) 384 op.addAttribute("name","remove"); 385 else 386 op.addAttribute("name","insert"); 387 Element var3L=new Element("Var"); 388 var3L.addAttribute("name","idInstance"); 389 op.addContent(var3L); 390 exp.addContent(var2L); 391 exp.addContent(op); 392 assL.addContent(var1L); 393 assL.addContent(exp); 394 newProcess.addContent(assL); 395 } } 397 if (input.equals("conditionT")){ 398 Element assC=new Element("Expression"); 399 Element varC=new Element("Var"); 400 varC.addAttribute("name","lista"); 401 Element opC=new Element("UnaryOp"); 402 opC.addAttribute("name","removeAll"); 403 assC.addContent(varC); 404 assC.addContent(opC); 405 newProcess.addContent(assC); 406 } 407 newTransition.addContent(newProcess); 409 Element newProduce=new Element("Produce"); 412 if (!(stateSource.equals(stateTarget) )) { 414 Element itemS=new Element ("Item"); 415 itemS.addAttribute("typeName","state"); 416 Element attState=new Element("Parameter"); 417 attState.addAttribute("name","current"); 418 attState.addAttribute("value",stateTarget); 419 itemS.addContent(attState); 420 newProduce.addContent(itemS); 421 Element itemL=new Element ("Item"); 422 itemL.addAttribute("typeName","listaSel"); 423 Element attLista=new Element("Parameter"); 424 attLista.addAttribute("name","lista"); 425 attLista.addAttribute("alias","lista1"); 426 itemL.addContent(attLista); 427 newProduce.addContent(itemL); 428 Element itemA=new Element ("Item"); 430 itemA.addAttribute("typeName","activity"); 431 if ((activityName!=null)&& (activityName.size()>0)) { 432 activityB=true; 433 Iterator itName=activityName.iterator(); 434 Iterator itValue=activityValue.iterator(); 435 while ( (itName.hasNext()) &&(itValue.hasNext()) ){ 436 String name=(String )itName.next(); 437 String value=(String )itValue.next(); 438 if ( (name.equals("generate"))||(name.equals("eButton")) ) { 439 Element var3A=new Element("Parameter"); 440 var3A.addAttribute("name","eButton"); 441 var3A.addAttribute("value",value); 442 itemA.addContent(var3A); 443 } 444 if (name.equals("dButton")) { 445 Element var3A=new Element("Parameter"); 446 var3A.addAttribute("name","dButton"); 447 var3A.addAttribute("value",value); 448 itemA.addContent(var3A); 449 } 450 } 451 } 452 newProduce.addContent(itemA); 453 }else { Element itemL=new Element ("Item"); 455 itemL.addAttribute("typeName","listaSel"); 456 Element attLista=new Element("Parameter"); 457 attLista.addAttribute("name","lista"); 458 itemL.addContent(attLista); 459 newProduce.addContent(itemL); 460 } if (input.equals("conditionT")){ 462 System.out.println(" ###### sono in conditionT"); 463 Iterator itName=activityName.iterator(); 464 Iterator itValue=activityValue.iterator(); 465 while ( (itName.hasNext()) &&(itValue.hasNext()) ){ 466 String name=(String )itName.next(); 467 String value=(String )itValue.next(); 468 Element itemD=new Element ("Item"); 469 itemD.addAttribute("typeName","activity"); 470 Element var3D=new Element("Parameter"); 471 var3D.addAttribute("name","dButton"); 472 var3D.addAttribute("value",value); 473 itemD.addContent(var3D); Element itemS=new Element ("Item"); 475 itemS.addAttribute("typeName","state"); 476 Element attState=new Element("Parameter"); 477 attState.addAttribute("name","current"); 478 attState.addAttribute("value","Start"); 479 itemS.addContent(attState); 480 newProduce.addContent(itemS); 481 newProduce.addContent(itemD); 482 } 483 } 484 newTransition.addContent(newProduce); 485 486 if ((activityName!=null)&&(activityValue!=null)) { 488 Iterator itName=activityName.iterator(); 489 Iterator itValue=activityValue.iterator(); 490 Element newOut=null; 491 while ( (itName.hasNext()) &&(itValue.hasNext())) { 492 String name=(String )itName.next(); 493 String value=(String )itValue.next(); 494 if (name.equals("generate")){ 495 newOut=new Element("Output"); 496 Element itemO=new Element("Item"); 497 itemO.addAttribute("typeName","activity"); 498 Element varOL=new Element("Parameter"); 499 varOL.addAttribute("name","idType"); 500 varOL.addAttribute("value",value); 501 itemO.addContent(varOL); 502 newOut.addContent(itemO); 503 Element itemL=new Element("Item"); 506 itemL.addAttribute("typeName","listaSel"); 507 Element varL=new Element("Parameter"); 508 varL.addAttribute("name","lista"); 509 itemL.addContent(varL); 510 newOut.addContent(itemL); 511 } 512 } 513 if (newOut!=null) 514 newTransition.addContent(newOut); 515 } 516 517 518 if (get!=null) { 520 Element newGet=new Element("Get"); 521 if ((input.equals("triggerR"))||(input.equals("triggerF")) ){ 522 Element itemT=new Element("Item"); 523 itemT.addAttribute("typeName","activity"); 524 Element itemPar=new Element("Parameter"); 525 itemPar.addAttribute("name","idType"); 526 Iterator itGet=get.iterator(); 527 itemPar.addAttribute("value",(String )itGet.next()); 528 itemT.addContent(itemPar); 529 newGet.addContent(itemT); 530 } 531 if (input.equals("conditionT")){ 532 Element itemT=new Element("Item"); 533 Iterator itGet=get.iterator(); 534 itemT.addAttribute("typeName","conditionRule"); 535 newGet.addContent(itemT); 536 } 537 if (input.equals("conditionF")){ 538 Element itemT=new Element("Item"); 539 Iterator itGet=get.iterator(); 540 itemT.addAttribute("typeName","conditionRule"); 541 newGet.addContent(itemT); 542 } 543 if ((input.equals("select"))||(input.equals("deselect")) ) { 544 Element itemA1=new Element("Item"); 545 itemA1.addAttribute("typeName","action"); 546 Element parameterA1=new Element("Parameter"); 547 parameterA1.addAttribute("name",input); 548 parameterA1.addAttribute("value","true"); 549 Element parameterA11=new Element("Parameter"); 550 if (input.equals("select")){ 551 parameterA11.addAttribute("name","deselect"); 552 parameterA11.addAttribute("value","false"); 553 } 554 if (input.equals("deselect")) { 555 parameterA11.addAttribute("name","select"); 556 parameterA11.addAttribute("value","false"); 557 } 558 itemA1.addContent(parameterA1); 559 itemA1.addContent(parameterA11); 560 Element parameterA2=new Element("Parameter"); 561 parameterA2.addAttribute("name","idInstance"); 562 itemA1.addContent(parameterA2); 563 Element parameterA3=new Element("Parameter"); 564 parameterA3.addAttribute("name","idType"); 565 if (get!=null && get.size()>0) { 566 Iterator itGet=get.iterator(); 567 while (itGet.hasNext()) { 568 nomeTipo=(String )itGet.next(); 569 parameterA3.addAttribute("value",nomeTipo); 570 } 571 } 572 itemA1.addContent(parameterA3); 573 newGet.addContent(itemA1); 574 } 575 592 newTransition.addContent(newGet); 593 } 594 596 root.addContent(newTransition); 597 } 598 599 600 607 protected void transitionError (String stateSource, String element,String input) { 608 Cve.errLog.debug(""); 609 Element newTransition=new Element("Transition"); 610 boolean activityB=false; String stateTarget=stateSource+element+"E"; 612 String app=""; 613 614 contTrans++; 615 app="Error transaction:"+stateSource+" to "+ stateTarget; 616 newTransition.addAttribute("id","idError"+contTrans); 617 newTransition.addAttribute("description",app); 618 619 Element newWhen=new Element("When"); 621 Element itemW=new Element ("Item"); 622 itemW.addAttribute("typeName","state"); 623 Element parameterW=new Element ("Parameter"); 625 parameterW.addAttribute("name","current"); 626 parameterW.addAttribute("value",stateSource); 627 itemW.addContent(parameterW); 628 newWhen.addContent(itemW); 629 newTransition.addContent(newWhen); 630 631 Element newProduce=new Element("Produce"); 633 Element itemS=new Element ("Item"); 634 itemS.addAttribute("typeName","state"); 635 Element attState=new Element("Parameter"); 636 attState.addAttribute("name","current"); 637 attState.addAttribute("value",stateTarget); 638 itemS.addContent(attState); 639 newProduce.addContent(itemS); 640 newTransition.addContent(newProduce); 641 642 Element newGet=new Element("Get"); 644 645 if ((input.equals("select"))||(input.equals("deselect")) ) { 646 Element itemA1=new Element("Item"); 647 itemA1.addAttribute("typeName","action"); 648 Element parameterA1=new Element("Parameter"); 649 parameterA1.addAttribute("name",input); 650 parameterA1.addAttribute("value","true"); 651 Element parameterA11=new Element("Parameter"); 652 if (input.equals("select")) { 653 parameterA11.addAttribute("name","deselect"); 654 parameterA11.addAttribute("value","false"); 655 } 656 if (input.equals("deselect")) { 657 parameterA11.addAttribute("name","select"); 658 parameterA11.addAttribute("value","false"); 659 } 660 itemA1.addContent(parameterA1); 661 itemA1.addContent(parameterA11); 662 Element parameterA2=new Element("Parameter"); 663 parameterA2.addAttribute("name","idInstance"); 664 itemA1.addContent(parameterA2); 665 Element parameterA3=new Element("Parameter"); 666 parameterA3.addAttribute("name","idType"); 667 parameterA3.addAttribute("value",element); 668 itemA1.addContent(parameterA3); 669 newGet.addContent(itemA1); 670 } 671 newTransition.addContent(newGet); 672 673 675 root.addContent(newTransition); 676 transitionErrorToNormal(stateTarget,stateSource); 678 } 679 680 683 protected void transitionErrorToNormal (String stateSource, String stateTarget) { 684 Element newTransition=new Element("Transition"); 685 String app="Error transaction:"+stateSource+" to "+ stateTarget; 686 contTrans++; 687 newTransition.addAttribute("id","idError"+contTrans); 688 newTransition.addAttribute("description",app); 689 690 Element newWhen=new Element("When"); 692 Element itemW=new Element ("Item"); 693 itemW.addAttribute("typeName","state"); 694 Element parameterW=new Element ("Parameter"); 696 parameterW.addAttribute("name","current"); 697 parameterW.addAttribute("value",stateSource); 698 itemW.addContent(parameterW); 699 newWhen.addContent(itemW); 700 newTransition.addContent(newWhen); 701 702 Element newProduce=new Element("Produce"); 704 Element itemS=new Element ("Item"); 705 itemS.addAttribute("typeName","state"); 706 Element attState=new Element("Parameter"); 707 attState.addAttribute("name","current"); 708 attState.addAttribute("value",stateTarget); 709 itemS.addContent(attState); 710 newProduce.addContent(itemS); 711 newTransition.addContent(newProduce); 712 713 root.addContent(newTransition); 714 } 715 716 717 722 private String trovaId(String name) { 723 Cve.errLog.debug(""); 724 String campo=" ",campo1=" "; 725 Map scheletro=specifica.getScheletro(); 726 int pos=name.indexOf(notazioneStato); 727 Collection attr=(Collection)scheletro.get(name); 732 Iterator itAttr=attr.iterator(); 733 boolean trovatoId=true; 734 while ((itAttr.hasNext())&&(trovatoId) ){ 735 campo=(String )itAttr.next(); 736 if (itAttr.hasNext()) 737 campo1=(String )itAttr.next(); 738 if (campo1.equals("Identificatore")) 739 trovatoId=false; 740 } 741 return campo; 742 } 743 } 744 745 | Popular Tags |