public static Class getNestedPropertyType(DynaClass bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, ClassNotFoundException, NoSuchFieldException { // Resolve nested references while (resolver.hasNested(name)) { String next = resolver.next(name); if (resolver.isIndexed(next) || resolver.isMapped(next)) { String property = resolver.getProperty(next); Class<?> clazz = Class.forName(bean.getName()); Class<?> detectTypeParameter = detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1); bean = WrapDynaClass.createDynaClass(detectTypeParameter); return getNestedPropertyType(bean, resolver.remove(name)); } DynaProperty db = bean.getDynaProperty(next); bean = WrapDynaClass.createDynaClass(db.getType()); name = resolver.remove(name); } if (resolver.isMapped(name) || resolver.isIndexed(name)) { String property = resolver.getProperty(name); Class<?> clazz = Class.forName(bean.getName()); return detectTypeParameter(clazz, property, resolver.isIndexed(name) ? 0 : 1); } Class<?> type = bean.getDynaProperty(name).getType(); return type; }
/** * Return the value of a simple property with the specified name. * * @param name Name of the property whose value is to be retrieved * @exception IllegalArgumentException if there is no property of the specified name */ public Object get(String name) { if (!dynaClass.isReadable(name)) { return null; } Object value = null; try { value = PropertyUtils.getSimpleProperty(instance, name); } catch (Throwable t) { throw new RuntimeException("Failed getting property " + name, t); } return (value); }
/** * Return the value of a mapped property with the specified name, or <code>null</code> if there is * no value for the specified key. * * @param name Name of the property whose value is to be retrieved * @param key Key of the value to be retrieved * @exception IllegalArgumentException if there is no property of the specified name * @exception IllegalArgumentException if the specified property exists, but is not mapped */ public Object get(String name, String key) { if (!dynaClass.isReadable(name)) { return null; } Object value = null; try { value = PropertyUtils.getMappedProperty(instance, name, key); } catch (Throwable t) { throw new IllegalArgumentException("Property '" + name + "' has no mapped read method"); } return (value); }
/** * Return the value of an indexed property with the specified name. * * @param name Name of the property whose value is to be retrieved * @param index Index of the value to be retrieved * @exception IllegalArgumentException if there is no property of the specified name * @exception IllegalArgumentException if the specified property exists, but is not indexed * @exception IndexOutOfBoundsException if the specified index is outside the range of the * underlying property * @exception NullPointerException if no array or List has been initialized for this property */ public Object get(String name, int index) { if (!dynaClass.isReadable(name)) { return null; } Object value = null; try { value = PropertyUtils.getIndexedProperty(instance, name, index); } catch (IndexOutOfBoundsException e) { throw e; } catch (Throwable t) { throw new IllegalArgumentException("Property '" + name + "' has no indexed read method"); } return (value); }
/** * Construct a new <code>DynaBean</code> associated with the specified JavaBean instance. * * @param instance JavaBean instance to be wrapped */ public WrapDynaBean(Object instance) { super(); this.instance = instance; this.dynaClass = WrapDynaClass.createDynaClass(instance.getClass()); }
private WrapDynaClass getDynaClass(Object reference) { if (dynaClass == null && reference != null) { dynaClass = WrapDynaClass.createDynaClass(reference.getClass()); } return dynaClass; }
public ListContainer(Class<T> type) { backingList = new ArrayList<T>(); dynaClass = WrapDynaClass.createDynaClass(type); }
public ListContainer(Class<T> type, Collection<T> backingList) { dynaClass = WrapDynaClass.createDynaClass(type); setCollection(backingList); }