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++;
105 Host host = Host.getByName(hostName);
107 MsgNative.processCreate(process, host);
108 Vector<String> args_ = args;
109 int size = args_.size();
111 for (int index = 0; index < size; index++)
112 process.args.add(args_.get(index));
114 process.properties = properties;
115 properties = new Hashtable<String,String>();
117 } catch(HostNotFoundException e) {
118 System.out.println(e.toString());
121 } catch(ClassNotFoundException e) {
122 System.out.println(function +
123 " 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)");
126 } catch(InstantiationException e) {
127 System.out.println("Unable to create the process. I got an instantiation exception");
129 } catch(IllegalAccessException e) {
130 System.out.println("Unable to create the process. I got an illegal access exception");
140 public static void onStartDocument() {
141 args = new Vector<String>();
142 properties = new Hashtable<String,String>();
152 public static void onBeginProcess(String hostName, String function) {
153 setProcessIdentity(hostName, function);
161 public static void onProperty(String id, String value) {
162 setProperty(id, value);
169 public static void onProcessArg(String arg) {
170 registerProcessArg(arg);
176 public static void onEndProcess() {
183 public static void onEndDocument() {