Merge

Thu, 08 Jun 2017 13:44:31 -0700

author
asaha
date
Thu, 08 Jun 2017 13:44:31 -0700
changeset 1393
f7e7fd169aa4
parent 1392
32a01bf45f0f
parent 1382
f87d9aaee64f
child 1394
c59814f445e8

Merge

.hgtags file | annotate | diff | comparison | revisions
     1.1 --- a/.hgtags	Tue Dec 13 12:52:09 2016 -0800
     1.2 +++ b/.hgtags	Thu Jun 08 13:44:31 2017 -0700
     1.3 @@ -659,11 +659,44 @@
     1.4  14fa3ed278a279dc85c150bf54b2ec4fa29cf347 jdk8u112-b14
     1.5  5f84e87f91d5bc36ed026b88d183821e5109d730 jdk8u112-b15
     1.6  d82dd7a24a496e26987caa328d1fb4fc794a4770 jdk8u112-b16
     1.7 +021da5d50285a523d4622a727ea1a7019f2b52e4 jdk8u112-b31
     1.8  452662a83e5bc6dc7e9425ddd10f6c8fc98d50d8 jdk8u121-b00
     1.9  9cd16be39ca6f2c8f7cc99ad07a77bb9d0696c75 jdk8u121-b01
    1.10  f092b9a890ceeca4a2f4d55cf7d6f3f113cdb462 jdk8u121-b02
    1.11  c1b0f76c9fe9657d3f5cdd1e23bfd1d499018431 jdk8u121-b03
    1.12  44674172423a0d361466e34eedcaec18a8810b13 jdk8u121-b04
    1.13 +18da635b5919a0b7cdde8573a0d502efdbf3673e jdk8u121-b05
    1.14 +5b76a2126855f8949ab8fbadfa3ee2f29da9c21c jdk8u121-b06
    1.15 +f10aa5b29848eab891bdd173540d91fd31f9ff20 jdk8u121-b07
    1.16 +105d3bbf5e3b2b24da665b332d2dbf44980c87f2 jdk8u121-b08
    1.17 +9f2588382771f855c4450f59b470d069a1cb1d01 jdk8u121-b09
    1.18 +c317f0eacd602a8765d25b0fcd382f76af3697a5 jdk8u121-b10
    1.19 +89aa912be940d6c30f59b80c826f212541912a56 jdk8u121-b11
    1.20 +52b3f9fb54ee4304a9c34a2fe07f0c9a49472185 jdk8u121-b12
    1.21 +5b8834cc3bb9e24153319c766e04e194945a61b9 jdk8u121-b13
    1.22  2359a73f36ca99ba30aef88a38936f6f4e18e65c jdk8u131-b00
    1.23 +bc5500cde753aed78c92e7301548fa1450c9b104 jdk8u131-b01
    1.24 +c146d8a61d677fd4d07778d0295b4e88e16a7dd3 jdk8u131-b02
    1.25 +e0d1730c483c2d63fa78b74df4dd7fec8682220c jdk8u131-b03
    1.26 +d2694f83db12a0aff88260c3a09a5b2474ee4afa jdk8u131-b04
    1.27 +d7763a127acc2b87793b59b388062b7fbecd7755 jdk8u131-b05
    1.28 +0e3bd0a2751161863c1d0d5e9ce7a22b9a440c12 jdk8u131-b06
    1.29 +62b6998733d3f94a0092c2863b81159330fe92e0 jdk8u131-b07
    1.30 +4e86f5b1caaf3083befd44c7369885eacdd3fe95 jdk8u131-b08
    1.31 +548546d23a924ff0962df885468ce49816ae48a9 jdk8u131-b09
    1.32 +bc74b4850d97ff1986bf551c752ce212f97f4b0e jdk8u131-b10
    1.33 +7817f0d2519573e42405ef96a7c7ff1d768f92ec jdk8u131-b11
    1.34  74aa403ef03d56469e9364cc45c2ec18c6e50e33 jdk8u141-b00
    1.35 +b1138396b99b1f8ebdb7d28c7143c96eb5b4f991 jdk8u141-b01
    1.36 +a7b9281956f9616eab0498386b9605853db7b408 jdk8u141-b02
    1.37 +3d27876c2ce476b16195c4519b266613f13e3e1b jdk8u141-b03
    1.38 +a08a6118b9df52f2963f482dbe6801d56b9086f7 jdk8u141-b04
    1.39 +dcbac02db203e4734921852aeed19416c7820f15 jdk8u141-b05
    1.40 +f552ee60279fa16d60477fc59c21fee8d298840a jdk8u141-b06
    1.41 +86a22a62ecd5f74faf535de048fe40563e99065f jdk8u141-b07
    1.42 +1d5f442d50dff2e2c8efd58a1b95bcefe5253a1b jdk8u141-b08
    1.43 +34f55abdda466e3aab4900368127f09183ef859d jdk8u141-b09
    1.44 +e965788c8d73328fce1eeb96af953815dc13b927 jdk8u141-b10
    1.45 +7f1844127578d6726da60f6813bfa9206b57dda9 jdk8u141-b11
    1.46 +d8134565e6c8cab3ccd0e356c787e0aa75ef68ee jdk8u141-b12
    1.47  eb09a34966f43c62cb286c78c10dc722fd12d884 jdk8u151-b00
     2.1 --- a/THIRD_PARTY_README	Tue Dec 13 12:52:09 2016 -0800
     2.2 +++ b/THIRD_PARTY_README	Thu Jun 08 13:44:31 2017 -0700
     2.3 @@ -3318,12 +3318,12 @@
     2.4  
     2.5  -------------------------------------------------------------------------------
     2.6  
     2.7 -%% This notice is provided with respect to zlib v1.2.8, which may be included 
     2.8 +%% This notice is provided with respect to zlib v1.2.11, which may be included 
     2.9  with JRE 8, JDK 8, and OpenJDK 8.
    2.10  
    2.11  --- begin of LICENSE ---
    2.12  
    2.13 -  version 1.2.8, April 28th, 2013
    2.14 +  version 1.2.11, January 15th, 2017
    2.15  
    2.16    Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
    2.17  
     3.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/impl/DetailImpl.java	Tue Dec 13 12:52:09 2016 -0800
     3.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/impl/DetailImpl.java	Thu Jun 08 13:44:31 2017 -0700
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -47,13 +47,13 @@
    3.11      public DetailEntry addDetailEntry(Name name) throws SOAPException {
    3.12          DetailEntry entry = createDetailEntry(name);
    3.13          addNode(entry);
    3.14 -        return (DetailEntry) circumventBug5034339(entry);
    3.15 +        return entry;
    3.16      }
    3.17  
    3.18      public DetailEntry addDetailEntry(QName qname) throws SOAPException {
    3.19          DetailEntry entry = createDetailEntry(qname);
    3.20          addNode(entry);
    3.21 -        return (DetailEntry) circumventBug5034339(entry);
    3.22 +        return entry;
    3.23      }
    3.24  
    3.25      protected SOAPElement addElement(Name name) throws SOAPException {
    3.26 @@ -119,28 +119,4 @@
    3.27         return true;
    3.28     }
    3.29  
    3.30 -    //overriding this method since the only two uses of this method
    3.31 -    // are in ElementImpl and DetailImpl
    3.32 -    //whereas the original base impl does the correct job for calls to it inside ElementImpl
    3.33 -    // But it would not work for DetailImpl.
    3.34 -    protected SOAPElement circumventBug5034339(SOAPElement element) {
    3.35 -
    3.36 -        Name elementName = element.getElementName();
    3.37 -        if (!isNamespaceQualified(elementName)) {
    3.38 -            String prefix = elementName.getPrefix();
    3.39 -            String defaultNamespace = getNamespaceURI(prefix);
    3.40 -            if (defaultNamespace != null) {
    3.41 -                Name newElementName =
    3.42 -                    NameImpl.create(
    3.43 -                        elementName.getLocalName(),
    3.44 -                        elementName.getPrefix(),
    3.45 -                        defaultNamespace);
    3.46 -                SOAPElement newElement = createDetailEntry(newElementName);
    3.47 -                replaceChild(newElement, element);
    3.48 -                return newElement;
    3.49 -            }
    3.50 -        }
    3.51 -        return element;
    3.52 -    }
    3.53 -
    3.54  }
     4.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/impl/ElementImpl.java	Tue Dec 13 12:52:09 2016 -0800
     4.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/impl/ElementImpl.java	Thu Jun 08 13:44:31 2017 -0700
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -127,8 +127,11 @@
    4.11      }
    4.12  
    4.13      public SOAPElement addChildElement(String localName) throws SOAPException {
    4.14 -        return (SOAPElement) addChildElement(
    4.15 -            NameImpl.createFromUnqualifiedName(localName));
    4.16 +        String nsUri = getNamespaceURI("");
    4.17 +        Name name = (nsUri == null || nsUri.isEmpty())
    4.18 +                ?  NameImpl.createFromUnqualifiedName(localName)
    4.19 +                :  NameImpl.createFromQualifiedName(localName, nsUri);
    4.20 +        return addChildElement(name);
    4.21      }
    4.22  
    4.23      public SOAPElement addChildElement(String localName, String prefix)
    4.24 @@ -372,13 +375,13 @@
    4.25      protected SOAPElement addElement(Name name) throws SOAPException {
    4.26          SOAPElement newElement = createElement(name);
    4.27          addNode(newElement);
    4.28 -        return circumventBug5034339(newElement);
    4.29 +        return newElement;
    4.30      }
    4.31  
    4.32      protected SOAPElement addElement(QName name) throws SOAPException {
    4.33          SOAPElement newElement = createElement(name);
    4.34          addNode(newElement);
    4.35 -        return circumventBug5034339(newElement);
    4.36 +        return newElement;
    4.37      }
    4.38  
    4.39      protected SOAPElement createElement(Name name) {
    4.40 @@ -1201,26 +1204,6 @@
    4.41          return !"".equals(name.getNamespaceURI());
    4.42      }
    4.43  
    4.44 -    protected SOAPElement circumventBug5034339(SOAPElement element) {
    4.45 -
    4.46 -        Name elementName = element.getElementName();
    4.47 -        if (!isNamespaceQualified(elementName)) {
    4.48 -            String prefix = elementName.getPrefix();
    4.49 -            String defaultNamespace = getNamespaceURI(prefix);
    4.50 -            if (defaultNamespace != null) {
    4.51 -                Name newElementName =
    4.52 -                    NameImpl.create(
    4.53 -                        elementName.getLocalName(),
    4.54 -                        elementName.getPrefix(),
    4.55 -                        defaultNamespace);
    4.56 -                SOAPElement newElement = createElement(newElementName);
    4.57 -                replaceChild(newElement, element);
    4.58 -                return newElement;
    4.59 -            }
    4.60 -        }
    4.61 -        return element;
    4.62 -    }
    4.63 -
    4.64      //TODO: This is a temporary SAAJ workaround for optimizing XWS
    4.65      // should be removed once the corresponding JAXP bug is fixed
    4.66      // It appears the bug will be fixed in JAXP 1.4 (not by Appserver 9 timeframe)
     5.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/message/saaj/SaajStaxWriter.java	Tue Dec 13 12:52:09 2016 -0800
     5.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/message/saaj/SaajStaxWriter.java	Thu Jun 08 13:44:31 2017 -0700
     5.3 @@ -1,5 +1,5 @@
     5.4  /*
     5.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     5.6 + * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
     5.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.8   *
     5.9   * This code is free software; you can redistribute it and/or modify it
    5.10 @@ -25,8 +25,10 @@
    5.11  
    5.12  package com.sun.xml.internal.ws.api.message.saaj;
    5.13  
    5.14 +import java.util.Iterator;
    5.15  import java.util.Arrays;
    5.16 -import java.util.Iterator;
    5.17 +import java.util.List;
    5.18 +import java.util.LinkedList;
    5.19  
    5.20  import javax.xml.namespace.NamespaceContext;
    5.21  import javax.xml.namespace.QName;
    5.22 @@ -42,6 +44,17 @@
    5.23  /**
    5.24   * SaajStaxWriter builds a SAAJ SOAPMessage by using XMLStreamWriter interface.
    5.25   *
    5.26 + * <p>
    5.27 + * Defers creation of SOAPElement until all the aspects of the name of the element are known.
    5.28 + * In some cases, the namespace uri is indicated only by the {@link #writeNamespace(String, String)} call.
    5.29 + * After opening an element ({@code writeStartElement}, {@code writeEmptyElement} methods), all attributes
    5.30 + * and namespace assignments are retained within {@link DeferredElement} object ({@code deferredElement} field).
    5.31 + * As soon as any other method than {@code writeAttribute}, {@code writeNamespace}, {@code writeDefaultNamespace}
    5.32 + * or {@code setNamespace} is called, the contents of {@code deferredElement} is transformed into new SOAPElement
    5.33 + * (which is appropriately inserted into the SOAPMessage under construction).
    5.34 + * This mechanism is necessary to fix JDK-8159058 issue.
    5.35 + * </p>
    5.36 + *
    5.37   * @author shih-chang.chen@oracle.com
    5.38   */
    5.39  public class SaajStaxWriter implements XMLStreamWriter {
    5.40 @@ -49,6 +62,7 @@
    5.41      protected SOAPMessage soap;
    5.42      protected String envURI;
    5.43      protected SOAPElement currentElement;
    5.44 +    protected DeferredElement deferredElement;
    5.45  
    5.46      static final protected String Envelope = "Envelope";
    5.47      static final protected String Header = "Header";
    5.48 @@ -59,6 +73,7 @@
    5.49          soap = msg;
    5.50          currentElement = soap.getSOAPPart().getEnvelope();
    5.51          envURI = currentElement.getNamespaceURI();
    5.52 +        this.deferredElement = new DeferredElement();
    5.53      }
    5.54  
    5.55      public SOAPMessage getSOAPMessage() {
    5.56 @@ -67,11 +82,8 @@
    5.57  
    5.58      @Override
    5.59      public void writeStartElement(final String localName) throws XMLStreamException {
    5.60 -        try {
    5.61 -            currentElement = currentElement.addChildElement(localName);
    5.62 -        } catch (SOAPException e) {
    5.63 -            throw new XMLStreamException(e);
    5.64 -        }
    5.65 +        currentElement = deferredElement.flushTo(currentElement);
    5.66 +        deferredElement.setLocalName(localName);
    5.67      }
    5.68  
    5.69      @Override
    5.70 @@ -81,8 +93,10 @@
    5.71  
    5.72      @Override
    5.73      public void writeStartElement(final String prefix, final String ln, final String ns) throws XMLStreamException {
    5.74 -        try {
    5.75 -            if (envURI.equals(ns)) {
    5.76 +        currentElement = deferredElement.flushTo(currentElement);
    5.77 +
    5.78 +        if (envURI.equals(ns)) {
    5.79 +            try {
    5.80                  if (Envelope.equals(ln)) {
    5.81                      currentElement = soap.getSOAPPart().getEnvelope();
    5.82                      fixPrefix(prefix);
    5.83 @@ -96,13 +110,16 @@
    5.84                      fixPrefix(prefix);
    5.85                      return;
    5.86                  }
    5.87 +            } catch (SOAPException e) {
    5.88 +                throw new XMLStreamException(e);
    5.89              }
    5.90 -            currentElement = (prefix == null) ?
    5.91 -                    currentElement.addChildElement(new QName(ns, ln)) :
    5.92 -                    currentElement.addChildElement(ln, prefix, ns);
    5.93 -        } catch (SOAPException e) {
    5.94 -            throw new XMLStreamException(e);
    5.95 +
    5.96          }
    5.97 +
    5.98 +        deferredElement.setLocalName(ln);
    5.99 +        deferredElement.setNamespaceUri(ns);
   5.100 +        deferredElement.setPrefix(prefix);
   5.101 +
   5.102      }
   5.103  
   5.104      private void fixPrefix(final String prfx) throws XMLStreamException {
   5.105 @@ -129,11 +146,13 @@
   5.106  
   5.107      @Override
   5.108      public void writeEndElement() throws XMLStreamException {
   5.109 +        currentElement = deferredElement.flushTo(currentElement);
   5.110          if (currentElement != null) currentElement = currentElement.getParentElement();
   5.111      }
   5.112  
   5.113      @Override
   5.114      public void writeEndDocument() throws XMLStreamException {
   5.115 +        currentElement = deferredElement.flushTo(currentElement);
   5.116      }
   5.117  
   5.118      @Override
   5.119 @@ -151,19 +170,14 @@
   5.120  
   5.121      @Override
   5.122      public void writeAttribute(final String prefix, final String ns, final String ln, final String value) throws XMLStreamException {
   5.123 -        try {
   5.124 -            if (ns == null) {
   5.125 -                if (prefix == null && xmlns.equals(ln)) {
   5.126 -                    currentElement.addNamespaceDeclaration("", value);
   5.127 -                } else {
   5.128 -                    currentElement.setAttributeNS("", ln, value);
   5.129 -                }
   5.130 +        if (ns == null && prefix == null && xmlns.equals(ln)) {
   5.131 +            writeNamespace("", value);
   5.132 +        } else {
   5.133 +            if (deferredElement.isInitialized()) {
   5.134 +                deferredElement.addAttribute(prefix, ns, ln, value);
   5.135              } else {
   5.136 -                QName name = (prefix == null) ? new QName(ns, ln) : new QName(ns, ln, prefix);
   5.137 -                currentElement.addAttribute(name, value);
   5.138 +                addAttibuteToElement(currentElement, prefix, ns, ln, value);
   5.139              }
   5.140 -        } catch (SOAPException e) {
   5.141 -            throw new XMLStreamException(e);
   5.142          }
   5.143      }
   5.144  
   5.145 @@ -174,16 +188,16 @@
   5.146  
   5.147      @Override
   5.148      public void writeNamespace(String prefix, final String uri) throws XMLStreamException {
   5.149 -
   5.150          // make prefix default if null or "xmlns" (according to javadoc)
   5.151 -        if (prefix == null || "xmlns".equals(prefix)) {
   5.152 -            prefix = "";
   5.153 -        }
   5.154 -
   5.155 -        try {
   5.156 -            currentElement.addNamespaceDeclaration(prefix, uri);
   5.157 -        } catch (SOAPException e) {
   5.158 -            throw new XMLStreamException(e);
   5.159 +        String thePrefix = prefix == null || "xmlns".equals(prefix) ? "" : prefix;
   5.160 +        if (deferredElement.isInitialized()) {
   5.161 +            deferredElement.addNamespaceDeclaration(thePrefix, uri);
   5.162 +        } else {
   5.163 +            try {
   5.164 +                currentElement.addNamespaceDeclaration(thePrefix, uri);
   5.165 +            } catch (SOAPException e) {
   5.166 +                throw new XMLStreamException(e);
   5.167 +            }
   5.168          }
   5.169      }
   5.170  
   5.171 @@ -194,35 +208,40 @@
   5.172  
   5.173      @Override
   5.174      public void writeComment(final String data) throws XMLStreamException {
   5.175 +        currentElement = deferredElement.flushTo(currentElement);
   5.176          Comment c = soap.getSOAPPart().createComment(data);
   5.177          currentElement.appendChild(c);
   5.178      }
   5.179  
   5.180      @Override
   5.181      public void writeProcessingInstruction(final String target) throws XMLStreamException {
   5.182 +        currentElement = deferredElement.flushTo(currentElement);
   5.183          Node n = soap.getSOAPPart().createProcessingInstruction(target, "");
   5.184          currentElement.appendChild(n);
   5.185      }
   5.186  
   5.187      @Override
   5.188      public void writeProcessingInstruction(final String target, final String data) throws XMLStreamException {
   5.189 +        currentElement = deferredElement.flushTo(currentElement);
   5.190          Node n = soap.getSOAPPart().createProcessingInstruction(target, data);
   5.191          currentElement.appendChild(n);
   5.192      }
   5.193  
   5.194      @Override
   5.195      public void writeCData(final String data) throws XMLStreamException {
   5.196 +        currentElement = deferredElement.flushTo(currentElement);
   5.197          Node n = soap.getSOAPPart().createCDATASection(data);
   5.198          currentElement.appendChild(n);
   5.199      }
   5.200  
   5.201      @Override
   5.202      public void writeDTD(final String dtd) throws XMLStreamException {
   5.203 -        //TODO ... Don't do anything here
   5.204 +        currentElement = deferredElement.flushTo(currentElement);
   5.205      }
   5.206  
   5.207      @Override
   5.208      public void writeEntityRef(final String name) throws XMLStreamException {
   5.209 +        currentElement = deferredElement.flushTo(currentElement);
   5.210          Node n = soap.getSOAPPart().createEntityReference(name);
   5.211          currentElement.appendChild(n);
   5.212      }
   5.213 @@ -250,6 +269,7 @@
   5.214  
   5.215      @Override
   5.216      public void writeCharacters(final String text) throws XMLStreamException {
   5.217 +        currentElement = deferredElement.flushTo(currentElement);
   5.218          try {
   5.219              currentElement.addTextNode(text);
   5.220          } catch (SOAPException e) {
   5.221 @@ -259,6 +279,7 @@
   5.222  
   5.223      @Override
   5.224      public void writeCharacters(final char[] text, final int start, final int len) throws XMLStreamException {
   5.225 +        currentElement = deferredElement.flushTo(currentElement);
   5.226          char[] chr = (start == 0 && len == text.length) ? text : Arrays.copyOfRange(text, start, start + len);
   5.227          try {
   5.228              currentElement.addTextNode(new String(chr));
   5.229 @@ -274,10 +295,16 @@
   5.230  
   5.231      @Override
   5.232      public void setPrefix(final String prefix, final String uri) throws XMLStreamException {
   5.233 -        try {
   5.234 -            this.currentElement.addNamespaceDeclaration(prefix, uri);
   5.235 -        } catch (SOAPException e) {
   5.236 -            throw new XMLStreamException(e);
   5.237 +        // TODO: this in fact is not what would be expected from XMLStreamWriter
   5.238 +        //       (e.g. XMLStreamWriter for writing to output stream does not write anything as result of
   5.239 +        //        this method, it just rememebers that given prefix is associated with the given uri
   5.240 +        //        for the scope; to actually declare the prefix assignment in the resulting XML, one
   5.241 +        //        needs to call writeNamespace(...) method
   5.242 +        // Kept for backwards compatibility reasons - this might be worth of further investigation.
   5.243 +        if (deferredElement.isInitialized()) {
   5.244 +            deferredElement.addNamespaceDeclaration(prefix, uri);
   5.245 +        } else {
   5.246 +            throw new XMLStreamException("Namespace not associated with any element");
   5.247          }
   5.248      }
   5.249  
   5.250 @@ -308,12 +335,12 @@
   5.251                  return currentElement.lookupPrefix(namespaceURI);
   5.252              }
   5.253              public Iterator getPrefixes(final String namespaceURI) {
   5.254 -                return new Iterator() {
   5.255 +                return new Iterator<String>() {
   5.256                      String prefix = getPrefix(namespaceURI);
   5.257                      public boolean hasNext() {
   5.258                          return (prefix != null);
   5.259                      }
   5.260 -                    public Object next() {
   5.261 +                    public String next() {
   5.262                          if (!hasNext()) throw new java.util.NoSuchElementException();
   5.263                          String next = prefix;
   5.264                          prefix = null;
   5.265 @@ -324,4 +351,209 @@
   5.266              }
   5.267          };
   5.268      }
   5.269 +
   5.270 +    static void addAttibuteToElement(SOAPElement element, String prefix, String ns, String ln, String value)
   5.271 +            throws XMLStreamException {
   5.272 +        try {
   5.273 +            if (ns == null) {
   5.274 +                element.setAttributeNS("", ln, value);
   5.275 +            } else {
   5.276 +                QName name = prefix == null ? new QName(ns, ln) : new QName(ns, ln, prefix);
   5.277 +                element.addAttribute(name, value);
   5.278 +            }
   5.279 +        } catch (SOAPException e) {
   5.280 +            throw new XMLStreamException(e);
   5.281 +        }
   5.282 +    }
   5.283 +
   5.284 +    /**
   5.285 +     * Holds details of element that needs to be deferred in order to manage namespace assignments correctly.
   5.286 +     *
   5.287 +     * <p>
   5.288 +     * An instance of can be set with all the aspects of the element name (local name, prefix, namespace uri).
   5.289 +     * Attributes and namespace declarations (special case of attribute) can be added.
   5.290 +     * Namespace declarations are handled so that the element namespace is updated if it is implied by the namespace
   5.291 +     * declaration and the namespace was not set to non-{@code null} value previously.
   5.292 +     * </p>
   5.293 +     *
   5.294 +     * <p>
   5.295 +     * The state of this object can be {@link #flushTo(SOAPElement) flushed} to SOAPElement - new SOAPElement will
   5.296 +     * be added a child element; the new element will have exactly the shape as represented by the state of this
   5.297 +     * object. Note that the {@link #flushTo(SOAPElement)} method does nothing
   5.298 +     * (and returns the argument immediately) if the state of this object is not initialized
   5.299 +     * (i.e. local name is null).
   5.300 +     * </p>
   5.301 +     *
   5.302 +     * @author ondrej.cerny@oracle.com
   5.303 +     */
   5.304 +    static class DeferredElement {
   5.305 +        private String prefix;
   5.306 +        private String localName;
   5.307 +        private String namespaceUri;
   5.308 +        private final List<NamespaceDeclaration> namespaceDeclarations;
   5.309 +        private final List<AttributeDeclaration> attributeDeclarations;
   5.310 +
   5.311 +        DeferredElement() {
   5.312 +            this.namespaceDeclarations = new LinkedList<NamespaceDeclaration>();
   5.313 +            this.attributeDeclarations = new LinkedList<AttributeDeclaration>();
   5.314 +            reset();
   5.315 +        }
   5.316 +
   5.317 +
   5.318 +        /**
   5.319 +         * Set prefix of the element.
   5.320 +         * @param prefix namespace prefix
   5.321 +         */
   5.322 +        public void setPrefix(final String prefix) {
   5.323 +            this.prefix = prefix;
   5.324 +        }
   5.325 +
   5.326 +        /**
   5.327 +         * Set local name of the element.
   5.328 +         *
   5.329 +         * <p>
   5.330 +         *     This method initializes the element.
   5.331 +         * </p>
   5.332 +         *
   5.333 +         * @param localName local name {@code not null}
   5.334 +         */
   5.335 +        public void setLocalName(final String localName) {
   5.336 +            if (localName == null) {
   5.337 +                throw new IllegalArgumentException("localName can not be null");
   5.338 +            }
   5.339 +            this.localName = localName;
   5.340 +        }
   5.341 +
   5.342 +        /**
   5.343 +         * Set namespace uri.
   5.344 +         *
   5.345 +         * @param namespaceUri namespace uri
   5.346 +         */
   5.347 +        public void setNamespaceUri(final String namespaceUri) {
   5.348 +            this.namespaceUri = namespaceUri;
   5.349 +        }
   5.350 +
   5.351 +        /**
   5.352 +         * Adds namespace prefix assignment to the element.
   5.353 +         *
   5.354 +         * @param prefix prefix (not {@code null})
   5.355 +         * @param namespaceUri namespace uri
   5.356 +         */
   5.357 +        public void addNamespaceDeclaration(final String prefix, final String namespaceUri) {
   5.358 +            if (null == this.namespaceUri && null != namespaceUri && prefix.equals(emptyIfNull(this.prefix))) {
   5.359 +                this.namespaceUri = namespaceUri;
   5.360 +            }
   5.361 +            this.namespaceDeclarations.add(new NamespaceDeclaration(prefix, namespaceUri));
   5.362 +        }
   5.363 +
   5.364 +        /**
   5.365 +         * Adds attribute to the element.
   5.366 +         * @param prefix prefix
   5.367 +         * @param ns namespace
   5.368 +         * @param ln local name
   5.369 +         * @param value value
   5.370 +         */
   5.371 +        public void addAttribute(final String prefix, final String ns, final String ln, final String value) {
   5.372 +            if (ns == null && prefix == null && xmlns.equals(ln)) {
   5.373 +                this.addNamespaceDeclaration(prefix, value);
   5.374 +            } else {
   5.375 +                this.attributeDeclarations.add(new AttributeDeclaration(prefix, ns, ln, value));
   5.376 +            }
   5.377 +        }
   5.378 +
   5.379 +        /**
   5.380 +         * Flushes state of this element to the {@code target} element.
   5.381 +         *
   5.382 +         * <p>
   5.383 +         * If this element is initialized then it is added with all the namespace declarations and attributes
   5.384 +         * to the {@code target} element as a child. The state of this element is reset to uninitialized.
   5.385 +         * The newly added element object is returned.
   5.386 +         * </p>
   5.387 +         * <p>
   5.388 +         * If this element is not initialized then the {@code target} is returned immediately, nothing else is done.
   5.389 +         * </p>
   5.390 +         *
   5.391 +         * @param target target element
   5.392 +         * @return {@code target} or new element
   5.393 +         * @throws XMLStreamException on error
   5.394 +         */
   5.395 +        public SOAPElement flushTo(final SOAPElement target) throws XMLStreamException {
   5.396 +            try {
   5.397 +                if (this.localName != null) {
   5.398 +                    // add the element appropriately (based on namespace declaration)
   5.399 +                    final SOAPElement newElement;
   5.400 +                    if (this.namespaceUri == null) {
   5.401 +                        // add element with inherited scope
   5.402 +                        newElement = target.addChildElement(this.localName);
   5.403 +                    } else if (prefix == null) {
   5.404 +                        newElement = target.addChildElement(new QName(this.namespaceUri, this.localName));
   5.405 +                    } else {
   5.406 +                        newElement = target.addChildElement(this.localName, this.prefix, this.namespaceUri);
   5.407 +                    }
   5.408 +                    // add namespace declarations
   5.409 +                    for (NamespaceDeclaration namespace : this.namespaceDeclarations) {
   5.410 +                        target.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri);
   5.411 +                    }
   5.412 +                    // add attribute declarations
   5.413 +                    for (AttributeDeclaration attribute : this.attributeDeclarations) {
   5.414 +                        addAttibuteToElement(newElement,
   5.415 +                                attribute.prefix, attribute.namespaceUri, attribute.localName, attribute.value);
   5.416 +                    }
   5.417 +                    // reset state
   5.418 +                    this.reset();
   5.419 +
   5.420 +                    return newElement;
   5.421 +                } else {
   5.422 +                    return target;
   5.423 +                }
   5.424 +                // else after reset state -> not initialized
   5.425 +            } catch (SOAPException e) {
   5.426 +                throw new XMLStreamException(e);
   5.427 +            }
   5.428 +        }
   5.429 +
   5.430 +        /**
   5.431 +         * Is the element initialized?
   5.432 +         * @return boolean indicating whether it was initialized after last flush
   5.433 +         */
   5.434 +        public boolean isInitialized() {
   5.435 +            return this.localName != null;
   5.436 +        }
   5.437 +
   5.438 +        private void reset() {
   5.439 +            this.localName = null;
   5.440 +            this.prefix = null;
   5.441 +            this.namespaceUri = null;
   5.442 +            this.namespaceDeclarations.clear();
   5.443 +            this.attributeDeclarations.clear();
   5.444 +        }
   5.445 +
   5.446 +        private static String emptyIfNull(String s) {
   5.447 +            return s == null ? "" : s;
   5.448 +        }
   5.449 +    }
   5.450 +
   5.451 +    static class NamespaceDeclaration {
   5.452 +        final String prefix;
   5.453 +        final String namespaceUri;
   5.454 +
   5.455 +        NamespaceDeclaration(String prefix, String namespaceUri) {
   5.456 +            this.prefix = prefix;
   5.457 +            this.namespaceUri = namespaceUri;
   5.458 +        }
   5.459 +    }
   5.460 +
   5.461 +    static class AttributeDeclaration {
   5.462 +        final String prefix;
   5.463 +        final String namespaceUri;
   5.464 +        final String localName;
   5.465 +        final String value;
   5.466 +
   5.467 +        AttributeDeclaration(String prefix, String namespaceUri, String localName, String value) {
   5.468 +            this.prefix = prefix;
   5.469 +            this.namespaceUri = namespaceUri;
   5.470 +            this.localName = localName;
   5.471 +            this.value = value;
   5.472 +        }
   5.473 +    }
   5.474  }

mercurial