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 java.lang.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 and Description
    --- | ---
    `static class` | `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 and Description
    --- | ---
    `protected` | `BeanValueType()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected java.lang.IllegalArgumentException` | `conversionException(java.lang.Object value)`
    `static BeanValueType.Convertability` | `convertabilityFrom(java.lang.Class<?> klass, java.lang.Object value)` How well could `convertFrom` convert the value to the klass?
    `BeanValueType.Convertability` | `convertabilityFrom(java.lang.Object value)`
    `protected BeanValueType.Convertability` | `convertabilityToString()`
    `static BeanValueType.Convertability` | `convertabilityToString(java.lang.Class<?> klass)`
    `static java.lang.Object` | `convertFrom(java.lang.Class<?> klass, java.lang.Object value)` Convert the value into an object of the class.
    `ValueType` | `convertFrom(java.lang.Object value)`
    `static JavaScriptObject` | `convertMapToJavascriptObject(java.util.Map valueMap)`
    `static java.lang.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(java.lang.Object[] array)`
    `static JavaScriptObject` | `convertToJavaScriptObject(java.lang.Object value)` Converts the value to a JavaScriptObject.
    `static java.lang.String` | `convertToString(java.lang.Object value)` Converts the value to a string.
    `protected java.lang.String` | `doConvertToString(ValueType value)`
    `static BeanValueType<?>` | `getBeanValueType(java.lang.Class<?> valueType)`
    `protected abstract java.lang.Class<?>` | `getValueType()`
    `static boolean` | `isA(JavaScriptObject value, java.lang.String scClassName)` Is the SmartClient object an instance (or subclass) of the SmartClient class?
    `static boolean` | `isAssignableFrom(java.lang.Class<?> possibleSuperclass, java.lang.Class<?> possibleSubclass)` Can objects of the possible sub-class be assigned to the possible super-class?
    `static boolean` | `isAssignableFrom(java.lang.Class<?> klass, java.lang.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(java.lang.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(java.lang.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 Detail

    - #### BeanValueType

          protected BeanValueType()

  - ### Method Detail

    - #### getBeanValueType

          public static BeanValueType<?> getBeanValueType(java.lang.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(java.lang.Class<?> klass,
                                 java.lang.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:
        `java.lang.IllegalArgumentException` - If the Class represents an interface, and no BeanValueType subclass has been generated to handle it.

    - #### isAssignableFrom

          public static boolean isAssignableFrom(java.lang.Class<?> possibleSuperclass,
                                 java.lang.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:
        `java.lang.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,
                    java.lang.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 java.lang.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(java.lang.Class<?> klass,
                                                        java.lang.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:
        `java.lang.IllegalArgumentException` - If there is no BeanValueType subclass for the klass

    - #### convertFrom

          public static java.lang.Object convertFrom(java.lang.Class<?> klass,
                                     java.lang.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:
        `java.lang.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(java.lang.Class<?> klass)

    - #### convertToString

          public static java.lang.String convertToString(java.lang.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(java.lang.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(java.lang.Object[] array)

    - #### convertMapToJavascriptObject

          public static JavaScriptObject convertMapToJavascriptObject(java.util.Map valueMap)

    - #### convertToJavaScriptObject

          public static JavaScriptObject convertToJavaScriptObject(java.lang.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 java.lang.Class<?> getValueType()

    - #### isAssignableFrom

          protected abstract boolean isAssignableFrom(java.lang.Object value)

    - #### nullValue

          protected ValueType nullValue()

    - #### convertabilityToString

          protected BeanValueType.Convertability convertabilityToString()

    - #### doConvertToString

          protected java.lang.String doConvertToString(ValueType value)

    - #### convertabilityFrom

          public BeanValueType.Convertability convertabilityFrom(java.lang.Object value)

    - #### convertFrom

          public ValueType convertFrom(java.lang.Object value)

    - #### conversionException

          protected java.lang.IllegalArgumentException conversionException(java.lang.Object value)