01: /*
02: * $Id: UnacceptableErrorCodeXINSCallException.java,v 1.11 2007/03/16 09:54:58 agoubard Exp $
03: *
04: * Copyright 2003-2007 Orange Nederland Breedband B.V.
05: * See the COPYRIGHT file for redistribution and use restrictions.
06: */
07: package org.xins.client;
08:
09: import org.xins.common.MandatoryArgumentChecker;
10:
11: import org.xins.common.service.TargetDescriptor;
12:
13: /**
14: * Exception that indicates an error code was received from the server-side
15: * that is not expected at the client-side.
16: *
17: * @version $Revision: 1.11 $ $Date: 2007/03/16 09:54:58 $
18: * @author <a href="mailto:ernst@ernstdehaan.com">Ernst de Haan</a>
19: *
20: * @since XINS 1.2.0
21: */
22: public class UnacceptableErrorCodeXINSCallException extends
23: UnacceptableResultXINSCallException {
24:
25: /**
26: * Constructs a new <code>UnacceptableErrorCodeXINSCallException</code>
27: * based on a <code>XINSCallResultData</code> instance.
28: *
29: * @param request
30: * the original request, cannot be <code>null</code>.
31: *
32: * @param target
33: * descriptor for the target that was attempted to be called, cannot be
34: * <code>null</code>.
35: *
36: * @param duration
37: * the call duration in milliseconds, must be >= 0.
38: *
39: * @param resultData
40: * the result data, cannot be <code>null</code>.
41: *
42: * @throws IllegalArgumentException
43: * if <code>request == null
44: * || target == null
45: * || duration < 0
46: * || resultData == null
47: * || resultData.{@link XINSCallResult#getErrorCode()
48: * getErrorCode()} == null</code>.
49: */
50: public UnacceptableErrorCodeXINSCallException(
51: XINSCallRequest request, TargetDescriptor target,
52: long duration, XINSCallResultData resultData)
53: throws IllegalArgumentException {
54:
55: super (request, target, duration, resultData,
56: getDetail(resultData));
57: }
58:
59: /**
60: * Constructs a detail message for the constructor to pass up to the
61: * superconstructor.
62: *
63: * @param result
64: * the {@link XINSCallResultData} that is has an error code set that is
65: * considered unacceptable, never <code>null</code>.
66: *
67: * @return
68: * the detail message, never <code>null</code>.
69: *
70: * @throws IllegalArgumentException
71: * if <code>result == null
72: * || result.{@link XINSCallResultData#getErrorCode()
73: * getErrorCode()} == null</code>.
74: */
75: private static final String getDetail(XINSCallResultData result)
76: throws IllegalArgumentException {
77:
78: // Check preconditions
79: MandatoryArgumentChecker.check("result", result);
80: if (result.getErrorCode() == null) {
81: throw new IllegalArgumentException(
82: "result.getErrorCode() == null");
83: }
84:
85: // Generate detail message
86: return "Error code \"" + result.getErrorCode()
87: + "\" is not acceptable for this function.";
88: }
89: }
|