Clover coverage report - SOJO - 1.0.0
Coverage timestamp: Mo Mai 4 2009 16:26:33 CEST
file stats: LOC: 90   Methods: 11
NCLOC: 57   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
XmlRpcSerializer.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 net.sf.sojo.interchange.AbstractSerializer;
 19   
 20    public class XmlRpcSerializer extends AbstractSerializer {
 21   
 22    private XmlRpcParser xmlRpcParser = new XmlRpcParser();
 23    private boolean returnValueAsList = false;
 24    private boolean convertResult2XmlRpcExceptionAndThrow = false;
 25    private String methodName = null;
 26    XmlRpcWalkerInterceptor xmlRpcWalker = new XmlRpcWalkerInterceptor();
 27   
 28   
 29  66 public XmlRpcSerializer() {
 30  66 setWithSimpleKeyMapper(false);
 31  66 walker.addInterceptor(xmlRpcWalker);
 32    }
 33   
 34  1 public XmlRpcSerializer(boolean pvReturnValueAsList) {
 35  1 this();
 36  1 setReturnValueAsList(pvReturnValueAsList);
 37    }
 38   
 39   
 40  5 public String getMethodName() { return methodName; }
 41   
 42  7 public void setReturnValueAsList(boolean pvReturnValueAsList) { returnValueAsList = pvReturnValueAsList; }
 43  56 public boolean getReturnValueAsList() { return returnValueAsList; }
 44   
 45   
 46   
 47  4 public void setConvertResult2XmlRpcExceptionAndThrow(boolean pvConvertResult2XmlRpcException) {
 48  4 convertResult2XmlRpcExceptionAndThrow = pvConvertResult2XmlRpcException;
 49    }
 50  56 public boolean getConvertResult2XmlRpcExceptionAndThrow() {
 51  56 return convertResult2XmlRpcExceptionAndThrow;
 52    }
 53   
 54   
 55   
 56  30 public Object serialize (Object pvRootObject) {
 57  30 walker.walk(pvRootObject);
 58  30 String lvReturn = xmlRpcWalker.getXmlRpcString();
 59  30 return lvReturn;
 60    }
 61   
 62  3 public String serializeXmlRpcRequest (String pvMethodName, Object pvArgs) {
 63  3 if (pvMethodName == null || pvMethodName.length() == 0) {
 64  2 throw new XmlRpcException("Missing method-name: " + getMethodName());
 65    }
 66  1 Object o = serialize(pvArgs);
 67  1 StringBuffer lvReturn = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><methodCall><methodName>");
 68  1 lvReturn.append(pvMethodName).append("</methodName>" + o + "</methodCall>");
 69  1 return lvReturn.toString();
 70    }
 71   
 72  1 public String serializeXmlRpcResponse (Object pvReturnValue) {
 73  1 Object o = serialize(pvReturnValue);
 74  1 StringBuffer lvReturn = new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><methodResponse>");
 75  1 lvReturn.append(o).append("</methodResponse>");
 76  1 return lvReturn.toString();
 77    }
 78   
 79  57 public Object deserialize(Object pvSourceObject, Class pvRootClass) {
 80  57 Object lvReturn = null;
 81  57 if (pvSourceObject != null) {
 82  56 xmlRpcParser.setReturnValueAsList(getReturnValueAsList());
 83  56 xmlRpcParser.setConvertResult2XmlRpcExceptionAndThrow(getConvertResult2XmlRpcExceptionAndThrow());
 84  56 lvReturn = xmlRpcParser.parse(pvSourceObject.toString());
 85  49 methodName = xmlRpcParser.getMethodName();
 86    }
 87  50 lvReturn = getObjectUtil().makeComplex(lvReturn, pvRootClass);
 88  50 return lvReturn;
 89    }
 90    }