|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xml.sax.helpers.DefaultHandler redstone.xmlrpc.XmlRpcParser
public abstract class XmlRpcParser
An XmlRpcParser converts inbound XML-RPC messages to their Java counterparts through the use of a SAX compliant parser. This is an abstract class that is only concerned with the XML-RPC values contained in a message. Deriving classes supply a handleParsedValue() method that is called whenever an XML-RPC value has been parsed.
If a class needs to be notified of additional parts of an XML-RPC message, the startElement() or endElement() methods are overridden and extended with checks for the appropriate element. This is the case with XmlRpcClient that wants to know if a fault element is present. Also, the XmlRpcServer wants to know the name of the method for which values are supplied.
Internally, the implementation uses pre-calculated hash values of the element names to allow for switch() constructs when comparing elements supplied by the SAX parser.
Field Summary | |
---|---|
static int |
ARRAY
The hash value of array elements |
static int |
BASE64
The hash value of double elements |
static int |
BOOLEAN
The hash value of boolean elements |
static int |
DATE
The hash value of double elements |
static int |
DOUBLE
The hash value of double elements |
static int |
I4
The hash value of i4 elements |
static int |
INT
The hash value of int elements |
static int |
MEMBER
The hash value of member elements |
static int |
NAME
The hash value of name elements |
static int |
STRING
The hash value of string elements |
static int |
STRUCT
The hash value of struct elements |
static int |
VALUE
The hash value of value elements |
Constructor Summary | |
---|---|
XmlRpcParser()
|
Method Summary | |
---|---|
void |
characters(char[] data,
int start,
int length)
Called by the SAX driver when character data is available. |
void |
endElement(java.lang.String uri,
java.lang.String name,
java.lang.String qualifiedName)
Called by SAX driver when a new end-element has been found in the message. |
void |
parse(java.io.InputStream is)
Parses the XML-RPC message contained in the supplied input stream. |
void |
startElement(java.lang.String uri,
java.lang.String name,
java.lang.String qualifiedName,
org.xml.sax.Attributes attributes)
Called by SAX driver when a new element has been found in the message. |
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int VALUE
public static final int STRING
public static final int I4
public static final int INT
public static final int BOOLEAN
public static final int DOUBLE
public static final int DATE
public static final int BASE64
public static final int STRUCT
public static final int ARRAY
public static final int MEMBER
public static final int NAME
Constructor Detail |
---|
public XmlRpcParser()
Method Detail |
---|
public void parse(java.io.InputStream is) throws XmlRpcException
is
- The input stream containing the XML-RPC message
XmlRpcException
public void startElement(java.lang.String uri, java.lang.String name, java.lang.String qualifiedName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
This implementation uses a switch construct on the hash value of the element name. This increases readability, in my opinion, and perhaps performance as well (only one loop -- in hashCode() -- instead of in every equals() call).
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
See
- SAX documentation
org.xml.sax.SAXException
public void endElement(java.lang.String uri, java.lang.String name, java.lang.String qualifiedName) throws org.xml.sax.SAXException
This implementation determines if our current state is that we have a current value that needs to be processed, and if that value has some character data in the buffer required to finalize the value. The handleParsedValue() method is only called if a top-level value element has ended. If not, the value is added to the enclosing value, which may be an array or a struct.
Note that struct values are processed when the member element ends and not when the value element ends. This is because we need to use the included member name.
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
See
- SAX documentation
org.xml.sax.SAXException
public void characters(char[] data, int start, int length)
This implementation appends the data to an internal string buffer. The method is called for every element, wether characters are included int the element or not. This leads to the buffer being prepended with whitespace until actual character data is aquired. This is removed using the trim() method when the character data is consumed.
characters
in interface org.xml.sax.ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
See
- SAX documentation
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |