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.*;
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 extends DefaultHandler
35 * This class is used to create the processes descibed in the deployment file.
40 * The vector which contains the arguments of the main function
41 * of the process object.
46 * The name of the host of the process.
48 private String hostName;
51 * The function of the process.
53 private String function;
56 * Default constructor.
58 public ProcessFactory(){
59 this.args = new Vector();
65 * This method is called by the start element handler.
66 * It sets the host and the function of the process to create,
67 * and clear the vector containing the arguments of the
68 * previouse process function if needed.
70 * @host The host of the process to create.
71 * @function The function of the process to create.
74 public void setProcessIdentity(String hostName, String function){
75 this.hostName = hostName;
76 this.function = function;
83 * This method is called by the startElement() handler.
84 * It stores the argument of the function of the next
85 * process to create in the vector of arguments.
87 * @arg The argument to add.
90 public void registerProcessArg(String arg){
94 public void createProcess(){
97 Class cls = Class.forName(this.function);
98 simgrid.msg.Process process = (simgrid.msg.Process)cls.newInstance();
99 process.name = process.getName(); //this.function;
100 process.id = simgrid.msg.Process.nextProcessId++;
101 Host host = Host.getByName(this.hostName);
102 Msg.processCreate(process,host);
103 Vector args = processFactory.args;
104 int size = args.size();
106 for(int index = 0; index < size; index++)
107 process.args.add(args.get(index));
109 } catch(JniException e)
111 System.out.println(e.toString());
114 } catch(NativeException e)
116 System.out.println(e.toString());
119 } catch(HostNotFoundException e) {
120 System.out.println(e.toString());
123 } catch(ClassNotFoundException e) {
124 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)");
127 } catch(InstantiationException e) {
128 System.out.println("instantiation exception");
130 } catch (IllegalAccessException e) {
131 System.out.println("illegal access exception");
133 } catch (IllegalArgumentException e) {
134 System.out.println("illegal argument exception");
142 * the ProcessFactory object used to create the processes.
144 private ProcessFactory processFactory;
146 public ApplicationHandler() {
150 * instanciates the process factory
152 public void startDocument(){
153 this.processFactory = new ProcessFactory();
156 public void characters(char[] caracteres, int debut, int longueur) {} // NOTHING TODO
161 public void startElement(String nameSpace, String localName,String qName,Attributes attr) {
162 if(localName.equals("process"))
163 onProcessIdentity(attr);
164 else if(localName.equals("argument"))
169 * process attributs handler.
171 public void onProcessIdentity(Attributes attr) {
172 processFactory.setProcessIdentity(attr.getValue(0),attr.getValue(1));
176 * process arguments handler.
178 public void onProcessArg(Attributes attr) {
179 processFactory.registerProcessArg(attr.getValue(0));
183 * creates the process
185 public void endElement(String nameSpace, String localName,String qName) {
186 if(localName.equals("process"))
188 processFactory.createProcess();
192 public void endDocument() {} // NOTHING TODO