001    /*
002     * Copyright 2002-2004 the original author or authors.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package org.springframework.richclient.util;
017    
018    /**
019     *
020     * A convenience extension to Spring's {@link org.springframework.util.Assert}
021     * class. This is mainly for use within the framework.
022     *
023     * @author Oliver Hutchinson
024     * @author Kevin Stembridge
025     *
026     */
027    public class Assert extends org.springframework.util.Assert {
028    
029            /**
030             * Assert that an object required; that is, it is not null.
031             *
032             * <pre>
033             * required(clazz, &quot;class&quot;);
034             * </pre>
035             *
036             * @param object the object to check
037             * @param name the name of the object being checked
038             * @throws IllegalArgumentException if the object is <code>null</code>
039             */
040            public static void required(Object object, String name) {
041                    if (object == null) {
042                            throw new IllegalArgumentException(name + " is required; it cannot be null");
043                    }
044            }
045    
046            /**
047             * Confirms that the given array is not null and that all of its elements
048             * are not null also.
049             *
050             * @param array The array whose elements, if any, must all be non-null.
051             * @param arrayName The property name of the array, only used for display
052             * purposes. May be null.
053             *
054             * @throws IllegalArgumentException if the given array is null or if any of
055             * its elements are null.
056             */
057            public static void noElementsNull(Object[] array, String arrayName) {
058    
059                    if (arrayName == null) {
060                            arrayName = "array";
061                    }
062    
063                    required(array, arrayName);
064    
065                    for (int i = 0; i < array.length; i++) {
066                            required(array[i], arrayName + "[" + i + "]");
067                    }
068    
069            }
070    
071    }