1 4 5 package cve.esecutori; 6 7 import cve.esecutori.servizioEACBuildSemantic.*; 8 9 import cve.core.elementEEL.*; 10 import cve.staticLayout.*; 11 import cve.util.*; 12 13 import java.awt.*; 14 import java.awt.event.*; 15 16 import javax.swing.*; 17 import javax.swing.tree.*; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.io.*; 22 import java.util.*; 23 24 import org.jdom.*; 25 import org.jdom.Document; 26 import org.jdom.Element; 27 import org.jdom.JDOMException; 28 import org.jdom.input.SAXBuilder; 29 import org.jdom.output.XMLOutputter; 30 31 32 47 public class EACBuildSemantic extends Esecutore implements SpecificationSemantic 48 { 49 50 static String fileSem, fileSint, fileAss, fileAssFile; 52 53 private Document document; 55 private DefaultMutableTreeNode treeSinRules,treeSemRules; 56 private DefaultMutableTreeNode treeSpeSem,treeAssSem, treeFileAssFile; 57 58 private String idRegolaSint, idRegolaSem; 60 private String translationClass; 61 62 65 public EACBuildSemantic(){ 66 translationClass = new String (""); 67 } 68 69 73 public DefaultMutableTreeNode getModelSintRules(){ 74 return treeSinRules; 75 } 76 77 78 82 public DefaultMutableTreeNode getModelSemRules(){ 83 return treeSemRules; 84 } 85 86 90 public DefaultMutableTreeNode getModelAssSem(){ 91 return treeAssSem; 92 } 93 94 95 96 102 public void setSintaxRules(String file){ 103 ViewLog.writeInLog(" #E Eseguito setSintaxRules: "+file+"\n"); 104 105 this.fileSint = file; 106 107 treeSinRules=setFile(fileSint,"SINTAX RULES"); 109 setModel(treeSinRules,"setSintaxRules",fileSint); 111 } 112 113 117 public void delSintaxRules(){ 118 ViewLog.writeInLog(" #E Eseguito delSintaxRules: "+"\n"); 119 120 this.fileSint = null; 121 setModel(null,"delSintaxRules",null); 122 } 123 124 130 public void setSemanticRules(String file){ 131 ViewLog.writeInLog(" #E Eseguito setSemanticRules: "+file+"\n"); 132 133 134 this.fileSem = file; 136 137 treeSemRules=setFile(fileSem,"SEMANTIC RULES"); 139 setModel(treeSemRules,"setSemanticRules",fileSem); 141 } 142 143 144 148 public void delSemanticRules(){ 149 ViewLog.writeInLog(" #E Eseguito delSemanticRules: "+"\n"); 150 151 this.fileSem = null; 152 setModel(null,"delSemanticRules",null); 153 } 154 155 162 public void newSemanticTree(String file){ 163 164 ViewLog.writeInLog(" #E Eseguito newSemanticTree: "+file+"\n"); 165 166 this.fileSem = file; 168 169 String newStringFile = new String (); 170 newStringFile = createStringFile(); 171 172 try{ 174 FileOutputStream fileoutputstream = new FileOutputStream(fileSem); 175 PrintStream printstream = new PrintStream(fileoutputstream); 176 printstream.println(newStringFile); 177 printstream.close(); 178 }catch(IOException e){ 179 System.out.println("#E Errore in creazione file Regole Semantiche"); 180 } 181 182 treeSemRules=setFile(fileSem,"SEMANTIC RULES"); 184 185 setModel(treeSemRules,"setSemanticRules",fileSem); 187 188 } 189 190 197 public void newAssociationTree(String fileRegAss, String fileAssF){ 198 199 ViewLog.writeInLog(" #E Eseguito newAssociationTree: "+fileRegAss+"\n"); 200 201 this.fileAss = fileRegAss; 203 204 String newStringFileAss = new String (); 205 newStringFileAss = createStringFileAss(); 206 207 try{ 209 FileOutputStream fileoutputstream = new FileOutputStream(fileAss); 210 PrintStream printstream = new PrintStream(fileoutputstream); 211 printstream.println(newStringFileAss); 212 printstream.close(); 213 }catch(IOException e){ 214 System.out.println("#E Errore in creazione file Associazione Regole Semantiche"); 215 } 216 217 219 227 this.fileAssFile=fileAssF; 228 229 this.translationClass = ""; 231 String newStringFileAssFile = new String (); 232 newStringFileAssFile = createStringFileAssFile(fileAssFile, fileSint, fileSem, fileAss); 233 234 try{ 236 FileOutputStream fileoutputstream2 = new FileOutputStream(fileAssFile); 237 PrintStream printstream2 = new PrintStream(fileoutputstream2); 238 printstream2.println(newStringFileAssFile); 239 printstream2.close(); 240 }catch(IOException e){ 241 System.out.println("E# Errore in creazione file Associazione File Regole Sintattiche-Semantiche"); 242 } 243 244 treeAssSem=setFile(fileAss,"ASSOCIATION TREE"); 247 248 setModel(treeAssSem,"setAssociationSemantic",fileAss); 250 251 treeFileAssFile=setFile(fileAssFile,"ASSOCIATION FILE TREE"); 254 255 setModel(treeFileAssFile,"setAssociationFile",fileAssFile); 257 258 259 } 260 261 269 public void assSemSint(String idRuleSint, String idRuleSem){ 270 271 ViewLog.writeInLog(" #E Eseguito assSemSint: Regola Sint: "+idRuleSint+" Regola Sem: "+idRuleSem+"\n"); 272 273 274 try{ 277 278 AssociationSem ass=new AssociationSem(fileSint,fileSem, fileAss); 280 281 ass.setAssociation(idRuleSint, idRuleSem); 283 284 }catch(IOException e){ 285 System.out.println("#E Errore nella creazione dell'associazione Regole! " + e); 286 } 287 288 289 treeAssSem=setFile(fileAss,"ASSOCIATION TREE"); 291 292 setModel(treeAssSem,"setAssociationSemantic",fileAss); 294 } 295 296 300 public void delAssRules(){ 301 302 ViewLog.writeInLog(" #E Eseguito delAssRules" + "\n"); 303 304 this.fileAss = null; 305 setModel(null,"delAssRules",null); 306 } 307 308 309 316 public void getAll(String pathfileAssFile){ 317 318 ViewLog.writeInLog(" #E Eseguito getAll da file: " + pathfileAssFile + "\n"); 319 320 this.fileAssFile = pathfileAssFile; 321 322 ElementXML objSearch = new ElementXML(fileAssFile); 324 325 this.fileSint = objSearch.getParameter(objSearch.getRootDocument(),"SyntaxFile","nameFile",null,null); 327 this.fileSint = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "\\" + this.fileSint; 328 329 330 this.fileSem = objSearch.getParameter(objSearch.getRootDocument(),"SemanticFile","nameFile",null,null); 332 this.fileSem = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "\\" + this.fileSem; 333 334 335 this.fileAss = objSearch.getParameter(objSearch.getRootDocument(),"AssociationFile","nameFile",null,null); 337 this.fileAss = ConfigurationRead.getCveRoot() + ConfigurationRead.getCveWSpeRoot() + "\\" + this.fileAss; 338 339 this.translationClass = objSearch.getParameter(objSearch.getRootDocument(),"TranslationSemanticClass","nameFile",null,null); 341 343 344 treeSinRules = setFile(fileSint,"SINTAX RULES"); 346 treeSemRules = setFile(fileSem,"SEMANTIC RULES"); 347 treeAssSem = setFile(fileAss,"ASSOCIATION TREE"); 348 treeFileAssFile = setFile(fileAssFile,"ASSOCIATION FILE TREE"); 349 350 351 setModel(treeSinRules,"setSintaxRules",fileSint); 353 setModel(treeSemRules,"setSemanticRules",fileSem); 354 setModel(treeAssSem,"setAssociationSemantic",fileAss); 355 setModel(treeFileAssFile,"setAssociationFile",fileAssFile); 356 357 } 358 359 360 364 public void delAll(){ 365 366 ViewLog.writeInLog(" #E Eseguito delAll" + "\n"); 367 368 this.fileSint = null; 369 this.fileAss = null; 370 this.fileSem = null; 371 this.fileAssFile = null; 372 this.translationClass = ""; 373 setModel(null,"delSintaxRules",null); 374 setModel(null,"delSemanticRules",null); 375 setModel(null,"delAssRules",null); 376 377 } 378 379 384 public void setTranslationSemantic(String typeS){ 385 translationClass = typeS; 386 ViewLog.writeInLog(" #E Eseguita Impostazione Tipo Traduzione Semantica: "+translationClass+"\n"); 387 System.out.println(" #E Eseguita Impostazione Tipo Traduzione Semantica: "+translationClass); 388 389 changeAttributeAss("TranslationSemanticClass", translationClass); 391 392 treeFileAssFile = setFile(fileAssFile,"ASSOCIATION FILE TREE"); 394 395 setModel(treeFileAssFile,"setAssociationFile",fileAssFile); 397 } 398 399 400 405 public String getTranslationSemantic(){ 406 ViewLog.writeInLog(" #E Eseguita Lettura Tipo Traduzione Semantica: "+translationClass+"\n"); 407 System.out.println(" #E Eseguita Lettura Tipo Traduzione Semantica: "+translationClass); 408 return translationClass; 409 } 410 411 412 413 414 415 416 419 private void setModel(DefaultMutableTreeNode treeModel, String Action, String pathFile){ 420 SpecificationEventSem speEv=new SpecificationEventSem(); 421 speEv.setActionUser(Action); 422 speEv.setModelTree(treeModel); 423 speEv.setFileTree(pathFile); 424 ObservableCve ob=getObservable(); 425 ob.setDate(speEv); 426 } 427 428 434 private DefaultMutableTreeNode setFileNew(String nameRoot){ 435 DefaultMutableTreeNode p1=new DefaultMutableTreeNode (nameRoot); 436 return p1; 437 } 438 439 447 private DefaultMutableTreeNode setFile(String fileLetto,String nameRoot) 448 { 449 DefaultMutableTreeNode p1=new DefaultMutableTreeNode (nameRoot); 450 451 try { 452 SAXBuilder builder = new SAXBuilder(false); 454 document = builder.build(new File (fileLetto)); 455 } catch (JDOMException e) { 456 if (e.getRootCause() != null) { 457 e.getRootCause().printStackTrace(); 458 } 459 e.printStackTrace(); 460 } catch (Exception e) { 461 e.printStackTrace(); 462 } 463 Element root=document.getRootElement(); 464 addNodes(p1,root); 465 return p1; 466 } 467 468 469 475 private void addNodes (DefaultMutableTreeNode pnode,Element ele){ 476 DefaultMutableTreeNode node; 477 if ((ele!=null)&&(pnode!=null)) { 478 java.util.List figli=ele.getChildren(); 479 Iterator it=figli.iterator(); 480 if (it!=null){ 481 while (it.hasNext()){ 482 Element newEle=(Element)it.next(); 483 String nome=createString(newEle); 484 node= new DefaultMutableTreeNode(nome); 485 pnode.add(node); 486 addNodes(node,newEle); 487 } 488 } 489 } 490 } 491 492 493 494 501 private DefaultMutableTreeNode newAssTree(String nameRoot){ 502 DefaultMutableTreeNode proot=new DefaultMutableTreeNode (nameRoot); 503 return proot; 504 } 505 506 507 513 private String createString(Element ele){ 514 String app=new String (); 515 app=ele.getName(); 516 java.util.List attrList=((Element)ele).getAttributes(); 517 for (int i=0;i<attrList.size();i++){ 518 String name=((Attribute)attrList.get(i)).getName(); 519 String value=((Attribute)attrList.get(i)).getValue(); 520 app=app+" "+name+"="+value; 521 } 522 return app; 523 } 524 525 526 532 private String createStringFile(){ 533 534 String app = new String (); 536 537 app = ""; 538 app = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 539 app = app + "<WippogRules>"; 540 app = app + "<Defines description=\"Definizione dei tipi utilizzati\">"; 541 app = app + "</Defines>"; 542 app = app + "<Imports>"; 543 app = app + "<Item typeName=\"activity\"/>"; 544 app = app + "<Item typeName=\"listaSel\"/>"; 545 app = app + "</Imports>"; 546 app = app + "<Exports>"; 547 app = app + "<Item typeName=\"conditionRule\"/>"; 548 app = app + "</Exports>"; 549 app = app + "</WippogRules>"; 550 551 return app; 552 } 553 554 555 556 562 private String createStringFileAss(){ 563 564 String app = new String (); 566 567 app = ""; 568 app = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 569 app = app + "<WippogAssRules>"; 570 app = app + "</WippogAssRules>"; 571 572 return app; 573 } 574 575 584 private String createStringFileAssFile(String fileAssociationFile, String SyntaxFile, String SemanticFile, String AssFile){ 585 586 String nameFileAss, nameFileSin, nameFileControl, nameFileSem, nameFileAssRule; 587 588 File fileAppoAss= new File (fileAssociationFile); 591 nameFileAss=fileAppoAss.getName(); 592 593 File fileAppoSin= new File (SyntaxFile); 595 nameFileSin=fileAppoSin.getName(); 596 597 nameFileControl=nameFileSin.substring(5); 598 599 File fileAppoSem= new File (SemanticFile); 602 nameFileSem=fileAppoSem.getName(); 603 604 File fileAppoAssRule= new File (AssFile); 606 nameFileAssRule=fileAppoAssRule.getName(); 607 608 String app = new String (); 610 611 app = ""; 612 app = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+"\r\n" ; 613 app = app + "<WippogFileAssRules>" +"\r\n"; 614 app = app + "\t<InfoFile description=\"Informazioni file di Associazione\" >" +"\r\n"; 615 app = app + "\t\t<FilePath nameFile=\"" + nameFileAss + "\" />" +"\r\n"; 616 app = app + "\t</InfoFile>" +"\r\n"; 617 app = app + "\t<WippogFileAss>" +"\r\n"; 618 app = app + "\t\t<ControlFile nameFile=\"" + nameFileControl + "\" />" +"\r\n"; 619 app = app + "\t\t<SyntaxFile nameFile=\"" + nameFileSin + "\" />" +"\r\n"; 620 app = app + "\t\t<SemanticFile nameFile=\"" + nameFileSem + "\" />"+"\r\n"; 621 app = app + "\t\t<AssociationFile nameFile=\"" + nameFileAssRule + "\" />"+"\r\n"; 622 app = app + "\t\t<TranslationSemanticClass nameFile=\"" + translationClass + "\" />"+"\r\n"; 623 app = app + "\t</WippogFileAss>" +"\r\n"; 624 app = app + "</WippogFileAssRules>"+"\r\n"; 625 626 return app; 627 } 628 629 630 637 private void changeAttributeAss(String name, String value){ 638 639 Element rootEnv; 640 Document docEnv = null; 641 642 try { 644 SAXBuilder builder = new SAXBuilder(false); 646 docEnv = builder.build(new File (fileAssFile)); 647 } catch (JDOMException e) { 649 if (e.getRootCause() != null) { 650 e.getRootCause().printStackTrace(); 651 } 652 e.printStackTrace(); 653 } catch (Exception e) { 654 e.printStackTrace(); 655 } 656 657 rootEnv = docEnv.getRootElement(); 659 660 661 java.util.List figliWFAR = rootEnv.getChildren("WippogFileAss"); 663 Iterator itFigliWFAR = figliWFAR.iterator(); 664 665 666 Element appoFigli = (Element)itFigliWFAR.next(); 668 java.util.List figliWFA = appoFigli.getChildren(name); 669 Iterator itFigliWFA = figliWFA.iterator(); 670 671 Element nodo = (Element)itFigliWFA.next(); 672 673 appoFigli.removeContent(nodo); 675 676 Element newNode = new Element(name); 678 java.util.List attList = newNode.getAttributes(); 679 680 Attribute att = new Attribute("nameFile",value); 681 attList.add(att); 682 newNode.setAttributes(attList); 683 684 appoFigli.addContent(newNode); 686 687 writeFileXML(fileAssFile, rootEnv); 689 690 } 691 692 693 700 private static void writeFileXML(String path, Element root){ 701 File fileS = new File (path); 702 try{ 703 fileS.createNewFile(); 704 FileWriter outS= new FileWriter (fileS); 705 XMLOutputter fmtS = new XMLOutputter(" ",true); 706 707 708 String appS=fmtS.outputString(root); 709 outS.write(appS); 710 outS.close(); 711 }catch( IOException e){ 712 System.out.println(" CVESemanticFactory.writeFileXML: Problema in scrittura file XML!!!"+"\r\n"); 713 } 714 } 715 716 717 718 719 } | Popular Tags |