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.parser;
00020
00021 import java.util.ArrayList;
00022 import java.util.List;
00023
00024 import javax.xml.namespace.QName;
00025
00026 import org.apache.ws.commons.util.NamespaceContextImpl;
00027 import org.apache.xmlrpc.common.TypeFactory;
00028 import org.apache.xmlrpc.common.XmlRpcStreamConfig;
00029 import org.apache.xmlrpc.serializer.ObjectArraySerializer;
00030 import org.apache.xmlrpc.serializer.TypeSerializerImpl;
00031 import org.xml.sax.Attributes;
00032 import org.xml.sax.SAXException;
00033 import org.xml.sax.SAXParseException;
00034
00035
00039 public class ObjectArrayParser extends RecursiveTypeParserImpl {
00040 private int level = 0;
00041 private List list;
00042
00048 public ObjectArrayParser(XmlRpcStreamConfig pConfig,
00049 NamespaceContextImpl pContext,
00050 TypeFactory pFactory) {
00051 super(pConfig, pContext, pFactory);
00052 }
00053
00054 public void startDocument() throws SAXException {
00055 level = 0;
00056 list = new ArrayList();
00057 super.startDocument();
00058 }
00059
00060 protected void addResult(Object pValue) {
00061 list.add(pValue);
00062 }
00063
00064 public void endElement(String pURI, String pLocalName, String pQName) throws SAXException {
00065 switch (--level) {
00066 case 0:
00067 setResult(list.toArray());
00068 break;
00069 case 1:
00070 break;
00071 case 2:
00072 endValueTag();
00073 break;
00074 default:
00075 super.endElement(pURI, pLocalName, pQName);
00076 }
00077 }
00078
00079 public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException {
00080 switch (level++) {
00081 case 0:
00082 if (!"".equals(pURI) || !ObjectArraySerializer.ARRAY_TAG.equals(pLocalName)) {
00083 throw new SAXParseException("Expected array element, got "
00084 + new QName(pURI, pLocalName),
00085 getDocumentLocator());
00086 }
00087 break;
00088 case 1:
00089 if (!"".equals(pURI) || !ObjectArraySerializer.DATA_TAG.equals(pLocalName)) {
00090 throw new SAXParseException("Expected data element, got "
00091 + new QName(pURI, pLocalName),
00092 getDocumentLocator());
00093 }
00094 break;
00095 case 2:
00096 if (!"".equals(pURI) || !TypeSerializerImpl.VALUE_TAG.equals(pLocalName)) {
00097 throw new SAXParseException("Expected data element, got "
00098 + new QName(pURI, pLocalName),
00099 getDocumentLocator());
00100 }
00101 startValueTag();
00102 break;
00103 default:
00104 super.startElement(pURI, pLocalName, pQName, pAttrs);
00105 break;
00106 }
00107 }
00108
00109 }