Methods Summary |
---|
public boolean | add(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.
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 boolean | addAll(java.util.Collection c)add Collection to set of Children (Unsupported)
implementations must synchronized on the hierarchy lock and "children" protected field
throw new UnsupportedOperationException();
|
public void | addBeanContextMembershipListener(java.beans.beancontext.BeanContextMembershipListener bcml)Adds a BeanContextMembershipListener
if (bcml == null) throw new NullPointerException("listener");
synchronized(bcmListeners) {
if (bcmListeners.contains(bcml))
return;
else
bcmListeners.add(bcml);
}
|
public boolean | avoidingGui()Used to determine if the BeanContext
child is avoiding using its GUI.
return !okToUseGui && needsGui();
|
protected java.util.Iterator | bcsChildren()Returns an iterator of all children
of this BeanContext. synchronized(children) { return children.values().iterator(); }
|
protected void | bcsPreDeserializationHook(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 void | bcsPreSerializationHook(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 void | childDeserializedHook(java.lang.Object child, java.beans.beancontext.BeanContextSupport$BCSChild bcsc)Called by readObject with the newly deserialized child and BCSChild.
synchronized(children) {
children.put(child, bcsc);
}
|
protected void | childJustAddedHook(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 void | childJustRemovedHook(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 boolean | classEquals(java.lang.Class first, java.lang.Class second)Tests to see if two class objects,
or their names are equal.
return first.equals(second) || first.getName().equals(second.getName());
|
public void | clear()clear the children (Unsupported)
implementations must synchronized on the hierarchy lock and "children" protected field
throw new UnsupportedOperationException();
|
public boolean | contains(java.lang.Object o)Determines whether or not the specified object
is currently a child of this BeanContext.
synchronized(children) {
return children.containsKey(o);
}
|
public boolean | containsAll(java.util.Collection c)Tests to see if all objects in the
specified Collection are children of
this BeanContext.
synchronized(children) {
Iterator i = c.iterator();
while (i.hasNext())
if(!contains(i.next()))
return false;
return true;
}
|
public boolean | containsKey(java.lang.Object o)Determines whether or not the specified object
is currently a child of this BeanContext.
synchronized(children) {
return children.containsKey(o);
}
|
protected final java.lang.Object[] | copyChildren()Gets a copy of the this BeanContext's children.
synchronized(children) { return children.keySet().toArray(); }
|
protected java.beans.beancontext.BeanContextSupport$BCSChild | createBCSChild(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.
return new BCSChild(targetChild, peer);
|
protected final void | deserialize(java.io.ObjectInputStream ois, java.util.Collection coll)used by readObject to deserialize a collection.
int count = 0;
count = ois.readInt();
while (count-- > 0) {
coll.add(ois.readObject());
}
|
public synchronized void | dontUseGui()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 void | fireChildrenAdded(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 void | fireChildrenRemoved(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.BeanContext | getBeanContextPeer()Gets the instance of BeanContext that
this object is providing the implementation for. return (BeanContext)getBeanContextChildPeer();
|
protected static final java.beans.beancontext.BeanContextChild | getChildBeanContextChild(java.lang.Object child)Gets the BeanContextChild (if any) of the specified child
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.BeanContextMembershipListener | getChildBeanContextMembershipListener(java.lang.Object child)Gets the BeanContextMembershipListener
(if any) of the specified child
try {
return (BeanContextMembershipListener)child;
} catch (ClassCastException cce) {
return null;
}
|
protected static final java.beans.PropertyChangeListener | getChildPropertyChangeListener(java.lang.Object child)Gets the PropertyChangeListener
(if any) of the specified child
try {
return (PropertyChangeListener)child;
} catch (ClassCastException cce) {
return null;
}
|
protected static final java.io.Serializable | getChildSerializable(java.lang.Object child)Gets the Serializable (if any) associated with the specified Child
try {
return (Serializable)child;
} catch (ClassCastException cce) {
return null;
}
|
protected static final java.beans.VetoableChangeListener | getChildVetoableChangeListener(java.lang.Object child)Gets the VetoableChangeListener
(if any) of the specified child
try {
return (VetoableChangeListener)child;
} catch (ClassCastException cce) {
return null;
}
|
protected static final java.beans.Visibility | getChildVisibility(java.lang.Object child)Gets the Component (if any) associated with the specified child.
try {
return (Visibility)child;
} catch (ClassCastException cce) {
return null;
}
|
public synchronized java.util.Locale | getLocale()Gets the locale for this BeanContext. return locale;
|
public java.net.URL | getResource(java.lang.String name, java.beans.beancontext.BeanContextChild bcc)
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.InputStream | getResourceAsStream(java.lang.String name, java.beans.beancontext.BeanContextChild bcc)
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 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
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.Object | instantiateChild(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.
BeanContext bc = getBeanContextPeer();
return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
|
public synchronized boolean | isDesignTime()Reports whether or not this object is in
currently in design time mode. return designTime;
|
public boolean | isEmpty()Reports whether or not this
BeanContext is empty.
A BeanContext is considered
empty when it contains zero
nested children.
synchronized(children) {
return children.isEmpty();
}
|
public boolean | isSerializing()Is this BeanContext in the
process of being serialized? return serializing;
|
public java.util.Iterator | iterator()Gets all JavaBean or BeanContext instances
currently nested in this BeanContext.
synchronized(children) {
return new BCSIterator(children.keySet().iterator());
}
|
public synchronized boolean | needsGui()
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.
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 void | okToUseGui()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 void | propertyChange(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 void | readChildren(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 void | readObject(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 boolean | remove(java.lang.Object targetChild)Removes a child from this BeanContext. If the child object is not
for adding then this method throws an IllegalStateException.
return remove(targetChild, true);
|
protected boolean | remove(java.lang.Object targetChild, boolean callChildSetBC)internal remove used when removal caused by
unexpected setBeanContext or
by remove() invocation.
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 boolean | removeAll(java.util.Collection c)remove all specified children (Unsupported)
implementations must synchronized on the hierarchy lock and "children" protected field
throw new UnsupportedOperationException();
|
public void | removeBeanContextMembershipListener(java.beans.beancontext.BeanContextMembershipListener bcml)Removes a BeanContextMembershipListener
if (bcml == null) throw new NullPointerException("listener");
synchronized(bcmListeners) {
if (!bcmListeners.contains(bcml))
return;
else
bcmListeners.remove(bcml);
}
|
public boolean | retainAll(java.util.Collection c)retain only specified children (Unsupported)
implementations must synchronized on the hierarchy lock and "children" protected field
throw new UnsupportedOperationException();
|
protected final void | serialize(java.io.ObjectOutputStream oos, java.util.Collection coll)Used by writeObject to serialize a Collection.
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 void | setDesignTime(boolean dTime)Sets the new design time value for this BeanContext.
if (designTime != dTime) {
designTime = dTime;
firePropertyChange("designMode", Boolean.valueOf(!dTime), Boolean.valueOf(dTime));
}
|
public synchronized void | setLocale(java.util.Locale newLocale)Sets the locale of this BeanContext.
if ((locale != null && !locale.equals(newLocale)) && newLocale != null) {
Locale old = locale;
fireVetoableChange("locale", old, newLocale); // throws
locale = newLocale;
firePropertyChange("locale", old, newLocale);
}
|
public int | size()Gets the number of children currently nested in
this BeanContext.
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.
synchronized(children) {
return children.keySet().toArray(arry);
}
|
protected boolean | validatePendingAdd(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;
|
protected boolean | validatePendingRemove(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;
|
public void | vetoableChange(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 void | writeChildren(java.io.ObjectOutputStream oos)Used to serialize all children of
this BeanContext.
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 void | writeObject(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().
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;
}
}
|