snichol 2002/06/27 20:07:36
Modified: java/docs changes.html
java/src/org/apache/soap Body.java Constants.java
java/src/org/apache/soap/encoding/soapenc
BeanMultiRefSerializer.java SoapEncUtils.java
java/src/org/apache/soap/rpc SOAPContext.java
Log:
Generalize a little so that multi-reference serializers besides
BeanMultiRefSerializer can exist.
Revision Changes Path
1.31 +1 -1 xml-soap/java/docs/changes.html
Index: changes.html
===================================================================
RCS file: /home/cvs/xml-soap/java/docs/changes.html,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- changes.html 28 Jun 2002 02:33:16 -0000 1.30
+++ changes.html 28 Jun 2002 03:07:35 -0000 1.31
@@ -42,7 +42,7 @@
<li>Enhance multi-reference deserialization by only deserializing
the object once, regardless of the number of references. Provide
initial support for multi-reference serialization. The new
- BeanMultiRefSerializer is the only serializer for which
+ BeanMultiRefSerializer is an example of a serializer for which
multi-reference serialization is supported. Added a sample to
demonstrate serialization and deserialization of a cyclic graph
of beans.</li>
1.8 +4 -5 xml-soap/java/src/org/apache/soap/Body.java
Index: Body.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/Body.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Body.java 28 Jun 2002 02:33:16 -0000 1.7
+++ Body.java 28 Jun 2002 03:07:36 -0000 1.8
@@ -175,17 +175,16 @@
// serialize any multiRefs
if (ctx.getMultiRefCount() > 0) {
- // TODO: support other serializers by having them registered
- // with the SOAPContext for each multiRef.
- BeanSerializer ser = new BeanSerializer();
+ // This context tells serialization that this is a multiRef with id=X
MultiRefContext mrc = new MultiRefContext();
// Note: it is *essential* that one keep calling the getMultiRefCount method
// rather than storing the result in a variable, as the act of serialization
// could generate additional multiRefs.
for (int id = 0; id < ctx.getMultiRefCount(); id++) {
- Object o = ctx.getMultiRef(id);
+ Object obj = ctx.getMultiRefObject(id);
+ Serializer ser = ctx.getMultiRefSerializer(id);
mrc.setId(id);
- ser.marshall(actualEncStyle, o.getClass(), o, mrc,
+ ser.marshall(actualEncStyle, obj.getClass(), obj, mrc,
sink, nsStack, xjmr, ctx);
sink.write(StringUtils.lineSeparator);
}
1.26 +2 -0 xml-soap/java/src/org/apache/soap/Constants.java
Index: Constants.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/Constants.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Constants.java 10 Jun 2002 03:49:57 -0000 1.25
+++ Constants.java 28 Jun 2002 03:07:36 -0000 1.26
@@ -64,6 +64,7 @@
*
* @author Sanjiva Weerawarana ([EMAIL PROTECTED])
* @author Matthew J. Duftler ([EMAIL PROTECTED])
+ * @author Scott Nichol ([EMAIL PROTECTED])
*/
public class Constants
{
@@ -176,6 +177,7 @@
// Attribute values.
public static String ATTRVAL_TRUE = "true";
+ public static String ATTRVAL_MULTIREF_ID_PREFIX = "id";
// SOAP defined fault codes.
public static String FAULT_CODE_VERSION_MISMATCH =
1.2 +3 -3
xml-soap/java/src/org/apache/soap/encoding/soapenc/BeanMultiRefSerializer.java
Index: BeanMultiRefSerializer.java
===================================================================
RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/encoding/soapenc/BeanMultiRefSerializer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanMultiRefSerializer.java 28 Jun 2002 02:33:16 -0000 1.1
+++ BeanMultiRefSerializer.java 28 Jun 2002 03:07:36 -0000 1.2
@@ -73,7 +73,6 @@
* @author Scott Nichol ([EMAIL PROTECTED])
*/
public class BeanMultiRefSerializer implements Serializer, Deserializer {
- // Delegate de-serialization to the BeanSerializer
private BeanSerializer deser = new BeanSerializer();
public void marshall(String inScopeEncStyle, Class javaType, Object src,
@@ -82,8 +81,8 @@
throws IllegalArgumentException, IOException {
nsStack.pushScope();
- int id = ctx.addMultiRef(src);
- sink.write("<" + context.toString() + " " + Constants.ATTR_REFERENCE +
"=\"#id" + id + "\" />");
+ int id = ctx.addMultiRef(src, deser);
+ sink.write("<" + context.toString() + " " + Constants.ATTR_REFERENCE +
"=\"#" + Constants.ATTRVAL_MULTIREF_ID_PREFIX + id + "\" />");
nsStack.popScope();
}
@@ -91,6 +90,7 @@
public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src,
XMLJavaMappingRegistry xjmr, SOAPContext ctx)
throws IllegalArgumentException {
+ // Delegate de-serialization to the BeanSerializer
return deser.unmarshall(inScopeEncStyle, elementType, src, xjmr, ctx);
}
}
1.14 +2 -1
xml-soap/java/src/org/apache/soap/encoding/soapenc/SoapEncUtils.java
Index: SoapEncUtils.java
===================================================================
RCS file:
/home/cvs/xml-soap/java/src/org/apache/soap/encoding/soapenc/SoapEncUtils.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SoapEncUtils.java 28 Jun 2002 02:33:16 -0000 1.13
+++ SoapEncUtils.java 28 Jun 2002 03:07:36 -0000 1.14
@@ -160,8 +160,9 @@
sink.write('<' + context.toString() + namespaceDecl);
+ // Write the id for a multiRef element
if (context instanceof MultiRefContext)
- sink.write(' ' + Constants.ATTR_ID + "=\"id" + ((MultiRefContext)
context).getId() + "\"");
+ sink.write(' ' + Constants.ATTR_ID + "=\"" +
Constants.ATTRVAL_MULTIREF_ID_PREFIX + ((MultiRefContext) context).getId() + "\"");
// Get prefixes for the needed namespaces.
String elementTypeNS = elementType.getNamespaceURI();
1.9 +30 -10 xml-soap/java/src/org/apache/soap/rpc/SOAPContext.java
Index: SOAPContext.java
===================================================================
RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/rpc/SOAPContext.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SOAPContext.java 28 Jun 2002 02:33:17 -0000 1.8
+++ SOAPContext.java 28 Jun 2002 03:07:36 -0000 1.9
@@ -60,6 +60,7 @@
import java.io.*;
import java.util.*;
import org.apache.soap.util.*;
+import org.apache.soap.util.xml.Serializer;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.server.*;
@@ -102,6 +103,16 @@
private static final String DEFAULT_BASEURI = "thismessage:/";
+ // Holds information about a multiRef to be serialized.
+ private class MultiRefInfo {
+ public Object obj;
+ public Serializer ser;
+ public MultiRefInfo(Object obj, Serializer ser) {
+ this.obj = obj;
+ this.ser = ser;
+ }
+ }
+
/**
* Constructor.
*/
@@ -595,31 +606,40 @@
* The id of the object is always between 0 and the count of multiRefs
* minus 1.
*
- * @param o The object for which a multiRef is desired.
+ * @param obj The object for which a multiRef is desired.
+ * @param ser The serializer with which to serialize the object.
* @return The id of the element.
*/
- public int addMultiRef(Object o) {
+ public int addMultiRef(Object obj, Serializer ser) {
// While a Hashtable might seem a better choice than a vector here,
// a Vector is easier to work with during serialization, since
// multiRefs may be added during the serialization of other multiRefs.
for (int i = 0; i < multiRef.size(); i++) {
- if (multiRef.elementAt(i) == o)
+ if (((MultiRefInfo) multiRef.elementAt(i)).obj == obj)
return i;
}
- multiRef.addElement(o);
+ multiRef.addElement(new MultiRefInfo(obj, ser));
return multiRef.size() - 1;
- // TODO: support other serializers by having them registered
- // with the SOAPContext for each multiRef object.
}
/**
- * Gets the multiRef for a particular id.
+ * Gets the multiRef object for a particular id.
+ *
+ * @param id The id.
+ * @return The multiRef object for the id.
+ */
+ public Object getMultiRefObject(int id) {
+ return ((MultiRefInfo) multiRef.elementAt(id)).obj;
+ }
+
+ /**
+ * Gets the multiRef serializer for a particular id.
*
* @param id The id.
- * @return The multiRef for the id.
+ * @return The multiRef serializer for the id.
*/
- public Object getMultiRef(int id) {
- return multiRef.elementAt(id);
+ public Serializer getMultiRefSerializer(int id) {
+ return ((MultiRefInfo) multiRef.elementAt(id)).ser;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>