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 gd...@apache.org on 2002/08/14 14:34:14 UTC
cvs commit: xml-axis/java/src/org/apache/axis/encoding/ser BeanSerializer.java SimpleSerializer.java
gdaniels 2002/08/14 05:34:14
Modified: java/src/org/apache/axis/encoding/ser BeanSerializer.java
SimpleSerializer.java
Removed: java/src/org/apache/axis/encoding
AttributeSerializationContextImpl.java
Log:
Simplify attribute serialization. SimpleSerializer gets a static
valueToString() method which accounts for the Double/Float values,
and just calls toString() on other things. Then the serializers just
call this instead of building an entire new SerializationContext each time
with suppressed elements. This should speed things up, and removes
an unnecessary class.
Revision Changes Path
1.48 +1 -9 xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
Index: BeanSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- BeanSerializer.java 13 Aug 2002 14:58:58 -0000 1.47
+++ BeanSerializer.java 14 Aug 2002 12:34:14 -0000 1.48
@@ -60,7 +60,6 @@
import org.apache.axis.description.FieldDesc;
import org.apache.axis.description.TypeDesc;
import org.apache.axis.encoding.SerializationContext;
-import org.apache.axis.encoding.AttributeSerializationContextImpl;
import org.apache.axis.encoding.Serializer;
import org.apache.axis.utils.BeanPropertyDescriptor;
import org.apache.axis.utils.BeanUtils;
@@ -78,7 +77,6 @@
import java.io.IOException;
import java.io.Serializable;
-import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.List;
@@ -499,13 +497,7 @@
QName qname,
AttributesImpl attrs,
SerializationContext context) throws Exception {
- StringWriter writer = new StringWriter();
- SerializationContext attributeContext = new AttributeSerializationContextImpl(writer, context);
- attributeContext.serialize(qname,
- null,
- propValue);
- writer.close();
- String propString = writer.getBuffer().toString();
+ String propString = SimpleSerializer.valueToString(propValue);
String namespace = qname.getNamespaceURI();
String localName = qname.getLocalPart();
1.21 +29 -28 xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java
Index: SimpleSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- SimpleSerializer.java 8 Jul 2002 14:37:44 -0000 1.20
+++ SimpleSerializer.java 14 Aug 2002 12:34:14 -0000 1.21
@@ -141,36 +141,37 @@
context.startElement(name, attributes);
if (value != null) {
- // We could have separate serializers/deserializers to take
- // care of Float/Double cases, but it makes more sence to
- // put them here with the rest of the java lang primitives.
- if (value instanceof Float ||
- value instanceof Double) {
- double data = 0.0;
- if (value instanceof Float) {
- data = ((Float) value).doubleValue();
- } else {
- data = ((Double) value).doubleValue();
- }
- if (Double.isNaN(data)) {
- context.writeString("NaN");
- } else if (data == Double.POSITIVE_INFINITY) {
- context.writeString("INF");
- } else if (data == Double.NEGATIVE_INFINITY) {
- context.writeString("-INF");
- } else {
- context.writeString(value.toString());
- }
- } else if (value instanceof String) {
- context.writeString(
- XMLUtils.xmlEncodeString(value.toString()));
- } else if (value instanceof SimpleType) {
- context.writeString(value.toString());
+ context.writeString(valueToString(value));
+ }
+ context.endElement();
+ }
+
+ public static String valueToString(Object value) {
+ // We could have separate serializers/deserializers to take
+ // care of Float/Double cases, but it makes more sence to
+ // put them here with the rest of the java lang primitives.
+ if (value instanceof Float ||
+ value instanceof Double) {
+ double data = 0.0;
+ if (value instanceof Float) {
+ data = ((Float) value).doubleValue();
+ } else {
+ data = ((Double) value).doubleValue();
+ }
+ if (Double.isNaN(data)) {
+ return "NaN";
+ } else if (data == Double.POSITIVE_INFINITY) {
+ return "INF";
+ } else if (data == Double.NEGATIVE_INFINITY) {
+ return "-INF";
} else {
- context.writeString(value.toString());
+ return value.toString();
}
+ } else if (value instanceof String) {
+ return XMLUtils.xmlEncodeString(value.toString());
+ } else {
+ return value.toString();
}
- context.endElement();
}
private Attributes getObjectAttributes(Object value,
@@ -212,7 +213,7 @@
// the attribute may be more sophisticated. For example, don't
// serialize if the attribute matches the default value.
if (propValue != null) {
- String propString = propValue.toString();
+ String propString = valueToString(propValue);
String namespace = qname.getNamespaceURI();
String localName = qname.getLocalPart();