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.
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 annotating
them with the BeanFactory.Generate
annotation instead. For instance:
@BeanFactory.Generate public class MyCanvas extends Canvas { ... }
For framework classes (where you cannot annotate the class directly), you can supply an array of Class literals to the annotation. For instance:
@BeanFactory.Generate({Canvas.class, TreeGrid.class}) public interface EmptyInterface { ... }
When you supply an array of class literals, the class you annotate
(here EmptyInterface
) will not itself have a
BeanFactory generated for it. Thus, you can use an empty inner
interface for this purpose.
If there are only a limited number of classes which require dynamic
configuration, it will save code size to use the
BeanFactory.Generate
annotation 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.