public static interface BeanFactory.MetaFactory
BeanFactory
reflection mechanism.
Note: While this mechanism continues to work, there is
now an easier way to register classes for reflection, by annotating
them with the BeanFactory.Generate
annotation.
In order to use a BeanFactory
for a class, you need to
register it by generating a BeanFactory
subclass for the
class. You can use BeanFactory.CanvasMetaFactory
to scan the
class path and register every Canvas
subclass (including your
custom subclasses), or use BeanFactory.FormItemMetaFactory
to
regiser every FormItem
subclass. However, if you know that you only need to register some
classes for reflection, then you can use
BeanFactory.MetaFactory
instead (or, even more conveniently,
the BeanFactory.Generate
annotation).
Usage of BeanFactory.MetaFactory
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 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 the factory for.If you want, you can keep a reference to the results of the GWT.create()
,
and call the functions:
MyMetaFactory metaFactory = GWT.create(MyMetaFactory.class); BeanFactory<TileGrid> myTileGridFactory = myMetaFactory.getTileGridBeanFactory();
However, you don't have to do that ... you can ignore the results of GWT.create()
and just use the BeanFactory
static API:
... except that "TileGrid" would probably be a variable!GWT.create(MyMetaFactory.class); Object myGrid = BeanFactory.newInstance("TileGrid"); BeanFactory.setProperty(myGrid, "width", 207);
You can also use the generated classes in ComponentXML
,
by specifying the fully-qualified class name as the constructor for objects.
Note that the call to GWT.create()
must occur at run-time before
the factories are used. However, you can modularize by creating some factories
first and other factories later, as long as each factory is created before
being used.
BeanFactory.Generate