KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnode > Util > DFSRChecker > DFSR > Options


1 /*
2  * $Id: Options.java,v 1.4 2005/07/08 12:04:11 kofron Exp $
3  *
4  * Copyright 2004
5  * Distributed Systems Research Group
6  * Department of Software Engineering
7  * Faculty of Mathematics and Physics
8  * Charles University, Prague
9  *
10  * Copyright 2005
11  * Formal Methods In Software Engineering Group
12  * Institute of Computer Science
13  * Academy of Sciences of the Czech Republic
14  *
15  * This code was developed by Jan Kofron <kofron@nenya.ms.mff.cuni.cz>
16  */

17
18 package SOFA.SOFAnode.Util.DFSRChecker.DFSR;
19
20
21 import SOFA.SOFAnode.Util.DFSRChecker.parser.Debug;
22
23 import com.martiansoftware.jsap.*;
24 import com.martiansoftware.jsap.stringparsers.IntegerStringParser;
25 import com.martiansoftware.jsap.stringparsers.StringStringParser;
26
27 /**
28  * This class contains the options for the checker program.
29  */

30 public class Options {
31     /**
32      * Visualization type constants
33      */

34     public static final int DOTVISUALIZATION = 1;
35
36     /**
37      * Action constants
38      */

39     public static final int ACTIONTESTCOMPLIANCE = 1;
40
41     public static final int ACTIONTESTCONSENT = 2;
42
43     public static final int ACTIONVISUALIZE = 3;
44     
45     /**
46      * infinite activity constant
47      */

48     public static final int IAYES = 0;
49     
50     public static final int IANO = 1;
51     
52     public static final int IANOTRACE = 2;
53     
54     
55     /**
56      * Action type - testing or visualization.
57      */

58     public static int action = ACTIONTESTCOMPLIANCE;
59
60     /**
61      * Multinodes optimization
62      */

63     public static boolean multinodes = true;
64
65     /**
66      * Forward cutting optimization
67      */

68     public static boolean forwardcutting = true;
69
70     /**
71      * Explicit automata optimization
72      */

73     public static boolean explicit = false;
74
75     public static int explicitsize = 1000;
76
77     /**
78      * The total amount of memory available to the checker data in MB Note that
79      * the program itself need additional 10 - 15 MB for itself.
80      */

81     public static int totalmemory = 60;
82
83     /**
84      * Minimal amount of memory dedicated to the state cache in MB
85      */

86     public static int statememory = 48;
87
88     /**
89      * Visualization option - visualization of the tree 0 stands for no
90      * visualization
91      */

92     public static int visualizationtype = 0;
93     
94     /**
95      * Types of checking while using the consent operator, default = true
96      */

97     public static boolean badactivity = true;
98     public static boolean noactivity = true;
99     public static int infiniteactivity = 1;
100     
101     /**
102      * The name of a file containing the input protocols
103      */

104     public static String JavaDoc inputfile = "";
105     
106     /**
107      * Parses the command line
108      *
109      * @param args
110      * Command-line arguments to be parsed
111      */

112     public static String JavaDoc[] parseCommandLine(String JavaDoc[] args) {
113         JSAP jsap;
114         JSAPResult res;
115         
116         try {
117             jsap = new JSAP();
118             IntegerStringParser isp = JSAP.INTEGER_PARSER;
119             StringStringParser ssp = JSAP.STRING_PARSER;
120             
121             jsap.registerParameter(new FlaggedOption("action", ssp, "test", JSAP.REQUIRED, 'a', "action" ) );
122             jsap.registerParameter(new Switch("disablemultinodes",'m',"nomultinodes") );
123             jsap.registerParameter(new Switch("disableexplicit",'e',"noexplicit") );
124             jsap.registerParameter(new Switch("disableforwardcut",'c',"noforwardcut") );
125             jsap.registerParameter(new Switch("disablebadactivity", 'b', "nobadactivity"));
126             jsap.registerParameter(new Switch("disablenoactivity", 'n', "nonoactivity"));
127             jsap.registerParameter(new FlaggedOption("verbose", ssp, "0", JSAP.NOT_REQUIRED, 'v', "verbose" ) );
128             jsap.registerParameter(new FlaggedOption("infiniteactivity", ssp, "notrace", JSAP.NOT_REQUIRED, 'i', "infiniteactivity"));
129             jsap.registerParameter(new FlaggedOption("file", ssp, "", JSAP.NOT_REQUIRED, 'f', "file" ) );
130
131             jsap.registerParameter(new FlaggedOption("totalmem", isp, "60", JSAP.NOT_REQUIRED, 't', "totalmem" ) );
132             jsap.registerParameter(new FlaggedOption("cachesize", isp, "48", JSAP.NOT_REQUIRED, 's', "cachesize" ) );
133             
134             UnflaggedOption parameters = new UnflaggedOption("protocolsetc", ssp, "", true, true);
135
136             jsap.registerParameter(parameters);
137             
138             res = jsap.parse(args);
139             
140             if (!res.success())
141                 return null;
142             
143         } catch (Exception JavaDoc e) {
144             return null;
145         }
146         
147         String JavaDoc _action = res.getString("action");
148         
149         if (_action.equals("test"))
150             action = ACTIONTESTCOMPLIANCE;
151         else if (_action.equals("testconsent"))
152             action = ACTIONTESTCONSENT;
153         //else if (_action.equals("testnoconsent"))
154
// action = ACTIONTESTNOCONSENT;
155
else if (_action.equals("visualizedot")) {
156             action = ACTIONVISUALIZE;
157             visualizationtype = DOTVISUALIZATION;
158         }
159         else
160             return null;
161         
162         
163         if (res.getBoolean("disablemultinodes"))
164             multinodes = false;
165         
166         if (res.getBoolean("disableexplicit"))
167             explicit = false;
168         
169         if (res.getBoolean("disableforwardcut"))
170             forwardcutting = false;
171         
172         if (res.getBoolean("disablebadactivity"))
173             badactivity = false;
174         
175         if (res.getBoolean("disablenoactivity"))
176             noactivity = false;
177         
178         String JavaDoc ia = res.getString("infiniteactivity");
179         
180         if (ia.equals("yes"))
181             infiniteactivity = IAYES;
182         else if (ia.equals("no"))
183             infiniteactivity = IANO;
184         else if (ia.equals("notrace"))
185             infiniteactivity = IANOTRACE;
186         else
187             return null;
188         
189         String JavaDoc verbose = res.getString("verbose");
190         
191         if (verbose.equals("0"))
192              Debug.setLevel(0);
193         else if (verbose.equals("1"))
194             Debug.setLevel(2);
195         else if (verbose.equals("2"))
196             Debug.setLevel(3);
197         else
198             return null;
199
200         totalmemory = res.getInt("totalmem");
201         statememory = res.getInt("cachesize");
202         
203         Options.inputfile = res.getString("file");
204         
205         return res.getStringArray("protocolsetc");
206     }
207 }
208
Popular Tags