cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r835028 - in /cxf/branches/2.2.x-fixes: ./ common/common/src/main/java/org/apache/cxf/common/util/ common/common/src/main/java/org/apache/cxf/helpers/ common/common/src/main/java/org/apache/cxf/staxutils/ rt/bindings/jbi/src/main/java/org/a...
Date Wed, 11 Nov 2009 19:27:48 GMT
Author: dkulp
Date: Wed Nov 11 19:27:48 2009
New Revision: 835028

URL: http://svn.apache.org/viewvc?rev=835028&view=rev
Log:
Merged revisions 835016 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r835016 | dkulp | 2009-11-11 14:09:41 -0500 (Wed, 11 Nov 2009) | 2 lines
  
  [CXF-2530] Move all the "create a prefix for me" stuff to a couple
  places so we only need to optimize/debug one place.
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
    cxf/branches/2.2.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
    cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/common/util/StringUtils.java
Wed Nov 11 19:27:48 2009
@@ -69,10 +69,10 @@
     }
 
     public static boolean isEmpty(String str) {
-        if (str != null && str.trim().length() > 0) {
-            return false;
+        if (str == null || str.length() == 0) {
+            return true;
         }
-        return true;
+        return str.trim().length() == 0;
     }
     
     public static boolean isEmpty(List<String> list) {

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
Wed Nov 11 19:27:48 2009
@@ -549,7 +549,7 @@
             p = "ns" + i;
             i++;
         }
-        el.setAttribute(XMLNAMESPACE + ":" + p, ns);
+        addNamespacePrefix(el, ns, p);
         return p;
     }
 

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/CachingXmlEventWriter.java
Wed Nov 11 19:27:48 2009
@@ -160,21 +160,9 @@
         } 
     }
     
