Package com.smartgwt.client.bean
Class BeanFactory<BeanClass>
java.lang.Object
com.smartgwt.client.bean.BeanFactory<BeanClass>
- Direct Known Subclasses:
- BeanFactoryForBaseClass,- BeanFactoryForBaseWidget,- BeanFactoryForDataClass
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 SummaryNested ClassesModifier and TypeClassDescriptionstatic interfacestatic interfaceInterface used to trigger the generation and registration of reflection metadata forCanvasand all its subclasses found in the classpath (including your custom subclasses).static interfaceInterface used to trigger the generation and registration of reflection metadata forFormItemand all its subclasses found in the classpath (including your custom subclasses).static @interfacestatic @interfaceAnnotation which will trigger the generation of BeanFactories.static interfaceAn interface which you can extend in order to register classes with theBeanFactoryreflection mechanism.static @interface
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected Map<String,BeanProperty<BeanClass>> protected JavaScriptObjectprotected BeanFactory
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedThe constructor is protected because you should not create BeanFactory instances directly.
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract voidstatic voidprotected BeanFactory<?>abstract JavaScriptObjectdoGetOrCreateJsObj(Object bean) doGetProperty(Object bean, String propertyName) doGetPropertyAsString(Object bean, String propertyName) protected abstract BeanClassabstract voiddoSetJsObj(Object bean, JavaScriptObject jsObj) voiddoSetProperties(Object bean, Map<String, Object> properties) voiddoSetProperty(Object bean, String propertyName, Object value) String[]static String[]getAttributes(Class<?> beanClass) Gets an array of the names of the properties of a class.static String[]getAttributes(String beanClassName) Gets an array of the names of the properties of a class.static StringgetDefaultScClassName(Class<?> beanClass) Gets the default scClassName for the class.static BeanFactory<?>getFactory(Class<?> klass) static BeanFactory<?>getFactory(Object object) static BeanFactory<?>getFactory(String className) static Class<?>protected abstract ObjectgetJavascriptProperty(BeanClass bean, String propertyName) protected abstract JsArray<JavaScriptObject>static JavaScriptObjectgetOrCreateJsObj(Object bean) protected abstract BeanProperty<BeanClass>[]getProperties(JsArray<JavaScriptObject> methods) static ObjectgetProperty(Object bean, String property) Gets a property of a bean.static StringgetPropertyAsString(Object bean, String property) Gets a property of a bean as a String.static JavaScriptObjectprotected Classabstract booleanisFactoryCreated(BeanClass bean) booleanstatic booleanisFrameworkClass(Class<?> beanClass) Indicates whether the class is defined by the SmartGWT framework.newInstance(JavaScriptObject properties) static ObjectnewInstance(Class<?> klass) Create an instance based on the provided class object.static ObjectnewInstance(Class<?> klass, JavaScriptObject properties) Create an instance based on the provided class object, and apply the provided properties to it.static ObjectnewInstance(Class<?> klass, Map<String, Object> properties) Create an instance based on the provided class object, and apply the provided properties to it.static ObjectnewInstance(String className) Create an instance based on the provided class name.static ObjectnewInstance(String className, JavaScriptObject properties) Create an instance based on the provided class name, and apply the provided properties to it.static ObjectnewInstance(String className, Map<String, Object> properties) Create an instance based on the provided class name, and apply the provided properties to it.newInstance(Map<String, Object> properties) protected static IllegalStateExceptionnoFactoryException(Class<?> klass) protected static IllegalStateExceptionnoFactoryException(String name) voidprotected static voidregisterFactory(BeanFactory<?> factory) protected abstract voidprotected abstract voidsetJavascriptProperty(BeanClass bean, String propertyName, Object value) static voidsetJsObj(Object bean, JavaScriptObject jsObj) static voidsetProperties(Object bean, Map<String, Object> properties) Applies a Map of property names and values to a bean.static voidsetProperty(Object bean, String property, Object value) Sets a property of a bean to a value.protected void
- 
Field Details- 
superclassFactory
- 
properties
- 
sgwtFactory
 
- 
- 
Constructor Details- 
BeanFactoryprotected BeanFactory()The constructor is protected because you should not create BeanFactory instances directly. Instead, useBeanFactory.MetaFactory,BeanFactory.CanvasMetaFactoryorBeanFactory.FormItemMetaFactoryto create bean factories, and then use the static methods on BeanFactory.
 
- 
- 
Method Details- 
getSGWTModule
- 
getFactoryProperties
- 
clearFactoryPropertiespublic static void clearFactoryProperties()
- 
getFactoryPropertiesClass
- 
getFactory
- 
getFactory
- 
getFactory
- 
registerFactory
- 
noFactoryException
- 
noFactoryException
- 
newInstanceCreate 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
 
- 
newInstanceCreate 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
 
- 
newInstanceCreate 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
 
- 
newInstanceCreate 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
 
- 
newInstanceCreate 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
 
- 
newInstanceCreate 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
 
- 
setPropertySets 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
 
- 
setPropertiesApplies 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
 
- 
getPropertyGets 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
 
- 
getPropertyAsStringGets 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
 
- 
getAttributesGets 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
 
- 
getAttributesGets 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
- 
setJsObj
- 
isFrameworkClassIndicates 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
 
- 
getDefaultScClassNameGets the default scClassName for the class.- Parameters:
- beanClass- The Class object
- Throws:
- IllegalStateException- If no factory has been generated for the class
 
- 
getSuperclass
- 
createSuperclassFactory
- 
registerValueTypesprotected abstract void registerValueTypes()
- 
getMethods
- 
getProperties
- 
registerClassNameWithSGWTFactorypublic void registerClassNameWithSGWTFactory()
- 
getBeanClass
- 
getBeanClassName
- 
doNewInstance
- 
newInstance
- 
newInstance
- 
newInstance
- 
triggerStaticInitializersprotected void triggerStaticInitializers()
- 
doSetProperty
- 
doSetProperties
- 
getAttributes
- 
doGetProperty
- 
doGetPropertyAsString
- 
setJavascriptProperty
- 
getJavascriptProperty
- 
doGetOrCreateJsObj
- 
doSetJsObj
- 
isFactoryCreated
- 
applyFactoryProperties
- 
isFrameworkClasspublic boolean isFrameworkClass()
- 
getDefaultScClassName
 
-