2 * These are the upcalls used by the FleXML parser for application files
4 * Copyright 2006,2007,2010 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;
21 public final class ApplicationHandler {
25 * The vector which contains the arguments of the main function
26 * of the process object.
28 public static Vector<String> args;
33 public static Hashtable<String,String> properties;
36 * The name of the host of the process.
38 private static String hostName;
41 * The function of the process.
43 private static String function;
46 * This method is called by the start element handler.
47 * It sets the host and the function of the process to create,
48 * and clear the vector containing the arguments of the
49 * previouse process function if needed.
53 * @host The host of the process to create.
54 * @function The function of the process to create.
57 public static void setProcessIdentity(String hostName_, String function_) {
64 if(!properties.isEmpty())
68 * This method is called by the startElement() handler.
69 * It stores the argument of the function of the next
70 * process to create in the vector of arguments.
73 * @arg The argument to add.
75 */ public static void registerProcessArg(String arg) {
84 public static void setProperty(String id, String value)
86 properties.put(id,value);
93 public static String getHostName()
101 @SuppressWarnings("unchecked")
102 public static void createProcess() {
104 Class<Process> cls = (Class<Process>) Class.forName(function);
106 Process process = cls.newInstance();
107 process.name = function;
108 process.id = org.simgrid.msg.Process.nextProcessId++;
109 Host host = Host.getByName(hostName);
111 MsgNative.processCreate(process, host);
112 Vector<String> args_ = args;
113 int size = args_.size();
115 for (int index = 0; index < size; index++)
116 process.args.add(args_.get(index));
118 process.properties = properties;
119 properties = new Hashtable<String,String>();
121 } catch(HostNotFoundException e) {
122 System.out.println(e.toString());
125 } catch(ClassNotFoundException e) {
126 System.out.println(function +
127 " 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)");
130 } catch(InstantiationException e) {
131 System.out.println("Unable to create the process. I got an instantiation exception");
133 } catch(IllegalAccessException e) {
134 System.out.println("Unable to create the process. I got an illegal access exception");
144 public static void onStartDocument() {
145 args = new Vector<String>();
146 properties = new Hashtable<String,String>();
156 public static void onBeginProcess(String hostName, String function) {
157 setProcessIdentity(hostName, function);
165 public static void onProperty(String id, String value) {
166 setProperty(id, value);
173 public static void onProcessArg(String arg) {
174 registerProcessArg(arg);
180 public static void onEndProcess() {
187 public static void onEndDocument() {