001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * $Id: DetailImpl.java,v 1.3 2007/08/23 10:54:47 kumarjayanti Exp $
022: * $Revision: 1.3 $
023: * $Date: 2007/08/23 10:54:47 $
024: */
025:
026: package com.sun.xml.messaging.saaj.soap.impl;
027:
028: import java.util.Iterator;
029: import java.util.NoSuchElementException;
030:
031: import javax.xml.namespace.QName;
032: import javax.xml.soap.*;
033:
034: import org.w3c.dom.Element;
035:
036: import com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl;
037: import com.sun.xml.messaging.saaj.soap.name.NameImpl;
038:
039: public abstract class DetailImpl extends FaultElementImpl implements
040: Detail {
041: public DetailImpl(SOAPDocumentImpl ownerDoc, NameImpl detailName) {
042: super (ownerDoc, detailName);
043: }
044:
045: protected abstract DetailEntry createDetailEntry(Name name);
046:
047: protected abstract DetailEntry createDetailEntry(QName name);
048:
049: public DetailEntry addDetailEntry(Name name) throws SOAPException {
050: DetailEntry entry = createDetailEntry(name);
051: addNode(entry);
052: return (DetailEntry) circumventBug5034339(entry);
053: }
054:
055: public DetailEntry addDetailEntry(QName qname) throws SOAPException {
056: DetailEntry entry = createDetailEntry(qname);
057: addNode(entry);
058: return (DetailEntry) circumventBug5034339(entry);
059: }
060:
061: protected SOAPElement addElement(Name name) throws SOAPException {
062: return addDetailEntry(name);
063: }
064:
065: protected SOAPElement addElement(QName name) throws SOAPException {
066: return addDetailEntry(name);
067: }
068:
069: protected SOAPElement convertToSoapElement(Element element) {
070: if (element instanceof DetailEntry) {
071: return (SOAPElement) element;
072: } else {
073: DetailEntry detailEntry = createDetailEntry(NameImpl
074: .copyElementName(element));
075: return replaceElementWithSOAPElement(element,
076: (ElementImpl) detailEntry);
077: }
078: }
079:
080: public Iterator getDetailEntries() {
081: return new Iterator() {
082: Iterator eachNode = getChildElementNodes();
083: SOAPElement next = null;
084: SOAPElement last = null;
085:
086: public boolean hasNext() {
087: if (next == null) {
088: while (eachNode.hasNext()) {
089: next = (SOAPElement) eachNode.next();
090: if (next instanceof DetailEntry) {
091: break;
092: }
093: next = null;
094: }
095: }
096: return next != null;
097: }
098:
099: public Object next() {
100: if (!hasNext()) {
101: throw new NoSuchElementException();
102: }
103: last = next;
104: next = null;
105: return last;
106: }
107:
108: public void remove() {
109: if (last == null) {
110: throw new IllegalStateException();
111: }
112: SOAPElement target = last;
113: removeChild(target);
114: last = null;
115: }
116: };
117: }
118:
119: protected boolean isStandardFaultElement() {
120: return true;
121: }
122:
123: //overriding this method since the only two uses of this method
124: // are in ElementImpl and DetailImpl
125: //whereas the original base impl does the correct job for calls to it inside ElementImpl
126: // But it would not work for DetailImpl.
127: protected SOAPElement circumventBug5034339(SOAPElement element) {
128:
129: Name elementName = element.getElementName();
130: if (!isNamespaceQualified(elementName)) {
131: String prefix = elementName.getPrefix();
132: String defaultNamespace = getNamespaceURI(prefix);
133: if (defaultNamespace != null) {
134: Name newElementName = NameImpl.create(elementName
135: .getLocalName(), elementName.getPrefix(),
136: defaultNamespace);
137: SOAPElement newElement = createDetailEntry(newElementName);
138: replaceChild(newElement, element);
139: return newElement;
140: }
141: }
142: return element;
143: }
144:
145: }
|