public class BeanContextSupport extends BeanContextChildSupport implements BeanContext, PropertyChangeListener, VetoableChangeListener, Serializable
BeanContext interface. This class can be used directly, or be a super class of your class, or be a delegate of
your implementation that needs to support BeanContext interface.| Modifier and Type | Class and Description |
|---|---|
protected class |
BeanContextSupport.BCSChild
Every child of context is companied with a
BCSChild instance. |
protected static class |
BeanContextSupport.BCSIterator
This implementation wraps an iterator and override
remove() with a noop method. |
| Modifier and Type | Field and Description |
|---|---|
protected ArrayList |
bcmListeners
A list of registered membership listeners.
|
protected HashMap |
children
A map of children - key is child instance, value is
BCSChild instance. |
protected boolean |
designTime
A flag indicating whether this context is in design mode.
|
protected Locale |
locale
The locale of this context.
|
protected boolean |
okToUseGui
A flag indicating whether this context is allowed to use GUI.
|
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupportglobalHierarchyLockPROPERTYNAME| Constructor and Description |
|---|
BeanContextSupport()
Constructs a standload
BeanContextSupport. |
BeanContextSupport(BeanContext peer)
Constructs a
BeanContextSupport which is a delegate of the given peer. |
BeanContextSupport(BeanContext peer,
Locale locale)
Constructs a
BeanContextSupport which is a delegate of the given peer. |
BeanContextSupport(BeanContext peer,
Locale locale,
boolean designTime)
Constructs a
BeanContextSupport which is a delegate of the given peer. |
BeanContextSupport(BeanContext peer,
Locale locale,
boolean designTime,
boolean okToUseGui)
Constructs a
BeanContextSupport which is a delegate of the given peer. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(Object child)
Add a child to this context.
|
boolean |
addAll(Collection collection)
This method is unsupported, throws
UnsupportedOperationException. |
void |
addBeanContextMembershipListener(BeanContextMembershipListener listener) |
boolean |
avoidingGui() |
protected Iterator |
bcsChildren()
Returns an iterator of all
BCSChild instances, with remove() disabled. |
protected void |
bcsPreDeserializationHook(ObjectInputStream ois)
This method is called by
readObject() after defaultReadObject() and before deserializing any children or listeners. |
protected void |
bcsPreSerializationHook(ObjectOutputStream oos)
This method is called by
writeObject() after defaultWriteObject() and before serializing any children or listeners. |
protected void |
childDeserializedHook(Object child,
BeanContextSupport.BCSChild bcsChild)
This method is called during deserialization everytime a child is read.
|
protected void |
childJustAddedHook(Object child,
BeanContextSupport.BCSChild bcsChild)
This method is called everytime a child is added to this context.
|
protected void |
childJustRemovedHook(Object child,
BeanContextSupport.BCSChild bcsChild)
This method is called everytime a child is removed from this context.
|
protected static boolean |
classEquals(Class clz1,
Class clz2)
Compares if two classes are equal or their class names are equal.
|
void |
clear()
This method is unsupported, throws
UnsupportedOperationException. |
boolean |
contains(Object child)
Returns true if the given object is a child of this context.
|
boolean |
containsAll(Collection collection)
Returns true if given objects are children of this context.
|
boolean |
containsKey(Object child)
Returns true if the given object is a child of this context.
|
protected Object[] |
copyChildren()
Returns an array containing all children of this context.
|
protected BeanContextSupport.BCSChild |
createBCSChild(Object child,
Object proxyPeer)
Creates a
BCSChild object to company the given child. |
protected void |
deserialize(ObjectInputStream ois,
Collection collection)
Deserialize a collection.
|
void |
dontUseGui() |
protected void |
fireChildrenAdded(BeanContextMembershipEvent event)
Notifies registered
BeanContextMembershipListeners that a new child has been added. |
protected void |
fireChildrenRemoved(BeanContextMembershipEvent event)
Notifies registered
BeanContextMembershipListeners that a child has been removed. |
BeanContext |
getBeanContextPeer()
Returns the peer of this context casted as
BeanContext. |
protected static BeanContextChild |
getChildBeanContextChild(Object child)
Returns the
BeanContextChild related with the given child. |
protected static BeanContextMembershipListener |
getChildBeanContextMembershipListener(Object child)
Returns the given child casted to
BeanContextMembershipListener, or null if it does not implements the interface. |
protected static PropertyChangeListener |
getChildPropertyChangeListener(Object child)
Returns the given child casted to
PropertyChangeListener, or null if it does not implements the interface. |
protected static Serializable |
getChildSerializable(Object child)
Returns the given child casted to
Serializable, or null if it does not implements the interface. |
protected static VetoableChangeListener |
getChildVetoableChangeListener(Object child)
Returns the given child casted to
VetoableChangeListener, or null if it does not implements the interface. |
protected static Visibility |
getChildVisibility(Object child)
Returns the given child casted to
Visibility, or null if it does not implements the interface. |
Locale |
getLocale()
Returns the locale of this context.
|
URL |
getResource(String resourceName,
BeanContextChild child) |
InputStream |
getResourceAsStream(String resourceName,
BeanContextChild child) |
protected void |
initialize()
Initializes all transient fields of this instance, called by constructors and
readObject(). |
Object |
instantiateChild(String beanName) |
boolean |
isDesignTime() |
boolean |
isEmpty() |
boolean |
isSerializing()
Returns true if this context is currently being serialized (by another thread).
|
Iterator |
iterator()
Returns an iterator of children of this context, with
remove() disabled. |
boolean |
needsGui()
Returns true if this context or its children needs GUI to work properly.
|
void |
okToUseGui() |
void |
propertyChange(PropertyChangeEvent event) |
void |
readChildren(ObjectInputStream ois)
Deserializes children from the given object input stream.
|
boolean |
remove(Object child)
Removes the given child from this context.
|
protected boolean |
remove(Object child,
boolean setChildBC)
Removes the given child from this context.
|
boolean |
removeAll(Collection collection)
This method is unsupported, throws
UnsupportedOperationException. |
void |
removeBeanContextMembershipListener(BeanContextMembershipListener listener) |
boolean |
retainAll(Collection collection)
This method is unsupported, throws
UnsupportedOperationException. |
protected void |
serialize(ObjectOutputStream oos,
Collection collection)
Serializes the given collection.
|
void |
setDesignTime(boolean designTime) |
void |
setLocale(Locale newLocale)
Sets the locale of this context.
|
int |
size()
Returns the number children of this context.
|
Object[] |
toArray()
Returns an array of children of this context.
|
Object[] |
toArray(Object[] array)
Returns an array of children of this context.
|
protected boolean |
validatePendingAdd(Object child)
Validates the pending add of child.
|
protected boolean |
validatePendingRemove(Object child)
Validates the pending removal of child.
|
void |
vetoableChange(PropertyChangeEvent pce) |
void |
writeChildren(ObjectOutputStream oos)
Serializes children to the given object input stream.
|
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContextclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContextequals, hashCodeprotected transient ArrayList bcmListeners
protected transient HashMap children
BCSChild instance. All access to this object should be synchronized on itself.protected Locale locale
protected boolean okToUseGui
protected boolean designTime
public BeanContextSupport()
BeanContextSupport.public BeanContextSupport(BeanContext peer)
BeanContextSupport which is a delegate of the given peer.peer - the peer of this contextpublic BeanContextSupport(BeanContext peer, Locale locale)
BeanContextSupport which is a delegate of the given peer.peer - the peer of this contextlocale - the locale of this contextpublic BeanContextSupport(BeanContext peer, Locale locale, boolean designTime)
BeanContextSupport which is a delegate of the given peer.peer - the peer of this contextlocale - the locale of this contextdesignTime - whether in design mode or notpublic BeanContextSupport(BeanContext peer, Locale locale, boolean designTime, boolean okToUseGui)
BeanContextSupport which is a delegate of the given peer.peer - the peer of this contextlocale - the locale of this contextdesignTime - whether in design mode or notokToUseGui - whether GUI is usable or notpublic boolean add(Object child)
If the child already exists in this context, simply returns false. Otherwise, it is validated by calling validatePendingAdd(). If the add is
valid, the child and its proxy (if the child implements BeanContextProxy) is then added, and setBeanContext() is called on it
(if the child implements BeanContextChild or it has a proxy). Last, the childJustAddedHook() is called and all registered
BeanContextMembershipListeners are notified.
add in interface Collectionchild - the child to addIllegalStateException - if the child is not valid to addCollection.add(java.lang.Object)public boolean addAll(Collection collection)
UnsupportedOperationException.addAll in interface CollectionCollection.addAll(java.util.Collection)public void addBeanContextMembershipListener(BeanContextMembershipListener listener)
addBeanContextMembershipListener in interface BeanContextpublic boolean avoidingGui()
avoidingGui in interface Visibilityprotected Iterator bcsChildren()
BCSChild instances, with remove() disabled.BCSChild instancesprotected void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException
readObject() after defaultReadObject() and before deserializing any children or listeners. Subclass
can insert its specific deserialization behavior by overrideing this method.
The default implementation does nothing.
ois - the object input streamIOExceptionClassNotFoundExceptionprotected void bcsPreSerializationHook(ObjectOutputStream oos) throws IOException
writeObject() after defaultWriteObject() and before serializing any children or listeners. Subclass
can insert its specific serialization behavior by overrideing this method.
The default implementation does nothing.
oos - the object output streamIOExceptionprotected void childDeserializedHook(Object child, BeanContextSupport.BCSChild bcsChild)
The default implementation does nothing.
child - the child just deserializedbcsChild - the BCSChild just deserializedprotected void childJustAddedHook(Object child, BeanContextSupport.BCSChild bcsChild)
The default implementation does nothing.
child - the child just addedbcsChild - the BCSChild just addedprotected void childJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsChild)
The default implementation does nothing.
child - the child just removedbcsChild - the BCSChild just removedprotected static final boolean classEquals(Class clz1, Class clz2)
clz1 - a classclz2 - another classpublic void clear()
UnsupportedOperationException.clear in interface CollectionCollection.clear()public boolean contains(Object child)
contains in interface Collectionchild - the object to testCollection.contains(java.lang.Object)public boolean containsAll(Collection collection)
containsAll in interface Collectioncollection - a collection of objectsCollection.containsAll(java.util.Collection)public boolean containsKey(Object child)
child - the object to testprotected final Object[] copyChildren()
protected BeanContextSupport.BCSChild createBCSChild(Object child, Object proxyPeer)
BCSChild object to company the given child.child - the childproxyPeer - the proxy peer of the child if there is oneBCSChild object to company the given childprotected final void deserialize(ObjectInputStream ois, Collection collection) throws IOException, ClassNotFoundException
First read a int indicating of number of rest objects, then read the objects one by one.
ois - the stream where the collection is read fromcollection - the collection to hold read objectsIOException - if I/O exception occursClassNotFoundException - if class of any read object is not foundpublic void dontUseGui()
dontUseGui in interface Visibilityprotected final void fireChildrenAdded(BeanContextMembershipEvent event)
BeanContextMembershipListeners that a new child has been added.event - the BeanContextMembershipEventprotected final void fireChildrenRemoved(BeanContextMembershipEvent event)
BeanContextMembershipListeners that a child has been removed.event - the BeanContextMembershipEventpublic BeanContext getBeanContextPeer()
BeanContext.BeanContextprotected static final BeanContextChild getChildBeanContextChild(Object child)
BeanContextChild related with the given child.
If the child implements BeanContextChild, it is returned. If the child implements BeanContextProxy, the proxy is returned.
Otherwise, null is returned.
child - a childBeanContextChild related with the given childIllegalStateException - if the child implements both BeanContextChild and BeanContextProxyprotected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object child)
BeanContextMembershipListener, or null if it does not implements the interface.child - a childBeanContextMembershipListener, or null if it does not implements the interfaceprotected static final PropertyChangeListener getChildPropertyChangeListener(Object child)
PropertyChangeListener, or null if it does not implements the interface.child - a childPropertyChangeListener, or null if it does not implements the interfaceprotected static final Serializable getChildSerializable(Object child)
Serializable, or null if it does not implements the interface.child - a childSerializable, or null if it does not implements the interfaceprotected static final VetoableChangeListener getChildVetoableChangeListener(Object child)
VetoableChangeListener, or null if it does not implements the interface.child - a childVetoableChangeListener, or null if it does not implements the interfaceprotected static final Visibility getChildVisibility(Object child)
Visibility, or null if it does not implements the interface.child - a childVisibility, or null if it does not implements the interfacepublic Locale getLocale()
public URL getResource(String resourceName, BeanContextChild child)
getResource in interface BeanContextpublic InputStream getResourceAsStream(String resourceName, BeanContextChild child) throws IllegalArgumentException
getResourceAsStream in interface BeanContextIllegalArgumentExceptionprotected void initialize()
readObject().public Object instantiateChild(String beanName) throws IOException, ClassNotFoundException
instantiateChild in interface BeanContextIOExceptionClassNotFoundExceptionpublic boolean isDesignTime()
isDesignTime in interface DesignModepublic boolean isEmpty()
isEmpty in interface Collectionpublic boolean isSerializing()
public Iterator iterator()
remove() disabled.iterator in interface Iterableiterator in interface CollectionCollection.iterator()public boolean needsGui()
The implementation checks the peer and all the children that implement Visibility to see if any of their needsGui() returns
true, and if any of the children extends java.awt.Component.
needsGui in interface VisibilityVisibility.needsGui()public void okToUseGui()
okToUseGui in interface Visibilitypublic void propertyChange(PropertyChangeEvent event)
propertyChange in interface PropertyChangeListenerpublic final void readChildren(ObjectInputStream ois) throws IOException, ClassNotFoundException
The implementation reads pairs of child object and BCSChild object according to serializable property. For each pair, it is
added to the children map and the childDeserializedHook() is called. If the child implements BeanContextChild, its
setBeanContext() is also called.
This method is called by readObject() if the context works standalone. Or if this support object is a delegate of another
BeanContext implementation, then this method should be called by the peer. Doing this means that derialization can proceed without any
circular dependency problems.
ois - the object input streamIOException - if I/O exception occursClassNotFoundException - if class of read object is not foundpublic boolean remove(Object child)
Delegates to remove(child, true).
remove in interface Collectionchild - a child of this contextIllegalArgumentException - if the child is nullIllegalStateException - if the child is not valid to removeCollection.remove(java.lang.Object)protected boolean remove(Object child, boolean setChildBC)
If the given child is not a child of this context, simply returns false. Otherwise, validatePendingRemove() is called. If the removal is
valid, the child's beanContext property is updated (if required) and the child and its proxy peer (if there is one) is removed. Last,
childJustRemovedHook() is called and listeners are notified.
child - a child of this contextsetChildBC - whether to call setBeanContext() on the child or notIllegalArgumentException - if the child is nullIllegalStateException - if the child is not valid to removepublic boolean removeAll(Collection collection)
UnsupportedOperationException.removeAll in interface CollectionCollection.removeAll(java.util.Collection)public void removeBeanContextMembershipListener(BeanContextMembershipListener listener)
removeBeanContextMembershipListener in interface BeanContextpublic boolean retainAll(Collection collection)
UnsupportedOperationException.retainAll in interface CollectionCollection.retainAll(java.util.Collection)protected final void serialize(ObjectOutputStream oos, Collection collection) throws IOException
First writes a int indicating the number of all serializable elements (implements Serializable, then objects are writtern one
by one.
oos - the stream where the collection is writtern tocollection - the collection to serializeIOException - if I/O exception occurspublic void setDesignTime(boolean designTime)
setDesignTime in interface DesignModepublic void setLocale(Locale newLocale) throws PropertyVetoException
VetoableChangeListeners and PropertyChangeListeners are notified.newLocale - the new locale to setPropertyVetoException - if any VetoableChangeListener vetos this changepublic int size()
size in interface CollectionCollection.size()public Object[] toArray()
toArray in interface CollectionCollection.toArray()public Object[] toArray(Object[] array)
toArray in interface CollectionCollection.toArray(java.lang.Object[])protected boolean validatePendingAdd(Object child)
Default implementation always returns true.
child - the child to be addedprotected boolean validatePendingRemove(Object child)
Default implementation always returns true.
child - the child to be removedpublic void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException
vetoableChange in interface VetoableChangeListenerPropertyVetoExceptionpublic final void writeChildren(ObjectOutputStream oos) throws IOException
The implementation iterates through all children and writes out pairs of child object and BCSChild object if the child is serializable
(implements Serialization.
This method is called by writeObject() if the context works standalone. Or if this support object is a delegate of another
BeanContext implementation, then this method should be called by the peer to avoid the 'chicken and egg' problem during deserialization.
oos - the stream to writeIOException - if I/O exception occursCopyright © 2014. All Rights Reserved.