Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use now the SimGrid parser instead of Xerces.
[simgrid.git] / src / java / simgrid / msg / ApplicationHandler.java
index 14d5e57..37c6e66 100644 (file)
@@ -12,8 +12,7 @@
 package simgrid.msg;
 
 import java.util.Vector;
-import org.xml.sax.*;
-import org.xml.sax.helpers.*;
+import java.util.Hashtable;
 
 /**
  * The handler used to parse the deployment file which contains 
@@ -28,17 +27,19 @@ import org.xml.sax.helpers.*;
  * @since SimGrid 3.3
  * @since JDK1.5011 
  */
-public final class ApplicationHandler extends DefaultHandler {
+public final class ApplicationHandler{
 
   /* 
    * This class is used to create the processes descibed in the deployment file.
    */
-  class ProcessFactory {
+  static class ProcessFactory {
                 /**
                 * The vector which contains the arguments of the main function 
                 * of the process object.
                 */
     public Vector args;
+    
+    public Hashtable properties;
 
                 /**
                 * The name of the host of the process.
@@ -49,12 +50,14 @@ public final class ApplicationHandler extends DefaultHandler {
                 * The function of the process.
                 */
     private String function;
+    
 
                 /**
                 * Default constructor.
                 */
     public ProcessFactory() {
       this.args = new Vector();
+      this.properties = new Hashtable();
       this.hostName = null;
       this.function = null;
     }
@@ -74,6 +77,9 @@ public final class ApplicationHandler extends DefaultHandler {
 
       if (!args.isEmpty())
         args.clear();
+        
+      if(!properties.isEmpty())
+       properties.clear();
     }
                 /**
                 * This method is called by the startElement() handler.
@@ -83,7 +89,17 @@ public final class ApplicationHandler extends DefaultHandler {
                 * @arg                                 The argument to add.
                 *
                 */ public void registerProcessArg(String arg) {
-      this.args.add(arg);
+      args.add(arg);
+    }
+    
+    public void setProperty(String id, String value)
+    {
+       properties.put(id,value);       
+    }
+    
+    public String getHostName()
+    {
+       return hostName;
     }
 
     public void createProcess() {
@@ -92,7 +108,7 @@ public final class ApplicationHandler extends DefaultHandler {
         Class cls = Class.forName(this.function);
 
         simgrid.msg.Process process = (simgrid.msg.Process) cls.newInstance();
-        process.name = process.getName();       //this.function;
+        process.name = /*process.getName();*/       this.function;
         process.id = simgrid.msg.Process.nextProcessId++;
         Host host = Host.getByName(this.hostName);
 
@@ -102,6 +118,9 @@ public final class ApplicationHandler extends DefaultHandler {
 
         for (int index = 0; index < size; index++)
           process.args.add(args.get(index));
+          
+        process.properties = this.properties;
+        this.properties = new Hashtable();
 
       } catch(JniException e) {
         System.out.println(e.toString());
@@ -137,7 +156,7 @@ public final class ApplicationHandler extends DefaultHandler {
   /* 
    * the ProcessFactory object used to create the processes.
    */
-  private ProcessFactory processFactory;
+  public static ProcessFactory processFactory;
 
   public ApplicationHandler() {
     super();
@@ -145,47 +164,27 @@ public final class ApplicationHandler extends DefaultHandler {
     /**
      * instanciates the process factory 
      */
-  public void startDocument() {
-    this.processFactory = new ProcessFactory();
-  }
-
-  public void characters(char[]caracteres, int debut, int longueur) {
-  }                             // NOTHING TODO
-
-   /**
-    * element handlers
-    */
-  public void startElement(String nameSpace, String localName, String qName,
-                           Attributes attr) {
-    if (localName.equals("process"))
-      onProcessIdentity(attr);
-    else if (localName.equals("argument"))
-      onProcessArg(attr);
+  public static void onStartDocument() {
+    processFactory = new ProcessFactory();
   }
-
-     /**
-     * process attributs handler.
-     */
-  public void onProcessIdentity(Attributes attr) {
-    processFactory.setProcessIdentity(attr.getValue(0), attr.getValue(1));
+  
+   public static void onBeginProcess(String hostName, String function)
+   {
+        processFactory.setProcessIdentity(hostName, function);
+}
+       public static void onProperty(String id, String value) {
+    processFactory.setProperty(id, value);
   }
-
-        /**
-     * process arguments handler.
-     */
-  public void onProcessArg(Attributes attr) {
-    processFactory.registerProcessArg(attr.getValue(0));
+  
+   public static void onProcessArg(String arg) {
+    processFactory.registerProcessArg(arg);
   }
-
-    /**
-     * creates the process
-     */
-  public void endElement(String nameSpace, String localName, String qName) {
-    if (localName.equals("process")) {
+  
+  public static void onEndProcess() {
+    
       processFactory.createProcess();
-    }
-  }
+  }        
 
-  public void endDocument() {
-  }                             // NOTHING TODO
+  public static void onEndDocument() {
+  }  // NOTHING TODO
 }