FileDocCategorySizeDatePackage
BeanContextSupport.javaAPI DocJava SE 5 API40909Fri Aug 26 14:56:58 BST 2005java.beans.beancontext

BeanContextSupport

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.

author
Laurence P. G. Cable
version
1.46, 01/13/03
since
1.2

Fields Summary
static final long
serialVersionUID
protected transient HashMap
children
all accesses to the protected HashMap children field shall be synchronized on that object.
private int
serializable
protected transient ArrayList
bcmListeners
all accesses to the protected ArrayList bcmListeners field shall be synchronized on that object.
protected Locale
locale
The current locale of this BeanContext.
protected boolean
okToUseGui
A boolean indicating if this instance may now render a GUI.
protected boolean
designTime
A boolean indicating whether or not this object is currently in design time mode.
private transient PropertyChangeListener
childPCL
private transient VetoableChangeListener
childVCL
private transient boolean
serializing
Constructors Summary
public BeanContextSupport(BeanContext peer, Locale lcle, boolean dTime, boolean visible)
Construct a BeanContextSupport instance

param
peer The peer BeanContext we are supplying an implementation for, or null if this object is its own peer
param
lcle The current Locale for this BeanContext. If lcle is null, the default locale is assigned to the BeanContext instance.
param
dTime The initial state, true if in design mode, false if runtime.
param
visible The initial visibility.
see
java.util.Locale#getDefault()
see
java.util.Locale#setDefault(java.util.Locale)


            	                                                                         	                                                         	                                                	                   
             
	super(peer);

	locale          = lcle != null ? lcle : Locale.getDefault();
	designTime      = dTime;
	okToUseGui      = visible;

	initialize();
    
public BeanContextSupport(BeanContext peer, Locale lcle, boolean dtime)
Create an instance using the specified Locale and design mode.

param
peer The peer BeanContext we are supplying an implementation for, or null if this object is its own peer
param
lcle The current Locale for this BeanContext. If lcle is null, the default locale is assigned to the BeanContext instance.
param
dtime The initial state, true if in design mode, false if runtime.
see
java.util.Locale#getDefault()
see
java.util.Locale#setDefault(java.util.Locale)

	this (peer, lcle, dtime, true);
    
public BeanContextSupport(BeanContext peer, Locale lcle)
Create an instance using the specified locale

param
peer The peer BeanContext we are supplying an implementation for, or null if this object is its own peer
param
lcle The current Locale for this BeanContext. If lcle is null, the default locale is assigned to the BeanContext instance.
see
java.util.Locale#getDefault()
see
java.util.Locale#setDefault(java.util.Locale)

	this (peer, lcle, false, true);
    
public BeanContextSupport(BeanContext peer)
Create an instance using with a default locale

param
peer The peer BeanContext we are supplying an implementation for, or null if this object is its own peer

	this (peer, null, false, true);
    
public BeanContextSupport()
Create an instance that is not a delegate of another object

	this (null, null, false, true);
    
