Class BeanFactory<BeanClass>

java.lang.Object
com.smartgwt.client.bean.BeanFactory<BeanClass>
Direct Known Subclasses:
BeanFactoryForBaseClass, BeanFactoryForBaseWidget, BeanFactoryForDataClass

public abstract class BeanFactory<BeanClass> extends 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.

  • Field Details

  • Constructor Details

  • Method Details

    • getSGWTModule

      public static JavaScriptObject getSGWTModule()
    • getFactoryProperties

      public static Map<String,Object> getFactoryProperties()
    • clearFactoryProperties

      public static void clearFactoryProperties()
    • getFactoryPropertiesClass

      public static Class<?> getFactoryPropertiesClass()
    • getFactory

      public static BeanFactory<?> getFactory(String className)
    • getFactory

      public static BeanFactory<?> getFactory(Class<?> klass)
    • getFactory

      public static BeanFactory<?> getFactory(Object object)
    • registerFactory

      protected static void registerFactory(BeanFactory<?> factory)
    • noFactoryException

      protected static IllegalStateException noFactoryException(String name)
    • noFactoryException

      protected static IllegalStateException noFactoryException(Class<?> klass)
    • newInstance

      public static Object newInstance(String className)
      Create an instance based on the provided class name.
      Parameters:
      className - the class name
      Returns:
      a new instance of the class
      Throws:
      IllegalStateException - If no factory has been generated for the className
    • newInstance

      public static Object newInstance(Class<?> klass)
      Create an instance based on the provided class object.
      Parameters:
      klass - the class object
      Returns:
      a new instance of the class
      Throws:
      IllegalStateException - If no factory has been generated for the klass
    • newInstance

      public static Object newInstance(String className, 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:
      IllegalStateException - If no factory has been generated for the className
    • newInstance

      public static Object newInstance(Class<?> klass, 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:
      IllegalStateException - If no factory has been generated for the class
    • newInstance

      public static Object newInstance(String className, Map<String,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:
      IllegalStateException - If no factory has been generated for the className
    • newInstance

      public static Object newInstance(Class<?> klass, Map<String,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:
      IllegalStateException - If no factory has been generated for the class
    • setProperty

      public static void setProperty(Object bean, String property, 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:
      IllegalStateException - If no factory has been generated for the bean's class
      IllegalArgumentException - If there is no appropriate setter for the value
    • setProperties

      public static void setProperties(Object bean, Map<String,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:
      IllegalStateException - If no factory has been generated for the bean's class
      IllegalArgumentException - If there is no appropriate setter for a value
    • getProperty

      public static Object getProperty(Object bean, String property)
      Gets a property of a bean.
      Parameters:
      bean - The object whose property to get
      property - The name of the property
      Throws:
      IllegalStateException - If no factory has been generated for the bean's class
    • getPropertyAsString

      public static String getPropertyAsString(Object bean, 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:
      IllegalStateException - If no factory has been generated for the bean's class
    • getAttributes

      public static String[] getAttributes(String beanClassName)
      Gets an array of the names of the properties of a class.
      Parameters:
      beanClassName - The name of the class
      Throws:
      IllegalStateException - If no factory has been generated for the class
    • getAttributes

      public static String[] getAttributes(Class<?> beanClass)
      Gets an array of the names of the properties of a class.
      Parameters:
      beanClass - The klass object
      Throws:
      IllegalStateException - If no factory has been generated for the class
    • getOrCreateJsObj

      public static JavaScriptObject getOrCreateJsObj(Object bean)
    • setJsObj

      public static void setJsObj(Object bean, JavaScriptObject jsObj)
    • isFrameworkClass

      public static boolean isFrameworkClass(Class<?> beanClass)
      Indicates whether the class is defined by the SmartGWT framework.
      Parameters:
      beanClass - The Class object
      Throws:
      IllegalStateException - If no factory has been generated for the class
    • getDefaultScClassName

      public static String getDefaultScClassName(Class<?> beanClass)
      Gets the default scClassName for the class.
      Parameters:
      beanClass - The Class object
      Throws:
      IllegalStateException - If no factory has been generated for the class
    • getSuperclass

      protected Class getSuperclass()
    • createSuperclassFactory

      protected BeanFactory<?> createSuperclassFactory()
    • registerValueTypes

      protected abstract void registerValueTypes()
    • getMethods

      protected abstract JsArray<JavaScriptObject> getMethods()
    • getProperties

      protected abstract BeanProperty<BeanClass>[] getProperties(JsArray<JavaScriptObject> methods)
    • registerClassNameWithSGWTFactory

      public void registerClassNameWithSGWTFactory()
    • getBeanClass

      public abstract Class<BeanClass> getBeanClass()
    • getBeanClassName

      public String getBeanClassName()
    • doNewInstance

      protected abstract BeanClass doNewInstance()
    • newInstance

      public BeanClass newInstance()
    • newInstance

      public BeanClass newInstance(JavaScriptObject properties)
    • newInstance

      public BeanClass newInstance(Map<String,Object> properties)
    • triggerStaticInitializers

      protected void triggerStaticInitializers()
    • doSetProperty

      public void doSetProperty(Object bean, String propertyName, Object value)
    • doSetProperties

      public void doSetProperties(Object bean, Map<String,Object> properties)
    • getAttributes

      public String[] getAttributes()
    • doGetProperty

      public Object doGetProperty(Object bean, String propertyName)
    • doGetPropertyAsString

      public String doGetPropertyAsString(Object bean, String propertyName)
    • setJavascriptProperty

      protected abstract void setJavascriptProperty(BeanClass bean, String propertyName, Object value)
    • getJavascriptProperty

      protected abstract Object getJavascriptProperty(BeanClass bean, String propertyName)
    • doGetOrCreateJsObj

      public abstract JavaScriptObject doGetOrCreateJsObj(Object bean)
    • doSetJsObj

      public abstract void doSetJsObj(Object bean, JavaScriptObject jsObj)
    • isFactoryCreated

      public abstract boolean isFactoryCreated(BeanClass bean)
    • applyFactoryProperties

      protected abstract void applyFactoryProperties(BeanClass bean)
    • isFrameworkClass

      public boolean isFrameworkClass()
    • getDefaultScClassName

      public String getDefaultScClassName()