Package com.smartgwt.client.bean

# Class BeanValueType<ValueType>

java.lang.Object
com.smartgwt.client.bean.BeanValueType<ValueType>

Direct Known Subclasses:
  `ArrayValueType`, `BooleanValueType`, `DateValueType`, `InterfaceValueType`, `JsoWrapperValueType`, `NumberValueType`, `OtherValueType`, `StringValueType`

public abstract class BeanValueType<ValueType> extends Object
Class with static methods that help with various reflection-like tasks with respect to values used by `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

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `BeanValueType.Convertability`
  An enum used to indicate how well a BeanValueType can handle a conversion.
  `static interface`
  `BeanValueType.MetaFactory`
  Interface used to trigger the generation and registration of reflection metadata for argument types.

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `BeanValueType()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected IllegalArgumentException`
  `conversionException(Object value)`
  `static BeanValueType.Convertability`
  `convertabilityFrom(Class<?> klass, Object value)`
  How well could `convertFrom` convert the value to the klass?
  `BeanValueType.Convertability`
  `convertabilityFrom(Object value)`
  `protected BeanValueType.Convertability`
  `convertabilityToString()`
  `static BeanValueType.Convertability`
  `convertabilityToString(Class<?> klass)`
  `static Object`
  `convertFrom(Class<?> klass, Object value)`
  Convert the value into an object of the class.
  `ValueType`
  `convertFrom(Object value)`
  `static JavaScriptObject`
  `convertMapToJavascriptObject(Map valueMap)`
  `static Object`
  `convertToJava(JavaScriptObject obj)`
  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<?>`
  `getValueType()`
  `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, would `value instanceof Klass` return true (if we had the class literal to work with)?
  `protected abstract boolean`
  `isAssignableFrom(Object value)`
  `protected ValueType`
  `nullValue()`
  `static void`
  `registerBasicValueTypes()`
  Registers `BeanValueTypes` 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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### BeanValueType

    protected BeanValueType()

- ## Method Details

  - ### getBeanValueType

    public static BeanValueType<?> getBeanValueType(Class<?> valueType)

  - ### registerBeanValueType

    protected static void registerBeanValueType(BeanValueType beanValueType)

  - ### registerBasicValueTypes

    public static void registerBasicValueTypes()
    Registers `BeanValueTypes` 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 the `BeanValueType.MetaFactory` interface.

  - ### isAssignableFrom

    public static boolean isAssignableFrom(Class<?> klass, Object value)
    Can the value be assigned to the class? Or, to put it another way, would `value 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

    public static boolean isAssignableFrom(Class<?> possibleSuperclass, Class<?> possibleSubclass)
    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 assignment
      `possibleSubclass` - 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 use `isAssignableFrom(Class<?>, Object)` with the value to be assigned.

  - ### isA

    public static boolean isA(JavaScriptObject value, String scClassName)
    Is the SmartClient object an instance (or subclass) of the SmartClient class?
    Parameters:
      `value` - The SmartClient object
      `scClassName` - The SmartClient class name (e.g. "ListGrid")

  - ### convertToJava

    public static Object convertToJava(JavaScriptObject obj)
    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 for `BeanFactory` to work properly. Note that this method may return a `JavaScriptObject` -- either the value itself, or possibly a new `JavaScriptObject` constructed from a config block. In those cases, it may be that `convertFrom()` 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 a `JavaScriptObject`).

  - ### convertabilityFrom

    public static BeanValueType.Convertability convertabilityFrom(Class<?> klass, Object value)
    How well could `convertFrom` 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

    public static Object convertFrom(Class<?> klass, Object value)
    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

    public static BeanValueType.Convertability convertabilityToString(Class<?> klass)

  - ### convertToString

    public static String convertToString(Object value)
    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

    public static JavaScriptObject wrapInJavascriptArray(Object value)
    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 a `String`, 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

    public static JavaScriptObject convertToJavaScriptArray(Object[] array)

  - ### convertMapToJavascriptObject

    public static JavaScriptObject convertMapToJavascriptObject(Map valueMap)

  - ### convertToJavaScriptObject

    public static JavaScriptObject convertToJavaScriptObject(Object value)
    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

    protected abstract Class<?> getValueType()

  - ### isAssignableFrom

    protected abstract boolean isAssignableFrom(Object value)

  - ### nullValue

    protected ValueType nullValue()

  - ### convertabilityToString

    protected BeanValueType.Convertability convertabilityToString()

  - ### doConvertToString

    protected String doConvertToString(ValueType value)

  - ### convertabilityFrom

    public BeanValueType.Convertability convertabilityFrom(Object value)

  - ### convertFrom

    public ValueType convertFrom(Object value)

  - ### conversionException

    protected IllegalArgumentException conversionException(Object value)