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;
16 import org.xml.sax.helpers.*;
17 import java.lang.reflect.*;
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
36 * This class is used to create the processes descibed in the deployment file.
41 * The vector which contains the arguments of the main function
42 * of the process object.
44 public Vector<String> args;
47 * The name of the host of the process.
49 private String hostName;
52 * The function of the process.
54 private String function;
57 * Default constructor.
59 public ProcessFactory(){
60 this.args = new Vector<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;
84 * This method is called by the startElement() handler.
85 * It stores the argument of the function of the next
86 * process to create in the vector of arguments.
88 * @arg The argument to add.
91 public void registerProcessArg(String arg){
95 public void createProcess(){
98 System.out.println("Create process " + function + " on the host " + hostName);
99 Class cls = Class.forName(this.function);
100 simgrid.msg.Process process = (simgrid.msg.Process)cls.newInstance();
101 process.name = process.getName(); //this.function;
102 process.id = simgrid.msg.Process.nextProcessId++;
103 Host host = Host.getByName(this.hostName);
104 Msg.processCreate(process,host);
106 Vector<String> args = processFactory.args;
107 int size = args.size();
109 for(int index = 0; index < size; index++)
110 process.addArg(args.get(index));
112 } catch(JniException e)
114 System.out.println(e.toString());
117 } catch(NativeException e)
119 System.out.println(e.toString());
122 } catch(HostNotFoundException e) {
123 System.out.println(e.toString());
126 } catch(ClassNotFoundException e) {
127 System.out.println(this.function + " 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("instantiation exception");
133 } catch (IllegalAccessException e) {
134 System.out.println("illegal access exception");
136 } catch (IllegalArgumentException e) {
137 System.out.println("illegal argument exception");
145 * the ProcessFactory object used to create the processes.
147 private ProcessFactory processFactory;
149 public ApplicationHandler() {
153 * instanciates the process factory
155 public void startDocument(){
156 this.processFactory = new ProcessFactory();
159 public void characters(char[] caracteres, int debut, int longueur) {} // NOTHING TODO
164 public void startElement(String nameSpace, String localName,String qName,Attributes attr) {
165 if(localName.equals("process"))
166 onProcessIdentity(attr);
167 else if(localName.equals("argument"))
172 * process attributs handler.
174 public void onProcessIdentity(Attributes attr) {
175 processFactory.setProcessIdentity(attr.getValue(0),attr.getValue(1));
179 * process arguments handler.
181 public void onProcessArg(Attributes attr) {
182 processFactory.registerProcessArg(attr.getValue(0));
186 * creates the process
188 public void endElement(String nameSpace, String localName,String qName) {
189 if(localName.equals("process"))
191 processFactory.createProcess();
195 public void endDocument() {} // NOTHING TODO