Methods Summary
public booleanadd(java.lang.Object targetChild)
/ /** Adds/nests a child within this BeanContext.

Invoked as a side effect of java.beans.Beans.instantiate(). If the child object is not valid for adding then this method throws an IllegalStateException.

param
targetChild The child objects to nest within this BeanContext
return
true if the child was added successfully.
see
#validatePendingAdd


	if (targetChild == null) throw new IllegalArgumentException();

	// The specification requires that we do nothing if the child
	// is already nested herein.

	if (children.containsKey(targetChild)) return false; // test before locking

	synchronized(BeanContext.globalHierarchyLock) {
	    if (children.containsKey(targetChild)) return false; // check again

	    if (!validatePendingAdd(targetChild)) {
	        throw new IllegalStateException();
	    }


	    // The specification requires that we invoke setBeanContext() on the
	    // newly added child if it implements the java.beans.beancontext.BeanContextChild interface

	    BeanContextChild cbcc  = getChildBeanContextChild(targetChild);
	    BeanContextChild  bccp = null;

	    synchronized(targetChild) {

		if (targetChild instanceof BeanContextProxy) {
		    bccp = ((BeanContextProxy)targetChild).getBeanContextProxy();

		    if (bccp == null) throw new NullPointerException("BeanContextPeer.getBeanContextProxy()");
		}

	        BCSChild bcsc  = createBCSChild(targetChild, bccp);
		BCSChild pbcsc = null;

	        synchronized (children) {
		    children.put(targetChild, bcsc);

		    if (bccp != null) children.put(bccp, pbcsc = createBCSChild(bccp, targetChild));
		}

	        if (cbcc != null) synchronized(cbcc) {
		    try {
	                cbcc.setBeanContext(getBeanContextPeer());
	            } catch (PropertyVetoException pve) {

		        synchronized (children) {
			    children.remove(targetChild);

			    if (bccp != null) children.remove(bccp);
			}

	                throw new IllegalStateException();
	            }

	            cbcc.addPropertyChangeListener("beanContext", childPCL);
	            cbcc.addVetoableChangeListener("beanContext", childVCL);
		}

	        Visibility v = getChildVisibility(targetChild);

	        if (v != null) {
	            if (okToUseGui)
	                v.okToUseGui();
	            else
	                v.dontUseGui();
	        }

	        if (getChildSerializable(targetChild) != null) serializable++;

	        childJustAddedHook(targetChild, bcsc);

		if (bccp != null) {
	            v = getChildVisibility(bccp);

	            if (v != null) {
	                if (okToUseGui)
	                    v.okToUseGui();
	                else
	                    v.dontUseGui();
	            }

		    if (getChildSerializable(bccp) != null) serializable++;

	            childJustAddedHook(bccp, pbcsc);
		}


	    }

	    // The specification requires that we fire a notification of the change

	    fireChildrenAdded(new BeanContextMembershipEvent(getBeanContextPeer(), bccp == null ? new Object[] { targetChild } : new Object[] { targetChild, bccp } ));

        }

	return true;
    
public booleanaddAll(java.util.Collection c)
add Collection to set of Children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

throws
UnsupportedOperationException

	throw new UnsupportedOperationException();
    
public voidaddBeanContextMembershipListener(java.beans.beancontext.BeanContextMembershipListener bcml)
Adds a BeanContextMembershipListener

param
bcml the BeanContextMembershipListener to add
throws
NullPointerException

	if (bcml == null) throw new NullPointerException("listener");

	synchronized(bcmListeners) {
	    if (bcmListeners.contains(bcml))
		return;
	    else
	        bcmListeners.add(bcml);
	}
    
public booleanavoidingGui()
Used to determine if the BeanContext child is avoiding using its GUI.

return
is this instance avoiding using its GUI?
see
Visibility

	return !okToUseGui && needsGui();
    
protected java.util.IteratorbcsChildren()
Returns an iterator of all children of this BeanContext.

return
an iterator for all the current BCSChild values

 synchronized(children) { return children.values().iterator();  } 
protected voidbcsPreDeserializationHook(java.io.ObjectInputStream ois)
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().

    
protected voidbcsPreSerializationHook(java.io.ObjectOutputStream oos)
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().

    
protected voidchildDeserializedHook(java.lang.Object child, java.beans.beancontext.BeanContextSupport$BCSChild bcsc)
Called by readObject with the newly deserialized child and BCSChild.

param
child the newly deserialized child
param
bcsc the newly deserialized BCSChild

	synchronized(children) {
	    children.put(child, bcsc);
	}
    
protected voidchildJustAddedHook(java.lang.Object child, java.beans.beancontext.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.

    
protected voidchildJustRemovedHook(java.lang.Object child, java.beans.beancontext.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.

    
protected static final booleanclassEquals(java.lang.Class first, java.lang.Class second)
Tests to see if two class objects, or their names are equal.

param
first the first object
param
second the second object
return
true if equal, false if not

	return first.equals(second) || first.getName().equals(second.getName());
    
public voidclear()
clear the children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

throws
UnsupportedOperationException

	throw new UnsupportedOperationException();
    
public booleancontains(java.lang.Object o)
Determines whether or not the specified object is currently a child of this BeanContext.

param
o the Object in question
return
if this object is a child

	synchronized(children) {
	    return children.containsKey(o);
	}
    
public booleancontainsAll(java.util.Collection c)
Tests to see if all objects in the specified Collection are children of this BeanContext.

param
c the specified Collection
return
true if all objects in the collection are children of this BeanContext, false if not.

	synchronized(children) {
	    Iterator i = c.iterator();
	    while (i.hasNext())
	        if(!contains(i.next()))
		    return false;

	    return true;
	}
    
public booleancontainsKey(java.lang.Object o)
Determines whether or not the specified object is currently a child of this BeanContext.

param
o the Object in question
return
if this object is a child

	synchronized(children) {
	    return children.containsKey(o);
	}
    
protected final java.lang.Object[]copyChildren()
Gets a copy of the this BeanContext's children.

return
a copy of the current nested children

	synchronized(children) { return children.keySet().toArray(); }
    
protected java.beans.beancontext.BeanContextSupport$BCSChildcreateBCSChild(java.lang.Object targetChild, java.lang.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.

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

	return new BCSChild(targetChild, peer);
    
protected final voiddeserialize(java.io.ObjectInputStream ois, java.util.Collection coll)
used by readObject to deserialize a collection.

param
ois the ObjectInputStream to use
param
coll the Collection

	int count = 0;

	count = ois.readInt();

	while (count-- > 0) {
	    coll.add(ois.readObject());
	}
    
public synchronized voiddontUseGui()
notify this instance that it may no longer render a GUI.

	if (okToUseGui) {
	    okToUseGui = false;

	    // lets also tell the Children that can that they may not use their GUI's
	    synchronized(children) {
	        for (Iterator i = children.keySet().iterator(); i.hasNext();) {
		    Visibility v = getChildVisibility(i.next());

		    if (v != null) v.dontUseGui();
	       }
	    }
	}
    
protected final voidfireChildrenAdded(java.beans.beancontext.BeanContextMembershipEvent bcme)
Fire a BeanContextshipEvent on the BeanContextMembershipListener interface

	Object[] copy;
							  
	synchronized(bcmListeners) { copy = bcmListeners.toArray(); }

	for (int i = 0; i < copy.length; i++)
	    ((BeanContextMembershipListener)copy[i]).childrenAdded(bcme);
    
protected final voidfireChildrenRemoved(java.beans.beancontext.BeanContextMembershipEvent bcme)
Fire a BeanContextshipEvent on the BeanContextMembershipListener interface

	Object[] copy;
							  
	synchronized(bcmListeners) { copy = bcmListeners.toArray(); }

	for (int i = 0; i < copy.length; i++)
	    ((BeanContextMembershipListener)copy[i]).childrenRemoved(bcme);
    
public java.beans.beancontext.BeanContextgetBeanContextPeer()
Gets the instance of BeanContext that this object is providing the implementation for.

return
the BeanContext instance

 return (BeanContext)getBeanContextChildPeer(); 
protected static final java.beans.beancontext.BeanContextChildgetChildBeanContextChild(java.lang.Object child)
Gets the BeanContextChild (if any) of the specified child

param
child the specified child
return
the BeanContextChild (if any) of the specified child
throws
IllegalArgumentException if child implements both BeanContextChild and BeanContextProxy

        try {
	    BeanContextChild bcc = (BeanContextChild)child;

	    if (child instanceof BeanContextChild && child instanceof BeanContextProxy) 
		throw new IllegalArgumentException("child cannot implement both BeanContextChild and BeanContextProxy");
	    else
		return bcc;
	} catch (ClassCastException cce) {
	    try {
		return ((BeanContextProxy)child).getBeanContextProxy();
	    } catch (ClassCastException cce1) {
	        return null;
	    }
	}
    
protected static final java.beans.beancontext.BeanContextMembershipListenergetChildBeanContextMembershipListener(java.lang.Object child)
Gets the BeanContextMembershipListener (if any) of the specified child

param
child the specified child
return
the BeanContextMembershipListener (if any) of the specified child

	try {
	    return (BeanContextMembershipListener)child;
	} catch (ClassCastException cce) {
	    return null;
	}
    
protected static final java.beans.PropertyChangeListenergetChildPropertyChangeListener(java.lang.Object child)
Gets the PropertyChangeListener (if any) of the specified child

param
child the specified child
return
the PropertyChangeListener (if any) of the specified child

	try {
	    return (PropertyChangeListener)child;
	} catch (ClassCastException cce) {
	    return null;
	}
    
protected static final java.io.SerializablegetChildSerializable(java.lang.Object child)
Gets the Serializable (if any) associated with the specified Child

param
child the specified child
return
the Serializable (if any) associated with the specified Child

        try {
	    return (Serializable)child;
	} catch (ClassCastException cce) {
	    return null;
	}
    
protected static final java.beans.VetoableChangeListenergetChildVetoableChangeListener(java.lang.Object child)
Gets the VetoableChangeListener (if any) of the specified child

param
child the specified child
return
the VetoableChangeListener (if any) of the specified child

	try {
	    return (VetoableChangeListener)child;
	} catch (ClassCastException cce) {
	    return null;
	}
    
protected static final java.beans.VisibilitygetChildVisibility(java.lang.Object child)
Gets the Component (if any) associated with the specified child.

param
child the specified child
return
the Component (if any) associated with the specified child.

	try {
	    return (Visibility)child;
	} catch (ClassCastException cce) {
	    return null;
	}
    
public synchronized java.util.LocalegetLocale()
Gets the locale for this BeanContext.

return
the current Locale of the BeanContext

 return locale; 
public java.net.URLgetResource(java.lang.String name, java.beans.beancontext.BeanContextChild bcc)

param
name the name of the resource requested.
param
bcc the child object making the request.
return
the requested resource as an InputStream

	if (name == null) throw new NullPointerException("name");
	if (bcc  == null) throw new NullPointerException("bcc");

	if (containsKey(bcc)) {
	    ClassLoader cl = bcc.getClass().getClassLoader();

	    return cl != null ? cl.getResource(name)
			      : ClassLoader.getSystemResource(name);
	} else throw new IllegalArgumentException("Not a valid child");
    
public java.io.InputStreamgetResourceAsStream(java.lang.String name, java.beans.beancontext.BeanContextChild bcc)

param
name the name of the resource requested.
param
bcc the child object making the request.
return
the requested resource as an InputStream
throws
NullPointerException

	if (name == null) throw new NullPointerException("name");
	if (bcc  == null) throw new NullPointerException("bcc");

	if (containsKey(bcc)) {
	    ClassLoader cl = bcc.getClass().getClassLoader();

	    return cl != null ? cl.getResourceAsStream(name)
			      : ClassLoader.getSystemResourceAsStream(name);
	} else throw new IllegalArgumentException("Not a valid child");
    
protected synchronized voidinitialize()
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

	children     = new HashMap(serializable + 1);
	bcmListeners = new ArrayList(1);

	childPCL = new PropertyChangeListener() {

	    /*
	     * this adaptor is used by the BeanContextSupport class to forward
	     * property changes from a child to the BeanContext, avoiding 
	     * accidential serialization of the BeanContext by a badly 
	     * behaved Serializable child.
	     */

	    public void propertyChange(PropertyChangeEvent pce) {
	        BeanContextSupport.this.propertyChange(pce);
	    }
	};

	childVCL = new VetoableChangeListener() {

	    /*
	     * this adaptor is used by the BeanContextSupport class to forward
	     * vetoable changes from a child to the BeanContext, avoiding 
	     * accidential serialization of the BeanContext by a badly 
	     * behaved Serializable child.
	     */

	    public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
	        BeanContextSupport.this.vetoableChange(pce);
             }
        };
    
