3 * Copyright 2006,2007 Martin Quinson, Malek Cherier
6 * This program is free software; you can redistribute
7 * it and/or modify it under the terms of the license
8 * (GNU LGPL) which comes with this package.
10 * These are the upcalls used by the FleXML parser for application files
15 import java.util.Vector;
16 import java.util.Hashtable;
19 * The handler used to parse the deployment file which contains
20 * the description of the application (simulation).
22 * @author Abdelmalek Cherier
23 * @author Martin Quinson
24 * @version 1.00, 07/05/01
31 public final class ApplicationHandler {
34 * This class is used to create the processes described in the deployment file.
36 static class ProcessFactory {
38 * The vector which contains the arguments of the main function
39 * of the process object.
41 public Vector<String> args;
43 public Hashtable<String,String> properties;
46 * The name of the host of the process.
48 private String hostName;
51 * The function of the process.
53 private String function;
57 * Default constructor.
59 public ProcessFactory() {
60 this.args = new Vector<String>();
61 this.properties = new Hashtable<String,String>();
66 * This method is called by the start element handler.
67 * It sets the host and the function of the process to create,
68 * and clear the vector containing the arguments of the
69 * previouse process function if needed.
71 * @host The host of the process to create.
72 * @function The function of the process to create.
75 public void setProcessIdentity(String hostName, String function) {
76 this.hostName = hostName;
77 this.function = function;
82 if(!properties.isEmpty())
86 * This method is called by the startElement() handler.
87 * It stores the argument of the function of the next
88 * process to create in the vector of arguments.
90 * @arg The argument to add.
92 */ public void registerProcessArg(String arg) {
96 public void setProperty(String id, String value)
98 properties.put(id,value);
101 public String getHostName()
106 @SuppressWarnings("unchecked")
107 public void createProcess() {
109 Class<simgrid.msg.Process> cls = (Class<Process>) Class.forName(this.function);
111 simgrid.msg.Process process = cls.newInstance();
112 process.name = this.function;
113 process.id = simgrid.msg.Process.nextProcessId++;
114 Host host = Host.getByName(this.hostName);
116 MsgNative.processCreate(process, host);
117 Vector args = processFactory.args;
118 int size = args.size();
120 for (int index = 0; index < size; index++)
121 process.args.add(args.get(index));
123 process.properties = this.properties;
124 this.properties = new Hashtable();
126 } catch(JniException e) {
127 System.out.println(e.toString());
130 } catch(NativeException e) {
131 System.out.println(e.toString());
134 } catch(HostNotFoundException e) {
135 System.out.println(e.toString());
138 } catch(ClassNotFoundException e) {
139 System.out.println(this.function +
140 " 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)");
143 } catch(InstantiationException e) {
144 System.out.println("instantiation exception");
146 } catch(IllegalAccessException e) {
147 System.out.println("illegal access exception");
149 } catch(IllegalArgumentException e) {
150 System.out.println("illegal argument exception");
158 * the ProcessFactory object used to create the processes.
160 public static ProcessFactory processFactory;
163 * instanciates the process factory
165 public static void onStartDocument() {
166 processFactory = new ProcessFactory();
169 public static void onBeginProcess(String hostName, String function) {
170 processFactory.setProcessIdentity(hostName, function);
172 public static void onProperty(String id, String value) {
173 processFactory.setProperty(id, value);
176 public static void onProcessArg(String arg) {
177 processFactory.registerProcessArg(arg);
180 public static void onEndProcess() {
181 processFactory.createProcess();
184 public static void onEndDocument() {