Often you might like to get access to information about a DynamicBean that has not yet been instantiated. For instance, you might have a DynamicBean based on JDBC ResultSets. You want to know what properties a ResultSet for some query might have. Using the above techniques, there is no way to do this; where would the DynamicBeanInfo come from?

You might 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 the 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 is Query.class.

After the 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—that is, 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 might, for instance, call DynamicBeans.getBeanInfoFromType(Date.class), and the result is a DynamicBeanInfo describing an instance of Date. This is the same result you get by calling DynamicBeans.getBeanInfo() on an instance of Date.


Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices