Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
ObjectArrayParser |
|
| 3.6;3,6 |
1 | /* |
|
2 | * Copyright 1999,2005 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.xmlrpc.parser; |
|
17 | ||
18 | import java.util.ArrayList; |
|
19 | import java.util.List; |
|
20 | ||
21 | import javax.xml.namespace.QName; |
|
22 | ||
23 | import org.apache.ws.commons.util.NamespaceContextImpl; |
|
24 | import org.apache.xmlrpc.common.TypeFactory; |
|
25 | import org.apache.xmlrpc.common.XmlRpcStreamConfig; |
|
26 | import org.apache.xmlrpc.serializer.ObjectArraySerializer; |
|
27 | import org.apache.xmlrpc.serializer.TypeSerializerImpl; |
|
28 | import org.xml.sax.Attributes; |
|
29 | import org.xml.sax.SAXException; |
|
30 | import org.xml.sax.SAXParseException; |
|
31 | ||
32 | ||
33 | /** Parser for an array of objects, as created by |
|
34 | * {@link org.apache.xmlrpc.serializer.ObjectArraySerializer}. |
|
35 | */ |
|
36 | public class ObjectArrayParser extends RecursiveTypeParserImpl { |
|
37 | 24 | private int level = 0; |
38 | private List list; |
|
39 | ||
40 | /** Creates a new instance. |
|
41 | * @param pContext The namespace context. |
|
42 | * @param pConfig The request or response configuration. |
|
43 | * @param pFactory The type factory. |
|
44 | */ |
|
45 | public ObjectArrayParser(XmlRpcStreamConfig pConfig, |
|
46 | NamespaceContextImpl pContext, |
|
47 | TypeFactory pFactory) { |
|
48 | 24 | super(pConfig, pContext, pFactory); |
49 | 24 | } |
50 | ||
51 | public void startDocument() throws SAXException { |
|
52 | 24 | level = 0; |
53 | 24 | list = new ArrayList(); |
54 | 24 | super.startDocument(); |
55 | 24 | } |
56 | ||
57 | protected void addResult(Object pValue) { |
|
58 | 104 | list.add(pValue); |
59 | 104 | } |
60 | ||
61 | public void endElement(String pURI, String pLocalName, String pQName) throws SAXException { |
|
62 | 248 | switch (--level) { |
63 | case 0: |
|
64 | 24 | setResult(list.toArray()); |
65 | 24 | break; |
66 | case 1: |
|
67 | 24 | break; |
68 | case 2: |
|
69 | 104 | endValueTag(); |
70 | 104 | break; |
71 | default: |
|
72 | 96 | super.endElement(pURI, pLocalName, pQName); |
73 | } |
|
74 | 248 | } |
75 | ||
76 | public void startElement(String pURI, String pLocalName, String pQName, Attributes pAttrs) throws SAXException { |
|
77 | 248 | switch (level++) { |
78 | case 0: |
|
79 | 24 | if (!"".equals(pURI) || !ObjectArraySerializer.ARRAY_TAG.equals(pLocalName)) { |
80 | 0 | throw new SAXParseException("Expected array element, got " |
81 | 0 | + new QName(pURI, pLocalName), |
82 | 0 | getDocumentLocator()); |
83 | } |
|
84 | 0 | break; |
85 | case 1: |
|
86 | 24 | if (!"".equals(pURI) || !ObjectArraySerializer.DATA_TAG.equals(pLocalName)) { |
87 | 0 | throw new SAXParseException("Expected data element, got " |
88 | 0 | + new QName(pURI, pLocalName), |
89 | 0 | getDocumentLocator()); |
90 | } |
|
91 | 0 | break; |
92 | case 2: |
|
93 | 104 | if (!"".equals(pURI) || !TypeSerializerImpl.VALUE_TAG.equals(pLocalName)) { |
94 | 0 | throw new SAXParseException("Expected data element, got " |
95 | 0 | + new QName(pURI, pLocalName), |
96 | 0 | getDocumentLocator()); |
97 | } |
|
98 | 104 | startValueTag(); |
99 | 104 | break; |
100 | case 3: |
|
101 | 96 | super.startElement(pURI, pLocalName, pQName, pAttrs); |
102 | break; |
|
103 | } |
|
104 | 248 | } |
105 | ||
106 | } |