1 package csdl.jblanket.report.element; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 import java.util.Map ; 6 7 import org.xml.sax.Attributes ; 8 import org.xml.sax.ContentHandler ; 9 import org.xml.sax.Locator ; 10 import org.xml.sax.SAXException ; 11 12 20 public class ElementContentHandler implements ContentHandler { 21 22 23 private Locator locator; 24 25 private Map namespaceMappings; 26 27 28 private MethodSetsElement methodSets; 29 30 private MethodElement currentMethodElement; 31 32 33 private String methodCategory; 34 35 private String timeStamp; 36 37 38 44 public ElementContentHandler(MethodSetsElement methodSets, String methodCategory) { 45 46 this.namespaceMappings = new HashMap (); 47 48 this.methodSets = methodSets; 49 50 this.methodCategory = methodCategory; 51 } 52 53 61 public void characters(char[] chars, int start, int length) throws SAXException { 62 } 63 64 69 public void endDocument() throws SAXException { 70 } 71 72 81 public void endElement(String namespaceURI, String localName, String qName) 82 throws SAXException { 83 84 if (!localName.equals("Method")) { 85 return; 86 } 87 88 String className = this.currentMethodElement.getClassName(); 90 MethodSetElement methodSet = (MethodSetElement) this.methodSets.get(className); 91 if (methodSet == null) { 92 String 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 methodSet.setTimeStamp(this.timeStamp); 119 } 120 121 127 public void endPrefixMapping(String prefix) throws SAXException { 128 129 for (Iterator i = this.namespaceMappings.keySet().iterator(); i.hasNext(); ) { 130 String uri = (String ) i.next(); 131 String thisPrefix = (String ) this.namespaceMappings.get(uri); 132 if (prefix.equals(thisPrefix)) { 133 this.namespaceMappings.remove(uri); 134 break; 135 } 136 } 137 } 138 139 148 public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException { 149 } 150 151 158 public void processingInstruction(String target, String data) throws SAXException { 159 } 160 161 166 public void setDocumentLocator(Locator locator) { 167 this.locator = locator; 168 } 169 170 176 public void skippedEntity(String name) throws SAXException { 177 } 178 179 184 public void startDocument() throws SAXException { 185 } 186 187 197 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) 198 throws SAXException { 199 200 if (localName.equals("MethodSet")) { 201 202 this.timeStamp = atts.getValue("timestamp"); 203 } 204 else if (localName.equals("Method")) { 205 206 String className = atts.getValue("class"); 208 String methodName = atts.getValue("method"); 209 MethodElement method = new MethodElement(className, methodName); 210 211 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 229 public void startPrefixMapping(String prefix, String uri) throws SAXException { 230 this.namespaceMappings.put(uri, prefix); 231 } 232 } 233 | Popular Tags |