1 /* 2 * Copyright (c) 1997, 2017, 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.ResourceBundle; 29 import java.util.logging.Logger; 30 31 import javax.xml.soap.SOAPElement; 32 import javax.xml.soap.SOAPException; 33 34 import com.sun.xml.internal.messaging.saaj.util.SAAJUtil; 35 import org.w3c.dom.Comment; 36 import org.w3c.dom.DOMException; 37 import org.w3c.dom.Document; 38 import org.w3c.dom.NamedNodeMap; 39 import org.w3c.dom.Node; 40 import org.w3c.dom.NodeList; 41 import org.w3c.dom.Text; 42 43 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; 44 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants; 45 import org.w3c.dom.UserDataHandler; 46 47 public class SOAPCommentImpl 48 implements javax.xml.soap.Text, org.w3c.dom.Comment { 49 50 protected static final Logger log = 51 Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN, 52 "com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings"); 53 protected static ResourceBundle rb = 54 log.getResourceBundle(); 55 56 @Override 57 public String getData() throws DOMException { 58 return comment.getData(); 59 } 60 61 @Override 62 public void setData(String data) throws DOMException { 63 comment.setData(data); 64 } 65 66 @Override 67 public int getLength() { 68 return comment.getLength(); 69 } 70 71 @Override 72 public String substringData(int offset, int count) throws DOMException { 73 return comment.substringData(offset, count); 74 } 75 76 @Override 77 public void appendData(String arg) throws DOMException { 78 comment.appendData(arg); 79 } 80 81 @Override 82 public void insertData(int offset, String arg) throws DOMException { 83 comment.insertData(offset, arg); 84 } 85 86 @Override 87 public void deleteData(int offset, int count) throws DOMException { 88 comment.deleteData(offset, count); 89 } 90 91 @Override 92 public void replaceData(int offset, int count, String arg) throws DOMException { 93 comment.replaceData(offset, count, arg); 94 } 95 96 @Override 97 public String getNodeName() { 98 return comment.getNodeName(); 99 } 100 101 @Override 102 public String getNodeValue() throws DOMException { 103 return comment.getNodeValue(); 104 } 105 106 @Override 107 public void setNodeValue(String nodeValue) throws DOMException { 108 comment.setNodeValue(nodeValue); 109 } 110 111 @Override 112 public short getNodeType() { 113 return comment.getNodeType(); 114 } 115 116 @Override 117 public Node getParentNode() { 118 return comment.getParentNode(); 119 } 120 121 @Override 122 public NodeList getChildNodes() { 123 return comment.getChildNodes(); 124 } 125 126 @Override 127 public Node getFirstChild() { 128 return comment.getFirstChild(); 129 } 130 131 @Override 132 public Node getLastChild() { 133 return comment.getLastChild(); 134 } 135 136 @Override 137 public Node getPreviousSibling() { 138 return comment.getPreviousSibling(); 139 } 140 141 @Override 142 public Node getNextSibling() { 143 return comment.getNextSibling(); 144 } 145 146 @Override 147 public NamedNodeMap getAttributes() { 148 return comment.getAttributes(); 149 } 150 151 @Override 152 public Document getOwnerDocument() { 153 return comment.getOwnerDocument(); 154 } 155 156 @Override 157 public Node insertBefore(Node newChild, Node refChild) throws DOMException { 158 return comment.insertBefore(newChild, refChild); 159 } 160 161 @Override 162 public Node replaceChild(Node newChild, Node oldChild) throws DOMException { 163 return comment.replaceChild(newChild, oldChild); 164 } 165 166 @Override 167 public Node removeChild(Node oldChild) throws DOMException { 168 return comment.removeChild(oldChild); 169 } 170 171 @Override 172 public Node appendChild(Node newChild) throws DOMException { 173 return comment.appendChild(newChild); 174 } 175 176 @Override 177 public boolean hasChildNodes() { 178 return comment.hasChildNodes(); 179 } 180 181 @Override 182 public Node cloneNode(boolean deep) { 183 return comment.cloneNode(deep); 184 } 185 186 @Override 187 public void normalize() { 188 comment.normalize(); 189 } 190 191 @Override 192 public boolean isSupported(String feature, String version) { 193 return comment.isSupported(feature, version); 194 } 195 196 @Override 197 public String getNamespaceURI() { 198 return comment.getNamespaceURI(); 199 } 200 201 @Override 202 public String getPrefix() { 203 return comment.getPrefix(); 204 } 205 206 @Override 207 public void setPrefix(String prefix) throws DOMException { 208 comment.setPrefix(prefix); 209 } 210 211 @Override 212 public String getLocalName() { 213 return comment.getLocalName(); 214 } 215 216 @Override 217 public boolean hasAttributes() { 218 return comment.hasAttributes(); 219 } 220 221 @Override 222 public String getBaseURI() { 223 return comment.getBaseURI(); 224 } 225 226 @Override 227 public short compareDocumentPosition(Node other) throws DOMException { 228 return comment.compareDocumentPosition(other); 229 } 230 231 @Override 232 public String getTextContent() throws DOMException { 233 return comment.getTextContent(); 234 } 235 236 @Override 237 public void setTextContent(String textContent) throws DOMException { 238 comment.setTextContent(textContent); 239 } 240 241 @Override 242 public boolean isSameNode(Node other) { 243 return comment.isSameNode(other); 244 } 245 246 @Override 247 public String lookupPrefix(String namespaceURI) { 248 return comment.lookupPrefix(namespaceURI); 249 } 250 251 @Override 252 public boolean isDefaultNamespace(String namespaceURI) { 253 return comment.isDefaultNamespace(namespaceURI); 254 } 255 256 @Override 257 public String lookupNamespaceURI(String prefix) { 258 return comment.lookupNamespaceURI(prefix); 259 } 260 261 @Override 262 public boolean isEqualNode(Node arg) { 263 return comment.isEqualNode(arg); 264 } 265 266 @Override 267 public Object getFeature(String feature, String version) { 268 return comment.getFeature(feature, version); 269 } 270 271 @Override 272 public Object setUserData(String key, Object data, UserDataHandler handler) { 273 return comment.setUserData(key, data, handler); 274 } 275 276 @Override 277 public Object getUserData(String key) { 278 return comment.getUserData(key); 279 } 280 281 private Comment comment; 282 283 public SOAPCommentImpl(SOAPDocumentImpl ownerDoc, String text) { 284 comment = ownerDoc.getDomDocument().createComment(text); 285 ownerDoc.register(this); 286 } 287 288 public String getValue() { 289 String nodeValue = getNodeValue(); 290 return (nodeValue.equals("") ? null : nodeValue); 291 } 292 293 public void setValue(String text) { 294 setNodeValue(text); 295 } 296 297 298 public void setParentElement(SOAPElement element) throws SOAPException { 299 if (element == null) { 300 log.severe("SAAJ0112.impl.no.null.to.parent.elem"); 301 throw new SOAPException("Cannot pass NULL to setParentElement"); 302 } 303 ((ElementImpl) element).addNode(this); 304 } 305 306 public SOAPElement getParentElement() { 307 return (SOAPElement) getParentNode(); 308 } 309 310 public void detachNode() { 311 org.w3c.dom.Node parent = getParentNode(); 312 if (parent != null) { 313 parent.removeChild(this); 314 } 315 } 316 317 public void recycleNode() { 318 detachNode(); 319 // TBD 320 // - add this to the factory so subsequent 321 // creations can reuse this object. 322 } 323 324 public boolean isComment() { 325 return true; 326 } 327 328 public Text splitText(int offset) throws DOMException { 329 log.severe("SAAJ0113.impl.cannot.split.text.from.comment"); 330 throw new UnsupportedOperationException("Cannot split text from a Comment Node."); 331 } 332 333 public Text replaceWholeText(String content) throws DOMException { 334 log.severe("SAAJ0114.impl.cannot.replace.wholetext.from.comment"); 335 throw new UnsupportedOperationException("Cannot replace Whole Text from a Comment Node."); 336 } 337 338 public String getWholeText() { 339 //TODO: maybe we have to implement this in future. 340 throw new UnsupportedOperationException("Not Supported"); 341 } 342 343 public boolean isElementContentWhitespace() { 344 //TODO: maybe we have to implement this in future. 345 throw new UnsupportedOperationException("Not Supported"); 346 } 347 348 public Comment getDomElement() { 349 return comment; 350 } 351 }