1 16 17 18 package org.apache.xmlrpc; 19 20 import java.util.Hashtable ; 21 import java.io.InputStream ; 22 23 import org.xml.sax.AttributeList ; 24 import org.xml.sax.SAXException ; 25 26 36 public class XmlRpcClientResponseProcessor extends XmlRpc 37 { 38 39 protected Object result; 40 41 42 protected boolean fault; 43 44 47 public XmlRpcClientResponseProcessor() 48 { 49 } 50 51 59 public Object decodeResponse(InputStream is) 60 throws XmlRpcClientException 61 { 62 result = null; 63 fault = false; 64 try 65 { 66 parse(is); 67 if (fault) 68 { 69 return decodeException(result); 70 } 71 else 72 { 73 return result; 74 } 75 } 76 catch (Exception x) 77 { 78 throw new XmlRpcClientException("Error decoding XML-RPC response", x); 79 } 80 } 81 82 94 protected XmlRpcException decodeException(Object result) 95 throws XmlRpcClientException 96 { 97 Hashtable exceptionData; 98 99 try 100 { 101 exceptionData = (Hashtable ) result; 102 return new XmlRpcException( 103 Integer.parseInt(exceptionData.get("faultCode").toString()), 104 (String ) exceptionData.get("faultString") 105 ); 106 } 107 catch (Exception x) 108 { 109 throw new XmlRpcClientException("Error decoding XML-RPC exception response", x); 110 } 111 } 112 113 protected void objectParsed(Object what) 114 { 115 result = what; 116 } 117 118 121 public void startElement(String name, AttributeList atts) 122 throws SAXException 123 { 124 if ("fault".equals(name)) 125 { 126 fault = true; 127 } 128 else 129 { 130 super.startElement(name, atts); 131 } 132 } 133 134 141 protected boolean canReUse() 142 { 143 result = null; 144 fault = false; 145 return true; 146 } 147 } 148 | Popular Tags |