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 {
34 * This class is used to create the processes descibed in the deployment file.
36 class ProcessFactory {
38 * The vector which contains the arguments of the main function
39 * of the process object.
44 * The name of the host of the process.
46 private String hostName;
49 * The function of the process.
51 private String function;
54 * Default constructor.
56 public ProcessFactory() {
57 this.args = new Vector();
62 * This method is called by the start element handler.
63 * It sets the host and the function of the process to create,
64 * and clear the vector containing the arguments of the
65 * previouse process function if needed.
67 * @host The host of the process to create.
68 * @function The function of the process to create.
71 public void setProcessIdentity(String hostName, String function) {
72 this.hostName = hostName;
73 this.function = function;
79 * This method is called by the startElement() handler.
80 * It stores the argument of the function of the next
81 * process to create in the vector of arguments.
83 * @arg The argument to add.
85 */ public void registerProcessArg(String arg) {
89 public void createProcess() {
92 Class cls = Class.forName(this.function);
94 simgrid.msg.Process process = (simgrid.msg.Process) cls.newInstance();
95 process.name = process.getName(); //this.function;
96 process.id = simgrid.msg.Process.nextProcessId++;
97 Host host = Host.getByName(this.hostName);
99 MsgNative.processCreate(process, host);
100 Vector args = processFactory.args;
101 int size = args.size();
103 for (int index = 0; index < size; index++)
104 process.args.add(args.get(index));
106 } catch(JniException e) {
107 System.out.println(e.toString());
110 } catch(NativeException e) {
111 System.out.println(e.toString());
114 } catch(HostNotFoundException e) {
115 System.out.println(e.toString());
118 } catch(ClassNotFoundException e) {
119 System.out.println(this.function +
120 " 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)");
123 } catch(InstantiationException e) {
124 System.out.println("instantiation exception");
126 } catch(IllegalAccessException e) {
127 System.out.println("illegal access exception");
129 } catch(IllegalArgumentException e) {
130 System.out.println("illegal argument exception");
138 * the ProcessFactory object used to create the processes.
140 private ProcessFactory processFactory;
142 public ApplicationHandler() {
146 * instanciates the process factory
148 public void startDocument() {
149 this.processFactory = new ProcessFactory();
152 public void characters(char[]caracteres, int debut, int longueur) {
158 public void startElement(String nameSpace, String localName, String qName,
160 if (localName.equals("process"))
161 onProcessIdentity(attr);
162 else if (localName.equals("argument"))
167 * process attributs handler.
169 public void onProcessIdentity(Attributes attr) {
170 processFactory.setProcessIdentity(attr.getValue(0), attr.getValue(1));
174 * process arguments handler.
176 public void onProcessArg(Attributes attr) {
177 processFactory.registerProcessArg(attr.getValue(0));
181 * creates the process
183 public void endElement(String nameSpace, String localName, String qName) {
184 if (localName.equals("process")) {
185 processFactory.createProcess();
189 public void endDocument() {