You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by sn...@apache.org on 2002/08/29 05:33:44 UTC
cvs commit: xml-soap/java/src/org/apache/soap/encoding/soapenc CollectionSerializer.java MapSerializer.java
snichol 2002/08/28 20:33:44
Modified: java/docs changes.html
java/src/org/apache/soap/encoding SOAPMappingRegistry.java
java/src/org/apache/soap/encoding/soapenc MapSerializer.java
Added: java/samples/collection CollectionClient.java
CollectionService.java DeploymentDescriptor.xml
README testit.cmd testit.sh
java/src/org/apache/soap/encoding/soapenc
CollectionSerializer.java
Log:
Add serialization of collection/map interfaces and concrete classes
(besides Vector and Hashtable).
Revision Changes Path
1.41 +1 -0 xml-soap/java/docs/changes.html
Index: changes.html
===================================================================
RCS file: /home/cvs/xml-soap/java/docs/changes.html,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- changes.html 28 Aug 2002 18:53:40 -0000 1.40
+++ changes.html 29 Aug 2002 03:33:43 -0000 1.41
@@ -64,6 +64,7 @@
<li>Fix handling of missing Content-Type header.</li>
<li>Fix EJB and CORBA providers to check deployment descriptor to
determine whether method is exposed.</li>
+ <li>Add serialization of collection/map interfaces and concrete classes.</li>
</ul>
</li>
</ul>
1.1 xml-soap/java/samples/collection/CollectionClient.java
Index: CollectionClient.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 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 "SOAP" 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 and was
* originally based on software copyright (c) 2000, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package samples.collection;
import java.io.*;
import java.util.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.encoding.soapenc.*;
import org.apache.soap.rpc.*;
/**
* See \samples\collection\readme for info.
*
* @author Scott Nichol (snichol@computer.org)
*/
public class CollectionClient {
private static String getType(URL endpointURL, Call call) {
Response resp;
try {
resp = call.invoke(endpointURL, "");
} catch (SOAPException e) {
return "Caught SOAPException (" +
e.getFaultCode() + "): " +
e.getMessage();
}
// Check the response.
if (!resp.generatedFault()) {
Parameter ret = resp.getReturnValue();
return (String) ret.getValue();
} else {
Fault fault = resp.getFault();
return "Generated fault: " + fault;
}
}
private static void makeCall(URL endpointURL, Call call, Class type, Object value) {
Vector params = new Vector();
params.addElement(new Parameter("collection", type, value, null));
call.setParams(params);
System.out.println(type.getName() + " returns " + getType(endpointURL, call));
}
public static void main(String[] args) throws Exception {
if (args.length != 1
&& (args.length != 2 || !args[0].startsWith("-"))) {
System.err.println("Usage:");
System.err.println(" java " + CollectionClient.class.getName() +
" [-encodingStyleURI] SOAP-router-URL");
System.exit (1);
}
// Process the arguments.
int offset = 2 - args.length;
String encodingStyleURI = args.length == 2
? args[0].substring(1)
: Constants.NS_URI_SOAP_ENC;
URL url = new URL(args[1 - offset]);
// Build the call.
Call call = new Call();
call.setTargetObjectURI("urn:CollectionService");
call.setMethodName("getType");
call.setEncodingStyleURI(encodingStyleURI);
// Build a Stack to serialize in various ways.
Stack param = new Stack();
param.addElement("Mercury");
param.addElement("Venus");
param.addElement("Earth");
param.addElement("Mars");
param.addElement("Jupiter");
param.addElement("Saturn");
param.addElement("Uranus");
param.addElement("Neptune");
param.addElement("Pluto");
makeCall(url, call, Collection.class, param);
makeCall(url, call, List.class, param);
makeCall(url, call, Vector.class, param);
makeCall(url, call, Stack.class, param);
// Build an ArrayList to serialize in various ways.
ArrayList param1 = new ArrayList(param);
makeCall(url, call, ArrayList.class, param1);
// Build a TreeSet to serialize in various ways.
TreeSet param2 = new TreeSet(param);
makeCall(url, call, Set.class, param2);
makeCall(url, call, SortedSet.class, param2);
makeCall(url, call, TreeSet.class, param2);
// Build an HashSet to serialize in various ways.
HashSet param3 = new HashSet(param);
makeCall(url, call, HashSet.class, param3);
// Build a LinkedList to serialize in various ways.
LinkedList param4 = new LinkedList(param);
makeCall(url, call, LinkedList.class, param4);
// Build a Hashtable to serialize in various ways.
Hashtable param5 = new Hashtable();
param5.put("Mercury", new Integer(1));
param5.put("Venus", new Integer(2));
param5.put("Earth", new Integer(3));
param5.put("Mars", new Integer(4));
param5.put("Jupiter", new Integer(5));
param5.put("Saturn", new Integer(6));
param5.put("Uranus", new Integer(7));
param5.put("Neptune", new Integer(8));
param5.put("Pluto", new Integer(9));
makeCall(url, call, Map.class, param5);
makeCall(url, call, Dictionary.class, param5);
makeCall(url, call, Hashtable.class, param5);
// Build a HashMap to serialize in various ways.
HashMap param6 = new HashMap(param5);
makeCall(url, call, HashMap.class, param6);
// Build a WeakHashMap to serialize in various ways.
WeakHashMap param7 = new WeakHashMap(param5);
makeCall(url, call, WeakHashMap.class, param7);
// Build a TreeMap to serialize in various ways.
TreeMap param8 = new TreeMap(param5);
makeCall(url, call, SortedMap.class, param8);
makeCall(url, call, TreeMap.class, param8);
}
}
1.1 xml-soap/java/samples/collection/CollectionService.java
Index: CollectionService.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 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 "SOAP" 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 and was
* originally based on software copyright (c) 2000, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package samples.collection;
import java.util.*;
/**
* @author Scott Nichol (snichol@computer.org)
*/
public class CollectionService {
public String getType(Collection c) {
return "Collection";
}
public String getType(List l) {
return "List";
}
public String getType(Map m) {
return "Map";
}
public String getType(Set s) {
return "Set";
}
public String getType(SortedMap m) {
return "SortedMap";
}
public String getType(SortedSet s) {
return "SortedSet";
}
public String getType(ArrayList l) {
return "ArrayList";
}
public String getType(Dictionary d) {
return "Dictionary";
}
public String getType(HashMap m) {
return "HashMap";
}
public String getType(HashSet s) {
return "HashSet";
}
public String getType(Hashtable t) {
return "Hashtable";
}
public String getType(LinkedList l) {
return "LinkedList";
}
public String getType(Stack s) {
return "Stack";
}
public String getType(TreeMap m) {
return "TreeMap";
}
public String getType(TreeSet s) {
return "TreeSet";
}
public String getType(Vector v) {
return "Vector";
}
public String getType(WeakHashMap m) {
return "WeakHashMap";
}
}
1.1 xml-soap/java/samples/collection/DeploymentDescriptor.xml
Index: DeploymentDescriptor.xml
===================================================================
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:CollectionService">
<isd:provider type="java"
scope="Application"
methods="getType">
<isd:java class="samples.collection.CollectionService" static="false"/>
<isd:option key="SessionRequired" value="false"/>
</isd:provider>
<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
</isd:service>
1.1 xml-soap/java/samples/collection/README
Index: README
===================================================================
Service:
-------
To install this service on an Apache-SOAP listener, you need to make
the samples.collection package available on the Apache-SOAP listener's
classpath. Then deploy this service by filling in the deployment
template using the info in the deployment descriptor in this
directory or by using the service manager client:
java org.apache.soap.server.ServiceManagerClient routerURL deploy dd.xml
where routerURL is the URL of the SOAP RPC router and dd.xml is the
name of the deployment descriptor file. For example:
java org.apache.soap.server.ServiceManagerClient \
http://localhost:8080/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
Client:
------
There is 1 sample clients:
java samples.collection.CollectionClient
Run this with no args to see the usage.
Additional Client Classpath Requirements:
----------------------------------------
../..
Explanation:
-----------
This is a simple service that tests the serialization of collections, both
concrete classes and interfaces.
Sample Usage:
------------
java samples.collection.CollectionClient \
http://localhost:2020/soap/servlet/rpcrouter
1.1 xml-soap/java/samples/collection/testit.cmd
Index: testit.cmd
===================================================================
@echo off
echo This test assumes a server URL of http://localhost:8080/soap/servlet/rpcrouter
echo Deploying the collection service...
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
echo .
echo Verify that it's there
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter list
echo .
echo Run the client
java samples.collection.CollectionClient http://localhost:8080/soap/servlet/rpcrouter
echo .
echo Undeploy it now
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter undeploy urn:CollectionService
echo .
echo Verify that it's gone
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter list
1.1 xml-soap/java/samples/collection/testit.sh
Index: testit.sh
===================================================================
echo This test assumes a server URL of http://localhost:8080/soap/servlet/rpcrouter
echo Deploying the collection service...
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter deploy DeploymentDescriptor.xml
echo
echo Verify that it\'s there
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter list
echo
echo Run the client
java samples.collection.CollectionClient http://localhost:8080/soap/servlet/rpcrouter
echo
echo Undeploy it now
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter undeploy urn:CollectionService
echo
echo Verify that it\'s gone
java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter list
1.29 +78 -9 xml-soap/java/src/org/apache/soap/encoding/SOAPMappingRegistry.java
Index: SOAPMappingRegistry.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/encoding/SOAPMappingRegistry.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- SOAPMappingRegistry.java 11 Apr 2002 23:22:04 -0000 1.28
+++ SOAPMappingRegistry.java 29 Aug 2002 03:33:44 -0000 1.29
@@ -286,15 +286,22 @@
throws IllegalArgumentException, IOException {
nsStack.pushScope();
- SoapEncUtils.generateStructureHeader(inScopeEncStyle,
- javaType,
- context,
- sink,
- nsStack,
- xjmr);
-
- sink.write(src + "</" + context + '>');
+ if (src == null)
+ {
+ SoapEncUtils.generateNullStructure(inScopeEncStyle, javaType, context,
+ sink, nsStack, xjmr);
+ }
+ else
+ {
+ SoapEncUtils.generateStructureHeader(inScopeEncStyle,
+ javaType,
+ context,
+ sink,
+ nsStack,
+ xjmr);
+ sink.write(src + "</" + context + '>');
+ }
nsStack.popScope();
}
};
@@ -519,15 +526,77 @@
*/
mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Vector"),
Vector.class, vectorSer, vectorSer);
+ // Note: the element type 'Map' is maintained for backward compatibility
mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Map"),
Hashtable.class, hashtableSer, hashtableSer);
try {
Class mapClass = Class.forName("java.util.Map");
MapSerializer mapSer = new MapSerializer();
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "MapInterface"),
+ mapClass, mapSer, mapSer);
+
+ mapClass = Class.forName("java.util.SortedMap");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "SortedMap"),
+ mapClass, mapSer, mapSer);
+
+ mapClass = Class.forName("java.util.Dictionary");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Dictionary"),
+ mapClass, mapSer, mapSer);
+
+ mapClass = Class.forName("java.util.HashMap");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "HashMap"),
+ mapClass, mapSer, mapSer);
+
+ mapClass = Class.forName("java.util.TreeMap");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "TreeMap"),
+ mapClass, mapSer, mapSer);
- mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Map"),
+ mapClass = Class.forName("java.util.WeakHashMap");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "WeakHashMap"),
mapClass, mapSer, mapSer);
+ } catch (ClassNotFoundException cnfe) {
+ } catch (NoClassDefFoundError ncdfe) {
+ // If the class can't be loaded, continue without it...
+ }
+
+ try {
+ Class collectionClass = Class.forName("java.util.Collection");
+ CollectionSerializer collectionSer = new CollectionSerializer();
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Collection"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.List");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "List"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.Set");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Set"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.SortedSet");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "SortedSet"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.ArrayList");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "ArrayList"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.LinkedList");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "LinkedList"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.HashSet");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "HashSet"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.TreeSet");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "TreeSet"),
+ collectionClass, collectionSer, collectionSer);
+
+ collectionClass = Class.forName("java.util.Stack");
+ mapTypes(soapEncURI, new QName(Constants.NS_URI_XML_SOAP, "Stack"),
+ collectionClass, collectionSer, collectionSer);
} catch (ClassNotFoundException cnfe) {
} catch (NoClassDefFoundError ncdfe) {
// If the class can't be loaded, continue without it...
1.10 +16 -2 xml-soap/java/src/org/apache/soap/encoding/soapenc/MapSerializer.java
Index: MapSerializer.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/encoding/soapenc/MapSerializer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MapSerializer.java 18 May 2001 14:31:14 -0000 1.9
+++ MapSerializer.java 29 Aug 2002 03:33:44 -0000 1.10
@@ -109,7 +109,7 @@
}
hashtableSer.marshall(inScopeEncStyle,
- Hashtable.class,
+ javaType,
hashtable,
context,
sink,
@@ -125,10 +125,24 @@
SOAPContext ctx)
throws IllegalArgumentException
{
- return hashtableSer.unmarshall(inScopeEncStyle,
+ Bean bean = hashtableSer.unmarshall(inScopeEncStyle,
elementType,
src,
xjmr,
ctx);
+ // Create a new bean based on the de-serialized hashtable
+ // and elementType
+ Class javaType = xjmr.queryJavaType(elementType, inScopeEncStyle);
+ if (javaType != null) {
+ bean.type = javaType;
+ if (javaType.equals(SortedMap.class) || javaType.equals(TreeMap.class)) {
+ bean.value = new TreeMap((Hashtable) bean.value);
+ } else if (javaType.equals(HashMap.class)) {
+ bean.value = new HashMap((Hashtable) bean.value);
+ } else if (javaType.equals(WeakHashMap.class)) {
+ bean.value = new WeakHashMap((Hashtable) bean.value);
+ }
+ }
+ return bean;
}
}
1.1 xml-soap/java/src/org/apache/soap/encoding/soapenc/CollectionSerializer.java
Index: CollectionSerializer.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000 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 "SOAP" 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 and was
* originally based on software copyright (c) 2000, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.soap.encoding.soapenc;
import java.beans.*;
import java.io.*;
import java.util.*;
import java.lang.reflect.*;
import org.w3c.dom.*;
import org.apache.soap.util.*;
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
/**
* A <code>CollectionSerializer</code> can be used to serialize and
* deserialize Collections using the <code>SOAP-ENC</code>
* encoding style. This is a quick implementation that simply
* delegates to the VectorSerializer.
*
* @author Scott Nichol (snichol@computer.org)
*/
public class CollectionSerializer implements Serializer, Deserializer {
private final VectorSerializer vectorSer = new VectorSerializer();
public void marshall(String inScopeEncStyle,
Class javaType,
Object src,
Object context,
Writer sink,
NSStack nsStack,
XMLJavaMappingRegistry xjmr,
SOAPContext ctx)
throws IllegalArgumentException, IOException {
Vector vector = null;
if (src instanceof Vector) {
vector = (Vector) src;
} else if (src instanceof Collection) {
vector = new Vector((Collection) src);
} else {
throw new IllegalArgumentException("Tried to pass a '" +
src.getClass().toString() +
"' to CollectionSerializer");
}
vectorSer.marshall(inScopeEncStyle,
javaType,
vector,
context,
sink,
nsStack,
xjmr,
ctx);
}
public Bean unmarshall(String inScopeEncStyle,
QName elementType,
Node src,
XMLJavaMappingRegistry xjmr,
SOAPContext ctx)
throws IllegalArgumentException {
Bean bean = vectorSer.unmarshall(inScopeEncStyle,
elementType,
src,
xjmr,
ctx);
// Create a new bean based on the de-serialized vector
// and elementType
Class javaType = xjmr.queryJavaType(elementType, inScopeEncStyle);
if (javaType != null) {
bean.type = javaType;
if (javaType.equals(Stack.class)) {
Stack s = new Stack();
Vector v = (Vector) bean.value;
for (int i = 0; i < v.size(); i++)
s.addElement(v.elementAt(i));
bean.value = s;
} else if (javaType.equals(List.class) || javaType.equals(ArrayList.class)) {
bean.value = new ArrayList((Vector) bean.value);
} else if (javaType.equals(LinkedList.class)) {
bean.value = new LinkedList((Vector) bean.value);
} else if (javaType.equals(Set.class) || javaType.equals(SortedSet.class) || javaType.equals(TreeSet.class)) {
bean.value = new TreeSet((Vector) bean.value);
} else if (javaType.equals(HashSet.class)) {
bean.value = new HashSet((Vector) bean.value);
}
}
return bean;
}
}