Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 }