Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* $Id: UnsuccessfulXINSCallException.java,v 1.25 2006/08/28 09:12:30 agoubard Exp $
*
* Copyright 2003-2006 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.spec.ErrorCodeSpec;
/**
* Exception that indicates that a result code was returned by the API call.
*
* @version $Revision: 1.25 $ $Date: 2006/08/28 09:12:30 $
* @author Ernst de Haan
*
* @since XINS 1.0.0
*/
public class UnsuccessfulXINSCallException
extends XINSCallException
implements XINSCallResultData {
//-------------------------------------------------------------------------
// NOTE: Since XINS 1.1.0, this class is no longer final. However, all
// methods still are.
//-------------------------------------------------------------------------
// NOTE: Since XINS 1.2.0, this class implements the XINSCallResultData
// interface.
//-------------------------------------------------------------------------
// Class functions
//-------------------------------------------------------------------------
/**
* Delegate for the constructor that determines the detail message based on
* a XINSCallResultData object and an optional detailed
* description.
*
* @param result
* the {@link XINSCallResultData} instance, should not be
* null.
*
* @param detail
* detailed description to include, or null if unavailable.
*
* @return
* the detail message for the constructor to use, never
* null.
*
* @throws IllegalArgumentException
* if result == null
* || result.{@link XINSCallResultData#getErrorCode() getErrorCode()} == null.
*/
private static final String determineDetail(XINSCallResultData result,
String detail)
throws IllegalArgumentException {
// Argument cannot be null
MandatoryArgumentChecker.check("result", result);
// Result must be unsuccessful
String errorCode = result.getErrorCode();
if (errorCode == null) {
throw new IllegalArgumentException("result.getErrorCode() == null");
}
if (detail == null || detail.length() < 1) {
return "Error code \"" + errorCode + "\".";
} else {
return "Error code \"" + errorCode + "\": " + detail;
}
}
//-------------------------------------------------------------------------
// Constructors
//-------------------------------------------------------------------------
/**
* Constructs a new UnsuccessfulXINSCallException 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.
*/
UnsuccessfulXINSCallException(XINSCallRequest request,
TargetDescriptor target,
long duration,
XINSCallResultData resultData,
String detail)
throws IllegalArgumentException {
super("Unsuccessful XINS call result", request, target, duration,
determineDetail(resultData, detail), null);
// Check additional precondition
MandatoryArgumentChecker.check("resultData", resultData);
// TODO: Check all mandatory arguments at once
// Result object must be unsuccessful
String errorCode = resultData.getErrorCode();
if (errorCode == null) {
throw new IllegalArgumentException("resultData.getErrorCode() == null");
}
// Store details
_result = resultData;
}
//-------------------------------------------------------------------------
// Fields
//-------------------------------------------------------------------------
/**
* The result data. The value of this field cannot be null.
*/
private final XINSCallResultData _result;
/**
* The type of the error.
*/
private ErrorCodeSpec.Type _type;
//-------------------------------------------------------------------------
// Methods
//-------------------------------------------------------------------------
/**
* Returns the error code.
*
* @return
* the error code, never null.
*/
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, not null.
*
* @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 a {@link DataElement}, can be null;
*/
public final DataElement getDataElement() {
return _result.getDataElement();
}
/**
* Sets the type of the error code.
*
* @param type
* the type of the error (functionnal or technical).
*/
void setType(ErrorCodeSpec.Type type) {
_type = type;
}
/**
* Returns the type of the error code.
*
* @return
* the type as a {@link ErrorCodeSpec ErrorCodeSpec.Type}, can be null if it's unknown.
*
* @since XINS 1.4.0
*/
public final ErrorCodeSpec.Type getType() {
return _type;
}
}