DynaBean should support nested dynamic structures
-------------------------------------------------

                 Key: BEANUTILS-405
                 URL: https://issues.apache.org/jira/browse/BEANUTILS-405
             Project: Commons BeanUtils
          Issue Type: New Feature
          Components: DynaBean
    Affects Versions: 1.8.3
            Reporter: Michael Vorburger


It would be useful if DynaBean would have support for "nested dynamic types", 
like e.g. EMF and SDO have.

Currently simple types (or the content types of indexed or mapped types) must 
"be a Java language primitive (such as int, a simple object (such as a 
java.lang.String), or a more complex object whose class is defined either by 
the Java language".  It turns out it wouldn't be very hard at all (I've tried 
and will attach a patch) to make some minor changes to relax this, and in 
addition also allow the following usage:

{noformat}      DynaProperty[] adrProps = new DynaProperty[]{
            new DynaProperty("zip", Long.class)
          };
        BasicDynaClass adrDynaClass = new BasicDynaClass("Address", adrProps);

        DynaProperty[] empProps = new DynaProperty[]{
            new DynaProperty("address",     java.util.Map.class,  adrDynaClass),
            new DynaProperty("subordinate", java.util.List.class, 
DynaClass.class),
            new DynaProperty("firstName",   String.class),
            new DynaProperty("lastName",    String.class),
            new DynaProperty("mainAddress", adrDynaClass),
            new DynaProperty("boss",        DynaClass.class)
          };
        BasicDynaClass empDynaClass = new BasicDynaClass("Employee", empProps);
        empDynaClass.getDynaProperty("boss").setDynaType(empDynaClass);
        empDynaClass.getDynaProperty("subordinate").setDynaType(empDynaClass);
        
        // ---
        
        DynaBean address = adrDynaClass.newInstance();
        address.set("zip", new Long(9016));
        DynaBean subordinate = empDynaClass.newInstance();
        subordinate.set("firstName", "Dino");
        DynaBean boss = empDynaClass.newInstance();
        boss.set("firstName", "Wilma");
        DynaBean employee = empDynaClass.newInstance();
        employee.set("firstName", "Fred");
        employee.set("lastName", "Flintstone");
        employee.set("mainAddress", address);
        employee.set("boss", boss);
        PropertyUtils.setProperty(employee, "boss.lastName", "Flintstone");
        employee.set("address", new HashMap());
        PropertyUtils.setProperty(employee, "address(home)", address);
        employee.set("subordinate", new ArrayList());
        ((List)employee.get("subordinate")).add(subordinate);
{noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to