1 /*
2 * Copyright 2007 Werner Guttmann
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14 package org.exolab.castor.util;
15
16 import java.lang.reflect.InvocationTargetException;
17 import java.lang.reflect.Method;
18
19 /**
20 * Utility class to support reflection-based operations.
21 *
22 * @since 1.1.2
23 */
24 public class ReflectionUtil {
25
26 /**
27 * Calls isEnum() method on target class vi areflection to find out whether the given type is a
28 * Java 5 enumeration.
29 *
30 * @param type The type to analyze.
31 * @return True if the type given is a Java 5.0 enum.
32 * @throws NoSuchMethodException If the method can not be found.
33 * @throws IllegalAccessException If access to this method is illegal
34 * @throws InvocationTargetException If the target method can not be invoked.
35 */
36 public static Boolean isEnumViaReflection(Class type)
37 throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
38 Method isEnumMethod = type.getClass().getMethod("isEnum", (Class[]) null);
39 return (Boolean) isEnumMethod.invoke(type, (Object[]) null);
40 }
41
42
43 }