sanjiva 01/06/28 14:04:04 Modified: java/src/org/apache/soap/encoding SOAPMappingRegistry.java java/src/org/apache/soap/rpc Call.java java/src/org/apache/soap/server DeploymentDescriptor.java java/src/org/apache/soap/server/http MessageRouterServlet.java RPCRouterServlet.java ServerHTTPUtils.java java/src/org/apache/soap/util/xml XMLJavaMappingRegistry.java Log: made several changes to reduce the overhead of a SOAPMappingRegistry creation and also to reduce the number of SMRs created. Bill fixed the deployment descriptor to javaType= doesn't get output if the value is null (see bugzilla bug #2385). Removed SMR constructor which took the schema namespace URI because it doesn't work (new'ing an SMR with the desired URI isn't enough to make the entire thing use that schema URI). Submitted by: Bill Nagy, me Revision Changes Path 1.23 +206 -81 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.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- SOAPMappingRegistry.java 2001/05/23 18:42:19 1.22 +++ SOAPMappingRegistry.java 2001/06/28 21:04:02 1.23 @@ -82,31 +82,41 @@ */ public class SOAPMappingRegistry extends XMLJavaMappingRegistry { - private static final String soapEncURI = Constants.NS_URI_SOAP_ENC; + private static SOAPMappingRegistry baseReg1999; + private static SOAPMappingRegistry baseReg2000; + private static SOAPMappingRegistry baseReg2001; + + private SOAPMappingRegistry parent = null; + private String schemaURI; + + private static String soapEncURI = Constants.NS_URI_SOAP_ENC; - private static final QName arrayQName = new QName(soapEncURI, "Array"); + private static QName arrayQName = new QName(soapEncURI, "Array"); + + // create all the standard serializers/deserializers as static vars. + // these fill into all the various base registries. - private final StringDeserializer stringDeser = new StringDeserializer(); - private final IntDeserializer intDeser = new IntDeserializer(); - private final DecimalDeserializer decimalDeser = new DecimalDeserializer(); - private final FloatDeserializer floatDeser = new FloatDeserializer(); - private final DoubleDeserializer doubleDeser = new DoubleDeserializer(); - private final BooleanDeserializer booleanDeser = new BooleanDeserializer(); - private final LongDeserializer longDeser = new LongDeserializer(); - private final ShortDeserializer shortDeser = new ShortDeserializer(); - private final ByteDeserializer byteDeser = new ByteDeserializer(); - - private final QNameSerializer qNameSer = new QNameSerializer(); - private final ParameterSerializer paramSer = new ParameterSerializer(); - private final ArraySerializer arraySer = new ArraySerializer(); - private final VectorSerializer vectorSer = new VectorSerializer(); - private final HashtableSerializer hashtableSer = new HashtableSerializer(); - public static final MimePartSerializer partSer = new MimePartSerializer(); - private final XMLParameterSerializer xmlParamSer = - new XMLParameterSerializer(); - private final DateSerializer dateSer = new DateSerializer(); - private final CalendarSerializer calSer = new CalendarSerializer(); - private final UrTypeDeserializer objDeser = new UrTypeDeserializer(); + private static StringDeserializer stringDeser = new StringDeserializer(); + private static IntDeserializer intDeser = new IntDeserializer(); + private static DecimalDeserializer decimalDeser = new DecimalDeserializer(); + private static FloatDeserializer floatDeser = new FloatDeserializer(); + private static DoubleDeserializer doubleDeser = new DoubleDeserializer(); + private static BooleanDeserializer booleanDeser = new BooleanDeserializer(); + private static LongDeserializer longDeser = new LongDeserializer(); + private static ShortDeserializer shortDeser = new ShortDeserializer(); + private static ByteDeserializer byteDeser = new ByteDeserializer(); + + private static QNameSerializer qNameSer = new QNameSerializer(); + private static ParameterSerializer paramSer = new ParameterSerializer(); + private static ArraySerializer arraySer = new ArraySerializer(); + private static VectorSerializer vectorSer = new VectorSerializer(); + private static HashtableSerializer hashtableSer = new HashtableSerializer(); + private static XMLParameterSerializer xmlParamSer = + new XMLParameterSerializer(); + private static DateSerializer dateSer = new DateSerializer(); + private static CalendarSerializer calSer = new CalendarSerializer(); + private static UrTypeDeserializer objDeser = new UrTypeDeserializer(); + public static MimePartSerializer partSer = new MimePartSerializer(); /** * The following stuff is here to deal with the slight differences @@ -117,7 +127,7 @@ * !!! The order of the elements in these arrays is critical. Be * careful when editing. */ - QName schema1999QNames [] = { + private static QName schema1999QNames [] = { Constants.string1999QName, Constants.int1999QName, Constants.int1999QName, @@ -144,7 +154,7 @@ Constants.object1999QName, }; - QName schema2000QNames [] = { + private static QName schema2000QNames [] = { Constants.string2000QName, Constants.int2000QName, Constants.int2000QName, @@ -171,7 +181,7 @@ Constants.object2000QName, }; - QName schema2001QNames [] = { + private static QName schema2001QNames [] = { Constants.string2001QName, Constants.int2001QName, Constants.int2001QName, @@ -198,10 +208,7 @@ Constants.object2001QName, }; - public String schemaURI = Constants.NS_URI_1999_SCHEMA_XSD; - QName [] schemaQNames = schema1999QNames; - - Class classes [] = { + private static Class classes [] = { String.class, Integer.class, int.class, @@ -233,7 +240,7 @@ the characters {&, ", ', <, >} with their appropriate escape sequences. */ - Serializer cleanSer = new Serializer() + private static Serializer cleanSer = new Serializer() { public void marshall(String inScopeEncStyle, Class javaType, Object src, Object context, Writer sink, NSStack nsStack, @@ -259,7 +266,7 @@ This serializer should be used for numbers and other things that will not have any of the following characters: {&, ", ', <, >} */ - Serializer ser = new Serializer() + private static Serializer ser = new Serializer() { public void marshall(String inScopeEncStyle, Class javaType, Object src, Object context, Writer sink, NSStack nsStack, @@ -280,7 +287,7 @@ } }; - Serializer serializers [] = { + private static Serializer serializers [] = { cleanSer, // String ser, // Integer ser, // int @@ -307,7 +314,7 @@ null, // Object }; - Deserializer deserializers [] = { + private static Deserializer deserializers [] = { stringDeser, null, intDeser, @@ -334,39 +341,114 @@ objDeser, }; + /** + * Create a new SMR. The resulting registry is aware of all + * pre-defined type mappings. + */ public SOAPMappingRegistry() { - this(Constants.NS_URI_CURRENT_SCHEMA_XSD); + this.schemaURI = Constants.NS_URI_CURRENT_SCHEMA_XSD; + this.parent = getBaseRegistry (Constants.NS_URI_CURRENT_SCHEMA_XSD); } + /** + * This constructor takes a "parent" registry as a base registry. + * Lookup requests cascade up to the parent while registration + * requests stay here. + */ + public SOAPMappingRegistry(SOAPMappingRegistry parent) + { + this(parent, Constants.NS_URI_CURRENT_SCHEMA_XSD); + } + + /** + * This constructor is the base constructor. If parent is null, then this + * is viewed as a base registry and the registry is initialized with + * all the default mappings etc.. If it is not-null, the no init + * is done and the parent is assumed to have the stuff in it already. + * + * @param parent the "parent" SMR to delegate lookups to if I can't + * find the stuff in my tables. If parent is null, then I get + * pre-loaded with all the default type mappings etc. (some + * of which are based on the schema URI). If parent is not null, + * the default stuff is not put in - the idea is that in that + * case the parent already contains the defaults. + * @param schemaURI the namespace URI of XSD to be used for serializers. + * Deserializers for all 3 XSD URIs are always registered. + */ + public SOAPMappingRegistry(SOAPMappingRegistry parent, String schemaURI) + { + this.parent = parent; + if (parent == null) { + initializeRegistry(schemaURI); + } + this.schemaURI = schemaURI; + } + /** - * Sets up serializers for the specified Schema typeset. - * @param schemaURI Should be one of Constants.NS_URI_1999_SCHEMA_XSD, - * Constants.NS_URI_2000_SCHEMA_XSD, or Constants.NS_URI_2001_SCHEMA_XSD. + * Return the singleton registry instance configured for the + * indicated schema URI. If the schemaURI is unrecognized, the + * 2001 base registry is returned. */ - public SOAPMappingRegistry(String schemaURI) + public static SOAPMappingRegistry getBaseRegistry (String schemaURI) { + synchronized (SOAPMappingRegistry.class) { + if (baseReg1999 == null) { + baseReg1999 = + new SOAPMappingRegistry (null, Constants.NS_URI_1999_SCHEMA_XSD); + baseReg2000 = + new SOAPMappingRegistry (null, Constants.NS_URI_2000_SCHEMA_XSD); + baseReg2001 = + new SOAPMappingRegistry (null, Constants.NS_URI_2001_SCHEMA_XSD); + } + } + + if (schemaURI.equals(Constants.NS_URI_1999_SCHEMA_XSD)) { + return baseReg1999; + } else if (schemaURI.equals(Constants.NS_URI_2000_SCHEMA_XSD)) { + return baseReg2000; + } else { + return baseReg2001; + } + } + + /** + * Return the schemaURI that was used to create this registry + * instance. + */ + public String getSchemaURI () { + return schemaURI; + } + + /** + * Initialize myself with all the built-in default stuff. If schemaURI + * is not recognized, defaults to 2001 schema URI. + */ + private void initializeRegistry(String schemaURI) { - // Set up the correct "current" schema typeset. + QName schemaQNames[] = null; + if (schemaURI.equals(Constants.NS_URI_1999_SCHEMA_XSD)) { schemaQNames = schema1999QNames; mapSchemaTypes(schema2000QNames, false); mapSchemaTypes(schema2001QNames, false); } else if (schemaURI.equals(Constants.NS_URI_2000_SCHEMA_XSD)) { - schemaQNames = schema2000QNames; mapSchemaTypes(schema1999QNames, false); + schemaQNames = schema2000QNames; mapSchemaTypes(schema2001QNames, false); - } else if (schemaURI.equals(Constants.NS_URI_2001_SCHEMA_XSD)) { - schemaQNames = schema2001QNames; + } else { + if (!schemaURI.equals(Constants.NS_URI_2001_SCHEMA_XSD)) { + System.err.println("WARNING: Unrecognized Schema URI '" + schemaURI + + "' specified. Defaulting to '" + + Constants.NS_URI_2001_SCHEMA_XSD + "'."); + } mapSchemaTypes(schema1999QNames, false); mapSchemaTypes(schema2000QNames, false); - } else { - System.err.println("WARNING: Unrecognized Schema URI '" + schemaURI + - "' specified. Defaulting to '" + this.schemaURI + - "'."); + schemaQNames = schema2001QNames; } + // map the ones that I want to do read-write with mapSchemaTypes(schemaQNames, true); - + // Register parameter serializer for SOAP-ENC encoding style. mapTypes(soapEncURI, RPCConstants.Q_ELEM_PARAMETER, Parameter.class, paramSer, paramSer); @@ -433,7 +515,7 @@ * side (i.e. when output gets generated it'll be as those QNames), * otherwise we just do deserializers. */ - public void mapSchemaTypes(QName [] schemaQNames, boolean serialize) + private void mapSchemaTypes(QName [] schemaQNames, boolean serialize) { for (int i = 0; i < schemaQNames.length; i++) { QName qName = schemaQNames[i]; @@ -452,27 +534,27 @@ * is found, SOAP-ENC:Array is returned. Obviously, this only applies when * the encoding style is soap encoding. */ - public QName queryElementType(Class javaType, String encodingStyleURI) - throws IllegalArgumentException + protected QName queryElementType_(Class javaType, String encodingStyleURI) { - try - { - return super.queryElementType(javaType, encodingStyleURI); + QName qn = super.queryElementType_(javaType, encodingStyleURI); + if (qn != null) { + return qn; } - catch (IllegalArgumentException e) - { - if (javaType != null - && (javaType.isArray()) - && encodingStyleURI != null - && encodingStyleURI.equals(soapEncURI)) - { - return arrayQName; + if (parent != null) { + qn = parent.queryElementType_(javaType, encodingStyleURI); + if (qn != null) { + return qn; } - else - { - throw e; - } } + + if (javaType != null + && (javaType.isArray()) + && encodingStyleURI != null + && encodingStyleURI.equals(soapEncURI)) { + return arrayQName; + } + + return null; } /** @@ -482,24 +564,67 @@ * serializer is found for javaType, ArraySerailizer is returned. * Obviously, this only applies when the encoding style is soap encoding. */ - public Serializer querySerializer(Class javaType, String encodingStyleURI) - throws IllegalArgumentException + protected Serializer querySerializer_(Class javaType, + String encodingStyleURI) { - try - { - return super.querySerializer(javaType, encodingStyleURI); + Serializer s = super.querySerializer_(javaType, encodingStyleURI); + if (s != null) { + return s; } - catch (IllegalArgumentException e) - { - if (javaType != null - && encodingStyleURI != null - && encodingStyleURI.equals(soapEncURI)) - { - if (javaType.isArray()) { - return arraySer; - } + if (parent != null) { + s = parent.querySerializer_(javaType, encodingStyleURI); + if (s != null) { + return s; + } + } + + if (javaType != null + && encodingStyleURI != null + && encodingStyleURI.equals(soapEncURI)) { + if (javaType.isArray()) { + return arraySer; + } + } + + return null; + } + + /** + * Override the query deserializer to look at the parent too before + * saying that a deserializer is not available. + */ + protected Deserializer queryDeserializer_(QName elementType, + String encodingStyleURI) + { + Deserializer ds = super.queryDeserializer_(elementType, encodingStyleURI); + if (ds != null) { + return ds; + } + if (parent != null) { + ds = parent.queryDeserializer_(elementType, encodingStyleURI); + if (ds != null) { + return ds; + } + } + return null; + } + + /** + * Overide the query Javatype to look at the parent too before + * saying that a Java type is not available. + */ + protected Class queryJavaType_(QName elementType, String encodingStyleURI) + { + Class jt = super.queryJavaType_(elementType, encodingStyleURI); + if (jt != null) { + return jt; + } + if (parent != null) { + jt = parent.queryJavaType_(elementType, encodingStyleURI); + if (jt != null) { + return jt; } - throw e; } + return null; } } 1.11 +13 -1 xml-soap/java/src/org/apache/soap/rpc/Call.java Index: Call.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/rpc/Call.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- Call.java 2001/05/17 18:25:46 1.10 +++ Call.java 2001/06/28 21:04:03 1.11 @@ -85,7 +85,7 @@ public class Call extends RPCMessage { private DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); - private SOAPMappingRegistry smr = new SOAPMappingRegistry(); + private SOAPMappingRegistry smr = null; private SOAPTransport st = null;; public Call() @@ -113,6 +113,12 @@ public SOAPMappingRegistry getSOAPMappingRegistry() { + // if the smr hasn't been created yet, do it now + if (smr == null) + { + smr = new SOAPMappingRegistry(); + } + return smr; } @@ -190,6 +196,12 @@ if (SOAPActionURI == null) { SOAPActionURI = ""; + } + + // if the smr hasn't been created yet, do it now + if (smr == null) + { + smr = new SOAPMappingRegistry(); } try 1.29 +18 -6 xml-soap/java/src/org/apache/soap/server/DeploymentDescriptor.java Index: DeploymentDescriptor.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/DeploymentDescriptor.java,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- DeploymentDescriptor.java 2001/05/23 17:59:01 1.28 +++ DeploymentDescriptor.java 2001/06/28 21:04:03 1.29 @@ -401,8 +401,11 @@ TypeMapping tm = mappings[i]; pw.print (" <isd:map encodingStyle=\"" + tm.encodingStyle + "\" xmlns:x=\"" + tm.elementType.getNamespaceURI () + - "\" qname=\"x:" + tm.elementType.getLocalPart () + - "\" javaType=\"" + tm.javaType + "\""); + "\" qname=\"x:" + tm.elementType.getLocalPart () + "\""); + + if (tm.javaType != null) { + pw.print (" javaType=\"" + tm.javaType + "\""); + } if (tm.xml2JavaClassName != null) { pw.print (" xml2JavaClassName=\"" + tm.xml2JavaClassName + "\""); } @@ -757,13 +760,22 @@ smr = (SOAPMappingRegistry)defaultSMRClass.newInstance(); } catch (Exception e) { - smr = new SOAPMappingRegistry(); - } + // this needs to be logged somewhere + } } - else { - smr = new SOAPMappingRegistry(); + + if (smr == null) { + SOAPMappingRegistry baseReg = SOAPMappingRegistry.getBaseRegistry ( + Constants.NS_URI_CURRENT_SCHEMA_XSD); + if (maps == null) { + dd.setCachedSMR (baseReg); + return baseReg; + } else { + smr = new SOAPMappingRegistry (baseReg); + } } } + if (maps != null) { for (int i = 0; i < maps.length; i++) { TypeMapping tm = maps[i]; 1.28 +2 -1 xml-soap/java/src/org/apache/soap/server/http/MessageRouterServlet.java Index: MessageRouterServlet.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/MessageRouterServlet.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- MessageRouterServlet.java 2001/05/29 04:17:50 1.27 +++ MessageRouterServlet.java 2001/06/28 21:04:03 1.28 @@ -308,7 +308,8 @@ Envelope env = resp.buildEnvelope(); StringWriter sw = new StringWriter(); - env.marshall(sw, new SOAPMappingRegistry (), resp.getSOAPContext()); + env.marshall(sw, ServerHTTPUtils.getSMRFromContext (context), + resp.getSOAPContext()); String envelopeString = sw.toString(); sres = new TransportMessage(envelopeString, resCtx, null); } 1.32 +3 -3 xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java Index: RPCRouterServlet.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/RPCRouterServlet.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- RPCRouterServlet.java 2001/05/29 04:17:51 1.31 +++ RPCRouterServlet.java 2001/06/28 21:04:03 1.32 @@ -316,9 +316,9 @@ resCtx = new SOAPContext(); // get rid of old one resp = new Response (null, null, fault, null, null, respEncStyle, resCtx); - SOAPMappingRegistry smr = (call != null - ? call.getSOAPMappingRegistry () - : new SOAPMappingRegistry()); + SOAPMappingRegistry smr = + (call != null) ? call.getSOAPMappingRegistry () + : ServerHTTPUtils.getSMRFromContext (context); Envelope env = resp.buildEnvelope(); StringWriter sw = new StringWriter(); env.marshall(sw, smr, resp.getSOAPContext()); 1.21 +20 -0 xml-soap/java/src/org/apache/soap/server/http/ServerHTTPUtils.java Index: ServerHTTPUtils.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/http/ServerHTTPUtils.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ServerHTTPUtils.java 2001/06/25 20:53:47 1.20 +++ ServerHTTPUtils.java 2001/06/28 21:04:03 1.21 @@ -69,6 +69,7 @@ import org.apache.soap.util.*; import org.apache.soap.util.xml.*; import org.apache.soap.rpc.SOAPContext; +import org.apache.soap.encoding.SOAPMappingRegistry; import javax.activation.*; import javax.mail.*; import javax.mail.internet.*; @@ -354,5 +355,24 @@ } return targetObject; + } + + /** + * Return the soap mapping registry instance from the servlet context. + * If one isn't there, then create one and store it in there and then + * return it. + */ + public static SOAPMappingRegistry + getSMRFromContext (ServletContext context) { + SOAPMappingRegistry smr = null; + synchronized (context) { + smr = + (SOAPMappingRegistry) context.getAttribute ("__cached_servlet_SMR__"); + if (smr == null) { + smr = new SOAPMappingRegistry (); + context.setAttribute ("__cached_servlet_SMR__", smr); + } + } + return smr; } } 1.7 +91 -37 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.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XMLJavaMappingRegistry.java 2001/03/19 06:20:52 1.6 +++ XMLJavaMappingRegistry.java 2001/06/28 21:04:04 1.7 @@ -115,8 +115,13 @@ } } - public Serializer querySerializer(Class javaType, String encodingStyleURI) - throws IllegalArgumentException + /** + * This version returns null if the serializer is not found. It is + * intended for internal usage (its used for chaining registries, + * for example). + */ + protected Serializer querySerializer_(Class javaType, + String encodingStyleURI) { if (encodingStyleURI == null) { encodingStyleURI = defaultEncodingStyle; @@ -131,27 +136,40 @@ else { java2XMLKey = getKey(null, encodingStyleURI); - s = (Serializer)sReg.get(java2XMLKey); - - if (s != null) - { - return s; - } - else - { - throw new IllegalArgumentException("No Serializer found to " + - "serialize a '" + - getClassName(javaType) + - "' using encoding style '" + - encodingStyleURI + "'."); - } + return (Serializer)sReg.get(java2XMLKey); } } - public Deserializer queryDeserializer(QName elementType, - String encodingStyleURI) + /** + * This version calls the protected method to do the work and if its + * not found throws an exception. + */ + public Serializer querySerializer(Class javaType, String encodingStyleURI) throws IllegalArgumentException { + Serializer s = querySerializer_(javaType, encodingStyleURI); + if (s != null) + { + return s; + } + else + { + throw new IllegalArgumentException("No Serializer found to " + + "serialize a '" + + getClassName(javaType) + + "' using encoding style '" + + encodingStyleURI + "'."); + } + } + + /** + * This version returns null if the deserializer is not found. It is + * intended for internal usage (its used for chaining registries, + * for example). + */ + protected Deserializer queryDeserializer_(QName elementType, + String encodingStyleURI) + { if (encodingStyleURI == null) { encodingStyleURI = defaultEncodingStyle; } @@ -166,32 +184,55 @@ else { xml2JavaKey = getKey(null, encodingStyleURI); - ds = (Deserializer)dsReg.get(xml2JavaKey); - - if (ds != null) - { - return ds; - } - else - { - throw new IllegalArgumentException("No Deserializer found to " + - "deserialize a '" + elementType + - "' using encoding style '" + - encodingStyleURI + "'."); - } + return (Deserializer)dsReg.get(xml2JavaKey); } } - public QName queryElementType(Class javaType, String encodingStyleURI) + /** + * This version calls the protected method to do the work and if its + * not found throws an exception. + */ + public Deserializer queryDeserializer(QName elementType, + String encodingStyleURI) throws IllegalArgumentException { + Deserializer ds = queryDeserializer_(elementType, encodingStyleURI); + if (ds != null) + { + return ds; + } + else + { + throw new IllegalArgumentException("No Deserializer found to " + + "deserialize a '" + elementType + + "' using encoding style '" + + encodingStyleURI + "'."); + } + } + + /** + * This version returns null if the element type is not found. It is + * intended for internal usage (its used for chaining registries, + * for example). + */ + protected QName queryElementType_(Class javaType, String encodingStyleURI) + { if (encodingStyleURI == null) { encodingStyleURI = defaultEncodingStyle; } String java2XMLkey = getKey(javaType, encodingStyleURI); - QName elementType = (QName)java2XMLReg.get(java2XMLkey); + return (QName)java2XMLReg.get(java2XMLkey); + } + /** + * This version calls the protected method to do the work and if its + * not found throws an exception. + */ + public QName queryElementType(Class javaType, String encodingStyleURI) + throws IllegalArgumentException + { + QName elementType = queryElementType_(javaType, encodingStyleURI); if (elementType != null) { return elementType; @@ -205,16 +246,29 @@ } } - public Class queryJavaType(QName elementType, String encodingStyleURI) - throws IllegalArgumentException + /** + * This version returns null if the Java type is not found. It is + * intended for internal usage (its used for chaining registries, + * for example). + */ + protected Class queryJavaType_(QName elementType, String encodingStyleURI) { if (encodingStyleURI == null) { encodingStyleURI = defaultEncodingStyle; } String xml2JavaKey = getKey(elementType, encodingStyleURI); - Class javaType = (Class)xml2JavaReg.get(xml2JavaKey); + return (Class)xml2JavaReg.get(xml2JavaKey); + } + /** + * This version calls the protected method to do the work and if its + * not found throws an exception. + */ + public Class queryJavaType(QName elementType, String encodingStyleURI) + throws IllegalArgumentException + { + Class javaType = queryJavaType_(elementType, encodingStyleURI); if (javaType != null) { return javaType; @@ -265,7 +319,7 @@ return type + " + " + encodingStyleURI; } - private static String getClassName(Class javaType) + protected static String getClassName(Class javaType) { return javaType != null ? StringUtils.getClassName(javaType) : "null"; }