View Javadoc
1   /*
2    * Copyright 2007 Werner Guttmann
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.exolab.castor.util;
17  
18  import java.lang.reflect.InvocationTargetException;
19  import java.lang.reflect.Method;
20  
21  /**
22   * Utility class to support reflection-based operations.
23   *
24   * @since 1.1.2
25   */
26  public class ReflectionUtil {
27  
28      /**
29       * Calls isEnum() method on target class vi areflection to find out
30       * whether the given type is a Java 5 enumeration.
31       * @param type The type to analyze.
32       * @return True if the type given is a Java 5.0 enum.
33       * @throws NoSuchMethodException If the method can not be found.
34       * @throws IllegalAccessException If access to this method is illegal
35       * @throws InvocationTargetException If the target method can not be invoked.
36       */
37      public static Boolean isEnumViaReflection(Class type) 
38      throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
39          Method isEnumMethod = type.getClass().getMethod("isEnum", (Class[]) null);
40          return (Boolean) isEnumMethod.invoke(type, (Object[]) null);
41      }
42  
43  
44  }