You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2001/12/23 13:33:32 UTC
cvs commit: xml-axis/java/test/encoding DataSer.java
rubys 01/12/23 04:33:32
Modified: java/samples/encoding DataSer.java
java/src/org/apache/axis AxisEngine.java
java/src/org/apache/axis/client Call.java ServiceClient.java
java/src/org/apache/axis/deployment
SimpleDeploymentManager.java
java/src/org/apache/axis/deployment/wsdd WSDDService.java
java/src/org/apache/axis/encoding ArraySerializer.java
Base64Serializer.java BeanSerializer.java
BooleanDeserializerFactory.java DateSerializer.java
DeserializerFactory.java ElementSerializer.java
EnumSerializer.java FloatSerializer.java
HexSerializer.java JAFDataHandlerDeserializer.java
MapSerializer.java SOAPTypeMappingRegistry.java
TypeMappingRegistry.java VectorDeserializer.java
java/src/org/apache/axis/handlers/soap SOAPService.java
java/test/encoding DataSer.java
Added: java/src/org/apache/axis InternalException.java
java/src/org/apache/axis/encoding BasicDeserializer.java
Log:
Enable deserialization factories to know the desired java class in advance.
This can result in signficiant performance improvements as the
deserializers produced by this factory can be pre-initialized.
I also couldn't take it any more and split out BasicDeserializer into
a separate (non-nested) class.
Finally, I started an InternalException class along the lines of Glyn's
suggestion. Among other things, it provides a place for convenient logging.
Revision Changes Path
1.13 +2 -1 xml-axis/java/samples/encoding/DataSer.java
Index: DataSer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/samples/encoding/DataSer.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DataSer.java 2001/10/26 18:18:57 1.12
+++ DataSer.java 2001/12/23 12:33:31 1.13
@@ -22,7 +22,8 @@
public static final QName myTypeQName = new QName("typeNS", "Data");
public static class DataSerFactory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {
return new DataSer();
}
}
1.61 +2 -0 xml-axis/java/src/org/apache/axis/AxisEngine.java
Index: AxisEngine.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisEngine.java,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -r1.60 -r1.61
--- AxisEngine.java 2001/12/06 17:09:40 1.60
+++ AxisEngine.java 2001/12/23 12:33:31 1.61
@@ -73,6 +73,7 @@
import javax.xml.rpc.namespace.QName;
import java.util.Hashtable;
+import java.beans.IntrospectionException;
/**
* An <code>AxisEngine</code> is the base class for AxisClient and
@@ -311,6 +312,7 @@
Class cls,
DeserializerFactory deserFactory,
Serializer serializer)
+ throws IntrospectionException
{
category.info(JavaUtils.getMessage("registerTypeMap00",
qName.toString(), cls.getName()));
1.1 xml-axis/java/src/org/apache/axis/InternalException.java
Index: InternalException.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis;
import org.apache.log4j.Category;
import java.io.StringWriter;
import java.io.PrintWriter;
/**
* Encapsulates exceptions for "should never occur" situations. Extends
* RuntimeException so it need not explicitly be caught. Logs the exception
* as a fatal error, and if debug is enabled, includes the full stack trace.
*
* @author Sam Ruby (rubys@us.ibm.com)
* @author Glyn Normington (glyn_normington@uk.ibm.com)
*/
public class InternalException extends RuntimeException {
private static Category category =
Category.getInstance(InternalException.class.getName());
/**
* Construct an Internal Exception from a String. The string is wrapped
* in an exception, enabling a stack traceback to be obtained.
* @param message String form of the error
*/
public InternalException(String message) {
this(new Exception(message));
}
/**
* Construct an Internal Exception from an Exception.
* @param exception original exception which was unexpected
*/
public InternalException(Exception e) {
super(e.toString());
// if the exception is merely bubbling up the stack, only log the
// event if debug is turned on.
if (!(e instanceof InternalException)) {
category.fatal(e);
} else {
category.debug(e);
}
// if the debug is enabled, add a stack trace.
if (category.isDebugEnabled()) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer));
category.debug(writer.getBuffer().toString());
}
}
}
1.54 +6 -1 xml-axis/java/src/org/apache/axis/client/Call.java
Index: Call.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Call.java,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- Call.java 2001/12/18 21:34:15 1.53
+++ Call.java 2001/12/23 12:33:31 1.54
@@ -96,6 +96,7 @@
import javax.xml.rpc.namespace.QName;
import javax.xml.rpc.JAXRPCException;
+import java.beans.IntrospectionException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
@@ -1004,9 +1005,13 @@
* @param _class the class of the associated Java data type.
* @param deserializerFactory a factory which can create deserializer
* instances for this type.
+ * @throws IntrospectionException _class is not compatible with the
+ * specified deserializer.
*/
public void addDeserializerFactory(QName qName, Class _class,
- DeserializerFactory deserFactory){
+ DeserializerFactory deserFactory)
+ throws IntrospectionException
+ {
TypeMappingRegistry typeMap = msgContext.getTypeMappingRegistry();
typeMap.addDeserializerFactory(qName, _class, deserFactory);
}
1.70 +4 -0 xml-axis/java/src/org/apache/axis/client/ServiceClient.java
Index: ServiceClient.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/ServiceClient.java,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- ServiceClient.java 2001/12/03 22:49:23 1.69
+++ ServiceClient.java 2001/12/23 12:33:31 1.70
@@ -68,6 +68,7 @@
import org.apache.log4j.Category;
import javax.xml.rpc.namespace.QName;
+import java.beans.IntrospectionException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Vector;
@@ -410,10 +411,13 @@
* @param _class the class of the associated Java data type.
* @param deserializerFactory a factory which can create deserializer
* instances for this type.
+ * @throws IntrospectionException _class is not compatible with the
+ * specified deserializer.
*/
public void addDeserializerFactory(QName qName,
Class _class,
DeserializerFactory deserializerFactory)
+ throws IntrospectionException
{
call.addDeserializerFactory(qName, _class, deserializerFactory);
}
1.23 +7 -1 xml-axis/java/src/org/apache/axis/deployment/SimpleDeploymentManager.java
Index: SimpleDeploymentManager.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/SimpleDeploymentManager.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- SimpleDeploymentManager.java 2001/12/06 16:56:05 1.22
+++ SimpleDeploymentManager.java 2001/12/23 12:33:31 1.23
@@ -56,6 +56,7 @@
import org.apache.axis.Constants;
import org.apache.axis.Handler;
+import org.apache.axis.InternalException;
import org.apache.axis.deployment.wsdd.WSDDGlobalConfiguration;
import org.apache.axis.deployment.wsdd.WSDDDocument;
import org.apache.axis.deployment.wsdd.WSDDHandler;
@@ -107,7 +108,12 @@
{
mappings = new Hashtable();
- mappings.put(Constants.URI_SOAP_ENC, new SOAPTypeMappingRegistry());
+ try {
+ mappings.put(Constants.URI_SOAP_ENC, new SOAPTypeMappingRegistry());
+ } catch (Exception e) {
+ // if this ever occurs, we have an internal error
+ throw new InternalException(e);
+ }
}
/**
1.29 +3 -1 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java
Index: WSDDService.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- WSDDService.java 2001/12/16 18:07:43 1.28
+++ WSDDService.java 2001/12/23 12:33:31 1.29
@@ -72,8 +72,8 @@
import javax.xml.rpc.namespace.QName;
import java.util.Vector;
import java.io.IOException;
+import java.beans.IntrospectionException;
-
/**
*
*/
@@ -279,6 +279,8 @@
tmr.addDeserializerFactory(mapping.getQName(), mapping
.getLanguageSpecificType(), deser);
}
+ } catch (IntrospectionException e) {
+ throw new WSDDException(e);
} catch (InstantiationException e) {
throw new WSDDException(e);
} catch (IllegalAccessException e) {
1.30 +4 -1 xml-axis/java/src/org/apache/axis/encoding/ArraySerializer.java
Index: ArraySerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ArraySerializer.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- ArraySerializer.java 2001/12/19 15:05:30 1.29
+++ ArraySerializer.java 2001/12/23 12:33:32 1.30
@@ -71,6 +71,8 @@
import java.util.List;
import java.util.StringTokenizer;
+import java.beans.IntrospectionException;
+
/** An ArraySerializer handles serializing and deserializing SOAP
* arrays.
*
@@ -100,7 +102,8 @@
}
public static class Factory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {
return new ArraySerializer();
}
}
1.12 +2 -1 xml-axis/java/src/org/apache/axis/encoding/Base64Serializer.java
Index: Base64Serializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/Base64Serializer.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Base64Serializer.java 2001/11/18 19:21:39 1.11
+++ Base64Serializer.java 2001/12/23 12:33:32 1.12
@@ -94,7 +94,8 @@
static public class Base64DeserializerFactory
implements DeserializerFactory
{
- public Deserializer getDeserializer(Class cls) {return new Base64Deser();}
+ public void setJavaClass(Class cls) {};
+ public Deserializer getDeserializer() {return new Base64Deser();}
}
/**
1.29 +34 -17 xml-axis/java/src/org/apache/axis/encoding/BeanSerializer.java
Index: BeanSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/BeanSerializer.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- BeanSerializer.java 2001/12/22 04:38:14 1.28
+++ BeanSerializer.java 2001/12/23 12:33:32 1.29
@@ -55,6 +55,7 @@
package org.apache.axis.encoding;
+import org.apache.axis.InternalException;
import org.apache.axis.message.SOAPHandler;
import org.apache.axis.utils.JavaUtils;
import org.apache.log4j.Category;
@@ -129,7 +130,7 @@
*/
public BeanSerializer(Class cls) {
super();
- this.cls = cls;
+ setCls(cls);
}
/**
@@ -137,8 +138,7 @@
* Equivalent to calling setCls(cls) on a new instance.
*/
public BeanSerializer(Class cls, short format) {
- super();
- this.cls = cls;
+ this(cls);
if (format > FORCE_LOWER ||
format < PROPERTY_NAME)
format = PROPERTY_NAME;
@@ -149,8 +149,7 @@
* Constructor that takes a class and a PropertyDescriptor array
*/
public BeanSerializer(Class cls, PropertyDescriptor[] pd) {
- super();
- this.cls = cls;
+ this(cls);
this.pd = processPropertyDescriptors(pd,cls);
}
@@ -328,24 +327,42 @@
* class. Caches the PropertyDescriptor
*/
public static class BeanDeserFactory implements DeserializerFactory {
- private Hashtable propertyDescriptors = new Hashtable();
+ private static Hashtable propertyDescriptors = new Hashtable();
+ private MyPropertyDescriptor [] pd;
- public Deserializer getDeserializer(Class cls) {
- MyPropertyDescriptor [] pd =
- (MyPropertyDescriptor [])propertyDescriptors.get(cls);
+ private Class cls;
+ private DeserializerFactory realDeserializerFactory;
+
+ public void setJavaClass(Class cls) throws IntrospectionException {
+ if ( (this.cls != null) && (this.cls != cls) ) {
+ throw new InternalException("Attempt to change class");
+ }
+
+ this.cls = cls;
+
+ pd = (MyPropertyDescriptor [])propertyDescriptors.get(cls);
if (pd == null) {
- try {
- PropertyDescriptor[] rawPd = Introspector.getBeanInfo(cls).getPropertyDescriptors();
- pd = processPropertyDescriptors(rawPd, cls);
- } catch (IntrospectionException e) {
- return null;
- }
+ PropertyDescriptor[] rawPd =
+ Introspector.getBeanInfo(cls).getPropertyDescriptors();
+ pd = processPropertyDescriptors(rawPd, cls);
propertyDescriptors.put(cls, pd);
}
- // If an enum class. Return the Deserializer for Enumeration
+ // If an enum class, use that factory class instead...
if (isEnumClass(cls)) {
- return EnumSerializer.getFactory().getDeserializer(cls);
+ realDeserializerFactory = EnumSerializer.getFactory(cls);
+ }
+ }
+
+ public Deserializer getDeserializer() {
+
+ // If this factory is just a proxy, use the real deserializer
+ // instead.
+ //
+ // Question: wouldn't it be better to require the deployer to use
+ // the right factory in the first place?
+ if (realDeserializerFactory != null) {
+ return realDeserializerFactory.getDeserializer();
}
BeanSerializer bs = new BeanSerializer();
1.9 +2 -1 xml-axis/java/src/org/apache/axis/encoding/BooleanDeserializerFactory.java
Index: BooleanDeserializerFactory.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/BooleanDeserializerFactory.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BooleanDeserializerFactory.java 2001/11/06 21:52:28 1.8
+++ BooleanDeserializerFactory.java 2001/12/23 12:33:32 1.9
@@ -87,6 +87,7 @@
}
}
- public Deserializer getDeserializer(Class cls) { return new BooleanDeser(); }
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() { return new BooleanDeser(); }
}
1.20 +3 -2 xml-axis/java/src/org/apache/axis/encoding/DateSerializer.java
Index: DateSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DateSerializer.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- DateSerializer.java 2001/11/21 16:34:19 1.19
+++ DateSerializer.java 2001/12/23 12:33:32 1.20
@@ -85,7 +85,7 @@
zulu.setTimeZone(TimeZone.getTimeZone("GMT"));
}
- static class DateDeser extends SOAPTypeMappingRegistry.BasicDeser {
+ static class DateDeser extends BasicDeserializer {
public Object makeValue(String source) {
Date result;
boolean bc = false;
@@ -193,7 +193,8 @@
}
static public class DateDeserializerFactory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {return new DateDeser();}
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {return new DateDeser();}
}
/**
1.6 +21 -3 xml-axis/java/src/org/apache/axis/encoding/DeserializerFactory.java
Index: DeserializerFactory.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializerFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DeserializerFactory.java 2001/10/30 14:19:29 1.5
+++ DeserializerFactory.java 2001/12/23 12:33:32 1.6
@@ -55,7 +55,25 @@
package org.apache.axis.encoding;
-public interface DeserializerFactory extends java.io.Serializable
-{
- public Deserializer getDeserializer(Class cls);
+import java.beans.IntrospectionException;
+
+/**
+ * DeserializerFactories produce preconfigured deserializers designed
+ * to convert an XML Element into the desired Java Class.
+ */
+public interface DeserializerFactory extends java.io.Serializable {
+
+ /**
+ * Specifify the class to be returned by the deserializer produced
+ * by this factory.
+ * @param cls the desired class
+ * @exception IntrospectionException unable to introspect the desired
+ * class or the class has the wrong type signature for its intended use.
+ */
+ public void setJavaClass(Class cls) throws IntrospectionException;
+
+ /**
+ * Obtain the desired deserializer.
+ */
+ public Deserializer getDeserializer();
}
1.5 +2 -1 xml-axis/java/src/org/apache/axis/encoding/ElementSerializer.java
Index: ElementSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ElementSerializer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ElementSerializer.java 2001/12/12 14:02:27 1.4
+++ ElementSerializer.java 2001/12/23 12:33:32 1.5
@@ -91,7 +91,8 @@
// Our static deserializer factory
public static class Factory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {
return new ElementSerializer();
}
}
1.3 +44 -14 xml-axis/java/src/org/apache/axis/encoding/EnumSerializer.java
Index: EnumSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/EnumSerializer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- EnumSerializer.java 2001/12/19 21:08:21 1.2
+++ EnumSerializer.java 2001/12/23 12:33:32 1.3
@@ -55,15 +55,21 @@
package org.apache.axis.encoding;
+import org.apache.axis.InternalException;
+
import org.xml.sax.Attributes;
import javax.xml.rpc.namespace.QName;
import java.io.IOException;
import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.beans.IntrospectionException;
+
/**
* Serializer for a JAX-RPC enum.
*
* @author Rich Scheuerle <sc...@us.ibm.com>
+ * @author Sam Ruby <ru...@us.ibm.com>
*/
public class EnumSerializer implements Serializer, Serializable {
@@ -99,22 +105,24 @@
context.endElement();
}
- public static DeserializerFactory getFactory()
+ public static DeserializerFactory getFactory(Class cls)
+ throws IntrospectionException
{
- return new EnumDeserializerFactory();
+ DeserializerFactory factory = new EnumDeserializerFactory();
+ factory.setJavaClass(cls);
+ return factory;
}
- public static class EnumDeserializer extends SOAPTypeMappingRegistry.BasicDeser {
- java.lang.reflect.Method fromStringMethod;
- public EnumDeserializer(Class cls)
- {
- try {
- fromStringMethod = cls.getMethod("fromString",
- new Class[] {java.lang.String.class});
- } catch (Exception e) {
- e.printStackTrace();
- throw new NullPointerException(e.toString());
- }
+ /**
+ * Deserialize an Enumeration data type. Prior to calling makeValue,
+ * the setFromStringMethod method must be called with an enumeration
+ * data type.
+ */
+ public static class EnumDeserializer extends BasicDeserializer {
+ private Method fromStringMethod;
+
+ protected void setFromStringMethod(Method fsm) {
+ this.fromStringMethod = fsm;
}
public Object makeValue(String source) throws Exception
@@ -126,8 +134,30 @@
}
}
+ /**
+ * Create a deserializer for a enumeration data type.
+ */
static public class EnumDeserializerFactory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {return new EnumDeserializer(cls);}
+ private Method fromStringMethod;
+
+ public void setJavaClass(Class cls) throws IntrospectionException {
+ if ( (this.fromStringMethod != null) ) {
+ throw new InternalException("Attempt to reuse factory");
+ }
+
+ try {
+ fromStringMethod = cls.getMethod("fromString",
+ new Class[] {java.lang.String.class});
+ } catch (Exception e) {
+ throw new IntrospectionException(e.toString());
+ }
+ }
+
+ public Deserializer getDeserializer() {
+ EnumDeserializer deserializer = new EnumDeserializer();
+ deserializer.setFromStringMethod(fromStringMethod);
+ return deserializer;
+ }
}
}
1.2 +13 -1 xml-axis/java/src/org/apache/axis/encoding/FloatSerializer.java
Index: FloatSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/FloatSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FloatSerializer.java 2001/11/15 20:31:38 1.1
+++ FloatSerializer.java 2001/12/23 12:33:32 1.2
@@ -55,6 +55,8 @@
package org.apache.axis.encoding;
+import org.apache.axis.InternalException;
+
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -108,7 +110,17 @@
static public class FloatDeserializerFactory
implements DeserializerFactory
{
- public Deserializer getDeserializer(Class cls) {
+ private Class cls;
+
+ public void setJavaClass(Class cls) {
+ if ( (this.cls != null) && (this.cls != cls) ) {
+ throw new InternalException("Attempt to change class");
+ }
+
+ this.cls = cls;
+ }
+
+ public Deserializer getDeserializer() {
if (cls == Float.class) {
return new FloatDeser();
} else {
1.10 +2 -1 xml-axis/java/src/org/apache/axis/encoding/HexSerializer.java
Index: HexSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/HexSerializer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- HexSerializer.java 2001/11/18 19:21:39 1.9
+++ HexSerializer.java 2001/12/23 12:33:32 1.10
@@ -94,7 +94,8 @@
static public class HexDeserializerFactory
implements DeserializerFactory
{
- public Deserializer getDeserializer(Class cls) {return new HexDeser();}
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {return new HexDeser();}
}
/**
1.2 +2 -1 xml-axis/java/src/org/apache/axis/encoding/JAFDataHandlerDeserializer.java
Index: JAFDataHandlerDeserializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/JAFDataHandlerDeserializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JAFDataHandlerDeserializer.java 2001/11/16 02:57:54 1.1
+++ JAFDataHandlerDeserializer.java 2001/12/23 12:33:32 1.2
@@ -88,7 +88,8 @@
*/
public static class Factory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {
return new JAFDataHandlerDeserializer();
}
1.12 +2 -1 xml-axis/java/src/org/apache/axis/encoding/MapSerializer.java
Index: MapSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/MapSerializer.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MapSerializer.java 2001/11/06 21:52:28 1.11
+++ MapSerializer.java 2001/12/23 12:33:32 1.12
@@ -92,7 +92,8 @@
// Our static deserializer factory
public static class Factory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {
return new MapSerializer();
}
}
1.51 +33 -89 xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java
Index: SOAPTypeMappingRegistry.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- SOAPTypeMappingRegistry.java 2001/12/11 18:40:33 1.50
+++ SOAPTypeMappingRegistry.java 2001/12/23 12:33:32 1.51
@@ -56,16 +56,15 @@
package org.apache.axis.encoding;
import org.apache.axis.Constants;
-import org.apache.axis.message.SOAPHandler;
+import org.apache.axis.InternalException;
import org.apache.axis.utils.JavaUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import javax.xml.rpc.namespace.QName;
import java.io.IOException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.util.List;
+import java.beans.IntrospectionException;
public class SOAPTypeMappingRegistry extends TypeMappingRegistry {
@@ -112,8 +111,10 @@
}
public static class ObjDeserializerFactory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) { return null; }
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() { return null; }
}
+
public static class ObjSerializer implements Serializer {
public void serialize(QName name, Attributes attributes,
Object value, SerializationContext context)
@@ -123,79 +124,7 @@
}
}
- public static abstract class BasicDeser extends Deserializer {
- StringBuffer val = new StringBuffer();
-
- public SOAPHandler onStartChild(String namespace,
- String localName,
- String prefix,
- Attributes attributes,
- DeserializationContext context)
- throws SAXException
- {
- throw new SAXException(
- JavaUtils.getMessage("cantHandle00", "BasicDeser"));
- }
-
- public void characters(char [] chars, int start, int end)
- throws SAXException
- {
- val.append(chars, start, end);
- }
-
- public void onEndElement(String namespace, String localName,
- DeserializationContext context)
- throws SAXException
- {
- try {
- value = makeValue(val.toString());
- } catch (InvocationTargetException ite) {
- Throwable realException = ite.getTargetException();
- if (realException instanceof Exception)
- throw new SAXException((Exception)realException);
- else
- throw new SAXException(ite.getMessage());
- } catch (Exception e) {
- throw new SAXException(e);
- }
- }
-
- abstract public Object makeValue(String source) throws Exception;
- }
-
- /** A deserializer for any simple type with a (String) constructor.
- *
- * The factory below will build one of these configured for the
- * desired Class each time.
- */
- public static class BasicDeserializer extends BasicDeser {
- Constructor constructor;
- public BasicDeserializer(Class cls)
- {
- try {
- constructor = cls.getDeclaredConstructor(
- new Class [] { String.class });
- } catch (Exception e) {
- // TODO : Handle errors / throw?
- e.printStackTrace();
- }
- }
-
- public Object makeValue(String source) throws Exception
- {
- return constructor.newInstance(new Object [] { source });
- }
- }
-
- public static class BasicDeserializerFactory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls)
- {
- return new BasicDeserializer(cls);
- }
- }
-
private Serializer arraySer = new ArraySerializer();
- private DeserializerFactory factory = new BasicDeserializerFactory();
private DeserializerFactory base64Ser =
new Base64Serializer.Base64DeserializerFactory();
private DeserializerFactory hexSer =
@@ -206,7 +135,9 @@
* @param base QName based on the current Schema namespace
* @param factory common factory to be used across all schemas
*/
- private void addDeserializersFor(QName base, Class cls, DeserializerFactory factory) {
+ private void addDeserializersFor(QName base, Class cls, DeserializerFactory factory)
+ throws IntrospectionException
+ {
addDeserializerFactory(base, cls, factory);
String localPart = base.getLocalPart();
for (int i=0; i<Constants.URIS_SCHEMA_XSD.length; i++) {
@@ -246,7 +177,7 @@
return qName;
}
- public SOAPTypeMappingRegistry() {
+ public SOAPTypeMappingRegistry() throws IntrospectionException {
SOAPEncoding se = new SOAPEncoding();
addSerializer(java.lang.String.class, XSD_STRING, se);
addSerializer(java.lang.Boolean.class, XSD_BOOLEAN, se);
@@ -263,13 +194,20 @@
addSerializer(Hex.class, XSD_HEXBIN, new HexSerializer());
addSerializer(java.math.BigDecimal.class, XSD_DECIMAL, se);
- addDeserializersFor(XSD_STRING, java.lang.String.class, factory);
- addDeserializersFor(XSD_INT, java.lang.Integer.class, factory);
- addDeserializersFor(XSD_INTEGER, java.math.BigInteger.class, factory);
- addDeserializersFor(XSD_LONG, java.lang.Long.class, factory);
- addDeserializersFor(XSD_SHORT, java.lang.Short.class, factory);
- addDeserializersFor(XSD_BYTE, java.lang.Byte.class, factory);
- addDeserializersFor(XSD_DECIMAL, java.math.BigDecimal.class, factory);
+ addDeserializersFor(XSD_STRING, java.lang.String.class,
+ BasicDeserializer.getFactory(java.lang.String.class));
+ addDeserializersFor(XSD_INT, java.lang.Integer.class,
+ BasicDeserializer.getFactory(java.lang.Integer.class));
+ addDeserializersFor(XSD_INTEGER, java.math.BigInteger.class,
+ BasicDeserializer.getFactory(java.math.BigInteger.class));
+ addDeserializersFor(XSD_LONG, java.lang.Long.class,
+ BasicDeserializer.getFactory(java.lang.Long.class));
+ addDeserializersFor(XSD_SHORT, java.lang.Short.class,
+ BasicDeserializer.getFactory(java.lang.Short.class));
+ addDeserializersFor(XSD_BYTE, java.lang.Byte.class,
+ BasicDeserializer.getFactory(java.lang.Byte.class));
+ addDeserializersFor(XSD_DECIMAL, java.math.BigDecimal.class,
+ BasicDeserializer.getFactory(java.math.BigDecimal.class));
addDeserializersFor(XSD_BOOLEAN, java.lang.Boolean.class,
new BooleanDeserializerFactory());
@@ -327,10 +265,16 @@
}
private static SOAPTypeMappingRegistry singleton = null;
- public synchronized static SOAPTypeMappingRegistry getSingleton()
- {
- if (singleton == null)
- singleton = new SOAPTypeMappingRegistry();
+ public synchronized static SOAPTypeMappingRegistry getSingleton() {
+ if (singleton == null) {
+ try {
+ singleton = new SOAPTypeMappingRegistry();
+ } catch (Exception e) {
+ // if this ever occurs, it is an internal error
+ throw new InternalException(e);
+ }
+ }
+
return singleton;
}
1.46 +7 -2 xml-axis/java/src/org/apache/axis/encoding/TypeMappingRegistry.java
Index: TypeMappingRegistry.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/TypeMappingRegistry.java,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- TypeMappingRegistry.java 2001/12/20 19:51:32 1.45
+++ TypeMappingRegistry.java 2001/12/23 12:33:32 1.46
@@ -64,6 +64,7 @@
import org.xml.sax.helpers.AttributesImpl;
import javax.xml.rpc.namespace.QName;
+import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.PrintStream;
import java.io.Serializable;
@@ -95,9 +96,11 @@
Class cls;
DeserializerFactory factory;
DeserializerDescriptor(Class cls, DeserializerFactory factory)
+ throws IntrospectionException
{
this.cls = cls;
this.factory = factory;
+ factory.setJavaClass(cls);
}
}
@@ -147,7 +150,9 @@
public void addDeserializerFactory(QName qname,
Class _class,
- DeserializerFactory deserializerFactory) {
+ DeserializerFactory deserializerFactory)
+ throws IntrospectionException
+ {
if (d == null) d= new Hashtable();
d.put(qname, new DeserializerDescriptor(_class, deserializerFactory));
}
@@ -186,7 +191,7 @@
if (d != null) {
DeserializerDescriptor desc = (DeserializerDescriptor)d.get(qname);
if ((desc != null) && (desc.factory != null))
- return desc.factory.getDeserializer(desc.cls);
+ return desc.factory.getDeserializer();
}
if (parent != null) return parent.getDeserializer(qname);
return null;
1.10 +2 -1 xml-axis/java/src/org/apache/axis/encoding/VectorDeserializer.java
Index: VectorDeserializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/VectorDeserializer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- VectorDeserializer.java 2001/11/06 21:52:28 1.9
+++ VectorDeserializer.java 2001/12/23 12:33:32 1.10
@@ -79,7 +79,8 @@
Category.getInstance(VectorDeserializer.class.getName());
public static class Factory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {
+ public void setJavaClass(Class cls) {}
+ public Deserializer getDeserializer() {
return new VectorDeserializer();
}
}
1.1 xml-axis/java/src/org/apache/axis/encoding/BasicDeserializer.java
Index: BasicDeserializer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Axis" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.axis.encoding;
import java.beans.IntrospectionException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.apache.axis.InternalException;
import org.apache.axis.message.SOAPHandler;
import org.apache.axis.utils.JavaUtils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* A deserializer for any simple type with a (String) constructor. Note:
* this class is designed so that subclasses need only override the makeValue
* method in order to construct objects of their own type.
*
* @author Glen Daniels (gdaniels@macromedia.com)
* @author Sam Ruby (rubys@us.ibm.com)
*/
public class BasicDeserializer extends Deserializer {
StringBuffer val = new StringBuffer();
private Constructor constructor;
/**
* Disallow nested elements. This method is defined by Deserializer.
*/
public SOAPHandler onStartChild(String namespace,
String localName,
String prefix,
Attributes attributes,
DeserializationContext context)
throws SAXException
{
throw new SAXException(
JavaUtils.getMessage("cantHandle00", "BasicDeser"));
}
/**
* Append any characters received to the value. This method is defined
* by Deserializer.
*/
public void characters(char [] chars, int start, int end)
throws SAXException
{
val.append(chars, start, end);
}
/**
* Append any characters to the value. This method is defined by
* Deserializer.
*/
public void onEndElement(String namespace, String localName,
DeserializationContext context)
throws SAXException
{
try {
value = makeValue(val.toString());
} catch (InvocationTargetException ite) {
Throwable realException = ite.getTargetException();
if (realException instanceof Exception)
throw new SAXException((Exception)realException);
else
throw new SAXException(ite.getMessage());
} catch (Exception e) {
throw new SAXException(e);
}
}
/**
* Setter for the private Constructor member.
* @param constructor the desired constructor to use
*/
public void setConstructor(Constructor constructor) {
this.constructor = constructor;
}
/**
* Convert the string that has been accumulated into an Object. Subclasses
* may override this.
* @param string the serialized value to be deserialized
* @throws Exception any exception thrown by this method will be wrapped
*/
public Object makeValue(String source) throws Exception
{
return constructor.newInstance(new Object [] { source });
}
/**
* Obtain a factory for the specified class.
* @param cls the desired class
*/
public static DeserializerFactory getFactory(Class cls)
throws IntrospectionException
{
DeserializerFactory factory = new BasicDeserializerFactory();
factory.setJavaClass(cls);
return factory;
}
/**
* Factory to create preinitialized BasicDeserializer instances. This
* factory will obtain desired constructor so that it does not need
* to be refound on every new BeanDeserializer.
*/
public static class BasicDeserializerFactory
implements DeserializerFactory
{
Constructor constructor;
/**
* Determine the constructor for the specified class. Ensure that the
* no attempt is made to reuse this factory for another class.
* @param cls the desired class
* @throws IntrospectionException class does not contain an appropriate
* constructor.
*/
public void setJavaClass(Class cls) throws IntrospectionException {
try {
Constructor constructor = cls.getDeclaredConstructor(
new Class [] {String.class});
if (this.constructor!=null)
if (!constructor.equals(this.constructor))
throw new InternalException("Attempt to reuse factory");
this.constructor = constructor;
} catch (NoSuchMethodException e) {
throw new IntrospectionException(e.toString());
}
}
/**
* Obtain an initialized deserializer.
*/
public Deserializer getDeserializer() {
BasicDeserializer deserializer = new BasicDeserializer();
deserializer.setConstructor(constructor);
return deserializer;
}
}
}
1.38 +2 -0 xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java
Index: SOAPService.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- SOAPService.java 2001/12/12 18:17:52 1.37
+++ SOAPService.java 2001/12/23 12:33:32 1.38
@@ -76,6 +76,7 @@
import javax.xml.rpc.namespace.QName;
import java.util.Enumeration;
import java.util.Vector;
+import java.beans.IntrospectionException;
/** A <code>SOAPService</code> is a Handler which encapsulates a SOAP
* invocation. It has an request chain, an response chain, and a pivot-point,
@@ -340,6 +341,7 @@
Class cls,
DeserializerFactory deserFactory,
Serializer serializer)
+ throws IntrospectionException
{
if (deserFactory != null)
typeMap.addDeserializerFactory(qName, cls, deserFactory);
1.10 +2 -1 xml-axis/java/test/encoding/DataSer.java
Index: DataSer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/encoding/DataSer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DataSer.java 2001/10/26 18:19:01 1.9
+++ DataSer.java 2001/12/23 12:33:32 1.10
@@ -20,7 +20,8 @@
public static final String FLOATMEMBER = "floatMember";
public static class DataSerFactory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) {
+ public void setJavaClass(Class cls) {};
+ public Deserializer getDeserializer() {
return new DataSer();
}
}