Java Platform 1.2

java.beans.beancontext
Class BeanContextSupport

java.lang.Object
  |
  +--java.beans.beancontext.BeanContextChildSupport
        |
        +--java.beans.beancontext.BeanContextSupport
Direct Known Subclasses:
BeanContextServicesSupport

public class BeanContextSupport
extends BeanContextChildSupport
implements BeanContext, Serializable, PropertyChangeListener, VetoableChangeListener

This helper class provides a utility implementation of the java.beans.beancontext.BeanContext interface.

Since this class directly implements the BeanContext interface, the class can, and is intended to be used either by subclassing this implementation, or via ad-hoc delegation of an instance of this class from another.

Since:
JDK1.2
See Also:
Serialized Form

Inner Class Summary
protected  class BeanContextSupport.BCSChild
           
protected static class BeanContextSupport.BCSIterator
          protected final subclass that encapsulates an iterator but implements a noop remove() method.
 
Field Summary
protected  ArrayList bcmListeners
          all accesses to the protected ArrayList bcmListeners field shall be synchronized on that object.
protected  HashMap children
          all accesses to the protected HashMap children field shall be synchronized on that object.
protected  boolean designTime
           
protected  Locale locale
           
protected  boolean okToUseGui
           
 
Fields inherited from class java.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
 
Constructor Summary
BeanContextSupport()
          Create an instance that is not a delegate of another object
BeanContextSupport(BeanContext peer)
          Create an instance using with a default locale
BeanContextSupport(BeanContext peer, Locale lcle)
          Create an instance using the specified locale
BeanContextSupport(BeanContext peer, Locale lcle, boolean dtime)
          Create an instance using the specified Locale and design mode.
BeanContextSupport(BeanContext peer, Locale lcle, boolean dTime, boolean visible)
           Construct a BeanContextSupport instance
 
Method Summary
 boolean add(Object targetChild)
           Adds/nests a child within this BeanContext Invoked as a side effect of java.beans.Beans.instantiate().
 boolean addAll(Collection c)
          add Collection to set of Children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field
 void addBeanContextMembershipListener(BeanContextMembershipListener bcml)
          Adds a BeanContextMembershipListener
 boolean avoidingGui()
           
protected  Iterator bcsChildren()
           
protected  void bcsPreDeserializationHook(ObjectInputStream ois)
          called by readObject after defaultReadObject() but prior to deserialization of any children.
protected  void bcsPreSerializationHook(ObjectOutputStream oos)
          called by writeObject after defaultWriteObject() but prior to serialization of currently serializable children.
protected  void childDeserializedHook(Object child, BeanContextSupport.BCSChild bcsc)
          called by readObject with the newly deserialized child and BCSChild
protected  void childJustAddedHook(Object child, BeanContextSupport.BCSChild bcsc)
          subclasses may override this method to simply extend add() semantics after the child has been added and before the event notification has occurred.
protected  void childJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsc)
          subclasses may override this method to simply extend remove() semantics after the child has been removed and before the event notification has occurred.
protected static boolean classEquals(Class first, Class second)
           
 void clear()
          clear the children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 boolean containsKey(Object o)
           
protected  Object[] copyChildren()
           
protected  BeanContextSupport.BCSChild createBCSChild(Object targetChild, Object peer)
           Subclasses can override this method to insert their own subclass of Child without having to override add() or the other Collection methods that add children to the set.
protected  void deserialize(ObjectInputStream ois, Collection coll)
          used by readObject to deserialize a collection
 void dontUseGui()
          notify this instance that it may no longer render a GUI.
protected  void fireChildrenAdded(BeanContextMembershipEvent bcme)
          Fire a BeanContextshipEvent on the BeanContextMembershipListener interface
protected  void fireChildrenRemoved(BeanContextMembershipEvent bcme)
          Fire a BeanContextshipEvent on the BeanContextMembershipListener interface
 BeanContext getBeanContextPeer()
           
protected static BeanContextChild getChildBeanContextChild(Object child)
           
protected static BeanContextMembershipListener getChildBeanContextMembershipListener(Object child)
           
protected static PropertyChangeListener getChildPropertyChangeListener(Object child)
           
