Uploaded image for project: 'Commons BeanUtils'
  1. Commons BeanUtils
  2. BEANUTILS-405

DynaBean should support nested dynamic structures

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.8.3
    • 2.0.0
    • DynaBean
    • None

    Description

      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:

          	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);
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              vorburger Michael Vorburger
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: