this.elementDynaClass = dynaBean.getDynaClass(); } else { dynaBean = new WrapDynaBean(object); this.wrapDynaClass = (WrapDynaClass)dynaBean.getDynaClass(); this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType )) { this.elementType = ((LazyDynaMap)dynaBean).getMap().getClass();
/** * Creates a new instance of {@code WrapDynaBean}, associates it with the specified * JavaBean instance, and initializes the bean's {@code DynaClass}. Using this * constructor this {@code WrapDynaBean} instance can be assigned a class which has * been configured externally. If no {@code WrapDynaClass} is provided, a new one is * created using a standard mechanism. * * @param instance JavaBean instance to be wrapped * @param cls the optional {@code WrapDynaClass} to be used for this bean * @since 1.9 */ public WrapDynaBean(final Object instance, final WrapDynaClass cls) { this.instance = instance; this.dynaClass = (cls != null) ? cls : (WrapDynaClass) getDynaClass(); }
/** * Set the value of a simple property with the specified name. * * @param name Name of the property whose value is to be set * @param value Value to which this property is to be set * * @throws ConversionException if the specified value cannot be * converted to the type required for this property * @throws IllegalArgumentException if there is no property * of the specified name * @throws NullPointerException if an attempt is made to set a * primitive property to null */ public void set(final String name, final Object value) { try { getPropertyUtils().setSimpleProperty(instance, name, value); } catch (final InvocationTargetException ite) { final Throwable cause = ite.getTargetException(); throw new IllegalArgumentException ("Error setting property '" + name + "' nested exception -" + cause); } catch (final Throwable t) { throw new IllegalArgumentException ("Error setting property '" + name + "', exception - " + t); } }
this.elementDynaBeanType = dynaBean.getClass(); if (WrapDynaBean.class.isAssignableFrom(elementDynaBeanType)) { this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); this.wrapDynaClass = (WrapDynaClass)elementDynaClass; } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType)) {
/** * <p>Instantiates a new standard JavaBean instance associated with * this DynaClass and return it wrapped in a new WrapDynaBean * instance. <strong>NOTE</strong> the JavaBean should have a * no argument constructor.</p> * * <strong>NOTE</strong> - Most common use cases should not need to use * this method. It is usually better to create new * <code>WrapDynaBean</code> instances by calling its constructor. * For example:</p> * <code><pre> * Object javaBean = ...; * DynaBean wrapper = new WrapDynaBean(javaBean); * </pre></code> * <p> * (This method is needed for some kinds of <code>DynaBean</code> framework.) * </p> * * @return A new <code>DynaBean</code> instance * @throws IllegalAccessException if the Class or the appropriate * constructor is not accessible * @throws InstantiationException if this Class represents an abstract * class, an array class, a primitive type, or void; or if instantiation * fails for some other reason */ public DynaBean newInstance() throws IllegalAccessException, InstantiationException { return new WrapDynaBean(getBeanClass().newInstance()); }
/** * Will decompose only if the Object is Serializable * @param o object to decompose * @param container Serializable container * @param alreadyDecomposed hashmap of decomposed objects */ @Override void decomposeInto(final Object o, final Serializable container, final IdentityHashMap<Object, Serializable> alreadyDecomposed) { LazyDynaBean decomposed = (LazyDynaBean)container; WrapDynaBean bean = new WrapDynaBean(o); WrapDynaClass dynaClass = (WrapDynaClass)bean.getDynaClass(); for (DynaProperty property : dynaClass.getDynaProperties()) { String name = property.getName(); Method readMethod = dynaClass.getPropertyDescriptor(name).getReadMethod(); if (MethodUtils.getAccessibleMethod(readMethod) != null) { Object beanProperty; try { beanProperty = bean.get(name); } catch (RuntimeException e) { throw new RuntimeException("Unable to decompose " + o.getClass().getName() + "." + name, e); } Serializable decomposedProperty = _delegate.decompose(beanProperty, alreadyDecomposed); decomposed.set(name, decomposedProperty); } } } }
WrapDynaBean wrapDynaBean=new WrapDynaBean(new A()); DynaProperty[] dynaProperties = wrapDynaBean.getDynaClass().getDynaProperties(); List<Object> objects=new ArrayList<>(); for (DynaProperty dynaProperty : dynaProperties) { System.out.println(dynaProperty.getName()+" = "+wrapDynaBean.get(dynaProperty.getName())); objects.add(wrapDynaBean.get(dynaProperty.getName())); } Object[] theArrayYouWant=objects.toArray(new Object[objects.size()]);
this.elementDynaBeanType = dynaBean.getClass(); if (WrapDynaBean.class.isAssignableFrom(elementDynaBeanType)) { this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); this.wrapDynaClass = (WrapDynaClass)elementDynaClass; } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType)) {
/** * <p>Instantiates a new standard JavaBean instance associated with * this DynaClass and return it wrapped in a new WrapDynaBean * instance. <strong>NOTE</strong> the JavaBean should have a * no argument constructor.</p> * * <strong>NOTE</strong> - Most common use cases should not need to use * this method. It is usually better to create new * <code>WrapDynaBean</code> instances by calling its constructor. * For example:</p> * <code><pre> * Object javaBean = ...; * DynaBean wrapper = new WrapDynaBean(javaBean); * </pre></code> * <p> * (This method is needed for some kinds of <code>DynaBean</code> framework.) * </p> * * @return A new <code>DynaBean</code> instance * @throws IllegalAccessException if the Class or the appropriate * constructor is not accessible * @throws InstantiationException if this Class represents an abstract * class, an array class, a primitive type, or void; or if instantiation * fails for some other reason */ public DynaBean newInstance() throws IllegalAccessException, InstantiationException { return new WrapDynaBean(getBeanClass().newInstance()); }
this.elementDynaClass = dynaBean.getDynaClass(); } else { dynaBean = new WrapDynaBean(object); this.wrapDynaClass = (WrapDynaClass)dynaBean.getDynaClass(); this.elementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); } else if (LazyDynaMap.class.isAssignableFrom(elementDynaBeanType )) { this.elementType = ((LazyDynaMap)dynaBean).getMap().getClass();
elem = get(i); } else { elem = ((WrapDynaBean) get(i)).getInstance();
/** * Creates a {@code DynaBean} instance which wraps the passed in bean. * * @param bean the bean to be wrapped (must not be <b>null</b>) * @return a {@code DynaBean} wrapping the passed in bean * @throws IllegalArgumentException if the bean is <b>null</b> * @since 2.0 */ public static DynaBean createWrapDynaBean(final Object bean) { if (bean == null) { throw new IllegalArgumentException("Bean must not be null!"); } final WrapDynaClass dynaClass = WrapDynaClass.createDynaClass(bean.getClass(), BEAN_UTILS_BEAN.getPropertyUtils()); return new WrapDynaBean(bean, dynaClass); }
/** * Creates a new instance of {@code WrapDynaBean}, associates it with the specified * JavaBean instance, and initializes the bean's {@code DynaClass}. Using this * constructor this {@code WrapDynaBean} instance can be assigned a class which has * been configured externally. If no {@code WrapDynaClass} is provided, a new one is * created using a standard mechanism. * * @param instance JavaBean instance to be wrapped * @param cls the optional {@code WrapDynaClass} to be used for this bean * @since 1.9 */ public WrapDynaBean(final Object instance, final WrapDynaClass cls) { this.instance = instance; this.dynaClass = (cls != null) ? cls : (WrapDynaClass) getDynaClass(); }
/** * Return the value of a simple property with the specified name. * * @param name Name of the property whose value is to be retrieved * @return The property's value * * @throws IllegalArgumentException if there is no property * of the specified name */ public Object get(final String name) { Object value = null; try { value = getPropertyUtils().getSimpleProperty(instance, name); } catch (final InvocationTargetException ite) { final Throwable cause = ite.getTargetException(); throw new IllegalArgumentException ("Error reading property '" + name + "' nested exception - " + cause); } catch (final Throwable t) { throw new IllegalArgumentException ("Error reading property '" + name + "', exception - " + t); } return (value); }
dynaBean = (DynaBean)element; } else { dynaBean = new WrapDynaBean(element); newElementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); } else if (LazyDynaMap.class.isAssignableFrom(newDynaBeanType)) { newElementType = ((LazyDynaMap)dynaBean).getMap().getClass();
elem = get(i); } else { elem = ((WrapDynaBean) get(i)).getInstance();
/** * Construct a new <code>BeanValidatorForm</code> with the specified bean. */ public BeanValidatorForm(Object bean) { if (bean instanceof DynaBean) { dynaBean = (DynaBean)bean; } else { dynaBean = new WrapDynaBean(bean); } }
/** * Return the property descriptor for the specified property name. * * @param name Name of the property for which to retrieve the descriptor * @return The descriptor for the specified property * * @throws IllegalArgumentException if this is not a valid property * name for our DynaClass */ protected DynaProperty getDynaProperty(final String name) { final DynaProperty descriptor = getDynaClass().getDynaProperty(name); if (descriptor == null) { throw new IllegalArgumentException ("Invalid property name '" + name + "'"); } return (descriptor); }
/** * Return the value of a simple property with the specified name. * * @param name Name of the property whose value is to be retrieved * @return The property's value * * @throws IllegalArgumentException if there is no property * of the specified name */ public Object get(final String name) { Object value = null; try { value = getPropertyUtils().getSimpleProperty(instance, name); } catch (final InvocationTargetException ite) { final Throwable cause = ite.getTargetException(); throw new IllegalArgumentException ("Error reading property '" + name + "' nested exception - " + cause); } catch (final Throwable t) { throw new IllegalArgumentException ("Error reading property '" + name + "', exception - " + t); } return (value); }
dynaBean = (DynaBean)element; } else { dynaBean = new WrapDynaBean(element); newElementType = ((WrapDynaBean)dynaBean).getInstance().getClass(); } else if (LazyDynaMap.class.isAssignableFrom(newDynaBeanType)) { newElementType = ((LazyDynaMap)dynaBean).getMap().getClass();