public class BeanContextSupport extends BeanContextChildSupport implements BeanContext, PropertyChangeListener, VetoableChangeListener, java.io.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 java.util.ArrayList |
bcmListeners
A list of registered membership listeners.
|
protected java.util.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 java.util.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, vcSupport
globalHierarchyLock
PROPERTYNAME
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,
java.util.Locale locale)
Constructs a
BeanContextSupport which is a delegate
of the given peer. |
BeanContextSupport(BeanContext peer,
java.util.Locale locale,
boolean designTime)
Constructs a
BeanContextSupport which is a delegate
of the given peer. |
BeanContextSupport(BeanContext peer,
java.util.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(java.lang.Object child)
Add a child to this context.
|
boolean |
addAll(java.util.Collection collection)
This method is unsupported, throws
UnsupportedOperationException . |
void |
addBeanContextMembershipListener(BeanContextMembershipListener listener) |
boolean |
avoidingGui() |
protected java.util.Iterator |
bcsChildren()
Returns an iterator of all
BCSChild instances,
with remove() disabled. |
protected void |
bcsPreDeserializationHook(java.io.ObjectInputStream ois)
This method is called by
readObject() after
defaultReadObject() and before deserializing any
children or listeners. |
protected void |
bcsPreSerializationHook(java.io.ObjectOutputStream oos)
This method is called by
writeObject() after
defaultWriteObject() and before serializing any
children or listeners. |
protected void |
childDeserializedHook(java.lang.Object child,
BeanContextSupport.BCSChild bcsChild)
This method is called during deserialization everytime a child is read.
|
protected void |
childJustAddedHook(java.lang.Object child,
BeanContextSupport.BCSChild bcsChild)
This method is called everytime a child is added to this context.
|
protected void |
childJustRemovedHook(java.lang.Object child,
BeanContextSupport.BCSChild bcsChild)
This method is called everytime a child is removed from this context.
|
protected static boolean |
classEquals(java.lang.Class clz1,
java.lang.Class clz2)
Compares if two classes are equal or their class names are equal.
|
void |
clear()
This method is unsupported, throws
UnsupportedOperationException . |
boolean |
contains(java.lang.Object child)
Returns true if the given object is a child of this context.
|
boolean |
containsAll(java.util.Collection collection)
Returns true if given objects are children of this context.
|
boolean |
containsKey(java.lang.Object child)
Returns true if the given object is a child of this context.
|
protected java.lang.Object[] |
copyChildren()
Returns an array containing all children of this context.
|
protected BeanContextSupport.BCSChild |
createBCSChild(java.lang.Object child,
java.lang.Object proxyPeer)
Creates a
BCSChild object to company the given child. |
protected void |
deserialize(java.io.ObjectInputStream ois,
java.util.Collection collection)
Deserialize a collection.
|
void |
dontUseGui() |
protected void |
fireChildrenAdded(BeanContextMembershipEvent event)
Notifies registered
BeanContextMembershipListener s that
a new child has been added. |
protected void |
fireChildrenRemoved(BeanContextMembershipEvent event)
Notifies registered
BeanContextMembershipListener s that
a child has been removed. |
BeanContext |
getBeanContextPeer()
Returns the peer of this context casted as
BeanContext . |
protected static BeanContextChild |
getChildBeanContextChild(java.lang.Object child)
Returns the
BeanContextChild related with the given child. |
protected static BeanContextMembershipListener |
getChildBeanContextMembershipListener(java.lang.Object child)
Returns the given child casted to
BeanContextMembershipListener ,
or null if it does not implements the interface. |
protected static PropertyChangeListener |
getChildPropertyChangeListener(java.lang.Object child)
Returns the given child casted to
PropertyChangeListener ,
or null if it does not implements the interface. |
protected static java.io.Serializable |
getChildSerializable(java.lang.Object child)
Returns the given child casted to
Serializable ,
or null if it does not implements the interface. |
protected static VetoableChangeListener |
getChildVetoableChangeListener(java.lang.Object child)
Returns the given child casted to
VetoableChangeListener ,
or null if it does not implements the interface. |
protected static Visibility |
getChildVisibility(java.lang.Object child)
Returns the given child casted to
Visibility ,
or null if it does not implements the interface. |
java.util.Locale |
getLocale()
Returns the locale of this context.
|
java.net.URL |
getResource(java.lang.String resourceName,
BeanContextChild child) |
java.io.InputStream |
getResourceAsStream(java.lang.String resourceName,
BeanContextChild child) |
protected void |
initialize()
Initializes all transient fields of this instance, called by
constructors and
readObject() . |
java.lang.Object |
instantiateChild(java.lang.String beanName) |
boolean |
isDesignTime() |
boolean |
isEmpty() |
boolean |
isSerializing()
Returns true if this context is currently being serialized
(by another thread).
|
java.util.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(java.io.ObjectInputStream ois)
Deserializes children from the given object input stream.
|
boolean |
remove(java.lang.Object child)
Removes the given child from this context.
|
protected boolean |
remove(java.lang.Object child,
boolean setChildBC)
Removes the given child from this context.
|
boolean |
removeAll(java.util.Collection collection)
This method is unsupported, throws
UnsupportedOperationException . |
void |
removeBeanContextMembershipListener(BeanContextMembershipListener listener) |
boolean |
retainAll(java.util.Collection collection)
This method is unsupported, throws
UnsupportedOperationException . |
protected void |
serialize(java.io.ObjectOutputStream oos,
java.util.Collection collection)
Serializes the given collection.
|
void |
setDesignTime(boolean designTime) |
void |
setLocale(java.util.Locale newLocale)
Sets the locale of this context.
|
int |
size()
Returns the number children of this context.
|
java.lang.Object[] |
toArray()
Returns an array of children of this context.
|
java.lang.Object[] |
toArray(java.lang.Object[] array)
Returns an array of children of this context.
|
protected boolean |
validatePendingAdd(java.lang.Object child)
Validates the pending add of child.
|
protected boolean |
validatePendingRemove(java.lang.Object child)
Validates the pending removal of child.
|
void |
vetoableChange(PropertyChangeEvent pce) |
void |
writeChildren(java.io.ObjectOutputStream oos)
Serializes children to the given object input stream.
|
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext
protected transient java.util.ArrayList bcmListeners
protected transient java.util.HashMap children
BCSChild
instance.
All access to this object should be synchronized on itself.protected java.util.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, java.util.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, java.util.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, java.util.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(java.lang.Object child)
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 BeanContextMembershipListener
s
are notified.
add
in interface java.util.Collection
child
- the child to addjava.lang.IllegalStateException
- if the child is not valid to addCollection.add(java.lang.Object)
public boolean addAll(java.util.Collection collection)
UnsupportedOperationException
.addAll
in interface java.util.Collection
Collection.addAll(java.util.Collection)
public void addBeanContextMembershipListener(BeanContextMembershipListener listener)
addBeanContextMembershipListener
in interface BeanContext
public boolean avoidingGui()
avoidingGui
in interface Visibility
protected java.util.Iterator bcsChildren()
BCSChild
instances,
with remove()
disabled.BCSChild
instancesprotected void bcsPreDeserializationHook(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
readObject()
after
defaultReadObject()
and before deserializing any
children or listeners. Subclass can insert its specific
deserialization behavior by overrideing this method.
ois
- the object input streamjava.io.IOException
java.lang.ClassNotFoundException
protected void bcsPreSerializationHook(java.io.ObjectOutputStream oos) throws java.io.IOException
writeObject()
after
defaultWriteObject()
and before serializing any
children or listeners. Subclass can insert its specific
serialization behavior by overrideing this method.
oos
- the object output streamjava.io.IOException
protected void childDeserializedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)
child
- the child just deserializedbcsChild
- the BCSChild
just deserializedprotected void childJustAddedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)
child
- the child just addedbcsChild
- the BCSChild
just addedprotected void childJustRemovedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)
child
- the child just removedbcsChild
- the BCSChild
just removedprotected static final boolean classEquals(java.lang.Class clz1, java.lang.Class clz2)
clz1
- a classclz2
- another classpublic void clear()
UnsupportedOperationException
.clear
in interface java.util.Collection
Collection.clear()
public boolean contains(java.lang.Object child)
contains
in interface java.util.Collection
child
- the object to testCollection.contains(java.lang.Object)
public boolean containsAll(java.util.Collection collection)
containsAll
in interface java.util.Collection
collection
- a collection of objectsCollection.containsAll(java.util.Collection)
public boolean containsKey(java.lang.Object child)
child
- the object to testprotected final java.lang.Object[] copyChildren()
protected BeanContextSupport.BCSChild createBCSChild(java.lang.Object child, java.lang.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(java.io.ObjectInputStream ois, java.util.Collection collection) throws java.io.IOException, java.lang.ClassNotFoundException
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 objectsjava.io.IOException
- if I/O exception occursjava.lang.ClassNotFoundException
- if class of any read object is not foundpublic void dontUseGui()
dontUseGui
in interface Visibility
protected final void fireChildrenAdded(BeanContextMembershipEvent event)
BeanContextMembershipListener
s that
a new child has been added.event
- the BeanContextMembershipEvent
protected final void fireChildrenRemoved(BeanContextMembershipEvent event)
BeanContextMembershipListener
s that
a child has been removed.event
- the BeanContextMembershipEvent
public BeanContext getBeanContextPeer()
BeanContext
.BeanContext
protected static final BeanContextChild getChildBeanContextChild(java.lang.Object child)
BeanContextChild
related with the given child.
BeanContextChild, it is returned.
If the child implements BeanContextProxy
, the proxy is returned.
Otherwise, null is returned.
child
- a childBeanContextChild
related with the given childjava.lang.IllegalStateException
- if the child implements both BeanContextChild
and BeanContextProxy
protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(java.lang.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(java.lang.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 java.io.Serializable getChildSerializable(java.lang.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(java.lang.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(java.lang.Object child)
Visibility
,
or null if it does not implements the interface.child
- a childVisibility
,
or null if it does not implements the interfacepublic java.util.Locale getLocale()
public java.net.URL getResource(java.lang.String resourceName, BeanContextChild child)
getResource
in interface BeanContext
public java.io.InputStream getResourceAsStream(java.lang.String resourceName, BeanContextChild child) throws java.lang.IllegalArgumentException
getResourceAsStream
in interface BeanContext
java.lang.IllegalArgumentException
protected void initialize()
readObject()
.public java.lang.Object instantiateChild(java.lang.String beanName) throws java.io.IOException, java.lang.ClassNotFoundException
instantiateChild
in interface BeanContext
java.io.IOException
java.lang.ClassNotFoundException
public boolean isDesignTime()
isDesignTime
in interface DesignMode
public boolean isEmpty()
isEmpty
in interface java.util.Collection
public boolean isSerializing()
public java.util.Iterator iterator()
remove()
disabled.iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
Collection.iterator()
public boolean needsGui()
Visibility to see if any of their needsGui()
returns true, and if any of the children extends
java.awt.Component
.
needsGui
in interface Visibility
Visibility.needsGui()
public void okToUseGui()
okToUseGui
in interface Visibility
public void propertyChange(PropertyChangeEvent event)
propertyChange
in interface PropertyChangeListener
public final void readChildren(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
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.
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 streamjava.io.IOException
- if I/O exception occursjava.lang.ClassNotFoundException
- if class of read object is not foundpublic boolean remove(java.lang.Object child)
remove(child, true).
remove
in interface java.util.Collection
child
- a child of this contextjava.lang.IllegalArgumentException
- if the child is nulljava.lang.IllegalStateException
- if the child is not valid to removeCollection.remove(java.lang.Object)
protected boolean remove(java.lang.Object child, boolean setChildBC)
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 notjava.lang.IllegalArgumentException
- if the child is nulljava.lang.IllegalStateException
- if the child is not valid to removepublic boolean removeAll(java.util.Collection collection)
UnsupportedOperationException
.removeAll
in interface java.util.Collection
Collection.removeAll(java.util.Collection)
public void removeBeanContextMembershipListener(BeanContextMembershipListener listener)
removeBeanContextMembershipListener
in interface BeanContext
public boolean retainAll(java.util.Collection collection)
UnsupportedOperationException
.retainAll
in interface java.util.Collection
Collection.retainAll(java.util.Collection)
protected final void serialize(java.io.ObjectOutputStream oos, java.util.Collection collection) throws java.io.IOException
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 serializejava.io.IOException
- if I/O exception occurspublic void setDesignTime(boolean designTime)
setDesignTime
in interface DesignMode
public void setLocale(java.util.Locale newLocale) throws PropertyVetoException
VetoableChangeListener
s
and PropertyChangeListener
s are notified.newLocale
- the new locale to setPropertyVetoException
- if any VetoableChangeListener
vetos this changepublic int size()
size
in interface java.util.Collection
Collection.size()
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
Collection.toArray()
public java.lang.Object[] toArray(java.lang.Object[] array)
toArray
in interface java.util.Collection
Collection.toArray(java.lang.Object[])
protected boolean validatePendingAdd(java.lang.Object child)
child
- the child to be addedprotected boolean validatePendingRemove(java.lang.Object child)
child
- the child to be removedpublic void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException
vetoableChange
in interface VetoableChangeListener
PropertyVetoException
public final void writeChildren(java.io.ObjectOutputStream oos) throws java.io.IOException
BCSChild object if the child is
serializable (implements Serialization
.
BeanContext
implementation, then this method should be
called by the peer to avoid the 'chicken and egg' problem during
deserialization.
oos
- the stream to writejava.io.IOException
- if I/O exception occurs