java.beans.beancontext
public class BeanContextChildSupport extends Object implements BeanContextChild, BeanContextServicesListener, Serializable
BeanContextChild
.
This class contains the most common implementations of the methods in
the BeanContextChild
BeanContextChild
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected BeanContext |
beanContext
The parent
BeanContext . |
BeanContextChild |
beanContextChildPeer
The peer on which to perform
set actions. |
protected PropertyChangeSupport |
pcSupport
Listeners are registered here and events are fired through here.
|
protected boolean |
rejectedSetBCOnce
If
setBeanContext() was vetoed once before, this
is set to true so that the next time, vetoes will
be ignored. |
protected VetoableChangeSupport |
vcSupport
Listeners are registered here and events are fired through here.
|
Constructor and Description |
---|
BeanContextChildSupport()
Create a new
BeanContextChildSupport with itself as the peer. |
BeanContextChildSupport(BeanContextChild peer)
Create a new
BeanContextChildSupport with the specified peer. |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Add a listener that will be notified when a specific property changes.
|
void |
addVetoableChangeListener(String propertyName,
VetoableChangeListener listener)
Add a listener that will be notified when a specific property
change is requested (a PropertyVetoException may be thrown) as
well as after the change is successfully made.
|
void |
firePropertyChange(String propertyName,
Object oldVal,
Object newVal)
Fire a property change.
|
void |
fireVetoableChange(String propertyName,
Object oldVal,
Object newVal)
Fire a vetoable property change.
|
BeanContext |
getBeanContext()
Get the parent
BeanContext . |
BeanContextChild |
getBeanContextChildPeer()
Get the peer (or
this if there is no peer). |
protected void |
initializeBeanContextResources()
Called by
setBeanContext() to grab resources when the parent has been set. |
boolean |
isDelegated()
Determine whether there is a peer.
|
protected void |
releaseBeanContextResources()
Called by
setBeanContext() to release resources of a what will soon no longer be the parent. |
void |
removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Remove a listener to a certain property.
|
void |
removeVetoableChangeListener(String propertyName,
VetoableChangeListener listener)
Remove a listener to a certain property.
|
void |
serviceAvailable(BeanContextServiceAvailableEvent event)
Called by
BeanContextServices whenever a service is made available. |
void |
serviceRevoked(BeanContextServiceRevokedEvent event)
Called by
BeanContextServices.revokeService() to indicate that a service has been revoked. |
void |
setBeanContext(BeanContext newBeanContext)
Set the parent
BeanContext . |
boolean |
validatePendingSetBeanContext(BeanContext newBeanContext)
Called by
setBeanContext() to determine whether the set should be rejected. |
public BeanContextChild beanContextChildPeer
set
actions.
This is here so that this class can be used as a peer.
When extending this class, this variable will be set to
this
.
protected transient BeanContext beanContext
BeanContext
.protected transient boolean rejectedSetBCOnce
setBeanContext()
was vetoed once before, this
is set to true
so that the next time, vetoes will
be ignored.protected PropertyChangeSupport pcSupport
protected VetoableChangeSupport vcSupport
public BeanContextChildSupport()
BeanContextChildSupport
with itself as the peer.
This is meant to be used when you subclass
BeanContextChildSupport
to create your child.public BeanContextChildSupport(BeanContextChild peer)
BeanContextChildSupport
with the specified peer.peer
- the peer to use, or null
to specify
this
.public void setBeanContext(BeanContext newBeanContext) throws PropertyVetoException
BeanContext
.
When this Object is being added to a new BeanContext or moved from an old one, a non-null value will be passed in.
When this Object is being removed from the current
BeanContext
, setBeanContext()
will
receive the parameter null
.
Order of events:
BeanContext
is the same as the old
one, nothing happens.
validatePendingSetBeanContext()
. If this call
returns false
, the change is rejected and a
PropertyVetoException
is thrown.
VetoableChangeEvent
s are fired with the name
"beanContext"
, using the
fireVetoableChange()
method. If a veto
occurs, reversion events are fired using the same method,
the change is rejected, and the veto is rethrown.
releaseBeanContextResources()
is called.
PropertyChangeEvent
s are fired using the
firePropertyChange()
method.
initializeBeanContextResources()
is called.
setBeanContext
in interface BeanContextChild
newBeanContext
- the new parent for the
BeanContextChild
, or null
to
signify removal from a tree.PropertyVetoException
- if the
BeanContextChild
implementor does not
wish to have its parent changed.public BeanContext getBeanContext()
BeanContext
.getBeanContext
in interface BeanContextChild
BeanContext
.public BeanContextChild getBeanContextChildPeer()
this
if there is no peer).this
if there is no peer.public boolean isDelegated()
getBeanContextChildPeer() == this
.public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
addPropertyChangeListener
in interface BeanContextChild
propertyName
- the name of the property to listen on.listener
- the listener to listen on the property.public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
removePropertyChangeListener
in interface BeanContextChild
propertyName
- the name of the property being listened on.listener
- the listener listening on the property.public void addVetoableChangeListener(String propertyName, VetoableChangeListener listener)
addVetoableChangeListener
in interface BeanContextChild
propertyName
- the name of the property to listen on.listener
- the listener to listen on the property.public void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener)
removeVetoableChangeListener
in interface BeanContextChild
propertyName
- the name of the property being listened onlistener
- the listener listening on the property.public void firePropertyChange(String propertyName, Object oldVal, Object newVal)
propertyName
- the name of the property that changedoldVal
- the old value of the propertynewVal
- the new value of the propertypublic void fireVetoableChange(String propertyName, Object oldVal, Object newVal) throws PropertyVetoException
propertyName
- the name of the property that changedoldVal
- the old value of the propertynewVal
- the new value of the propertyPropertyVetoException
- if the change is vetoed.public void serviceRevoked(BeanContextServiceRevokedEvent event)
BeanContextServices.revokeService()
to indicate that a service has been revoked.
If you have a reference to such a service, it should be
discarded and may no longer function properly.
getService()
will no longer work on the specified
service class after this event has been fired.
This method is meant to be overriden.
BeanContextChildSupport
's implementation does
nothing.
serviceRevoked
in interface BeanContextServiceRevokedListener
event
- the service revoked event.BeanContextServices.revokeService(java.lang.Class,java.beans.beancontext.BeanContextServiceProvider,boolean)
public void serviceAvailable(BeanContextServiceAvailableEvent event)
BeanContextServices
whenever a service is made available.
This method is meant to be overriden.
BeanContextChildSupport
's implementation does
nothing.
serviceAvailable
in interface BeanContextServicesListener
event
- the service revoked event, with useful information
about the new service.public boolean validatePendingSetBeanContext(BeanContext newBeanContext)
setBeanContext()
to determine whether the set should be rejected.
This method is meant to be overriden.
BeanContextChildSupport
's implementation simply
returns true
.
newBeanContext
- the new parent.protected void releaseBeanContextResources()
setBeanContext()
to release resources of a what will soon no longer be the parent.
This method is meant to be overriden.
BeanContextChildSupport
's implementation does
nothing.
protected void initializeBeanContextResources()
setBeanContext()
to grab resources when the parent has been set.
This method is meant to be overriden.
BeanContextChildSupport
's implementation does
nothing.