com.smartgwt.client.bean

## Class BeanFactory<BeanClass>

- java.lang.Object
- - com.smartgwt.client.bean.BeanFactory<BeanClass>

- Direct Known Subclasses:
    BeanFactoryForBaseClass, BeanFactoryForBaseWidget, BeanFactoryForDataClass

      public abstract class BeanFactory<BeanClass>
      extends java.lang.Object

  Utility class for creating objects and setting properties at run-time via reflection-like mechanisms.

  Subclasses must be generated for each `Class` you want to use. To trigger the generation of subclasses, see the documentation on `registering classes for reflection`.

  Once the appropriate subclass has been created, you can use the class via the static methods.

  For the moment, this class only works with subclasses of `BaseWidget` or `FormItem`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `BeanFactory.AnnotationMetaFactory`
    `static interface` | `BeanFactory.CanvasMetaFactory` Interface used to trigger the generation and registration of reflection metadata for `Canvas` and all its subclasses found in the classpath (including your custom subclasses).
    `static interface` | `BeanFactory.FormItemMetaFactory` Interface used to trigger the generation and registration of reflection metadata for `FormItem` and all its subclasses found in the classpath (including your custom subclasses).
    `static interface` | `BeanFactory.FrameworkClass`
    `static interface` | `BeanFactory.Generate` Annotation which will trigger the generation of BeanFactories.
    `static interface` | `BeanFactory.MetaFactory` An interface which you can extend in order to register classes with the `BeanFactory` reflection mechanism.
    `static interface` | `BeanFactory.ScClassName`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.util.Map<java.lang.String,BeanProperty<BeanClass>>` | `properties`
    `protected com.google.gwt.core.client.JavaScriptObject` | `sgwtFactory`
    `protected BeanFactory` | `superclassFactory`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `BeanFactory()` The constructor is protected because you should not create BeanFactory instances directly.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `applyFactoryProperties(BeanClass bean)`
    `static void` | `clearFactoryProperties()`
    `protected BeanFactory<?>` | `createSuperclassFactory()`
    `abstract com.google.gwt.core.client.JavaScriptObject` | `doGetOrCreateJsObj(java.lang.Object bean)`
    `java.lang.Object` | `doGetProperty(java.lang.Object bean, java.lang.String propertyName)`
    `java.lang.String` | `doGetPropertyAsString(java.lang.Object bean, java.lang.String propertyName)`
    `protected abstract BeanClass` | `doNewInstance()`
    `abstract void` | `doSetJsObj(java.lang.Object bean, com.google.gwt.core.client.JavaScriptObject jsObj)`
    `void` | `doSetProperties(java.lang.Object bean, java.util.Map<java.lang.String,java.lang.Object> properties)`
    `void` | `doSetProperty(java.lang.Object bean, java.lang.String propertyName, java.lang.Object value)`
    `java.lang.String[]` | `getAttributes()`
    `static java.lang.String[]` | `getAttributes(java.lang.Class<?> beanClass)` Gets an array of the names of the properties of a class.
    `static java.lang.String[]` | `getAttributes(java.lang.String beanClassName)` Gets an array of the names of the properties of a class.
    `abstract java.lang.Class<BeanClass>` | `getBeanClass()`
    `java.lang.String` | `getBeanClassName()`
    `java.lang.String` | `getDefaultScClassName()`
    `static java.lang.String` | `getDefaultScClassName(java.lang.Class<?> beanClass)` Gets the default scClassName for the class.
    `static BeanFactory<?>` | `getFactory(java.lang.Class<?> klass)`
    `static BeanFactory<?>` | `getFactory(java.lang.Object object)`
    `static BeanFactory<?>` | `getFactory(java.lang.String className)`
    `static java.util.Map<java.lang.String,java.lang.Object>` | `getFactoryProperties()`
    `static java.lang.Class<?>` | `getFactoryPropertiesClass()`
    `protected abstract java.lang.Object` | `getJavascriptProperty(BeanClass bean, java.lang.String propertyName)`
    `protected abstract com.google.gwt.core.client.JsArray<com.google.gwt.core.client.JavaScriptObject>` | `getMethods()`
    `static com.google.gwt.core.client.JavaScriptObject` | `getOrCreateJsObj(java.lang.Object bean)`
    `protected abstract BeanProperty<BeanClass>[]` | `getProperties(com.google.gwt.core.client.JsArray<com.google.gwt.core.client.JavaScriptObject> methods)`
    `static java.lang.Object` | `getProperty(java.lang.Object bean, java.lang.String property)` Gets a property of a bean.
    `static java.lang.String` | `getPropertyAsString(java.lang.Object bean, java.lang.String property)` Gets a property of a bean as a String.
    `static com.google.gwt.core.client.JavaScriptObject` | `getSGWTModule()`
    `protected java.lang.Class` | `getSuperclass()`
    `abstract boolean` | `isFactoryCreated(BeanClass bean)`
    `boolean` | `isFrameworkClass()`
    `static boolean` | `isFrameworkClass(java.lang.Class<?> beanClass)` Indicates whether the class is defined by the SmartGWT framework.
    `BeanClass` | `newInstance()`
    `static java.lang.Object` | `newInstance(java.lang.Class<?> klass)` Create an instance based on the provided class object.
    `static java.lang.Object` | `newInstance(java.lang.Class<?> klass, com.google.gwt.core.client.JavaScriptObject properties)` Create an instance based on the provided class object, and apply the provided properties to it.
    `static java.lang.Object` | `newInstance(java.lang.Class<?> klass, java.util.Map<java.lang.String,java.lang.Object> properties)` Create an instance based on the provided class object, and apply the provided properties to it.
    `BeanClass` | `newInstance(com.google.gwt.core.client.JavaScriptObject properties)`
    `BeanClass` | `newInstance(java.util.Map<java.lang.String,java.lang.Object> properties)`
    `static java.lang.Object` | `newInstance(java.lang.String className)` Create an instance based on the provided class name.
    `static java.lang.Object` | `newInstance(java.lang.String className, com.google.gwt.core.client.JavaScriptObject properties)` Create an instance based on the provided class name, and apply the provided properties to it.
    `static java.lang.Object` | `newInstance(java.lang.String className, java.util.Map<java.lang.String,java.lang.Object> properties)` Create an instance based on the provided class name, and apply the provided properties to it.
    `protected static java.lang.IllegalStateException` | `noFactoryException(java.lang.Class<?> klass)`
    `protected static java.lang.IllegalStateException` | `noFactoryException(java.lang.String name)`
    `void` | `registerClassNameWithSGWTFactory()`
    `protected static void` | `registerFactory(BeanFactory<?> factory)`
    `protected abstract void` | `registerValueTypes()`
    `protected abstract void` | `setJavascriptProperty(BeanClass bean, java.lang.String propertyName, java.lang.Object value)`
    `static void` | `setJsObj(java.lang.Object bean, com.google.gwt.core.client.JavaScriptObject jsObj)`
    `static void` | `setProperties(java.lang.Object bean, java.util.Map<java.lang.String,java.lang.Object> properties)` Applies a Map of property names and values to a bean.
    `static void` | `setProperty(java.lang.Object bean, java.lang.String property, java.lang.Object value)` Sets a property of a bean to a value.
    `protected void` | `triggerStaticInitializers()`

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

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

- - ### Field Detail

    - #### superclassFactory

          protected BeanFactory superclassFactory

    - #### properties

          protected java.util.Map<java.lang.String,BeanProperty<BeanClass>> properties

    - #### sgwtFactory

          protected com.google.gwt.core.client.JavaScriptObject sgwtFactory

  - ### Constructor Detail

    - #### BeanFactory

          protected BeanFactory()

      The constructor is protected because you should not create BeanFactory instances directly. Instead, use `BeanFactory.MetaFactory`, `BeanFactory.CanvasMetaFactory` or `BeanFactory.FormItemMetaFactory` to create bean factories, and then use the static methods on BeanFactory.
      See Also:
        `BeanFactory.MetaFactory`, `BeanFactory.CanvasMetaFactory`

  - ### Method Detail

    - #### getSGWTModule

          public static com.google.gwt.core.client.JavaScriptObject getSGWTModule()

    - #### getFactoryProperties

          public static java.util.Map<java.lang.String,java.lang.Object> getFactoryProperties()

    - #### clearFactoryProperties

          public static void clearFactoryProperties()

    - #### getFactoryPropertiesClass

          public static java.lang.Class<?> getFactoryPropertiesClass()

    - #### getFactory

          public static BeanFactory<?> getFactory(java.lang.String className)

    - #### getFactory

          public static BeanFactory<?> getFactory(java.lang.Class<?> klass)

    - #### getFactory

          public static BeanFactory<?> getFactory(java.lang.Object object)

    - #### registerFactory

          protected static void registerFactory(BeanFactory<?> factory)

    - #### noFactoryException

          protected static java.lang.IllegalStateException noFactoryException(java.lang.String name)

    - #### noFactoryException

          protected static java.lang.IllegalStateException noFactoryException(java.lang.Class<?> klass)

    - #### newInstance

          public static java.lang.Object newInstance(java.lang.String className)

      Create an instance based on the provided class name.
      Parameters:
        `className` - the class name
      Returns:
        a new instance of the class
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the className

    - #### newInstance

          public static java.lang.Object newInstance(java.lang.Class<?> klass)

      Create an instance based on the provided class object.
      Parameters:
        `klass` - the class object
      Returns:
        a new instance of the class
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the klass

    - #### newInstance

          public static java.lang.Object newInstance(java.lang.String className,
                                     com.google.gwt.core.client.JavaScriptObject properties)

      Create an instance based on the provided class name, and apply the provided properties to it. The properties are applied after the instance is constructed with its no-arg constructor, unless the constructor triggers a call to getOrCreateJsObj(). In that case, the properties are applied before calling getOrCreateJsObj(), to ensure that the jsObj gets all the intended properties when it is constructed.
      Parameters:
        `className` - the class name
        `properties` - a JavaScriptObject whose key/value pairs represent property names and values
      Returns:
        a new instance of the class, with the properties applied
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the className

    - #### newInstance

          public static java.lang.Object newInstance(java.lang.Class<?> klass,
                                     com.google.gwt.core.client.JavaScriptObject properties)

      Create an instance based on the provided class object, and apply the provided properties to it. The properties are applied after the instance is constructed with its no-arg constructor, unless the constructor triggers a call to getOrCreateJsObj(). In that case, the properties are applied before calling getOrCreateJsObj(), to ensure that the jsObj gets all the intended properties when it is constructed.
      Parameters:
        `klass` - the class object
        `properties` - a JavaScriptObject whose key/value pairs represent property names and values
      Returns:
        a new instance of the class, with the properties applied
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the class

    - #### newInstance

          public static java.lang.Object newInstance(java.lang.String className,
                                     java.util.Map<java.lang.String,java.lang.Object> properties)

      Create an instance based on the provided class name, and apply the provided properties to it. The properties are applied after the instance is constructed with its no-arg constructor, unless the constructor triggers a call to getOrCreateJsObj(). In that case, the properties are applied before calling getOrCreateJsObj(), to ensure that the jsObj gets all the intended properties when it is constructed.
      Parameters:
        `className` - the class name
        `properties` - a Map whose key/value pairs represent property names and values
      Returns:
        a new instance of the class, with the properties applied
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the className

    - #### newInstance

          public static java.lang.Object newInstance(java.lang.Class<?> klass,
                                     java.util.Map<java.lang.String,java.lang.Object> properties)

      Create an instance based on the provided class object, and apply the provided properties to it. The properties are applied after the instance is constructed with its no-arg constructor, unless the constructor triggers a call to getOrCreateJsObj(). In that case, the properties are applied before calling getOrCreateJsObj(), to ensure that the jsObj gets all the intended properties when it is constructed.
      Parameters:
        `klass` - the class object
        `properties` - a Map whose key/value pairs represent property names and values
      Returns:
        a new instance of the class, with the properties applied
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the class

    - #### setProperty

          public static void setProperty(java.lang.Object bean,
                         java.lang.String property,
                         java.lang.Object value)

      Sets a property of a bean to a value.
      Parameters:
        `bean` - The object whose property is to be set
        `property` - The name of the property
        `value` - The value to set
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the bean's class
        `java.lang.IllegalArgumentException` - If there is no appropriate setter for the value

    - #### setProperties

          public static void setProperties(java.lang.Object bean,
                           java.util.Map<java.lang.String,java.lang.Object> properties)

      Applies a Map of property names and values to a bean.
      Parameters:
        `bean` - The object whose properties are to be set
        `properties` - A Map whose key/value pairs represent property names and values
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the bean's class
        `java.lang.IllegalArgumentException` - If there is no appropriate setter for a value

    - #### getProperty

          public static java.lang.Object getProperty(java.lang.Object bean,
                                     java.lang.String property)

      Gets a property of a bean.
      Parameters:
        `bean` - The object whose property to get
        `property` - The name of the property
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the bean's class

    - #### getPropertyAsString

          public static java.lang.String getPropertyAsString(java.lang.Object bean,
                                             java.lang.String property)

      Gets a property of a bean as a String. In simple cases, this will be equivalent to getProperty().toString(). However, if there are multiple getters available, it will prefer getters that actually return strings (e.g. getWidthAsString() would be preferred to getWidth().toString()).
      Parameters:
        `bean` - The object whose property to get
        `property` - The name of the property
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the bean's class

    - #### getAttributes

          public static java.lang.String[] getAttributes(java.lang.String beanClassName)

      Gets an array of the names of the properties of a class.
      Parameters:
        `beanClassName` - The name of the class
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the class

    - #### getAttributes

          public static java.lang.String[] getAttributes(java.lang.Class<?> beanClass)

      Gets an array of the names of the properties of a class.
      Parameters:
        `beanClass` - The klass object
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the class

    - #### getOrCreateJsObj

          public static com.google.gwt.core.client.JavaScriptObject getOrCreateJsObj(java.lang.Object bean)

    - #### setJsObj

          public static void setJsObj(java.lang.Object bean,
                      com.google.gwt.core.client.JavaScriptObject jsObj)

    - #### isFrameworkClass

          public static boolean isFrameworkClass(java.lang.Class<?> beanClass)

      Indicates whether the class is defined by the SmartGWT framework.
      Parameters:
        `beanClass` - The Class object
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the class

    - #### getDefaultScClassName

          public static java.lang.String getDefaultScClassName(java.lang.Class<?> beanClass)

      Gets the default scClassName for the class.
      Parameters:
        `beanClass` - The Class object
      Throws:
        `java.lang.IllegalStateException` - If no factory has been generated for the class

    - #### getSuperclass

          protected java.lang.Class getSuperclass()

    - #### createSuperclassFactory

          protected BeanFactory<?> createSuperclassFactory()

    - #### registerValueTypes

          protected abstract void registerValueTypes()

    - #### getMethods

          protected abstract com.google.gwt.core.client.JsArray<com.google.gwt.core.client.JavaScriptObject> getMethods()

    - #### getProperties

          protected abstract BeanProperty<BeanClass>[] getProperties(com.google.gwt.core.client.JsArray<com.google.gwt.core.client.JavaScriptObject> methods)

    - #### registerClassNameWithSGWTFactory

          public void registerClassNameWithSGWTFactory()

    - #### getBeanClass

          public abstract java.lang.Class<BeanClass> getBeanClass()

    - #### getBeanClassName

          public java.lang.String getBeanClassName()

    - #### doNewInstance

          protected abstract BeanClass doNewInstance()

    - #### newInstance

          public BeanClass newInstance()

    - #### newInstance

          public BeanClass newInstance(com.google.gwt.core.client.JavaScriptObject properties)

    - #### newInstance

          public BeanClass newInstance(java.util.Map<java.lang.String,java.lang.Object> properties)

    - #### triggerStaticInitializers

          protected void triggerStaticInitializers()

    - #### doSetProperty

          public void doSetProperty(java.lang.Object bean,
                           java.lang.String propertyName,
                           java.lang.Object value)

    - #### doSetProperties

          public void doSetProperties(java.lang.Object bean,
                             java.util.Map<java.lang.String,java.lang.Object> properties)

    - #### getAttributes

          public java.lang.String[] getAttributes()

    - #### doGetProperty

          public java.lang.Object doGetProperty(java.lang.Object bean,
                                       java.lang.String propertyName)

    - #### doGetPropertyAsString

          public java.lang.String doGetPropertyAsString(java.lang.Object bean,
                                               java.lang.String propertyName)

    - #### setJavascriptProperty

          protected abstract void setJavascriptProperty(BeanClass bean,
                                   java.lang.String propertyName,
                                   java.lang.Object value)

    - #### getJavascriptProperty

          protected abstract java.lang.Object getJavascriptProperty(BeanClass bean,
                                               java.lang.String propertyName)

    - #### doGetOrCreateJsObj

          public abstract com.google.gwt.core.client.JavaScriptObject doGetOrCreateJsObj(java.lang.Object bean)

    - #### doSetJsObj

          public abstract void doSetJsObj(java.lang.Object bean,
                        com.google.gwt.core.client.JavaScriptObject jsObj)

    - #### isFactoryCreated

          public abstract boolean isFactoryCreated(BeanClass bean)

    - #### applyFactoryProperties

          protected abstract void applyFactoryProperties(BeanClass bean)

    - #### isFrameworkClass

          public boolean isFrameworkClass()

    - #### getDefaultScClassName

          public java.lang.String getDefaultScClassName()