org.xins.client.UnacceptableResultXINSCallException Maven / Gradle / Ivy
/*
* $Id: UnacceptableResultXINSCallException.java,v 1.22 2007/05/15 11:33:19 agoubard Exp $
*
* Copyright 2003-2007 Orange Nederland Breedband B.V.
* See the COPYRIGHT file for redistribution and use restrictions.
*/
package org.xins.client;
import org.xins.common.MandatoryArgumentChecker;
import org.xins.common.collections.PropertyReader;
import org.xins.common.service.TargetDescriptor;
import org.xins.common.xml.Element;
/**
* Exception that indicates that an API call returned a result that was
* considered unacceptable by the application layer.
*
* Note that this exception is not thrown if the result is
* invalid according to the XINS rules for a result XML document. Only if the
* result is just invalid in relation to the applicable API specification this
* exception is thrown.
*
* @version $Revision: 1.22 $ $Date: 2007/05/15 11:33:19 $
* @author Ernst de Haan
*
* @since XINS 1.0.0
*/
public class UnacceptableResultXINSCallException
extends XINSCallException {
/**
* The result that is considered unacceptable. Never null
.
*/
private final XINSCallResultData _result;
/**
* Constructs a new UnacceptableCallResultException
using the
* specified XINSCallResult
.
*
* @param result
* the {@link XINSCallResult} that is considered unacceptable, never
* null
.
*
* @param detail
* a detailed description of why the result is considered unacceptable,
* or null
if such a description is not available.
*
* @param cause
* the optional cause exception, or null
.
*
* @throws IllegalArgumentException
* if result == null
.
*/
public UnacceptableResultXINSCallException(XINSCallResult result,
String detail,
Throwable cause)
throws IllegalArgumentException {
super("Unacceptable XINS call result", result, detail, cause);
// Store the result
_result = result;
}
/**
* Constructs a new UnacceptableCallResultException
using the
* specified AbstractCAPICallResult
.
*
* @param result
* the {@link AbstractCAPICallResult} that is considered unacceptable,
* never null
.
*
* @param detail
* a detailed description of why the result is considered unacceptable,
* or null
if such a description is not available.
*
* @param cause
* the optional cause exception, or null
.
*
* @throws IllegalArgumentException
* if result == null
.
*/
public UnacceptableResultXINSCallException(AbstractCAPICallResult result,
String detail,
Throwable cause)
throws IllegalArgumentException {
this(checkArguments(result).getXINSCallResult(), detail, cause);
}
/**
* Constructs a new UnacceptableResultXINSCallException
based
* on a XINSCallResultData
instance.
*
* @param request
* the original request, cannot be null
.
*
* @param target
* descriptor for the target that was attempted to be called, cannot be
* null
.
*
* @param duration
* the call duration in milliseconds, must be >= 0.
*
* @param resultData
* the result data, cannot be null
.
*
* @param detail
* detail message, or null
.
*
* @throws IllegalArgumentException
* if request == null
* || target == null
* || duration < 0
* || resultData == null
* || resultData.{@link XINSCallResult#getErrorCode() getErrorCode()} == null
.
*/
UnacceptableResultXINSCallException(XINSCallRequest request,
TargetDescriptor target,
long duration,
XINSCallResultData resultData,
String detail)
throws IllegalArgumentException {
super("Unacceptable XINS call result",
request, target, duration, detail, (Throwable) null);
// Check additional precondition
MandatoryArgumentChecker.check("resultData", resultData);
// Store details
_result = resultData;
}
/**
* Checks the mandatory result
argument for the constructor
* that accepts an AbstractCAPICallResult
.
*
* @param result
* the argument for the constructor, cannot be null
.
*
* @return
* the argument result
, guaranteed not null
.
*
* @throws IllegalArgumentException
* if result == null
.
*/
private static AbstractCAPICallResult checkArguments(AbstractCAPICallResult result)
throws IllegalArgumentException {
MandatoryArgumentChecker.check("result", result);
return result;
}
/**
* Returns the error code.
*
* @return
* the error code or null
if the call was successful and no
* error code was returned.
*/
public final String getErrorCode() {
return _result.getErrorCode();
}
/**
* Gets all returned parameters.
*
* @return
* a {@link PropertyReader} containing all parameters, or
* null
if there are none.
*/
public final PropertyReader getParameters() {
return _result.getParameters();
}
/**
* Gets the value of the specified returned parameter.
*
* @param name
* the parameter name, not null
.
*
* @return
* the value of the parameter, or null
if there is no values.
*
* @throws IllegalArgumentException
* if name == null
.
*/
public final String getParameter(String name)
throws IllegalArgumentException {
PropertyReader p = getParameters();
if (p == null) {
return null;
} else {
return p.get(name);
}
}
/**
* Returns the optional extra data.
*
* @return
* the extra data as an {@link Element}, can be null
;
*/
public final Element getDataElement() {
return _result.getDataElement();
}
}