View Javadoc

1   /*
2    * Copyright 2011-2012 smartics, Kronseder & Reiner GmbH
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 de.smartics.util.lang;
17  
18  /**
19   * Signals that a given {@link String} argument is not <code>null</code> but
20   * contains only whitespaces or is empty.
21   */
22  public class BlankExceptNullArgumentException extends IllegalArgumentException
23  {
24    // ********************************* Fields *********************************
25  
26    // --- constants ------------------------------------------------------------
27  
28    /**
29     * The class version identifier.
30     * <p>
31     * The value of this constant is {@value}.
32     * </p>
33     */
34    private static final long serialVersionUID = 1L;
35  
36    // --- members --------------------------------------------------------------
37  
38    // ****************************** Initializer *******************************
39  
40    // ****************************** Constructors ******************************
41  
42    /**
43     * Convenience constructor if no argument name needs to be provided. This
44     * constructor is not recommended since the exception's message is less
45     * verbose.
46     */
47    public BlankExceptNullArgumentException()
48    {
49      this(null);
50    }
51  
52    /**
53     * Convenience constructor.
54     *
55     * @param argName the name of the {@link String} argument that contains only
56     *          whitespaces or was empty.
57     */
58    public BlankExceptNullArgumentException(final String argName)
59    {
60      this(argName, null);
61    }
62  
63    /**
64     * Default constructor.
65     *
66     * @param argName the name of the {@link String} argument that contains only
67     *          whitespaces or was empty.
68     * @param message an optional additional message to provide information about
69     *          the context of the argument.
70     * @see java.lang.IllegalArgumentException#IllegalArgumentException(java.lang.String)
71     */
72    public BlankExceptNullArgumentException(final String argName, final String message)
73    {
74      super((argName == null ? "Argument" : argName)
75            + " must not contain only whitespace or be empty"
76            + (message != null ? ": " + message : "."));
77    }
78  
79    // ****************************** Inner Classes *****************************
80  
81    // ********************************* Methods ********************************
82  
83    // --- init -----------------------------------------------------------------
84  
85    // --- get&set --------------------------------------------------------------
86  
87    // --- business -------------------------------------------------------------
88  
89    // --- object basics --------------------------------------------------------
90  
91  }