JIDE 3.5.15

com.jidesoft.introspector
Class BeanIntrospector

java.lang.Object
  extended by com.jidesoft.introspector.BeanIntrospector
All Implemented Interfaces:
Introspector<BeanProperty>

public class BeanIntrospector
extends Object
implements Introspector<BeanProperty>

A helper class to introspect properties in a Java Bean and provide an easy way to integrate with PropertyTable.


Nested Class Summary
static interface BeanIntrospector.LazyValue
           
 
Field Summary
static String PROPERTIES
           
static String PROPERTY
           
 
Constructor Summary
BeanIntrospector(Class<?> clazz)
          Creates a BeanIntrospector.
BeanIntrospector(Class<?> clazz, BeanInfo beanInfo)
          Creates a BeanIntrospector using BeanInfo.
BeanIntrospector(Class<?> clazz, InputStream in)
          Creates a BeanIntrospector using property xml file.
BeanIntrospector(Class<?> clazz, String fileName)
          Creates a BeanIntrospector using property xml file.
BeanIntrospector(Class<?> clazz, String[] properties)
          Creates a BeanIntrospector and allow you to pass in known properties.
BeanIntrospector(Class<?> clazz, String[] properties, boolean filtered)
          Creates a BeanIntrospector and allow you to pass in known properties.
BeanIntrospector(Class<?> clazz, String[] properties, int count)
          Creates a BeanIntrospector and allow you to pass in known properties.
 
Method Summary
 void addProperty(BeanProperty property)
          Adds a new property.
protected  BeanProperty createBeanProperty(PropertyDescriptor pd)
          Creates the bean property instance from the property descriptor.
protected  BeanProperty createBeanProperty(String name, Class<?> clazz)
          Creates the bean property instance from the property descriptor.
<T> BeanTableModel
createBeanTableModel(List<T> objects)
           
 List<Property> createPropertyList(Object beanObject)
           
 PropertyTableModel<Property> createPropertyTableModel(Object beanObject)
           
 BeanProperty getProperty(String name)
          Gets the property with the specified name.
 int getPropertyCount()
          Gets the property count.
 String[] getPropertyNames()
          Gets the properties names in an array.
 void introspectProperties(Class<?> clazz, InputStream in, boolean filtered)
          Creates a BeanIntrospector using property xml file's input stream.
 void introspectProperties(Class<?> clazz, String fileName, boolean filtered)
          Creates a BeanIntrospector using property xml file.
 void removeProperty(String name)
          Removes the property with the specified name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTIES

public static final String PROPERTIES
See Also:
Constant Field Values

PROPERTY

public static final String PROPERTY
See Also:
Constant Field Values
Constructor Detail

BeanIntrospector

public BeanIntrospector(Class<?> clazz)
                 throws IntrospectionException
Creates a BeanIntrospector. It will use reflection to find out all properties on the Bean so that you can use them to create a PropertyTableModel later.

Parameters:
clazz - the type of the object to be introspected.
Throws:
IntrospectionException - if the java bean introspection failed

BeanIntrospector

public BeanIntrospector(Class<?> clazz,
                        String[] properties)
                 throws IntrospectionException
Creates a BeanIntrospector and allow you to pass in known properties.

There are two purposes to pass a properties parameter into the constructor. One is you might want to assign different category and description for each property. Using reflection won't be able to get those information. Secondly you might want to control the properties to be exposed.

The format of properties array is

 new String[] {
      "propertyName1", "propertyDescription1", "propertyCategory1",
      "propertyName2", "propertyDescription2", "propertyCategory2",
      ...
 };
 

Parameters:
clazz - the type of the object to be introspected.
properties - a single dimension String array. See above for the format.
Throws:
IntrospectionException - if the java bean introspection failed

BeanIntrospector

public BeanIntrospector(Class<?> clazz,
                        String[] properties,
                        int count)
                 throws IntrospectionException
Creates a BeanIntrospector and allow you to pass in known properties.

There are two purposes to pass a properties parameter into the constructor. One is you might want to assign different category and description for each property. Using reflection won't be able to get those information. Secondly you might want to control the properties to be exposed.

There are several way to format the properties array depending on the count. If count is 1, the format will be

 new String[] {
      "propertyName1",
      "propertyName2",
      ...
 };
 
If count is 2, the format will be
 new String[] {
      "propertyName1", "displayName11",
      "propertyName2", "displayName12",
      ...
 };
 
If count is 3, the format will be
 new String[] {
      "propertyName1", "propertyDescription1", "propertyCategory1",
      "propertyName2", "propertyDescription2", "propertyCategory2",
      ...
 };
 
If count is 4, the format will be
 new String[] {
      "propertyName1", "displayName11", "propertyDescription1", "propertyCategory1",
      "propertyName2", "displayName12", "propertyDescription2", "propertyCategory2",
      ...
 };
 

