Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SessionsSaverLoader.java

00001 package edu.ksu.cis.bandera.bui.session;
00002 
00003 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00004  * Bandera, a Java(TM) analysis and transformation toolkit           *
00005  * Copyright (C) 2000   Robby (robby@cis.ksu.edu)                    *
00006  * All rights reserved.                                              *
00007  *                                                                   *
00008  * This work was done as a project in the SAnToS Laboratory,         *
00009  * Department of Computing and Information Sciences, Kansas State    *
00010  * University, USA (http://www.cis.ksu.edu/santos).                  *
00011  * It is understood that any modification not identified as such is  *
00012  * not covered by the preceding statement.                           *
00013  *                                                                   *
00014  * This work is free software; you can redistribute it and/or        *
00015  * modify it under the terms of the GNU Library General Public       *
00016  * License as published by the Free Software Foundation; either      *
00017  * version 2 of the License, or (at your option) any later version.  *
00018  *                                                                   *
00019  * This work is distributed in the hope that it will be useful,      *
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU *
00022  * Library General Public License for more details.                  *
00023  *                                                                   *
00024  * You should have received a copy of the GNU Library General Public *
00025  * License along with this toolkit; if not, write to the             *
00026  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,      *
00027  * Boston, MA  02111-1307, USA.                                      *
00028  *                                                                   *
00029  * Java is a trademark of Sun Microsystems, Inc.                     *
00030  *                                                                   *
00031  * To submit a bug report, send a comment, or get the latest news on *
00032  * this project and other SAnToS projects, please visit the web-site *
00033  *                http://www.cis.ksu.edu/santos                      *
00034  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00035 import java.io.*;
00036 import edu.ksu.cis.bandera.bui.session.datastructure.*;
00037 import edu.ksu.cis.bandera.bui.session.analysis.*;
00038 import edu.ksu.cis.bandera.bui.session.lexer.*;
00039 import edu.ksu.cis.bandera.bui.session.node.*;
00040 import edu.ksu.cis.bandera.bui.session.parser.*;
00041 import edu.ksu.cis.bandera.jjjc.util.*;
00042 import java.util.*;
00043 import edu.ksu.cis.bandera.bui.BUI;
00044 import edu.ksu.cis.bandera.bui.JPFOption;
00045 public class SessionsSaverLoader extends DepthFirstAdapter {
00046     private static Sessions sessions;
00047     private Session session;
00048     private StringBuffer buffer;
00049 /**
00050  * 
00051  * @param node edu.ksu.cis.bandera.bui.session.node.ASession
00052  */
00053 public void caseASession(ASession node) {
00054     session = new Session(node.getId().toString().trim());
00055     Object temp[] = node.getResource().toArray();
00056     for (int i = 0; i < temp.length; i++) {
00057         ((PResource) temp[i]).apply(this);
00058     }
00059     sessions.putSession(session);
00060 }
00061 /**
00062  * 
00063  * @param node edu.ksu.cis.bandera.bui.session.node.AStringResource
00064  */
00065 public void caseAStringResource(AStringResource node) {
00066     String key = node.getId().toString().trim();
00067     buffer = new StringBuffer();
00068     node.getStrings().apply(this);
00069 
00070     if ("source".equals(key)) {
00071         session.setFilename(buffer.toString());
00072     } else if ("classpath".equals(key)) {
00073         session.setClasspath(buffer.toString().replace('+', File.pathSeparatorChar));
00074     } else if ("included".equals(key)) {
00075         StringTokenizer t = new StringTokenizer(buffer.toString(), "+");
00076         String[] included = new String[t.countTokens()];
00077         for (int i = 0; t.hasMoreTokens(); i++) {
00078             included[i] = t.nextToken();
00079         }
00080         session.setIncludedPackagesOrTypes(included);
00081     } else if ("output".equals(key)) {
00082         session.setOutputName(buffer.toString());
00083     } else if ("directory".equals(key)) {
00084         session.setWorkingDirectory(buffer.toString());
00085     } else if ("description".equals(key)) {
00086         session.setDescription(buffer.toString());
00087     } else if ("components".equals(key)) {
00088         for (StringTokenizer tokenizer = new StringTokenizer(buffer.toString(), "+ ");
00089                 tokenizer.hasMoreTokens();) {
00090             String s = tokenizer.nextToken().toLowerCase();
00091             if ("slicer".equals(s)) {
00092                 session.setDoSlicer(true);
00093             } else if ("slabs".equals(s) || "babs".equals(s)) {
00094                 session.setDoSLABS(true);
00095             } else if ("checker".equals(s)) {
00096                 session.setDoChecker(true);
00097             }
00098         }
00099     } else if ("specification".equals(key)) {
00100         session.setSpecFilename(buffer.toString());
00101     } else if ("temporal".equals(key)) {
00102         session.setActiveTemporal(buffer.toString());
00103     } else if ("assertion".equals(key)) {
00104         for (StringTokenizer tokenizer = new StringTokenizer(buffer.toString(), "+ ");
00105                 tokenizer.hasMoreTokens();) {
00106             session.addActiveAssertion(tokenizer.nextToken());
00107         }
00108     } else if ("abstraction".equals(key)) {
00109         session.setAbsFilename(buffer.toString());
00110     } else if ("birc".equals(key)) {
00111         session.setBIRCOption(buffer.toString());
00112     } else if ("spin".equals(key)) {
00113         session.setSpinOptions(buffer.toString());
00114         session.setUseSPIN(true);
00115     } else if ("jpf".equals(key)) {
00116         session.setJpfOptions(buffer.toString());
00117         session.setUseJPF(true);
00118     } else if ("smv".equals(key)) {
00119         session.setSmvOptions(buffer.toString());
00120         session.setUseSMV(true);
00121     } else if ("dspin".equals(key)) {
00122         session.setDspinOptions(buffer.toString());
00123         session.setUseDSPIN(true);
00124     } else if ("birbounds".equals(key)) {
00125         StringTokenizer tok = new StringTokenizer(buffer.toString(), ",");
00126         int minInt, maxInt, maxArr, maxIns;
00127         try {
00128             minInt = Integer.parseInt(tok.nextToken().trim());
00129             maxInt = Integer.parseInt(tok.nextToken().trim());
00130             if (minInt > maxInt)
00131             {
00132                 System.out.println("WARNING: Illegal integer values detected!");
00133                 throw new Exception();
00134             }
00135             maxArr = Integer.parseInt(tok.nextToken().trim());
00136             maxIns = Integer.parseInt(tok.nextToken().trim());
00137         } catch (Exception e)
00138         {
00139             System.out.println("WARNING: BIR bounds setting is not acceptable. Revert to default value!");
00140             minInt = edu.ksu.cis.bandera.util.DefaultValues.birMinIntRange;
00141             maxInt = edu.ksu.cis.bandera.util.DefaultValues.birMaxIntRange;
00142             maxArr = edu.ksu.cis.bandera.util.DefaultValues.birMaxArrayLen;
00143             maxIns = edu.ksu.cis.bandera.util.DefaultValues.birMaxInstances;
00144         }
00145         session.setBirMinIntRange(minInt);
00146         session.setBirMaxIntRange(maxInt);
00147         session.setBirMaxArrayLen(maxArr);
00148         session.setBirMaxInstances(maxIns);
00149     } else {
00150         session.putResource(key, buffer.toString());
00151     }
00152 }
00153 /**
00154  * 
00155  * @param node edu.ksu.cis.bandera.bui.session.node.AStringsStrings
00156  */
00157 public void caseAStringsStrings(AStringsStrings node) {
00158     node.getStrings().apply(this);
00159     buffer.append(Util.decodeString(node.getStringLiteral().toString().trim()));
00160 }
00161 /**
00162  * 
00163  * @param node edu.ksu.cis.bandera.bui.session.node.AStringStrings
00164  */
00165 public void caseAStringStrings(AStringStrings node) {
00166     buffer.append(Util.decodeString(node.getStringLiteral().toString().trim()));
00167 }
00168 /**
00169  * 
00170  * @return edu.ksu.cis.bandera.bui.session.Sessions
00171  * @param filename java.lang.String
00172  */
00173 public static Sessions load(String filename) throws Exception {
00174     sessions = new Sessions();
00175     new Parser(new Lexer(new PushbackReader(new FileReader(filename)))).parse().apply(new SessionsSaverLoader());
00176     sessions.setFilename(filename);
00177     return sessions;
00178 }
00179 /**
00180  * 
00181  * @param sessions edu.ksu.cis.bandera.bui.session.Sessions
00182  */
00183 public static void save(Sessions sessions) throws Exception {
00184     if (sessions.getActiveSession() != null) sessions.getActiveSession().saveOptions(); 
00185     PrintWriter pw = new PrintWriter(new FileWriter(sessions.getFilename()), true);
00186     for (Enumeration e = sessions.getSessions().elements(); e.hasMoreElements();) {
00187         Session s = (Session) e.nextElement();
00188         pw.println(s.getStringRepresentation());
00189     }
00190     sessions.setSaved(true);
00191 }
00192 }

Generated at Thu Feb 7 06:54:48 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001