1 16 package org.apache.axis2.saaj; 17 18 import org.apache.axis2.util.XMLUtils; 19 import org.w3c.dom.*; 20 21 import javax.xml.parsers.ParserConfigurationException ; 22 import javax.xml.soap.SOAPException ; 23 24 30 public class SOAPDocumentImpl implements Document { 31 32 protected Document delegate = null; 34 protected SOAPPartImpl soapPart = null; 35 36 41 public SOAPDocumentImpl(SOAPPartImpl sp) { 42 try { 43 delegate = XMLUtils.newDocument(); 44 } catch (ParserConfigurationException e) { 45 } 47 soapPart = sp; 48 } 49 50 public DOMImplementation getImplementation() { 51 return delegate.getImplementation(); 52 } 53 54 61 public DocumentFragment createDocumentFragment() { 62 return delegate.createDocumentFragment(); 63 } 64 65 70 public DocumentType getDoctype() { 71 return delegate.getDoctype(); 72 } 73 74 79 public Element getDocumentElement() { 80 return soapPart.getDocumentElement(); 81 } 82 83 86 public Attr createAttribute(String name) throws DOMException { 87 return delegate.createAttribute(name); 88 } 89 90 93 public CDATASection createCDATASection(String arg0) throws DOMException { 94 return null; 96 } 97 98 101 public Comment createComment(String arg0) { 102 return null; 104 } 105 106 109 public Element createElement(String arg0) throws DOMException { 110 return null; 112 } 113 114 public Element getElementById(String elementId) { 115 return delegate.getElementById(elementId); 116 } 117 118 119 124 public EntityReference createEntityReference(String name) 125 throws DOMException { 126 throw new java.lang.UnsupportedOperationException ( 127 "createEntityReference"); 128 } 129 130 133 public Node importNode(Node arg0, boolean arg1) throws DOMException { 134 return null; 136 } 137 138 141 public NodeList getElementsByTagName(String localName) { 142 try{ 143 NodeListImpl list = new NodeListImpl(); 144 if (soapPart != null) { 145 SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl)soapPart.getEnvelope(); 146 SOAPHeaderImpl header = (SOAPHeaderImpl)soapEnv.getHeader(); 147 if (header != null) { 148 list.addNodeList(header.getElementsByTagName(localName)); 149 } 150 SOAPBodyImpl body = (SOAPBodyImpl)soapEnv.getBody(); 151 if (body != null) { 152 list.addNodeList(body.getElementsByTagName(localName)); 153 } 154 } 155 return list; 156 }catch (SOAPException se) { 157 throw new DOMException(DOMException.INVALID_STATE_ERR, ""); 158 } 159 } 160 161 164 public Text createTextNode(String data) { 165 TextImpl me = new TextImpl(delegate.createTextNode(data)); 166 me.setOwnerDocument(soapPart); 167 return me; 168 } 169 170 174 public Attr createAttributeNS(String namespaceURI, String qualifiedName) 175 throws DOMException { 176 return delegate.createAttributeNS(namespaceURI, qualifiedName); 177 } 178 179 182 public Element createElementNS(String arg0, String arg1) 183 throws DOMException { 184 return null; 186 } 187 188 191 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { 192 try{ 193 NodeListImpl list = new NodeListImpl(); 194 if (soapPart != null) { 195 SOAPEnvelopeImpl soapEnv = (SOAPEnvelopeImpl)soapPart.getEnvelope(); 196 SOAPHeaderImpl header = (SOAPHeaderImpl)soapEnv.getHeader(); 197 if (header != null) { 198 list.addNodeList(header.getElementsByTagNameNS(namespaceURI, localName)); 199 } 200 SOAPBodyImpl body = (SOAPBodyImpl)soapEnv.getBody(); 201 if (body != null) { 202 list.addNodeList(body.getElementsByTagNameNS(namespaceURI, localName)); 203 } 204 } 205 return list; 206 }catch (SOAPException se) { 207 throw new DOMException(DOMException.INVALID_STATE_ERR, ""); 208 } 209 } 210 211 212 public ProcessingInstruction createProcessingInstruction( 213 String target, 214 String data) 215 throws DOMException { 216 throw new java.lang.UnsupportedOperationException ( 217 "createProcessingInstruction"); 218 } 219 220 221 226 public short getNodeType() { 227 return Node.DOCUMENT_NODE; 228 } 229 230 231 public void normalize() { 232 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 233 } 234 235 236 public boolean hasAttributes() { 237 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 238 } 239 240 public boolean hasChildNodes() { 241 try { 242 if (soapPart != null) { 243 if (soapPart.getEnvelope() != null) { 244 return true; 245 } 246 } 247 return false; 248 } catch (SOAPException se) { 249 throw new DOMException(DOMException.INVALID_STATE_ERR, ""); 250 } 251 } 252 253 public String getLocalName() { 254 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 255 } 256 257 public String getNamespaceURI() { 258 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 259 } 260 261 262 public String getNodeName() { 263 return null; 264 } 265 266 public String getNodeValue() throws DOMException { 267 throw new DOMException( 268 DOMException.NO_DATA_ALLOWED_ERR, 269 "Cannot use TextNode.get in " + this); 270 } 271 272 public String getPrefix() { 273 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 274 } 275 276 public void setNodeValue(String nodeValue) throws DOMException { 277 throw new DOMException( 278 DOMException.NO_DATA_ALLOWED_ERR, 279 "Cannot use TextNode.set in " + this); 280 } 281 282 283 public void setPrefix(String prefix) { 284 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 285 } 286 287 291 public Document getOwnerDocument() { 292 return null; 293 } 294 295 public NamedNodeMap getAttributes() { 296 return null; 297 } 298 299 public Node getFirstChild() { 300 try { 301 if (soapPart != null) 302 return (org.apache.axis2.saaj.SOAPEnvelopeImpl) soapPart 303 .getEnvelope(); 304 else 305 return null; 306 } catch (SOAPException se) { 307 throw new DOMException(DOMException.INVALID_STATE_ERR, ""); 308 } 309 } 310 311 public Node getLastChild() { 312 try { 313 if (soapPart != null) 314 return (org.apache.axis2.saaj.SOAPEnvelopeImpl) soapPart 315 .getEnvelope(); 316 else 317 return null; 318 } catch (SOAPException se) { 319 throw new DOMException(DOMException.INVALID_STATE_ERR, ""); 320 } 321 } 322 323 public Node getNextSibling() { 324 325 return null; 326 } 327 328 public Node getParentNode() { 329 return null; 330 } 331 332 public Node getPreviousSibling() { 333 return null; 334 } 335 336 public Node cloneNode(boolean deep) { 337 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 338 } 339 340 341 public NodeList getChildNodes() { 342 try { 343 if (soapPart != null) { 344 NodeListImpl children = new NodeListImpl(); 345 children.addNode(soapPart.getEnvelope()); 346 return children; 347 } else { 348 return NodeListImpl.EMPTY_NODELIST; 349 } 350 } catch (SOAPException se) { 351 throw new DOMException(DOMException.INVALID_STATE_ERR, ""); 352 } 353 354 } 355 356 private String [] features = { "foo", "bar" }; 358 private String version = "version 2.0"; 359 360 public boolean isSupported(String feature, String version) { 361 if (!version.equalsIgnoreCase(version)) 362 return false; 363 else 364 return true; 365 } 366 367 public Node appendChild(Node newChild) throws DOMException { 368 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 369 } 370 371 public Node removeChild(Node oldChild) throws DOMException { 372 try { 373 Node envNode; 374 if (soapPart != null) { 375 envNode = soapPart.getEnvelope(); 376 if (envNode.equals(oldChild)) { 377 return envNode; 378 } 379 } 380 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 381 } catch (SOAPException se) { 382 throw new DOMException(DOMException.INVALID_STATE_ERR, ""); 383 } 384 } 385 386 public Node insertBefore(Node newChild, Node refChild) 387 throws DOMException { 388 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 389 } 390 391 public Node replaceChild(Node newChild, Node oldChild) 392 throws DOMException { 393 throw new DOMException(DOMException.NOT_SUPPORTED_ERR, ""); 394 } 395 396 397 } 398 | Popular Tags |