/** * 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(); }
/** * 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 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 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); }
/** * 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)getDynaClass(); }
/** * 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)getDynaClass(); }
/** * 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)getDynaClass(); }
/** * 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 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 * * @exception IllegalArgumentException if this is not a valid property * name for our DynaClass */ protected DynaProperty getDynaProperty(String name) { DynaProperty descriptor = getDynaClass().getDynaProperty(name); if (descriptor == null) { throw new IllegalArgumentException ("Invalid property name '" + name + "'"); } return (descriptor); }
/** * 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 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 * * @exception IllegalArgumentException if this is not a valid property * name for our DynaClass */ protected DynaProperty getDynaProperty(String name) { DynaProperty descriptor = getDynaClass().getDynaProperty(name); if (descriptor == null) { throw new IllegalArgumentException ("Invalid property name '" + name + "'"); } return (descriptor); }
/** * 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 * * @exception IllegalArgumentException if this is not a valid property * name for our DynaClass */ protected DynaProperty getDynaProperty(String name) { DynaProperty descriptor = getDynaClass().getDynaProperty(name); if (descriptor == null) { throw new IllegalArgumentException ("Invalid property name '" + name + "'"); } return (descriptor); }
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()]);
/** * 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); } } } }