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;
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;
26 public static Hashtable<String,String> properties;
29 * The name of the host of the process.
31 private static String hostName;
34 * The function of the process.
36 private static String function;
39 * This method is called by the start element handler.
40 * It sets the host and the function of the process to create,
41 * and clear the vector containing the arguments of the
42 * previouse process function if needed.
44 * @host The host of the process to create.
45 * @function The function of the process to create.
48 public static void setProcessIdentity(String hostName_, String function_) {
55 if(!properties.isEmpty())
59 * This method is called by the startElement() handler.
60 * It stores the argument of the function of the next
61 * process to create in the vector of arguments.
63 * @arg The argument to add.
65 */ public static void registerProcessArg(String arg) {
69 public static void setProperty(String id, String value)
71 properties.put(id,value);
74 public static String getHostName()
79 @SuppressWarnings("unchecked")
80 public static void createProcess() {
82 Class<Process> cls = (Class<Process>) Class.forName(function);
84 Process process = cls.newInstance();
85 process.name = function;
86 process.id = org.simgrid.msg.Process.nextProcessId++;
87 Host host = Host.getByName(hostName);
89 MsgNative.processCreate(process, host);
90 Vector<String> args_ = args;
91 int size = args_.size();
93 for (int index = 0; index < size; index++)
94 process.args.add(args_.get(index));
96 process.properties = properties;
97 properties = new Hashtable<String,String>();
99 } catch(HostNotFoundException e) {
100 System.out.println(e.toString());
103 } catch(ClassNotFoundException e) {
104 System.out.println(function +
105 " 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)");
108 } catch(InstantiationException e) {
109 System.out.println("Unable to create the process. I got an instantiation exception");
111 } catch(IllegalAccessException e) {
112 System.out.println("Unable to create the process. I got an illegal access exception");
119 public static void onStartDocument() {
120 args = new Vector<String>();
121 properties = new Hashtable<String,String>();
126 public static void onBeginProcess(String hostName, String function) {
127 setProcessIdentity(hostName, function);
130 public static void onProperty(String id, String value) {
131 setProperty(id, value);
134 public static void onProcessArg(String arg) {
135 registerProcessArg(arg);
138 public static void onEndProcess() {
142 public static void onEndDocument() {