/** * Returns true if sup is a superclass of sub (or the same), taking into account dynamic * classes. * * @param sup the supposed superclass * @param sub the supposed subclass * @return a boolean */ public static boolean isAssignableFrom(Class<?> sup, Class<?> sub) { Set<Class<?>> classes = Util.decomposeClass(sup); for (Class<?> clazz : classes) { if (!clazz.isAssignableFrom(sub)) { return false; } } return true; }
/** * Returns true if sup is a superclass of sub (or the same), taking into account dynamic * classes. * * @param sup the supposed superclass * @param sub the supposed subclass * @return a boolean */ public static boolean isAssignableFrom(Class<?> sup, Class<?> sub) { Set<Class<?>> classes = Util.decomposeClass(sup); for (Class<?> clazz : classes) { if (!clazz.isAssignableFrom(sub)) { return false; } } return true; }
private Set<String> getIgnorableFields(FastPathObject obj) { Set<String> ret = new HashSet<String>(); for (Class<?> clazz: Util.decomposeClass(obj.getClass())) { if (ignoredFields.containsKey(clazz)) { ret.addAll(ignoredFields.get(clazz)); } } return ret; }
private Set<String> getIgnorableFields(FastPathObject obj) { Set<String> ret = new HashSet<String>(); for (Class<?> clazz: Util.decomposeClass(obj.getClass())) { if (ignoredFields.containsKey(clazz)) { ret.addAll(ignoredFields.get(clazz)); } } return ret; }
/** * Return true if given type (of a constraint) can be assigned to the InterMineObject - i.e. * if the class or any superclass of the InterMineObject are the type. Type can be a qualified * or unqualified class name. * * @param cls the class in the model that will be assigned to * @param obj the InterMineObject to check * @return a boolean */ public static boolean canAssignObjectToType(Class<?> cls, InterMineObject obj) { for (Class<?> c : Util.decomposeClass(obj.getClass())) { if (cls.isAssignableFrom(c)) { return true; } } return false; } }
/** * Return true if given type (of a constraint) can be assigned to the InterMineObject - i.e. * if the class or any superclass of the InterMineObject are the type. Type can be a qualified * or unqualified class name. * * @param cls the class in the model that will be assigned to * @param obj the InterMineObject to check * @return a boolean */ public static boolean canAssignObjectToType(Class<?> cls, InterMineObject obj) { for (Class<?> c : Util.decomposeClass(obj.getClass())) { if (cls.isAssignableFrom(c)) { return true; } } return false; } }
/** * Return true if and only if the object is an instance of the class given by the className. * @param object the object to test * @param className the super class name to test for * @return true if object is an instance of className * @exception ClassNotFoundException if the class given by className cannot be located */ public static boolean isInstanceOf(FastPathObject object, String className) throws ClassNotFoundException { Set<Class<?>> classes = Util.decomposeClass(object.getClass()); Class<?> testClass = Class.forName(className); for (Class<?> objectClass: classes) { if (testClass.isAssignableFrom(objectClass)) { return true; } } return false; }
/** * Return true if and only if the object is an instance of the class given by the className. * @param object the object to test * @param className the super class name to test for * @return true if object is an instance of className * @exception ClassNotFoundException if the class given by className cannot be located */ public static boolean isInstanceOf(FastPathObject object, String className) throws ClassNotFoundException { Set<Class<?>> classes = Util.decomposeClass(object.getClass()); Class<?> testClass = Class.forName(className); for (Class<?> objectClass: classes) { if (testClass.isAssignableFrom(objectClass)) { return true; } } return false; }
/** * Returns a String representation. * * @return a String representation */ @Override public String toString() { Set<Class<?>> classes = Util.decomposeClass(type); if (classes.size() == 1) { return type.getName(); } else { boolean needComma = false; StringBuffer retval = new StringBuffer(); for (Class<?> clazz : classes) { retval.append(needComma ? ", " : "("); needComma = true; retval.append(clazz.getName()); } return retval.toString() + ")"; } } }
/** * Returns a String representation. * * @return a String representation */ @Override public String toString() { Set<Class<?>> classes = Util.decomposeClass(type); if (classes.size() == 1) { return type.getName(); } else { boolean needComma = false; StringBuffer retval = new StringBuffer(); for (Class<?> clazz : classes) { retval.append(needComma ? ", " : "("); needComma = true; retval.append(clazz.getName()); } return retval.toString() + ")"; } } }
/** * Returns the result of decomposeClass if that is a single class, or throws an exception if * there are more than one. * * @param clazz the class * @return the corresponding non-dynamic class */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> getSimpleClass( Class<? extends FastPathObject> clazz) { Set<Class<?>> decomposed = Util.decomposeClass(clazz); if (decomposed.size() > 1) { throw new IllegalArgumentException("No simple class for " + Util.getFriendlyName(clazz)); } return (Class) decomposed.iterator().next(); }
/** * Returns the result of decomposeClass if that is a single class, or throws an exception if * there are more than one. * * @param clazz the class * @return the corresponding non-dynamic class */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> getSimpleClass( Class<? extends FastPathObject> clazz) { Set<Class<?>> decomposed = Util.decomposeClass(clazz); if (decomposed.size() > 1) { throw new IllegalArgumentException("No simple class for " + Util.getFriendlyName(clazz)); } return (Class) decomposed.iterator().next(); }
/** * Creates a friendly name for a given class. * * @param clazz the class * @return a String describing the class, without package names */ public static synchronized String getFriendlyName(Class<?> clazz) { String retval = friendlyNameMap.get(clazz); if (retval == null) { retval = ""; Iterator<Class<?>> iter = decomposeClass(clazz).iterator(); boolean needComma = false; while (iter.hasNext()) { Class<?> constit = iter.next(); retval += needComma ? "," : ""; needComma = true; retval += constit.getName().substring(constit.getName().lastIndexOf('.') + 1); } friendlyNameMap.put(clazz, retval); } return retval; }
/** * Creates a friendly name for a given class. * * @param clazz the class * @return a String describing the class, without package names */ public static synchronized String getFriendlyName(Class<?> clazz) { String retval = friendlyNameMap.get(clazz); if (retval == null) { retval = ""; Iterator<Class<?>> iter = decomposeClass(clazz).iterator(); boolean needComma = false; while (iter.hasNext()) { Class<?> constit = iter.next(); retval += needComma ? "," : ""; needComma = true; retval += constit.getName().substring(constit.getName().lastIndexOf('.') + 1); } friendlyNameMap.put(clazz, retval); } return retval; }
/** * Returns the simple class name for the given class or throws an exception if * there are more than one. * @param clazz the class * @return the simple class name */ public static synchronized String getSimpleClassName(Class<?> clazz) { String retval = simpleNameMap.get(clazz); if (retval == null) { Set<Class<?>> decomposedClass = Util.decomposeClass(clazz); if (decomposedClass.size() > 1) { throw new IllegalArgumentException("No simple name for class: " + Util.getFriendlyName(clazz)); } else { retval = decomposedClass.iterator().next().getName(); simpleNameMap.put(clazz, retval); } } return retval; }
/** * Returns the simple class name for the given class or throws an exception if * there are more than one. * @param clazz the class * @return the simple class name */ public static synchronized String getSimpleClassName(Class<?> clazz) { String retval = simpleNameMap.get(clazz); if (retval == null) { Set<Class<?>> decomposedClass = Util.decomposeClass(clazz); if (decomposedClass.size() > 1) { throw new IllegalArgumentException("No simple name for class: " + Util.getFriendlyName(clazz)); } else { retval = decomposedClass.iterator().next().getName(); simpleNameMap.put(clazz, retval); } } return retval; }
Set<Class<?>> classes = Util.decomposeClass(type); StringBuffer retval = new StringBuffer(); if (osb != null) {
private Vector<ClassAttributes> getClassAttributes(Model model, Class<?> baseClass) { Vector<ClassAttributes> attributes = decomposedClassesCache.get(baseClass); if (attributes == null) { LOG.info("decomposedClassesCache: No entry for " + baseClass + ", adding..."); attributes = new Vector<ClassAttributes>(); for (Class<?> cls : Util.decomposeClass(baseClass)) { ClassDescriptor cld = model.getClassDescriptorByName(cls.getName()); attributes.add(new ClassAttributes(cld.getUnqualifiedName(), cld .getAllAttributeDescriptors())); } decomposedClassesCache.put(baseClass, attributes); } return attributes; }
private Vector<ClassAttributes> getClassAttributes(Model model, Class<?> baseClass) { Vector<ClassAttributes> attributes = decomposedClassesCache.get(baseClass); if (attributes == null) { LOG.info("decomposedClassesCache: No entry for " + baseClass + ", adding..."); attributes = new Vector<ClassAttributes>(); for (Class<?> cls : Util.decomposeClass(baseClass)) { ClassDescriptor cld = model.getClassDescriptorByName(cls.getName()); attributes.add(new ClassAttributes(cld.getUnqualifiedName(), cld .getAllAttributeDescriptors())); } decomposedClassesCache.put(baseClass, attributes); } return attributes; }
/** * Returns the value of a public or protected Field of an Object given the field name * * @param o the Object * @param fieldName the name of the relevant Field * @return the value of the Field * @throws IllegalAccessException if the field is inaccessible */ public static Object getFieldValue(Object o, String fieldName) throws IllegalAccessException { try { return getGetter(o.getClass(), fieldName).invoke(o, new Object[] {}); } catch (Exception e) { String type = ""; try { type = " (a " + getFieldInfo(o.getClass(), fieldName).getGetter().getReturnType() .getName() + ")"; } catch (Exception e3) { type = " (available fields are " + getFieldInfos(o.getClass()).keySet() + ")"; } IllegalAccessException e2 = new IllegalAccessException("Couldn't get field \"" + Util.decomposeClass(o.getClass()) + "." + fieldName + "\"" + type); e2.initCause(e); throw e2; } }