Clover coverage report - CRISPY - 1.1.1
Coverage timestamp: Mi Nov 15 2006 13:09:46 CET
file stats: LOC: 120   Methods: 6
NCLOC: 96   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RestContentHandler.java 75% 90,6% 100% 86,2%
coverage coverage
 1    package net.sf.crispy.impl.rest;
 2   
 3    import java.util.Hashtable;
 4    import java.util.Vector;
 5   
 6    import net.sf.crispy.util.Converter;
 7   
 8    import org.xml.sax.Attributes;
 9    import org.xml.sax.SAXException;
 10    import org.xml.sax.helpers.DefaultHandler;
 11   
 12    public class RestContentHandler extends DefaultHandler {
 13   
 14    private Hashtable map = new Hashtable();
 15    private String name = null;
 16    private String type = null;
 17    private Integer parentRef = null;
 18   
 19   
 20   
 21  53 public Object getResult() {
 22  53 Object ret = map.get(Integer.valueOf("0"));
 23  53 return ret;
 24    }
 25   
 26  484 public void startElement(String pvUri, String pvLocalName, String pvName, Attributes pvAttributes) throws SAXException {
 27  484 name = pvName;
 28  484 type = null;
 29  484 parentRef = null;
 30  484 if (name.equals("CLASS")) {
 31  116 name = null;
 32  116 Integer id = Integer.valueOf(pvAttributes.getValue("id"));
 33  116 String className = pvAttributes.getValue("type");
 34  116 Integer parentRef = Integer.valueOf(pvAttributes.getValue("parentRef"));
 35  116 String lvName = pvAttributes.getValue("name");
 36  116 try {
 37  116 Object classObject = Class.forName(className).newInstance();
 38  116 map.put(id, classObject);
 39  116 Object parent = map.get(parentRef);
 40  116 if (parent != null) {
 41  101 if (parent instanceof Hashtable) {
 42  16 if (lvName != null) { ((Hashtable) parent).put(lvName, classObject); }
 43    }
 44  48 else if (parent instanceof Vector) {
 45  48 ((Vector) parent).add(classObject);
 46    }
 47    }
 48    } catch (Exception e) {
 49  0 e.printStackTrace();
 50    }
 51   
 52    }
 53   
 54  368 else if (name.equals("property")) {
 55  368 name = pvAttributes.getValue("name");
 56  368 type = pvAttributes.getValue("type");
 57  368 parentRef = Integer.valueOf(pvAttributes.getValue("parentRef"));
 58    }
 59    }
 60   
 61  484 public void endElement(String pvUri, String pvLocalName, String pvName) throws SAXException {
 62  484 name = null;
 63  484 type = null;
 64  484 parentRef = null;
 65    }
 66   
 67   
 68  368 public void characters(char[] pvCh, int pvStart, int pvLength) throws SAXException {
 69  368 StringBuffer sb = new StringBuffer();
 70  368 sb.append(pvCh, pvStart, pvLength);
 71    // String temp = (String) map.get(name);
 72    // if (temp != null) { sb.append(temp); }
 73    // map.put(name, sb.toString());
 74   
 75  368 if (name != null) {
 76  325 Object lvClassObject = map.get(parentRef);
 77  325 if (name.equals("class")) {
 78  64 if (lvClassObject instanceof Hashtable) {
 79  64 ((Hashtable) lvClassObject).put(name, sb.toString());
 80    }
 81  0 else if (lvClassObject instanceof Vector) {
 82  0 System.out.println("--- Darf NICHT sein ---");
 83    // ((Vector) lvClassObject).add (name, sb.toString());
 84    }
 85    } else {
 86  261 try {
 87  261 Object lvValue = Converter.convertString2Value(sb.toString(), type);
 88  261 if (lvClassObject instanceof Hashtable) {
 89  258 if (lvValue != null) {
 90  257 ((Hashtable) lvClassObject).put(name, lvValue);
 91    }
 92    }
 93  3 else if (lvClassObject instanceof Vector) {
 94    // System.out.println("--- Darf NICHT sein: Vector ---");
 95  3 ((Vector) lvClassObject).add (sb.toString());
 96    }
 97    } catch (Exception e) {
 98  0 e.printStackTrace();
 99    }
 100    }
 101    }
 102    // simple datatype
 103  43 else if ((name == null) && (parentRef.equals(Integer.valueOf("-1")))) {
 104  43 try {
 105  43 Object lvValue = Converter.convertString2Value(sb.toString(), type);
 106  43 map.put(Integer.valueOf("0"), lvValue);
 107    } catch (Exception e) {
 108  0 e.printStackTrace();
 109    }
 110    }
 111    }
 112   
 113  58 public void startDocument() throws SAXException {
 114  58 map = new Hashtable();
 115  58 name = null;
 116    }
 117   
 118  58 public void endDocument() throws SAXException { }
 119   
 120    }