aboutsummaryrefslogtreecommitdiffstats
path: root/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java')
-rw-r--r--policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java112
1 files changed, 59 insertions, 53 deletions
diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
index bf59ec96..f618b4c9 100644
--- a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
+++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* policy-utils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,66 +21,72 @@
/**
*
*/
+
package org.onap.policy.drools.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+
/**
- * Reflection utilities
+ * Reflection utilities.
*
*/
public class ReflectionUtil {
-
- protected static final Logger logger = LoggerFactory.getLogger(ReflectionUtil.class);
- private ReflectionUtil(){
- }
-
- /**
- * returns (if exists) a class fetched from a given classloader
- *
- * @param classLoader the class loader
- * @param className the class name
- * @return the actual class
- * @throws IllegalArgumentException if an invalid parameter has been passed in
- */
- public static Class<?> fetchClass(ClassLoader classLoader,
- String className) {
- if (classLoader == null)
- throw new IllegalArgumentException("A class loader must be provided");
-
- if (className == null)
- throw new IllegalArgumentException("A class name to be fetched in class loader " +
- classLoader + " must be provided");
-
- try {
- return Class.forName(className, true, classLoader);
- } catch (Exception e) {
- logger.error("class {} fetched in {} does not exist", className, classLoader, e);
- }
-
- return null;
- }
-
- /**
- *
- * @param classLoader target class loader
- * @param classname class name to fetch
- * @return true if exists
- * @throws IllegalArgumentException if an invalid parameter has been passed in
- */
- public static boolean isClass(ClassLoader classLoader, String classname) {
- return fetchClass(classLoader, classname) != null;
- }
-
- /**
- * is a subclass?
- * @param parent superclass
- * @param presumedSubclass subclass
- * @return
- */
- public static boolean isSubclass(Class<?> parent, Class<?> presumedSubclass) {
- return parent.isAssignableFrom(presumedSubclass);
- }
+ protected static final Logger logger = LoggerFactory.getLogger(ReflectionUtil.class);
+
+ private ReflectionUtil(){
+ }
+
+ /**
+ * returns (if exists) a class fetched from a given classloader.
+ *
+ * @param classLoader the class loader
+ * @param className the class name
+ * @return the actual class
+ * @throws IllegalArgumentException if an invalid parameter has been passed in
+ */
+ public static Class<?> fetchClass(ClassLoader classLoader,
+ String className) {
+ if (classLoader == null) {
+ throw new IllegalArgumentException("A class loader must be provided");
+ }
+
+ if (className == null) {
+ throw new IllegalArgumentException("A class name to be fetched in class loader "
+ + classLoader + " must be provided");
+ }
+
+ try {
+ return Class.forName(className, true, classLoader);
+ } catch (Exception e) {
+ logger.error("class {} fetched in {} does not exist", className, classLoader, e);
+ }
+
+ return null;
+ }
+
+ /**
+ * Is class.
+ *
+ * @param classLoader target class loader
+ * @param classname class name to fetch
+ * @return true if exists
+ * @throws IllegalArgumentException if an invalid parameter has been passed in
+ */
+ public static boolean isClass(ClassLoader classLoader, String classname) {
+ return fetchClass(classLoader, classname) != null;
+ }
+
+ /**
+ * Is it a sub class.
+ *
+ * @param parent superclass
+ * @param presumedSubclass subclass
+ * @return
+ */
+ public static boolean isSubclass(Class<?> parent, Class<?> presumedSubclass) {
+ return parent.isAssignableFrom(presumedSubclass);
+ }
}