public static interface BeanValueType.MetaFactory
In order to use BeanValueType
to convert values to a type, you
need to create the correct kind of BeanValueType
for each
type, which sometimes involves code generation. This is all automatic
for types required by BeanFactory
. However, if want to use
BeanValueType
outside of BeanFactory
, then you
can use BeanValueType.MetaFactory
for specific types.
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 BeanValueType.MetaFactory { BeanValueType<Integer[]> getIntegerArrayValueType(); BeanValueType<Canvas> findMeTheCanvasValueType(); }
GWT.create(MyMetaFactory.class);
Each function in the interface you define will result in the creation
of the BeanValueType
for one type ... so, in this case, we
would end up with BeanValueTypes
for Integer arrays and
Canvas. The rules are as follows:
BeanValueType.MetaFactory
BeanValueType
,
with a generic type that is the type you want to be able to convert to.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); BeanValueType<Integer[]> integerArrayType = myMetaFactory.getIntegerArrayValueType(); Integer[] intArray = integerArrayType.convertFrom(new String[] {"7", "8"});
However, you don't have to do that ... you can ignore the results of
GWT.create()
and just use the BeanValueType
static
API:
GWT.create(MyMetaFactory.class); Integer[] intArray = BeanValueType.convertFrom(Integer[].class, new String[] {"7", "8"});
Note that the call to GWT.create()
must occur at run-time
before the types are used. However, you can modularize by creating some
types first and others later, as long as each BeanValueType
is created before being used.
If you just need to convert to basic types -- int, long, float,
double, boolean, Integer, Long, Float, Double, Boolean and String, then
you can call BeanValueType.registerBasicValueTypes()
instead of
using GWT.create()
.