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 di...@apache.org on 2003/12/12 14:43:04 UTC
cvs commit: ws-axis/java/src/org/apache/axis/encoding/ser/castor CastorEnumTypeDeserializer.java CastorEnumTypeDeserializerFactory.java CastorEnumTypeSerializer.java CastorEnumTypeSerializerFactory.java CastorDeserializer.java CastorDeserializerFactory.java CastorSerializer.java CastorSerializerFactory.java
dims 2003/12/12 05:43:04
Modified: java/src/org/apache/axis/encoding/ser/castor
CastorDeserializer.java
CastorDeserializerFactory.java
CastorSerializer.java CastorSerializerFactory.java
Added: java/src/org/apache/axis/encoding/ser/castor
CastorEnumTypeDeserializer.java
CastorEnumTypeDeserializerFactory.java
CastorEnumTypeSerializer.java
CastorEnumTypeSerializerFactory.java
Log:
Fix for Bug 25440 - CastorSerializer incorrectly serializes the object tree
Notes:
- Added additional files for Enum support with Castor from "Gurkan, Ozzie (MAN-Corporate)" <Oz...@cox.com>
Revision Changes Path
1.6 +4 -6 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorDeserializer.java
Index: CastorDeserializer.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorDeserializer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CastorDeserializer.java 20 Nov 2003 06:35:18 -0000 1.5
+++ CastorDeserializer.java 12 Dec 2003 13:43:04 -0000 1.6
@@ -55,8 +55,6 @@
package org.apache.axis.encoding.ser.castor;
-import javax.xml.namespace.QName;
-
import org.apache.axis.encoding.DeserializationContext;
import org.apache.axis.encoding.Deserializer;
import org.apache.axis.encoding.DeserializerImpl;
@@ -67,12 +65,14 @@
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.SAXException;
+import javax.xml.namespace.QName;
+
/**
* Castor deserializer
+ *
* @author Olivier Brand (olivier.brand@vodafone.com)
* @author Steve Loughran
* @version 1.0
- *
*/
public class CastorDeserializer
extends DeserializerImpl
@@ -94,11 +94,9 @@
String localName,
DeserializationContext context)
throws SAXException {
-
try {
MessageElement msgElem = context.getCurElement();
- if (msgElem != null)
- {
+ if (msgElem != null) {
// Unmarshall the nested XML element into a castor object of type 'javaType'
value = Unmarshaller.unmarshal(javaType, msgElem.getAsDOM());
}
1.3 +1 -1 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorDeserializerFactory.java
Index: CastorDeserializerFactory.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorDeserializerFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CastorDeserializerFactory.java 22 Apr 2003 19:34:37 -0000 1.2
+++ CastorDeserializerFactory.java 12 Dec 2003 13:43:04 -0000 1.3
@@ -61,7 +61,7 @@
/**
* A CastorDeserializer Factory
- *
+ *
* @author Olivier Brand (olivier.brand@vodafone.com)
*/
public class CastorDeserializerFactory extends BaseDeserializerFactory {
1.5 +11 -14 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializer.java
Index: CastorSerializer.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CastorSerializer.java 22 Apr 2003 19:34:37 -0000 1.4
+++ CastorSerializer.java 12 Dec 2003 13:43:04 -0000 1.5
@@ -74,10 +74,10 @@
/**
* Castor serializer
+ *
* @author Olivier Brand (olivier.brand@vodafone.com)
* @author Steve Loughran
* @version 1.0
- *
*/
public class CastorSerializer implements Serializer {
@@ -86,12 +86,13 @@
/**
* Serialize a Castor object.
- * @param name
- * @param attributes
- * @param value this must be a castor object for marshalling
- * @param context
+ *
+ * @param name
+ * @param attributes
+ * @param value this must be a castor object for marshalling
+ * @param context
* @throws IOException for XML schema noncompliance, bad object type, and any IO
- * trouble.
+ * trouble.
*/
public void serialize(
QName name,
@@ -99,16 +100,14 @@
Object value,
SerializationContext context)
throws IOException {
- context.startElement(name, attributes);
String fdate;
StringWriter writer = null;
try {
-
writer = new StringWriter();
// Create a Castor Marshaller initialized with the output stream
- Marshaller marshaller =new Marshaller(writer);
+ Marshaller marshaller = new Marshaller(writer);
// Don't include the DOCTYPE, otherwise an exception occurs due to
//2 DOCTYPE defined in the document. The XML fragment is included in
@@ -127,8 +126,6 @@
log.error(Messages.getMessage("castorValidationException00"), ve);
throw new IOException(Messages.getMessage("castorValidationException00")
+ ve.getLocalizedMessage());
- } finally {
- context.endElement();
}
}
@@ -140,10 +137,10 @@
* Return XML schema for the specified type, suitable for insertion into
* the <types> element of a WSDL document, or underneath an
* <element> or <attribute> declaration.
- *
+ *
* @param javaType the Java Class we're writing out schema for
- * @param types the Java2WSDL Types object which holds the context
- * for the WSDL being generated.
+ * @param types the Java2WSDL Types object which holds the context
+ * for the WSDL being generated.
* @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
1.3 +1 -1 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializerFactory.java
Index: CastorSerializerFactory.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializerFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CastorSerializerFactory.java 22 Apr 2003 19:34:37 -0000 1.2
+++ CastorSerializerFactory.java 12 Dec 2003 13:43:04 -0000 1.3
@@ -61,7 +61,7 @@
/**
* SerializerFactory for Castor objects
- *
+ *
* @author Olivier Brand (olivier.brand@vodafone.com)
*/
public class CastorSerializerFactory extends BaseSerializerFactory {
1.1 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorEnumTypeDeserializer.java
Index: CastorEnumTypeDeserializer.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.ser.castor;
import org.apache.axis.encoding.DeserializationContext;
import org.apache.axis.encoding.Deserializer;
import org.apache.axis.encoding.DeserializerImpl;
import org.apache.axis.message.MessageElement;
import org.apache.axis.utils.Messages;
import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
import java.lang.reflect.Method;
/**
* Castor deserializer
*
* @author Ozzie Gurkan
* @version 1.0
*/
public class CastorEnumTypeDeserializer
extends DeserializerImpl
implements Deserializer {
public QName xmlType;
public Class javaType;
public CastorEnumTypeDeserializer(Class javaType, QName xmlType) {
this.xmlType = xmlType;
this.javaType = javaType;
}
public void onEndElement(
String namespace,
String localName,
DeserializationContext context)
throws SAXException {
try {
MessageElement msgElem = context.getCurElement();
if (msgElem != null) {
Method method = javaType.getMethod("valueOf", new Class[]{String.class});
value = method.invoke(null, new Object[]{msgElem.getValue()});
}
} catch (Exception exp) {
log.error(Messages.getMessage("exception00"), exp);
throw new SAXException(exp);
}
}
}
1.1 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorEnumTypeDeserializerFactory.java
Index: CastorEnumTypeDeserializerFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 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.ser.castor;
import org.apache.axis.encoding.ser.BaseDeserializerFactory;
import javax.xml.namespace.QName;
/**
* A CastorEnumTypeDeserializer Factory
*
* @author Ozzie Gurkan
*/
public class CastorEnumTypeDeserializerFactory extends BaseDeserializerFactory {
public CastorEnumTypeDeserializerFactory(Class javaType, QName xmlType) {
super(CastorEnumTypeDeserializer.class, xmlType, javaType);
}
}
1.1 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorEnumTypeSerializer.java
Index: CastorEnumTypeSerializer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 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.ser.castor;
import org.apache.axis.Constants;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.encoding.Serializer;
import org.apache.axis.utils.Messages;
import org.apache.axis.wsdl.fromJava.Types;
import org.apache.commons.logging.Log;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Enumeration;
/**
* Castor serializer
*
* @author Ozzie Gurkan
* @version 1.0
*/
public class CastorEnumTypeSerializer implements Serializer {
protected static Log log =
LogFactory.getLog(CastorEnumTypeSerializer.class.getName());
/**
* Serialize a Castor Enum Type object.
*
* @param name
* @param attributes
* @param value this must be a castor object for marshalling
* @param context
* @throws IOException for XML schema noncompliance, bad object type, and any IO
* trouble.
*/
public void serialize(
QName name,
Attributes attributes,
Object value,
SerializationContext context)
throws IOException {
context.startElement(name, attributes);
try {
//get the value of the object
Method method = value.getClass().getMethod("toString", new Class[]{});
//call the method to return the string
String string = (String) method.invoke(value, new Object[]{});
//write the string
context.writeString(string);
} catch (Exception me) {
log.error(Messages.getMessage("exception00"), me);
throw new IOException("Castor object error: " + me.getLocalizedMessage());
} finally {
context.endElement();
}
}
public String getMechanismType() {
return Constants.AXIS_SAX;
}
/**
* Return XML schema for the specified type, suitable for insertion into
* the <types> element of a WSDL document, or underneath an
* <element> or <attribute> declaration.
*
* @param javaType the Java Class we're writing out schema for
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
* @return a type element containing a schema simpleType/complexType
* @see org.apache.axis.wsdl.fromJava.Types
*/
public Element writeSchema(Class javaType, Types types) throws Exception {
/*
<simpleType>
<restriction base="xsd:string">
<enumeration value="OK"/>
<enumeration value="ERROR"/>
<enumeration value="WARNING"/>
</restriction>
</simpleType>
*/
Element simpleType = types.createElement("simpleType");
Element restriction = types.createElement("restriction");
simpleType.appendChild(restriction);
restriction.setAttribute("base", Constants.NS_PREFIX_SCHEMA_XSD + ":string");
Method enumerateMethod = javaType.getMethod("enumerate", new Class[0]);
Enumeration en = (Enumeration) enumerateMethod.invoke(null, new Object[0]);
while (en.hasMoreElements()) {
Object obj = (Object) en.nextElement();
Method toStringMethod = obj.getClass().getMethod("toString", new Class[0]);
String value = (String) toStringMethod.invoke(obj, new Object[0]);
Element enumeration = types.createElement("enumeration");
restriction.appendChild(enumeration);
enumeration.setAttribute("value", value);
}
return simpleType;
}
}
1.1 ws-axis/java/src/org/apache/axis/encoding/ser/castor/CastorEnumTypeSerializerFactory.java
Index: CastorEnumTypeSerializerFactory.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 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.ser.castor;
import org.apache.axis.encoding.ser.BaseSerializerFactory;
import javax.xml.namespace.QName;
/**
* SerializerFactory for Castor Enum Type objects
*
* @author Ozzie Gurkan
*/
public class CastorEnumTypeSerializerFactory extends BaseSerializerFactory {
public CastorEnumTypeSerializerFactory(Class javaType, QName xmlType) {
super(CastorEnumTypeSerializer.class, xmlType, javaType);
}
}