soapfaultimpl.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 809 行 · 第 1/3 页
JAVA
809 行
new QName(faultCodeName.getURI(), faultCodeName.getLocalName(), faultCodeName.getPrefix());
setFaultCode(faultCodeQName);
}
/* (non-Javadoc)
* @see javax.xml.soap.SOAPFault#addDetail()
*/
public Detail addDetail() throws SOAPException {
if (isDetailAdded) {
throw new SOAPException("This SOAPFault already contains a Detail element. " +
"Please remove the existing Detail element before " +
"calling addDetail()");
}
SOAPFaultDetail omDetail;
SOAPFactory factory = (SOAPFactory)this.element.getOMFactory();
if (factory instanceof SOAP11Factory) {
omDetail = new SOAP11FaultDetailImpl(this.fault,
factory);
} else {
omDetail = new SOAP12FaultDetailImpl(this.fault,
factory);
}
Detail saajDetail = new DetailImpl(omDetail);
((NodeImpl)fault.getDetail()).setUserData(SAAJ_NODE, saajDetail, null);
isDetailAdded = true;
return saajDetail;
}
/* (non-Javadoc)
* @see javax.xml.soap.SOAPFault#getFaultCodeAsName()
*/
public Name getFaultCodeAsName() {
return new PrefixedQName(getFaultCodeAsQName());
}
/**
* Sets the fault string for this SOAPFault object to the given string. If this SOAPFault is
* part of a message that supports SOAP 1.2 then this call is equivalent to:
* addFaultReasonText(faultString, Locale.getDefault());
*
* @param faultString - a String giving an explanation of the fault
* @throws SOAPException - if there was an error in adding the faultString to the underlying XML
* tree.
* @see getFaultString()
*/
public void setFaultString(String faultString, Locale locale) throws SOAPException {
if (this.fault.getReason() != null) {
SOAPFaultReason reason = this.fault.getReason();
if (this.element.getOMFactory() instanceof SOAP11Factory) {
reason.setText(faultString);
} else if (this.element.getOMFactory() instanceof SOAP12Factory) {
addFaultReasonText(faultString, locale);
}
} else {
if (this.element.getOMFactory() instanceof SOAP11Factory) {
SOAPFaultReason reason = new SOAP11FaultReasonImpl(this.fault,
(SOAPFactory)this.element
.getOMFactory());
reason.setText(faultString);
} else if (this.element.getOMFactory() instanceof SOAP12Factory) {
addFaultReasonText(faultString, locale);
}
}
this.faultReasonLocale = locale;
}
/**
* Gets the locale of the fault string for this SOAPFault object. If this SOAPFault is part of a
* message that supports SOAP 1.2 then this call is equivalent to:
* <p/>
* Locale locale = null; try { locale = (Locale) getFaultReasonLocales().next(); } catch
* (SOAPException e) {} return locale;
*
* @return a Locale object indicating the native language of the fault string or null if no
* locale was specified
* @see setFaultString(String, Locale)
* @since SAAJ 1.2
*/
public Locale getFaultStringLocale() {
if (this.element.getOMFactory() instanceof SOAP11Factory) {
return this.faultReasonLocale;
} else if (this.element.getOMFactory() instanceof SOAP12Factory) {
Locale locale = null;
try {
if (getFaultReasonLocales().hasNext()) {
locale = (Locale)getFaultReasonLocales().next();
}
}
catch (SOAPException e) {
e.printStackTrace();
}
return locale;
} else {
return null;
}
}
/**
* Appends or replaces a Reason Text item containing the specified text message and an xml:lang
* derived from locale. If a Reason Text item with this xml:lang already exists its text value
* will be replaced with text. The locale parameter should not be null Code sample: SOAPFault
* fault = ...; fault.addFaultReasonText(Version Mismatch, Locale.ENGLISH);
*
* @param text - reason message string locale - Locale object representing the locale of the
* message
* @throws SOAPException - if there was an error in adding the Reason text or the locale passed
* was null. java.lang.UnsupportedOperationException - if this message
* does not support the SOAP 1.2 concept of Fault Reason.
*/
public void addFaultReasonText(String text, Locale locale) throws SOAPException {
if (locale == null) {
throw new SOAPException("Received null for locale");
}
if (this.element.getOMFactory() instanceof SOAP11Factory) {
throw new UnsupportedOperationException("Not supported in SOAP 1.1");
} else if (this.element.getOMFactory() instanceof SOAP12Factory) {
removeDefaults();
String existingReasonText = getFaultReasonText(locale);
if (existingReasonText == null) {
org.apache.axiom.soap.SOAPFactory soapFactory = null;
soapFactory = (SOAP12Factory)this.element.getOMFactory();
if (this.fault.getReason() == null) {
SOAPFaultReason soapFaultReason = soapFactory.createSOAPFaultReason(this.fault);
this.fault.setReason(soapFaultReason);
}
SOAPFaultText soapFaultText =
soapFactory.createSOAPFaultText(this.fault.getReason());
soapFaultText.setText(text);
soapFaultText.setLang(locale.toString());
} else {
//update the text
Iterator soapTextsItr = this.fault.getReason().getAllSoapTexts().iterator();
while (soapTextsItr.hasNext()) {
SOAPFaultText soapFaultText = (SOAPFaultText)soapTextsItr.next();
if (soapFaultText.getLang().equals(locale.toString())) {
soapFaultText.setText(text);
}
}
}
}
}
/**
* Adds a Subcode to the end of the sequence of Subcodes contained by this SOAPFault. Subcodes,
* which were introduced in SOAP 1.2, are represented by a recursive sequence of subelements
* rooted in the mandatory Code subelement of a SOAP Fault.
*
* @param subcode - a QName containing the Value of the Subcode.
* @throws SOAPException - if there was an error in setting the Subcode java.lang.UnsupportedOperationException
* - if this message does not support the SOAP 1.2 concept of Subcode.
*/
public void appendFaultSubcode(QName subcode) throws SOAPException {
org.apache.axiom.soap.SOAPFactory soapFactory = null;
SOAPFaultSubCode soapFaultSubCode = null;
if (subcode.getNamespaceURI() == null || subcode.getNamespaceURI().trim().length() == 0) {
throw new SOAPException("Unqualified QName object : " + subcode);
}
if (this.element.getOMFactory() instanceof SOAP11Factory) {
throw new UnsupportedOperationException();
} else if (this.element.getOMFactory() instanceof SOAP12Factory) {
soapFactory = DOOMAbstractFactory.getSOAP12Factory();
}
if (this.fault.getCode() == null) {
soapFactory.createSOAPFaultCode(this.fault);
//if SOAPFault is null, there cannot be a subcode.
//Hence should create one
soapFaultSubCode = soapFactory.createSOAPFaultSubCode(this.fault.getCode());
} else if (this.fault.getCode().getSubCode() != null) {
//find the last subcode.parent of the new subcode should be the this last subcode
soapFaultSubCode = soapFactory.createSOAPFaultSubCode(
getLastSubCode(this.fault.getCode().getSubCode()));
} else {
//FaultCode is there, but no FaultSubCode
soapFaultSubCode = soapFactory.createSOAPFaultSubCode(this.fault.getCode());
}
if (soapFaultSubCode != null) {
SOAPFaultValueImpl soapFaultValueimpl =
new SOAP12FaultValueImpl(soapFaultSubCode, soapFactory);
soapFaultValueimpl.setText(subcode.getPrefix() + ":" + subcode.getLocalPart());
soapFaultValueimpl.declareNamespace(subcode.getNamespaceURI(), subcode.getPrefix());
}
}
private SOAPFaultSubCode getLastSubCode(SOAPFaultSubCode firstSubCodeElement) {
SOAPFaultSubCode soapFaultSubCode = firstSubCodeElement.getSubCode();
if (soapFaultSubCode != null) {
return getLastSubCode(soapFaultSubCode);
}
return firstSubCodeElement;
}
/**
* Gets the fault code for this SOAPFault object as a <CODE>QName</CODE> object.
* <p/>
*/
public QName getFaultCodeAsQName() {
SOAPFaultCode soapFaultCode = this.fault.getCode();
if (soapFaultCode != null) {
if (this.element.getOMFactory() instanceof SOAP11Factory) {
return soapFaultCode.getTextAsQName();
} else {
return soapFaultCode.getValue().getTextAsQName();
}
}
return null;
}
/**
* Returns the optional Node element value for this SOAPFault object. The Node element is
* optional in SOAP 1.2.
*
* @return Content of the env:Fault/env:Node element as a String or null if none
* @throws UnsupportedOperationException
* - if this message does not support the SOAP 1.2 concept of Fault Node.
*/
public String getFaultNode() {
if (this.element.getOMFactory() instanceof SOAP11Factory) {
throw new UnsupportedOperationException("Message does not support the " +
"SOAP 1.2 concept of Fault Node");
} else {
if (fault != null && fault.getNode() != null && fault.getNode().getText() != null) {
return fault.getNode().getText();
}
}
return null;
}
/**
* Returns an Iterator over a distinct sequence of Locales for which there are associated Reason
* Text items. Any of these Locales can be used in a call to getFaultReasonText in order to
* obtain a localized version of the Reason Text string.
*
* @return an Iterator over a sequence of Locale objects for which there are associated Reason
* Text items.
* @throws SOAPException - if there was an error in retrieving the fault Reason locales.
* java.lang.UnsupportedOperationException - if this message does not
* support the SOAP 1.2 concept of Fault Reason.
* @since SAAJ 1.3
*/
public Iterator getFaultReasonLocales() throws SOAPException {
if (this.element.getOMFactory() instanceof SOAP11Factory) {
throw new UnsupportedOperationException("Message does not support the " +
"SOAP 1.2 concept of Fault Reason");
} else {
ArrayList faultReasonLocales = new ArrayList();
List soapTextList = this.fault.getReason().getAllSoapTexts();
if (soapTextList != null) {
Iterator faultReasons = soapTextList.iterator();
while (faultReasons.hasNext()) {
SOAPFaultText soapFaultText = (SOAPFaultText)faultReasons.next();
String lang = soapFaultText.getLang();
if (lang == null) {
faultReasonLocales.add(Locale.getDefault());
} else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?