protected static Serializable getChildSerializable(Object child)
           
protected static VetoableChangeListener getChildVetoableChangeListener(Object child)
           
protected static Visibility getChildVisibility(Object child)
           
 Locale getLocale()
           
 URL getResource(String name, BeanContextChild bcc)
           
 InputStream getResourceAsStream(String name, BeanContextChild bcc)
           
protected  void initialize()
          protected method called from constructor and readObject to initialize transient state of BeanContextSupport instance.
 Object instantiateChild(String beanName)
           The instantiateChild method is a convenience hook in BeanContext to simplify the task of instantiating a Bean, nested, into a BeanContext.
 boolean isDesignTime()
           
 boolean isEmpty()
           
 boolean isSerializing()
           
 Iterator iterator()
           
 boolean needsGui()
           
 void okToUseGui()
          Notify this instance that it may now render a GUI
 void propertyChange(PropertyChangeEvent pce)
          subclasses may envelope to monitor child property changes.
 void readChildren(ObjectInputStream ois)
          When an instance of this class is used as a delegate for the implementation of the BeanContext protocols (and its subprotocols) there exists a 'chicken and egg' problem during deserialization
 boolean remove(Object targetChild)
           
protected  boolean remove(Object targetChild, boolean callChildSetBC)
           
 boolean removeAll(Collection c)
          remove all specified children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field
 void removeBeanContextMembershipListener(BeanContextMembershipListener bcml)
          Removes a BeanContextMembershipListener
 boolean retainAll(Collection c)
          retain only specified children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field
protected  void serialize(ObjectOutputStream oos, Collection coll)
           
 void setDesignTime(boolean dTime)
           
 void setLocale(Locale newLocale)
           
 int size()
           
 Object[] toArray()
           
 Object[] toArray(Object[] arry)
           
protected  boolean validatePendingAdd(Object targetChild)
           Subclasses of this class may override, or envelope, this method to add validation behavior for the BeanContext to examine child objects immediately prior to their being added to the BeanContext.
protected  boolean validatePendingRemove(Object targetChild)
           Subclasses of this class may override, or envelope, this method to add validation behavior for the BeanContext to examine child objects immediately prior to their being removed from the BeanContext.
 void vetoableChange(PropertyChangeEvent pce)
          subclasses may envelope to monitor veto child property changes.
 void writeChildren(ObjectOutputStream oos)
           
 
Methods inherited from class java.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

children

protected transient HashMap children
all accesses to the protected HashMap children field shall be synchronized on that object.

bcmListeners

protected transient ArrayList bcmListeners
all accesses to the protected ArrayList bcmListeners field shall be synchronized on that object.

locale

protected Locale locale

okToUseGui

protected boolean okToUseGui

designTime

protected boolean designTime
Constructor Detail

BeanContextSupport

public BeanContextSupport(BeanContext peer,
                          Locale lcle,
                          boolean dTime,
                          boolean visible)

Construct a BeanContextSupport instance

Parameters:
peer - The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
lcle - The current Locale for this BeanContext.
dtime - The initial state, true if in design mode, false if runtime.
visible - The initial visibility.

BeanContextSupport

public BeanContextSupport(BeanContext peer,
                          Locale lcle,
                          boolean dtime)
Create an instance using the specified Locale and design mode.
Parameters:
peer - The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
lcle - The current Locale for this BeanContext.
dtime - The initial state, true if in design mode, false if runtime.

BeanContextSupport

public BeanContextSupport(BeanContext peer,
                          Locale lcle)
Create an instance using the specified locale
Parameters:
peer - The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
lcle - The current Locale for this BeanContext.

BeanContextSupport

public BeanContextSupport(BeanContext peer)
Create an instance using with a default locale
Parameters:
peer - The peer BeanContext we are supplying an implementation for, if null the this object is its own peer

BeanContextSupport

public BeanContextSupport()
Create an instance that is not a delegate of another object
Method Detail

getBeanContextPeer

public BeanContext getBeanContextPeer()
Returns:
the instance of BeanContext this object is providing the implemen tation for.

instantiateChild

public Object instantiateChild(String beanName)
                        throws IOException,
                               ClassNotFoundException

