java.beans.beancontext

Class BeanContextChildSupport

Implemented Interfaces:
BeanContextChild, BeanContextServiceRevokedListener, BeanContextServicesListener, EventListener, Serializable
Known Direct Subclasses:
BeanContextSupport

public class BeanContextChildSupport
extends Object
implements BeanContextChild, BeanContextServicesListener, Serializable

Support for creating a BeanContextChild. This class contains the most common implementations of the methods in the BeanContextChild
Since:
1.2
See Also:
BeanContextChild, Serialized Form

Field Summary

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 Summary

BeanContextChildSupport()
Create a new BeanContextChildSupport with itself as the peer.
BeanContextChildSupport(BeanContextChild peer)
Create a new BeanContextChildSupport with the specified peer.

Method Summary

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.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

beanContext

protected BeanContext beanContext
The parent BeanContext.

beanContextChildPeer

public BeanContextChild beanContextChildPeer
The peer on which to perform 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.


pcSupport

protected PropertyChangeSupport pcSupport
Listeners are registered here and events are fired through here.

rejectedSetBCOnce

protected boolean rejectedSetBCOnce
If setBeanContext() was vetoed once before, this is set to true so that the next time, vetoes will be ignored.

vcSupport

protected VetoableChangeSupport vcSupport
Listeners are registered here and events are fired through here.

Constructor Details

BeanContextChildSupport

public BeanContextChildSupport()
Create a new BeanContextChildSupport with itself as the peer. This is meant to be used when you subclass BeanContextChildSupport to create your child.

BeanContextChildSupport

public BeanContextChildSupport(BeanContextChild peer)
Create a new BeanContextChildSupport with the specified peer.
Parameters:
peer - the peer to use, or null to specify this.

Method Details

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Add a listener that will be notified when a specific property changes.
Specified by:
addPropertyChangeListener in interface BeanContextChild
Parameters:
propertyName - the name of the property to listen on.
listener - the listener to listen on the property.

addVetoableChangeListener

public 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.
Specified by:
addVetoableChangeListener in interface BeanContextChild
Parameters:
propertyName - the name of the property to listen on.
listener - the listener to listen on the property.

firePropertyChange

public void firePropertyChange(String propertyName,
                               Object oldVal,
                               Object newVal)
Fire a property change.
Parameters:
propertyName - the name of the property that changed
oldVal - the old value of the property
newVal - the new value of the property

fireVetoableChange

public void fireVetoableChange(String propertyName,
                               Object oldVal,
                               Object newVal)
            throws PropertyVetoException
Fire a vetoable property change.
Parameters:
propertyName - the name of the property that changed
oldVal - the old value of the property
newVal - the new value of the property
Throws:
PropertyVetoException - if the change is vetoed.

getBeanContext

public BeanContext getBeanContext()
Get the parent BeanContext.
Specified by:
getBeanContext in interface BeanContextChild
Returns:
the parent BeanContext.

getBeanContextChildPeer

public BeanContextChild getBeanContextChildPeer()
Get the peer (or this if there is no peer).
Returns:
the peer, or this if there is no peer.

initializeBeanContextResources

protected void initializeBeanContextResources()
Called by setBeanContext() to grab resources when the parent has been set.

This method is meant to be overriden. BeanContextChildSupport's implementation does nothing.


isDelegated

public boolean isDelegated()
Determine whether there is a peer. This is true iff getBeanContextChildPeer() == this.
Returns:
whether there is a peer.

releaseBeanContextResources

protected void releaseBeanContextResources()
Called by 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.


removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Remove a listener to a certain property.
Specified by:
removePropertyChangeListener in interface BeanContextChild
Parameters:
propertyName - the name of the property being listened on.
listener - the listener listening on the property.

removeVetoableChangeListener

public void removeVetoableChangeListener(String propertyName,
                                         VetoableChangeListener listener)
Remove a listener to a certain property.
Specified by:
removeVetoableChangeListener in interface BeanContextChild
Parameters:
propertyName - the name of the property being listened on
listener - the listener listening on the property.

serviceAvailable

public void serviceAvailable(BeanContextServiceAvailableEvent event)
Called by BeanContextServices whenever a service is made available.

This method is meant to be overriden. BeanContextChildSupport's implementation does nothing.

Specified by:
serviceAvailable in interface BeanContextServicesListener
Parameters:
event - the service revoked event, with useful information about the new service.

serviceRevoked

public void serviceRevoked(BeanContextServiceRevokedEvent event)
Called by 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.

Specified by:
serviceRevoked in interface BeanContextServiceRevokedListener
Parameters:
event - the service revoked event.

setBeanContext

public void setBeanContext(BeanContext newBeanContext)
            throws PropertyVetoException
Set the parent 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:

  1. If the new BeanContext is the same as the old one, nothing happens.
  2. If the change has not been rejected or vetoed before, call validatePendingSetBeanContext(). If this call returns false, the change is rejected and a PropertyVetoException is thrown.
  3. If the change has not been rejected or vetoed before, VetoableChangeEvents 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.
  4. releaseBeanContextResources() is called.
  5. The change is made.
  6. PropertyChangeEvents are fired using the firePropertyChange() method.
  7. initializeBeanContextResources() is called.

Specified by:
setBeanContext in interface BeanContextChild
Parameters:
newBeanContext - the new parent for the BeanContextChild, or null to signify removal from a tree.
Throws:
PropertyVetoException - if the BeanContextChild implementor does not wish to have its parent changed.

validatePendingSetBeanContext

public boolean validatePendingSetBeanContext(BeanContext newBeanContext)
Called by setBeanContext() to determine whether the set should be rejected.

This method is meant to be overriden. BeanContextChildSupport's implementation simply returns true.

Parameters:
newBeanContext - the new parent.
Returns:
whether to allow the parent to be changed to the new value.

java.beans.beancontext.BeanContextChildSupport Copyright (C) 1999 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.