Coverage Report - org.apache.xmlrpc.client.XmlRpcLocalTransport
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlRpcLocalTransport
81% 
94% 
8,667
 
 1  
 /*
 2  
  * Copyright 1999,2005 The Apache Software Foundation.
 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 org.apache.xmlrpc.client;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.Map;
 20  
 
 21  
 import org.apache.xmlrpc.XmlRpcConfig;
 22  
 import org.apache.xmlrpc.XmlRpcException;
 23  
 import org.apache.xmlrpc.XmlRpcRequest;
 24  
 import org.apache.xmlrpc.common.XmlRpcExtensionException;
 25  
 
 26  
 /** The default implementation of a local transport.
 27  
  */
 28  
 public class XmlRpcLocalTransport extends XmlRpcTransportImpl {
 29  
         /** Creates a new instance.
 30  
          * @param pClient The client, which creates the transport.
 31  
          */
 32  
         public XmlRpcLocalTransport(XmlRpcClient pClient) {
 33  22
                 super(pClient);
 34  22
         }
 35  
 
 36  
         private boolean isExtensionType(Object pObject) {
 37  52
                 if (pObject == null) {
 38  2
                         return true;
 39  50
                 } else if (pObject instanceof Object[]) {
 40  2
                         Object[] objects = (Object[]) pObject;
 41  6
                         for (int i = 0;  i < objects.length;  i++) {
 42  5
                                 if (isExtensionType(objects[i])) {
 43  1
                                         return true;
 44  
                                 }
 45  
                         }
 46  1
                         return false;
 47  48
                 } else if (pObject instanceof Map) {
 48  2
                         Map map = (Map) pObject;
 49  10
                         for (Iterator iter = map.entrySet().iterator();  iter.hasNext();  ) {
 50  6
                                 Map.Entry entry = (Map.Entry) iter.next();
 51  6
                                 if (isExtensionType(entry.getKey())  ||  isExtensionType(entry.getValue())) {
 52  0
                                         return true;
 53  
                                 }
 54  
                         }
 55  2
                         return false;
 56  
                 } else {
 57  61
                         return !(pObject instanceof Integer
 58  29
                                          ||  pObject instanceof String
 59  17
                                          ||  pObject instanceof byte[]
 60  15
                                          ||  pObject instanceof Double);
 61  
                 }
 62  
         }
 63  
 
 64  
         public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
 65  48
                 XmlRpcConfig config = pRequest.getConfig();
 66  48
                 if (!config.isEnabledForExtensions()) {
 67  35
                         for (int i = 0;  i < pRequest.getParameterCount();  i++) {
 68  24
                                 if (isExtensionType(pRequest.getParameter(i))) {
 69  13
                                         throw new XmlRpcExtensionException("Parameter " + i + " has invalid type, if isEnabledForExtensions() == false");
 70  
                                 }
 71  
                         }
 72  
                 }
 73  
                 Object result;
 74  
                 try {
 75  35
                         result = ((XmlRpcLocalClientConfig) config).getXmlRpcServer().execute(pRequest);
 76  0
                 } catch (Throwable t) {
 77  0
                         if (t instanceof XmlRpcClientException) {
 78  0
                                 throw (XmlRpcClientException) t;
 79  
                         } else {
 80  0
                                 throw new XmlRpcClientException("Failed to invoke method " + pRequest.getMethodName()
 81  0
                                                                                                 + ": " + t.getMessage(), t);
 82  
                         }
 83  
                 }
 84  35
                 if (!config.isEnabledForExtensions()) {
 85  11
                         if (isExtensionType(result)) {
 86  0
                                 throw new XmlRpcExtensionException("Result has invalid type, if isEnabledForExtensions() == false");
 87  
                         }
 88  
                 }
 89  35
                 return result;
 90  
         }
 91  
 }