Hello, Please find a proposed patch, for reducing namespaces lookup from parameters of SOAP envelope to the roots
Thanks, Pavel
Index: RPCMessage.java =================================================================== RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/rpc/RPCMessage.java,v retrieving revision 1.22 diff -u -r1.22 RPCMessage.java --- RPCMessage.java 18 Nov 2002 21:52:06 -0000 1.22 +++ RPCMessage.java 22 Nov 2002 12:51:46 -0000 @@ -83,6 +83,7 @@ protected String encodingStyleURI; protected SOAPContext ctx; + private static final QName N_ENCOD_STYLE = new QName(Constants.NS_URI_SOAP_ENV, +Constants.ATTR_ENCODING_STYLE); /** * Creates a message for the request or response of an RPC. * @@ -214,13 +215,9 @@ if (bodyEntries.size() > 0) { Element msgEl = (Element)bodyEntries.elementAt(0); Class toClass = isResponse ? Response.class : Call.class; - String declEnvEncStyle = env.getAttribute(new QName( - Constants.NS_URI_SOAP_ENV, Constants.ATTR_ENCODING_STYLE)); - String declBodyEncStyle = body.getAttribute(new QName( - Constants.NS_URI_SOAP_ENV, Constants.ATTR_ENCODING_STYLE)); - String actualEncStyle = declBodyEncStyle != null - ? declBodyEncStyle - : declEnvEncStyle; + String actualEncStyle = body.getAttribute(N_ENCOD_STYLE); + if (actualEncStyle == null) + actualEncStyle = env.getAttribute(N_ENCOD_STYLE); msg = RPCMessage.unmarshall(actualEncStyle, msgEl, toClass, svcMgr, respSMR, ctx); @@ -429,6 +426,9 @@ ? declMsgEncStyle : inScopeEncStyle; + // Create a namespace map, used in unmarshall + ctx.clearNSMap(); + // Is it a fault? if (isResponse && Constants.Q_ELEM_FAULT.matches(root)) { fault = Fault.unmarshall(actualMsgEncStyle, root, respSMR, ctx); @@ -478,7 +478,7 @@ Element tempEl = DOMUtils.getFirstChildElement(root); - // Get the return value. + // Get the return value. if (isResponse && tempEl != null) { String declParamEncStyle = DOMUtils.getAttributeNS(tempEl, Constants.NS_URI_SOAP_ENV, Constants.ATTR_ENCODING_STYLE); Index: SOAPContext.java =================================================================== RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/rpc/SOAPContext.java,v retrieving revision 1.16 diff -u -r1.16 SOAPContext.java --- SOAPContext.java 20 Nov 2002 21:34:42 -0000 1.16 +++ SOAPContext.java 22 Nov 2002 12:52:47 -0000 @@ -96,6 +96,8 @@ protected String rootPartContentType = ""; protected boolean oneWay = false; + private Map nsMap; + // Constants for checking type for base64 encoding private static MimeType MIME_STREAM; private static MimeType MIME_IMAGE; @@ -853,6 +855,22 @@ */ public void setOneWay(boolean oneWay) { this.oneWay = oneWay; + } + + /** + * Create a new mapping between namespaces and prefixes + * for usage in RPCMessage.unmarshall + */ + public void clearNSMap() { + nsMap = new HashMap(); + } + + /** + * Return the mapping between namespaces and prefixes + * in responce messages + */ + public Map getNSMap() { + return nsMap; } /** Index: ArraySerializer.java =================================================================== RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/encoding/soapenc/ArraySerializer.java,v retrieving revision 1.14 diff -u -r1.14 ArraySerializer.java --- ArraySerializer.java 18 Nov 2002 21:52:05 -0000 1.14 +++ ArraySerializer.java 22 Nov 2002 12:54:31 -0000 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -10,7 +10,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * 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 @@ -18,7 +18,7 @@ * distribution. * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * 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, @@ -26,7 +26,7 @@ * * 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 + * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", @@ -154,7 +154,8 @@ Element root = (Element)src; String name = root.getTagName(); QName arrayItemType = new QName("", ""); - Object array = getNewArray(inScopeEncStyle, root, arrayItemType, xjmr); + Object array = getNewArray(inScopeEncStyle, root, arrayItemType, xjmr, + ctx.getNSMap()); if (SoapEncUtils.isNull(root)) { @@ -185,7 +186,7 @@ } } - QName declItemType = SoapEncUtils.getTypeQName(actualEl); + QName declItemType = SoapEncUtils.getTypeQName(actualEl, ctx); QName actualItemType = declItemType != null ? declItemType : arrayItemType; @@ -205,7 +206,7 @@ if (javaType.isPrimitive()) throw new IllegalArgumentException("Cannot set null value for array element of primitive type: " + javaType.getName()); } - + tempEl = DOMUtils.getNextSiblingElement(tempEl); } @@ -214,11 +215,11 @@ public static Object getNewArray(String inScopeEncStyle, Element arrayEl, QName arrayItemType, - XMLJavaMappingRegistry xjmr) + XMLJavaMappingRegistry xjmr, Map nsMap) throws IllegalArgumentException { QName arrayTypeValue = SoapEncUtils.getAttributeValue(arrayEl, - Constants.NS_URI_SOAP_ENC, Constants.ATTR_ARRAY_TYPE, "array", true); + Constants.NS_URI_SOAP_ENC, Constants.ATTR_ARRAY_TYPE, "array", nsMap); String arrayTypeValueNamespaceURI = arrayTypeValue.getNamespaceURI(); String arrayTypeValueLocalPart = arrayTypeValue.getLocalPart(); int leftBracketIndex = arrayTypeValueLocalPart.lastIndexOf('['); Index: SoapEncUtils.java =================================================================== RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/encoding/soapenc/SoapEncUtils.java,v retrieving revision 1.18 diff -u -r1.18 SoapEncUtils.java --- SoapEncUtils.java 6 Nov 2002 15:11:08 -0000 1.18 +++ SoapEncUtils.java 22 Nov 2002 12:54:44 -0000 @@ -58,6 +58,7 @@ package org.apache.soap.encoding.soapenc; import java.io.*; +import java.util.Map; import org.w3c.dom.*; import org.apache.soap.util.xml.*; import org.apache.soap.*; @@ -342,11 +343,54 @@ } } + + /** + * @param el DOM Element to search + * @param attrNameNamespaceURI + * @param attrNameLocalPart + * @param elDesc + * @param nsMap + * + * @return QName or null + * @throws IllegalArgumentException + */ public static QName getAttributeValue(Element el, String attrNameNamespaceURI, String attrNameLocalPart, String elDesc, - boolean isRequired) + Map nsMap) + throws IllegalArgumentException + { + QName attrValue = getAttributeValue(el, attrNameNamespaceURI, + attrNameLocalPart, nsMap); + + if (attrValue == null && elDesc != null) + { + throw new IllegalArgumentException("The '" + + attrNameNamespaceURI + ':' + + attrNameLocalPart + + "' attribute must be " + + "specified for every " + + elDesc + '.'); + } + + return attrValue; + } + + /** + * @param el DOM Element to search + * @param attrNameNamespaceURI + * @param attrNameLocalPart + * @param elDesc + * @param nsMap + * + * @return QName or null + * @throws IllegalArgumentException + */ + public static QName getAttributeValue(Element el, + String attrNameNamespaceURI, + String attrNameLocalPart, + Map nsMap) throws IllegalArgumentException { String attrValue = DOMUtils.getAttributeNS(el, @@ -361,8 +405,14 @@ { String attrValuePrefix = attrValue.substring(0, index); String attrValueLocalPart = attrValue.substring(index + 1); - String attrValueNamespaceURI = - DOMUtils.getNamespaceURIFromPrefix(el, attrValuePrefix); + + // Check in stack for namespace first + String attrValueNamespaceURI = (String)nsMap.get(attrValuePrefix); + if (attrValueNamespaceURI == null) { + attrValueNamespaceURI = + DOMUtils.getNamespaceURIFromPrefix(el, attrValuePrefix); + nsMap.put(attrValuePrefix, attrValueNamespaceURI); + } if (attrValueNamespaceURI != null) { @@ -384,15 +434,6 @@ "namespace-qualified."); } } - else if (isRequired) - { - throw new IllegalArgumentException("The '" + - attrNameNamespaceURI + ':' + - attrNameLocalPart + - "' attribute must be " + - "specified for every " + - elDesc + '.'); - } else { return null; @@ -406,26 +447,27 @@ * has the SOAP-ENC namespaceURI. For now, this is limited to * checking for SOAP-ENC:Array. */ - public static QName getTypeQName(Element el) + public static QName getTypeQName(Element el, SOAPContext ctx) throws IllegalArgumentException { + Map nsMap = ctx.getNSMap(); // Try 2001 QName typeQName = getAttributeValue(el, Constants.NS_URI_2001_SCHEMA_XSI, - Constants.ATTR_TYPE, null, false); + Constants.ATTR_TYPE, nsMap); if (typeQName != null) return typeQName; // Try 2000 typeQName = getAttributeValue(el, Constants.NS_URI_2000_SCHEMA_XSI, - Constants.ATTR_TYPE, null, false); + Constants.ATTR_TYPE, nsMap); if (typeQName != null) return typeQName; // Try 1999 typeQName = getAttributeValue(el, Constants.NS_URI_1999_SCHEMA_XSI, - Constants.ATTR_TYPE, null, false); + Constants.ATTR_TYPE, nsMap); if (typeQName != null) return typeQName; Index: ParameterSerializer.java =================================================================== RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/encoding/soapenc/ParameterSerializer.java,v retrieving revision 1.14 diff -u -r1.14 ParameterSerializer.java --- ParameterSerializer.java 30 Aug 2002 21:39:00 -0000 1.14 +++ ParameterSerializer.java 22 Nov 2002 12:55:02 -0000 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -10,7 +10,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * 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 @@ -18,7 +18,7 @@ * distribution. * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * 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, @@ -26,7 +26,7 @@ * * 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 + * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", @@ -151,12 +151,12 @@ throw new IllegalArgumentException("No such ID '" + href + "'."); } - QName soapType = SoapEncUtils.getTypeQName(el); + QName soapType = SoapEncUtils.getTypeQName(el, ctx); if (soapType == null) { /* - No xsi:type attribute found: determine the type as the + No xsi:type attribute found: determine the type as the qualified name of the parameter element (if the parameter element is qualified) or as the qname formed by an empty namespace URI and the tag name of the parameter element. @@ -192,12 +192,12 @@ } else { - QName soapType = SoapEncUtils.getTypeQName(paramEl); + QName soapType = SoapEncUtils.getTypeQName(paramEl, ctx); if (soapType == null) { /* - No xsi:type attribute found: determine the type as the + No xsi:type attribute found: determine the type as the qualified name of the parameter element (if the parameter element is qualified) or as the qname formed by an empty namespace URI and the tag name of the parameter element. @@ -222,10 +222,10 @@ null) : xjmr.unmarshall(inScopeEncStyle, soapType, paramEl, ctx)); } - + Parameter parameter = new Parameter(name, bean.type, bean.value, null); - + return new Bean(Parameter.class, parameter); } } Index: VectorSerializer.java =================================================================== RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/encoding/soapenc/VectorSerializer.java,v retrieving revision 1.10 diff -u -r1.10 VectorSerializer.java --- VectorSerializer.java 18 Nov 2002 21:52:05 -0000 1.10 +++ VectorSerializer.java 22 Nov 2002 12:55:19 -0000 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -10,7 +10,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * 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 @@ -18,7 +18,7 @@ * distribution. * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * 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, @@ -26,7 +26,7 @@ * * 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 + * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", @@ -71,9 +71,9 @@ * A <code>VectorSerializer</code> can be used to serialize (but not * deserialize) Vectors and Enumerations using the <code>SOAP-ENC</code> * encoding style.<p> - * + * * This serializer turns Vectors/Enumerations into SOAP arrays. - * + * * @author Glen Daniels ([EMAIL PROTECTED]) */ public class VectorSerializer implements Serializer, Deserializer @@ -85,7 +85,7 @@ { nsStack.pushScope(); - if ((src != null) && + if ((src != null) && !(src instanceof Vector) && !(src instanceof Enumeration)) throw new IllegalArgumentException("Tried to pass a '" + @@ -93,7 +93,7 @@ String lengthStr; Enumeration enum; - + if (src instanceof Enumeration) { /** TODO: Right now we don't include a length on Enumerations, * due to efficiency concerns. There should be a way to configure @@ -105,7 +105,7 @@ } else { Vector v = (Vector)src; enum = v.elements(); - + lengthStr = src != null ? v.size() + "" : ""; @@ -172,9 +172,9 @@ if (SoapEncUtils.isNull(root)) { return new Bean(Vector.class, null); } - + Vector v = new Vector(); - + Element tempEl = DOMUtils.getFirstChildElement(root); while (tempEl != null) { String declEncStyle = DOMUtils.getAttributeNS(tempEl, @@ -194,8 +194,8 @@ throw new IllegalArgumentException("No such ID '" + href + "'"); } } - - QName declItemType = SoapEncUtils.getTypeQName(actualEl); + + QName declItemType = SoapEncUtils.getTypeQName(actualEl, ctx); QName actualItemType = declItemType; Bean itemBean = xjmr.unmarshall(actualEncStyle, actualItemType, @@ -205,7 +205,7 @@ tempEl = DOMUtils.getNextSiblingElement(tempEl); } - + return new Bean(Vector.class, v); } Index: HashtableSerializer.java =================================================================== RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/encoding/soapenc/HashtableSerializer.java,v retrieving revision 1.4 diff -u -r1.4 HashtableSerializer.java --- HashtableSerializer.java 18 Nov 2002 21:52:05 -0000 1.4 +++ HashtableSerializer.java 22 Nov 2002 12:55:34 -0000 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -10,7 +10,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * 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 @@ -18,7 +18,7 @@ * distribution. * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * 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, @@ -26,7 +26,7 @@ * * 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 + * software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", @@ -71,9 +71,9 @@ * A <code>HashtableSerializer</code> can be used to serialize and * deserialize Hashtables using the <code>SOAP-ENC</code> * encoding style.<p> - * + * * TODO: This should eventually deal with Maps, but doesn't yet. - * + * * @author Glen Daniels ([EMAIL PROTECTED]) */ public class HashtableSerializer implements Serializer, Deserializer @@ -81,7 +81,7 @@ private static final String STR_KEY = "key"; private static final String STR_ITEM = "item"; private static final String STR_VALUE = "value"; - + public void marshall(String inScopeEncStyle, Class javaType, Object src, Object context, Writer sink, NSStack nsStack, XMLJavaMappingRegistry xjmr, SOAPContext ctx) @@ -186,7 +186,7 @@ if (!tagName.equalsIgnoreCase("value")) { - throw new IllegalArgumentException("Got <" + tagName + + throw new IllegalArgumentException("Got <" + tagName + "> tag when expecting <" + STR_VALUE + ">"); } @@ -211,7 +211,7 @@ String actualEncStyle = (declEncStyle != null) ? declEncStyle : inScopeEncStyle; - QName declItemType = SoapEncUtils.getTypeQName(targetEl); + QName declItemType = SoapEncUtils.getTypeQName(targetEl, ctx); return xjmr.unmarshall(actualEncStyle, declItemType, targetEl, ctx); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>