Return-Path: Mailing-List: contact soap-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list soap-dev@xml.apache.org Received: (qmail 16329 invoked from network); 15 Nov 2002 14:48:48 -0000 Received: from unknown (HELO epmsa008.epam.com) (212.98.166.5) by daedalus.apache.org with SMTP; 15 Nov 2002 14:48:48 -0000 Received: by EPMSA008 with Internet Mail Service (5.5.2653.19) id ; Fri, 15 Nov 2002 16:48:52 +0200 Message-ID: <0418A01B842BD6118C7E00D0B7B6B60E24E22D@EPMSA005> From: Pavel Ausianik To: "'soap-dev@xml.apache.org'" Subject: RE: [PATCH] XMLJavaMappingRegistry QName DOMUtils Date: Fri, 15 Nov 2002 16:42:54 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C28CB5.47D55E10" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ------_=_NextPart_000_01C28CB5.47D55E10 Content-Type: text/plain; charset="WINDOWS-1251" Sorry, this time with a patch Pavel > -----Original Message----- > From: Pavel Ausianik [mailto:Pavel_Ausianik@epam.com] > Sent: Friday, November 15, 2002 3:34 PM > To: 'soap-dev@xml.apache.org' > Subject: [PATCH] XMLJavaMappingRegistry QName DOMUtils > > > Hello > > Please find patches for XMLJavaMappingRegistry QName DOMUtils > > XMLJavaMappingRegistry uses separated maps per encoding - and avoids > creating String keys which is expencive. Class and QName used > as a keys > QName changed so it not uses intern() in equals() because the > number of > calls per object instance was small > DOMUtils - avoid creating strings were not necessary (2 cases) > > Best regards, > Pavel > > > > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > ------_=_NextPart_000_01C28CB5.47D55E10 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="patch.txt" Index: QName.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/xml-soap/java/src/org/apache/soap/util/xml/QName.java,v retrieving revision 1.8 diff -u -r1.8 QName.java --- QName.java 30 Oct 2002 14:33:02 -0000 1.8 +++ QName.java 15 Nov 2002 14:40:09 -0000 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2000 The Apache Software Foundation. All rights=20 + * 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.=20 + * 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: =20 + * 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=20 + * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", @@ -93,19 +93,19 @@ "must not be null."); } =20 - setNamespaceURI(namespaceURI); - setLocalPart(localPart); + this.namespaceURI =3D namespaceURI; + this.localPart =3D localPart ; } =20 public QName(String namespaceURI, String localPart) { - setNamespaceURI(namespaceURI); - setLocalPart(localPart); + setNamespaceURI(namespaceURI); + setLocalPart(localPart); } - =20 + public void setNamespaceURI(String namespaceURI) { - this.namespaceURI =3D (namespaceURI =3D=3D null ? "" : = namespaceURI).intern(); + this.namespaceURI =3D (namespaceURI =3D=3D null ? "" : = namespaceURI); } =20 public String getNamespaceURI() @@ -115,7 +115,7 @@ =20 public void setLocalPart(String localPart) { - this.localPart =3D (localPart =3D=3D null ? "" : = localPart).intern(); + this.localPart =3D (localPart =3D=3D null ? "" : localPart); } =20 public String getLocalPart() @@ -131,8 +131,8 @@ public boolean equals(Object obj) { return (obj !=3D null - && namespaceURI =3D=3D ((QName)obj).getNamespaceURI() - && localPart =3D=3D ((QName)obj).getLocalPart()); + && namespaceURI.equals(((QName)obj).namespaceURI) + && localPart.equals(((QName)obj).localPart)); } =20 public boolean matches(Node node) Index: XMLJavaMappingRegistry.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/xml-soap/java/src/org/apache/soap/util/xml/XMLJavaMappin= gRegistry.java,v retrieving revision 1.11 diff -u -r1.11 XMLJavaMappingRegistry.java --- XMLJavaMappingRegistry.java 30 Oct 2002 14:33:02 -0000 1.11 +++ XMLJavaMappingRegistry.java 15 Nov 2002 14:40:21 -0000 @@ -78,21 +78,27 @@ * @author Matthew J. Duftler (duftler@us.ibm.com) * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com) * @author Francisco Curbera (curbera@us.ibm.com) - * @author Scott Nichol (snichol@computer.org) + * @author Pavel Ausianik <Pavel_Ausianik@epam.com> */ public class XMLJavaMappingRegistry { - /** Java type to Serializer */ - private Hashtable sReg =3D new Hashtable(); - /** XML type to Deserializer */ - private Hashtable dsReg =3D new Hashtable(); - /** XML type to Java type */ - private Hashtable xml2JavaReg =3D new Hashtable(); - /** Java type to XML type */ - private Hashtable java2XMLReg =3D new Hashtable(); - /** Encoding to use if none specified */ - private String defaultEncodingStyle =3D null; - =20 + private static final class Maps { + /** Java type to Serializer */ + Map sReg =3D new HashMap(); + /** XML type to Deserializer */ + Map dsReg =3D new HashMap(); + /** XML type to Java type */ + Map xml2JavaReg =3D new HashMap(); + /** Java type to XML type */ + Map java2XMLReg =3D new HashMap(); + }; + + /** Encoding to maps */ + Map encToMaps =3D new HashMap(); + + /** Encoding to use if none specified */ + private String defaultEncodingStyle =3D ""; + /** * Sets the default encoding style. If the query*() calls * are invoked with a null encodingStyleURI parameter, we'll @@ -102,7 +108,20 @@ */ public void setDefaultEncodingStyle(String defEncStyle) { - defaultEncodingStyle =3D defEncStyle; + if (defEncStyle !=3D null) + defaultEncodingStyle =3D defEncStyle; + } + + private Maps getMapsForEncoding(String encodingStyleURI) + { + if (encodingStyleURI =3D=3D null) + encodingStyleURI =3D defaultEncodingStyle; + Maps maps =3D (Maps)encToMaps.get(encodingStyleURI); + if (maps =3D=3D null) { + maps =3D new Maps(); + encToMaps.put(encodingStyleURI, maps); + } + return maps; } =20 /** @@ -117,7 +136,7 @@ * To register a default serializer and/or deserializer, set the * corresponding type to null. * - * @param encodingStyleURI The encoding style for the map. The=20 + * @param encodingStyleURI The encoding style for the map. The * encoding style qualifies the types. * @param elementType The XML type. * @param javaType The Java type. @@ -127,35 +146,36 @@ public void mapTypes(String encodingStyleURI, QName elementType, Class javaType, Serializer s, Deserializer ds) { - String java2XMLKey =3D null; - String xml2JavaKey =3D null; + Maps maps =3D getMapsForEncoding(encodingStyleURI); + + Object java2XMLKey =3D ""; + Object xml2JavaKey =3D ""; + + if (javaType !=3D null) + java2XMLKey =3D javaType; + if (elementType !=3D null) + xml2JavaKey =3D elementType; =20 if (s !=3D null) - { - java2XMLKey =3D getKey(javaType, encodingStyleURI); - sReg.put(java2XMLKey, s); - } + maps.sReg.put(java2XMLKey, s); =20 if (ds !=3D null) - { - xml2JavaKey =3D getKey(elementType, encodingStyleURI); - dsReg.put(xml2JavaKey, ds); - } + maps.dsReg.put( xml2JavaKey , ds); =20 // Only map types if both types are provided. if (elementType !=3D null && javaType !=3D null) { // Only map Java to XML if a serializer was provided if (s !=3D null) - java2XMLReg.put(java2XMLKey, elementType); + maps.java2XMLReg.put(java2XMLKey, elementType); // Only map XML to Java if a deserializer was provided if (ds !=3D null) - xml2JavaReg.put(xml2JavaKey, javaType); + maps.xml2JavaReg.put(xml2JavaKey, javaType); } } =20 /** - * This version returns null if the serializer is not found. It is=20 + * This version returns null if the serializer is not found. It is * intended for internal usage (its used for chaining registries, * for example). * @@ -167,26 +187,19 @@ protected Serializer querySerializer_(Class javaType, String encodingStyleURI) { - if (encodingStyleURI =3D=3D null) { - encodingStyleURI =3D defaultEncodingStyle; - } - String java2XMLKey =3D getKey(javaType, encodingStyleURI); - Serializer s =3D (Serializer)sReg.get(java2XMLKey); + Maps maps =3D getMapsForEncoding(encodingStyleURI); + Object java2XMLKey =3D ""; + if (javaType !=3D null) + java2XMLKey =3D javaType; =20 - if (s !=3D null) - { - return s; - } - else - { - java2XMLKey =3D getKey((Class) null, encodingStyleURI); - return (Serializer)sReg.get(java2XMLKey); - } + Serializer s =3D (Serializer)maps.sReg.get(java2XMLKey); + + return s !=3D null ? s : (Serializer)maps.sReg.get(""); } =20 /** * This version calls the protected method to do the work and if = it's - * not found throws an exception.=20 + * not found throws an exception. * * @param javaType The Java type. * @param encodingStyleURI The encoding style. @@ -212,7 +225,7 @@ } =20 /** - * This version returns null if the deserializer is not found. It is = + * This version returns null if the deserializer is not found. It is * intended for internal usage (its used for chaining registries, * for example). * @@ -224,27 +237,18 @@ protected Deserializer queryDeserializer_(QName elementType, String encodingStyleURI) { - if (encodingStyleURI =3D=3D null) { - encodingStyleURI =3D defaultEncodingStyle; - } - - String xml2JavaKey =3D getKey(elementType, encodingStyleURI); - Deserializer ds =3D (Deserializer)dsReg.get(xml2JavaKey); + Maps maps =3D getMapsForEncoding(encodingStyleURI); + Object xml2JavaKey =3D ""; + if (elementType !=3D null) + xml2JavaKey =3D elementType; =20 - if (ds !=3D null) - { - return ds; - } - else - { - xml2JavaKey =3D getKey((QName) null, encodingStyleURI); - return (Deserializer)dsReg.get(xml2JavaKey); - } + Deserializer ds =3D (Deserializer)maps.dsReg.get(xml2JavaKey); + return ds !=3D null ? ds : (Deserializer)maps.dsReg.get(""); } =20 /** * This version calls the protected method to do the work and if its - * not found throws an exception.=20 + * not found throws an exception. * * @param elementType The XML type. * @param encodingStyleURI The encoding style. @@ -270,7 +274,7 @@ } =20 /** - * This version returns null if the element type is not found. It is = + * This version returns null if the element type is not found. It is * intended for internal usage (its used for chaining registries, * for example). * @@ -281,17 +285,17 @@ */ protected QName queryElementType_(Class javaType, String = encodingStyleURI) { - if (encodingStyleURI =3D=3D null) { - encodingStyleURI =3D defaultEncodingStyle; - } + Maps maps =3D getMapsForEncoding(encodingStyleURI); + Object java2XMLKey =3D ""; + if (javaType !=3D null) + java2XMLKey =3D javaType; =20 - String java2XMLkey =3D getKey(javaType, encodingStyleURI); - return (QName)java2XMLReg.get(java2XMLkey); + return (QName)maps.java2XMLReg.get(java2XMLKey); } =20 /** * This version calls the protected method to do the work and if its - * not found throws an exception.=20 + * not found throws an exception. * * @param javaType The Java type. * @param encodingStyleURI The encoding style. @@ -316,7 +320,7 @@ } =20 /** - * This version returns null if the Java type is not found. It is=20 + * This version returns null if the Java type is not found. It is * intended for internal usage (its used for chaining registries, * for example). * @@ -327,17 +331,17 @@ */ protected Class queryJavaType_(QName elementType, String = encodingStyleURI) { - if (encodingStyleURI =3D=3D null) { - encodingStyleURI =3D defaultEncodingStyle; - } + Maps maps =3D getMapsForEncoding(encodingStyleURI); + Object xml2JavaKey =3D ""; + if (elementType !=3D null) + xml2JavaKey =3D elementType; =20 - String xml2JavaKey =3D getKey(elementType, encodingStyleURI); - return (Class)xml2JavaReg.get(xml2JavaKey); + return (Class)maps.xml2JavaReg.get(xml2JavaKey); } =20 /** * This version calls the protected method to do the work and if its - * not found throws an exception.=20 + * not found throws an exception. * * @param elementType The XML type. * @param encodingStyleURI The encoding style. @@ -397,36 +401,6 @@ } =20 return ds.unmarshall(inScopeEncStyle, elementType, src, this, = ctx); - } - - /** - * Creates a key for the registry Hashtables. - * - * @param type The XML type. - * @param encodingStyleURI The encoding style. - * @return The key. - */ - private static String getKey(QName type, String encodingStyleURI) - { - if (type =3D=3D null) - return encodingStyleURI; - String strObj =3D type.toString(); - return new StringBuffer(strObj.length() + 3 + = encodingStyleURI.length()).append(strObj).append(" + = ").append(encodingStyleURI).toString(); - } - - /** - * Creates a key for the registry Hashtables. - * - * @param type The Java type. - * @param encodingStyleURI The encoding style. - * @return The key. - */ - private static String getKey(Class type, String encodingStyleURI) - { - if (type =3D=3D null) - return encodingStyleURI; - String strObj =3D type.getName(); - return new StringBuffer(strObj.length() + 3 + = encodingStyleURI.length()).append(strObj).append(" + = ").append(encodingStyleURI).toString(); } =20 /** Index: DOMUtils.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: = /home/cvspublic/xml-soap/java/src/org/apache/soap/util/xml/DOMUtils.java= ,v retrieving revision 1.8 diff -u -r1.8 DOMUtils.java --- DOMUtils.java 6 Sep 2002 17:50:27 -0000 1.8 +++ DOMUtils.java 15 Nov 2002 14:41:38 -0000 @@ -2,7 +2,7 @@ * The Apache Software License, Version 1.1 * * - * Copyright (c) 2000 The Apache Software Foundation. All rights=20 + * 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.=20 + * 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: =20 + * 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=20 + * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", @@ -78,7 +78,7 @@ * returns "" if an attrib is not found). * * @param el Element whose attrib is looked for - * @param attrName name of attribute to look for=20 + * @param attrName name of attribute to look for * @return the attribute value */ static public String getAttribute (Element el, String attrName) { @@ -97,8 +97,8 @@ * returns "" if an attrib is not found). * * @param el Element whose attrib is looked for - * @param namespaceURI namespace URI of attribute to look for=20 - * @param localPart local part of attribute to look for=20 + * @param namespaceURI namespace URI of attribute to look for + * @param localPart local part of attribute to look for * @return the attribute value */ static public String getAttributeNS (Element el, @@ -122,24 +122,39 @@ * be combined. * @return the concatanated string. */ + static int num =3D 0; static public String getChildCharacterData (Element parentEl) { if (parentEl =3D=3D null) { return null; - }=20 + } Node tempNode =3D parentEl.getFirstChild(); - StringBuffer strBuf =3D new StringBuffer(64); - CharacterData charData; - - while (tempNode !=3D null) { - switch (tempNode.getNodeType()) { - case Node.TEXT_NODE : - case Node.CDATA_SECTION_NODE : charData =3D = (CharacterData)tempNode; - = strBuf.append(charData.getData()); - break; - } - tempNode =3D tempNode.getNextSibling(); + if (tempNode !=3D null) { + Node nextNode =3D tempNode.getNextSibling(); + // If only one Child element - return its directly + if (nextNode =3D=3D null) { + switch (tempNode.getNodeType()) { + case Node.TEXT_NODE : + case Node.CDATA_SECTION_NODE : + return ((CharacterData)tempNode).getData(); + } + return ""; + } + // Otherwise collect in StringBuffer + StringBuffer strBuf =3D new StringBuffer(64); + do { + switch (tempNode.getNodeType()) { + case Node.TEXT_NODE : + case Node.CDATA_SECTION_NODE : + = strBuf.append(((CharacterData)tempNode).getData()); + break; + } + tempNode =3D nextNode; + if ((tempNode =3D nextNode) !=3D null) + nextNode =3D nextNode.getNextSibling(); + } while (tempNode !=3D null); + return strBuf.toString(); } - return strBuf.toString(); + return ""; } =20 /** @@ -184,7 +199,7 @@ * * @return the first matching child element. */ - public static Element findChildElementWithAttribute (Element elem,=20 + public static Element findChildElementWithAttribute (Element elem, String attrName, String attrValue) { for (Node n =3D elem.getFirstChild (); n !=3D null; n =3D = n.getNextSibling ()) { @@ -197,7 +212,7 @@ return null; } =20 - /**=20 + /** * Count number of children of a certain type of the given element. * * @param elem the element whose kids are to be counted @@ -250,18 +265,21 @@ } } =20 + // Do not concatenate strings in the loop + String longPrefix =3D prefix =3D=3D null ? "" : "xmlns:" + prefix; + while (tempNode !=3D null && tempNode.getNodeType () =3D=3D = Node.ELEMENT_NODE) { Element tempEl =3D (Element) tempNode; String namespaceURI; - =20 + if (prefix =3D=3D null) { namespaceURI =3D getAttribute(tempEl, "xmlns"); } else { namespaceURI =3D getAttributeNS(tempEl, NS_URI_XMLNS, prefix); if (namespaceURI =3D=3D null) { // SAX parser (maybe others?) need this - namespaceURI =3D getAttribute(tempEl, "xmlns:" + prefix); + namespaceURI =3D getAttribute(tempEl, longPrefix); } } =20 @@ -285,7 +303,7 @@ String thisId =3D el.getAttribute("id"); if (id.equals(thisId)) return el; - =20 + NodeList list =3D el.getChildNodes(); for (int i =3D 0; i < list.getLength(); i++) { Node node =3D list.item(i); @@ -295,7 +313,7 @@ return ret; } } - =20 + return null; } =20 ------_=_NextPart_000_01C28CB5.47D55E10--