1 17 18 package SOFA.SOFAnode.Util.DFSRChecker; 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 23 24 import SOFA.SOFAnode.Util.DFSRChecker.DFSR.Options; 25 import SOFA.SOFAnode.Util.DFSRChecker.backend.ConsentBackend; 26 import SOFA.SOFAnode.Util.DFSRChecker.backend.DotVisBackend; 27 import SOFA.SOFAnode.Util.DFSRChecker.node.ActionRepository; 28 import SOFA.SOFAnode.Util.DFSRChecker.node.TreeNode; 29 import SOFA.SOFAnode.Util.DFSRChecker.parser.Builder; 30 import SOFA.SOFAnode.Util.DFSRChecker.parser.Debug; 31 import SOFA.SOFAnode.Util.DFSRChecker.parser.FileTokenizer; 32 import SOFA.SOFAnode.Util.DFSRChecker.parser.ProtocolReader; 33 import SOFA.SOFAnode.Util.DFSRChecker.parser.StringTokenizer; 34 import SOFA.SOFAnode.Util.SyntaxErrorException; 35 36 37 41 public class StandaloneMain { 42 43 47 public static void main(String [] args) { 48 49 String [] cldata = Options.parseCommandLine(args); 51 52 if (((cldata == null) || (cldata.length < 4)) && (Options.inputfile.equals(""))) 53 printUsageAndExit(); 54 55 56 try { 57 if ((Options.action == Options.ACTIONTESTCOMPLIANCE) || (Options.action == Options.ACTIONTESTCONSENT)) { 58 59 long ms = System.currentTimeMillis(); 60 61 ActionRepository repository = new ActionRepository(); 62 63 Object [] parsed = buildTrees(cldata, repository); 64 TreeNode[] nodes = (TreeNode[])parsed[0]; 65 String [] provs = (String [])parsed[1]; 66 String unbound = (String )parsed[2]; 67 68 String result; 69 70 result = new ConsentBackend(repository).perform(nodes, provs, unbound.split(",")).toString(); 71 72 if (result != null) 73 System.out.println(result); 74 else 75 System.out.println("OK"); 76 77 Debug.println("Taken " + (System.currentTimeMillis() - ms) / 1000 + " seconds."); 78 79 } else { ActionRepository repository = new ActionRepository(); 81 82 Object [] parsed = buildTrees(cldata, repository); 83 TreeNode[] nodes = (TreeNode[])parsed[0]; 84 String [] provs = (String [])parsed[1]; 85 String unbound = (String )parsed[2]; 86 87 88 DotVisBackend visb = new DotVisBackend(repository); 89 90 String result = visb.perform(nodes, provs, unbound.split(",")).toString(); 93 if (result != null) 94 System.out.println(result); 95 96 System.out.println("Visualization completed!"); 97 } 98 } catch (SyntaxErrorException e) { 99 System.out.println("Syntax error exception: " + e.getMessage()); 100 } 101 } 102 103 107 private static void printUsageAndExit() { 108 System.out.println("Syntax:\njava -jar checker.jar --action=<test|testconsent|visualizedot> [--verbose|-v=<0|1|2>] [--nomultinodes|-m] [--noexplicit|-e] [--noforwardcut|-f] [--nobadactivity|-b] [--nonoactivity|-n] [--infiniteactivity|-i=<yes|no|notrace>] [(--totalmem|-t)=<size>] [(--cachesize|-s)=<size>] <((--file|-f)=<inputfile>) | (<protocol1> <provisions_1_2> <protocol2> [<provisions_2_3> <protocol3>, ...] <unbound_operations)>"); 109 System.exit(1); 110 } 111 112 117 private static String removeSpaces(String src) { 118 StringBuffer buffer = new StringBuffer (src.length()); 119 120 for (int i = 0; i < src.length(); ++i) { 121 char c = src.charAt(i); 122 if (!Builder.isWhiteSpace(c)) 123 buffer.append(c); 124 } 125 126 return new String (buffer); 127 } 128 129 137 static Object [] buildTrees(String [] inputdata, ActionRepository repository) throws SyntaxErrorException { 138 TreeNode[] nodes; 139 String [] provisions; 140 String unbound; 141 142 ArrayList prots = new ArrayList (); 143 ArrayList provs = new ArrayList (); 144 Builder parser = new Builder(repository); 145 146 ProtocolReader reader; 147 148 if (Options.inputfile.equals("")) { 149 int i; 150 int j; 151 nodes = new TreeNode[inputdata.length / 2]; 152 provisions = new String [inputdata.length / 2 - 1]; 153 154 for (i = 0, j = 0; i < inputdata.length / 2 - 1; ++i) { 155 nodes[i] = parser.build(new StringTokenizer(inputdata[j++])); 156 provisions[i] = removeSpaces(inputdata[j++]); 157 } 158 159 nodes[i] = parser.build(new StringTokenizer(inputdata[j++])); 161 162 unbound = removeSpaces(inputdata[j++]); 165 166 Object [] result = new Object [3]; 167 168 result[0] = nodes; 169 result[1] = provisions; 170 result[2] = unbound; 171 172 return result; 173 174 } else { 175 try { 177 reader = new FileTokenizer(Options.inputfile); 178 } catch (IOException e) { 179 throw new SyntaxErrorException("Cannot read the source file"); 180 } 181 182 while (true) { 183 reader.resetIndex(); 184 TreeNode node = parser.build(reader); 185 if (node != null) { 186 prots.add(node); 187 provs.add(parseSynchro(reader)); 188 } else 189 break; 190 } 191 192 try { 193 reader.close(); 194 } 195 catch (IOException e) { 196 Debug.println("Warning: unable to close input file"); 197 } 198 199 nodes = new TreeNode[prots.size()]; 200 provisions = new String [provs.size() - 1]; 201 unbound = removeSpaces((String ) provs.get(provs.size() - 1)); 202 203 for (int i = 0; i < prots.size(); ++i) 204 nodes[i] = (TreeNode) prots.get(i); 205 206 for (int i = 0; i < provs.size() - 1; ++i) 207 provisions[i] = (String ) provs.get(i); 208 209 Object [] result = new Object [3]; 210 211 result[0] = nodes; 212 result[1] = provisions; 213 result[2] = unbound; 214 215 return result; 216 } 217 218 } 219 220 226 private static String parseSynchro(ProtocolReader reader) throws SyntaxErrorException { 227 String result = new String (); 228 char c; 229 230 try { 231 while ((c = (char)reader.read()) != (char)-1) 232 result += c; 233 234 Debug.println("Synchroops: " + result); 235 return result; 236 } 237 catch (IOException e) { 238 throw new SyntaxErrorException("Error while reading the input file"); 239 } 240 } 241 242 243 244 245 246 247 } 248 | Popular Tags |