91 element.removeAttribute(name);
92 }
93
94 @Override
95 public Attr getAttributeNode(String name) {
96 return element.getAttributeNode(name);
97 }
98
99 @Override
100 public Attr setAttributeNode(Attr newAttr) throws DOMException {
101 return element.setAttributeNode(newAttr);
102 }
103
104 @Override
105 public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
106 return element.removeAttributeNode(oldAttr);
107 }
108
109 @Override
110 public NodeList getElementsByTagName(String name) {
111 return new NodeListImpl(getSoapDocument(), element.getElementsByTagName(name));
112 }
113
114 @Override
115 public String getAttributeNS(String namespaceURI, String localName) throws DOMException {
116 return element.getAttributeNS(namespaceURI, localName);
117 }
118
119 protected static final Logger log =
120 Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN,
121 "com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings");
122
123 /**
124 * XML Information Set REC
125 * all namespace attributes (including those named xmlns,
126 * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
127 */
128 public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern();
129
130 /**
131 * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
132 * the Namespace URI that is automatically mapped to the "xml" prefix.
133 */
134 public final static String XML_URI = "http://www.w3.org/XML/1998/namespace".intern();
135
136 private final static String XMLNS = "xmlns".intern();
137
138 public ElementImpl(SOAPDocumentImpl ownerDoc, Name name) {
139 this.soapDocument = ownerDoc;
140 this.element = ownerDoc.getDomDocument().createElementNS(name.getURI(), name.getQualifiedName());
141 elementQName = NameImpl.convertToQName(name);
142 getSoapDocument().register(this);
143 }
144
145 public ElementImpl(SOAPDocumentImpl ownerDoc, QName name) {
146 this.soapDocument = ownerDoc;
147 this.element = ownerDoc.getDomDocument().createElementNS(name.getNamespaceURI(), getQualifiedName(name));
148 elementQName = name;
149 getSoapDocument().register(this);
150 }
151
152 public ElementImpl(SOAPDocumentImpl ownerDoc, Element domElement) {
153 this.element = domElement;
154 this.soapDocument = ownerDoc;
155 this.elementQName = new QName(domElement.getNamespaceURI(), domElement.getLocalName());
156 getSoapDocument().register(this);
157 }
158
159 public ElementImpl(
160 SOAPDocumentImpl ownerDoc,
161 String uri,
162 String qualifiedName) {
163
164 this.soapDocument = ownerDoc;
165 this.element = ownerDoc.getDomDocument().createElementNS(uri, qualifiedName);
166 elementQName =
167 new QName(uri, getLocalPart(qualifiedName), getPrefix(qualifiedName));
168 getSoapDocument().register(this);
169 }
170
171 public void ensureNamespaceIsDeclared(String prefix, String uri) {
172 String alreadyDeclaredUri = getNamespaceURI(prefix);
173 if (alreadyDeclaredUri == null || !alreadyDeclaredUri.equals(uri)) {
174 try {
175 addNamespaceDeclaration(prefix, uri);
176 } catch (SOAPException e) { /*ignore*/
177 }
178 }
179 }
180
181 public Document getOwnerDocument() {
182 return soapDocument;
183 }
184
185 @Override
186 public Node insertBefore(Node newChild, Node refChild) throws DOMException {
187 return element.insertBefore(getSoapDocument().getDomNode(newChild), getSoapDocument().getDomNode(refChild));
188 }
189
190 @Override
191 public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
192 return element.replaceChild(getSoapDocument().getDomNode(newChild), getSoapDocument().getDomNode(oldChild));
193 }
194
195 @Override
196 public Node removeChild(Node oldChild) throws DOMException {
197 return element.removeChild(getSoapDocument().getDomNode(oldChild));
198 }
199
200 @Override
201 public Node appendChild(Node newChild) throws DOMException {
202 return element.appendChild(getSoapDocument().getDomNode(newChild));
203 }
204
205 @Override
206 public boolean hasChildNodes() {
207 return element.hasChildNodes();
208 }
209
210 @Override
211 public Node cloneNode(boolean deep) {
212 return element.cloneNode(deep);
213 }
214
215 @Override
216 public void normalize() {
217 element.normalize();
218 }
219
220 @Override
221 public boolean isSupported(String feature, String version) {
222 return element.isSupported(feature, version);
586 } else {
587 return (SOAPElement)
588 getOwnerDocument().createElement(name.getQualifiedName());
589 }
590 }
591
592 protected SOAPElement createElement(QName name) {
593
594 if (isNamespaceQualified(name)) {
595 return (SOAPElement)
596 getOwnerDocument().createElementNS(
597 name.getNamespaceURI(),
598 getQualifiedName(name));
599 } else {
600 return (SOAPElement)
601 getOwnerDocument().createElement(getQualifiedName(name));
602 }
603 }
604
605 protected void addNode(org.w3c.dom.Node newElement) throws SOAPException {
606 insertBefore(getSoapDocument().getDomNode(newElement), null);
607
608 if (getOwnerDocument() instanceof DocumentFragment)
609 return;
610
611 if (newElement instanceof ElementImpl) {
612 ElementImpl element = (ElementImpl) newElement;
613 QName elementName = element.getElementQName();
614 if (!"".equals(elementName.getNamespaceURI())) {
615 element.ensureNamespaceIsDeclared(
616 elementName.getPrefix(), elementName.getNamespaceURI());
617 }
618 }
619
620 }
621
622 Element getFirstChildElement() {
623 Node child = getFirstChild();
624 while (child != null) {
625 if (child instanceof Element) {
626 return (Element) getSoapDocument().find(child);
627 }
628 child = child.getNextSibling();
629 }
630 return null;
631 }
632
633 protected SOAPElement findChild(NameImpl name) {
634 Node eachChild = getFirstChild();
635 while (eachChild != null) {
636 if (eachChild instanceof Element) {
637 SOAPElement eachChildSoap = (SOAPElement) getSoapDocument().find(eachChild);
638 if (eachChildSoap != null) {
639 if (eachChildSoap.getElementName().equals(name)) {
640 return eachChildSoap;
641 }
642 }
643 }
644 eachChild = eachChild.getNextSibling();
645 }
646 return null;
647 }
648
649 protected SOAPElement findAndConvertChildElement(NameImpl name) {
650 Iterator<Node> eachChild = getChildElementNodes();
651 while (eachChild.hasNext()) {
652 SOAPElement child = (SOAPElement) eachChild.next();
653 if (child.getElementName().equals(name)) {
654 return child;
655 }
656 }
657
861 }
862
863 public boolean removeNamespaceDeclaration(String prefix) {
864 org.w3c.dom.Attr declaration = getNamespaceAttr(prefix);
865 if (declaration == null) {
866 return false;
867 }
868 try {
869 removeAttributeNode(declaration);
870 } catch (DOMException de) {
871 // ignore
872 }
873 return true;
874 }
875
876 public Iterator<Node> getChildElements() {
877 return getChildElementsFrom(this);
878 }
879
880 protected SOAPElement convertToSoapElement(Element element) {
881 final Node soapNode = getSoapDocument().findIfPresent(element);
882 if (soapNode instanceof SOAPElement) {
883 return (SOAPElement) soapNode;
884 } else {
885 return replaceElementWithSOAPElement(
886 element,
887 (ElementImpl) createElement(NameImpl.copyElementName(element)));
888 }
889 }
890
891 protected SOAPElement replaceElementWithSOAPElement(
892 Element element,
893 ElementImpl copy) {
894
895 Iterator<Name> eachAttribute = getAllAttributesFrom(element);
896 while (eachAttribute.hasNext()) {
897 Name name = eachAttribute.next();
898 copy.addAttributeBare(name, getAttributeValueFrom(element, name));
899 }
900
901 Iterator<Node> eachChild = getChildElementsFrom(element);
902 while (eachChild.hasNext()) {
903 Node nextChild = eachChild.next();
904 copy.insertBefore(nextChild, null);
905 }
906
907 Node parent = getSoapDocument().find(element.getParentNode());
908 if (parent != null) {
909 parent.replaceChild(copy, element);
910 } // XXX else throw an exception?
911
912 return copy;
913 }
914
915 protected Iterator<Node> getChildElementNodes() {
916 return new Iterator<Node>() {
917 Iterator<Node> eachNode = getChildElements();
918 Node next = null;
919 Node last = null;
920
921 public boolean hasNext() {
922 if (next == null) {
923 while (eachNode.hasNext()) {
924 Node node = eachNode.next();
925 if (node instanceof Element) {
926 next = getSoapDocument().findIfPresent(node);
927 break;
928 }
929 }
930 }
931 return next != null;
932 }
933
934 public Node next() {
935 if (hasNext()) {
936 last = next;
937 next = null;
938 return last;
939 }
940 throw new NoSuchElementException();
941 }
942
943 public void remove() {
944 if (last == null) {
945 throw new IllegalStateException();
946 }
1084 return node;
1085 } else {
1086 log.severe("SAAJ0107.impl.elem.child.not.single.text");
1087 throw new IllegalStateException();
1088 }
1089 }
1090
1091 return null;
1092 }
1093
1094 protected javax.xml.soap.Node getValueNode() {
1095 Iterator<Node> i = getChildElements();
1096 while (i.hasNext()) {
1097 Node n = i.next();
1098 if (n.getNodeType() == org.w3c.dom.Node.TEXT_NODE ||
1099 n.getNodeType() == org.w3c.dom.Node.CDATA_SECTION_NODE) {
1100 // TODO: Hack to fix text node split into multiple lines.
1101 normalize();
1102 // Should remove the normalization step when this gets fixed in
1103 // DOM/Xerces.
1104 return getSoapDocument().find(n);
1105 }
1106 }
1107 return null;
1108 }
1109
1110 public void setParentElement(SOAPElement element) throws SOAPException {
1111 if (element == null) {
1112 log.severe("SAAJ0106.impl.no.null.to.parent.elem");
1113 throw new SOAPException("Cannot pass NULL to setParentElement");
1114 }
1115 element.addChildElement(this);
1116 findEncodingStyleAttributeName();
1117 }
1118
1119 protected void findEncodingStyleAttributeName() throws SOAPException {
1120 String soapNamespace = getSOAPNamespace();
1121 if (soapNamespace != null) {
1122 String soapNamespacePrefix = getNamespacePrefix(soapNamespace);
1123 if (soapNamespacePrefix != null) {
1124 setEncodingStyleNamespace(soapNamespace, soapNamespacePrefix);
1126 }
1127 }
1128
1129 protected void setEncodingStyleNamespace(
1130 String soapNamespace,
1131 String soapNamespacePrefix)
1132 throws SOAPException {
1133 Name encodingStyleAttributeName =
1134 NameImpl.create(
1135 "encodingStyle",
1136 soapNamespacePrefix,
1137 soapNamespace);
1138 encodingStyleAttribute.setName(encodingStyleAttributeName);
1139 }
1140
1141 public SOAPElement getParentElement() {
1142 Node parentNode = getParentNode();
1143 if (parentNode instanceof SOAPDocument) {
1144 return null;
1145 }
1146 return (SOAPElement) getSoapDocument().find(parentNode);
1147 }
1148
1149 protected String getSOAPNamespace() {
1150 String soapNamespace = null;
1151
1152 SOAPElement antecedent = this;
1153 while (antecedent != null) {
1154 Name antecedentName = antecedent.getElementName();
1155 String antecedentNamespace = antecedentName.getURI();
1156
1157 if (NameImpl.SOAP11_NAMESPACE.equals(antecedentNamespace)
1158 || NameImpl.SOAP12_NAMESPACE.equals(antecedentNamespace)) {
1159
1160 soapNamespace = antecedentNamespace;
1161 break;
1162 }
1163
1164 antecedent = antecedent.getParentElement();
1165 }
1166
1319 return null;
1320 }
1321
1322 String attrValue =
1323 element.getAttributeNS(nonzeroLengthUri, localName);
1324
1325 return attrValue;
1326 }
1327
1328 Attr attribute = null;
1329 attribute = element.getAttributeNode(qualifiedName);
1330
1331 return attribute == null ? null : attribute.getValue();
1332 }
1333
1334 protected Iterator<Node> getChildElementsFrom(final Element element) {
1335 return new Iterator<Node>() {
1336 Node next = element.getFirstChild();
1337 Node nextNext = null;
1338 Node last = null;
1339 Node soapElement = getSoapDocument().findIfPresent(element);
1340
1341 public boolean hasNext() {
1342 if (next != null) {
1343 return true;
1344 }
1345 if (nextNext != null) {
1346 next = nextNext;
1347 }
1348
1349 return next != null;
1350 }
1351
1352 public Node next() {
1353 if (hasNext()) {
1354 last = next;
1355 next = null;
1356
1357 if ((soapElement instanceof ElementImpl)
1358 && (last instanceof Element)) {
1359 last =
1360 ((ElementImpl) soapElement).convertToSoapElement(
1361 (Element) last);
1362 }
1363
1364 nextNext = last.getNextSibling();
1365 return getSoapDocument().findIfPresent(last);
1366 }
1367 throw new NoSuchElementException();
1368 }
1369
1370 public void remove() {
1371 if (last == null) {
1372 throw new IllegalStateException();
1373 }
1374 Node target = last;
1375 last = null;
1376 element.removeChild(target);
1377 }
1378 };
1379 }
1380
1381 public static String getQualifiedName(QName name) {
1382 String prefix = name.getPrefix();
1383 String localName = name.getLocalPart();
1384 String qualifiedName = null;
1385
1466
1467 }
1468
1469 @Override
1470 public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
1471 element.removeAttributeNS(namespaceURI, localName);
1472 }
1473
1474 @Override
1475 public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException {
1476 return element.getAttributeNodeNS(namespaceURI, localName);
1477 }
1478
1479 @Override
1480 public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
1481 return element.setAttributeNodeNS(newAttr);
1482 }
1483
1484 @Override
1485 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException {
1486 return new NodeListImpl(getSoapDocument(), element.getElementsByTagNameNS(namespaceURI, localName));
1487 }
1488
1489 @Override
1490 public boolean hasAttribute(String name) {
1491 return element.hasAttribute(name);
1492 }
1493
1494 @Override
1495 public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException {
1496 return element.hasAttributeNS(namespaceURI, localName);
1497 }
1498
1499 @Override
1500 public TypeInfo getSchemaTypeInfo() {
1501 return element.getSchemaTypeInfo();
1502 }
1503
1504 @Override
1505 public void setIdAttribute(String name, boolean isId) throws DOMException {
1506 element.setIdAttribute(name, isId);
1521 return element.getNodeName();
1522 }
1523
1524 @Override
1525 public String getNodeValue() throws DOMException {
1526 return element.getNodeValue();
1527 }
1528
1529 @Override
1530 public void setNodeValue(String nodeValue) throws DOMException {
1531 element.setNodeValue(nodeValue);
1532 }
1533
1534 @Override
1535 public short getNodeType() {
1536 return element.getNodeType();
1537 }
1538
1539 @Override
1540 public Node getParentNode() {
1541 return getSoapDocument().find(element.getParentNode());
1542 }
1543
1544 @Override
1545 public NodeList getChildNodes() {
1546 return new NodeListImpl(getSoapDocument(), element.getChildNodes());
1547 }
1548
1549 @Override
1550 public Node getFirstChild() {
1551 return getSoapDocument().findIfPresent(element.getFirstChild());
1552 }
1553
1554 @Override
1555 public Node getLastChild() {
1556 return getSoapDocument().findIfPresent(element.getLastChild());
1557 }
1558
1559 @Override
1560 public Node getPreviousSibling() {
1561 return getSoapDocument().findIfPresent(element.getPreviousSibling());
1562 }
1563
1564 @Override
1565 public Node getNextSibling() {
1566 return getSoapDocument().findIfPresent(element.getNextSibling());
1567 }
1568
1569 @Override
1570 public NamedNodeMap getAttributes() {
1571 return element.getAttributes();
1572 }
1573
1574 public Element getDomElement() {
1575 return element;
1576 }
1577
1578 public SOAPDocumentImpl getSoapDocument() {
1579 return soapDocument;
1580 }
1581 }
|
91 element.removeAttribute(name);
92 }
93
94 @Override
95 public Attr getAttributeNode(String name) {
96 return element.getAttributeNode(name);
97 }
98
99 @Override
100 public Attr setAttributeNode(Attr newAttr) throws DOMException {
101 return element.setAttributeNode(newAttr);
102 }
103
104 @Override
105 public Attr removeAttributeNode(Attr oldAttr) throws DOMException {
106 return element.removeAttributeNode(oldAttr);
107 }
108
109 @Override
110 public NodeList getElementsByTagName(String name) {
111 return new NodeListImpl(soapDocument, element.getElementsByTagName(name));
112 }
113
114 @Override
115 public String getAttributeNS(String namespaceURI, String localName) throws DOMException {
116 return element.getAttributeNS(namespaceURI, localName);
117 }
118
119 protected static final Logger log =
120 Logger.getLogger(LogDomainConstants.SOAP_IMPL_DOMAIN,
121 "com.sun.xml.internal.messaging.saaj.soap.impl.LocalStrings");
122
123 /**
124 * XML Information Set REC
125 * all namespace attributes (including those named xmlns,
126 * whose [prefix] property has no value) have a namespace URI of http://www.w3.org/2000/xmlns/
127 */
128 public final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/".intern();
129
130 /**
131 * The XML Namespace ("http://www.w3.org/XML/1998/namespace"). This is
132 * the Namespace URI that is automatically mapped to the "xml" prefix.
133 */
134 public final static String XML_URI = "http://www.w3.org/XML/1998/namespace".intern();
135
136 private final static String XMLNS = "xmlns".intern();
137
138 public ElementImpl(SOAPDocumentImpl ownerDoc, Name name) {
139 this.soapDocument = ownerDoc;
140 this.element = ownerDoc.getDomDocument().createElementNS(name.getURI(), name.getQualifiedName());
141 elementQName = NameImpl.convertToQName(name);
142 soapDocument.register(this);
143 }
144
145 public ElementImpl(SOAPDocumentImpl ownerDoc, QName name) {
146 this.soapDocument = ownerDoc;
147 this.element = ownerDoc.getDomDocument().createElementNS(name.getNamespaceURI(), getQualifiedName(name));
148 elementQName = name;
149 soapDocument.register(this);
150 }
151
152 public ElementImpl(SOAPDocumentImpl ownerDoc, Element domElement) {
153 this.element = domElement;
154 this.soapDocument = ownerDoc;
155 this.elementQName = new QName(domElement.getNamespaceURI(), domElement.getLocalName());
156 soapDocument.register(this);
157 }
158
159 public ElementImpl(
160 SOAPDocumentImpl ownerDoc,
161 String uri,
162 String qualifiedName) {
163
164 this.soapDocument = ownerDoc;
165 this.element = ownerDoc.getDomDocument().createElementNS(uri, qualifiedName);
166 elementQName =
167 new QName(uri, getLocalPart(qualifiedName), getPrefix(qualifiedName));
168 soapDocument.register(this);
169 }
170
171 public void ensureNamespaceIsDeclared(String prefix, String uri) {
172 String alreadyDeclaredUri = getNamespaceURI(prefix);
173 if (alreadyDeclaredUri == null || !alreadyDeclaredUri.equals(uri)) {
174 try {
175 addNamespaceDeclaration(prefix, uri);
176 } catch (SOAPException e) { /*ignore*/
177 }
178 }
179 }
180
181 public Document getOwnerDocument() {
182 return soapDocument;
183 }
184
185 @Override
186 public Node insertBefore(Node newChild, Node refChild) throws DOMException {
187 return soapDocument.findIfPresent(element.insertBefore(soapDocument.getDomNode(newChild), soapDocument.getDomNode(refChild)));
188 }
189
190 @Override
191 public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
192 return soapDocument.findIfPresent(element.replaceChild(soapDocument.getDomNode(newChild), soapDocument.getDomNode(oldChild)));
193 }
194
195 @Override
196 public Node removeChild(Node oldChild) throws DOMException {
197 return soapDocument.findIfPresent(element.removeChild(soapDocument.getDomNode(oldChild)));
198 }
199
200 @Override
201 public Node appendChild(Node newChild) throws DOMException {
202 return soapDocument.findIfPresent(element.appendChild(soapDocument.getDomNode(newChild)));
203 }
204
205 @Override
206 public boolean hasChildNodes() {
207 return element.hasChildNodes();
208 }
209
210 @Override
211 public Node cloneNode(boolean deep) {
212 return element.cloneNode(deep);
213 }
214
215 @Override
216 public void normalize() {
217 element.normalize();
218 }
219
220 @Override
221 public boolean isSupported(String feature, String version) {
222 return element.isSupported(feature, version);
586 } else {
587 return (SOAPElement)
588 getOwnerDocument().createElement(name.getQualifiedName());
589 }
590 }
591
592 protected SOAPElement createElement(QName name) {
593
594 if (isNamespaceQualified(name)) {
595 return (SOAPElement)
596 getOwnerDocument().createElementNS(
597 name.getNamespaceURI(),
598 getQualifiedName(name));
599 } else {
600 return (SOAPElement)
601 getOwnerDocument().createElement(getQualifiedName(name));
602 }
603 }
604
605 protected void addNode(org.w3c.dom.Node newElement) throws SOAPException {
606 insertBefore(soapDocument.getDomNode(newElement), null);
607
608 if (getOwnerDocument() instanceof DocumentFragment)
609 return;
610
611 if (newElement instanceof ElementImpl) {
612 ElementImpl element = (ElementImpl) newElement;
613 QName elementName = element.getElementQName();
614 if (!"".equals(elementName.getNamespaceURI())) {
615 element.ensureNamespaceIsDeclared(
616 elementName.getPrefix(), elementName.getNamespaceURI());
617 }
618 }
619
620 }
621
622 Element getFirstChildElement() {
623 Node child = getFirstChild();
624 while (child != null) {
625 if (child instanceof Element) {
626 return (Element) soapDocument.find(child);
627 }
628 child = child.getNextSibling();
629 }
630 return null;
631 }
632
633 protected SOAPElement findChild(NameImpl name) {
634 Node eachChild = getFirstChild();
635 while (eachChild != null) {
636 if (eachChild instanceof Element) {
637 SOAPElement eachChildSoap = (SOAPElement) soapDocument.find(eachChild);
638 if (eachChildSoap != null) {
639 if (eachChildSoap.getElementName().equals(name)) {
640 return eachChildSoap;
641 }
642 }
643 }
644 eachChild = eachChild.getNextSibling();
645 }
646 return null;
647 }
648
649 protected SOAPElement findAndConvertChildElement(NameImpl name) {
650 Iterator<Node> eachChild = getChildElementNodes();
651 while (eachChild.hasNext()) {
652 SOAPElement child = (SOAPElement) eachChild.next();
653 if (child.getElementName().equals(name)) {
654 return child;
655 }
656 }
657
861 }
862
863 public boolean removeNamespaceDeclaration(String prefix) {
864 org.w3c.dom.Attr declaration = getNamespaceAttr(prefix);
865 if (declaration == null) {
866 return false;
867 }
868 try {
869 removeAttributeNode(declaration);
870 } catch (DOMException de) {
871 // ignore
872 }
873 return true;
874 }
875
876 public Iterator<Node> getChildElements() {
877 return getChildElementsFrom(this);
878 }
879
880 protected SOAPElement convertToSoapElement(Element element) {
881 final Node soapNode = soapDocument.findIfPresent(element);
882 if (soapNode instanceof SOAPElement) {
883 return (SOAPElement) soapNode;
884 } else {
885 return replaceElementWithSOAPElement(
886 element,
887 (ElementImpl) createElement(NameImpl.copyElementName(element)));
888 }
889 }
890
891 protected SOAPElement replaceElementWithSOAPElement(
892 Element element,
893 ElementImpl copy) {
894
895 Iterator<Name> eachAttribute = getAllAttributesFrom(element);
896 while (eachAttribute.hasNext()) {
897 Name name = eachAttribute.next();
898 copy.addAttributeBare(name, getAttributeValueFrom(element, name));
899 }
900
901 Iterator<Node> eachChild = getChildElementsFrom(element);
902 while (eachChild.hasNext()) {
903 Node nextChild = eachChild.next();
904 copy.insertBefore(nextChild, null);
905 }
906
907 Node parent = soapDocument.find(element.getParentNode());
908 if (parent != null) {
909 parent.replaceChild(copy, element);
910 } // XXX else throw an exception?
911
912 return copy;
913 }
914
915 protected Iterator<Node> getChildElementNodes() {
916 return new Iterator<Node>() {
917 Iterator<Node> eachNode = getChildElements();
918 Node next = null;
919 Node last = null;
920
921 public boolean hasNext() {
922 if (next == null) {
923 while (eachNode.hasNext()) {
924 Node node = eachNode.next();
925 if (node instanceof Element) {
926 next = soapDocument.findIfPresent(node);
927 break;
928 }
929 }
930 }
931 return next != null;
932 }
933
934 public Node next() {
935 if (hasNext()) {
936 last = next;
937 next = null;
938 return last;
939 }
940 throw new NoSuchElementException();
941 }
942
943 public void remove() {
944 if (last == null) {
945 throw new IllegalStateException();
946 }
1084 return node;
1085 } else {
1086 log.severe("SAAJ0107.impl.elem.child.not.single.text");
1087 throw new IllegalStateException();
1088 }
1089 }
1090
1091 return null;
1092 }
1093
1094 protected javax.xml.soap.Node getValueNode() {
1095 Iterator<Node> i = getChildElements();
1096 while (i.hasNext()) {
1097 Node n = i.next();
1098 if (n.getNodeType() == org.w3c.dom.Node.TEXT_NODE ||
1099 n.getNodeType() == org.w3c.dom.Node.CDATA_SECTION_NODE) {
1100 // TODO: Hack to fix text node split into multiple lines.
1101 normalize();
1102 // Should remove the normalization step when this gets fixed in
1103 // DOM/Xerces.
1104 return soapDocument.find(n);
1105 }
1106 }
1107 return null;
1108 }
1109
1110 public void setParentElement(SOAPElement element) throws SOAPException {
1111 if (element == null) {
1112 log.severe("SAAJ0106.impl.no.null.to.parent.elem");
1113 throw new SOAPException("Cannot pass NULL to setParentElement");
1114 }
1115 element.addChildElement(this);
1116 findEncodingStyleAttributeName();
1117 }
1118
1119 protected void findEncodingStyleAttributeName() throws SOAPException {
1120 String soapNamespace = getSOAPNamespace();
1121 if (soapNamespace != null) {
1122 String soapNamespacePrefix = getNamespacePrefix(soapNamespace);
1123 if (soapNamespacePrefix != null) {
1124 setEncodingStyleNamespace(soapNamespace, soapNamespacePrefix);
1126 }
1127 }
1128
1129 protected void setEncodingStyleNamespace(
1130 String soapNamespace,
1131 String soapNamespacePrefix)
1132 throws SOAPException {
1133 Name encodingStyleAttributeName =
1134 NameImpl.create(
1135 "encodingStyle",
1136 soapNamespacePrefix,
1137 soapNamespace);
1138 encodingStyleAttribute.setName(encodingStyleAttributeName);
1139 }
1140
1141 public SOAPElement getParentElement() {
1142 Node parentNode = getParentNode();
1143 if (parentNode instanceof SOAPDocument) {
1144 return null;
1145 }
1146 return (SOAPElement) soapDocument.find(parentNode);
1147 }
1148
1149 protected String getSOAPNamespace() {
1150 String soapNamespace = null;
1151
1152 SOAPElement antecedent = this;
1153 while (antecedent != null) {
1154 Name antecedentName = antecedent.getElementName();
1155 String antecedentNamespace = antecedentName.getURI();
1156
1157 if (NameImpl.SOAP11_NAMESPACE.equals(antecedentNamespace)
1158 || NameImpl.SOAP12_NAMESPACE.equals(antecedentNamespace)) {
1159
1160 soapNamespace = antecedentNamespace;
1161 break;
1162 }
1163
1164 antecedent = antecedent.getParentElement();
1165 }
1166
1319 return null;
1320 }
1321
1322 String attrValue =
1323 element.getAttributeNS(nonzeroLengthUri, localName);
1324
1325 return attrValue;
1326 }
1327
1328 Attr attribute = null;
1329 attribute = element.getAttributeNode(qualifiedName);
1330
1331 return attribute == null ? null : attribute.getValue();
1332 }
1333
1334 protected Iterator<Node> getChildElementsFrom(final Element element) {
1335 return new Iterator<Node>() {
1336 Node next = element.getFirstChild();
1337 Node nextNext = null;
1338 Node last = null;
1339 Node soapElement = soapDocument.findIfPresent(element);
1340
1341 public boolean hasNext() {
1342 if (next != null) {
1343 return true;
1344 }
1345 if (nextNext != null) {
1346 next = nextNext;
1347 }
1348
1349 return next != null;
1350 }
1351
1352 public Node next() {
1353 if (hasNext()) {
1354 last = next;
1355 next = null;
1356
1357 if ((soapElement instanceof ElementImpl)
1358 && (last instanceof Element)) {
1359 last =
1360 ((ElementImpl) soapElement).convertToSoapElement(
1361 (Element) last);
1362 }
1363
1364 nextNext = last.getNextSibling();
1365 return soapDocument.findIfPresent(last);
1366 }
1367 throw new NoSuchElementException();
1368 }
1369
1370 public void remove() {
1371 if (last == null) {
1372 throw new IllegalStateException();
1373 }
1374 Node target = last;
1375 last = null;
1376 element.removeChild(target);
1377 }
1378 };
1379 }
1380
1381 public static String getQualifiedName(QName name) {
1382 String prefix = name.getPrefix();
1383 String localName = name.getLocalPart();
1384 String qualifiedName = null;
1385
1466
1467 }
1468
1469 @Override
1470 public void removeAttributeNS(String namespaceURI, String localName) throws DOMException {
1471 element.removeAttributeNS(namespaceURI, localName);
1472 }
1473
1474 @Override
1475 public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException {
1476 return element.getAttributeNodeNS(namespaceURI, localName);
1477 }
1478
1479 @Override
1480 public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {
1481 return element.setAttributeNodeNS(newAttr);
1482 }
1483
1484 @Override
1485 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException {
1486 return new NodeListImpl(soapDocument, element.getElementsByTagNameNS(namespaceURI, localName));
1487 }
1488
1489 @Override
1490 public boolean hasAttribute(String name) {
1491 return element.hasAttribute(name);
1492 }
1493
1494 @Override
1495 public boolean hasAttributeNS(String namespaceURI, String localName) throws DOMException {
1496 return element.hasAttributeNS(namespaceURI, localName);
1497 }
1498
1499 @Override
1500 public TypeInfo getSchemaTypeInfo() {
1501 return element.getSchemaTypeInfo();
1502 }
1503
1504 @Override
1505 public void setIdAttribute(String name, boolean isId) throws DOMException {
1506 element.setIdAttribute(name, isId);
1521 return element.getNodeName();
1522 }
1523
1524 @Override
1525 public String getNodeValue() throws DOMException {
1526 return element.getNodeValue();
1527 }
1528
1529 @Override
1530 public void setNodeValue(String nodeValue) throws DOMException {
1531 element.setNodeValue(nodeValue);
1532 }
1533
1534 @Override
1535 public short getNodeType() {
1536 return element.getNodeType();
1537 }
1538
1539 @Override
1540 public Node getParentNode() {
1541 return soapDocument.find(element.getParentNode());
1542 }
1543
1544 @Override
1545 public NodeList getChildNodes() {
1546 return new NodeListImpl(soapDocument, element.getChildNodes());
1547 }
1548
1549 @Override
1550 public Node getFirstChild() {
1551 return soapDocument.findIfPresent(element.getFirstChild());
1552 }
1553
1554 @Override
1555 public Node getLastChild() {
1556 return soapDocument.findIfPresent(element.getLastChild());
1557 }
1558
1559 @Override
1560 public Node getPreviousSibling() {
1561 return soapDocument.findIfPresent(element.getPreviousSibling());
1562 }
1563
1564 @Override
1565 public Node getNextSibling() {
1566 return soapDocument.findIfPresent(element.getNextSibling());
1567 }
1568
1569 @Override
1570 public NamedNodeMap getAttributes() {
1571 return new NamedNodeMapImpl(element.getAttributes(), soapDocument);
1572 }
1573
1574 public Element getDomElement() {
1575 return element;
1576 }
1577
1578 public SOAPDocumentImpl getSoapDocument() {
1579 return soapDocument;
1580 }
1581 }
|