Clover coverage report - SOJO - 1.0.0
Coverage timestamp: Mo Mai 4 2009 16:26:33 CEST
file stats: LOC: 80   Methods: 6
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XmlRpcParser.java 100% 100% 100% 100%
coverage
 1    /*
 2    * Copyright 2002-2005 the original author or authors.
 3    *
 4    * Licensed under the Apache License, Version 2.0 (the "License");
 5    * you may not use this file except in compliance with the License.
 6    * You may obtain a copy of the License at
 7    *
 8    * http://www.apache.org/licenses/LICENSE-2.0
 9    *
 10    * Unless required by applicable law or agreed to in writing, software
 11    * distributed under the License is distributed on an "AS IS" BASIS,
 12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13    * See the License for the specific language governing permissions and
 14    * limitations under the License.
 15    */
 16    package net.sf.sojo.interchange.xmlrpc;
 17   
 18    import java.io.ByteArrayInputStream;
 19    import java.util.Map;
 20   
 21    import javax.xml.parsers.SAXParser;
 22    import javax.xml.parsers.SAXParserFactory;
 23   
 24    import org.xml.sax.InputSource;
 25    import org.xml.sax.SAXParseException;
 26    import org.xml.sax.XMLReader;
 27   
 28    public class XmlRpcParser {
 29   
 30    private boolean returnValueAsList = true;
 31    private boolean convertResult2XmlRpcExceptionAndThrow = false;
 32    private String methodName = null;
 33   
 34   
 35  49 public String getMethodName() { return methodName; }
 36   
 37  56 public void setReturnValueAsList(boolean pvReturnValueAsList) { returnValueAsList = pvReturnValueAsList; }
 38  57 public boolean getReturnValueAsList() { return returnValueAsList; }
 39   
 40  56 public void setConvertResult2XmlRpcExceptionAndThrow(boolean pvConvertResult2XmlRpcException) {
 41  56 convertResult2XmlRpcExceptionAndThrow = pvConvertResult2XmlRpcException;
 42    }
 43  4 public boolean getConvertResult2XmlRpcExceptionAndThrow() {
 44  4 return convertResult2XmlRpcExceptionAndThrow;
 45    }
 46   
 47  58 public Object parse(final String pvXmlRpcString) throws XmlRpcException {
 48  58 Object lvReturn = null;
 49  58 boolean lvIsFault = false;
 50  58 try {
 51  58 if (pvXmlRpcString != null) {
 52  57 SAXParserFactory lvFactory = SAXParserFactory.newInstance();
 53  57 SAXParser lvParser = lvFactory.newSAXParser();
 54  57 XMLReader lvReader = lvParser.getXMLReader();
 55  57 XmlRpcContentHandler lvContentHandler = new XmlRpcContentHandler();
 56  57 lvContentHandler.setReturnValueAsList(getReturnValueAsList());
 57  57 lvReader.setContentHandler(lvContentHandler);
 58   
 59  57 ByteArrayInputStream lvArrayInputStream = new ByteArrayInputStream(pvXmlRpcString.getBytes());
 60  57 lvReader.parse(new InputSource(lvArrayInputStream));
 61  51 lvReturn = lvContentHandler.getResults();
 62  51 methodName = lvContentHandler.getMethodName();
 63  51 lvIsFault = lvContentHandler.isFault();
 64    }
 65    } catch (SAXParseException e) {
 66  1 throw new XmlRpcException(e.getMessage(), e);
 67    } catch (Exception e) {
 68  5 throw new XmlRpcException("Exception by parse XML-RPC-String: " + pvXmlRpcString, e);
 69    }
 70   
 71  52 if (lvIsFault == true && getConvertResult2XmlRpcExceptionAndThrow()) {
 72  2 Map lvMap = (Map) lvReturn;
 73  2 Object lvFaultCode = lvMap.get("faultCode");
 74  2 Object lvMessage = lvMap.get("faultString");
 75  2 throw new XmlRpcException(lvFaultCode + ": " + lvMessage);
 76    }
 77  50 return lvReturn;
 78   
 79    }
 80    }