001: /*
002: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
003: * California. All rights reserved.
004: *
005: * Permission to use, copy, modify, and distribute this software and its
006: * documentation for any purpose, without fee, and without written agreement is
007: * hereby granted, provided that the above copyright notice and the following
008: * two paragraphs appear in all copies of this software.
009: *
010: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014: *
015: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
018: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020: *
021: * Author: Matt Welsh <mdw@cs.berkeley.edu>
022: *
023: */
024:
025: package seda.sandStorm.main;
026:
027: import seda.sandStorm.api.*;
028: import seda.sandStorm.api.internal.*;
029: import seda.sandStorm.core.*;
030: import seda.sandStorm.internal.*;
031: import java.io.IOException;
032: import java.util.Date;
033:
034: /**
035: * This class is used to start a Sandstorm system from the commandline.
036: * The usage is:
037: * <pre>
038: * java seda.sandStorm.main.Main <configuration file> [initargs]
039: * </pre>
040: *
041: * A Sandstorm can be embedded within an application using the
042: * <tt>Sandstorm</tt> class.
043: *
044: * @author Matt Welsh
045: * @see Sandstorm
046: *
047: */
048: public class Main {
049:
050: private static void usage() {
051: System.err.println("Usage:");
052: System.err
053: .println("\tjava seda.sandStorm.main.Main [-profile] <configfile> [initargs]\n");
054: System.exit(-1);
055: }
056:
057: public static void main(String args[]) {
058:
059: try {
060:
061: Date d = new Date();
062: if (args.length < 1)
063: usage();
064:
065: System.out.println(sandStormConst.WELCOME_STRING);
066: System.out.println(" Starting at " + d.toString() + "\n");
067:
068: int n;
069: boolean PROFILE = false;
070:
071: if ((args.length > 1) && (args[0].equals("-profile"))) {
072: PROFILE = true;
073: n = 1;
074: } else {
075: n = 0;
076: }
077:
078: int numinitargs = args.length - n - 1;
079: String initargs[] = null;
080: if (numinitargs > 0) {
081: initargs = new String[numinitargs];
082: for (int j = 0; j < numinitargs; j++) {
083: initargs[j] = args[n + 1 + j];
084: }
085: }
086:
087: // -profile option overrides configuration file
088: SandstormConfig sscfg;
089: try {
090: sscfg = new SandstormConfig(args[n], initargs);
091: } catch (IOException fnfe) {
092: System.err.println("Error opening configuration file '"
093: + args[n] + "': " + fnfe);
094: fnfe.printStackTrace();
095: usage();
096: return;
097: }
098: if (PROFILE)
099: sscfg.putBoolean("global.profile.enable", true);
100: Sandstorm ss = new Sandstorm(sscfg);
101:
102: } catch (Exception e) {
103: System.err.println("Sandstorm.main(): Got exception: " + e);
104: e.printStackTrace();
105: }
106:
107: }
108: }
|