-    private String creatPrefix() {
-        int count = 1;
-        String pfx = "ns" + count;
-        while (curContext.getNamespaceURI(pfx) != null) {
-            count++;
-            pfx = "ns" + count;
-        }
-        return pfx;
-    }
     public void writeAttribute(String uri, String name, String value) throws XMLStreamException
{
         if (!StringUtils.isEmpty(uri)) {
-            String pfx = this.getPrefix(uri);
-            if (pfx == null) {
-                pfx = creatPrefix();
-            }
+            String pfx = StaxUtils.getUniquePrefix(this, uri, false);
             addEvent(factory.createAttribute(pfx, uri, name, value));            
         } else {            
             addEvent(factory.createAttribute(name, value));            

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Wed Nov 11 19:27:48 2009
@@ -81,6 +81,11 @@
     private static final BlockingQueue<XMLOutputFactory> OUTPUT_FACTORY_POOL;
     
     private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
+    private static final String DEF_PREFIXES[] = new String[] {
+        "ns1".intern(), "ns2".intern(), "ns3".intern(),
+        "ns4".intern(), "ns5".intern(), "ns6".intern(),
+        "ns7".intern(), "ns8".intern(), "ns9".intern()
+    };
     
     static {
         int i = 20;
@@ -212,6 +217,7 @@
         }
     }
 
+    
     public static void nextEvent(XMLStreamReader dr) {
         try {
             dr.next();
@@ -1020,7 +1026,6 @@
         return new QName(ns, localName, prefix);
     }
     
-
     /**
      * Create a unique namespace uri/prefix combination.
      * 
@@ -1042,18 +1047,29 @@
         }
         return prefix;
     }
-
+    public static String getUniquePrefix(XMLStreamWriter writer, String namespaceURI)
+        throws XMLStreamException {
+        return getUniquePrefix(writer, namespaceURI, false);
+    }
     public static String getUniquePrefix(XMLStreamWriter writer) {
-        int n = 1;
-        
         NamespaceContext nc = writer.getNamespaceContext();
+        if (nc == null) {
+            return DEF_PREFIXES[0];
+        }
+        for (String t : DEF_PREFIXES) {
+            String uri = nc.getNamespaceURI(t);
+            if (StringUtils.isEmpty(uri)) {
+                return t;
+            }
+        }
+
+        int n = 10;
         while (true) {
             String nsPrefix = "ns" + n;
-
-            if (nc == null || nc.getNamespaceURI(nsPrefix) == null) {
+            String uri = nc.getNamespaceURI(nsPrefix);
+            if (StringUtils.isEmpty(uri)) {
                 return nsPrefix;
             }
-
             n++;
         }
     }

Modified: cxf/branches/2.2.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/bindings/jbi/src/main/java/org/apache/cxf/binding/jbi/interceptor/JBIWrapperOutInterceptor.java
Wed Nov 11 19:27:48 2009
@@ -39,6 +39,7 @@
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public class JBIWrapperOutInterceptor extends AbstractOutDatabindingInterceptor {
 
@@ -129,14 +130,10 @@
             QName name = outPart.getConcreteName();
 
             try {
-                
-                int x = 1;
-                while (xmlWriter.getNamespaceContext().getNamespaceURI("ns" + x) != null)
{
-                    x++;
-                }
-                xmlWriter.setPrefix("ns" + x, name.getNamespaceURI());
-                xmlWriter.writeStartElement("ns" + x, name.getLocalPart(), name.getNamespaceURI());
-                xmlWriter.writeNamespace("ns" + x, name.getNamespaceURI());
+                String pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI());
+                xmlWriter.setPrefix(pfx, name.getNamespaceURI());
+                xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
+                xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
             } catch (XMLStreamException e) {
                 throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC",
BUNDLE), e);
             }

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/WrappedOutInterceptor.java
Wed Nov 11 19:27:48 2009
@@ -33,14 +33,10 @@
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.staxutils.StaxUtils;
 
 public class WrappedOutInterceptor extends AbstractOutDatabindingInterceptor {
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(WrappedOutInterceptor.class);
-    private static final String DEF_PREFIXES[] = new String[] {
-        "ns1".intern(), "ns2".intern(), "ns3".intern(),
-        "ns4".intern(), "ns5".intern(), "ns6".intern(),
-        "ns7".intern(), "ns8".intern(), "ns9".intern()
-    };
 
     private WrappedOutEndingInterceptor ending = new WrappedOutEndingInterceptor();
     
@@ -75,21 +71,7 @@
                     pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
                 }
                 if (pfx == null) {
-                    for (String t : DEF_PREFIXES) {
-                        if (!StringUtils.isEmpty(xmlWriter.getNamespaceContext()
-                                                     .getNamespaceURI(t))) {
-                            pfx = t;
-                            break;
-                        }
-                    }
-                    if (pfx == null) {    
-                        int x = 10;
-                        while (!StringUtils.isEmpty(xmlWriter.getNamespaceContext()
-                                                         .getNamespaceURI("ns" + x))) {
-                            x++;
-                        }
-                        pfx = "ns" + x;
-                    }
+                    pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
                 }
                 xmlWriter.setPrefix(pfx, name.getNamespaceURI());
                 xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/util/NamespaceHelper.java
Wed Nov 11 19:27:48 2009
@@ -34,6 +34,7 @@
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.JavaUtils;
+import org.apache.cxf.staxutils.StaxUtils;
 
 /**
  * Namespace utilities.
@@ -55,14 +56,12 @@
      */
     public static String getUniquePrefix(Element element, String namespaceURI) {
         String prefix = getPrefix(element, namespaceURI);
-
         // it is OK to have both namespace URI and prefix be empty. 
         if (prefix == null) {
             if ("".equals(namespaceURI)) {
                 return "";
             }
-            prefix = getUniquePrefix(element);
-            DOMUtils.addNamespacePrefix(element, namespaceURI, prefix);
+            prefix = DOMUtils.createNamespace(element, namespaceURI);
         }
         return prefix;
     }
@@ -75,20 +74,6 @@
         DOMUtils.getPrefixesRecursive(element, namespaceURI, prefixes);
     }
 
-    public static String getUniquePrefix(Element el) {
-        int n = 1;
-
-        while (true) {
-            String nsPrefix = "ns" + n;
-
-            if (DOMUtils.getNamespace(el, nsPrefix) == null) {
-                return nsPrefix;
-            }
-
-            n++;
-        }
-    }
-
     /**
      * Create a unique namespace uri/prefix combination.
      * 
@@ -99,9 +84,34 @@
      */
     public static String getUniquePrefix(XMLStreamWriter writer, String namespaceURI, boolean
declare)
         throws XMLStreamException {
-        String prefix = writer.getNamespaceContext().getPrefix(namespaceURI);
+        return getUniquePrefix(writer, namespaceURI, null, declare);
+    }
+    
+    
+    /**
+     * Make a unique prefix.
+     * @param writer target writer.
+     * @param namespaceURI namespace
+     * @param preferred if there's a proposed prefix (e.g. xsi), here it is.
+     * @param declare whether to declare to the stream.
+     * @return the prefix.
+     * @throws XMLStreamException
+     */
+    public static String getUniquePrefix(XMLStreamWriter writer, 
+                                         String namespaceURI,
+                                         String preferred,
+                                         boolean declare)
+        throws XMLStreamException {
+        
+        if (preferred != null) {
+            String existing = writer.getNamespaceContext().getNamespaceURI(preferred);
+            if (namespaceURI.equals(existing)) {
+                return preferred;
+            }
+        }
+        String prefix = preferred; 
         if (prefix == null) {
-            prefix = getUniquePrefix(writer);
+            prefix = StaxUtils.getUniquePrefix(writer);
 
             if (declare) {
                 writer.setPrefix(prefix, namespaceURI);
@@ -112,20 +122,6 @@
         return prefix;
     }
 
-    public static String getUniquePrefix(XMLStreamWriter writer) {
-        int n = 1;
-
-        while (true) {
-            String nsPrefix = "ns" + n;
-
-            if (writer.getNamespaceContext().getNamespaceURI(nsPrefix) == null) {
-                return nsPrefix;
-            }
-
-            n++;
-        }
-    }
-
     /**
      * Generates the name of a XML namespace from a given class name and
      * protocol. The returned namespace will take the form

Modified: cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java?rev=835028&r1=835027&r2=835028&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/xml/stax/ElementWriter.java
Wed Nov 11 19:27:48 2009
@@ -26,10 +26,10 @@
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.cxf.aegis.DatabindingException;
-import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.aegis.xml.AbstractMessageWriter;
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.staxutils.StaxUtils;
 
 /**
  * LiteralWriter
@@ -103,7 +103,7 @@
                
                 if (!StringUtils.isEmpty(namespace)) {
                     declare = true;
-                    prefix = NamespaceHelper.getUniquePrefix(writer);
+                    prefix = StaxUtils.getUniquePrefix(writer);
                 } else {
                     prefix = "";
                     if (!StringUtils.isEmpty(writer.getNamespaceContext().getNamespaceURI("")))
{
@@ -193,7 +193,7 @@
             String pfx = writer.getPrefix(ns);
 
             if (pfx == null) {
-                pfx = NamespaceHelper.getUniquePrefix(writer);
+                pfx = StaxUtils.getUniquePrefix(writer);
 
                 writer.setPrefix(pfx, ns);
                 writer.writeNamespace(pfx, ns);
@@ -221,7 +221,7 @@
                 } else if (contextPfx != null) {
                     pfx = contextPfx;
                 } else {
-                    pfx = NamespaceHelper.getUniquePrefix(writer);
+                    pfx = StaxUtils.getUniquePrefix(writer);
                 }
 
                 writer.setPrefix(pfx, ns);



Mime
View raw message