public static Object[] isSimpleGeneric(Type type, ClassTypeResolver classTypeResolver) throws ModelDriverException { Object[] result = new Object[3]; result[0] = false; result[1] = null; result[2] = null; if (type.isArray() || type.isPrimitive() || !type.isParameterized() || (type.isParameterized() && type.getTypeArguments().size() != 1)) { return result; } Type<?> argument = ((List<Type>) type.getTypeArguments()).get(0); if (!isSimpleClass(argument)) { return result; } try { String outerClass = classTypeResolver.getFullTypeName(type.getName()); String argumentClass = classTypeResolver.getFullTypeName(argument.getName()); result[0] = true; result[1] = outerClass; result[2] = argumentClass; return result; } catch (ClassNotFoundException e) { throw new ModelDriverException( "Class could not be resolved for name: " + type.getName() + ". " + e.getMessage(), e); } }
/** * @return Return true if the given type can be managed by the driver, and subsequently by the UI. * <p>E.g. of managed types are: int, Integer, java.lang.Integer, org.kie.SomeClass, * List<Integer>, java.util.List<org.kie.SomeClass> * <p>e.g. of not manged types are: int[], java.util.List<List<String>>, List<Map<String, * org.kie.SomeClass>> */ public static boolean isManagedType(Type type, ClassTypeResolver classTypeResolver) throws ModelDriverException { // quickest checks first. if (type.isPrimitive()) { return true; } if (type.isArray()) { return false; } if (type.isParameterized() && type.getTypeArguments().size() > 1) { return false; } try { Class<?> clazz = classTypeResolver.resolveType(type.getName()); if (clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isMemberClass()) { return false; } if (type.isParameterized()) { Class<?> bag = classTypeResolver.resolveType(type.getName()); if (!Collection.class.isAssignableFrom(bag)) { return false; } return isSimpleClass(((List<Type>) type.getTypeArguments()).get(0)); } return true; } catch (ClassNotFoundException e) { throw new ModelDriverException( "Class could not be resolved for name: " + type.getName() + ". " + e.getMessage(), e); } }
public static boolean isSimpleClass(Type<?> type) { return !type.isArray() && !type.isPrimitive() && !type.isParameterized(); }