public static <T> T createConfigurable(Class<T> c, Map<?, ?> properties) { Object o = Proxy.newProxyInstance(c.getClassLoader(), new Class<?>[] { c }, new ConfigurableHandler(properties, c.getClassLoader())); return c.cast(o); }
Class<?> resultType = (Class<?>) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection<?> input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i));
Object convertArray(Type componentType, Object o) throws Exception { if (o instanceof String) { String s = (String) o; if (componentType == Byte.class || componentType == byte.class) return s.getBytes(UTF_8); if (componentType == Character.class || componentType == char.class) return s.toCharArray(); } Collection<?> input = toCollection(o); Class<?> componentClass = getRawClass(componentType); Object array = Array.newInstance(componentClass, input.size()); int i = 0; for (Object next : input) { Array.set(array, i++, convert(componentType, next)); } return array; }
public Object convert(Type type, Object o) throws Exception { if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
public Object convert(Type type, Object o) throws Exception { if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
public Object convert(Type type, Object o) throws Exception { if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
public Object convert(Type type, Object o) throws Exception { if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
public Object convert(Type type, Object o) throws Exception { if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
public Object convert(Type type, Object o) throws Exception { if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
public Object convert(Type type, Object o) throws Exception { if (type instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) type; return convert(pType, o); return convertArray(gType.getGenericComponentType(), o); return convertArray(resultType.getComponentType(), o);
Class<?> resultType = (Class<?>) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection<?> input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i)); Map<?, ?> input = toMap(o); if (resultType.isInterface()) { if (resultType == SortedMap.class) result.put(convert(keyType, entry.getKey()), convert(valueType, entry.getValue()));
Class<?> resultType = (Class<?>) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection<?> input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i)); Map<?, ?> input = toMap(o); if (resultType.isInterface()) { if (resultType == SortedMap.class) result.put(convert(keyType, entry.getKey()), convert(valueType, entry.getValue()));
Class< ? > resultType = (Class< ? >) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection< ? > input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i)); Map< ? , ? > input = toMap(o); if (resultType.isInterface()) { if (resultType == SortedMap.class) result.put(convert(keyType, entry.getKey()), convert(valueType, entry.getValue()));
Class< ? > resultType = (Class< ? >) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection< ? > input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i)); Map< ? , ? > input = toMap(o); if (resultType.isInterface()) { if (resultType == SortedMap.class) result.put(convert(keyType, entry.getKey()), convert(valueType, entry.getValue()));
Class< ? > resultType = (Class< ? >) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection< ? > input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i)); Map< ? , ? > input = toMap(o); if (resultType.isInterface()) { if (resultType == SortedMap.class) result.put(convert(keyType, entry.getKey()), convert(valueType, entry.getValue()));
Class< ? > resultType = (Class< ? >) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection< ? > input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i)); Map< ? , ? > input = toMap(o); if (resultType.isInterface()) { if (resultType == SortedMap.class) result.put(convert(keyType, entry.getKey()), convert(valueType, entry.getValue()));
Class<?> resultType = (Class<?>) pType.getRawType(); if (Collection.class.isAssignableFrom(resultType)) { Collection<?> input = toCollection(o); if (resultType.isInterface()) { if (resultType == Collection.class || resultType == List.class) result.add(convert(componentType, i)); Map<?, ?> input = toMap(o); if (resultType.isInterface()) { if (resultType == SortedMap.class) result.put(convert(keyType, entry.getKey()), convert(valueType, entry.getValue()));
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Meta.AD ad = method.getAnnotation(Meta.AD.class); String id = Configurable.mangleMethodName(method.getName()); if (ad != null && !ad.id().equals(Meta.NULL)) id = ad.id(); Object o = properties.get(id); if (o == null) { if (ad != null) { if (ad.required()) throw new IllegalStateException("Attribute is required but not set " + method.getName()); o = ad.deflt(); if (o.equals(Meta.NULL)) o = null; } } if (o == null) { Class< ? > rt = method.getReturnType(); if (rt == boolean.class ) return false; if (method.getReturnType().isPrimitive()) { o = "0"; } else return null; } return convert(method.getGenericReturnType(), o); }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Meta.AD ad = method.getAnnotation(Meta.AD.class); String id = Configurable.mangleMethodName(method.getName()); if (ad != null && !ad.id().equals(Meta.NULL)) id = ad.id(); Object o = properties.get(id); if (o == null) { if (ad != null) { if (ad.required()) throw new IllegalStateException("Attribute is required but not set " + method.getName()); o = ad.deflt(); if (o.equals(Meta.NULL)) o = null; } } if (o == null) { Class< ? > rt = method.getReturnType(); if (rt == boolean.class ) return false; if (method.getReturnType().isPrimitive()) { o = "0"; } else return null; } return convert(method.getGenericReturnType(), o); }