Class BeanValueType<ValueType>
- Direct Known Subclasses:
ArrayValueType
,BooleanValueType
,DateValueType
,InterfaceValueType
,JsoWrapperValueType
,NumberValueType
,OtherValueType
,StringValueType
BeanFactories
(that is, the
return types of getters, and the parameter types of setters).
The primary interface is through the static methods. In some cases,
generated subclasses are required in order to work around GWT's limited
reflection capabilities. Those classes are automatically generated by the by
the BeanFactory
generator when necessary. If you want to use
BeanValueType
outside of BeanFactory
, then you'll
need to use the BeanValueType.MetaFactory
interface to register
types.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
An enum used to indicate how well a BeanValueType can handle a conversion.static interface
Interface used to trigger the generation and registration of reflection metadata for argument types. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected IllegalArgumentException
conversionException
(Object value) static BeanValueType.Convertability
convertabilityFrom
(Class<?> klass, Object value) How well couldconvertFrom
convert the value to the klass?convertabilityFrom
(Object value) protected BeanValueType.Convertability
static BeanValueType.Convertability
convertabilityToString
(Class<?> klass) static Object
convertFrom
(Class<?> klass, Object value) Convert the value into an object of the class.convertFrom
(Object value) static JavaScriptObject
convertMapToJavascriptObject
(Map valueMap) static Object
Performs basic conversion from a JavaScriptObject to an equivalent Java value, without taking into account any particularly desired Java types.static JavaScriptObject
convertToJavaScriptArray
(Object[] array) static JavaScriptObject
convertToJavaScriptObject
(Object value) Converts the value to a JavaScriptObject.static String
convertToString
(Object value) Converts the value to a string.protected String
doConvertToString
(ValueType value) static BeanValueType<?>
getBeanValueType
(Class<?> valueType) protected abstract Class<?>
static boolean
isA
(JavaScriptObject value, String scClassName) Is the SmartClient object an instance (or subclass) of the SmartClient class?static boolean
isAssignableFrom
(Class<?> possibleSuperclass, Class<?> possibleSubclass) Can objects of the possible sub-class be assigned to the possible super-class?static boolean
isAssignableFrom
(Class<?> klass, Object value) Can the value be assigned to the class? Or, to put it another way, wouldvalue instanceof Klass
return true (if we had the class literal to work with)?protected abstract boolean
isAssignableFrom
(Object value) protected ValueType
static void
RegistersBeanValueTypes
for boolean, double, float, long, Boolean, Double, Float, Long, Number, and String.protected static void
registerBeanValueType
(BeanValueType beanValueType) static JavaScriptObject
wrapInJavascriptArray
(Object value) Converts the value to a JavaScriptObject, and wraps it in a JavaScript array.
-
Constructor Details
-
BeanValueType
protected BeanValueType()
-
-
Method Details
-
getBeanValueType
-
registerBeanValueType
-
registerBasicValueTypes
public static void registerBasicValueTypes()RegistersBeanValueTypes
for boolean, double, float, long, Boolean, Double, Float, Long, Number, and String.This is not automatic in order to allow for more dead-code elimination if not being used.
If you need
BeanValueTypes
for other types, you can register them via theBeanValueType.MetaFactory
interface. -
isAssignableFrom
Can the value be assigned to the class? Or, to put it another way, wouldvalue instanceof Klass
return true (if we had the class literal to work with)?- Parameters:
klass
- The Class to be assigned to.value
- The value to be assigned- Throws:
IllegalArgumentException
- If the Class represents an interface, and no BeanValueType subclass has been generated to handle it.
-
isAssignableFrom
Can objects of the possible sub-class be assigned to the possible super-class?Like
Class.assignableFrom()
.- Parameters:
possibleSuperclass
- The possible super-class, or lhs of the assignmentpossibleSubclass
- The possible sub-class, or rhs of the assignment- Throws:
IllegalArgumentException
- If one of the classes is an interface and the other is not. In that case, you need to useisAssignableFrom(Class<?>, Object)
with the value to be assigned.
-
isA
Is the SmartClient object an instance (or subclass) of the SmartClient class?- Parameters:
value
- The SmartClient objectscClassName
- The SmartClient class name (e.g. "ListGrid")
-
convertToJava
Performs basic conversion from a JavaScriptObject to an equivalent Java value, without taking into account any particularly desired Java types.This is similar to
JSOHelper.convertToJava
, but has several differences which are needed forBeanFactory
to work properly. Note that this method may return aJavaScriptObject
-- either the value itself, or possibly a newJavaScriptObject
constructed from a config block. In those cases, it may be thatconvertFrom()
can still do some further conversion on the return value, since it can take into account opportunities for conversion that are specific to the desired type. In other words, this is a generic conversion function.- Parameters:
object
- A javascript value- Returns:
- A generic conversion to an
Object
(which may still be aJavaScriptObject
).
-
convertabilityFrom
How well couldconvertFrom
convert the value to the klass?This is used to choose the best setter amongst multiple setters, if there are multiple setters available.
- Parameters:
klass
- The desired class to convert to.value
- The value to be converted.- Returns:
- A constant indicating how well the conversion could be performed.
- Throws:
IllegalArgumentException
- If there is no BeanValueType subclass for the klass
-
convertFrom
Convert the value into an object of the class.Note that not all conversions are actually supported ... you can check with
convertabilityFrom()
. The target classes which are supported are generally the classes which are used as value types in properties of BeanFactories that have been generated. The values supported depend on the target class.- Parameters:
klass
- The class that you want to convert to.value
- The value that you want to convert.- Returns:
- The converted value.
- Throws:
IllegalArgumentException
- If there is no BeanValueType subclass for the klass, or if the BeanValueType is unable to convert the value.
-
convertabilityToString
-
convertToString
Converts the value to a string.Of course, you can always call
Object.toString()
. However, a BeanValueType subclass might implement a different strategy.- Parameters:
value
- The value to convert.- Returns:
- A string representing the value.
-
wrapInJavascriptArray
Converts the value to a JavaScriptObject, and wraps it in a JavaScript array. The wrapping avoids problems with declaring a return type for generic Javascript values. The array is always a JavaScriptObject. If the converted value were returned directly, then in development mode it could be auto-converted back to aString
, or a primitive numeric type, causing type errors no matter how the return value is declared here.- Parameters:
value
- Value to convert- Returns:
- A JavaScriptObject wrapped in a Javascript array
-
convertToJavaScriptArray
-
convertMapToJavascriptObject
-
convertToJavaScriptObject
Converts the value to a JavaScriptObject. Note that not all values will convert to JavaScriptObject, becuase the JSNI glue code will auto-convert them back. This returns values only when they really do convert to JavaScriptObject (so, not strings, or numbers).- Parameters:
value
- Value to convert- Returns:
- A JavaScriptObject
-
getValueType
-
isAssignableFrom
-
nullValue
-
convertabilityToString
-
doConvertToString
-
convertabilityFrom
-
convertFrom
-
conversionException
-