KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > report > element > ElementContentHandler


1 package csdl.jblanket.report.element;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Iterator JavaDoc;
5 import java.util.Map JavaDoc;
6
7 import org.xml.sax.Attributes JavaDoc;
8 import org.xml.sax.ContentHandler JavaDoc;
9 import org.xml.sax.Locator JavaDoc;
10 import org.xml.sax.SAXException JavaDoc;
11
12 /**
13  * Handles the content of an XML file as it is encountered by the SAX parser for the report.
14  * <p>
15  * NOTE: Method descriptions taken from org.xml.sax.ContentHandler.
16  *
17  * @author Joy M. Agustin
18  * @version $Id: ElementContentHandler.java,v 1.2 2004/11/07 08:53:26 timshadel Exp $
19  */

20 public class ElementContentHandler implements ContentHandler JavaDoc {
21
22   /** Locates any content handler event in the XML source document */
23   private Locator JavaDoc locator;
24   /** Container for names spaces */
25   private Map JavaDoc namespaceMappings;
26
27   /** Set of all MethodSets */
28   private MethodSetsElement methodSets;
29   /** Current MethodElement being processed */
30   private MethodElement currentMethodElement;
31
32   /** Category of methods being processed */
33   private String JavaDoc methodCategory;
34
35   private String JavaDoc timeStamp;
36
37
38   /**
39    * Constructs a new ElementContentHandler object.
40    *
41    * @param methodSets the set of MethodSets being processed.
42    * @param methodCategory the category of methods being processed.
43    */

44   public ElementContentHandler(MethodSetsElement methodSets, String JavaDoc methodCategory) {
45     
46     this.namespaceMappings = new HashMap JavaDoc();
47
48     this.methodSets = methodSets;
49
50     this.methodCategory = methodCategory;
51   }
52
53   /**
54    * Processes notification of character data -- not implemented.
55    *
56    * @param chars the characters making up the data within the element.
57    * @param start the starting index of characters.
58    * @param length the number of characters in <code>chars</code>.
59    * @throws SAXException if any SAX error occurs.
60    */

61   public void characters(char[] chars, int start, int length) throws SAXException JavaDoc {
62   }
63
64   /**
65    * Processes notification of the end of a document -- not implemented.
66    *
67    * @throws SAXException if any SAX error occurs.
68    */

69   public void endDocument() throws SAXException JavaDoc {
70   }
71
72   /**
73    * Processes notification of the end of an element.
74    *
75    * @param namespaceURI namespace URI of current element in context wrt document's complete set of
76    * namespaces.
77    * @param localName local, unprefixed name of current element.
78    * @param qName unmodified, unchanged name of current element.
79    * @throws SAXException if any SAX error occurs.
80    */

81   public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName)
82       throws SAXException JavaDoc {
83       
84     if (!localName.equals("Method")) {
85       return;
86     }
87     
88     // get MethodSetElement from methodSetMap
89
String JavaDoc className = this.currentMethodElement.getClassName();
90     MethodSetElement methodSet = (MethodSetElement) this.methodSets.get(className);
91     if (methodSet == null) {
92       String JavaDoc packageName = className.substring(0, className.lastIndexOf("."));
93       methodSet = new MethodSetElement(className.substring(0, className.lastIndexOf(".")),
94                                         className.substring(className.lastIndexOf(".") + 1));
95       this.methodSets.put(className, methodSet);
96     }
97
98     if ("tested".equals(this.methodCategory)) {
99       methodSet.addTestMethod(this.currentMethodElement);
100     }
101     else if ("untested".equals(this.methodCategory)) {
102       methodSet.addUntestMethod(this.currentMethodElement);
103     }
104     else if ("untestable".equals(this.methodCategory)) {
105         methodSet.addUntestableMethod(this.currentMethodElement);
106       }
107     else if ("oneline".equals(this.methodCategory)) {
108       methodSet.addOneLineMethod(this.currentMethodElement);
109     }
110     else if ("constructor".equals(this.methodCategory)) {
111       methodSet.addConstructorMethod(this.currentMethodElement);
112     }
113     else if ("excludedIndividual".equals(this.methodCategory)) {
114       methodSet.addExcludedIndividualMethod(this.currentMethodElement);
115     }
116
117     // get time stamp
118
methodSet.setTimeStamp(this.timeStamp);
119   }
120
121   /**
122    * Processes end of the scope of a prefix-URI mapping.
123    *
124    * @param prefix the prefix that was being mapped.
125    * @throws SAXException if any SAX error occurs.
126    */

