1 package cve.esecutori; 2 3 import cve.osservatori.servizioOACesecSemantic.*; 4 import cve.esecutori.servizioEACesecSemantic.*; 5 6 7 import cve.core.elementEEL.*; 8 import cve.osservatori.*; 9 import cve.esecutori.components.specificaSem.*; 10 import cve.esecutori.components.specificaLV.*; 11 import wippog.*; import wippog.tipidato.*; import wippog.eccezioni.*; 14 import wippog.activator.*; 15 import wippog.event.*; 16 17 import diagrammaticLanguage.*; 18 import interactionSemantic.*; 19 20 import cve.staticLayout.*; 21 import cve.util.ConfigurationRead; 22 import cve.util.ElementXML; 23 24 import java.awt.*; 25 import java.util.*; 26 import javax.swing.*; 27 import javax.swing.tree.*; 28 29 import java.io.File ; 30 import java.io.IOException ; 31 32 import org.jdom.*; 33 import org.jdom.input.SAXBuilder; 34 import org.jdom.output.XMLOutputter; 35 36 import org.apache.log4j.Logger; 37 38 public class EACesecSemantic extends Esecutore implements IEsecutionSentenceSemantic 39 { 40 43 private Vector sentence; 44 45 48 private HashMap rappresentations; 49 50 53 private ConfigElements configElements; 54 55 58 private Vector disabButton,enableButton; 59 60 63 private String path=ConfigurationRead.getCveRoot(); 64 65 68 private String nameId; 69 70 73 Vector listaSel; 74 75 78 private WippogMachine aut; 79 80 83 private WippogMachine sent; 84 85 88 private WippogMachine semexec; 89 90 private ResourcePool resource; 91 92 private IResource queryItem; 93 94 97 private WippogMachine sem; 98 99 private String idWMSent, idWMSem; 100 private String fileOutSem; 101 102 105 private String stateError=""; 106 107 110 private int contestoAutoma; 111 112 115 private int contestoSentenza; 116 117 120 private int contestoEsecuzione; 121 122 125 private int orientation = TOKEN; 126 final private static int TOKEN=1; 127 final private static int HOLDER=2; 128 private String pathFileInit; 129 130 133 private int fase = CREATION; 134 final private static int CREATION=1; 135 final private static int INITIALIZE=2; 136 final private static int EXECUTION=3; 137 final private static int INIT=0; 138 final private static int SELEZIONE=1; 139 final private static int TRIGGER_REL=2; 140 final private static int TRIGGER_NON_REL=3; 141 final private static int QUERY=4; 142 final private static int RELATION_CREATED=5; 143 final private static int AFTER_REL_CREATED= 6; 144 final private static int EXEC=1; 145 final private static int EXEC_STEP=2; 146 final private static int EXEC_PAUSE=3; 147 148 private String sincronizzatoreSent,sincronizzatoreAut; 151 private String sincronizzatoreSem, sincronizzatoreSem1 ,sincronizzatoreSemInit; 152 private String sincronizzatoreEx, sincronizzatoreSem0, sincronizzatoreSem01, sincronizzatoreSemIP, sincronizzatoreSemUpTC, sincronizzatoreSemUpTP; 153 private String idIstanza; 154 private int numEle=0; 155 private Collection lista=new Vector(); 156 157 private String fileSent = null; 159 private String fileLanguage = null; 160 private String fileAlf = null; 161 private String fileSem = null; 162 private String fileAssSem = null; 163 private String fileAssFile = null; 164 165 private Document document; 166 private Document docAssSem, docSem ,docSemOUT; 167 private Element treeSemOUT = null;; 168 169 private DefaultMutableTreeNode treeSinRules,treeSemRules, treeAlf, treeLang; 170 private DefaultMutableTreeNode treeSpeSem,treeAssSem, treeFileAssFile; 171 172 private Associations associations; 173 private Vector internal; 174 private IActivator activator; 175 private String s_activator; 176 177 private int num_internal, conta_init; 178 179 private String translationClass = new String (""); 180 181 182 183 186 public EACesecSemantic() 187 { 188 Cve.errLog.debug(""); 189 sentence = new Vector(); 190 listaSel= new Vector(); 191 rappresentations=new HashMap(); 192 sincronizzatoreSent=new String (); 193 sincronizzatoreAut=new String (); 194 sincronizzatoreSem=new String (); 195 sincronizzatoreSem1=new String (); 196 sincronizzatoreSemInit=new String (); 197 sincronizzatoreEx=new String (); 198 sincronizzatoreSem0=new String (); 199 sincronizzatoreSem01=new String (); 200 sincronizzatoreSemIP=new String (); 201 sincronizzatoreSemUpTC=new String (); 202 sincronizzatoreSemUpTP=new String (); 203 204 associations = new Associations(); 205 configElements = new ConfigElements(); 206 207 activator = new SeqActivator(); 209 s_activator = new String ("SeqActivator"); 210 } 211 212 217 public DefaultMutableTreeNode getModelAlf(){ 218 Cve.errLog.debug(""); 219 return treeAlf; 220 } 221 222 226 public DefaultMutableTreeNode getModelLang(){ 227 Cve.errLog.debug(""); 228 return treeLang; 229 } 230 231 235 public DefaultMutableTreeNode getModelSintRules(){ 236 Cve.errLog.debug(""); 237 return treeSinRules; 238 } 239 240 244 public DefaultMutableTreeNode getModelSemRules(){ 245 Cve.errLog.debug(""); 246 return treeSemRules; 247 } 248 249 253 public DefaultMutableTreeNode getModelAssSem(){ 254 Cve.errLog.debug(""); 255 return treeAssSem; 256 } 257 258 262 public DefaultMutableTreeNode getModelAssFile(){ 263 Cve.errLog.debug(""); 264 return treeFileAssFile; 265 } 266 267 275 public void setAssociation(String fileAss) { 276 Cve.errLog.debug(""); 277 ViewLog.writeInLog(" #E Eseguito setAssociation: "+fileAss+"\n"); 278 279 this.fileAssFile = fileAss; 280 ElementXML objSearch = new ElementXML(fileAssFile); 282 283 this.fileSent = objSearch.getParameter(objSearch.getRootDocument(),"SyntaxFile","nameFile",null,null); 285 this.fileSent = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "//" + this.fileSent; 286 ViewLog.writeInLog(" #E setAssociation: file Automa Sentenza = "+fileSent+"\n"); 287 System.out.println(" #E setAssociation: file Automa Sentenza = "+fileSent); 288 289 this.fileSem = objSearch.getParameter(objSearch.getRootDocument(),"SemanticFile","nameFile",null,null); 291 this.fileSem = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "//" + this.fileSem; 292 ViewLog.writeInLog(" #E setAssociation: file Automa Semantica = "+fileSem+"\n"); 293 System.out.println(" #E setAssociation: file Automa Semantica = "+fileSem); 294 295 this.fileAssSem = objSearch.getParameter(objSearch.getRootDocument(),"AssociationFile","nameFile",null,null); 297 this.fileAssSem = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "//" + this.fileAssSem; 298 299 this.translationClass = objSearch.getParameter(objSearch.getRootDocument(),"TranslationSemanticClass","nameFile",null,null); 301 ViewLog.writeInLog(" #E setAssociation: Translation Semantic Class = "+translationClass+"\n"); 302 System.out.println(" #E setAssociation: Translation Semantic Class = "+translationClass); 303 ViewLog.writeInLog(" #E setAssociation: file Associazione Regole = "+fileSem+"\n"); 304 System.out.println(" #E setAssociation: file Associazione Regole = "+fileSem); 305 306 this.fileLanguage = objSearch.getParameter(objSearch.getRootDocument(),"ControlFile","nameFile",null,null); 308 this.fileLanguage = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "//" + this.fileLanguage; 309 310 ViewLog.writeInLog(" #E setAssociation: file Automa Controllo = "+fileLanguage+"\n"); 311 System.out.println(" #E setAssociation: file Automa Controllo = "+fileLanguage); 312 313 ElementXML objSearch2 = new ElementXML(fileLanguage); 316 317 this.fileAlf = objSearch2.getParameter(objSearch2.getRootDocument(),"Alphabet","name",null,null); 319 this.fileAlf = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveVCARWRoot() + "//" + this.fileAlf; 320 321 ViewLog.writeInLog(" #E setAssociation: file Alfabeto = "+fileAlf+"\n"); 322 System.out.println(" #E setAssociation: file Alfabeto = "+fileAlf); 323 324 Vector attributiRap=new Vector(); 326 try { 327 Specifica spe=new Specifica(fileAlf); 328 rappresentations.clear(); 330 rappresentations.putAll(spe.getRappresentation()); 331 } catch (java.io.IOException e){ 332 ViewLog.writeInLog(" #E setAssociation: file alfabeto Errato "+fileAlf+"\n"); 333 } 334 SentenceEvent sentEv=new SentenceEvent(); 338 sentEv.setActionUser("language"); 339 sentEv.setRappresentations(rappresentations); 340 ObservableCve ob=getObservable(); 341 ob.setDate(sentEv); 342 343 345 ViewLog.writeInLog(" #E setAssociation: inizializzazione macchina WIPPOG AUTOMA DI CONTROLLO(abilitazioni,...)"+"\n"); 346 System.out.println(" #E setAssociation: inizializzazione macchina WIPPOG AUTOMA DI CONTROLLO(abilitazioni,...)"); 347 contestoAutoma = INIT; 349 initWippogAutoma(fileLanguage); 350 System.out.println("Dopo Inizializzazione e prima di init"); 351 aut.addItemGet("init"); 352 353 ViewLog.writeInLog(" #E setAssociation: inizializzazione macchina WIPPOG SENTENZA e sincronizzazione"+"\n"); 355 synchronized(lista) { 356 try { lista.wait();} 357 catch (InterruptedException e){ 358 Cve.errLog.error(e.toString()); 359 } 360 } 361 362 initWippogSentence(); 364 365 treeAlf = setFile(this.fileAlf, "ALPHABET"); 368 treeLang = setFile(this.fileLanguage,"CONTROL AUTOMATA"); 369 treeSinRules = setFile(this.fileSent, "SENTENCE RULES"); 370 treeSemRules = setFile(this.fileSem, "SEMANTIC RULES"); 371 treeAssSem = setFile(this.fileAssSem, "ASSOCIATION TREE"); 372 treeFileAssFile = setFile(this.fileAssFile, "ASSOCIATION FILE TREE"); 373 374 setModel(treeAlf, "setAlphabet" ,this.fileAlf); 376 setModel(treeLang, "setLanguage" ,this.fileLanguage); 377 setModel(treeSinRules, "setSintaxRules" ,this.fileSent); 378 setModel(treeSemRules, "setSemanticRules" ,this.fileSem); 379 setModel(treeAssSem, "setAssociationSemantic",this.fileAssSem); 380 setModel(treeFileAssFile,"setAssociationFile" ,this.fileAssFile); 381 382 associations.loadAssociations(this.fileSem,this.fileAssSem); 384 System.out.println(associations.toString()); 385 386 ViewLog.writeInLog(" #E setAssociation: inizializzazione macchina WIPPOG SEMANTICA e sincronizzazione"+"\n"); 388 System.out.println(" #E setAssociation: inizializzazione macchina WIPPOG SEMANTICA e sincronizzazione"); 389 390 setOrientation(this.orientation); 393 394 initWippogSemantica(fileSem); 395 396 idWMSent = sent.getId(); 399 fileOutSem = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeSemantic() + "//" + idWMSent + "_sem.xml"; 400 ViewLog.writeInLog(" #E setAssociation: file OUT Semantica temporaneo: " + fileOutSem+"\n"); 401 System.out.println(" #E setAssociation: file OUT Semantica temporaneo: " + fileOutSem); 402 403 } 405 406 407 411 public void clearAssociation(){ 412 413 Cve.errLog.debug(""); 414 ViewLog.writeInLog(" #E Eseguito clearAssociation"+"\n"); 415 System.out.println(" #E Eseguito clearAssociation"); 416 417 sentence.clear(); 419 rappresentations.clear(); 420 associations.clear(); 421 configElements.clear(); 422 423 ObservableCve ob=getObservable(); 424 SentenceEvent sentEv=new SentenceEvent(); 425 sentEv.setActionUser("clearLanguage"); 426 ob.setDate(sentEv); 427 428 this.fileAlf = null; 430 this.fileLanguage= null; 431 this.fileSent = null; 432 this.fileSem = null; 433 this.fileAssSem = null; 434 this.fileAssFile = null; 435 treeSemOUT = null; 436 437 SentenceEvent sentEv1=new SentenceEvent(); 439 sentEv1.setActionUser("delAll"); 440 ob.setDate(sentEv1); 441 442 } 443 444 448 public void saveSentence(){ 449 Cve.errLog.debug(""); 450 ViewLog.writeInLog(" #E Eseguito saveSentence"+"\n"); 451 452 454 CVESemanticFactory.createFile(sem,fileOutSem); 457 } 458 459 463 public Collection getSentence(){ 464 Cve.errLog.debug(""); 465 ViewLog.writeInLog(" #E Eseguito getSentence " + "\n"); 466 467 Vector sentenceClone=new Vector(); 468 Iterator itSent=sentence.iterator(); 469 while(itSent.hasNext()){ 470 ReferrableElement element=(ReferrableElement)itSent.next(); 471 ReferrableElement elementClone=(ReferrableElement)element.clone(); 472 sentenceClone.add(elementClone); 473 } 474 return sentenceClone; 475 } 476 477 486 public Collection inputTrigger(String idTipo) 487 { 488 Cve.errLog.debug(""); 489 ViewLog.writeInLog(" "+"\n"); 490 ViewLog.writeInLog(" #E Eseguito inputTrigger del tipo "+ idTipo + "\n"); 491 492 Representation rap=(Representation)rappresentations.get(idTipo); 494 String cp=rap.getAttribute("cp"); 496 cp=path+"/"+cp; 497 String activity; 499 if (rap.getAttribute("relation").equals("true")) { contestoAutoma=TRIGGER_REL; 501 contestoSentenza=TRIGGER_REL; 502 activity="activity(idType="+idTipo+")"; 506 System.out.println(" #E inputTrigger: Creazione di una Relazione: "+activity); 507 System.out.println(" #E inputTrigger: Sincronizzazione Automa di Controllo"); 508 aut.addItemGet(activity); 509 synchronized(sincronizzatoreAut) { 510 try { 511 sincronizzatoreAut.wait(); 513 } 515 catch (InterruptedException e){ 516 Cve.errLog.error(e.toString()); 517 } 518 } 519 520 System.out.println(" #E inputTrigger: Sincronizzazione Automa di Sentenza"); 521 synchronized(sincronizzatoreSent) { 522 try { sincronizzatoreSent.wait(); 524 } 526 catch (InterruptedException e){ 527 Cve.errLog.error(e.toString()); 528 } 529 } 530 531 } else { contestoAutoma=TRIGGER_NON_REL; 533 contestoSentenza=TRIGGER_NON_REL; 534 ViewLog.writeInLog(" #E inputTrigger: Selezionata una NON relazione: idTipo "+idTipo+"\n"); 535 activity="activity(generate="+idTipo+")"; 536 ViewLog.writeInLog(" #E inputTrigger: Creazione di una NON Relazione: "+activity+"\n"); 538 System.out.println(" #E inputTrigger: Creazione di una NON Relazione: "+activity); 539 sent.addItemGet(activity); 540 System.out.println(" #E inputTrigger: Sincronizzazione Automa di Controllo"); 542 synchronized(sincronizzatoreSent) { 543 try { 544 sincronizzatoreSent.wait(); 546 } 548 catch (InterruptedException e){ 549 Cve.errLog.error(e.toString()); 550 } 551 } 552 } 553 554 557 SentenceEvent sentEv=new SentenceEvent(); 559 sentEv.setActionUser("trigger"); 560 sentEv.setSentence(sentence); 561 ObservableCve ob=getObservable(); 562 ob.setDate(sentEv); 563 ViewLog.writeInLog(" #E inputTrigger: Fine creazione elemento"+"\n"); 564 System.out.println(" #E inputTrigger: Fine creazione elemento"); 565 return sentence; 566 } 567 568 574 public void inputSelected(String idTipo,String idIstanza, boolean select) 575 { 576 Cve.errLog.debug(""); 577 Representation rapre=(Representation)rappresentations.get(idTipo); 579 if (rapre.getAttribute("relation").equals("true") == false){ 580 581 ViewLog.writeInLog(" #E Eseguito inputSelected del tipo: "+ idTipo + " Istanza: " + idIstanza + " Select: " + select + "\n"); 586 System.out.println(" #E Eseguito inputSelected del tipo: "+ idTipo + " Istanza: " + idIstanza + " Select: " + select); 587 588 contestoAutoma=SELEZIONE; 589 String action=""; 590 if (select){ action="action(select=true;deselect=false;"+"idInstance="+idIstanza+";idType="+idTipo+")"; 594 ViewLog.writeInLog(" AZIONE:"+action+"\n"); 595 } 596 else { action="action(select=false;deselect=true;"+"idInstance="+idIstanza+";idType="+idTipo+")"; 600 ViewLog.writeInLog(" AZIONE:"+action+"\n"); 601 } 602 603 ViewLog.writeInLog(" #E inputSelected: AZIONE WIPPOG: "+action+"\n"); 604 System.out.println(" #E inputSelected: AZIONE WIPPOG: "+action); 605 606 aut.addItemGet(action); 607 synchronized(lista) { 609 try { 610 lista.wait(); 612 } 614 catch (InterruptedException e){ 615 Cve.errLog.error(e.toString()); 616 } 617 } 618 SentenceEvent sentEv=new SentenceEvent(); 619 sentEv.setActionUser("selected"); 620 sentEv.setSentence(sentence); 621 ObservableCve ob=getObservable(); 622 ob.setDate(sentEv); 623 } 625 } 626 627 632 public void inputQuery(String idTipo,String idIstanza){ 633 Cve.errLog.debug(""); 634 ViewLog.writeInLog(" #E Eseguito inputQuery tipo "+ idTipo + " idIstanza: " + idIstanza + "\n"); 635 System.out.println(" #E Eseguito inputQuery tipo "+ idTipo + " idIstanza: " + idIstanza); 636 637 String activity="activity(idInstance="+idIstanza+";"+"query="+idTipo+")"; 638 ViewLog.writeInLog(" #E inputQuery: ATTIVITA' WIPPOG: "+activity+"\n"); 641 System.out.println(" #E inputQuery: ATTIVITA' WIPPOG: "+activity); 642 contestoSentenza=QUERY; 643 sent.addItemGet(activity); 644 synchronized(sincronizzatoreSent) { 645 try { 646 sincronizzatoreSent.wait(); 648 } 650 catch (InterruptedException e){ 651 Cve.errLog.error(e.toString()); 652 } 653 } 654 655 System.out.println("Elemento Selezionato: " + queryItem.toString()); 656 SentenceEvent sentEv=new SentenceEvent(); 658 sentEv.setActionUser("query"); 659 sentEv.setSentence(sentence); 660 ObservableCve ob=getObservable(); 661 ob.setDate(sentEv); 662 } 663 664 669 public void setQueryItem(IResource item){ 670 Cve.errLog.debug(""); 671 this.queryItem = item; 672 } 673 674 679 public IResource getQueryItem(){ 680 Cve.errLog.debug(""); 681 return this.queryItem; 682 } 683 684 689 public void setStateError(String state){ 690 Cve.errLog.debug(""); 691 this.stateError = state; 692 } 693 694 699 public String getStateError(){ 700 Cve.errLog.debug(""); 701 return this.stateError; 702 } 703 704 709 public ConfigElement getConfigElement(String idIstanza){ 710 Cve.errLog.debug(""); 711 return configElements.getConfig(idIstanza); 712 } 713 714 719 public void inputModify(String id,String idIstanza){ 720 Cve.errLog.debug(""); 721 } 722 723 727 public void clearSentence(){ 728 Cve.errLog.debug(""); 729 ViewLog.writeInLog(" #E Eseguita Pulizia Sentenza (clearSentence) "+"\n"); 731 System.out.println(" #E Eseguita Pulizia Sentenza (clearSentence) "); 732 733 sentence.clear(); 734 configElements.clear(); 735 treeSemOUT = null; 736 737 initWippogSemantica(fileSem); 739 740 ObservableCve ob=getObservable(); 742 SentenceEvent sentEv=new SentenceEvent(); 743 sentEv.setActionUser("clearSentence"); 744 ob.setDate(sentEv); 745 746 } 747 748 751 public void rappresentationsClear(){ 752 Cve.errLog.debug(""); 753 ViewLog.writeInLog(" #E Eseguita Pulizia Rappresentazioni (rappresentationsClear) "+"\n"); 754 rappresentations.clear(); 755 } 756 757 760 public void sentenceClear(){ 761 Cve.errLog.debug(""); 762 ViewLog.writeInLog(" "+"\n"); 763 ViewLog.writeInLog(" #E Eseguita Pulizia Sentenza"+"\n"); 764 System.out.println(" #E Eseguita Pulizia Sentenza"); 765 sentence.clear(); 766 } 767 768 771 public HashMap getRappresentations(){ 772 Cve.errLog.debug(""); 773 ViewLog.writeInLog(" #E Eseguito Lettura Rappresentazioni (getRappresentations) "+"\n"); 774 System.out.println(" #E Eseguito Lettura Rappresentazioni (getRappresentations) "); 775 return rappresentations; 776 } 777 778 781 public Collection getDisableButton() { 782 Cve.errLog.debug(""); 783 ViewLog.writeInLog(" #E Eseguito Lettura Pulsanti disabilitati (getDisableButton) "+"\n"); 784 System.out.println(" #E Eseguito Lettura Pulsanti disabilitati (getDisableButton) "); 785 return disabButton; 786 } 787 788 791 public Collection getEnableButton() { 792 Cve.errLog.debug(""); 793 ViewLog.writeInLog(" #E Eseguito Lettura Pulsanti abilitati (getEnableButton) :"+enableButton.toString()+"\n"); 794 System.out.println(" #E Eseguito Lettura Pulsanti abilitati (getEnableButton) :"+enableButton.toString()+"\n"); 795 return enableButton; 796 } 797 798 799 800 806 public void setOrientation(int o){ 807 Cve.errLog.debug(""); 808 this.orientation = o; 809 ViewLog.writeInLog(" #E Eseguita Impostazione Orientamento Semantico: "+o+"\n"); 810 System.out.println(" #E Eseguita Impostazione Orientamento Semantico: "+o); 811 812 if (o==TOKEN){ 814 pathFileInit = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "//semantic//generate_token.xml"; 815 } 816 if (o==HOLDER){ 817 pathFileInit = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "//semantic//generate_holder.xml"; 818 } 819 CVESemanticFactory.createFileInit(pathFileInit,o); 820 821 } 822 823 828 public int getOrientation(){ 829 Cve.errLog.debug(""); 830 return this.orientation; 831 } 832 833 834 840 public void setFase(int fase_in){ 841 Cve.errLog.debug(""); 842 this.fase = fase_in; 843 System.out.println(" #E Eseguita Impostazione Fase Manipolazione: " + this.fase); 844 845 } 846 847 852 public int getFase(){ 853 Cve.errLog.debug(""); 854 System.out.println(" #E Eseguita lettura Fase Manipolazione: " + this.fase); 855 return this.fase ; 856 } 857 858 864 public void setActivator(String act){ 865 Cve.errLog.debug(""); 866 s_activator=act; 867 868 877 System.out.println(" #E Eseguita Impostazione Attivatore Semantico"); 878 879 } 880 881 886 public String getActivator(){ 887 Cve.errLog.debug(""); 888 System.out.println(" #E Eseguita lettura Attivatore Semantico "); 889 return this.s_activator ; 890 } 891 892 899 public void addInternalPool(String id, int num_token){ 900 Cve.errLog.debug(""); 901 System.out.println(" #E Eseguito Aggiornamento InternalPool: id: " + id + " Num.Token: " + num_token); 902 ConfigElement appo_config = configElements.getConfig(id); 904 appo_config.putParameter("num_token",Integer.toString(num_token)); 905 906 910 913 configElements.removeElement(id); 915 configElements.addElement(id,appo_config); 916 917 System.out.println(" #E Eseguito Aggiornamento Configurazioni: per id: " + id); 918 919 System.out.println("CONFIGURAZIONE ATTUALE ELEMENTI"); 921 System.out.println(configElements.toString()); 922 923 ReferrableElement holder=trovaDrawingDaId(id); 926 ComplexGraphicElement cge_holder = holder.getComplexGraphicElement(); 927 928 cge_holder.removeToken(); 930 931 VisToken tok=new VisToken(cge_holder.getX(),cge_holder.getY(),num_token); 932 cge_holder.addGraficElement(tok); 933 System.out.println(" #E Eseguito Aggiornamento CGE: per id: " + id + " Inserito Tokens: " + num_token); 934 935 internal = new Vector(); 939 Set setKey = (configElements.getAllConfig()).keySet(); 940 941 Iterator assIt = setKey.iterator(); 943 String key, appo_token; 944 ConfigElement appo_config1; 945 while (assIt.hasNext()){ 946 947 key = (String )assIt.next(); 949 appo_config1 = configElements.getConfig(key); 950 951 appo_token = appo_config1.getParameter("num_token"); 952 953 if (appo_token!=null){ 955 int i_token = Integer.valueOf(appo_token).intValue(); 957 if (i_token>0){ 958 959 for (int i=0;i<i_token;i++){ 961 internal.add(key); 962 } 963 } 964 } 965 } 966 967 968 971 CVESemanticFactory.addInternalPool(sem,internal); 973 975 setModel(convertElementNode(CVESemanticFactory.getTree(sem), "SEMANTIC SENTENCE"),"setSemantic" ,null); 977 978 979 SentenceEvent sentEv=new SentenceEvent(); 981 sentEv.setActionUser("trigger"); 982 sentEv.setSentence(sentence); 983 ObservableCve ob=getObservable(); 984 ob.setDate(sentEv); 985 986 synchronized( sincronizzatoreSem1 ) { 987 System.out.println("Fine AddInternalPool"); 988 sincronizzatoreSem1.notifyAll(); 989 } 990 } 991 992 993 1000 public void updateWeight(String id, int num_weight){ 1001 Cve.errLog.debug(""); 1002 System.out.println(" #E Eseguito Aggiornamento InternalWeight: id: " + id + " Num.Weight: " + num_weight); 1003 1004 ConfigElement appo_config = configElements.getConfig(id); 1007 appo_config.putParameter("weight",Integer.toString(num_weight)); 1008 1009 configElements.removeElement(id); 1011 configElements.addElement(id,appo_config); 1012 1013 System.out.println(" #E Eseguito Aggiornamento Configurazioni: per id: " + id + " Inserito Weight: " + num_weight); 1014 1015 System.out.println("CONFIGURAZIONE ATTUALE ELEMENTI"); 1017 System.out.println(configElements.toString()); 1018 1019 1023 ReferrableConnection re_labeled=(ReferrableConnection)trovaDrawingDaId(id); 1026 1027 1029 ComplexGraphicElement cge_labeled = re_labeled.getComplexGraphicElement(); 1030 1031 cge_labeled.removeLabel("weight"); 1034 1035 VisLabel label=new VisLabel("weight",Integer.toString(num_weight)); 1036 cge_labeled.addGraficElement(label); 1037 System.out.println(" #E Eseguito Aggiornamento CGE: per id: " + id + " Inserito Weight: " + num_weight); 1038 1039 re_labeled.setComplexGraphicElement(cge_labeled); 1041 1042 CVESemanticFactory.updateWeight(sem,id,num_weight); 1045 1046 setModel(convertElementNode(CVESemanticFactory.getTree(sem), "SEMANTIC SENTENCE"),"setSemantic" ,null); 1048 1049 SentenceEvent sentEv=new SentenceEvent(); 1051 sentEv.setActionUser("trigger"); 1052 sentEv.setSentence(sentence); 1053 ObservableCve ob=getObservable(); 1054 ob.setDate(sentEv); 1055 1056 } 1057 1058 1065 public void updateMaxToken(String id, int max_token){ 1066 System.out.println(" #E Eseguito updateMaxToken: id: " + id + " MaxToken: " + max_token); 1067 ConfigElement appo_config = configElements.getConfig(id); 1070 appo_config.putParameter("max_token",Integer.toString(max_token)); 1071 1072 configElements.removeElement(id); 1074 configElements.addElement(id,appo_config); 1075 1076 System.out.println(" #E Eseguito Aggiornamento Configurazioni: per id: " + id + " Inserito Max token: " + max_token); 1077 1078 System.out.println("CONFIGURAZIONE ATTUALE ELEMENTI"); 1080 System.out.println(configElements.toString()); 1081 1082 1086 ReferrableElement re_labeled=trovaDrawingDaId(id); 1089 1090 1092 ComplexGraphicElement cge_labeled = re_labeled.getComplexGraphicElement(); 1093 1094 cge_labeled.removeLabel("max token"); 1097 1098 VisLabel label=new VisLabel(cge_labeled.getX(),cge_labeled.getY(),"max token",Integer.toString(max_token)); 1099 cge_labeled.addGraficElement(label); 1100 System.out.println(" #E Eseguito Aggiornamento CGE: per id: " + id + " Inserito maxToken: " + max_token); 1101 1102 re_labeled.setComplexGraphicElement(cge_labeled); 1104 1105 1106 CVESemanticFactory.updateMaxToken(sem,id,max_token); 1108 1109 setModel(convertElementNode(CVESemanticFactory.getTree(sem), "SEMANTIC SENTENCE"),"setSemantic" ,null); 1111 1112 SentenceEvent sentEv=new SentenceEvent(); 1114 sentEv.setActionUser("trigger"); 1115 sentEv.setSentence(sentence); 1116 ObservableCve ob=getObservable(); 1117 ob.setDate(sentEv); 1118 1119 } 1120 1121 1122 1123 1127 public void startSent(){ 1128 1129 System.out.println(" #E Eseguito Avvio Semantica"); 1130 contestoEsecuzione = INIT; 1131 activator = null; 1132 semexec = null; 1133 1134 CVESemanticFactory.createFile(sem,fileOutSem); 1136 1137 initWippogSemExecution(fileOutSem); 1138 1139 } 1140 1141 1145 public void stepSent(){ 1146 System.out.println(" #E Esecuzione Semantica Passo Passo"); 1147 semexec.getActivator().trigger(); 1148 } 1149 1150 1154 public void stopSent(){ 1155 Cve.errLog.debug(""); 1156 System.out.println(" #E Arresto Esecuzione Semantica"); 1157 try{ 1158 semexec.stop(); 1159 semexec.clearResources(); 1160 } catch(WippogException e){ 1161 Cve.errLog.error(e.toString()); 1162 } 1163 1164 contestoEsecuzione = INIT; 1165 System.out.println("FINE ESECUZIONE"); 1166 SentenceEvent sentEv=new SentenceEvent(); 1168 sentEv.setActionUser("endSemantic"); 1169 sentEv.setSentence(sentence); 1170 ObservableCve ob=getObservable(); 1171 ob.setDate(sentEv); 1172 } 1173 1174 1176 1177 1185 private void setButtonState(Collection stateList,boolean enable){ 1186 Cve.errLog.debug(""); 1187 System.out.println(" #E setButtonState: Abilitazione: " + enable +" Elenco: "+ stateList.toString()); 1188 if (enable) 1189 this.enableButton=new Vector(stateList); 1190 else 1191 this.disabButton=new Vector(stateList); 1192 } 1193 1194 1198 private void addDrawing(ReferrableElement d) 1199 { 1200 Cve.errLog.debug(""); 1201 sentence.addElement(d); 1203 } 1205 1206 1207 1211 private void addAssociation(String idSint, Association ass) 1212 { 1213 Cve.errLog.debug(""); 1214 associations.addAss(idSint,ass); 1216 } 1218 1219 1220 1223 private boolean isInListaSel(String idIst){ 1224 Cve.errLog.debug(""); 1225 for (int i=0;i<listaSel.size();i++){ 1226 Object idIstListaO=listaSel.elementAt(i); 1227 String idIstLista=idIstListaO.toString(); 1228 if (idIst.equals(idIstLista)) 1230 return true; 1231 } 1232 return false; 1233 } 1234 1235 1239 private void initWippogAutoma(String fileAut){ 1240 Cve.errLog.debug(""); 1241 System.out.println(" #E Inizializzazione Listener WIPPOG AUTOMA da "+fileAut); 1242 try { 1243 aut=WippogFactory.load(fileAut,true); 1247 contestoAutoma = INIT; 1248 1249 aut.addWippogListener(new WippogAdapter() { 1251 1252 java.util.List items; 1254 WippogMachine wm; 1255 Collection rules; 1256 Iterator itRules; 1257 Transition t; 1258 1259 public void resourceProduced( WippogEvent event ) { 1261 Cve.errLog.debug(""); 1262 System.out.println(" #E <WippogAut>: Ascoltatore AUT resourceProduced"); 1263 1264 items=event.getResouces(); 1266 wm = event.getSource(); 1267 try{ 1268 wm.run(); 1269 } catch (WippogException e){ 1270 Cve.errLog.error(e.toString()); 1271 } 1272 1273 System.out.println(" #E <WippogAut>: Ascoltatore AUT resourceProduced: Passo eseguito"); 1274 } 1275 1276 public void stepExecuted( StepEvent event ) { 1278 Cve.errLog.debug(""); 1279 System.out.println(" #E <WippogAut>: Ascoltatore AUT stepExecuted: Passo eseguito"); 1280 Iterator itItems; 1281 IResource item; 1282 1283 Thread.yield(); 1285 switch (contestoAutoma) { 1287 case INIT: 1288 ViewLog.writeInLog(" #E <WippogAut>: INIZIALIZZAZIONE:abilitazione pulsanti"+ "\n"); 1289 System.out.println(" #E <WippogAut>: INIZIALIZZAZIONE:abilitazione pulsanti"); 1290 1291 itItems=items.iterator(); 1292 while (itItems.hasNext()){ 1293 item=(IResource)itItems.next(); 1294 String nameItem=item.getTypeName(); 1295 if (nameItem.equals("activity")){ 1297 Collection dButton=(Collection)item.getAttribute("dButton"); 1298 Iterator itbut=dButton.iterator(); 1299 setButtonState(dButton,false); 1300 SentenceEvent sentEv=new SentenceEvent(); 1301 sentEv.setActionUser("deselectButton"); 1302 ObservableCve ob=getObservable(); 1303 ob.setDate(sentEv); 1304 } 1305 } 1306 synchronized( lista ) { 1307 System.out.println("Rilascio Lista da INIT"); 1308 lista.notifyAll(); 1309 } 1310 break; 1311 case SELEZIONE: 1312 ViewLog.writeInLog(" #E <WippogAut>: Azione SELECT-DESELECT"+ "\n"); 1313 System.out.println(" #E <WippogAut>: Azione SELECT-DESELECT"); 1314 1315 itItems=items.iterator(); 1316 while (itItems.hasNext()){ 1317 item=(IResource)itItems.next(); 1318 String nameItem=item.getTypeName(); 1319 1320 if (nameItem.equals("state")){ 1321 String stateValue = ((Stringa)item.getAttribute("current")).toString(); 1322 System.out.println(" #E <WippogAut>: Stato corrente: "+ stateValue); 1323 if (stateValue.endsWith("E")){ 1324 setStateError(stateValue); 1326 1327 }else{ 1328 setStateError(""); 1329 } 1330 } 1331 if (nameItem.equals("listaSel")){ 1332 listaSel.clear(); 1333 listaSel.addAll( (Collection)item.getAttribute("lista")); 1334 setSelectCp(listaSel); } 1336 if (nameItem.equals("activity")){ 1337 Collection eButton=(Collection)item.getAttribute("eButton"); 1338 Collection dButton=(Collection)item.getAttribute("dButton"); 1339 if (eButton.size()>0){ 1340 Iterator itbut=eButton.iterator(); 1341 System.out.println(" #E pulsanti da abilitare-->"+eButton.toString()); 1343 setButtonState(eButton,true); 1344 SentenceEvent sentEv=new SentenceEvent(); 1345 sentEv.setActionUser("selectButton"); 1346 ObservableCve ob=getObservable(); 1347 ob.setDate(sentEv); 1348 } 1349 if (dButton.size()>0){ 1350 Iterator itbut=dButton.iterator(); 1351 System.out.println(" #E pulsanti da disabilitare-->"+dButton.toString()); 1353 setButtonState(dButton,false); 1354 SentenceEvent sentEv=new SentenceEvent(); 1355 sentEv.setActionUser("deselectButton"); 1356 ObservableCve ob=getObservable(); 1357 ob.setDate(sentEv); 1358 } 1359 } 1360 } 1361 synchronized( lista ) { 1362 System.out.println(" <AUT>: Rilascio Lista da SELEZIONE"); 1363 lista.notifyAll(); 1364 } 1365 break; 1366 case TRIGGER_REL: 1367 ViewLog.writeInLog(" #E <WippogAut>: creazione RELAZIONE"+ "\n"); 1369 System.out.println(" #E <WippogAut>: creazione RELAZIONE"); 1370 1371 Iterator itItemsRel=items.iterator(); 1372 while (itItemsRel.hasNext()){ 1373 item=(IResource)itItemsRel.next(); 1374 String nameItem=item.getTypeName(); 1375 if (nameItem.equals("listaSel")){ 1377 ViewLog.writeInLog(" #E <WippogAut>: Creazione relazione in specifica sentenza"+"\n"); 1378 System.out.println(" #E <WippogAut>: Creazione relazione in specifica sentenza"); 1379 listaSel.clear(); 1380 listaSel.addAll( (Collection)item.getAttribute("lista")); 1382 } 1383 } 1384 synchronized( sincronizzatoreAut ) { 1385 System.out.println(" <AUT>: Rilascio da TRIGGER_REL"); 1386 sincronizzatoreAut.notifyAll(); 1387 } 1388 break; 1389 1390 case RELATION_CREATED: 1391 ViewLog.writeInLog(" #E <WippogAut>: RELAZIONE CREATA"+ "\n"); 1393 System.out.println(" #E <WippogAut>: RELAZIONE CREATA"); 1394 listaSel.clear(); 1395 setSelectCp(listaSel); 1396 Iterator itItemsCre=items.iterator(); 1397 while (itItemsCre.hasNext()){ 1398 item=(IResource)itItemsCre.next(); 1399 String nameItem=item.getTypeName(); 1400 if (nameItem.equals("activity")){ 1401 Collection dButton=(Collection)item.getAttribute("dButton"); 1402 if (dButton.size()>0){ 1403 Iterator itbut=dButton.iterator(); 1404 setButtonState(dButton,false); 1405 SentenceEvent sentEv=new SentenceEvent(); 1406 sentEv.setActionUser("deselectButton"); 1407 ObservableCve ob=getObservable(); 1408 ob.setDate(sentEv); 1409 } 1410 } 1411 } 1412 1413 contestoAutoma = AFTER_REL_CREATED; 1414 1415 synchronized( sincronizzatoreAut ) { 1416 System.out.println(" <AUT>: Rilascio da RELATION_CREATED"); 1417 sincronizzatoreAut.notifyAll(); 1418 } 1419 break; 1420 1421 } } 1423 } ); } catch (Exception e) { 1425 Cve.errLog.error(e.toString()); 1426 e.printStackTrace(); 1427 ViewLog.writeInLog(" #E# problemi in wippog automa"+"\n"); 1428 } 1429 } 1430 1431 1437 private void initWippogSentence(){ 1438 Cve.errLog.debug(""); 1439 System.out.println(" #E Inizializzazione Listener WIPPOG SENT da "+fileSent); 1440 try { 1441 sent=WippogFactory.load(fileSent,true); 1443 sent.addWippogListener(new WippogAdapter() { 1444 1445 java.util.List items; 1447 WippogMachine wm; 1448 Collection rules; 1449 Iterator itRules; 1450 Transition t; 1451 1452 public void exportsPerformed( WippogEvent event){ 1454 Cve.errLog.debug(""); 1455 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT exportsPerformed"); 1456 1457 Collection idOut = (Collection)event.getResouces(); 1460 if (idOut != null){ 1461 for( Iterator itOut=idOut.iterator(); itOut.hasNext(); ) { 1462 1463 IResource appo_resource = (IResource)itOut.next(); 1465 String appo_name = appo_resource.getTypeName(); 1466 1467 System.out.println("EXPORTS : elemento: " + appo_name); 1468 1469 if (appo_name.equals("conditionRule")){ 1472 contestoAutoma = RELATION_CREATED; 1473 } 1474 1475 } 1476 } 1477 1478 }; 1479 1480 1481 public void resourceProduced( WippogEvent event ) { 1483 Cve.errLog.debug(""); 1484 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT resourceProduced"); 1485 1486 items=event.getResouces(); 1488 wm = event.getSource(); 1489 1490 try{ 1491 wm.run(); 1492 } catch (WippogException e){ 1493 Cve.errLog.error(e.toString()); 1494 } 1495 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT resourceProduced: Passo eseguito"); 1496 } 1497 1498 public void stepExecuted( StepEvent event ) { 1500 Cve.errLog.debug(""); 1501 System.out.println(" #E <WippogSentenza>: Ascoltatore SENT stepExecuted: Passo eseguito"); 1502 rules = event.getRules(); 1503 itRules = rules.iterator();; 1504 t = (Transition)itRules.next(); 1506 Thread.yield(); 1508 Iterator itItems; 1510 1512 switch (contestoSentenza){ 1513 case TRIGGER_NON_REL: 1514 String idTipo=((IResource)items.get(0)).getTypeName(); 1521 Representation rapre=(Representation)rappresentations.get(idTipo); 1522 nameId=rapre.getAttribute("nameId"); 1523 IWippogObject idIstanzaW=((IResource)items.get(0)).getAttribute(nameId); 1524 1525 ViewLog.writeInLog(" #E <WippogSentenza>: Creazione Elemento NON RELAZIONE: idTipo: "+ idTipo + " nameId: " +nameId+" idIstanza: " +idIstanzaW+"\n"); 1526 System.out.println(" #E <WippogSentenza>: Creazione Elemento NON RELAZIONE: idTipo: "+ idTipo + " nameId: " +nameId+" idIstanza: " +idIstanzaW); 1527 1528 if (rapre.getAttribute("cpType").equals("icon")){ 1530 String cp=path+"/"+rapre.getAttribute("cp"); 1532 ComplexGraphicElement cge=new ComplexGraphicElement(); 1533 ImageIcon icon=new ImageIcon(cp); 1534 IconElement ge=new IconElement(icon); 1536 cge.addGraficElement(ge); 1537 1538 VisLabel lb_id = new VisLabel("id",idIstanzaW.toString()); 1541 cge.addGraficElement(lb_id); 1542 1543 diagrammaticLanguage.Entity ent=new diagrammaticLanguage.Entity("",idTipo,idIstanzaW.toString()); 1544 ent.setComplexGraphicElement(cge); 1545 addDrawing((ReferrableElement)ent); 1548 } 1549 if (rapre.getAttribute("cpType").equals("adj")){ 1550 try { 1551 Class newIstanzaVis=Class.forName(rapre.getAttribute("cp")); 1552 GraphicElement ge=(GraphicElement)newIstanzaVis.newInstance(); 1553 ge.setAttachZone(new BorderPlace(ge)); 1554 ComplexGraphicElement cge=new ComplexGraphicElement(); 1555 cge.addGraficElement(ge); 1556 1557 VisLabel lb_id = new VisLabel((int)ge.getX(), (int)ge.getY(), "id",idIstanzaW.toString()); 1559 cge.addGraficElement(lb_id); 1560 1561 if (rapre.getAttribute("max_token") != null){ 1563 VisLabel lb_mt = new VisLabel((int)ge.getX(), (int)ge.getY()+15, "max token","1"); 1565 cge.addGraficElement(lb_mt); 1566 } 1567 1568 diagrammaticLanguage.Entity ent=new diagrammaticLanguage.Entity("",idTipo,idIstanzaW.toString()); 1569 ent.setComplexGraphicElement(cge); 1570 1575 addDrawing((ReferrableElement)ent); 1576 1578 } catch(InstantiationException e){ 1579 Cve.errLog.error(e.toString()); 1580 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallita creazione istanza"+"\n"); 1581 } catch(IllegalAccessException e1){ 1582 Cve.errLog.error(e1.toString()); 1583 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallito accesso"+"\n"); 1584 } 1585 catch(ClassNotFoundException e2){ 1586 Cve.errLog.error(e2.toString()); 1587 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallita ricerca classe"+"\n"); 1588 } 1589 } 1590 1591 ConfigElement appo_config = new ConfigElement(); 1594 1595 if (rapre.getAttribute("holder").equals("true")){ 1597 appo_config.putParameter("num_token","0"); 1598 if (rapre.getAttribute("max_token") != null){ 1600 appo_config.putParameter("max_token","1"); 1601 } 1602 } 1603 configElements.addElement(idIstanzaW.toString(), appo_config); 1604 1605 break; 1608 case TRIGGER_REL: 1609 1610 ViewLog.writeInLog(" #E <WippogSentenza>: Creazione Elemento RELAZIONE"+"\n"); 1611 System.out.println(" #E <WippogSentenza>: Creazione Elemento RELAZIONE"); 1612 itItems=items.iterator(); 1619 while (itItems.hasNext()){ 1620 IResource item=(IResource)itItems.next(); 1621 idTipo=item.getTypeName(); 1622 rapre=(Representation)rappresentations.get(idTipo); 1624 if ((rapre!=null)&&(rapre.getAttribute("relation").equals("true"))) { nameId=rapre.getAttribute("nameId"); 1626 1628 idIstanzaW=item.getAttribute(nameId); 1630 ViewLog.writeInLog(" #E <WippogSentenza>: RELAZIONE idIstanza: "+idIstanzaW.toString()+" nameId: "+nameId +"\n"); 1631 System.out.println(" #E <WippogSentenza>: RELAZIONE idIstanza: "+idIstanzaW.toString()+" nameId: "+nameId); 1632 1633 if (rapre.getAttribute("cpType").equals("adj")){ 1636 try { 1637 ViewLog.writeInLog(" #E <WippogSentenza>: RELAZIONE Tipo: "+idTipo+" Rappresentazione: "+rapre.getAttribute("cp")+"\n"); 1639 System.out.println(" #E <WippogSentenza>: RELAZIONE Tipo: "+idTipo+" Rappresentazione: "+rapre.getAttribute("cp")); 1640 1641 ReferrableElement source = new ReferrableElement(); 1644 ReferrableElement target = new ReferrableElement(); 1645 1646 if (listaSel.size()>0){ 1648 String sourceId = listaSel.get(0).toString(); 1649 String targetId = listaSel.get(1).toString(); 1650 System.out.println(" #E <WippogSentenza>: TRIGGER_REL DA SEL: SOURCEID: "+sourceId+" TARGETID: "+targetId); 1651 1652 source=trovaDrawingDaId(sourceId); 1653 target=trovaDrawingDaId(targetId); 1654 1655 System.out.println(" #E <WippogSentenza>: TRIGGER_REL: Tipo SOURCE: "+source.getIdType()+" TARGET: "+target.getIdType()); 1656 1657 Touches touches=new Touches(source, target); 1658 1659 Class newIstanzaVis=Class.forName(rapre.getAttribute("cp")); 1661 GraphicElement graphicRel=(GraphicElement)newIstanzaVis.newInstance(); 1662 1663 1664 Point sourceCentre = source.getComplexGraphicElement().getCentre(); 1666 Point targetCentre = target.getComplexGraphicElement().getCentre(); 1667 1668 ComplexGraphicElement cge=new ComplexGraphicElement(); 1669 cge.addGraficElement(graphicRel); 1670 1671 VisLabel lb_id2 = new VisLabel(sourceCentre, targetCentre, "id",idIstanzaW.toString(),1); 1673 cge.addGraficElement(lb_id2); 1674 1675 if (rapre.getAttribute("weight") != null){ 1677 VisLabel lb_w = new VisLabel(sourceCentre, targetCentre, "weight","1", 2); 1679 cge.addGraficElement(lb_w); 1680 } 1681 1682 ReferrableConnection con=new ReferrableConnection("",idTipo,idIstanzaW.toString()); 1684 con.setComplexGraphicElement(cge); 1685 1686 con.setTouches(touches); 1687 1688 addDrawing((ReferrableElement)con); 1689 } 1690 1691 } catch(InstantiationException e){ 1693 Cve.errLog.error(e.toString()); 1694 } catch(IllegalAccessException e1){ 1695 Cve.errLog.error(e1.toString()); 1696 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallito accesso"+"\n"); 1697 } catch(ClassNotFoundException e2){ 1698 Cve.errLog.error(e2.toString()); 1699 ViewLog.writeInLog(" #E <WippogSentenza>: newIstance() fallita ricerca classe"+"\n"); 1700 } 1701 1702 ConfigElement appo_config1 = new ConfigElement(); 1705 if (rapre.getAttribute("weight") != null){ 1707 appo_config1.putParameter("weight","1"); 1708 } 1709 configElements.addElement(idIstanzaW.toString(), appo_config1); 1710 } 1711 } 1712 } 1713 break; 1714 case QUERY: 1715 ViewLog.writeInLog(" #E <WippogSentenza>: QUERY ELEMENT"+"\n"); 1716 System.out.println(" #E <WippogSentenza>: QUERY ELEMENT"); 1717 1718 itItems=items.iterator(); 1719 while (itItems.hasNext()){ 1720 1721 IResource item=(IResource)itItems.next(); 1722 setQueryItem(item); 1723 1724 } 1725 break; 1726 } 1728 synchronized( sincronizzatoreSent ) { 1730 System.out.println(" <SENT> StepExecuted - All Cases!!!"); 1731 sincronizzatoreSent.notifyAll(); 1732 } 1733 updateCreationeSemantic(t,items); 1736 1738 } } ); 1741 }catch (Exception e) { 1743 Cve.errLog.error(e.toString()); 1744 ViewLog.writeInLog(" #E <WippogSentenza>: problemi in wippog sentenza"+"\n"); 1745 } 1746 } 1747 1748 private void updateCreationeSemantic(Transition t, java.util.List items){ 1750 Cve.errLog.debug(""); 1751 System.out.println(" #E <WippogSentenza>: UpdateCreationSemantic t.iD= "+ t.getId() + " Items prodotti: " + items.toString()); 1752 IResource item; 1754 Representation rapre; 1755 String idTipo; 1756 IWippogObject idIstanzaW; 1757 1758 Association appo_ass = associations.getAss(t.getId()); 1761 if (appo_ass != null){ 1762 1763 Iterator itItems=items.iterator(); 1766 while (itItems.hasNext()){ 1767 item=(IResource)itItems.next(); 1768 idTipo=item.getTypeName(); 1769 rapre=(Representation)rappresentations.get(idTipo); 1770 if (rapre!=null){ 1771 String nameId=rapre.getAttribute("nameId"); 1772 idIstanzaW = item.getAttribute(nameId); 1773 1774 System.out.println(" #E <WippogSentenza>: Name: " + nameId + " SentenceId: "+ idIstanzaW.toString() + " idTipo: " +idTipo); 1776 1777 appo_ass.setParameter(nameId, idIstanzaW.toString()); 1779 1780 ConfigElement appo_configP = configElements.getConfig(idIstanzaW.toString()); 1783 1784 String app_token = appo_configP.getParameter("max_token"); 1786 1787 if (app_token != null) appo_ass.setParameter("max_token",app_token); 1788 1789 String app_weight = appo_configP.getParameter("weight"); 1791 1792 if (app_weight != null) appo_ass.setParameter("weight",app_weight); 1793 } 1794 } 1795 1796 String appo_risorsa = associations.getResource(t.getId()); 1798 1799 System.out.println("Invio Semantica WM: " + sem.getId() + " Risorsa: " + appo_risorsa); 1800 CVESemanticFactory.setWMCurrent(sem); 1802 sem.addItemGet(appo_risorsa); 1803 1804 synchronized(sincronizzatoreSem) { 1805 try { 1806 System.out.println(" Attesa aggiornamento Semantica"); 1807 sincronizzatoreSem.wait(); 1808 System.out.println(" Dopo attesa aggiornamento Semantica"); 1809 } 1810 catch (InterruptedException e){ 1811 Cve.errLog.error(e.toString()); 1812 } 1813 } 1814 treeSemOUT = CVESemanticFactory.getTree(sem); 1816 setModel(convertElementNode(treeSemOUT, "SEMANTIC SENTENCE"),"setSemantic" ,null); 1817 } 1818 1819 System.out.println("ELENCO CONFIGURAZIONI"); 1822 System.out.println(configElements.toString()); 1823 } 1825 1826 1827 1831 private void initWippogSemantica(String fileSem){ 1832 Cve.errLog.debug(""); 1833 System.out.println(" #E Inizializzazione Listener WIPPOG SEMANTICA da "+fileSem); 1834 try { 1835 sem=WippogFactory.load(fileSem,true); 1837 CVESemanticFactory.load(sem,translationClass); 1840 CVESemanticFactory.setOrientation(sem,this.orientation); 1842 1843 treeSemOUT = CVESemanticFactory.getTree(sem); 1845 setModel(convertElementNode(treeSemOUT, "SEMANTIC SENTENCE"),"setSemantic" ,null); 1846 1847 sem.addWippogListener(new WippogAdapter() { 1849 1850 1852 public void stepExecuted( StepEvent event ) { 1854 Cve.errLog.debug(""); 1856 Thread.yield(); 1857 1862 synchronized( sincronizzatoreSem ) { 1863 System.out.println("Albero Semantico Creato"); 1864 sincronizzatoreSem.notifyAll(); 1865 } 1866 } 1867 1868 }); 1870 } catch (Exception e) { 1871 Cve.errLog.error(e.toString()); 1872 ViewLog.writeInLog(" #E# problemi in wippog automa SEMANTICA"+"\n"); 1873 } 1874 1875 } 1876 1877 1882 private void initWippogSemExecution(String fileSem){ 1883 Cve.errLog.debug(""); 1884 System.out.println(" #E Inizializzazione Listener WIPPOG ESECUZIONE SEMANTICA da "+fileSem); 1885 try { 1886 semexec = null; 1888 semexec=WippogFactory.load(pathFileInit,true); 1889 contestoEsecuzione = INIT; 1890 1893 treeSemOUT = CVESemanticFactory.getTree(sem); 1895 1896 semexec.addWippogListener(new WippogAdapter() { 1898 1899 java.util.List itemsC; 1901 java.util.List itemsP; 1902 WippogMachine wm; 1903 Collection rules; 1904 Iterator itRules; 1905 Transition t; 1906 Collection idElementConsumed = null, idElementProduced = null; 1907 1908 public void resourceConsumed( WippogEvent event ) { 1910 Cve.errLog.debug(""); 1911 System.out.println(" #E <WippogSemExec>: Ascoltatore SEM EXEC resourceConsumed"); 1912 if (contestoEsecuzione == EXEC){ 1913 Thread.yield(); 1914 itemsC=event.getResouces(); 1916 idElementConsumed = (Collection)event.getResouces(); 1917 updateTokenConsumed(idElementConsumed); 1918 idElementConsumed = null; 1919 } 1920 System.out.println(" #E <WippogSemExec>: Ascoltatore SEM EXEC resourceConsumed: Passo eseguito"); 1921 } 1922 1923 public void resourceProduced( WippogEvent event ) { 1925 Cve.errLog.debug(""); 1926 System.out.println(" #E <WippogSemExec>: Ascoltatore SEM EXEC resourceProduced"); 1927 1928 if (contestoEsecuzione == EXEC){ 1929 1930 Thread.yield(); 1931 itemsP=event.getResouces(); 1933 idElementProduced = (Collection)event.getResouces(); 1934 updateTokenProduced(idElementProduced); 1935 idElementProduced = null; 1936 wm = event.getSource(); 1937 } 1938 System.out.println(" #E <WippogSemExec>: Ascoltatore SEM EXEC resourceProduced: Passo eseguito"); 1939 } 1940 1941 public void stepExecuted( StepEvent event ) { 1943 1945 if (contestoEsecuzione == INIT){ 1947 Thread.yield(); 1948 synchronized( sincronizzatoreSemIP ) { 1949 System.out.println("SEMEXEC - StepEsxecuted - Risorsa Creata!!!"); 1950 sincronizzatoreSemIP.notifyAll(); 1951 } 1952 } 1953 1954 setModel(convertElementNode(treeSemOUT, "SEMANTIC SENTENCE"),"setSemantic" ,null); 1956 1957 } 1959 } ); 1961 } catch (Exception e) { 1962 Cve.errLog.error(e.toString()); 1963 ViewLog.writeInLog(" #E# problemi in wippog automa ESECUZIONE SEMANTICA"+"\n"); 1964 } 1965 1966 try{ 1968 1975 1976 addInternalPool(); 1978 1979 semexec.stop(); 1981 System.out.println("WM SEM EXEC DOPO ADD INTERNAL POOL Activator: "+ s_activator); 1982 System.out.println(semexec.toString()); 1983 1984 contestoEsecuzione = EXEC; 1986 if (s_activator.equals("StepActivator")){ 1989 semexec.setActivator(new StepActivator()); 1991 System.out.println("***************Impostato attivatore Step"); 1992 1993 } 1994 if (s_activator.equals("SeqActivator")){ 1995 semexec.setActivator(new SeqActivator()); 1997 System.out.println("***************Impostato attivatore Seq"); 1998 1999 } 2000 2001 semexec.load(fileSem); 2003 semexec.run(); 2006 } catch (Exception e) { 2007 Cve.errLog.error(e.toString()); 2008 ViewLog.writeInLog(" #E# problemi in wippog automa ESECUZIONE SEMANTICA"+"\n"); 2009 } 2010 2011 } 2012 2013 2019 private void updateTokenConsumed(Collection idElementWhen){ 2020 Cve.errLog.debug(""); 2021 if (idElementWhen != null){ 2024 int num_token_input = 0; 2025 for( Iterator itWhen=idElementWhen.iterator(); itWhen.hasNext(); ) { 2026 2027 IResource appo_resource = (IResource)itWhen.next(); 2029 2030 IWippogObject id_obj = appo_resource.getAttribute("idH"); 2034 2035 String appoWhen = id_obj.toString(); 2036 System.out.println("updateTokenConsumed : elemento: " + appoWhen); 2037 ConfigElement appo_configEl = configElements.getConfig(appoWhen); 2039 num_token_input = Integer.valueOf(appo_configEl.getParameter("num_token")).intValue(); 2040 2041 if (num_token_input>=1){ 2042 addInternalPool(appoWhen,num_token_input-1); 2043 } 2044 } 2045 } 2046 2047 synchronized( sincronizzatoreSemUpTC ) { 2048 System.out.println("Token Consumati Aggiornati"); 2049 sincronizzatoreSemUpTC.notifyAll(); 2050 } 2051 2052 } 2053 2054 2055 2061 private void updateTokenProduced(Collection idElementProduced){ 2062 Cve.errLog.debug(""); 2063 if (idElementProduced != null){ 2066 2067 int num_token_input = 0; 2068 2069 for( Iterator itProduced=idElementProduced.iterator(); itProduced.hasNext(); ) { 2070 2071 IResource appo_resource = (IResource)itProduced.next(); 2073 2074 IWippogObject id_obj = appo_resource.getAttribute("idH"); 2078 2079 String appoProduce = id_obj.toString(); 2080 System.out.println("updateTokenProduced : elemento: " + appoProduce); 2081 2082 ConfigElement appo_configEl = configElements.getConfig(appoProduce); 2084 num_token_input = Integer.valueOf(appo_configEl.getParameter("num_token")).intValue(); 2085 addInternalPool(appoProduce,num_token_input+1); 2086 2087 } 2088 } 2089 synchronized( sincronizzatoreSemUpTP ) { 2090 System.out.println("Token Prodotti Aggiornati"); 2091 sincronizzatoreSemUpTP.notifyAll(); 2092 } 2093 2094 2095 } 2096 2097 2098 2102 private ReferrableElement trovaDrawingDaId(String idIstanza){ 2103 Cve.errLog.debug(""); 2104 System.out.println("trovaDrawingDaId idIstanza "+idIstanza); 2105 for (int i=0;i<sentence.size();i++){ 2106 ReferrableElement d=(ReferrableElement)sentence.elementAt(i); 2107 String idIst=d.getIdInstance(); 2108 System.out.println(" trovaDrawingDaId Elemento trovato idIstanza "+idIst); 2109 if(idIst.equals(idIstanza)){ 2110 return d; 2112 } 2113 } 2114 return null; 2115 } 2116 2117 2121 private void setSelectCp(Collection listaSel){ 2122 Cve.errLog.debug(""); 2123 for (int i=0;i<sentence.size();i++){ 2124 ReferrableElement d=(ReferrableElement)sentence.elementAt(i); 2125 String idIst=d.getIdInstance(); 2126 if(isInListaSel(idIst)){ 2127 ViewLog.writeInLog(" #E Selected Element (setSelectCp): configuro l'elemento " + idIst + " come selezionato" + "\n"); 2128 System.out.println(" #E Selected Element (setSelectCp): configuro l'elemento " + idIst + " come selezionato" + "\n"); 2129 2130 d.setSelected(true); 2131 } else { 2132 ViewLog.writeInLog(" #E Selected Element (setSelectCp): configuro l'elemento " + idIst + " come NON selezionato" + "\n"); 2133 System.out.println(" #E Selected Element (setSelectCp): configuro l'elemento " + idIst + " come NON selezionato" + "\n"); 2134 2135 d.setSelected(false); 2136 } 2137 } 2138 SentenceEvent sentEv=new SentenceEvent(); 2139 sentEv.setActionUser("selected"); 2140 sentEv.setSentence(sentence); 2141 ObservableCve ob=getObservable(); 2142 ob.setDate(sentEv); 2143 } 2144 2145 2146 2148 2151 private void setModel(DefaultMutableTreeNode treeModel, String Action, String pathFile){ 2152 Cve.errLog.debug(""); 2153 SentenceEvent sentEv=new SentenceEvent(); 2154 sentEv.setActionUser(Action); 2155 sentEv.setModelTree(treeModel); 2156 sentEv.setFileTree(pathFile); 2157 ObservableCve ob=getObservable(); 2158 ob.setDate(sentEv); 2159 } 2160 2161 2168 private DefaultMutableTreeNode convertElementNode(Element rootElement, String nameRoot){ 2169 Cve.errLog.debug(""); 2170 DefaultMutableTreeNode p1=new DefaultMutableTreeNode (nameRoot); 2171 addNodes(p1,rootElement); 2172 return p1; 2173 } 2174 2175 2176 2184 private DefaultMutableTreeNode setFile(String fileLetto,String nameRoot){ 2185 Cve.errLog.debug(""); 2186 DefaultMutableTreeNode p1=new DefaultMutableTreeNode (nameRoot); 2187 2188 try { 2189 SAXBuilder builder = new SAXBuilder(false); 2191 document = builder.build(new File (fileLetto)); 2192 } catch (JDOMException e) { 2193 Cve.errLog.error(e.toString()); 2194 }catch (Exception e) { 2195 Cve.errLog.error(e.toString()); 2196 } 2197 Element root=document.getRootElement(); 2198 addNodes(p1,root); 2199 return p1; 2200 } 2201 2202 2203 2209 private void addNodes (DefaultMutableTreeNode pnode,Element ele){ 2210 Cve.errLog.debug(""); 2211 DefaultMutableTreeNode node; 2212 if ((ele!=null)&&(pnode!=null)) { 2213 java.util.List figli=ele.getChildren(); 2214 Iterator it=figli.iterator(); 2215 if (it!=null){ 2216 while (it.hasNext()){ 2217 Element newEle=(Element)it.next(); 2218 String nome=createString(newEle); 2219 node= new DefaultMutableTreeNode(nome); 2220 pnode.add(node); 2221 addNodes(node,newEle); 2222 } 2223 } 2224 } 2225 } 2226 2227 2233 private String createString(Element ele){ 2234 Cve.errLog.debug(""); 2235 String app=new String (); 2236 app=ele.getName(); 2237 java.util.List attrList=((Element)ele).getAttributes(); 2238 for (int i=0;i<attrList.size();i++){ 2239 String name=((Attribute)attrList.get(i)).getName(); 2240 String value=((Attribute)attrList.get(i)).getValue(); 2241 app=app+" "+name+"="+value; 2242 } 2243 return app; 2244 } 2245 2246 2247 2249 2254 private void addInternalPool(){ 2255 Cve.errLog.debug(""); 2256 String appo_generate = new String (); 2257 num_internal = internal.size(); 2258 2259 System.out.println(" #E addInternalPool INIZIALE: " + num_internal + " internal: " + internal.toString()); 2261 2262 for (int i=0 ; i<internal.size();i++){ 2263 2266 String appoRes = (String )internal.get(i); 2268 if (orientation==TOKEN && appoRes != null){ 2269 System.out.println("Risorsa in creazione: " + appoRes + " numero: " + i); 2270 appo_generate = "generate(idH="+appoRes+")"; 2271 System.out.println(" creazione internal pool: " + appo_generate); 2272 semexec.addItemGet(appo_generate); 2273 synchronized(sincronizzatoreSemIP) { 2275 try { 2276 System.out.println(" Attesa creazione internal pool"); 2277 sincronizzatoreSemIP.wait(); 2278 System.out.println(" Dopo attesa creazione internal pool"); 2279 } 2280 catch (InterruptedException e){ 2281 Cve.errLog.error(e.toString()); 2282 } 2283 } 2284 } 2285 } 2286 } } | Popular Tags |