public java.lang.ObjectinstantiateChild(java.lang.String beanName)

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.

param
beanName the name of the Bean to instantiate within this BeanContext
throws
IOException if there is an I/O error when the bean is being deserialized
throws
ClassNotFoundException if the class identified by the beanName parameter is not found
return
the new object

	BeanContext bc = getBeanContextPeer();

	return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
    
public synchronized booleanisDesignTime()
Reports whether or not this object is in currently in design time mode.

return
true if in design time mode, false if not

 return designTime; 
public booleanisEmpty()
Reports whether or not this BeanContext is empty. A BeanContext is considered empty when it contains zero nested children.

return
if there are not children

	synchronized(children) {
	    return children.isEmpty();
	}
    
public booleanisSerializing()
Is this BeanContext in the process of being serialized?

return
if this BeanContext is currently being serialized

 return serializing; 
public java.util.Iteratoriterator()
Gets all JavaBean or BeanContext instances currently nested in this BeanContext.

return
an Iterator of the nested children

	synchronized(children) {
	    return new BCSIterator(children.keySet().iterator());
	}
    
public synchronized booleanneedsGui()

This method is typically called from the environment in order to determine if the implementor "needs" a GUI.

The algorithm used herein tests the BeanContextPeer, and its current children to determine if they are either Containers, Components, or if they implement Visibility and return needsGui() == true.

