KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > IncompleteArgumentException


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.lang;
17
18 import java.util.Arrays JavaDoc;
19
20 /**
21  * <p>Thrown to indicate an incomplete argument to a method.
22  * This exception supplements the standard <code>IllegalArgumentException</code>
23  * by providing a more semantically rich description of the problem.</p>
24  *
25  * <p><code>IncompleteArgumentException</code> represents the case where a method takes
26  * in a parameter that has a number of properties, some of which have not been set.
27  * A case might be a search requirements bean that must have three properties set
28  * in order for the method to run, but only one is actually set.
29  * This exception would be used in place of
30  * <code>IllegalArgumentException</code>, yet it still extends it.</p>
31  *
32  * <pre>
33  * public void foo(PersonSearcher search) {
34  * if (search.getSurname() == null ||
35  * search.getForename() == null ||
36  * search.getSex() == null) {
37  * throw new IncompleteArgumentException("search");
38  * }
39  * // do something with the searcher
40  * }
41  * </pre>
42  *
43  * @author Matthew Hawthorne
44  * @since 2.0
45  * @version $Id: IncompleteArgumentException.java 161243 2005-04-14 04:30:28Z ggregory $
46  */

47 public class IncompleteArgumentException extends IllegalArgumentException JavaDoc {
48
49     /**
50      * <p>Instantiates with the specified description.</p>
51      *
52      * @param argName a description of the incomplete argument
53      */

54     public IncompleteArgumentException(String JavaDoc argName) {
55         super(argName + " is incomplete.");
56     }
57
58     /**
59      * <p>Instantiates with the specified description.</p>
60      *
61      * @param argName a description of the incomplete argument
62      * @param items an array describing the arguments missing
63      */

64     public IncompleteArgumentException(String JavaDoc argName, String JavaDoc[] items) {
65         super(
66             argName
67                 + " is missing the following items: "
68                 + safeArrayToString(items));
69     }
70
71     /**
72      * <p>Converts an array to a string without throwing an exception.</p>
73      *
74      * @param array an array
75      * @return the array as a string
76      */

77     private static final String JavaDoc safeArrayToString(Object JavaDoc[] array) {
78         return array == null ? null : Arrays.asList(array).toString();
79     }
80
81 }
82
Popular Tags