KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > ParameterCheckHelper


1 /**
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2005 ? EBM WebSourcing
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): EBM WebSourcing
21  * --------------------------------------------------------------------------
22  * $Id: ParameterCheckHelper.java,v 1.2 2005/07/22 10:24:27 wjoseph Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.petals.util;
27
28 /**
29  * Class managing parameters to checks there nullity or emptyness
30  *
31  * @author wjoseph - eBMWebSourcing
32  *
33  */

34 public final class ParameterCheckHelper {
35
36     private static final String JavaDoc MUST_NOT_BE_EMPTY = " must not be empty";
37
38     private static final String JavaDoc MUST_NOT_BE_NULL = " must not be null";
39
40     private ParameterCheckHelper() {
41         // avoid to be build
42
}
43
44     /**
45      * Checks if the parameter is an empty string
46      *
47      * @param parameter
48      * parameter to be tested
49      * @param parameterName
50      * name of the parameter
51      * @throws IllegalArgumentException
52      * if parameter is empty
53      */

54     public static void isEmptyParameter(String JavaDoc parameter, String JavaDoc parameterName)
55         throws IllegalArgumentException JavaDoc {
56         if (parameter != null
57             && parameter.length() == 0) {
58             throw new IllegalArgumentException JavaDoc(parameterName
59                 + MUST_NOT_BE_EMPTY);
60         }
61     }
62
63     /**
64      * Checks if the parameter is an empty string and log in error if it is
65      * empty
66      *
67      * @param parameter
68      * parameter to be tested
69      * @param parameterName
70      * name of the parameter
71      * @param log
72      * logger to use
73      * @throws IllegalArgumentException
74      * if parameter is empty
75      */

76     public static void isEmptyParameterWithLog(String JavaDoc parameter,
77         String JavaDoc parameterName, LoggingUtil log) throws IllegalArgumentException JavaDoc {
78         if (parameter != null
79             && parameter.length() == 0) {
80             log.error(parameterName
81                 + MUST_NOT_BE_EMPTY);
82             throw new IllegalArgumentException JavaDoc(parameterName
83                 + MUST_NOT_BE_EMPTY);
84         }
85     }
86
87     /**
88      * Checks if the parameter is null
89      *
90      * @param parameter
91      * parameter to be tested
92      * @param parameterName
93      * name of the parameter
94      * @throws IllegalArgumentException
95      * if parameter is null
96      */

97     public static void isNullParameter(Object JavaDoc parameter, String JavaDoc parameterName)
98         throws IllegalArgumentException JavaDoc {
99         if (parameter == null) {
100             throw new IllegalArgumentException JavaDoc(parameterName
101                 + MUST_NOT_BE_NULL);
102         }
103     }
104
105     /**
106      * Checks if the parameter is null and log in error if it is null
107      *
108      * @param parameter
109      * parameter to be tested
110      * @param parameterName
111      * name of the parameter
112      * @param log
113      * logger to use
114      * @throws IllegalArgumentException
115      * if parameter is null
116      */

117     public static void isNullParameterWithLog(Object JavaDoc parameter,
118         String JavaDoc parameterName, LoggingUtil log) throws IllegalArgumentException JavaDoc {
119         if (parameter == null) {
120             log.error(parameterName
121                 + MUST_NOT_BE_NULL);
122             throw new IllegalArgumentException JavaDoc(parameterName
123                 + MUST_NOT_BE_NULL);
124         }
125     }
126
127 }
128
Popular Tags