ObjectArrayParser.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.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 }


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