1 4 5 package cve.esecutori.components.automatonB; 6 7 import java.io.File ; 8 import java.io.IOException ; 9 import java.io.*; 10 import java.util.*; 11 12 import org.jdom.*; 13 import org.jdom.Document; 14 import org.jdom.Element; 15 import org.jdom.JDOMException; 16 import org.jdom.input.SAXBuilder; 17 import org.jdom.output.XMLOutputter; 18 19 import cve.esecutori.components.specificaLV.*; 20 import cve.staticLayout.*; 21 import cve.util.ConfigurationRead; 22 23 import org.apache.log4j.Logger; 24 25 44 public class AutControlB implements IAutomaControllo { 45 46 private WippogAut wip; 47 48 51 private HashSet memberRel=new HashSet(); 52 53 56 private HashSet stateSet=new HashSet(); 57 58 61 private HashSet userAction=new HashSet(); 62 63 66 private HashSet activityValue=new HashSet(); 67 private HashSet activityName=new HashSet(); 68 69 72 private Vector activityValueA=new Vector(); 73 private Vector activityNameA=new Vector(); 74 75 78 private HashSet processValue=new HashSet(); 79 private HashSet processName=new HashSet(); 80 81 84 private HashSet idGet=new HashSet(); 85 86 89 private HashSet produceValue=new HashSet(); 90 private HashSet produceName=new HashSet(); 91 private HashSet scheletroName=new HashSet(); 93 private Vector scheletroValue=new Vector(); 94 95 97 98 109 public String createCA(String fileA,File fileLang,ISpecifica spe)throws java.io.IOException { 110 Cve.errLog.debug(""); 111 String nameFileLanguage=fileLang.getName(); 113 String filePath=fileLang.getParent(); 114 String fileS=filePath+"/"+"Sent_"+nameFileLanguage; 115 initialize(fileA,fileS,spe); 116 CollectionTransaction colleTransactionAut=new CollectionTransaction(); 117 userAction.add("select"); 119 userAction.add("deselect"); 120 create_kernel_bin(spe, colleTransactionAut); 122 free_creation(spe); 123 create_traps(colleTransactionAut,spe); 124 String fileAut=wip.saveFileAut(fileLang); 126 return fileAut; 127 } 128 129 130 133 public static void main(String [] args) throws java.io.IOException { 134 Cve.errLog.debug(""); 135 String fileS="filesent"; 139 String fileA=ConfigurationRead.getCveRoot()+"/VisualLanguage/cveAlf1.xml"; 141 String fileR=ConfigurationRead.getCveRoot()+"/VisualLanguage/cveRules1.xml"; 142 Specifica spe=new Specifica(fileR,fileA); 143 AutControlB msf=new AutControlB(); 145 } 148 149 151 152 155 private void initialize(String fileA,String fileS,ISpecifica spe) { 156 Cve.errLog.debug(""); 157 wip= new WippogAut(spe); 158 wip.configAut (fileA,fileS); 159 } 161 162 169 private void free_creation(ISpecifica spe) { 170 Cve.errLog.debug(""); 171 Collection free=spe.getFreeCreation(); 172 System.out.println("<<<<<<<< DENTRO FREE CREATION >>>>>>>free-->"+free.size()); 173 clearList(); 175 if ((free!=null)&&(stateSet!=null)) { 176 Iterator its=stateSet.iterator(); 178 while (its.hasNext()){ 179 String stato=(String )its.next(); 180 Iterator itf=free.iterator(); 182 while(itf.hasNext()){ String freeEle=(String )itf.next(); 184 activityValueA.add(freeEle); 185 activityNameA.add("Generate"); 186 idGet.add(freeEle); 187 wip.transitionA(stato,stato,"TriggerF",activityValueA, activityNameA,idGet); clearList(); 189 196 } 197 } 198 } 199 } 200 201 207 private void create_traps(CollectionTransaction colleTransactionAut,ISpecifica spe) { 208 Cve.errLog.debug(""); 209 System.out.println("<<<<<<<< DENTRO CREATE TRAPS >>>>>>>"); 210 Vector free=new Vector( spe.getNonRelation() ); 211 System.out.println("<<<<<<<< DENTRO CREATE TRAPS >>>>>>>free-->"+free.size()); 212 Iterator its=stateSet.iterator(); 213 while (its.hasNext()){ String state=(String )its.next(); 215 System.out.println(" DENTRO STATE:"+state); 216 Iterator user=userAction.iterator(); 217 while (user.hasNext()) { String action=(String )user.next(); 219 System.out.println(" DENTRO USER ACTION:"+action); 220 Iterator itEle=free.iterator(); 221 while(itEle.hasNext()) { ElementNonRel eleNonRel=(ElementNonRel)itEle.next(); 223 String element=((Element)eleNonRel.getElementXml()).getAttributeValue("name"); 224 System.out.println(" DENTRO ELEMENT:"+element); 225 if (!colleTransactionAut.exist(state,action,element)) { 227 System.out.println("Trans ERRORE -> State:"+state+" Action:"+action+" Element:"+element); 228 wip.transitionError(state,element,action); 229 230 } 231 } 232 } 233 } 234 } 235 236 245 private void create_kernel_bin(ISpecifica spe,CollectionTransaction colleStateGet)throws java.io.IOException { 246 247 Cve.errLog.debug(""); 250 HashMap Ks=new HashMap(),Kt=new HashMap(),Kst=new HashMap(); 251 252 HashSet listName=new HashSet(), KsTot=new HashSet(),KtTot=new HashSet(),KstTot=new HashSet(); 255 Vector KRel=new Vector(spe.getRelation()); 256 Vector KNonRel=new Vector( spe.getNonRelation() ); 257 ViewLog.writeInLog(" ****************************"+"\n"); 258 ViewLog.writeInLog(" Sono in create kernel il numero di relazioni e' "+KRel.size()+"\n"); 259 ViewLog.writeInLog(" Sono in create kernel il numero di non relazioni e' "+KNonRel.size()+"\n"); 260 for (int i=0; i<KRel.size(); i++) { 261 ElementRel eleRel=(ElementRel)KRel.get(i); String nameRel=((Element)eleRel.getElementXml()).getAttributeValue("name"); 263 ViewLog.writeInLog(" Relazione in esame "+nameRel+"\n"); 264 for (int j=0; j<KNonRel.size(); j++) { 265 ElementNonRel eleNonRel=(ElementNonRel)KNonRel.get(j); 266 String nameNonRel=((Element)eleNonRel.getElementXml()).getAttributeValue("name"); 267 ViewLog.writeInLog(" ->Elemento non relazione esaminato "+nameNonRel+"\n"); 268 listName=(HashSet)spe.getTarget(eleRel,eleNonRel); 269 if ((listName!=null)&&(listName.size()>0)) { 270 Kt.put(nameNonRel,listName); 271 memberRel.addAll(listName); 272 KtTot.addAll(listName); ViewLog.writeInLog(" KtTot e' lunga "+ listName.size()+ "\n"); 274 ViewLog.writeInLog(" Kt per la coppia esaminata <relazione, elemento> e' lunga "+ listName.size()+":"); 275 Iterator it=listName.iterator(); 276 while (it.hasNext()) { 277 String app=(String )it.next(); 278 ViewLog.writeInLog(" "+ app+","); 279 } 280 ViewLog.writeInLog("\n"); 281 } 282 listName=(HashSet)spe.getSource(eleRel,eleNonRel); 283 if ((listName!=null)&&(listName.size()>0)){ 284 Ks.put(nameNonRel,listName); 285 memberRel.addAll(listName); 286 KsTot.addAll(listName); ViewLog.writeInLog(" KtTot e' lunga "+ listName.size()+ "\n"); 288 ViewLog.writeInLog(" Ks per la coppia esaminata <relazione, elemento> e' lunga** "+ listName.size()+":"); 289 Iterator it=listName.iterator(); 290 while (it.hasNext()){ 291 String app=(String )it.next(); 292 ViewLog.writeInLog(" "+ app+","); 293 } 294 ViewLog.writeInLog("\n"); 295 } 296 listName=(HashSet)spe.getSourceTarget(eleRel, eleNonRel); 297 if ((listName!=null)&&(listName.size()>0)) { 298 Kst.put(nameNonRel,listName); 299 memberRel.addAll(listName); 300 KstTot.addAll(listName); ViewLog.writeInLog(" kst listName e' lungo** "+listName.size()+":"); 302 Iterator it=listName.iterator(); 303 while (it.hasNext()){ 304 String app=(String )it.next(); 305 ViewLog.writeInLog(" **elemento ks** "+ app+"\n"); 306 } 307 ViewLog.writeInLog("\n"); 308 } 309 } 310 createControlBin(nameRel,memberRel,Ks,Kt,Kst, KsTot,KtTot,KstTot,colleStateGet); 313 ViewLog.writeInLog(" Fine creazione automa per relazione "+nameRel+"\n"); 314 if (memberRel!=null) 315 memberRel.clear(); 316 if (Kst!=null) 317 Kst.clear(); 318 if (Ks!=null) 319 Ks.clear(); 320 if (Kt!=null) 321 Kt.clear(); 322 if (KsTot!=null) 323 KsTot.clear(); 324 if (KtTot!=null) 325 KtTot.clear(); 326 if (KstTot!=null) 327 KstTot.clear(); 328 } 329 } 330 331 335 private void createControlBin(String nameEleRel,Set memberRel,Map Ksou,Map Ktar,Map Ksoutar,Set KsTot,Set KtTot,Set KstTot, CollectionTransaction colleStateGet){ 336 HashSet Ktot=new HashSet(); 337 String input, cond; 338 340 Cve.errLog.debug(""); 341 if (memberRel!=null) 342 Ktot=new HashSet(memberRel); 343 ViewLog.writeInLog(" INIZIO CREATECONTROLBIN"+"\n"); 344 ViewLog.writeInLog(" la relazione e' "+nameEleRel+"\n"); 345 ViewLog.writeInLog(" Member e' lungo "+memberRel.size()+"\n"); 346 if (memberRel!=null){ 347 Iterator it=memberRel.iterator(); while (it.hasNext()){ 349 String nameEle=(String )it.next(); 350 ViewLog.writeInLog(" membro "+nameEle+"\n"); 351 } 352 } 353 ViewLog.writeInLog(" KsTot "+"\n"); 354 if ((KsTot!=null)){ 355 Iterator itst=KsTot.iterator(); while (itst.hasNext()){ 357 String nameEle=(String )itst.next(); 358 ViewLog.writeInLog(" source tot relazione corrente "+nameEle+"\n"); 359 } 360 } 361 ViewLog.writeInLog(" KtTot "+"\n"); 362 if ((KtTot!=null)){ 363 Iterator itst=KtTot.iterator(); while (itst.hasNext()){ 365 String nameEle=(String )itst.next(); 366 ViewLog.writeInLog(" target tot della relazione corrente "+nameEle+"\n"); 367 } 368 } 369 ViewLog.writeInLog(" KstTot "+"\n"); 370 if ((KstTot!=null)){ 371 Iterator itst=KstTot.iterator(); while (itst.hasNext()){ 373 String nameEle=(String )itst.next(); 374 ViewLog.writeInLog(" Kst tot della relazione corrente "+nameEle+"\n"); 375 } 376 } 377 ViewLog.writeInLog(" *** automa creato correttamante (CREATECONTROLBIN) "+"\n"); 378 379 stateSet.add("Start"); 383 Iterator itKtot=Ktot.iterator(); 384 System.out.println("\n\n"); 385 System.out.println("@ PRIMA CICLO WHILE rel->"+nameEleRel+" @@@@@"+"\n"); 386 while (itKtot.hasNext()) { 387 System.out.println("@@ dentro CICLO WHILE "); 388 String nameEleX=(String )itKtot.next(); 389 String nameEleXSel=nameEleX+"_Sel"; 390 String nameEleY=""; 391 String namePairXYSel=""; 392 System.out.println("@@ EleX->"+nameEleX); 393 stateSet.add(nameEleXSel); clearList(); 395 idGet.add(nameEleX); 396 System.out.println("@@ 1)Start->"+nameEleXSel); 397 if (colleStateGet.insertIfNotExist("Start","select",nameEleX)) 399 wip.transitionA("Start",nameEleXSel,"select",activityValueA,activityNameA,idGet); clearList(); 401 idGet.add(nameEleX); 402 System.out.println("@@ 2)"+nameEleXSel+"->Start"); 403 if (colleStateGet.insertIfNotExist(nameEleXSel,"deselect",nameEleX)) 404 wip.transitionA(nameEleXSel,"Start","deselect",activityValueA,activityNameA,idGet); if ((KstTot.contains(nameEleX))||(KsTot.contains(nameEleX)) ){ System.out.println("@@ dentro if se e' sorgente->"+nameEleX ); 407 HashSet Kstt= new HashSet(); 408 if (Ktar.get(nameEleX)!=null){ Kstt.addAll((Set)Ktar.get(nameEleX)); 410 System.out.println("@@ Kstt vale (Ktar)->"+Kstt.toString() ); 411 } 412 if (Ksoutar.get(nameEleX)!=null){ Kstt.addAll((Set)Ksoutar.get(nameEleX)); 414 System.out.println("@@ Kstt vale (Ksoutar)->"+Kstt.toString() ); 415 } 416 if (Kstt!=null) { 417 System.out.println("@@ Inizo a scorrere target->"); 418 Iterator itKstt=Kstt.iterator(); 419 while (itKstt.hasNext()) { 420 nameEleY=(String )itKstt.next(); 421 System.out.println("@@@ target->"+nameEleY); 422 String nameEleYSel=nameEleY+"_Sel"; 423 namePairXYSel=nameEleX+nameEleY+"_Sel"; 425 stateSet.add(namePairXYSel); 426 clearList(); 427 activityNameA.add("eButton"); 428 activityValueA.add(nameEleRel); 429 idGet.add(nameEleY); 430 System.out.println("@@@ 3)"+nameEleXSel+"->"+namePairXYSel); 431 if (colleStateGet.insertIfNotExist(nameEleXSel,"select",nameEleY)) 432 wip.transitionA(nameEleXSel,namePairXYSel,"select",activityValueA,activityNameA,idGet); clearList(); 434 activityNameA.add("dButton"); 435 activityValueA.add(nameEleRel); 436 idGet.add(nameEleY); 437 System.out.println("@@@ 4)"+namePairXYSel+"->"+nameEleXSel); 438 if (colleStateGet.insertIfNotExist(namePairXYSel,"deselect",nameEleY)) 439 wip.transitionA(namePairXYSel,nameEleXSel,"deselect",activityValueA,activityNameA,idGet); clearList(); 441 activityValueA.add(nameEleRel); 442 activityNameA.add("generate"); 443 idGet.add(nameEleRel); 444 System.out.println("@@@ 5)"+namePairXYSel+"->"+namePairXYSel+ "Trigger"); 445 if (colleStateGet.insertIfNotExist(namePairXYSel,"triggerR",nameEleRel)) 446 wip.transitionA(namePairXYSel,namePairXYSel,"triggerR",activityValueA, activityNameA,idGet); activityValueA.add(nameEleRel); 448 activityNameA.add("generate"); 449 idGet.add(nameEleRel); 450 452 clearList(); 454 activityValueA.add(nameEleRel); 455 activityNameA.add("dButton"); 456 clearList(); 457 459 clearList(); 461 activityValueA.add(nameEleRel); 462 activityNameA.add("dButton"); if (colleStateGet.insertIfNotExist(namePairXYSel,"conditionT","")) 464 wip.transitionA(namePairXYSel,namePairXYSel,"conditionT",activityValueA,activityNameA,idGet); clearList(); 467 activityValueA.add(nameEleRel); 468 activityNameA.add("dButton"); 469 idGet.add(nameEleX); 470 if (colleStateGet.insertIfNotExist(namePairXYSel,"deselect",nameEleX)) 471 wip.transitionA(namePairXYSel,nameEleYSel,"deselect",activityValueA,activityNameA,idGet); clearList(); 473 } } } 507 514 521 529 534 } 540 } 541 542 545 private void clearList() { 546 Cve.errLog.debug(""); 547 activityValue.clear(); 548 activityName.clear(); 549 activityValueA.clear(); 550 activityNameA.clear(); 551 processValue.clear(); 552 processName.clear(); 553 produceValue.clear(); 554 produceName.clear(); 555 idGet.clear(); 556 scheletroName.clear(); 557 scheletroValue.clear(); 558 } 559 } 560 561 564 class StateGet { 565 String state=""; 566 String userAction=""; 567 String element=""; 568 569 StateGet(String state,String userAction,String element){ 570 Cve.errLog.debug(""); 571 this.state=state; 572 this.userAction=userAction; 573 this.element=element; 574 } 575 } 576 577 580 class CollectionTransaction { 581 Vector colStateGet=null; 582 583 CollectionTransaction() { 584 Cve.errLog.debug(""); 585 colStateGet=new Vector(); 586 } 587 588 592 boolean insertIfNotExist(String state, String userAction,String element) { 593 int i=0; 594 StateGet curr=null,stateGet; 595 boolean trovato=false; 596 597 Cve.errLog.debug(""); 598 stateGet=new StateGet(state,userAction,element); 599 while ( (i<colStateGet.size())&&(!trovato) ){ 600 curr=(StateGet)colStateGet.get(i); 601 if ( (curr.state.equals(stateGet.state))&& 602 (curr.userAction.equals(stateGet.userAction))&& 603 (curr.element.equals(stateGet.element)) ) { 604 trovato=true; 605 System.out.println("----- Stato -->"+stateGet.state+" userAction-->"+stateGet.userAction+" ele-->"+stateGet.element); 606 } 607 i++; 608 } 609 if (trovato) 610 return false; 611 System.out.println("----- insertIfNotExist insert State:"+state+ " UserAction:"+userAction+" element:"+element); 613 colStateGet.add(stateGet); 614 return true; 615 } 616 617 618 621 boolean exist(String state, String userAction,String element) { 622 int i=0; 623 StateGet curr=null; 624 boolean trovato=false; 625 626 Cve.errLog.debug(""); 627 while ( (i<colStateGet.size())&&(!trovato) ){ 628 curr=(StateGet)colStateGet.get(i); 629 if ( (curr.state.equals(state))&& 630 (curr.userAction.equals(userAction))&& 631 (curr.element.equals(element)) ){ 632 trovato=true; 633 System.out.println("TROVATO ----- Stato -->"+state+" userAction-->"+userAction+" ele-->"+element); 634 } 635 i++; 636 } 637 return trovato; 638 } 639 } 640 | Popular Tags |