2 * These are the upcalls used by the FleXML parser for application files
4 * Copyright 2006,2007,2010,2011 The SimGrid team.
7 * This program is free software; you can redistribute
8 * it and/or modify it under the terms of the license
9 * (GNU LGPL) which comes with this package.
12 package org.simgrid.msg;
14 import java.util.Hashtable;
15 import java.util.Vector;
17 public final class ApplicationHandler {
21 * The vector which contains the arguments of the main function
22 * of the process object.
24 public static Vector<String> args;
29 public static Hashtable<String,String> properties;
32 * The name of the host of the process.
34 private static String hostName;
37 * The function of the process.
39 private static String function;
42 * This method is called by the start element handler.
43 * It sets the host and the function of the process to create,
44 * and clear the vector containing the arguments of the
45 * previouse process function if needed.
49 * @host The host of the process to create.
50 * @function The function of the process to create.
53 public static void setProcessIdentity(String hostName_, String function_) {
60 if(!properties.isEmpty())
64 * This method is called by the startElement() handler.
65 * It stores the argument of the function of the next
66 * process to create in the vector of arguments.
69 * @arg The argument to add.
71 */ public static void registerProcessArg(String arg) {
80 public static void setProperty(String id, String value)
82 properties.put(id,value);
89 public static String getHostName()
97 @SuppressWarnings("unchecked")
98 public static void createProcess() {
100 Class<Process> cls = (Class<Process>) Class.forName(function);
102 Process process = cls.newInstance();
103 process.name = function;
104 process.id = org.simgrid.msg.Process.nextProcessId++;
106 MsgNative.processCreate(process, hostName);
107 Vector<String> args_ = args;
108 int size = args_.size();
110 for (int index = 0; index < size; index++)
111 process.args.add(args_.get(index));
113 process.properties = properties;
114 properties = new Hashtable<String,String>();
116 } catch(HostNotFoundException e) {
117 System.out.println(e.toString());
120 } catch(ClassNotFoundException e) {
121 System.out.println(function +
122 " class not found\n The attribut function of the element process of your deployment file\n must correspond to the name of a Msg Proces class)");
125 } catch(InstantiationException e) {
126 System.out.println("Unable to create the process. I got an instantiation exception");
128 } catch(IllegalAccessException e) {
129 System.out.println("Unable to create the process. I got an illegal access exception");
139 public static void onStartDocument() {
140 args = new Vector<String>();
141 properties = new Hashtable<String,String>();
151 public static void onBeginProcess(String hostName, String function) {
152 setProcessIdentity(hostName, function);
160 public static void onProperty(String id, String value) {
161 setProperty(id, value);
168 public static void onProcessArg(String arg) {
169 registerProcessArg(arg);
175 public static void onEndProcess() {
182 public static void onEndDocument() {