aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.xml.internal.messaging.saaj.soap.impl; aoqi@0: aoqi@0: import java.util.Iterator; aoqi@0: import java.util.NoSuchElementException; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.soap.*; aoqi@0: aoqi@0: import org.w3c.dom.Element; aoqi@0: aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; aoqi@0: aoqi@0: public abstract class DetailImpl extends FaultElementImpl implements Detail { aoqi@0: public DetailImpl(SOAPDocumentImpl ownerDoc, NameImpl detailName) { aoqi@0: super(ownerDoc, detailName); aoqi@0: } aoqi@0: aoqi@0: protected abstract DetailEntry createDetailEntry(Name name); aoqi@0: protected abstract DetailEntry createDetailEntry(QName name); aoqi@0: aoqi@0: public DetailEntry addDetailEntry(Name name) throws SOAPException { aoqi@0: DetailEntry entry = createDetailEntry(name); aoqi@0: addNode(entry); aoqi@0: return (DetailEntry) circumventBug5034339(entry); aoqi@0: } aoqi@0: aoqi@0: public DetailEntry addDetailEntry(QName qname) throws SOAPException { aoqi@0: DetailEntry entry = createDetailEntry(qname); aoqi@0: addNode(entry); aoqi@0: return (DetailEntry) circumventBug5034339(entry); aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement addElement(Name name) throws SOAPException { aoqi@0: return addDetailEntry(name); aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement addElement(QName name) throws SOAPException { aoqi@0: return addDetailEntry(name); aoqi@0: } aoqi@0: aoqi@0: protected SOAPElement convertToSoapElement(Element element) { aoqi@0: if (element instanceof DetailEntry) { aoqi@0: return (SOAPElement) element; aoqi@0: } else { aoqi@0: DetailEntry detailEntry = aoqi@0: createDetailEntry(NameImpl.copyElementName(element)); aoqi@0: return replaceElementWithSOAPElement( aoqi@0: element, aoqi@0: (ElementImpl) detailEntry); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public Iterator getDetailEntries() { aoqi@0: return new Iterator() { aoqi@0: Iterator eachNode = getChildElementNodes(); aoqi@0: SOAPElement next = null; aoqi@0: SOAPElement last = null; aoqi@0: aoqi@0: public boolean hasNext() { aoqi@0: if (next == null) { aoqi@0: while (eachNode.hasNext()) { aoqi@0: next = (SOAPElement) eachNode.next(); aoqi@0: if (next instanceof DetailEntry) { aoqi@0: break; aoqi@0: } aoqi@0: next = null; aoqi@0: } aoqi@0: } aoqi@0: return next != null; aoqi@0: } aoqi@0: aoqi@0: public Object next() { aoqi@0: if (!hasNext()) { aoqi@0: throw new NoSuchElementException(); aoqi@0: } aoqi@0: last = next; aoqi@0: next = null; aoqi@0: return last; aoqi@0: } aoqi@0: aoqi@0: public void remove() { aoqi@0: if (last == null) { aoqi@0: throw new IllegalStateException(); aoqi@0: } aoqi@0: SOAPElement target = last; aoqi@0: removeChild(target); aoqi@0: last = null; aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: protected boolean isStandardFaultElement() { aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: //overriding this method since the only two uses of this method aoqi@0: // are in ElementImpl and DetailImpl aoqi@0: //whereas the original base impl does the correct job for calls to it inside ElementImpl aoqi@0: // But it would not work for DetailImpl. aoqi@0: protected SOAPElement circumventBug5034339(SOAPElement element) { aoqi@0: aoqi@0: Name elementName = element.getElementName(); aoqi@0: if (!isNamespaceQualified(elementName)) { aoqi@0: String prefix = elementName.getPrefix(); aoqi@0: String defaultNamespace = getNamespaceURI(prefix); aoqi@0: if (defaultNamespace != null) { aoqi@0: Name newElementName = aoqi@0: NameImpl.create( aoqi@0: elementName.getLocalName(), aoqi@0: elementName.getPrefix(), aoqi@0: defaultNamespace); aoqi@0: SOAPElement newElement = createDetailEntry(newElementName); aoqi@0: replaceChild(newElement, element); aoqi@0: return newElement; aoqi@0: } aoqi@0: } aoqi@0: return element; aoqi@0: } aoqi@0: aoqi@0: }