1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.xmlrpc.common; |
17 |
|
|
18 |
|
import java.io.Serializable; |
19 |
|
import java.util.Date; |
20 |
|
import java.util.List; |
21 |
|
import java.util.Map; |
22 |
|
|
23 |
|
import org.apache.ws.commons.util.NamespaceContextImpl; |
24 |
|
import org.apache.xmlrpc.client.XmlRpcClient; |
25 |
|
import org.apache.xmlrpc.parser.BooleanParser; |
26 |
|
import org.apache.xmlrpc.parser.ByteArrayParser; |
27 |
|
import org.apache.xmlrpc.parser.DateParser; |
28 |
|
import org.apache.xmlrpc.parser.DoubleParser; |
29 |
|
import org.apache.xmlrpc.parser.FloatParser; |
30 |
|
import org.apache.xmlrpc.parser.I1Parser; |
31 |
|
import org.apache.xmlrpc.parser.I2Parser; |
32 |
|
import org.apache.xmlrpc.parser.I4Parser; |
33 |
|
import org.apache.xmlrpc.parser.I8Parser; |
34 |
|
import org.apache.xmlrpc.parser.MapParser; |
35 |
|
import org.apache.xmlrpc.parser.NodeParser; |
36 |
|
import org.apache.xmlrpc.parser.NullParser; |
37 |
|
import org.apache.xmlrpc.parser.ObjectArrayParser; |
38 |
|
import org.apache.xmlrpc.parser.SerializableParser; |
39 |
|
import org.apache.xmlrpc.parser.TypeParser; |
40 |
|
import org.apache.xmlrpc.serializer.BooleanSerializer; |
41 |
|
import org.apache.xmlrpc.serializer.ByteArraySerializer; |
42 |
|
import org.apache.xmlrpc.serializer.DateSerializer; |
43 |
|
import org.apache.xmlrpc.serializer.DoubleSerializer; |
44 |
|
import org.apache.xmlrpc.serializer.FloatSerializer; |
45 |
|
import org.apache.xmlrpc.serializer.I1Serializer; |
46 |
|
import org.apache.xmlrpc.serializer.I2Serializer; |
47 |
|
import org.apache.xmlrpc.serializer.I4Serializer; |
48 |
|
import org.apache.xmlrpc.serializer.I8Serializer; |
49 |
|
import org.apache.xmlrpc.serializer.ListSerializer; |
50 |
|
import org.apache.xmlrpc.serializer.MapSerializer; |
51 |
|
import org.apache.xmlrpc.serializer.NodeSerializer; |
52 |
|
import org.apache.xmlrpc.serializer.NullSerializer; |
53 |
|
import org.apache.xmlrpc.serializer.ObjectArraySerializer; |
54 |
|
import org.apache.xmlrpc.serializer.SerializableSerializer; |
55 |
|
import org.apache.xmlrpc.serializer.StringSerializer; |
56 |
|
import org.apache.xmlrpc.serializer.TypeSerializer; |
57 |
|
import org.apache.xmlrpc.serializer.XmlRpcWriter; |
58 |
|
import org.w3c.dom.Node; |
59 |
|
import org.xml.sax.SAXException; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
1 |
public class TypeFactoryImpl implements TypeFactory { |
65 |
1 |
private static final TypeSerializer NULL_SERIALIZER = new NullSerializer(); |
66 |
1 |
private static final TypeSerializer STRING_SERIALIZER = new StringSerializer(); |
67 |
1 |
private static final TypeSerializer I4_SERIALIZER = new I4Serializer(); |
68 |
1 |
private static final TypeSerializer BOOLEAN_SERIALIZER = new BooleanSerializer(); |
69 |
1 |
private static final TypeSerializer DOUBLE_SERIALIZER = new DoubleSerializer(); |
70 |
1 |
private static final TypeSerializer DATE_SERIALIZER = new DateSerializer(); |
71 |
1 |
private static final TypeSerializer BYTE_SERIALIZER = new I1Serializer(); |
72 |
1 |
private static final TypeSerializer SHORT_SERIALIZER = new I2Serializer(); |
73 |
1 |
private static final TypeSerializer LONG_SERIALIZER = new I8Serializer(); |
74 |
1 |
private static final TypeSerializer FLOAT_SERIALIZER = new FloatSerializer(); |
75 |
1 |
private static final TypeSerializer NODE_SERIALIZER = new NodeSerializer(); |
76 |
1 |
private static final TypeSerializer SERIALIZABLE_SERIALIZER = new SerializableSerializer(); |
77 |
|
|
78 |
|
private final XmlRpcController controller; |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
518 |
public TypeFactoryImpl(XmlRpcController pController) { |
84 |
518 |
controller = pController; |
85 |
518 |
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
public XmlRpcController getController() { |
92 |
0 |
return controller; |
93 |
|
} |
94 |
|
|
95 |
|
public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException { |
96 |
878 |
if (pObject == null) { |
97 |
40 |
if (pConfig.isEnabledForExtensions()) { |
98 |
24 |
return NULL_SERIALIZER; |
99 |
|
} else { |
100 |
16 |
throw new SAXException(new XmlRpcExtensionException("Null values aren't supported, if isEnabledForExtensions() == false")); |
101 |
|
} |
102 |
838 |
} else if (pObject instanceof String) { |
103 |
112 |
return STRING_SERIALIZER; |
104 |
726 |
} else if (pObject instanceof Byte) { |
105 |
57 |
if (pConfig.isEnabledForExtensions()) { |
106 |
33 |
return BYTE_SERIALIZER; |
107 |
|
} else { |
108 |
24 |
throw new SAXException(new XmlRpcExtensionException("Byte values aren't supported, if isEnabledForExtensions() == false")); |
109 |
|
} |
110 |
669 |
} else if (pObject instanceof Short) { |
111 |
48 |
if (pConfig.isEnabledForExtensions()) { |
112 |
32 |
return SHORT_SERIALIZER; |
113 |
|
} else { |
114 |
16 |
throw new SAXException(new XmlRpcExtensionException("Short values aren't supported, if isEnabledForExtensions() == false")); |
115 |
|
} |
116 |
621 |
} else if (pObject instanceof Integer) { |
117 |
323 |
return I4_SERIALIZER; |
118 |
298 |
} else if (pObject instanceof Long) { |
119 |
56 |
if (pConfig.isEnabledForExtensions()) { |
120 |
40 |
return LONG_SERIALIZER; |
121 |
|
} else { |
122 |
16 |
throw new SAXException(new XmlRpcExtensionException("Long values aren't supported, if isEnabledForExtensions() == false")); |
123 |
|
} |
124 |
242 |
} else if (pObject instanceof Boolean) { |
125 |
0 |
return BOOLEAN_SERIALIZER; |
126 |
242 |
} else if (pObject instanceof Float) { |
127 |
40 |
if (pConfig.isEnabledForExtensions()) { |
128 |
24 |
return FLOAT_SERIALIZER; |
129 |
|
} else { |
130 |
16 |
throw new SAXException(new XmlRpcExtensionException("Float values aren't supported, if isEnabledForExtensions() == false")); |
131 |
|
} |
132 |
202 |
} else if (pObject instanceof Double) { |
133 |
72 |
return DOUBLE_SERIALIZER; |
134 |
130 |
} else if (pObject instanceof Date) { |
135 |
0 |
return DATE_SERIALIZER; |
136 |
130 |
} else if (pObject instanceof byte[]) { |
137 |
33 |
return new ByteArraySerializer(); |
138 |
97 |
} else if (pObject instanceof Object[]) { |
139 |
32 |
return new ObjectArraySerializer(this, pConfig); |
140 |
65 |
} else if (pObject instanceof List) { |
141 |
0 |
return new ListSerializer(this, pConfig); |
142 |
65 |
} else if (pObject instanceof Map) { |
143 |
33 |
return new MapSerializer(this, pConfig); |
144 |
32 |
} else if (pObject instanceof Node) { |
145 |
16 |
if (pConfig.isEnabledForExtensions()) { |
146 |
8 |
return NODE_SERIALIZER; |
147 |
|
} else { |
148 |
8 |
throw new SAXException(new XmlRpcExtensionException("DOM nodes aren't supported, if isEnabledForExtensions() == false")); |
149 |
|
} |
150 |
16 |
} else if (pObject instanceof Serializable) { |
151 |
16 |
if (pConfig.isEnabledForExtensions()) { |
152 |
8 |
return SERIALIZABLE_SERIALIZER; |
153 |
|
} else { |
154 |
8 |
throw new SAXException(new XmlRpcExtensionException("Serializable objects aren't supported, if isEnabledForExtensions() == false")); |
155 |
|
} |
156 |
|
} else { |
157 |
0 |
return null; |
158 |
|
} |
159 |
|
} |
160 |
|
|
161 |
|
public TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName) { |
162 |
648 |
if (XmlRpcWriter.EXTENSIONS_URI.equals(pURI)) { |
163 |
168 |
if (!pConfig.isEnabledForExtensions()) { |
164 |
0 |
return null; |
165 |
|
} |
166 |
168 |
if (NullSerializer.NIL_TAG.equals(pLocalName)) { |
167 |
24 |
return new NullParser(); |
168 |
144 |
} else if (I1Serializer.I1_TAG.equals(pLocalName)) { |
169 |
32 |
return new I1Parser(); |
170 |
112 |
} else if (I2Serializer.I2_TAG.equals(pLocalName)) { |
171 |
32 |
return new I2Parser(); |
172 |
80 |
} else if (I8Serializer.I8_TAG.equals(pLocalName)) { |
173 |
40 |
return new I8Parser(); |
174 |
40 |
} else if (FloatSerializer.FLOAT_TAG.equals(pLocalName)) { |
175 |
24 |
return new FloatParser(); |
176 |
16 |
} else if (NodeSerializer.DOM_TAG.equals(pLocalName)) { |
177 |
8 |
return new NodeParser(); |
178 |
8 |
} else if (SerializableSerializer.SERIALIZABLE_TAG.equals(pLocalName)) { |
179 |
8 |
return new SerializableParser(); |
180 |
|
} |
181 |
480 |
} else if ("".equals(pURI)) { |
182 |
480 |
if (I4Serializer.INT_TAG.equals(pLocalName) || I4Serializer.I4_TAG.equals(pLocalName)) { |
183 |
320 |
return new I4Parser(); |
184 |
160 |
} else if (BooleanSerializer.BOOLEAN_TAG.equals(pLocalName)) { |
185 |
0 |
return new BooleanParser(); |
186 |
160 |
} else if (DoubleSerializer.DOUBLE_TAG.equals(pLocalName)) { |
187 |
72 |
return new DoubleParser(); |
188 |
88 |
} else if (DateSerializer.DATE_TAG.equals(pLocalName)) { |
189 |
0 |
return new DateParser(); |
190 |
88 |
} else if (ObjectArraySerializer.ARRAY_TAG.equals(pLocalName)) { |
191 |
24 |
return new ObjectArrayParser(pConfig, pContext, this); |
192 |
64 |
} else if (MapSerializer.STRUCT_TAG.equals(pLocalName)) { |
193 |
32 |
return new MapParser(pConfig, pContext, this); |
194 |
32 |
} else if (ByteArraySerializer.BASE_64_TAG.equals(pLocalName)) { |
195 |
32 |
return new ByteArrayParser(); |
196 |
|
} |
197 |
|
} |
198 |
0 |
return null; |
199 |
|
} |
200 |
|
} |