snichol 2002/10/22 21:05:22 Modified: java/src/org/apache/soap/util/xml XMLJavaMappingRegistry.java Log: In mapTypes, only map Java type to XML type if a serializer was provided, and only map XML type to Java type if a deserializer was provided. Revision Changes Path 1.9 +106 -6 xml-soap/java/src/org/apache/soap/util/xml/XMLJavaMappingRegistry.java Index: XMLJavaMappingRegistry.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/xml/XMLJavaMappingRegistry.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- XMLJavaMappingRegistry.java 4 Oct 2002 13:34:17 -0000 1.8 +++ XMLJavaMappingRegistry.java 23 Oct 2002 04:05:22 -0000 1.9 @@ -67,30 +67,63 @@ import org.apache.soap.encoding.SOAPMappingRegistry; /** - * An <code>XMLJavaMappingRegistry</code> ... + * An <code>XMLJavaMappingRegistry</code>, which maps + * <ul> + * <li>Java types to Serializers</li> + * <li>XML types to Deserializers</li> + * <li>Java types to XML types</li> + * <li>XML types to Java types</li> + * </ul> * * @author Matthew J. Duftler ([EMAIL PROTECTED]) * @author Sanjiva Weerawarana ([EMAIL PROTECTED]) * @author Francisco Curbera ([EMAIL PROTECTED]) + * @author Scott Nichol ([EMAIL PROTECTED]) */ public class XMLJavaMappingRegistry { + /** Java type to Serializer */ private Hashtable sReg = new Hashtable(); + /** XML type to Deserializer */ private Hashtable dsReg = new Hashtable(); + /** XML type to Java type */ private Hashtable xml2JavaReg = new Hashtable(); + /** Java type to XML type */ private Hashtable java2XMLReg = new Hashtable(); + /** Encoding to use if none specified */ private String defaultEncodingStyle = null; - /** Set the default encoding style. If the query*() calls + /** + * Sets the default encoding style. If the query*() calls * are invoked with a null encodingStyleURI parameter, we'll * use this instead. + * + * @param defEncStyle The default encoding style. */ public void setDefaultEncodingStyle(String defEncStyle) { defaultEncodingStyle = defEncStyle; } - // To register the default, set both types to null. + /** + * Adds type and serializer mappings. If a serializer is specified, + * a mapping from the Java type to the serializer is added. If a + * deserializer is specifed, a mapping from the XML type to the + * deserializer is added. If both XML and Java types are specified, + * a mapping from the Java type to the XML type is added if a serializer + * is specified, and a mapping from the XML type to the Java type is + * added if a deserializer is specified. + * + * To register a default serializer and/or deserializer, set the + * corresponding type to null. + * + * @param encodingStyleURI The encoding style for the map. The + * encoding style qualifies the types. + * @param elementType The XML type. + * @param javaType The Java type. + * @param s The serializer. + * @param ds The deserializer. + */ public void mapTypes(String encodingStyleURI, QName elementType, Class javaType, Serializer s, Deserializer ds) { @@ -110,8 +143,12 @@ // Only map types if both types are provided. if (elementType != null && javaType != null) { - java2XMLReg.put(java2XMLKey, elementType); - xml2JavaReg.put(xml2JavaKey, javaType); + // Only map Java to XML if a serializer was provided + if (s != null) + java2XMLReg.put(java2XMLKey, elementType); + // Only map XML to Java if a deserializer was provided + if (ds != null) + xml2JavaReg.put(xml2JavaKey, javaType); } } @@ -119,6 +156,11 @@ * This version returns null if the serializer is not found. It is * intended for internal usage (its used for chaining registries, * for example). + * + * @param javaType The Java type. + * @param encodingStyleURI The encoding style. + * @return The serializer for the Java type and encoding style, null + * if one is not found. */ protected Serializer querySerializer_(Class javaType, String encodingStyleURI) @@ -141,8 +183,13 @@ } /** - * This version calls the protected method to do the work and if its + * This version calls the protected method to do the work and if it's * not found throws an exception. + * + * @param javaType The Java type. + * @param encodingStyleURI The encoding style. + * @return The serializer for the Java type and encoding style. + * @exception IllegalArgumentException If no serializer is found for the type. */ public Serializer querySerializer(Class javaType, String encodingStyleURI) throws IllegalArgumentException @@ -166,6 +213,11 @@ * This version returns null if the deserializer is not found. It is * intended for internal usage (its used for chaining registries, * for example). + * + * @param elementType The XML type. + * @param encodingStyleURI The encoding style. + * @return The deserializer for the XML type and encoding style, null + * if one is not found. */ protected Deserializer queryDeserializer_(QName elementType, String encodingStyleURI) @@ -191,6 +243,11 @@ /** * This version calls the protected method to do the work and if its * not found throws an exception. + * + * @param elementType The XML type. + * @param encodingStyleURI The encoding style. + * @return The deserializer for the XML type and encoding style. + * @exception IllegalArgumentException If no deserializer is found for the type. */ public Deserializer queryDeserializer(QName elementType, String encodingStyleURI) @@ -214,6 +271,11 @@ * This version returns null if the element type is not found. It is * intended for internal usage (its used for chaining registries, * for example). + * + * @param javaType The Java type. + * @param encodingStyleURI The encoding style. + * @return The XML type for the Java type and encoding style, null + * if one is not found. */ protected QName queryElementType_(Class javaType, String encodingStyleURI) { @@ -228,6 +290,11 @@ /** * This version calls the protected method to do the work and if its * not found throws an exception. + * + * @param javaType The Java type. + * @param encodingStyleURI The encoding style. + * @return The XML type for the Java type and encoding style. + * @exception IllegalArgumentException If no XML type is found for the Java type. */ public QName queryElementType(Class javaType, String encodingStyleURI) throws IllegalArgumentException @@ -250,6 +317,11 @@ * This version returns null if the Java type is not found. It is * intended for internal usage (its used for chaining registries, * for example). + * + * @param elementType The XML type. + * @param encodingStyleURI The encoding style. + * @return The Java type for the XML type and encoding style, null + * if one is not found. */ protected Class queryJavaType_(QName elementType, String encodingStyleURI) { @@ -264,6 +336,11 @@ /** * This version calls the protected method to do the work and if its * not found throws an exception. + * + * @param elementType The XML type. + * @param encodingStyleURI The encoding style. + * @return The Java type for the XML type and encoding style. + * @exception IllegalArgumentException If no Java type is found for the XML type. */ public Class queryJavaType(QName elementType, String encodingStyleURI) throws IllegalArgumentException @@ -282,6 +359,11 @@ } } + /** + * Marshalls a Java object using the serializer for its type. + * + * @deprecated ParameterSerializer delegates to other serializers. + */ public void marshall(String inScopeEncStyle, Class javaType, Object src, Object context, Writer sink, NSStack nsStack, SOAPContext ctx) @@ -293,6 +375,11 @@ sink, nsStack, this, ctx); } + /** + * Unmarshalls a Java object using the deserializer for its XML type. + * + * @deprecated ParameterDeserializer delegates to other serializers. + */ public Bean unmarshall(String inScopeEncStyle, QName elementType, Node src, SOAPContext ctx) throws IllegalArgumentException @@ -314,12 +401,25 @@ return ds.unmarshall(inScopeEncStyle, elementType, src, this, ctx); } + /** + * Creates a key for the registry Hashtables. + * + * @param type The Java type (as a Class) or the XML type (as a QName). + * @param encodingStyleURI The encoding style. + * @return The key. + */ private static String getKey(Object type, String encodingStyleURI) { String strObj = String.valueOf(type); return new StringBuffer(strObj.length() + 3 + encodingStyleURI.length()).append(strObj).append(" + ").append(encodingStyleURI).toString(); } + /** + * Gets the name of a Java class. + * + * @param javaType The Java class. + * @return The name of the Java class. + */ protected static String getClassName(Class javaType) { return javaType != null ? StringUtils.getClassName(javaType) : "null";
-- To unsubscribe, e-mail: <mailto:soap-dev-unsubscribe@;xml.apache.org> For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>