001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xml.saaj;
031:
032: import javax.xml.namespace.*;
033: import javax.xml.soap.*;
034: import java.util.*;
035:
036: import com.caucho.util.L10N;
037:
038: /**
039: *
040: **/
041: public class SOAP11FaultImpl extends SOAPBodyElementImpl implements
042: SOAPFault {
043: private static final L10N L = new L10N(SOAP11FaultImpl.class);
044:
045: private static final NameImpl SOAP_1_1_FAULT_NAME = new NameImpl(
046: SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "Fault",
047: SOAPConstants.SOAP_ENV_PREFIX);
048:
049: private static final Name FAULT_CODE = new NameImpl("faultcode");
050: private static final Name FAULT_STRING = new NameImpl("faultstring");
051: private static final Name FAULT_ACTOR = new NameImpl("faultactor");
052:
053: protected Detail _detail;
054: protected SOAPElement _faultActor;
055: protected SOAPElement _faultCode;
056: protected SOAPElement _faultString;
057: protected Locale _faultLocale;
058:
059: SOAP11FaultImpl(SOAPFactory factory) throws SOAPException {
060: this (factory, SOAP_1_1_FAULT_NAME);
061: }
062:
063: SOAP11FaultImpl(SOAPFactory factory, NameImpl name)
064: throws SOAPException {
065: super (factory, name);
066: /*
067:
068: _faultCode = _factory.createElement(FAULT_CODE);
069: _faultString = _factory.createElement(FAULT_STRING);
070:
071: addChildElement(_faultCode);
072: addChildElement(_faultString);*/
073: }
074:
075: public SOAPElement addChildElement(SOAPElement element)
076: throws SOAPException {
077: if (FAULT_CODE.getLocalName().equals(element.getLocalName())
078: && element.getNamespaceURI() == null
079: || "".equals(element.getNamespaceURI())) {
080: _faultCode = element;
081: } else if (FAULT_STRING.getLocalName().equals(
082: element.getLocalName())
083: && element.getNamespaceURI() == null
084: || "".equals(element.getNamespaceURI())) {
085: _faultString = element;
086: }
087:
088: return super .addChildElement(element);
089: }
090:
091: // Detail
092:
093: public Detail addDetail() throws SOAPException {
094: if (_detail != null)
095: throw new SOAPException(
096: "Fault already contains a valid Detail");
097:
098: _detail = new SOAP11DetailImpl(_factory);
099:
100: return _detail;
101: }
102:
103: public Detail getDetail() {
104: return _detail;
105: }
106:
107: public boolean hasDetail() {
108: return _detail != null;
109: }
110:
111: // reason
112:
113: public void addFaultReasonText(String text, Locale locale)
114: throws SOAPException {
115: throw new UnsupportedOperationException(
116: "Fault reasons unsupported in SOAP 1.1");
117: }
118:
119: public Iterator getFaultReasonLocales() throws SOAPException {
120: throw new UnsupportedOperationException(
121: "Fault reasons unsupported in SOAP 1.1");
122: }
123:
124: public String getFaultReasonText(Locale locale)
125: throws SOAPException {
126: throw new UnsupportedOperationException(
127: "Fault reasons unsupported in SOAP 1.1");
128: }
129:
130: public Iterator getFaultReasonTexts() throws SOAPException {
131: throw new UnsupportedOperationException(
132: "Fault reasons unsupported in SOAP 1.1");
133: }
134:
135: // subcode
136:
137: public void appendFaultSubcode(QName subcode) throws SOAPException {
138: throw new UnsupportedOperationException(
139: "Subcodes unsupported in SOAP 1.1");
140: }
141:
142: public Iterator getFaultSubcodes() {
143: throw new UnsupportedOperationException(
144: "Subcodes unsupported in SOAP 1.1");
145: }
146:
147: public void removeAllFaultSubcodes() {
148: throw new UnsupportedOperationException(
149: "Subcodes unsupported in SOAP 1.1");
150: }
151:
152: // actor
153:
154: public void setFaultActor(String faultActor) throws SOAPException {
155: if (_faultActor == null) {
156: _faultActor = _factory.createElement(FAULT_ACTOR);
157: addChildElement(_faultActor);
158: }
159:
160: _faultActor.setValue(faultActor);
161: }
162:
163: public String getFaultActor() {
164: if (_faultActor == null)
165: return null;
166:
167: return _faultActor.getValue();
168: }
169:
170: // faultcode
171:
172: public String getFaultCode() {
173: if (_faultCode == null)
174: return null;
175:
176: return _faultCode.getValue();
177: }
178:
179: public Name getFaultCodeAsName() {
180: String faultcode = getFaultCode();
181:
182: if (_faultCode == null)
183: return null;
184:
185: int colon = faultcode.indexOf(':');
186:
187: if (colon >= 0) {
188: String prefix = faultcode.substring(0, colon);
189: String localName = faultcode.substring(colon + 1);
190: String uri = _faultCode.getNamespaceURI(prefix);
191:
192: return new NameImpl(uri, localName, prefix);
193: }
194:
195: return new NameImpl(faultcode);
196: }
197:
198: public QName getFaultCodeAsQName() {
199: return (NameImpl) getFaultCodeAsName();
200: }
201:
202: public void setFaultCode(Name faultCodeName) throws SOAPException {
203: if (faultCodeName.getPrefix() == null
204: || "".equals(faultCodeName.getPrefix()))
205: throw new SOAPException(
206: L
207: .l(
208: "Fault codes must have qualified names. Name given: {0}",
209: faultCodeName));
210:
211: if (_faultCode == null) {
212: _faultCode = _factory.createElement(FAULT_CODE);
213: addChildElement(_faultCode);
214: }
215:
216: if (getNamespaceURI(faultCodeName.getPrefix()) == null) {
217: _faultCode.addNamespaceDeclaration(faultCodeName
218: .getPrefix(), faultCodeName.getURI());
219: }
220:
221: _faultCode.setValue(faultCodeName.getQualifiedName());
222: }
223:
224: public void setFaultCode(QName faultCodeQName) throws SOAPException {
225: setFaultCode((Name) NameImpl.fromQName(faultCodeQName));
226: }
227:
228: public void setFaultCode(String faultCode) throws SOAPException {
229: /* XXX Should we check for a QName here?
230: if (faultCode.indexOf(':') < 0)
231: throw new SOAPException(L.l("Fault codes must have qualified names. Name given: {0}", faultCode));
232: */
233: if (_faultCode == null) {
234: _faultCode = _factory.createElement(FAULT_CODE);
235: addChildElement(_faultCode);
236: }
237:
238: _faultCode.setValue(faultCode);
239: }
240:
241: // faultstring
242:
243: public String getFaultString() {
244: if (_faultString == null)
245: return null;
246:
247: return _faultString.getValue();
248: }
249:
250: public void setFaultString(String faultString) throws SOAPException {
251: if (_faultString == null) {
252: _faultString = _factory.createElement(FAULT_STRING);
253: addChildElement(_faultString);
254: }
255:
256: _faultString.setValue(faultString);
257: }
258:
259: public void setFaultString(String faultString, Locale locale)
260: throws SOAPException {
261: if (_faultString == null) {
262: _faultString = _factory.createElement(FAULT_STRING);
263: addChildElement(_faultString);
264: }
265:
266: _faultString.setValue(faultString);
267: _faultLocale = locale;
268: }
269:
270: public Locale getFaultStringLocale() {
271: return _faultLocale;
272: }
273:
274: // faultnode
275:
276: public String getFaultNode() {
277: throw new UnsupportedOperationException(
278: "Fault nodes unsupported in SOAP 1.1");
279: }
280:
281: public void setFaultNode(String uri) throws SOAPException {
282: throw new UnsupportedOperationException(
283: "Fault nodes unsupported in SOAP 1.1");
284: }
285:
286: // faultrole
287:
288: public String getFaultRole() {
289: throw new UnsupportedOperationException(
290: "Fault role unsupported in SOAP 1.1");
291: }
292:
293: public void setFaultRole(String uri) throws SOAPException {
294: throw new UnsupportedOperationException(
295: "Fault role unsupported in SOAP 1.1");
296: }
297: }
|