001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.saaj;
020:
021: import org.apache.axiom.om.impl.dom.ElementImpl;
022: import org.apache.axiom.soap.SOAPFaultDetail;
023:
024: import javax.xml.namespace.QName;
025: import javax.xml.soap.Detail;
026: import javax.xml.soap.DetailEntry;
027: import javax.xml.soap.Name;
028: import javax.xml.soap.SOAPElement;
029: import javax.xml.soap.SOAPException;
030: import java.util.ArrayList;
031: import java.util.Collection;
032: import java.util.Iterator;
033:
034: /**
035: * A container for <code>DetailEntry</code> objects. <code>DetailEntry</code> objects give detailed
036: * error information that is application-specific and related to the <code>SOAPBody</code> object
037: * that contains it.
038: * <p/>
039: * A <code>Detail</code> object, which is part of a <code>SOAPFault</code> object, can be retrieved
040: * using the method <code>SOAPFault.getDetail</code>. The <code>Detail</code> interface provides two
041: * methods. One creates a new <code>DetailEntry</code> object and also automatically adds it to the
042: * <code>Detail</code> object. The second method gets a list of the <code>DetailEntry</code> objects
043: * contained in a <code>Detail</code> object.
044: * <p/>
045: * The following code fragment, in which <i>sf</i> is a <code>SOAPFault</code> object, gets its
046: * <code>Detail</code> object (<i>d</i>), adds a new <code>DetailEntry</code> object to <i>d</i>,
047: * and then gets a list of all the <code>DetailEntry</code> objects in <i>d</i>. The code also
048: * creates a <code>Name</code> object to pass to the method <code>addDetailEntry</code>. The
049: * variable <i>se</i>, used to create the <code>Name</code> object, is a <code>SOAPEnvelope</code>
050: * object. <PRE> Detail d = sf.getDetail(); Name name = se.createName("GetLastTradePrice", "WOMBAT",
051: * "http://www.wombat.org/trader"); d.addDetailEntry(name); Iterator it = d.getDetailEntries();
052: * </PRE>
053: */
054: public class DetailImpl extends SOAPFaultElementImpl implements Detail {
055:
056: // private SOAPFaultDetail faultDetail;
057:
058: /** @param element */
059: public DetailImpl(SOAPFaultDetail element) {
060: super ((ElementImpl) element);
061: // faultDetail = element;
062: }
063:
064: /**
065: * Creates a new <code>DetailEntry</code> object with the given name and adds it to this
066: * <code>Detail</code> object.
067: *
068: * @param name a <code>Name</code> object identifying the new <code>DetailEntry</code> object
069: * @return DetailEntry.
070: * @throws SOAPException thrown when there is a problem in adding a DetailEntry object to this
071: * Detail object.
072: */
073: public DetailEntry addDetailEntry(Name name) throws SOAPException {
074: SOAPElementImpl childElement = (SOAPElementImpl) addChildElement(name);
075: DetailEntryImpl detailEntry = new DetailEntryImpl(
076: childElement.element);
077: childElement.element.setUserData(SAAJ_NODE, detailEntry, null);
078: return detailEntry;
079: }
080:
081: /**
082: * Gets a list of the detail entries in this <code>Detail</code> object.
083: *
084: * @return an <code>Iterator</code> object over the <code>DetailEntry</code> objects in this
085: * <code>Detail</code> object
086: */
087: public Iterator getDetailEntries() {
088: final Iterator detailEntriesIter = element.getChildElements();
089: Collection details = new ArrayList();
090: while (detailEntriesIter.hasNext()) {
091: details.add(new DetailEntryImpl(
092: (ElementImpl) detailEntriesIter.next()));
093: }
094: return details.iterator();
095: }
096:
097: /**
098: * Creates a new DetailEntry object with the given name and adds it to this Detail object.
099: *
100: * @param name - a Name object identifying the new DetailEntry object
101: * @throws SOAPException - thrown when there is a problem in adding a DetailEntry object to this
102: * Detail object.
103: */
104: public DetailEntry addDetailEntry(QName qname) throws SOAPException {
105: SOAPElementImpl childElement = (SOAPElementImpl) addChildElement(qname);
106: DetailEntryImpl detailEntry = new DetailEntryImpl(
107: childElement.element);
108: childElement.element.setUserData(SAAJ_NODE, detailEntry, null);
109: return detailEntry;
110: }
111:
112: public SOAPElement addAttribute(QName qname, String value)
113: throws SOAPException {
114: return super .addAttribute(qname, value);
115: }
116:
117: public SOAPElement addChildElement(QName qname)
118: throws SOAPException {
119: return super .addChildElement(qname);
120: }
121:
122: public QName createQName(String localName, String prefix)
123: throws SOAPException {
124: return super .createQName(localName, prefix);
125: }
126:
127: public Iterator getAllAttributesAsQNames() {
128: return super .getAllAttributesAsQNames();
129: }
130:
131: public String getAttributeValue(QName qname) {
132: return super .getAttributeValue(qname);
133: }
134:
135: public Iterator getChildElements(QName qname) {
136: return super .getChildElements(qname);
137: }
138:
139: public QName getElementQName() {
140: return super .getElementQName();
141: }
142:
143: public boolean removeAttribute(QName qname) {
144: return super .removeAttribute(qname);
145: }
146:
147: public SOAPElement setElementQName(QName newName)
148: throws SOAPException {
149: return super.setElementQName(newName);
150: }
151: }
|