return
true if the implementor needs a GUI

	BeanContext bc = getBeanContextPeer();

	if (bc != this) {
	    if (bc instanceof Visibility) return ((Visibility)bc).needsGui();

	    if (bc instanceof Container || bc instanceof Component)
		return true;
	}

	synchronized(children) {
	    for (Iterator i = children.keySet().iterator(); i.hasNext();) {
	        Object c = i.next();

	        try {
		        return ((Visibility)c).needsGui();
		    } catch (ClassCastException cce) {
		        // do nothing ...
		    }

		    if (c instanceof Container || c instanceof Component)
		        return true;
	    }
	}

	return false;
    
public synchronized voidokToUseGui()
Notify this instance that it may now render a GUI

	if (!okToUseGui) {
	    okToUseGui = true;

	    // lets also tell the Children that can that they may use their GUI's
	    synchronized(children) {
	        for (Iterator i = children.keySet().iterator(); i.hasNext();) {
		    Visibility v = getChildVisibility(i.next());

		    if (v != null) v.okToUseGui();
	        }
	    }
	}
    
public voidpropertyChange(java.beans.PropertyChangeEvent pce)
subclasses may envelope to monitor child property changes.

	String propertyName = pce.getPropertyName();
	Object source	    = pce.getSource();

	synchronized(children) {
	    if ("beanContext".equals(propertyName) &&
	        containsKey(source)		       &&
	        ((BCSChild)children.get(source)).isRemovePending()) {
	        BeanContext bc = getBeanContextPeer();

	        if (bc.equals(pce.getOldValue()) && !bc.equals(pce.getNewValue())) {
	            remove(source, false);
	        } else {
		    ((BCSChild)children.get(source)).setRemovePending(false);
	        }
	    }
        }
    
