Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e5fd30dd63969f363340d63c04e3b5701d40cc2d
[simgrid.git] / src / java / simgrid / msg / ApplicationHandler.java
1 /*
2  * simgrid.msg.ApplicationHandler.java  1.00 07/05/01
3  *
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           
5  * All right reserved. 
6  *
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. 
10  */
11
12 package simgrid.msg;
13
14 import org.xml.sax.*;
15 import org.xml.sax.helpers.*;
16 import java.lang.reflect.*;
17
18 /**
19  * The handler used to parse the deployment file which contains 
20  * the description of the application (simulation).
21  *
22  * @author  Abdelmalek Cherier
23  * @author  Martin Quinson
24  * @version 1.00, 07/05/01
25  * @see Host
26  * @see Process
27  * @see Simulation
28  * @since SimGrid 3.3
29  * @since JDK1.5011 
30  */
31 public final class ApplicationHandler extends DefaultHandler
32 {
33         /* the current process. */
34     public simgrid.msg.Process process;
35     
36     public ApplicationHandler() {
37         super();
38     }
39     
40     public void startDocument() {} // NOTHING TODO
41     public void endDocument() {}   // NOTHING TODO
42     
43     public void characters(char[] chars, int beg, int lgr) {}   // NOTHING TODO
44     
45    /**
46     * element handlers
47     */
48     public void startElement(String nameSpace, String localName,String qName,Attributes attr)  {
49         if(localName.equals("process"))
50             onStartProcess(attr);   
51         else if(localName.equals("argument"))
52             onArgument(attr);
53     }
54     public void endElement(String nameSpace, String localName,String qName)  {
55         if(localName.equals("process"))
56             onEndProcess();   
57     }
58     
59     /**
60      * process element handler.
61      */
62     public void onStartProcess(Attributes attr) {
63         String hostName = attr.getValue(0);
64         String className = attr.getValue(1);
65                 
66         try {
67                 
68             Class cls = Class.forName(className);
69                 
70             process = (simgrid.msg.Process)cls.newInstance();
71             process.name = className;
72             process.id = simgrid.msg.Process.nextProcessId++;
73             
74             Host host = Host.getByName(hostName);
75                 
76             Msg.processCreate(process,host);
77                 
78         } catch(Exception e) {
79             e.printStackTrace();
80         } 
81     }
82     
83     public void onEndProcess() {} // NOTHING TODO   
84     
85     /**
86      * function arguments handler.
87      */
88     public void onArgument(Attributes attr) {
89         //Msg.info("Add "+attr.getValue(0)+" as argument to "+process.msgName());
90         process.addArg(attr.getValue(0));      
91     }
92     
93    /**
94     * end of element handler.
95     */
96     
97 }