public static <T> T createConfigurable(Class<T> c, Dictionary<?, ?> properties) { Map<Object, Object> alt = new HashMap<>(); for (Enumeration<?> e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); alt.put(key, properties.get(key)); } return createConfigurable(c, alt); }
private Collection< ? > toCollection(Object o) { if (o instanceof Collection) return (Collection< ? >) o; if (o.getClass().isArray()) { if (o.getClass().getComponentType().isPrimitive()) { int length = Array.getLength(o); List<Object> result = new ArrayList<Object>(length); for (int i = 0; i < length; i++) { result.add(Array.get(o, i)); } return result; } return Arrays.asList((Object[]) o); } if (o instanceof String) { String s = (String) o; if (SPLITTER_P.matcher(s).find()) return Arrays.asList(s.split("\\|")); else return unescape(s); } return Arrays.asList(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) { if (method.getReturnType().isPrimitive() || Number.class.isAssignableFrom(method.getReturnType())) { o = "0"; } else return null; } return convert(method.getGenericReturnType(), o); }
@Override 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 static <T> T createConfigurable(Class<T> c, Dictionary< ? , ? > properties) { Map<Object,Object> alt = new HashMap<Object,Object>(); for (Enumeration< ? > e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); alt.put(key, properties.get(key)); } return createConfigurable(c, alt); }
@Override 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); }
private Collection< ? > toCollection(Object o) { if (o instanceof Collection) return (Collection< ? >) o; if (o.getClass().isArray()) { if (o.getClass().getComponentType().isPrimitive()) { int length = Array.getLength(o); List<Object> result = new ArrayList<Object>(length); for (int i = 0; i < length; i++) { result.add(Array.get(o, i)); } return result; } return Arrays.asList((Object[]) o); } if (o instanceof String) { String s = (String) o; if (SPLITTER_P.matcher(s).find()) return Arrays.asList(s.split("\\|")); else return unescape(s); } return Arrays.asList(o); }
public static <T> T createConfigurable(Class<T> c, Dictionary< ? , ? > properties) { Map<Object,Object> alt = new HashMap<Object,Object>(); for (Enumeration< ? > e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); alt.put(key, properties.get(key)); } return createConfigurable(c, alt); }
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 || rt == Boolean.class) return false; if (method.getReturnType().isPrimitive()) { o = "0"; } else return null; } return convert(method.getGenericReturnType(), o); }
private Collection< ? > toCollection(Object o) { if (o instanceof Collection) return (Collection< ? >) o; if (o.getClass().isArray()) { if (o.getClass().getComponentType().isPrimitive()) { int length = Array.getLength(o); List<Object> result = new ArrayList<Object>(length); for (int i = 0; i < length; i++) { result.add(Array.get(o, i)); } return result; } return Arrays.asList((Object[]) o); } if (o instanceof String) { String s = (String) o; if (SPLITTER_P.matcher(s).find()) return Arrays.asList(s.split("\\|")); else return unescape(s); } return Arrays.asList(o); }
public static <T> T createConfigurable(Class<T> c, Dictionary<?, ?> properties) { Map<Object,Object> alt = new HashMap<Object,Object>(); for( Enumeration<?> e = properties.keys(); e.hasMoreElements(); ) { Object key = e.nextElement(); alt.put(key, properties.get(key)); } return createConfigurable(c, alt); }
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); }
private Collection<?> toCollection(Object o) { if (o instanceof Collection) return (Collection<?>) o; if (o.getClass() .isArray()) { if (o.getClass() .getComponentType() .isPrimitive()) { int length = Array.getLength(o); List<Object> result = new ArrayList<>(length); for (int i = 0; i < length; i++) { result.add(Array.get(o, i)); } return result; } return Arrays.asList((Object[]) o); } if (o instanceof String) { String s = (String) o; if (SPLITTER_P.matcher(s) .find()) return Arrays.asList(s.split("\\|")); else return unescape(s); } return Arrays.asList(o); }
public static <T> T createConfigurable(Class<T> c, Dictionary< ? , ? > properties) { Map<Object,Object> alt = new HashMap<Object,Object>(); for (Enumeration< ? > e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); alt.put(key, properties.get(key)); } return createConfigurable(c, alt); }
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); }
private Collection<?> toCollection(Object o) { if (o instanceof Collection) return (Collection<?>) o; if (o.getClass() .isArray()) { if (o.getClass() .getComponentType() .isPrimitive()) { int length = Array.getLength(o); List<Object> result = new ArrayList<>(length); for (int i = 0; i < length; i++) { result.add(Array.get(o, i)); } return result; } return Arrays.asList((Object[]) o); } if (o instanceof String) { String s = (String) o; if (SPLITTER_P.matcher(s) .find()) return Arrays.asList(s.split("\\|")); else return unescape(s); } return Arrays.asList(o); }
public static <T> T createConfigurable(Class<T> c, Dictionary< ? , ? > properties) { Map<Object,Object> alt = new HashMap<Object,Object>(); for (Enumeration< ? > e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); alt.put(key, properties.get(key)); } return createConfigurable(c, alt); }
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); }
private Collection<?> toCollection(Object o) { if (o instanceof Collection) return (Collection<?>) o; if (o.getClass() .isArray()) { if (o.getClass() .getComponentType() .isPrimitive()) { int length = Array.getLength(o); List<Object> result = new ArrayList<>(length); for (int i = 0; i < length; i++) { result.add(Array.get(o, i)); } return result; } return Arrays.asList((Object[]) o); } if (o instanceof String) { String s = (String) o; if (SPLITTER_P.matcher(s) .find()) return Arrays.asList(s.split("\\|")); else return unescape(s); } return Arrays.asList(o); }
public static <T> T createConfigurable(Class<T> c, Dictionary<?, ?> properties) { Map<Object, Object> alt = new HashMap<>(); for (Enumeration<?> e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); alt.put(key, properties.get(key)); } return createConfigurable(c, alt); }