1 4 package cve.esecutori; 5 6 import cve.esecutori.components.specificaLV.*; 7 import cve.esecutori.components.automatonB.*; 8 import cve.core.elementEEL.*; 9 import cve.esecutori.servizioEACBuild.*; 10 import cve.staticLayout.*; 11 12 import java.awt.*; 13 import java.awt.event.*; 14 15 import javax.swing.*; 16 import javax.swing.tree.*; 17 18 import java.io.File ; 19 import java.io.IOException ; 20 import java.io.*; 21 import java.util.*; 22 23 import org.jdom.*; 24 import org.jdom.input.SAXBuilder; 25 import org.jdom.output.XMLOutputter; 26 27 import org.apache.log4j.Logger; 28 29 42 public class EACBuild extends Esecutore implements SpecificationLanguage 43 { 44 static String filereg,filealf,fileout; 45 private Document document; 46 private DefaultMutableTreeNode treeAlf,treeReg,treeSent,treeAut; 47 48 51 public EACBuild(){ 52 Cve.errLog.debug(""); 53 } 54 55 58 public DefaultMutableTreeNode getModelAlf(){ 59 Cve.errLog.debug(""); 60 return treeAlf; 61 } 62 63 64 67 public DefaultMutableTreeNode getModelReg(){ 68 Cve.errLog.debug(""); 69 return treeReg; 70 } 71 72 75 public DefaultMutableTreeNode getModelAut(){ 76 Cve.errLog.debug(""); 77 return treeAut; 78 } 79 80 83 public DefaultMutableTreeNode getModelSent(){ 84 Cve.errLog.debug(""); 85 return treeSent; 86 } 87 88 92 public void setAlphabet(String file){ 93 Cve.errLog.debug(""); 94 treeAlf=setFile(file,"ALPHABET"); 96 SpecificationEvent speEv=new SpecificationEvent(); 98 speEv.setActionUser("setAlphabet"); 99 speEv.setModelTree(treeAlf); 100 ObservableCve ob=getObservable(); 101 ob.setDate(speEv); 102 } 103 104 108 public void setRules(String file){ 109 Cve.errLog.debug(""); 110 treeReg=setFile(file,"RULES"); 112 SpecificationEvent speEv=new SpecificationEvent(); 114 speEv.setActionUser("setRules"); 115 speEv.setModelTree(treeReg); 116 ObservableCve ob=getObservable(); 117 ob.setDate(speEv); 118 } 119 120 124 public void setAutoma(String file){ 125 Cve.errLog.debug(""); 126 treeAut=setFile(file,"AUTOMATA"); 128 SpecificationEvent speEv=new SpecificationEvent(); 130 speEv.setActionUser("setAutoma"); 131 speEv.setModelTree(treeAut); 132 ObservableCve ob=getObservable(); 133 ob.setDate(speEv); 134 } 135 136 140 public void setSentenza(String file){ 141 Cve.errLog.debug(""); 142 treeSent=setFile(file,"SENTENCE"); 144 SpecificationEvent speEv=new SpecificationEvent(); 146 speEv.setActionUser("setSentenza"); 147 speEv.setModelTree(treeSent); 148 ObservableCve ob=getObservable(); 149 ob.setDate(speEv); 150 } 151 152 156 public void delAlphabet(){ 157 Cve.errLog.debug(""); 158 SpecificationEvent speEv=new SpecificationEvent(); 159 speEv.setActionUser("delAlphabet"); 160 speEv.setModelTree(null); 161 ObservableCve ob=getObservable(); 162 ob.setDate(speEv); 163 } 164 165 169 public void delRules(){ 170 Cve.errLog.debug(""); 171 SpecificationEvent speEv=new SpecificationEvent(); 172 speEv.setActionUser("delRules"); 173 speEv.setModelTree(null); 174 ObservableCve ob=getObservable(); 175 ob.setDate(speEv); 176 } 177 178 182 public void makeLanguage(String fileA, String fileR){ 183 Cve.errLog.debug(""); 184 try { 185 Specifica spe=new Specifica(fileR,fileA); 186 GenerationSentence gs=new GenerationSentence(spe); 188 File fileLang=gs.createGS(); 190 String nameFileLanguage=fileLang.getName(); 193 String filePath=fileLang.getParent(); 194 String fileS=filePath+"/"+"Sent_"+nameFileLanguage; 195 treeSent=setFile(fileS,"SENTENCE"); 196 SpecificationEvent speEv1=new SpecificationEvent(); 197 speEv1.setActionUser("setSentenza"); 199 speEv1.setModelTree(treeSent); 200 ObservableCve ob=getObservable(); 201 ob.setDate(speEv1); 202 AutControlB msf=new AutControlB(); 204 String fileAut=msf.createCA(fileA,fileLang,spe); 205 treeAut=setFile(fileAut,"AUTOMATA"); 207 SpecificationEvent speEv=new SpecificationEvent(); 209 speEv.setActionUser("setAutoma"); 210 speEv.setModelTree(treeAut); 211 ob.setDate(speEv); 213 }catch(IOException e){ 214 Cve.errLog.error(e.toString()); 215 } 217 } 218 219 220 221 228 private DefaultMutableTreeNode setFile(String fileLetto,String nameRoot){ 229 Cve.errLog.debug(""); 230 DefaultMutableTreeNode p1=new DefaultMutableTreeNode (nameRoot); 231 try { 232 SAXBuilder builder = new SAXBuilder(false); 234 document = builder.build(new File (fileLetto)); 235 } catch (JDOMException e) { 236 if (e.getRootCause() != null) { 237 Cve.errLog.error(e.toString()); 238 } 239 } catch (Exception e) { 240 Cve.errLog.error(e.toString()); 241 } 242 Element root=document.getRootElement(); 243 addNodes(p1,root); 244 return p1; 245 } 246 247 252 private void addNodes (DefaultMutableTreeNode pnode,Element ele){ 253 Cve.errLog.debug(""); 254 DefaultMutableTreeNode node; 255 if ((ele!=null)&&(pnode!=null)) { 256 java.util.List figli=ele.getChildren(); 257 Iterator it=figli.iterator(); 258 if (it!=null){ 259 while (it.hasNext()){ 260 Element newEle=(Element)it.next(); 261 String nome=createString(newEle); 263 node= new DefaultMutableTreeNode(nome); 264 pnode.add(node); 265 addNodes(node,newEle); 266 } 267 } 268 } 269 } 270 271 272 276 private String createString(Element ele){ 277 Cve.errLog.debug(""); 278 String app=new String (); 279 app=ele.getName(); 280 java.util.List attrList=((Element)ele).getAttributes(); 281 for (int i=0;i<attrList.size();i++){ 282 String name=((Attribute)attrList.get(i)).getName(); 283 String value=((Attribute)attrList.get(i)).getValue(); 284 app=app+" "+name+"="+value; 285 } 286 return app; 287 } 288 } 289 290 291 | Popular Tags |