Parameters:
clazz - the type of the object to be introspected.
properties - a single dimension String array. See above for the format.
count - the count of the attributes for each property. See above.
Throws:
IntrospectionException - if the java bean introspection failed

BeanIntrospector

public BeanIntrospector(Class<?> clazz,
                        String[] properties,
                        boolean filtered)
                 throws IntrospectionException
Creates a BeanIntrospector and allow you to pass in known properties. You also have the option to use the propertiesarray as a filter or not.

Parameters:
clazz - the type of the object to be introspected.
properties - a single dimension String array. See above for the format.
filtered - true if only properties defined in properties array are used. Otherwise, it will still use reflection to find all properties and add additional attributes defined in properties array to those properties.
Throws:
IntrospectionException - if the java bean introspection failed

BeanIntrospector

public BeanIntrospector(Class<?> clazz,
                        String fileName)
                 throws IntrospectionException
Creates a BeanIntrospector using property xml file. The property xml file is in the format of
 
      
      
      ...
 
 
Possible attributes for Property element are "name", "displayName", "value", "type", "description"; "dependingProperties", "category", "converterContext", "editorContext", "editable", "autoIntrospect", "expert", "hidden" and "preferred". The only required attribute is "name". All other are optional.

Parameters:
clazz - the type of the object to be introspected.
fileName - the file name
Throws:
IntrospectionException - if the java bean introspection failed

BeanIntrospector

public BeanIntrospector(Class<?> clazz,
                        InputStream in)
                 throws IntrospectionException
Creates a BeanIntrospector using property xml file.

Parameters:
clazz - the type of the object to be introspected.
in - the input stream
Throws:
IntrospectionException - if the java bean introspection failed
See Also:
for the xml file format.

BeanIntrospector

public BeanIntrospector(Class<?> clazz,
                        BeanInfo beanInfo)
Creates a BeanIntrospector using BeanInfo.

Parameters:
clazz - the type of the object to be introspected.
beanInfo - the bean info
Method Detail

introspectProperties

public void introspectProperties(Class<?> clazz,
                                 String fileName,
                                 boolean filtered)
                          throws IntrospectionException
Creates a BeanIntrospector using property xml file.

Parameters:
clazz - the type of the object to be introspected.
fileName - the file name
filtered - true to use the properties defined in the file to filter the property list.
Throws:
IntrospectionException - if the java bean introspection failed

introspectProperties

public void introspectProperties(Class<?> clazz,
                                 InputStream in,
                                 boolean filtered)
                          throws IntrospectionException
Creates a BeanIntrospector using property xml file's input stream.

Parameters:
clazz - the type of the object to be introspected.
in - the input stream
filtered - true to use the properties defined in the input stream to filter the property list.
Throws:
IntrospectionException - if the java bean introspection failed

createBeanProperty

protected BeanProperty createBeanProperty(PropertyDescriptor pd)
Creates the bean property instance from the property descriptor.

Parameters:
pd - the property descriptor
Returns:
the BeanProperty instance.
Since:
3.4.4

createBeanProperty

protected BeanProperty createBeanProperty(String name,
                                          Class<?> clazz)
Creates the bean property instance from the property descriptor.

Parameters:
name - the property name
clazz - the bean class
Returns:
the BeanProperty instance.
Since:
3.4.4

createPropertyTableModel

public PropertyTableModel<Property> createPropertyTableModel(Object beanObject)

createBeanTableModel

public <T> BeanTableModel createBeanTableModel(List<T> objects)

createPropertyList

public List<Property> createPropertyList(Object beanObject)

getPropertyCount

public int getPropertyCount()
Description copied from interface: Introspector
Gets the property count.

Specified by:
getPropertyCount in interface Introspector<BeanProperty>
Returns:
the property count.

getProperty

public BeanProperty getProperty(String name)
Description copied from interface: Introspector
Gets the property with the specified name.

Specified by:
getProperty in interface Introspector<BeanProperty>
Parameters:
name - the property name.
Returns:
the property with the specified name.

removeProperty

public void removeProperty(String name)
Description copied from interface: Introspector
Removes the property with the specified name.

Specified by:
removeProperty in interface Introspector<BeanProperty>
Parameters:
name - the property name.

addProperty

public void addProperty(BeanProperty property)
Description copied from interface: Introspector
Adds a new property.

Specified by:
addProperty in interface Introspector<BeanProperty>
Parameters:
property - a new property

getPropertyNames

public String[] getPropertyNames()
Description copied from interface: Introspector
Gets the properties names in an array.

Specified by:
getPropertyNames in interface Introspector<BeanProperty>
Returns:
the property names.

JIDE 3.5.15