Often you might like to get access to information about a DynamicBean
that has not yet been instantiated. For instance, imagine that you have a DynamicBean
based on JDBC ResultSets
. You might like to know what properties a ResultSet
for some query would have if the query took place. Using the above techniques, there’s no way to do this; where would the DynamicBeanInfo
come from?
Imagine that you have a Query
class or interface, which describes a query that generates a ResultSet
when executed. It would be nice to have a way to get a DynamicBeanInfo
from the Query
without executing it. We’d like to use the Query
(apart from its other functions) as a “dynamic type”: it can provide information about the dynamic beans that it is capable of generating.
Dynamic Beans provides an interface called DynamicBeanTyper
. It contains a single method:
public DynamicBeanInfo getBeanInfoFromType(Object pDescription)
throws IntrospectionException;
The purpose of this method is to return a DynamicBeanInfo
from an object (such as our imagined Query
) that plays the role of a dynamic type. You register a DynamicBeanTyper
by calling DynamicBeans.registerBeanTyper(Class, DynamicBeanTyper)
. The class parameter is the class of a dynamic type, not the class of a DynamicBean
. In this example, it would be Query.class
.
Once our example DynamicBeanTyper
is registered, the static method DynamicBeans.getBeanInfoFromType(Object)
can be used to obtain a DynamicBeanInfo
for any Query
.
One final, useful twist: instances of java.lang.Class
(i.e. static types) act as dynamic types. In other words, there is a DynamicBeanTyper
registered for Class.class
. Its function is to return a DynamicBeanInfo
that describes an instance of the given class, as analyzed by JavaBeans introspection. You could, for instance, call DynamicBeans.getBeanInfoFromType(Date.class)
, and the result would be a DynamicBeanInfo
describing an instance of Date
. This is exactly the same result you would get by calling DynamicBeans.getBeanInfo()
on an instance of Date
.