KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > util > state > LoadHandler


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.util.state;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Hashtable JavaDoc;
11 import java.util.Map JavaDoc;
12
13 import org.xml.sax.Attributes JavaDoc;
14 import org.xml.sax.SAXException JavaDoc;
15 import org.xml.sax.helpers.DefaultHandler JavaDoc;
16
17
18 /**
19  * @author Laurent Etiemble
20  * @version $Revision: 1.2 $
21  */

22 public class LoadHandler extends DefaultHandler JavaDoc
23 {
24    /** Description of the Field */
25    private Map JavaDoc context = new HashMap JavaDoc();
26    /** Description of the Field */
27    private String JavaDoc path = "";
28    /** Description of the Field */
29    private Map JavaDoc rules = new Hashtable JavaDoc();
30
31    /** Description of the Field */
32    public final static String JavaDoc ATTRIBUTES = "ATTRIBUTES";
33    /** Description of the Field */
34    public final static String JavaDoc ELEMENT = "ELEMENT";
35    /** Description of the Field */
36    public final static String JavaDoc TEXT = "TEXT";
37
38
39    /**Constructor for the WorkbenchHandler object */
40    public LoadHandler() { }
41
42
43    /**
44     * Adds a feature to the Rule attribute of the WorkbenchHandler object
45     *
46     * @param path The feature to be added to the Rule attribute
47     * @param rule The feature to be added to the Rule attribute
48     */

49    public void addRule(String JavaDoc path, Rule rule)
50    {
51       this.rules.put(path, rule);
52    }
53
54
55    /**
56     * Description of the Method
57     *
58     * @param ch Description of the Parameter
59     * @param start Description of the Parameter
60     * @param length Description of the Parameter
61     * @exception SAXException Description of the Exception
62     */

63    public void characters(char[] ch, int start, int length)
64       throws SAXException JavaDoc
65    {
66       String JavaDoc text = new String JavaDoc(ch, start, length);
67       this.context.put("TEXT", text);
68       Rule rule = (Rule) this.rules.get(this.path);
69       if (rule != null)
70       {
71          rule.loadBody(this.context);
72       }
73    }
74
75
76    /**
77     * Description of the Method
78     *
79     * @param uri Description of the Parameter
80     * @param localName Description of the Parameter
81     * @param qName Description of the Parameter
82     * @exception SAXException Description of the Exception
83     */

84    public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName)
85       throws SAXException JavaDoc
86    {
87       this.context.put("ELEMENT", qName);
88       Rule rule = (Rule) this.rules.get(this.path);
89       if (rule != null)
90       {
91          rule.loadExit(this.context);
92       }
93       this.path = this.path.substring(0, this.path.length() - qName.length() - 1);
94    }
95
96
97    /**
98     * Gets the context attribute of the LoadHandler object
99     *
100     * @return The context value
101     */

102    public Map JavaDoc getContext()
103    {
104       return this.context;
105    }
106
107
108    /**
109     * Description of the Method
110     *
111     * @param uri Description of the Parameter
112     * @param localName Description of the Parameter
113     * @param qName Description of the Parameter
114     * @param attributes Description of the Parameter
115     * @exception SAXException Description of the Exception
116     */

117    public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc attributes)
118       throws SAXException JavaDoc
119    {
120       this.context.put("ELEMENT", qName);
121       this.context.put("ATTRIBUTES", attributes);
122       this.path = path + "/" + qName;
123       Rule rule = (Rule) this.rules.get(this.path);
124       if (rule != null)
125       {
126          rule.loadEnter(this.context);
127       }
128    }
129 }
130
Popular Tags