The instantiateChild method is a convenience hook in BeanContext to simplify the task of instantiating a Bean, nested, into a BeanContext.

The semantics of the beanName parameter are defined by java.beans.Beans.instantate.

Specified by:
instantiateChild in interface BeanContext
Parameters:
beanName - the name of the Bean to instantiate within this BeanContext

size

public int size()
Returns:
number of children

isEmpty

public boolean isEmpty()
Returns:
if there are not children

contains

public boolean contains(Object o)
Returns:
if this object is a child

containsKey

public boolean containsKey(Object o)
Returns:
if this object is a child

iterator

public Iterator iterator()
Returns:
the iterator

toArray

public Object[] toArray()
Returns:
an array of children

toArray

public Object[] toArray(Object[] arry)
Returns:
an array of children

createBCSChild

protected BeanContextSupport.BCSChild createBCSChild(Object targetChild,
                                                     Object peer)

Subclasses can override this method to insert their own subclass of Child without having to override add() or the other Collection methods that add children to the set.

Parameters:
targetChild - the child to create the Child on behalf of
peer - the peer if the tragetChild and the peer are related by an implementation of BeanContextProxy

add

public boolean add(Object targetChild)

Adds/nests a child within this BeanContext

Invoked as a side effect of java.beans.Beans.instantiate().

Parameters:
targetChildren - The child objects to nest within this BeanContext

remove

public boolean remove(Object targetChild)
Parameters:
targetChildren - The child objects to remove

remove

protected boolean remove(Object targetChild,
                         boolean callChildSetBC)

containsAll

public boolean containsAll(Collection c)
Returns:
if all object objects in specified Collection are children.

addAll

public boolean addAll(Collection c)
add Collection to set of Children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

removeAll

public boolean removeAll(Collection c)
remove all specified children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

retainAll

public boolean retainAll(Collection c)
retain only specified children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

clear

public void clear()
clear the children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

addBeanContextMembershipListener

public void addBeanContextMembershipListener(BeanContextMembershipListener bcml)
Adds a BeanContextMembershipListener
Specified by:
addBeanContextMembershipListener in interface BeanContext
Parameters:
bcml - the BeanContextMembershipListener to add

removeBeanContextMembershipListener

public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml)
Removes a BeanContextMembershipListener
Specified by:
removeBeanContextMembershipListener in interface BeanContext
Parameters:
bcml - the BeanContextMembershipListener to remove

getResourceAsStream

public InputStream getResourceAsStream(String name,
                                       BeanContextChild bcc)
Specified by:
getResourceAsStream in interface BeanContext
Parameters:
name - the name of the resource requested.
child - the child object making the request.
Returns:
the requested resource as an InputStream

getResource

public URL getResource(String name,
                       BeanContextChild bcc)
Specified by:
getResource in interface BeanContext
Parameters:
name - the name of the resource requested.
child - the child object making the request.
Returns:
the requested resource as an InputStream

setDesignTime

public void setDesignTime(boolean dTime)
Parameters:
dTime - the new designTime value

isDesignTime

public boolean isDesignTime()
Returns:
Design time

setLocale

public void setLocale(Locale newLocale)
               throws PropertyVetoException
Parameters:
newLocale - the new locale

getLocale

public Locale getLocale()
Returns:
the current Locale of the BeanContext

needsGui

public boolean needsGui()

dontUseGui

public void dontUseGui()
notify this instance that it may no longer render a GUI.

okToUseGui

public void okToUseGui()
Notify this instance that it may now render a GUI

avoidingGui

public boolean avoidingGui()
Returns:
is this instance avoiding using its GUI?

isSerializing

public boolean isSerializing()
Returns:
if this BeanContext is currently being serialized

bcsChildren

protected Iterator bcsChildren()
Returns:
an iterator for all the current BCSChild values

bcsPreSerializationHook

protected void bcsPreSerializationHook(ObjectOutputStream oos)
                                throws IOException
called by writeObject after defaultWriteObject() but prior to serialization of currently serializable children. This method may be overridden by subclasses to perform custom serialization of their state prior to this superclass serializing the children. This method should not however be used by subclasses to replace their own implementation (if any) of writeObject().

bcsPreDeserializationHook

