|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.jbeans.BaseBeanProperty
This class is the base class for the BeanProperty and the NestedBeanProperty classes. It provides the standard methods used by both classes and the standard properties
Field Summary | |
protected static int |
BAD_CONVERT
Used to denote a conversion event has failed to take place when sub-classes are firing events |
protected Class |
beanClass
Holds the Class that the property is contain in |
protected List |
conversionListeners
This holds the list of conversion listeners for the bean property |
protected static int |
GET
Used to denote a get event when sub-classes are firing events |
protected static int |
POST_CONVERT
Used to denote a conversion event has just taken place when sub-classes are firing events |
protected static int |
PRE_CONVERT
Used to denote a conversion event is about to take place when sub-classes are firing events |
protected List |
propertyListeners
This holds the list of property listeners for the bean property |
protected String |
propertyName
Holds the name of the property that this bean property describes |
protected Class |
propertyType
Holds the Class type of the property that this bean property describes |
protected static int |
SET
Used to denote a set event when sub-classes are firing events |
Constructor Summary | |
protected |
BaseBeanProperty()
Empty default constructor which can be called by sub-classes that are not going to use the propertyName and beanClass or need to delay the initialization of those members until later. |
protected |
BaseBeanProperty(String propertyName,
Class beanClass)
Constuctor with initial properties. |
protected |
BaseBeanProperty(String propertyName,
String beanClass)
Constuctor with initial properties. |
Method Summary | |
void |
addConversionListener(ConversionListener listener)
Adds a conversion listener to the list of listeners for this property. |
void |
addPropertyListener(PropertyListener listener)
Adds a property listener to the list of listeners for this property. |
protected Object |
convertParameter(Object parameter,
Object bean)
Converts the given value parameter (parameter) to a type that is accepted by the set method of this property. |
protected void |
fireConversionEvent(int type,
Object oldValue,
Object newValue,
Object bean)
Fires off a conversion event using the type constants of this class and the parameters given. |
protected void |
firePropertyEvent(int type,
Object oldValue,
Object newValue,
Object bean,
int index)
Fires off a property event using the type constants of this class and the parameters given. |
Class |
getBeanClass()
Returns the class of the bean that this property is contained in |
Iterator |
getConversionListeners()
Returns an iterator for the list of conversion listeners. |
String |
getFullName()
Gets the full name of the property. |
Iterator |
getPropertyListeners()
Returns an iterator for the list of property listeners. |
String |
getPropertyName()
Gets the name of the property. |
Class |
getPropertyType()
Gets the type of the property. |
abstract Object |
getPropertyValue(Object bean)
Gets the the property value. |
boolean |
hasConversionListeners()
Returns true if there are any conversion listeners for this property. |
boolean |
hasPropertyListeners()
Returns true if there are any property listeners for this property. |
protected abstract void |
initialize()
Sub-classes should put all the initialization logic in this method NOT in constructors. |
Object |
instantiate()
Creates an instance of the class that this BeanProperty's property is contained in. |
void |
removeConversionListener(ConversionListener listener)
Removes the given conversion listener from the list of conversion listeners. |
void |
removePropertyListener(PropertyListener listener)
Removes the given property listener from the list of property listeners. |
void |
setPropertyValue(Object bean,
Object value)
Sets the value of the bean property to the given value. |
abstract void |
setPropertyValue(Object bean,
Object value,
boolean convert)
Sets the the property value. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int GET
protected static final int SET
protected static final int PRE_CONVERT
protected static final int POST_CONVERT
protected static final int BAD_CONVERT
protected String propertyName
protected Class beanClass
protected Class propertyType
protected List propertyListeners
protected List conversionListeners
Constructor Detail |
protected BaseBeanProperty()
protected BaseBeanProperty(String propertyName, Class beanClass) throws BeanException
initialize()
. The initialize method must be implemented my sub-classes and
should do all the initialization work. This constructor simply calls the default
constructor, sets up the propertyName and beanClass members and then calls to
initializeprotected BaseBeanProperty(String propertyName, String beanClass) throws BeanException
initialize()
. The initialize method must be implemented my sub-classes and
should do all the initialization work. This constructor simply calls the default
constructor, sets up the propertyName and beanClass members and then calls to
initialize. This method takes the fully qualified name of the bean class to be
used.Method Detail |
protected abstract void initialize() throws BeanException
For example, if the the BeanProperty constructor set up the read and write Method objects for itself and the IndexedBeanProperty wanted to chain constructors an error would occur because the indexed properties do not have the same signatures as the bean properties. This would cause the BeanProperty constructor that did the initialization to throw a BeanException stating that the property didn't exist even though it did.
For this reason, the initialize method should be used to do all the initialization.
BeanException
- If there was any errors during initializationpublic String getPropertyName()
For BeanProperty
getName() -> name
For IndexedBeanProperty
getFoo(index) -> foo
For NestedBeanProperty
getFoo().getBar().getName() -> foo.bar.name
New sub-classes can override this method, but it is advisable to use the default version because it returns the property name that was used during construction.
NOTE: If a sub-classes uses the default constructor and does not make use of the propertyName member of this class, then this method should be overridden (if applicable).
public Class getPropertyType()
For BeanProperty and IndexedBeanProperty
public String getName() {} -> java.lang.String
For NestedBeanProperty, this method returns the type of the last property
in the nesting.
i.e. getFoo().getBar().getName() and public String getName() {} -> java.lang.String
public String getFullName()
public Class getBeanClass()
public Object instantiate() throws BeanException
BeanException
- If there was a problem instantiating the classpublic void addPropertyListener(PropertyListener listener)
listener
- The new property listener to add to the listpublic void removePropertyListener(PropertyListener listener)
listener
- The property listener to remove from the listpublic Iterator getPropertyListeners()
public boolean hasPropertyListeners()
public void addConversionListener(ConversionListener listener)
listener
- The new conversion listener to add to the listpublic void removeConversionListener(ConversionListener listener)
listener
- The conversion listener to remove from the listpublic Iterator getConversionListeners()
public boolean hasConversionListeners()
public abstract Object getPropertyValue(Object bean) throws BeanException
bean
- The bean instance to set the property onBeanException
- If there was an error getting the JavaBean property or
the getter/is method threw a checked Exceptionpublic abstract void setPropertyValue(Object bean, Object value, boolean convert) throws BeanException, TypeConversionException
bean
- The bean instance to set the property onvalue
- The value to set on the beanconvert
- Determines whether or not the value should be converted
to the correct parameter type for the property set methodBeanException
- If there was an error setting the JavaBean property or
the setter method threw a checked ExceptionTypeConversionException
- If there was an error attempting to auto
convert the value being setpublic void setPropertyValue(Object bean, Object value) throws BeanException
bean
- The instance of the JavaBean to set the property onvalue
- The value to set the property toBeanException
- If there was an error setting the JavaBean property or
the setter method threw a checked Exceptionprotected Object convertParameter(Object parameter, Object bean) throws TypeConversionException
parameter
- The value parameter object to convertbean
- The bean object that this parameter object is being converted for
and is usually used when firing eventsTypeConversionException
- If there was a problem converting the parameterprotected void firePropertyEvent(int type, Object oldValue, Object newValue, Object bean, int index) throws BeanException
type
- The type of event to fire. Must be either the GET or SET
constants of this classoldValue
- The old value of the property, which is the same as the newValue
for all events except the SET eventnewValue
- The new value of the property, which is normally the current
value of the property except for the SET eventbean
- The bean object that the event is occurring forindex
- The index if this is an IndexedBeanProperty (use -1 for all other
types of properties)IllegalArgumentException
- If the type is not a valid property event type
and there are listenersprotected void fireConversionEvent(int type, Object oldValue, Object newValue, Object bean)
type
- The type of event to fire. Must be either the PRE_CONVERT,
POST_CONVERT or BAD_CONVERT constants of this classoldValue
- The old value of the property, which is the parameter value
before conversionnewValue
- The new value of the property, which is the parameter value
after conversion unless this is called for the PRE_CONVERT and
BAD_CONVERT events and then it should be the same as the oldValuebean
- The bean object that the event is occurring forIllegalArgumentException
- If the type is not a valid conversion event type
and there are listeners
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |