01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.pluto.util;
18:
19: import org.apache.commons.logging.Log;
20: import org.apache.commons.logging.LogFactory;
21:
22: /**
23: * Static class that provides utility static methods for argument validation.
24: *
25: */
26: public class ArgumentUtility {
27:
28: /** Logger. */
29: public static final Log LOG = LogFactory
30: .getLog(ArgumentUtility.class);
31:
32: // Static Utility Methods --------------------------------------------------
33:
34: /**
35: * Validates that the passed-in argument value is not null.
36: * @param argumentName the argument name.
37: * @param argument the argument value.
38: * @throws IllegalArgumentException if the argument value is null.
39: */
40: public static void validateNotNull(String argumentName,
41: Object argument) throws IllegalArgumentException {
42: if (argument == null) {
43: if (LOG.isDebugEnabled()) {
44: LOG.debug("Validation failed for argument: "
45: + argumentName
46: + ": argument should not be null.");
47: }
48: throw new IllegalArgumentException("Illegal Argument: "
49: + argumentName + " (argument should not be null)");
50: }
51: }
52:
53: /**
54: * Validates that the passed-in string argument value is not null or empty.
55: * @param argumentName the argument name.
56: * @param argument the argument value.
57: * @throws IllegalArgumentException if the argument value is null or empty.
58: */
59: public static void validateNotEmpty(String argumentName,
60: String argument) throws IllegalArgumentException {
61: if (argument == null || "".equals(argument)) {
62: if (LOG.isDebugEnabled()) {
63: LOG.debug("Validation failed for argument: "
64: + argumentName
65: + ": argument should not be null or empty.");
66: }
67: throw new IllegalArgumentException("Illegal Argument: "
68: + argumentName
69: + " (argument should not be null or empty)");
70: }
71: }
72:
73: }
|