protected void bcsPreDeserializationHook(ObjectInputStream ois)
                                  throws IOException,
                                         ClassNotFoundException
called by readObject after defaultReadObject() but prior to deserialization of any children. This method may be overridden by subclasses to perform custom deserialization of their state prior to this superclass deserializing the children. This method should not however be used by subclasses to replace their own implementation (if any) of readObject().

childDeserializedHook

protected void childDeserializedHook(Object child,
                                     BeanContextSupport.BCSChild bcsc)
called by readObject with the newly deserialized child and BCSChild

serialize

protected final void serialize(ObjectOutputStream oos,
                               Collection coll)
                        throws IOException

deserialize

protected final void deserialize(ObjectInputStream ois,
                                 Collection coll)
                          throws IOException,
                                 ClassNotFoundException
used by readObject to deserialize a collection

writeChildren

public final void writeChildren(ObjectOutputStream oos)
                         throws IOException

readChildren

public final void readChildren(ObjectInputStream ois)
                        throws IOException,
                               ClassNotFoundException
When an instance of this class is used as a delegate for the implementation of the BeanContext protocols (and its subprotocols) there exists a 'chicken and egg' problem during deserialization

vetoableChange

public void vetoableChange(PropertyChangeEvent pce)
                    throws PropertyVetoException
subclasses may envelope to monitor veto child property changes.
Specified by:
vetoableChange in interface VetoableChangeListener

propertyChange

public void propertyChange(PropertyChangeEvent pce)
subclasses may envelope to monitor child property changes.
Specified by:
propertyChange in interface PropertyChangeListener

validatePendingAdd

protected boolean validatePendingAdd(Object targetChild)

Subclasses of this class may override, or envelope, this method to add validation behavior for the BeanContext to examine child objects immediately prior to their being added to the BeanContext.


validatePendingRemove

protected boolean validatePendingRemove(Object targetChild)

Subclasses of this class may override, or envelope, this method to add validation behavior for the BeanContext to examine child objects immediately prior to their being removed from the BeanContext.


childJustAddedHook

protected void childJustAddedHook(Object child,
                                  BeanContextSupport.BCSChild bcsc)
subclasses may override this method to simply extend add() semantics after the child has been added and before the event notification has occurred. The method is called with the child synchronized.

childJustRemovedHook

protected void childJustRemovedHook(Object child,
                                    BeanContextSupport.BCSChild bcsc)
subclasses may override this method to simply extend remove() semantics after the child has been removed and before the event notification has occurred. The method is called with the child synchronized.

getChildVisibility

protected static final Visibility getChildVisibility(Object child)
Returns:
the Component (if any) associated with the specified Child

getChildSerializable

protected static final Serializable getChildSerializable(Object child)
Returns:
the Serializable (if any) associated with the specified Child

getChildPropertyChangeListener

protected static final PropertyChangeListener getChildPropertyChangeListener(Object child)
Returns:
the PropertyChangeListener (if any) of the specified child

getChildVetoableChangeListener

protected static final VetoableChangeListener getChildVetoableChangeListener(Object child)
Returns:
the VetoableChangeListener (if any) of the specified child

getChildBeanContextMembershipListener

protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object child)
Returns:
the BeanContextMembershipListener (if any) of the specified child

getChildBeanContextChild

protected static final BeanContextChild getChildBeanContextChild(Object child)
Returns:
the BeanContextChild (if any) of the specified child

fireChildrenAdded

protected final void fireChildrenAdded(BeanContextMembershipEvent bcme)
Fire a BeanContextshipEvent on the BeanContextMembershipListener interface

fireChildrenRemoved

protected final void fireChildrenRemoved(BeanContextMembershipEvent bcme)
Fire a BeanContextshipEvent on the BeanContextMembershipListener interface

initialize

protected void initialize()
protected method called from constructor and readObject to initialize transient state of BeanContextSupport instance. This class uses this method to instantiate inner class listeners used to monitor PropertyChange and VetoableChange events on children. subclasses may envelope this method to add their own initialization behavior

copyChildren

protected final Object[] copyChildren()

classEquals

protected static final boolean classEquals(Class first,
                                           Class second)
Returns:
if two class objects, or their names are equal.

Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.