public interface Reflection
Component XML
or
Component Schema
,
or for other purposes, such as for
autoChildren
or for
DataSourceField.setEditorType(Class)
,
you must first register the class with the
BeanFactory
reflection mechanism.
You can do this in onModuleLoad()
, or at some later point
before the constructor is used.
If you want to register Canvas
and all its subclasses found in the classpath (including your custom subclasses),
you can use the BeanFactory.CanvasMetaFactory
interface to do this automatically:
GWT.create(BeanFactory.CanvasMetaFactory.class);
Similarly, to register FormItem
and all its subclasses found in the classpath (including your custom subclasses),
you can use the BeanFactory.FormItemMetaFactory
.
GWT.create(BeanFactory.FormItemMetaFactory.class);
Alternatively, if only specific classes need to be instantiated and
configured dynamically, you can register just those classes by using the
BeanFactory.MetaFactory
interface instead.
Usage is most easily explained with an example. First, you define an
interface. (Note that it can be an inner interface.)
... and then you trigger the generation process:public interface MyMetaFactory extends BeanFactory.MetaFactory { BeanFactory<ListGrid> getListGridFactory(); BeanFactory<TileGrid> getTileGridBeanFactory(); }
GWT.create(MyMetaFactory.class);
Each function in the interface you define will result in the creation of
one registered BeanFactory
... so, in this case, we would end up with
bean factories for ListGrid
and TileGrid
. The rules
are as follows:
BeanFactory.MetaFactory
BeanFactory
,
with a generic type that is the class you want to register for reflection.
If there are only a limited number of classes which require dynamic
configuration, it will save code size to use the
BeanFactory.MetaFactory
interface to generate
factories for those specific types, rather than using
BeanFactory.CanvasMetaFactory
or
BeanFactory.FormItemMetaFactory
. Once a factory
is generated for a class, GWT's opportunities to prune dead code are more
limited for that class, since it cannot know what properties will be set or
retrieved at run-time.