2 * simgrid.msg.ApplicationHandler.java 1.00 07/05/01
4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
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 import org.xml.sax.helpers.*;
20 * The handler used to parse the deployment file which contains
21 * the description of the application (simulation).
23 * @author Abdelmalek Cherier
24 * @author Martin Quinson
25 * @version 1.00, 07/05/01
32 public final class ApplicationHandler extends DefaultHandler {
35 * This class is used to create the processes descibed in the deployment file.
37 class ProcessFactory {
39 * The vector which contains the arguments of the main function
40 * of the process object.
44 public Hashtable properties;
47 * The name of the host of the process.
49 private String hostName;
52 * The function of the process.
54 private String function;
58 * Default constructor.
60 public ProcessFactory() {
61 this.args = new Vector();
62 this.properties = new Hashtable();
67 * This method is called by the start element handler.
68 * It sets the host and the function of the process to create,
69 * and clear the vector containing the arguments of the
70 * previouse process function if needed.
72 * @host The host of the process to create.
73 * @function The function of the process to create.
76 public void setProcessIdentity(String hostName, String function) {
77 this.hostName = hostName;
78 this.function = function;
80 if (!this.args.isEmpty())
83 if(!this.properties.isEmpty())
84 this.properties.clear();
87 * This method is called by the startElement() handler.
88 * It stores the argument of the function of the next
89 * process to create in the vector of arguments.
91 * @arg The argument to add.
93 */ public void registerProcessArg(String arg) {
97 public void setProperty(String id, String value)
99 this.properties.put(id,value);
102 public String getHostName()
104 return this.hostName;
107 public void createProcess() {
110 Class cls = Class.forName(this.function);
112 simgrid.msg.Process process = (simgrid.msg.Process) cls.newInstance();
113 process.name = /*process.getName();*/ this.function;
114 process.id = simgrid.msg.Process.nextProcessId++;
115 Host host = Host.getByName(this.hostName);
117 MsgNative.processCreate(process, host);
118 Vector args = processFactory.args;
119 int size = args.size();
121 for (int index = 0; index < size; index++)
122 process.args.add(args.get(index));
124 process.properties = this.properties;
125 this.properties = new Hashtable();
127 } catch(JniException e) {
128 System.out.println(e.toString());
131 } catch(NativeException e) {
132 System.out.println(e.toString());
135 } catch(HostNotFoundException e) {
136 System.out.println(e.toString());
139 } catch(ClassNotFoundException e) {
140 System.out.println(this.function +
141 " 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)");
144 } catch(InstantiationException e) {
145 System.out.println("instantiation exception");
147 } catch(IllegalAccessException e) {
148 System.out.println("illegal access exception");
150 } catch(IllegalArgumentException e) {
151 System.out.println("illegal argument exception");
159 * the ProcessFactory object used to create the processes.
161 private ProcessFactory processFactory;
163 public ApplicationHandler() {
167 * instanciates the process factory
169 public void startDocument() {
170 this.processFactory = new ProcessFactory();
173 public void characters(char[]caracteres, int debut, int longueur) {
179 public void startElement(String nameSpace, String localName, String qName,
181 if (localName.equals("process"))
182 onProcessIdentity(attr);
183 else if(localName.equals("prop"))
185 else if (localName.equals("argument"))
190 * process attributs handler.
192 public void onProcessIdentity(Attributes attr) {
193 processFactory.setProcessIdentity(attr.getValue(0), attr.getValue(1));
196 public void onProperty(Attributes attr) {
197 processFactory.setProperty(attr.getValue(0), attr.getValue(1));
201 * process arguments handler.
203 public void onProcessArg(Attributes attr) {
204 processFactory.registerProcessArg(attr.getValue(0));
208 * creates the process
210 public void endElement(String nameSpace, String localName, String qName) {
211 if (localName.equals("process")) {
212 processFactory.createProcess();
216 public void endDocument() {