TypeFactoryImpl.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.common;
00020 
00021 import java.io.Serializable;
00022 import java.math.BigDecimal;
00023 import java.math.BigInteger;
00024 import java.util.Calendar;
00025 import java.util.Date;
00026 import java.util.List;
00027 import java.util.Map;
00028 import java.util.TimeZone;
00029 
00030 import org.apache.ws.commons.util.NamespaceContextImpl;
00031 import org.apache.xmlrpc.parser.BigDecimalParser;
00032 import org.apache.xmlrpc.parser.BigIntegerParser;
00033 import org.apache.xmlrpc.parser.BooleanParser;
00034 import org.apache.xmlrpc.parser.ByteArrayParser;
00035 import org.apache.xmlrpc.parser.CalendarParser;
00036 import org.apache.xmlrpc.parser.DateParser;
00037 import org.apache.xmlrpc.parser.DoubleParser;
00038 import org.apache.xmlrpc.parser.FloatParser;
00039 import org.apache.xmlrpc.parser.I1Parser;
00040 import org.apache.xmlrpc.parser.I2Parser;
00041 import org.apache.xmlrpc.parser.I4Parser;
00042 import org.apache.xmlrpc.parser.I8Parser;
00043 import org.apache.xmlrpc.parser.MapParser;
00044 import org.apache.xmlrpc.parser.NodeParser;
00045 import org.apache.xmlrpc.parser.NullParser;
00046 import org.apache.xmlrpc.parser.ObjectArrayParser;
00047 import org.apache.xmlrpc.parser.SerializableParser;
00048 import org.apache.xmlrpc.parser.StringParser;
00049 import org.apache.xmlrpc.parser.TypeParser;
00050 import org.apache.xmlrpc.serializer.BigDecimalSerializer;
00051 import org.apache.xmlrpc.serializer.BigIntegerSerializer;
00052 import org.apache.xmlrpc.serializer.BooleanSerializer;
00053 import org.apache.xmlrpc.serializer.ByteArraySerializer;
00054 import org.apache.xmlrpc.serializer.CalendarSerializer;
00055 import org.apache.xmlrpc.serializer.DateSerializer;
00056 import org.apache.xmlrpc.serializer.DoubleSerializer;
00057 import org.apache.xmlrpc.serializer.FloatSerializer;
00058 import org.apache.xmlrpc.serializer.I1Serializer;
00059 import org.apache.xmlrpc.serializer.I2Serializer;
00060 import org.apache.xmlrpc.serializer.I4Serializer;
00061 import org.apache.xmlrpc.serializer.I8Serializer;
00062 import org.apache.xmlrpc.serializer.ListSerializer;
00063 import org.apache.xmlrpc.serializer.MapSerializer;
00064 import org.apache.xmlrpc.serializer.NodeSerializer;
00065 import org.apache.xmlrpc.serializer.NullSerializer;
00066 import org.apache.xmlrpc.serializer.ObjectArraySerializer;
00067 import org.apache.xmlrpc.serializer.SerializableSerializer;
00068 import org.apache.xmlrpc.serializer.StringSerializer;
00069 import org.apache.xmlrpc.serializer.TypeSerializer;
00070 import org.apache.xmlrpc.serializer.XmlRpcWriter;
00071 import org.apache.xmlrpc.util.XmlRpcDateTimeDateFormat;
00072 import org.w3c.dom.Node;
00073 import org.xml.sax.SAXException;
00074 
00075 
00078 public class TypeFactoryImpl implements TypeFactory {
00079         private static final TypeSerializer NULL_SERIALIZER = new NullSerializer();
00080         private static final TypeSerializer STRING_SERIALIZER = new StringSerializer();
00081         private static final TypeSerializer I4_SERIALIZER = new I4Serializer();
00082         private static final TypeSerializer BOOLEAN_SERIALIZER = new BooleanSerializer();
00083         private static final TypeSerializer DOUBLE_SERIALIZER = new DoubleSerializer();
00084         private static final TypeSerializer BYTE_SERIALIZER = new I1Serializer();
00085         private static final TypeSerializer SHORT_SERIALIZER = new I2Serializer();
00086         private static final TypeSerializer LONG_SERIALIZER = new I8Serializer();
00087         private static final TypeSerializer FLOAT_SERIALIZER = new FloatSerializer();
00088         private static final TypeSerializer NODE_SERIALIZER = new NodeSerializer();
00089     private static final TypeSerializer SERIALIZABLE_SERIALIZER = new SerializableSerializer();
00090     private static final TypeSerializer BIGDECIMAL_SERIALIZER = new BigDecimalSerializer();
00091     private static final TypeSerializer BIGINTEGER_SERIALIZER = new BigIntegerSerializer();
00092     private static final TypeSerializer CALENDAR_SERIALIZER = new CalendarSerializer();
00093 
00094         private final XmlRpcController controller;
00095     private DateSerializer dateSerializer;
00096 
00100         public TypeFactoryImpl(XmlRpcController pController) {
00101                 controller = pController;
00102         }
00103 
00109         public XmlRpcController getController() {
00110                 return controller;
00111         }
00112 
00113         public TypeSerializer getSerializer(XmlRpcStreamConfig pConfig, Object pObject) throws SAXException {
00114                 if (pObject == null) {
00115                         if (pConfig.isEnabledForExtensions()) {
00116                                 return NULL_SERIALIZER;
00117                         } else {
00118                                 throw new SAXException(new XmlRpcExtensionException("Null values aren't supported, if isEnabledForExtensions() == false"));
00119                         }
00120                 } else if (pObject instanceof String) {
00121                         return STRING_SERIALIZER;
00122                 } else if (pObject instanceof Byte) {
00123                         if (pConfig.isEnabledForExtensions()) {
00124                                 return BYTE_SERIALIZER;
00125                         } else {
00126                                 throw new SAXException(new XmlRpcExtensionException("Byte values aren't supported, if isEnabledForExtensions() == false"));
00127                         }
00128                 } else if (pObject instanceof Short) {
00129                         if (pConfig.isEnabledForExtensions()) {
00130                                 return SHORT_SERIALIZER;
00131                         } else {
00132                                 throw new SAXException(new XmlRpcExtensionException("Short values aren't supported, if isEnabledForExtensions() == false"));
00133                         }
00134                 } else if (pObject instanceof Integer) {
00135                         return I4_SERIALIZER;
00136                 } else if (pObject instanceof Long) {
00137                         if (pConfig.isEnabledForExtensions()) {
00138                                 return LONG_SERIALIZER;
00139                         } else {
00140                                 throw new SAXException(new XmlRpcExtensionException("Long values aren't supported, if isEnabledForExtensions() == false"));
00141                         }
00142                 } else if (pObject instanceof Boolean) {
00143                         return BOOLEAN_SERIALIZER;
00144                 } else if (pObject instanceof Float) {
00145                         if (pConfig.isEnabledForExtensions()) {
00146                                 return FLOAT_SERIALIZER;
00147                         } else {
00148                                 throw new SAXException(new XmlRpcExtensionException("Float values aren't supported, if isEnabledForExtensions() == false"));
00149                         }
00150                 } else if (pObject instanceof Double) {
00151                         return DOUBLE_SERIALIZER;
00152                 } else if (pObject instanceof Calendar) {
00153             if (pConfig.isEnabledForExtensions()) {
00154                 return CALENDAR_SERIALIZER;
00155             } else {
00156                 throw new SAXException(new XmlRpcExtensionException("Calendar values aren't supported, if isEnabledForExtensions() == false"));
00157             }
00158         } else if (pObject instanceof Date) {
00159             if (dateSerializer == null) {
00160                 dateSerializer = new DateSerializer(new XmlRpcDateTimeDateFormat(){
00161                     private static final long serialVersionUID = 24345909123324234L;
00162                     protected TimeZone getTimeZone() {
00163                         return controller.getConfig().getTimeZone();
00164                     }
00165                 });
00166             }
00167             return dateSerializer;
00168         } else if (pObject instanceof byte[]) {
00169                         return new ByteArraySerializer();
00170                 } else if (pObject instanceof Object[]) {
00171                         return new ObjectArraySerializer(this, pConfig);
00172                 } else if (pObject instanceof List) {
00173                         return new ListSerializer(this, pConfig);
00174                 } else if (pObject instanceof Map) {
00175                         return new MapSerializer(this, pConfig);
00176                 } else if (pObject instanceof Node) {
00177                         if (pConfig.isEnabledForExtensions()) {
00178                                 return NODE_SERIALIZER;
00179                         } else {
00180                                 throw new SAXException(new XmlRpcExtensionException("DOM nodes aren't supported, if isEnabledForExtensions() == false"));
00181                         }
00182         } else if (pObject instanceof BigInteger) {
00183             if (pConfig.isEnabledForExtensions()) {
00184                 return BIGINTEGER_SERIALIZER;
00185             } else {
00186                 throw new SAXException(new XmlRpcExtensionException("BigInteger values aren't supported, if isEnabledForExtensions() == false"));
00187             }
00188         } else if (pObject instanceof BigDecimal) {
00189             if (pConfig.isEnabledForExtensions()) {
00190                 return BIGDECIMAL_SERIALIZER;
00191             } else {
00192                 throw new SAXException(new XmlRpcExtensionException("BigDecimal values aren't supported, if isEnabledForExtensions() == false"));
00193             }
00194                 } else if (pObject instanceof Serializable) {
00195                         if (pConfig.isEnabledForExtensions()) {
00196                                 return SERIALIZABLE_SERIALIZER;
00197                         } else {
00198                                 throw new SAXException(new XmlRpcExtensionException("Serializable objects aren't supported, if isEnabledForExtensions() == false"));
00199                         }
00200                 } else {
00201                         return null;
00202                 }
00203         }
00204 
00205         public TypeParser getParser(XmlRpcStreamConfig pConfig, NamespaceContextImpl pContext, String pURI, String pLocalName) {
00206                 if (XmlRpcWriter.EXTENSIONS_URI.equals(pURI)) {
00207                         if (!pConfig.isEnabledForExtensions()) {
00208                                 return null;
00209                         }
00210                         if (NullSerializer.NIL_TAG.equals(pLocalName)) {
00211                                 return new NullParser();
00212                         } else if (I1Serializer.I1_TAG.equals(pLocalName)) {
00213                                 return new I1Parser();
00214                         } else if (I2Serializer.I2_TAG.equals(pLocalName)) {
00215                                 return new I2Parser();
00216                         } else if (I8Serializer.I8_TAG.equals(pLocalName)) {
00217                                 return new I8Parser();
00218                         } else if (FloatSerializer.FLOAT_TAG.equals(pLocalName)) {
00219                                 return new FloatParser();
00220             } else if (NodeSerializer.DOM_TAG.equals(pLocalName)) {
00221                 return new NodeParser();
00222             } else if (BigDecimalSerializer.BIGDECIMAL_TAG.equals(pLocalName)) {
00223                 return new BigDecimalParser();
00224             } else if (BigIntegerSerializer.BIGINTEGER_TAG.equals(pLocalName)) {
00225                 return new BigIntegerParser();
00226                         } else if (SerializableSerializer.SERIALIZABLE_TAG.equals(pLocalName)) {
00227                                 return new SerializableParser();
00228                         } else if (CalendarSerializer.CALENDAR_TAG.equals(pLocalName)) {
00229                             return new CalendarParser();
00230             }
00231                 } else if ("".equals(pURI)) {
00232                         if (I4Serializer.INT_TAG.equals(pLocalName)  ||  I4Serializer.I4_TAG.equals(pLocalName)) {
00233                                 return new I4Parser();
00234                         } else if (BooleanSerializer.BOOLEAN_TAG.equals(pLocalName)) {
00235                                 return new BooleanParser();
00236                         } else if (DoubleSerializer.DOUBLE_TAG.equals(pLocalName)) {
00237                                 return new DoubleParser();
00238                         } else if (DateSerializer.DATE_TAG.equals(pLocalName)) {
00239                                 return new DateParser(new XmlRpcDateTimeDateFormat(){
00240                     private static final long serialVersionUID = 7585237706442299067L;
00241                     protected TimeZone getTimeZone() {
00242                         return controller.getConfig().getTimeZone();
00243                     }
00244                 });
00245                         } else if (ObjectArraySerializer.ARRAY_TAG.equals(pLocalName)) {
00246                                 return new ObjectArrayParser(pConfig, pContext, this);
00247                         } else if (MapSerializer.STRUCT_TAG.equals(pLocalName)) {
00248                                 return new MapParser(pConfig, pContext, this);
00249                         } else if (ByteArraySerializer.BASE_64_TAG.equals(pLocalName)) {
00250                                 return new ByteArrayParser();
00251                         } else if (StringSerializer.STRING_TAG.equals(pLocalName)) {
00252                                 return new StringParser();
00253                         }
00254                 }
00255                 return null;
00256         }
00257 }


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