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 st...@apache.org on 2002/10/18 01:35:48 UTC
cvs commit: xml-axis/java/src/org/apache/axis/encoding/ser/castor CastorDeserializer.java CastorDeserializerFactory.java CastorSerializer.java CastorSerializerFactory.java
stevel 2002/10/17 16:35:48
Added: java/src/org/apache/axis/encoding/ser/castor
CastorDeserializer.java
CastorDeserializerFactory.java
CastorSerializer.java CastorSerializerFactory.java
Log:
castor support. I'm hoping someone will get a chance to play with this and hence write the docs and tests to go with it.
Revision Changes Path
1.1 xml-axis/java/src/org/apache/axis/encoding/ser/castor/CastorDeserializer.java
Index: CastorDeserializer.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.exolab.castor.xml.Unmarshaller;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
import java.util.ArrayList;
/**
* Castor deserializer
* @author Olivier Brand (olivier.brand@vodafone.com)
* @author Steve Loughran
* @version 1.0
*
*/
public class CastorDeserializer
extends DeserializerImpl
implements Deserializer {
public QName xmlType;
public Class javaType;
public CastorDeserializer(Class javaType, QName xmlType) {
this.xmlType = xmlType;
this.javaType = javaType;
}
/**
* Return something even if no characters were found.
*/
public void onEndElement(
String namespace,
String localName,
DeserializationContext context)
throws SAXException {
try {
MessageElement msgElem = context.getCurElement();
if (msgElem != null) {
ArrayList children = msgElem.getChildren();
if (children != null) {
msgElem = (MessageElement) children.get(0);
if (msgElem != null) {
// Unmarshall the nested XML element into a castor object of type 'javaType'
value = Unmarshaller.unmarshal(javaType, msgElem.getAsDOM());
}
}
}
} catch (MarshalException me) {
log.error(Messages.getMessage("castorMarshalException00"), me);
throw new SAXException(Messages.getMessage("castorMarshalException00")
+ me.getLocalizedMessage());
} catch (ValidationException ve) {
log.error(Messages.getMessage("castorValidationException00"), ve);
throw new SAXException(Messages.getMessage("castorValidationException00")
+ ve.getLocalizedMessage());
} catch (Exception exp) {
log.error(Messages.getMessage("exception00"), exp);
throw new SAXException(exp);
}
}
}
1.1 xml-axis/java/src/org/apache/axis/encoding/ser/castor/CastorDeserializerFactory.java
Index: CastorDeserializerFactory.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 CastorDeserializer Factory
*
* @author Olivier Brand (olivier.brand@vodafone.com)
*/
public class CastorDeserializerFactory extends BaseDeserializerFactory {
public CastorDeserializerFactory(Class javaType, QName xmlType) {
super(CastorDeserializer.class, xmlType, javaType);
}
}
1.1 xml-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializer.java
Index: CastorSerializer.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.utils.Messages;
import org.apache.axis.encoding.SerializationContext;
import org.apache.axis.encoding.Serializer;
import org.apache.axis.encoding.DeserializerImpl;
import org.apache.axis.wsdl.fromJava.Types;
import org.apache.commons.logging.Log;
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import javax.xml.namespace.QName;
import java.io.*;
/**
* Castor serializer
* @author Olivier Brand (olivier.brand@vodafone.com)
* @author Steve Loughran
* @version 1.0
*
*/
public class CastorSerializer implements Serializer {
protected static Log log =
LogFactory.getLog(CastorSerializer.class.getName());
/**
* Serialize a Castor 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);
String fdate;
StringWriter writer = null;
try {
writer = new StringWriter();
// Create a Castor Marshaller initialized with the output stream
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
//an XML document containing already a DOCTYPE
marshaller.setMarshalAsDocument(false);
// Marshall the Castor object into the stream (sink)
marshaller.marshal(value);
context.writeString(writer.toString());
} catch (MarshalException me) {
log.error(Messages.getMessage("castorMarshalException00"), me);
throw new IOException(Messages.getMessage("castorMarshalException00")
+ me.getLocalizedMessage());
} catch (ValidationException ve) {
log.error(Messages.getMessage("castorValidationException00"), ve);
throw new IOException(Messages.getMessage("castorValidationException00")
+ ve.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.
*
* @param types the Java2WSDL Types object which holds the context
* for the WSDL being generated.
* @return true if we wrote a schema, false if we didn't.
* @see org.apache.axis.wsdl.fromJava.Types
*/
public boolean writeSchema(Types types) throws Exception {
return false;
}
}
1.1 xml-axis/java/src/org/apache/axis/encoding/ser/castor/CastorSerializerFactory.java
Index: CastorSerializerFactory.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 objects
*
* @author Olivier Brand (olivier.brand@vodafone.com)
*/
public class CastorSerializerFactory extends BaseSerializerFactory {
public CastorSerializerFactory(Class javaType, QName xmlType) {
super(CastorSerializer.class, xmlType, javaType);
}
}