src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/impl/ElementImpl.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.messaging.saaj.soap.impl;
  27 


  28 import java.util.*;
  29 import java.util.logging.Level;
  30 import java.util.logging.Logger;
  31 
  32 import javax.xml.namespace.QName;
  33 import javax.xml.soap.*;
  34 
  35 import org.w3c.dom.*;
  36 import org.w3c.dom.Node;
  37 
  38 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
  39 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
  40 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
  41 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
  42 import com.sun.xml.internal.messaging.saaj.util.*;
  43 
  44 public class ElementImpl
  45     extends com.sun.org.apache.xerces.internal.dom.ElementNSImpl
  46     implements SOAPElement, SOAPBodyElement {
  47 


  92         SOAPDocumentImpl ownerDoc,
  93         String uri,
  94         String qualifiedName) {
  95 
  96         super(ownerDoc, uri, qualifiedName);
  97         elementQName =
  98             new QName(uri, getLocalPart(qualifiedName), getPrefix(qualifiedName));
  99     }
 100 
 101     public void ensureNamespaceIsDeclared(String prefix, String uri) {
 102         String alreadyDeclaredUri = getNamespaceURI(prefix);
 103         if (alreadyDeclaredUri == null || !alreadyDeclaredUri.equals(uri)) {
 104             try {
 105                 addNamespaceDeclaration(prefix, uri);
 106             } catch (SOAPException e) { /*ignore*/
 107             }
 108         }
 109     }
 110 
 111     public Document getOwnerDocument() {
 112         SOAPDocument ownerSOAPDocument =
 113             ((SOAPDocument) super.getOwnerDocument());
 114         if (ownerSOAPDocument == null) {
 115             return null;
 116         }
 117         return ownerSOAPDocument.getDocument();
 118     }
 119 
 120     public SOAPElement addChildElement(Name name) throws SOAPException {
 121         return  addElement(name);
 122     }
 123 
 124     public SOAPElement addChildElement(QName qname) throws SOAPException {
 125         return  addElement(qname);
 126     }
 127 
 128     public SOAPElement addChildElement(String localName) throws SOAPException {
 129         return (SOAPElement) addChildElement(
 130             NameImpl.createFromUnqualifiedName(localName));
 131     }
 132 
 133     public SOAPElement addChildElement(String localName, String prefix)
 134         throws SOAPException {
 135         String uri = getNamespaceURI(prefix);
 136         if (uri == null) {
 137             log.log(


 782         Node currentChild = getFirstChild();
 783 
 784         while (currentChild != null) {
 785             Node temp = currentChild.getNextSibling();
 786             if (currentChild instanceof javax.xml.soap.Node) {
 787                 ((javax.xml.soap.Node) currentChild).detachNode();
 788             } else {
 789                 Node parent = currentChild.getParentNode();
 790                 if (parent != null) {
 791                     parent.removeChild(currentChild);
 792                 }
 793 
 794             }
 795             currentChild = temp;
 796         }
 797     }
 798 
 799     public void setEncodingStyle(String encodingStyle) throws SOAPException {
 800         if (!"".equals(encodingStyle)) {
 801             try {
 802                 JaxmURI uri = new JaxmURI(encodingStyle);
 803             } catch (JaxmURI.MalformedURIException m) {
 804                 log.log(
 805                     Level.SEVERE,
 806                     "SAAJ0105.impl.encoding.style.mustbe.valid.URI",
 807                     new String[] { encodingStyle });
 808                 throw new IllegalArgumentException(
 809                     "Encoding style (" + encodingStyle + ") should be a valid URI");
 810             }
 811         }
 812         encodingStyleAttribute.setValue(encodingStyle);
 813         tryToFindEncodingStyleAttributeName();
 814     }
 815 
 816     public String getEncodingStyle() {
 817         String encodingStyle = encodingStyleAttribute.getValue();
 818         if (encodingStyle != null)
 819             return encodingStyle;
 820         String soapNamespace = getSOAPNamespace();
 821         if (soapNamespace != null) {
 822             Attr attr = getAttributeNodeNS(soapNamespace, "encodingStyle");
 823             if (attr != null) {


1209             if (defaultNamespace != null) {
1210                 Name newElementName =
1211                     NameImpl.create(
1212                         elementName.getLocalName(),
1213                         elementName.getPrefix(),
1214                         defaultNamespace);
1215                 SOAPElement newElement = createElement(newElementName);
1216                 replaceChild(newElement, element);
1217                 return newElement;
1218             }
1219         }
1220         return element;
1221     }
1222 
1223     //TODO: This is a temporary SAAJ workaround for optimizing XWS
1224     // should be removed once the corresponding JAXP bug is fixed
1225     // It appears the bug will be fixed in JAXP 1.4 (not by Appserver 9 timeframe)
1226     public void setAttributeNS(
1227         String namespaceURI,String qualifiedName, String value) {
1228         int index = qualifiedName.indexOf(':');
1229         String prefix, localName;
1230         if (index < 0) {
1231             prefix = null;
1232             localName = qualifiedName;
1233         }
1234         else {
1235             prefix = qualifiedName.substring(0, index);
1236             localName = qualifiedName.substring(index + 1);
1237         }
1238 
1239         // Workaround for bug 6467808 - This needs to be fixed in JAXP
1240 
1241         // Rolling back this fix, this is a wrong fix, infact its causing other regressions in JAXWS tck and
1242         // other tests, because of this change the namespace declarations on soapenv:Fault element are never
1243         // picked up. The fix for bug 6467808 should be in JAXP.
1244 //        if(elementQName.getLocalPart().equals("Fault") &&
1245 //                (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(value) ||
1246 //                SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(value)))
1247 //            return;
1248 
1249         super.setAttributeNS(namespaceURI,qualifiedName,value);
1250         //String tmpLocalName = this.getLocalName();
1251         String tmpURI = this.getNamespaceURI();
1252         boolean isIDNS = false;
1253         if( tmpURI != null && (tmpURI.equals(DSIG_NS) || tmpURI.equals(XENC_NS))){
1254             isIDNS = true;
1255         }
1256         //No need to check for Signature/encryption element
1257         //just check for namespace.
   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.messaging.saaj.soap.impl;
  27 
  28 import java.net.URI;
  29 import java.net.URISyntaxException;
  30 import java.util.*;
  31 import java.util.logging.Level;
  32 import java.util.logging.Logger;
  33 
  34 import javax.xml.namespace.QName;
  35 import javax.xml.soap.*;
  36 
  37 import org.w3c.dom.*;
  38 import org.w3c.dom.Node;
  39 
  40 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
  41 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
  42 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
  43 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
  44 import com.sun.xml.internal.messaging.saaj.util.*;
  45 
  46 public class ElementImpl
  47     extends com.sun.org.apache.xerces.internal.dom.ElementNSImpl
  48     implements SOAPElement, SOAPBodyElement {
  49 


  94         SOAPDocumentImpl ownerDoc,
  95         String uri,
  96         String qualifiedName) {
  97 
  98         super(ownerDoc, uri, qualifiedName);
  99         elementQName =
 100             new QName(uri, getLocalPart(qualifiedName), getPrefix(qualifiedName));
 101     }
 102 
 103     public void ensureNamespaceIsDeclared(String prefix, String uri) {
 104         String alreadyDeclaredUri = getNamespaceURI(prefix);
 105         if (alreadyDeclaredUri == null || !alreadyDeclaredUri.equals(uri)) {
 106             try {
 107                 addNamespaceDeclaration(prefix, uri);
 108             } catch (SOAPException e) { /*ignore*/
 109             }
 110         }
 111     }
 112 
 113     public Document getOwnerDocument() {
 114         Document doc = super.getOwnerDocument();
 115         if (doc instanceof SOAPDocument)
 116             return ((SOAPDocument) doc).getDocument();
 117         else
 118             return doc;

 119     }
 120 
 121     public SOAPElement addChildElement(Name name) throws SOAPException {
 122         return  addElement(name);
 123     }
 124 
 125     public SOAPElement addChildElement(QName qname) throws SOAPException {
 126         return  addElement(qname);
 127     }
 128 
 129     public SOAPElement addChildElement(String localName) throws SOAPException {
 130         return (SOAPElement) addChildElement(
 131             NameImpl.createFromUnqualifiedName(localName));
 132     }
 133 
 134     public SOAPElement addChildElement(String localName, String prefix)
 135         throws SOAPException {
 136         String uri = getNamespaceURI(prefix);
 137         if (uri == null) {
 138             log.log(


 783         Node currentChild = getFirstChild();
 784 
 785         while (currentChild != null) {
 786             Node temp = currentChild.getNextSibling();
 787             if (currentChild instanceof javax.xml.soap.Node) {
 788                 ((javax.xml.soap.Node) currentChild).detachNode();
 789             } else {
 790                 Node parent = currentChild.getParentNode();
 791                 if (parent != null) {
 792                     parent.removeChild(currentChild);
 793                 }
 794 
 795             }
 796             currentChild = temp;
 797         }
 798     }
 799 
 800     public void setEncodingStyle(String encodingStyle) throws SOAPException {
 801         if (!"".equals(encodingStyle)) {
 802             try {
 803                 new URI(encodingStyle);
 804             } catch (URISyntaxException m) {
 805                 log.log(
 806                     Level.SEVERE,
 807                     "SAAJ0105.impl.encoding.style.mustbe.valid.URI",
 808                     new String[] { encodingStyle });
 809                 throw new IllegalArgumentException(
 810                     "Encoding style (" + encodingStyle + ") should be a valid URI");
 811             }
 812         }
 813         encodingStyleAttribute.setValue(encodingStyle);
 814         tryToFindEncodingStyleAttributeName();
 815     }
 816 
 817     public String getEncodingStyle() {
 818         String encodingStyle = encodingStyleAttribute.getValue();
 819         if (encodingStyle != null)
 820             return encodingStyle;
 821         String soapNamespace = getSOAPNamespace();
 822         if (soapNamespace != null) {
 823             Attr attr = getAttributeNodeNS(soapNamespace, "encodingStyle");
 824             if (attr != null) {


1210             if (defaultNamespace != null) {
1211                 Name newElementName =
1212                     NameImpl.create(
1213                         elementName.getLocalName(),
1214                         elementName.getPrefix(),
1215                         defaultNamespace);
1216                 SOAPElement newElement = createElement(newElementName);
1217                 replaceChild(newElement, element);
1218                 return newElement;
1219             }
1220         }
1221         return element;
1222     }
1223 
1224     //TODO: This is a temporary SAAJ workaround for optimizing XWS
1225     // should be removed once the corresponding JAXP bug is fixed
1226     // It appears the bug will be fixed in JAXP 1.4 (not by Appserver 9 timeframe)
1227     public void setAttributeNS(
1228         String namespaceURI,String qualifiedName, String value) {
1229         int index = qualifiedName.indexOf(':');
1230         String localName;
1231         if (index < 0)

1232             localName = qualifiedName;
1233         else


1234             localName = qualifiedName.substring(index + 1);

1235 
1236         // Workaround for bug 6467808 - This needs to be fixed in JAXP
1237 
1238         // Rolling back this fix, this is a wrong fix, infact its causing other regressions in JAXWS tck and
1239         // other tests, because of this change the namespace declarations on soapenv:Fault element are never
1240         // picked up. The fix for bug 6467808 should be in JAXP.
1241 //        if(elementQName.getLocalPart().equals("Fault") &&
1242 //                (SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE.equals(value) ||
1243 //                SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE.equals(value)))
1244 //            return;
1245 
1246         super.setAttributeNS(namespaceURI,qualifiedName,value);
1247         //String tmpLocalName = this.getLocalName();
1248         String tmpURI = this.getNamespaceURI();
1249         boolean isIDNS = false;
1250         if( tmpURI != null && (tmpURI.equals(DSIG_NS) || tmpURI.equals(XENC_NS))){
1251             isIDNS = true;
1252         }
1253         //No need to check for Signature/encryption element
1254         //just check for namespace.