|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
DetailedIllegalArgumentException.java | 100% | 100% | 100% | 100% |
|
1 | /* | |
2 | * Copyright (c) 1998, 2005 Gargoyle Software Inc. All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions are met: | |
6 | * | |
7 | * 1. Redistributions of source code must retain the above copyright notice, | |
8 | * this list of conditions and the following disclaimer. | |
9 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
10 | * this list of conditions and the following disclaimer in the documentation | |
11 | * and/or other materials provided with the distribution. | |
12 | * 3. The end-user documentation included with the redistribution, if any, must | |
13 | * include the following acknowledgment: | |
14 | * | |
15 | * "This product includes software developed by Gargoyle Software Inc. | |
16 | * (http://www.GargoyleSoftware.com/)." | |
17 | * | |
18 | * Alternately, this acknowledgment may appear in the software itself, if | |
19 | * and wherever such third-party acknowledgments normally appear. | |
20 | * 4. The name "Gargoyle Software" must not be used to endorse or promote | |
21 | * products derived from this software without prior written permission. | |
22 | * For written permission, please contact info@GargoyleSoftware.com. | |
23 | * 5. Products derived from this software may not be called "GSBase", nor may | |
24 | * "GSBase" appear in their name, without prior written permission of | |
25 | * Gargoyle Software Inc. | |
26 | * | |
27 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, | |
28 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
29 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE | |
30 | * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
31 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
32 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
33 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
34 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
35 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
36 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | package com.gargoylesoftware.base.util; | |
39 | ||
40 | ||
41 | /** | |
42 | * A more detailed version of IllegalArgumentException that contains | |
43 | * information about what argument was not legal. | |
44 | * | |
45 | * @version $Revision: 1.5 $ | |
46 | * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> | |
47 | */ | |
48 | public class DetailedIllegalArgumentException extends IllegalArgumentException { | |
49 | private static final long serialVersionUID = -6090279070118149533L; | |
50 | private final String argumentName_; | |
51 | private final Object argumentValue_; | |
52 | ||
53 | ||
54 | /** | |
55 | * Create an instance | |
56 | * | |
57 | * @param argumentName The name of the argument that was illegal | |
58 | * @param argumentValue The illegal value | |
59 | * @param message The message to use in the exception | |
60 | */ | |
61 | 36 | public DetailedIllegalArgumentException( |
62 | final String argumentName, final Object argumentValue, final String message ) { | |
63 | ||
64 | 36 | super("argumentName=["+argumentName+"] argumentValue=["+argumentValue+"]" |
65 | 36 | + (message==null?"":" message=["+message+"]")); |
66 | ||
67 | 36 | argumentName_ = argumentName; |
68 | 36 | argumentValue_ = argumentValue; |
69 | } | |
70 | ||
71 | ||
72 | /** | |
73 | * Create an instance | |
74 | * | |
75 | * @param argumentName The name of the argument that was illegal | |
76 | * @param argumentValue The illegal value | |
77 | */ | |
78 | 3 | public DetailedIllegalArgumentException( |
79 | final String argumentName, final Object argumentValue ) { | |
80 | ||
81 | 3 | this( argumentName, argumentValue, null ); |
82 | } | |
83 | ||
84 | ||
85 | /** | |
86 | * Create an instance | |
87 | * | |
88 | * @param argumentName The name of the argument that was illegal | |
89 | * @param argumentValue The illegal value | |
90 | * @param message A message | |
91 | */ | |
92 | 2 | public DetailedIllegalArgumentException( |
93 | final String argumentName, final int argumentValue, final String message ) { | |
94 | ||
95 | 2 | this(argumentName, new Integer(argumentValue), message); |
96 | } | |
97 | ||
98 | ||
99 | /** | |
100 | * Create an instance | |
101 | * | |
102 | * @param argumentName The name of the argument that was illegal | |
103 | * @param argumentValue The illegal value | |
104 | */ | |
105 | 2 | public DetailedIllegalArgumentException( |
106 | final String argumentName, final int argumentValue ) { | |
107 | ||
108 | 2 | this(argumentName, new Integer(argumentValue)); |
109 | } | |
110 | ||
111 | ||
112 | /** | |
113 | * Return the name of the argument that was illegal | |
114 | * @return the name of the argument | |
115 | */ | |
116 | 4 | public String getArgumentName() { |
117 | 4 | return argumentName_; |
118 | } | |
119 | ||
120 | ||
121 | /** | |
122 | * Return the value of the argument | |
123 | * @return The value of the argument | |
124 | */ | |
125 | 2 | public Object getArgumentValue() { |
126 | 2 | return argumentValue_; |
127 | } | |
128 | } | |
129 |
|