This topic is about Java BeanUtils – Lazy DynaBeans.
Description
Lazy DynaBeans is an implementation of DynaBean, which gives the characteristics of Lazy List and Lazy Map this connects the properties of DynaClass. There are four types of Lazy DynaBeans:
- LazyDynaBean: It specifies lazy DynaBean that provides dynamically modified properties of names and data types.
- LazyDynaMap: It gives light weight implementation of DynaBean to map by using lazy map or list system.
- LazyDynaList: It provides list for DynaBean, Map’s or POJOS (Plain Old Java Object that specifies the normal java class).
- LazyDynaClass: It implements the MutableDynaClass interface.
The following are the features of Lazy DynaBeans:
- Lazy property addition: It is used by the Lazy beans to add property to DynaClass automatically when set method is called and it has capability to add or remove the DynaClass’s properties.
- Lazy List/Array growth: The Lazy list or array will grow automatically when an indexed property is not able to accommodate the index being set.
- Lazy List/Array instantiation: The indexed property getter and setter methods of DynaBean’s results in lazy list or array instantiation, if there is no existence of an indexed property. If an indexed property is not defined, then it will be added automatically to DynaClass and default List implementation instantiated.
- Lazy Map instantiation: The mapped property getter and setter methods of DynaBean’s results in lazy map instantiation, if there is no existence of mapped property. If mapped property is not defined, then it will be added automatically to DynaClass and default Map implementation instantiated.
- Lazy Bean instantiation: The LazyDynaBean will instantiates the bean using a default empty constructor, if DynaClass property is defined as DynaBean or regular bean and does not exist in the DynaBean.
LazyDynaBean
It is implementation of standard lazy bean which specifies the lazy DynaBean that provides dynamically modified properties of names and data types. It implements the MutableDynaClass interface by associating with the LazyDynaClass. The below simple code shows usage of LazyDynaBean by using getters or setters:
DynaBean dynaBean = new LazyDynaBean(); dynaBean.set("company", "Model"); // simple dynaBean.set("customer", "fname", "Steve"); // mapped dynaBean.set("customer", "lname", "Smith"); // mapped dynaBean.set("address", 0, addressLine1); // indexed dynaBean.set("address", 1, addressLine2); // indexed
LazyDynaMap
It gives light weight implementation of DynaBean to map by using lazy map or list system and it does not associates with properties of DynaClass. It itself implements the DynaClass interface and obtain the information of DynaClass from the map contents. LazyDynaMap creates its own Map by instantiating it or can be generated around an existing Map.
The below code shows creation of new map:
DynaBean dynaBean = new LazyDynaBean(); DynaBean dynaBean = new LazyDynaMap(); // create DynaBean dynaBean.set("company", "Model"); // simple dynaBean.set("customer", "fname", "Steve"); // mapped dynaBean.set("address", 0, addressLine1); // indexed Map demoMap = dynaBean.getMap() // retrieve the Map
The below code shows use of existing Map in DynaBean:
Map demoMap = .... // exisitng Map DynaBean dynaBean = new LazyDynaMap(demoMap); // wrap Map in DynaBean dynaBean.set("ford", "raptor"); // set properties
LazyDynaList
It provides list for DynaBean, Map’s or POJOS (Plain Old Java Object that specifies the normal java class). There are two main points of this class:
- It automatically grows and occupies the list with DynaBean, java.util.Map or POJOS to specify the Lazy List behavior.
- It provides easy way to put a Collection or Array into Lazy list and easy way to come out from the Lazy List.
LazyDynaClass
It implements the MutableDynaClass interface and extends the BasicDynaClass. It can be used as default DynaClass by LazyDynaBean and with other DynaBean implementations. There is nothing to with the DynaClass when you are using the LazyDynaBean.
The below code creates the LazyDynaClass:
MutableDynaClass dynaClass = new LazyDynaClass(); // create DynaClass dynaClass.add("price", java.lang.Integer.class); // add property dynaClass.add("orders", OrderBean[].class); // add indexed property dynaClass.add("orders", java.util.TreeMapp.class); // add mapped property DynaBean dynaBean = new LazyDynaBean(dynaClass); // Create DynaBean with associated DynaClass
The below code creates the LazyDynaBean and get the DynaClass:
DynaBean dynaBean = new LazyDynaBean(); // Create LazyDynaBean MutableDynaClass dynaClass = (MutableDynaClass)dynaBean.getDynaClass(); // get DynaClass dynaClass.add("price", java.lang.Integer.class); // add property dynaClass.add("exBeans", myPackage.MyBean[].class); // add 'array' indexed property dynaClass.add("exMap", java.util.TreeMapp.class); // add mapped property
In this topic we learned about Java BeanUtils – Lazy DynaBeans. To know more, Click Here.
Pingback: Java BeanUtils - WrapDynaBean - Adglob Infosystem Pvt Ltd