public final voidreadChildren(java.io.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

	int count = serializable; 

	while (count-- > 0) {
	    Object                      child = null;
	    BeanContextSupport.BCSChild bscc  = null;
	  
	    try {
	        child = ois.readObject();
	        bscc  = (BeanContextSupport.BCSChild)ois.readObject();
	    } catch (IOException ioe) {
		continue;
	    } catch (ClassNotFoundException cnfe) {
		continue;
	    }


	    synchronized(child) {
		BeanContextChild bcc = null;

		try {
		    bcc = (BeanContextChild)child;
		} catch (ClassCastException cce) {
		    // do nothing;
		}

		if (bcc != null) {
		    try {
			bcc.setBeanContext(getBeanContextPeer());

	               bcc.addPropertyChangeListener("beanContext", childPCL);
	               bcc.addVetoableChangeListener("beanContext", childVCL);
	
		    } catch (PropertyVetoException pve) {
			continue;
		    }
		}

		childDeserializedHook(child, bscc);
	    }
	}
    
private synchronized voidreadObject(java.io.ObjectInputStream ois)
deserialize contents ... if this instance has a distinct peer the children are *not* serialized here, the peer's readObject() must call readChildren() after deserializing this instance.


	synchronized(BeanContext.globalHierarchyLock) {
	    ois.defaultReadObject();

	    initialize();

	    bcsPreDeserializationHook(ois);

	    if (serializable > 0 && this.equals(getBeanContextPeer()))
	        readChildren(ois);

	    deserialize(ois, bcmListeners = new ArrayList(1));
	}
    
public booleanremove(java.lang.Object targetChild)
Removes a child from this BeanContext. If the child object is not for adding then this method throws an IllegalStateException.

param
targetChild The child objects to remove
see
#validatePendingRemove

	return remove(targetChild, true);
    
protected booleanremove(java.lang.Object targetChild, boolean callChildSetBC)
internal remove used when removal caused by unexpected setBeanContext or by remove() invocation.

param
targetChild the JavaBean, BeanContext, or Object to be removed
param
callChildSetBC used to indicate that the child should be notified that it is no longer nested in this BeanContext.


	if (targetChild == null) throw new IllegalArgumentException();

	synchronized(BeanContext.globalHierarchyLock) {
	    if (!containsKey(targetChild)) return false;

	    if (!validatePendingRemove(targetChild)) {
	        throw new IllegalStateException();
	    }

            BCSChild bcsc  = (BCSChild)children.get(targetChild);
	    BCSChild pbcsc = null;
	    Object   peer  = null;

	    // we are required to notify the child that it is no longer nested here if
	    // it implements java.beans.beancontext.BeanContextChild

	    synchronized(targetChild) {
	        if (callChildSetBC) {
	            BeanContextChild cbcc = getChildBeanContextChild(targetChild);
	            if (cbcc != null) synchronized(cbcc) {
	                cbcc.removePropertyChangeListener("beanContext", childPCL);
	                cbcc.removeVetoableChangeListener("beanContext", childVCL);

			try {
	                    cbcc.setBeanContext(null);
	                } catch (PropertyVetoException pve1) {
	                    cbcc.addPropertyChangeListener("beanContext", childPCL);
	                    cbcc.addVetoableChangeListener("beanContext", childVCL);
	    	            throw new IllegalStateException();
	                }

		    }
	        }

	        synchronized (children) {
		    children.remove(targetChild);

		    if (bcsc.isProxyPeer()) {
			pbcsc = (BCSChild)children.get(peer = bcsc.getProxyPeer());
			children.remove(peer);
		    }
		}

	        if (getChildSerializable(targetChild) != null) serializable--;

	        childJustRemovedHook(targetChild, bcsc);

		if (peer != null) {
	            if (getChildSerializable(peer) != null) serializable--;

	            childJustRemovedHook(peer, pbcsc);
		}
	    }

	    fireChildrenRemoved(new BeanContextMembershipEvent(getBeanContextPeer(), peer == null ? new Object[] { targetChild } : new Object[] { targetChild, peer } ));

	}

	return true;
    
public booleanremoveAll(java.util.Collection c)
remove all specified children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

throws
UnsupportedOperationException

	throw new UnsupportedOperationException();
    
public voidremoveBeanContextMembershipListener(java.beans.beancontext.BeanContextMembershipListener bcml)
Removes a BeanContextMembershipListener

param
bcml the BeanContextMembershipListener to remove
throws
NullPointerException

	if (bcml == null) throw new NullPointerException("listener");

	synchronized(bcmListeners) {
	    if (!bcmListeners.contains(bcml))
		return;
	    else
	        bcmListeners.remove(bcml);
	}
    
public booleanretainAll(java.util.Collection c)
retain only specified children (Unsupported) implementations must synchronized on the hierarchy lock and "children" protected field

throws
UnsupportedOperationException

	throw new UnsupportedOperationException();
    
protected final voidserialize(java.io.ObjectOutputStream oos, java.util.Collection coll)
Used by writeObject to serialize a Collection.

param
oos the ObjectOutputStream to use during serialization
param
coll the Collection to serialize
throws
IOException if serialization failed

   	int      count   = 0;
	Object[] objects = coll.toArray();
    
	for (int i = 0; i < objects.length; i++) {
	    if (objects[i] instanceof Serializable)
		count++;
	    else
		objects[i] = null;
	}

        oos.writeInt(count); // number of subsequent objects

	for (int i = 0; count > 0; i++) {
	    Object o = objects[i];

	    if (o != null) {
		oos.writeObject(o);
		count--;
	    }
	}
    
public synchronized voidsetDesignTime(boolean dTime)
Sets the new design time value for this BeanContext.

param
dTime the new designTime value

	if (designTime != dTime) {
	    designTime = dTime;

	    firePropertyChange("designMode", Boolean.valueOf(!dTime), Boolean.valueOf(dTime));
	}
    
public synchronized voidsetLocale(java.util.Locale newLocale)
Sets the locale of this BeanContext.

param
newLocale the new locale. This method call will have no effect if newLocale is null.
throws
PropertyVetoException if the new value is rejected


	if ((locale != null && !locale.equals(newLocale)) && newLocale != null) {
	    Locale old = locale;

	    fireVetoableChange("locale", old, newLocale); // throws

	    locale = newLocale;

	    firePropertyChange("locale", old, newLocale);
	}
    
public intsize()
Gets the number of children currently nested in this BeanContext.

return
number of children

	synchronized(children) {
	    return children.size();
	}
    
public java.lang.Object[]toArray()
Gets all JavaBean or BeanContext instances currently nested in this BeanContext.

	synchronized(children) {
	    return children.keySet().toArray();
	}
    
public java.lang.Object[]toArray(java.lang.Object[] arry)
Gets an array containing all children of this BeanContext that match the types contained in arry.

param
arry The array of object types that are of interest.
return
an array of children

	synchronized(children) {
	    return children.keySet().toArray(arry);
	}
    
protected booleanvalidatePendingAdd(java.lang.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.

return
true iff the child may be added to this BeanContext, otherwise false.

	return true;
    
protected booleanvalidatePendingRemove(java.lang.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.

return
true iff the child may be removed from this BeanContext, otherwise false.

	return true;
    
public voidvetoableChange(java.beans.PropertyChangeEvent pce)
subclasses may envelope to monitor veto child property changes.

	String propertyName = pce.getPropertyName();
	Object source	    = pce.getSource();

	synchronized(children) {
	    if ("beanContext".equals(propertyName) &&
	        containsKey(source)	               &&
	        !getBeanContextPeer().equals(pce.getNewValue())
	    ) {
	        if (!validatePendingRemove(source)) {
		    throw new PropertyVetoException("current BeanContext vetoes setBeanContext()", pce);
	        } else ((BCSChild)children.get(source)).setRemovePending(true);
	    }
	}
    
public final voidwriteChildren(java.io.ObjectOutputStream oos)
Used to serialize all children of this BeanContext.

param
oos the ObjectOutputStream to use during serialization
throws
IOException if serialization failed

	if (serializable <= 0) return;

	boolean prev = serializing;

	serializing = true;

	int count = 0;

	synchronized(children) {
	    Iterator i = children.entrySet().iterator();

	    while (i.hasNext() && count < serializable) {
	        Map.Entry entry = (Map.Entry)i.next();

	        if (entry.getKey() instanceof Serializable) {
	      	    try {
		        oos.writeObject(entry.getKey());   // child
		        oos.writeObject(entry.getValue()); // BCSChild
		    } catch (IOException ioe) {
		        serializing = prev;
		        throw ioe;
		    }
		    count++;
	        }
	    }
	}
	
        serializing = prev;

	if (count != serializable) {
	    throw new IOException("wrote different number of children than expected");
	}

    
private synchronized voidwriteObject(java.io.ObjectOutputStream oos)
Serialize the BeanContextSupport, if this instance has a distinct peer (that is this object is acting as a delegate for another) then the children of this instance are not serialized here due to a 'chicken and egg' problem that occurs on deserialization of the children at the same time as this instance. Therefore in situations where there is a distinct peer to this instance it should always call writeObject() followed by writeChildren() and readObject() followed by readChildren().

param
oos the ObjectOutputStream

	serializing = true;

	synchronized (BeanContext.globalHierarchyLock) {
	    try {
	        oos.defaultWriteObject(); // serialize the BeanContextSupport object

	        bcsPreSerializationHook(oos);

	        if (serializable > 0 && this.equals(getBeanContextPeer()))
	            writeChildren(oos);

	        serialize(oos, (Collection)bcmListeners);
	    } finally {
	        serializing = false;
	    }
 	}