/** * (REQUIRED) * set this to the class name (e.g. org.project.MyClass) * and it will be converted into the class object * @param persistentClassname this is the fully qualified classname of the persistent type */ public void setPersistentClassname(String persistentClassname) { persistentType = ClassLoaderUtils.getClassFromString(persistentClassname); if (persistentType == null) { throw new IllegalArgumentException( "Invalid class name for persistentClassname, could not create class from string: " + persistentClassname); } } /* (non-Javadoc)
/** * Taken from PonderUtilCore around version 1.2.2 * - Antranig Basman (antranig@caret.cam.ac.uk) */ private static void appendSuperclasses(Class<?> clazz, List<Class<?>> accrete) { Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; ++i) { accrete.add(interfaces[i]); } for (int i = 0; i < interfaces.length; ++i) { appendSuperclasses(interfaces[i], accrete); } }
/** * Finds a class type that is in the containing collection, * will always return something (failsafe to Object.class) * @param collection * @return the class type contained in this collecion */ @SuppressWarnings("unchecked") public static Class<?> getClassFromCollection(Collection collection) { return ClassLoaderUtils.getClassFromCollection(collection); }
/** * @return a list of all superclasses and implemented interfaces by the supplied class, * recursively to the base, up to but excluding Object.class. These will be listed in order from * the supplied class, all concrete superclasses in ascending order, and then finally all * interfaces in recursive ascending order.<br/> * This will include duplicates if any superclasses implement the same classes */ public static List<Class<?>> getSuperclasses(Class<?> clazz) { return ClassLoaderUtils.getSuperclasses(clazz); }
/** * @param className a fully qualified class name (e.g. org.dspace.MyClass) * @return the Class if it can be found in the context or current {@link ClassLoader} OR null if no class can be found */ public static Class<?> getClassFromString(String className) { Class<?> c = null; try { ClassLoader cl = getCurrentClassLoader(); c = Class.forName(className, true, cl); } catch (ClassNotFoundException e) { try { ClassLoader cl = ClassLoaderUtils.class.getClassLoader(); c = Class.forName(className, true, cl); } catch (ClassNotFoundException e1) { try { c = Class.forName(className); } catch (ClassNotFoundException e2) { c = null; } } } return c; }
/** * @return a list of all superclasses and implemented interfaces by the supplied class, * recursively to the base, up to but excluding Object.class. These will be listed in order from * the supplied class, all concrete superclasses in ascending order, and then finally all * interfaces in recursive ascending order.<br/> * This will include duplicates if any superclasses implement the same classes */ public static List<Class<?>> getSuperclasses(Class<?> clazz) { return ClassLoaderUtils.getSuperclasses(clazz); }
/** * @param className a fully qualified class name (e.g. org.dspace.MyClass) * @return the Class if it can be found in the context or current {@link ClassLoader} OR null if no class can be found */ public static Class<?> getClassFromString(String className) { Class<?> c = null; try { ClassLoader cl = getCurrentClassLoader(); c = Class.forName(className, true, cl); } catch (ClassNotFoundException e) { try { ClassLoader cl = ClassLoaderUtils.class.getClassLoader(); c = Class.forName(className, true, cl); } catch (ClassNotFoundException e1) { try { c = Class.forName(className); } catch (ClassNotFoundException e2) { c = null; } } } return c; }
public Class<?> convert(Object value) { String className = value.toString(); Class<?> c = ClassLoaderUtils.getClassFromString(className); if (c == null) { throw new UnsupportedOperationException("Class convert failure: cannot convert source ("+value+") and type ("+value.getClass()+") to a Class"); } return c; }
/** * Taken from PonderUtilCore around version 1.2.2 * - Antranig Basman (antranig@caret.cam.ac.uk) */ private static void appendSuperclasses(Class<?> clazz, List<Class<?>> accrete) { Class<?>[] interfaces = clazz.getInterfaces(); for (int i = 0; i < interfaces.length; ++i) { accrete.add(interfaces[i]); } for (int i = 0; i < interfaces.length; ++i) { appendSuperclasses(interfaces[i], accrete); } }
/** * Finds a class type that is in the containing collection, * will always return something (failsafe to Object.class) * @param collection * @return the class type contained in this collecion */ @SuppressWarnings("unchecked") public static Class<?> getClassFromCollection(Collection collection) { return ClassLoaderUtils.getClassFromCollection(collection); }
public Class<?> convert(Object value) { String className = value.toString(); Class<?> c = ClassLoaderUtils.getClassFromString(className); if (c == null) { throw new UnsupportedOperationException("Class convert failure: cannot convert source ("+value+") and type ("+value.getClass()+") to a Class"); } return c; }
/** * Returns a list of all superclasses and implemented interfaces by the supplied class, * recursively to the base, up to but excluding Object.class. These will be listed in order from * the supplied class, all concrete superclasses in ascending order, and then finally all * interfaces in recursive ascending order.<br/> * This will include duplicates if any superclasses implement the same classes * * Taken from PonderUtilCore around version 1.2.2 * - Antranig Basman (antranig@caret.cam.ac.uk) */ public static List<Class<?>> getSuperclasses(Class<?> clazz) { List<Class<?>> accumulate = new ArrayList<Class<?>>(); while (clazz != Object.class) { accumulate.add(clazz); clazz = clazz.getSuperclass(); } int supers = accumulate.size(); for (int i = 0; i < supers; ++i) { appendSuperclasses(accumulate.get(i), accumulate); } return accumulate; }
/** * Set the list of persistent classes that this DAO will handle<br/> * This no longer requires this to be set before the class initializes * Do this using Spring like so: * <xmp> <property name="persistentClasses"> <list> <value>org.sakaiproject.*yourappname*.model.*YourObject*</value> </list> </property> * </xmp> * @param classes a list of Strings representing the * the fully qualified classpath and classname of persistent objects */ public void setPersistentClasses(List<String> classes) { if (classes.size() == 0) { throw new IllegalArgumentException("persistent class list must have at least one item"); } List<Class<?>> classList = new ArrayList<Class<?>>(); for (Iterator<String> i = classes.iterator(); i.hasNext();) { String className = i.next(); Class<?> c = ClassLoaderUtils.getClassFromString(className); if (c == null) { throw new IllegalArgumentException( "Invalid class type in list of persistent classes: " + className); } classList.add(c); } this.classes = classList; }
/** * Returns a list of all superclasses and implemented interfaces by the supplied class, * recursively to the base, up to but excluding Object.class. These will be listed in order from * the supplied class, all concrete superclasses in ascending order, and then finally all * interfaces in recursive ascending order.<br/> * This will include duplicates if any superclasses implement the same classes * * Taken from PonderUtilCore around version 1.2.2 * - Antranig Basman (antranig@caret.cam.ac.uk) */ public static List<Class<?>> getSuperclasses(Class<?> clazz) { List<Class<?>> accumulate = new ArrayList<Class<?>>(); while (clazz != Object.class) { accumulate.add(clazz); clazz = clazz.getSuperclass(); } int supers = accumulate.size(); for (int i = 0; i < supers; ++i) { appendSuperclasses(accumulate.get(i), accumulate); } return accumulate; }
Class<?> dynaBean = ClassLoaderUtils.getClassFromString(DYNABEAN_CLASSNAME); if (dynaBean != null) { Class<?> adapterClass = ClassLoaderUtils.getClassFromString(path); if (adapterClass == null) { System.err.println("WARN: Could not find adapter class: " + path + ", will continue without the dynabean adapter");
Class<?> dynaBean = ClassLoaderUtils.getClassFromString(DYNABEAN_CLASSNAME); if (dynaBean != null) { Class<?> adapterClass = ClassLoaderUtils.getClassFromString(path); if (adapterClass == null) { System.err.println("WARN: Could not find adapter class: " + path + ", will continue without the dynabean adapter");