/*=============================================================================*
* Copyright 2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*=============================================================================*/
package org.apache.ws.resource.faults;
import org.apache.ws.util.SaajUtils;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlObject;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import javax.xml.rpc.JAXRPCException;
import javax.xml.rpc.soap.SOAPFaultException;
import javax.xml.soap.Detail;
import javax.xml.soap.DetailEntry;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
/**
* Subclass of JAX-RPC {@link SOAPFaultException} that adds convenient methods for
* adding Detail entries. The entries may be specified as either DOM nodes or XmlBeans.
*
* @author Ian P. Springer
*/
public class FaultException extends SOAPFaultException
{
private Detail m_detail;
public FaultException( QName faultCode, String faultString, String faultActor, Detail detail )
{
super( faultCode, faultString, faultActor, detail );
m_detail = detail;
}
public FaultException( QName faultCode, String faultString, String faultActor )
{
this( faultCode, faultString, faultActor, createDetail() );
}
public FaultException( QName faultCode, String faultString )
{
this( faultCode, faultString, null );
}
private static Detail createDetail()
{
try
{
return SOAPFactory.newInstance().createDetail();
}
catch ( SOAPException soape )
{
throw new JAXRPCException( "Failed to create SAAJ Detail object via SOAPFactory.", soape );
}
}
public DetailEntry addDetailEntry( XmlObject xmlElem )
{
XmlObject docXBean = XmlBeanUtils.getDocument( xmlElem );
return addDetailEntry( ((Document)docXBean.newDomNode()).getDocumentElement() );
}
public DetailEntry addDetailEntry( Element domElem )
{
if ( m_detail == null )
{
throw new IllegalStateException( "Detail entry cannot be added because Detail is null." );
}
try
{
return SaajUtils.addDetailEntry( m_detail, domElem );
}
catch ( SOAPException soape )
{
throw new JAXRPCException( "Failed to add detail entry to SAAJ Detail object.", soape );
}
}
public Detail getDetail()
{
return m_detail;
}
}