127   public void endPrefixMapping(String JavaDoc prefix) throws SAXException JavaDoc {
128     
129     for (Iterator JavaDoc i = this.namespaceMappings.keySet().iterator(); i.hasNext(); ) {
130       String JavaDoc uri = (String JavaDoc) i.next();
131       String JavaDoc thisPrefix = (String JavaDoc) this.namespaceMappings.get(uri);
132       if (prefix.equals(thisPrefix)) {
133         this.namespaceMappings.remove(uri);
134         break;
135       }
136     }
137   }
138
139   /**
140    * Processes notification of ignorable whitespace in element content -- not implemented.
141    *
142    * @param chars the characters making up the data within the element.
143    * @param start the starting index of characters.
144    * @param length the number of characters in <code>chars</code>.
145
146    * @throws SAXException if any SAX error occurs.
147    */

148   public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException JavaDoc {
149   }
150
151   /**
152    * Processes notification of a processing instruction -- not implemented.
153    *
154    * @param target the processing instruction target.
155    * @param data the processing instruction data, or null if none was supplied.
156    * @throws SAXException if any SAX error occurs.
157    */

158   public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc {
159   }
160
161   /**
162    * Processes an object for locating the origin of SAX document events.
163    *
164    * @param locator an object that can return the location of any SAX document event.
165    */

166   public void setDocumentLocator(Locator JavaDoc locator) {
167     this.locator = locator;
168   }
169
170   /**
171    * Processes notification of a skipped entity -- not implemented.
172    *
173    * @param name the name of the skipped entry.
174    * @throws SAXException if any SAX error occurs.
175    */

176   public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc {
177   }
178
179   /**
180    * Processes notification of the beginning of a document - not implememented.
181    *
182    * @throws SAXException if any SAX error occurs.
183    */

184   public void startDocument() throws SAXException JavaDoc {
185   }
186
187   /**
188    * Processes notification of the beginning of an element.
189    *
190    * @param namespaceURI namespace URI of current element in context wrt document's complete set of
191    * namespaces.
192    * @param localName local, unprefixed name of current element.
193    * @param qName unmodified, unchanged name of current element.
194    * @param atts reference to all of the attributes within current element.
195    * @throws SAXException if any SAX error occurs.
196    */

197   public void startElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts)
198     throws SAXException JavaDoc {
199       
200     if (localName.equals("MethodSet")) {
201
202       this.timeStamp = atts.getValue("timestamp");
203     }
204     else if (localName.equals("Method")) {
205
206       // get class name
207
String JavaDoc className = atts.getValue("class");
208       String JavaDoc methodName = atts.getValue("method");
209       MethodElement method = new MethodElement(className, methodName);
210
211       //this.methodSetsMap.put(className, method);
212
this.currentMethodElement = method;
213     }
214     else if (localName.equals("Parameter")) {
215
216       ParameterElement parameter = new ParameterElement(atts.getValue("type"));
217       this.currentMethodElement.addParameter(parameter);
218     }
219
220   }
221
222   /**
223    * Processes begin of the scope of a prefix-URI Namespace mapping.
224    *
225    * @param prefix the namespace prefix being declared.
226    * @param uri the namespace URI the prefix is mapped to.
227    * @throws SAXException if any SAX error occurs.
228    */

229   public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) throws SAXException JavaDoc {
230     this.namespaceMappings.put(uri, prefix);
231   }
232 }
233
Popular Tags