Example #1
0
  /**
   * Method for instantiating and starting the application based from the information from the
   * xml-configuration file.
   */
  public static final void start() {
    try {
      JAXBContext context = JAXBContext.newInstance(Application.class);
      Unmarshaller um = context.createUnmarshaller();

      if (configurationFile != null && configurationFile.exists()) {
        SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema =
            sf.newSchema(
                TcLoadTester.class
                    .getClassLoader()
                    .getResource("com/siemens/tcloadtester/TcLoadTester.xsd"));
        um.setSchema(schema);
        app = (Application) um.unmarshal(new FileInputStream(configurationFile));
      } else if (!gui) {
        throw new Exception("Configuration file does not exist.");
      } else {
        app = new Application();
      }

      app.init();

    } catch (Exception e) {
      if (gui) {
        UserInterface.DisplayError("Initialization error", e);
        UserInterface.loop();
      } else {
        e.printStackTrace();
      }
    }
  }
Example #2
0
  /**
   * Application entry method that opens the xml-configuration file and parses it into class
   * objects.
   *
   * @param args Args passed from command line.
   */
  public static final void main(String[] args) {
    String config;
    String output;
    String marker;

    try {
      setGlobalProperties();

      appPath =
          new File(
              TcLoadTester.class.getProtectionDomain().getCodeSource().getLocation().getPath());

      if (parseArgs(args, "-debug") != null) debug = true;
      if (parseArgs(args, "-nogui") != null) gui = false;
      if ((config = parseArgs(args, "-config")) != null) configurationFile = new File(config);
      if ((output = parseArgs(args, "-output")) != null) outputFile = new File(output);
      if ((marker = parseArgs(args, "-marker")) != null) markerId = marker;

      if (!gui && configurationFile == null) {
        usage();
        throw new Exception("No configuration defined.");
      }

      // Register shutdown hook to capture kill events
      Shutdown shutdownHook = new Shutdown();
      Runtime.getRuntime().addShutdownHook(shutdownHook.init());

      logger = new Logger();
      if (gui) {
        userInterface = new UserInterface();
        eventListeners.add(userInterface);
        UserInterface.init();
      }

      start();
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.exit(0);
  }