KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cve > esecutori > components > automatonB > GenerationSentence


1 package cve.esecutori.components.automatonB;
2
3 import java.io.*;
4 import java.util.*;
5
6 import org.jdom.*;
7 import org.jdom.input.SAXBuilder;
8 import org.jdom.output.XMLOutputter;
9
10 import cve.esecutori.components.specificaLV.*;
11 import cve.util.ConfigurationRead;
12 import cve.staticLayout.*;
13
14 import org.apache.log4j.Logger;
15
16 /**
17 * Classe finalizzata alla generazione di una specifica wippog sentenza
18 *
19 * @see cve.esecutori.components.automatonB.WippogSent
20 *
21 * @version 1.0 09/01/02
22 * @author Domenico Ventriglia
23 */

24 public class GenerationSentence implements IGenetarationSentence {
25    private WippogSent wip;
26    private ISpecifica specifica;
27
28    /**
29    * Configurazione iniziale delle specifica sentenza
30    *
31    * @param spe il gestore della specifica scelto deve implementare ISpecifica
32    */

33    public GenerationSentence(ISpecifica spe)throws java.io.IOException JavaDoc {
34       Cve.errLog.debug("");
35       specifica=spe;
36       //String fileSent="c:/cve1.0/src/petriSent.xml";
37
wip=new WippogSent(specifica.getScheletro());
38    }
39
40    /**
41    * Generazione delle transizioni corrispodenti alle regole wcarw
42    * Result: se true tutto ok, se false allora si sono verificati errori
43    */

44    public File createGS() {
45       Cve.errLog.debug("");
46       wip.configSent ();
47       createSpe();
48       File fileLang=wip.saveFileXml("SAVE SENTENCE FILE");
49       return fileLang;
50    }
51
52    /**
53    * Simulazione del componente di creazione di specifica wippg sentenza
54    */

55    public static void main(String JavaDoc[] args) throws java.io.IOException JavaDoc {
56       // lettura alfabeto e regole
57
String JavaDoc fileA=ConfigurationRead.getCveRoot()+"/VisualLanguage/cveAlf1.xml";
58       String JavaDoc fileR=ConfigurationRead.getCveRoot()+"/VisualLanguage/cveRules1.xml";
59       // analisi dei file
60
Specifica spe=new Specifica(fileR,fileA);
61       // creazione sentenza
62
GenerationSentence gs=new GenerationSentence(spe);
63       gs.createGS();
64    }
65
66    /* ############## METODI PRIVATI ###################### */
67
68    /**
69    * Creazione di una specifica wippog sentenza
70    */

71    private void createSpe (){
72       Cve.errLog.debug("");
73       String JavaDoc idQuery;
74       // prendo istanza di Rules (collezione di regole + assert)
75
Rules speRules=specifica.getRules();
76       // prendo insieme delle regole
77
Collection rules=speRules.getRules();
78       Iterator itRul=rules.iterator();
79       // per ogni regola estraggo info
80
while(itRul.hasNext()){
81          Rule rule=(Rule)itRul.next();
82          wip.openTransition(rule.getId(),rule.getComment());
83          if (rule.getType().equals("kfree")){
84             wip.writeProduce(rule.getPostFree(),null,true);
85             wip.writeOut(null,rule.getPostFree(),true);
86             wip.writeGet(null,rule.getPostFree(),true);
87          } else {
88             wip.writeWhen(rule.getPrecondition());
89             wip.writeIf(rule.getPrecondition(),rule.getCondition());
90             wip.writeProcess(rule.getAssignmentCons());
91             wip.writeProduce(rule.getConseguent(),rule.getPrecondition(),false);
92             wip.writeOut((ElementRel)rule.getRel(),null,false);
93             wip.writeGet((ElementRel)rule.getRel(),null,false);
94          }
95          wip.closeTransition();
96       } // transizioni query
97
Collection elementNonRel=specifica.getNonRelation();
98       Iterator itEle=elementNonRel.iterator();
99       while(itEle.hasNext()){
100          ElementNonRel eleAlfNonRel=(ElementNonRel)itEle.next();
101          idQuery="Q"+"_"+eleAlfNonRel.getName();
102          wip.openTransition(idQuery,"Query element "+eleAlfNonRel.getName());
103          Vector app=new Vector();
104          app.add(eleAlfNonRel);
105          wip.writeWhen(app);
106          wip.writeIfQuery(eleAlfNonRel.getNameId());
107          wip.writeProduceQuery (app);
108          wip.writeGetQuery(eleAlfNonRel.getName());
109          wip.closeTransition();
110          idQuery="";
111       }
112    }
113
114 }
115
116
Popular Tags