XmlRpcLocalTransport.java
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *   http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing,
00013  * software distributed under the License is distributed on an
00014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015  * KIND, either express or implied.  See the License for the
00016  * specific language governing permissions and limitations
00017  * under the License.    
00018  */
00019 package org.apache.xmlrpc.client;
00020 
00021 import java.util.Collection;
00022 import java.util.Date;
00023 import java.util.Iterator;
00024 import java.util.Map;
00025 
00026 import org.apache.xmlrpc.XmlRpcConfig;
00027 import org.apache.xmlrpc.XmlRpcException;
00028 import org.apache.xmlrpc.XmlRpcRequest;
00029 import org.apache.xmlrpc.common.TypeConverter;
00030 import org.apache.xmlrpc.common.TypeConverterFactory;
00031 import org.apache.xmlrpc.common.XmlRpcExtensionException;
00032 import org.apache.xmlrpc.common.XmlRpcRequestProcessor;
00033 
00036 public class XmlRpcLocalTransport extends XmlRpcTransportImpl {
00040         public XmlRpcLocalTransport(XmlRpcClient pClient) {
00041                 super(pClient);
00042         }
00043 
00044         private boolean isExtensionType(Object pObject) {
00045                 if (pObject == null) {
00046                         return true;
00047                 } else if (pObject instanceof Object[]) {
00048                         Object[] objects = (Object[]) pObject;
00049                         for (int i = 0;  i < objects.length;  i++) {
00050                                 if (isExtensionType(objects[i])) {
00051                                         return true;
00052                                 }
00053                         }
00054                         return false;
00055         } else if (pObject instanceof Collection) {
00056             for (Iterator iter = ((Collection) pObject).iterator();  iter.hasNext();  ) {
00057                 if (isExtensionType(iter.next())) {
00058                     return true;
00059                 }
00060             }
00061             return false;
00062                 } else if (pObject instanceof Map) {
00063                         Map map = (Map) pObject;
00064                         for (Iterator iter = map.entrySet().iterator();  iter.hasNext();  ) {
00065                                 Map.Entry entry = (Map.Entry) iter.next();
00066                                 if (isExtensionType(entry.getKey())  ||  isExtensionType(entry.getValue())) {
00067                                         return true;
00068                                 }
00069                         }
00070                         return false;
00071                 } else {
00072                         return !(pObject instanceof Integer
00073                      ||  pObject instanceof Date
00074                                          ||  pObject instanceof String
00075                                          ||  pObject instanceof byte[]
00076                                          ||  pObject instanceof Double);
00077                 }
00078         }
00079 
00080         public Object sendRequest(XmlRpcRequest pRequest) throws XmlRpcException {
00081                 XmlRpcConfig config = pRequest.getConfig();
00082                 if (!config.isEnabledForExtensions()) {
00083                         for (int i = 0;  i < pRequest.getParameterCount();  i++) {
00084                                 if (isExtensionType(pRequest.getParameter(i))) {
00085                                         throw new XmlRpcExtensionException("Parameter " + i + " has invalid type, if isEnabledForExtensions() == false");
00086                                 }
00087                         }
00088                 }
00089                 final XmlRpcRequestProcessor server = ((XmlRpcLocalClientConfig) config).getXmlRpcServer();
00090         Object result;
00091                 try {
00092                         result = server.execute(pRequest);
00093         } catch (XmlRpcException t) {
00094             throw t;
00095                 } catch (Throwable t) {
00096                     throw new XmlRpcClientException("Failed to invoke method " + pRequest.getMethodName()
00097                             + ": " + t.getMessage(), t);
00098                 }
00099                 if (!config.isEnabledForExtensions()) {
00100                         if (isExtensionType(result)) {
00101                                 throw new XmlRpcExtensionException("Result has invalid type, if isEnabledForExtensions() == false");
00102                         }
00103                 }
00104 
00105                 if (result == null) {
00106                     return null;
00107         }
00108         final TypeConverterFactory typeConverterFactory = server.getTypeConverterFactory();
00109         final TypeConverter typeConverter = typeConverterFactory.getTypeConverter(result.getClass());
00110         return typeConverter.backConvert(result);
00111         }
00112 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49