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.
14 import java.util.Vector;
15 import java.util.Hashtable;
17 public final class ApplicationHandler {
20 * This class is used to create the processes described in the deployment file.
22 static class ProcessFactory {
24 * The vector which contains the arguments of the main function
25 * of the process object.
27 public Vector<String> args;
29 public Hashtable<String,String> properties;
32 * The name of the host of the process.
34 private String hostName;
37 * The function of the process.
39 private String function;
43 * Default constructor.
45 public ProcessFactory() {
46 this.args = new Vector<String>();
47 this.properties = new Hashtable<String,String>();
52 * This method is called by the start element handler.
53 * It sets the host and the function of the process to create,
54 * and clear the vector containing the arguments of the
55 * previouse process function if needed.
57 * @host The host of the process to create.
58 * @function The function of the process to create.
61 public void setProcessIdentity(String hostName, String function) {
62 this.hostName = hostName;
63 this.function = function;
68 if(!properties.isEmpty())
72 * This method is called by the startElement() handler.
73 * It stores the argument of the function of the next
74 * process to create in the vector of arguments.
76 * @arg The argument to add.
78 */ public void registerProcessArg(String arg) {
82 public void setProperty(String id, String value)
84 properties.put(id,value);
87 public String getHostName()
92 @SuppressWarnings("unchecked")
93 public void createProcess() {
95 Class<simgrid.msg.Process> cls = (Class<Process>) Class.forName(this.function);
97 simgrid.msg.Process process = cls.newInstance();
98 process.name = this.function;
99 process.id = simgrid.msg.Process.nextProcessId++;
100 Host host = Host.getByName(this.hostName);
102 MsgNative.processCreate(process, host);
103 Vector<String> args = processFactory.args;
104 int size = args.size();
106 for (int index = 0; index < size; index++)
107 process.args.add(args.get(index));
109 process.properties = this.properties;
110 this.properties = new Hashtable();
112 } catch(JniException e) {
113 System.out.println(e.toString());
116 } catch(NativeException e) {
117 System.out.println(e.toString());
120 } catch(HostNotFoundException e) {
121 System.out.println(e.toString());
124 } catch(ClassNotFoundException e) {
125 System.out.println(this.function +
126 " 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)");
129 } catch(InstantiationException e) {
130 System.out.println("instantiation exception");
132 } catch(IllegalAccessException e) {
133 System.out.println("illegal access exception");
135 } catch(IllegalArgumentException e) {
136 System.out.println("illegal argument exception");
144 * the ProcessFactory object used to create the processes.
146 public static ProcessFactory processFactory;
149 * instanciates the process factory
151 public static void onStartDocument() {
152 processFactory = new ProcessFactory();
155 public static void onBeginProcess(String hostName, String function) {
156 processFactory.setProcessIdentity(hostName, function);
158 public static void onProperty(String id, String value) {
159 processFactory.setProperty(id, value);
162 public static void onProcessArg(String arg) {
163 processFactory.registerProcessArg(arg);
166 public static void onEndProcess() {
167 processFactory.createProcess();
170 public static void onEndDocument() {