Class BeanContextSupport
- All Implemented Interfaces:
Serializable,Iterable,Collection,EventListener,BeanContext,BeanContextChild,BeanContextServiceRevokedListener,BeanContextServicesListener,DesignMode,PropertyChangeListener,VetoableChangeListener,Visibility
- Direct Known Subclasses:
BeanContextServicesSupport
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.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classEvery child of context is companied with aBCSChildinstance.protected static final classThis implementation wraps an iterator and overrideremove()with a noop method. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ArrayListA list of registered membership listeners.protected HashMapA map of children - key is child instance, value isBCSChildinstance.protected booleanA flag indicating whether this context is in design mode.protected LocaleThe locale of this context.protected booleanA flag indicating whether this context is allowed to use GUI.Fields inherited from class javaa.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupportFields inherited from interface javaa.beans.beancontext.BeanContext
globalHierarchyLockFields inherited from interface javaa.beans.DesignMode
PROPERTYNAME -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a standloadBeanContextSupport.Constructs aBeanContextSupportwhich is a delegate of the given peer.BeanContextSupport(BeanContext peer, Locale locale) Constructs aBeanContextSupportwhich is a delegate of the given peer.BeanContextSupport(BeanContext peer, Locale locale, boolean designTime) Constructs aBeanContextSupportwhich is a delegate of the given peer.BeanContextSupport(BeanContext peer, Locale locale, boolean designTime, boolean okToUseGui) Constructs aBeanContextSupportwhich is a delegate of the given peer. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a child to this context.booleanaddAll(Collection collection) This method is unsupported, throwsUnsupportedOperationException.voidbooleanprotected IteratorReturns an iterator of allBCSChildinstances, withremove()disabled.protected voidThis method is called byreadObject()afterdefaultReadObject()and before deserializing any children or listeners.protected voidThis method is called bywriteObject()afterdefaultWriteObject()and before serializing any children or listeners.protected voidchildDeserializedHook(Object child, BeanContextSupport.BCSChild bcsChild) This method is called during deserialization everytime a child is read.protected voidchildJustAddedHook(Object child, BeanContextSupport.BCSChild bcsChild) This method is called everytime a child is added to this context.protected voidchildJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsChild) This method is called everytime a child is removed from this context.protected static final booleanclassEquals(Class clz1, Class clz2) Compares if two classes are equal or their class names are equal.voidclear()This method is unsupported, throwsUnsupportedOperationException.booleanReturns true if the given object is a child of this context.booleancontainsAll(Collection collection) Returns true if given objects are children of this context.booleancontainsKey(Object child) Returns true if the given object is a child of this context.protected final Object[]Returns an array containing all children of this context.protected BeanContextSupport.BCSChildcreateBCSChild(Object child, Object proxyPeer) Creates aBCSChildobject to company the given child.protected final voiddeserialize(ObjectInputStream ois, Collection collection) Deserialize a collection.voidprotected final voidNotifies registeredBeanContextMembershipListeners that a new child has been added.protected final voidNotifies registeredBeanContextMembershipListeners that a child has been removed.Returns the peer of this context casted asBeanContext.protected static final BeanContextChildgetChildBeanContextChild(Object child) Returns theBeanContextChildrelated with the given child.protected static final BeanContextMembershipListenerReturns the given child casted toBeanContextMembershipListener, or null if it does not implements the interface.protected static final PropertyChangeListenerReturns the given child casted toPropertyChangeListener, or null if it does not implements the interface.protected static final SerializablegetChildSerializable(Object child) Returns the given child casted toSerializable, or null if it does not implements the interface.protected static final VetoableChangeListenerReturns the given child casted toVetoableChangeListener, or null if it does not implements the interface.protected static final VisibilitygetChildVisibility(Object child) Returns the given child casted toVisibility, or null if it does not implements the interface.Returns the locale of this context.getResource(String resourceName, BeanContextChild child) getResourceAsStream(String resourceName, BeanContextChild child) protected voidInitializes all transient fields of this instance, called by constructors andreadObject().instantiateChild(String beanName) booleanbooleanisEmpty()booleanReturns true if this context is currently being serialized (by another thread).iterator()Returns an iterator of children of this context, withremove()disabled.booleanneedsGui()Returns true if this context or its children needs GUI to work properly.voidvoidfinal voidDeserializes children from the given object input stream.booleanRemoves the given child from this context.protected booleanRemoves the given child from this context.booleanremoveAll(Collection collection) This method is unsupported, throwsUnsupportedOperationException.voidbooleanretainAll(Collection collection) This method is unsupported, throwsUnsupportedOperationException.protected final voidserialize(ObjectOutputStream oos, Collection collection) Serializes the given collection.voidsetDesignTime(boolean designTime) voidSets the locale of this context.intsize()Returns the number children of this context.Object[]toArray()Returns an array of children of this context.Object[]Returns an array of children of this context.protected booleanvalidatePendingAdd(Object child) Validates the pending add of child.protected booleanvalidatePendingRemove(Object child) Validates the pending removal of child.voidfinal voidSerializes children to the given object input stream.Methods inherited from class javaa.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javaa.beans.beancontext.BeanContextChild
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContextMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
bcmListeners
A list of registered membership listeners. All access to this object should be synchronized on itself. -
children
A map of children - key is child instance, value isBCSChildinstance. All access to this object should be synchronized on itself. -
locale
The locale of this context. -
okToUseGui
protected boolean okToUseGuiA flag indicating whether this context is allowed to use GUI. -
designTime
protected boolean designTimeA flag indicating whether this context is in design mode.
-
-
Constructor Details
-
BeanContextSupport
public BeanContextSupport()Constructs a standloadBeanContextSupport. -
BeanContextSupport
Constructs aBeanContextSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this context
-
BeanContextSupport
Constructs aBeanContextSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this contextlocale- the locale of this context
-
BeanContextSupport
Constructs aBeanContextSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this contextlocale- the locale of this contextdesignTime- whether in design mode or not
-
BeanContextSupport
Constructs aBeanContextSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this contextlocale- the locale of this contextdesignTime- whether in design mode or notokToUseGui- whether GUI is usable or not
-
-
Method Details
-
add
Add a child to this context.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 implementsBeanContextProxy) is then added, andsetBeanContext()is called on it (if the child implementsBeanContextChildor it has a proxy). Last, thechildJustAddedHook()is called and all registeredBeanContextMembershipListeners are notified.- Specified by:
addin interfaceCollection- Parameters:
child- the child to add- Returns:
- true if the child is added to this context; otherwise false
- Throws:
IllegalStateException- if the child is not valid to add- See Also:
-
addAll
This method is unsupported, throwsUnsupportedOperationException.- Specified by:
addAllin interfaceCollection- See Also:
-
addBeanContextMembershipListener
- Specified by:
addBeanContextMembershipListenerin interfaceBeanContext
-
avoidingGui
public boolean avoidingGui()- Specified by:
avoidingGuiin interfaceVisibility
-
bcsChildren
Returns an iterator of allBCSChildinstances, withremove()disabled.- Returns:
- an iterator of all
BCSChildinstances
-
bcsPreDeserializationHook
protected void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException This method is called byreadObject()afterdefaultReadObject()and before deserializing any children or listeners. Subclass can insert its specific deserialization behavior by overrideing this method.The default implementation does nothing.
- Parameters:
ois- the object input stream- Throws:
IOExceptionClassNotFoundException
-
bcsPreSerializationHook
This method is called bywriteObject()afterdefaultWriteObject()and before serializing any children or listeners. Subclass can insert its specific serialization behavior by overrideing this method.The default implementation does nothing.
- Parameters:
oos- the object output stream- Throws:
IOException
-
childDeserializedHook
This method is called during deserialization everytime a child is read.The default implementation does nothing.
- Parameters:
child- the child just deserializedbcsChild- theBCSChildjust deserialized
-
childJustAddedHook
This method is called everytime a child is added to this context. This method is called with child synchronized.The default implementation does nothing.
- Parameters:
child- the child just addedbcsChild- theBCSChildjust added
-
childJustRemovedHook
This method is called everytime a child is removed from this context. This method is called with child synchronized.The default implementation does nothing.
- Parameters:
child- the child just removedbcsChild- theBCSChildjust removed
-
classEquals
Compares if two classes are equal or their class names are equal.- Parameters:
clz1- a classclz2- another class- Returns:
- true if two class objects are equal or their class names are equal.
-
clear
public void clear()This method is unsupported, throwsUnsupportedOperationException.- Specified by:
clearin interfaceCollection- See Also:
-
contains
Returns true if the given object is a child of this context.- Specified by:
containsin interfaceCollection- Parameters:
child- the object to test- Returns:
- true if the given object is a child of this context
- See Also:
-
containsAll
Returns true if given objects are children of this context.- Specified by:
containsAllin interfaceCollection- Parameters:
collection- a collection of objects- Returns:
- true if given objects are children of this context
- See Also:
-
containsKey
Returns true if the given object is a child of this context.- Parameters:
child- the object to test- Returns:
- true if the given object is a child of this context
-
copyChildren
Returns an array containing all children of this context.- Returns:
- an array containing all children of this context
-
createBCSChild
Creates aBCSChildobject to company the given child.- Parameters:
child- the childproxyPeer- the proxy peer of the child if there is one- Returns:
- a
BCSChildobject to company the given child
-
deserialize
protected final void deserialize(ObjectInputStream ois, Collection collection) throws IOException, ClassNotFoundException Deserialize a collection.First read a
intindicating of number of rest objects, then read the objects one by one.- Parameters:
ois- the stream where the collection is read fromcollection- the collection to hold read objects- Throws:
IOException- if I/O exception occursClassNotFoundException- if class of any read object is not found
-
dontUseGui
public void dontUseGui()- Specified by:
dontUseGuiin interfaceVisibility
-
fireChildrenAdded
Notifies registeredBeanContextMembershipListeners that a new child has been added.- Parameters:
event- theBeanContextMembershipEvent
-
fireChildrenRemoved
Notifies registeredBeanContextMembershipListeners that a child has been removed.- Parameters:
event- theBeanContextMembershipEvent
-
getBeanContextPeer
Returns the peer of this context casted asBeanContext.- Returns:
- the peer of this context casted as
BeanContext
-
getChildBeanContextChild
Returns theBeanContextChildrelated with the given child.If the child implements
BeanContextChild, it is returned. If the child implementsBeanContextProxy, the proxy is returned. Otherwise, null is returned.- Parameters:
child- a child- Returns:
- the
BeanContextChildrelated with the given child - Throws:
IllegalStateException- if the child implements bothBeanContextChildandBeanContextProxy
-
getChildBeanContextMembershipListener
protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object child) Returns the given child casted toBeanContextMembershipListener, or null if it does not implements the interface.- Parameters:
child- a child- Returns:
- the given child casted to
BeanContextMembershipListener, or null if it does not implements the interface
-
getChildPropertyChangeListener
Returns the given child casted toPropertyChangeListener, or null if it does not implements the interface.- Parameters:
child- a child- Returns:
- the given child casted to
PropertyChangeListener, or null if it does not implements the interface
-
getChildSerializable
Returns the given child casted toSerializable, or null if it does not implements the interface.- Parameters:
child- a child- Returns:
- the given child casted to
Serializable, or null if it does not implements the interface
-
getChildVetoableChangeListener
Returns the given child casted toVetoableChangeListener, or null if it does not implements the interface.- Parameters:
child- a child- Returns:
- the given child casted to
VetoableChangeListener, or null if it does not implements the interface
-
getChildVisibility
Returns the given child casted toVisibility, or null if it does not implements the interface.- Parameters:
child- a child- Returns:
- the given child casted to
Visibility, or null if it does not implements the interface
-
getLocale
Returns the locale of this context.- Returns:
- the locale of this context
-
getResource
- Specified by:
getResourcein interfaceBeanContext
-
getResourceAsStream
public InputStream getResourceAsStream(String resourceName, BeanContextChild child) throws IllegalArgumentException - Specified by:
getResourceAsStreamin interfaceBeanContext- Throws:
IllegalArgumentException
-
initialize
protected void initialize()Initializes all transient fields of this instance, called by constructors andreadObject(). -
instantiateChild
- Specified by:
instantiateChildin interfaceBeanContext- Throws:
IOExceptionClassNotFoundException
-
isDesignTime
public boolean isDesignTime()- Specified by:
isDesignTimein interfaceDesignMode
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection
-
isSerializing
public boolean isSerializing()Returns true if this context is currently being serialized (by another thread).- Returns:
- true if this context is currently being serialized (by another thread)
-
iterator
Returns an iterator of children of this context, withremove()disabled.- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- See Also:
-
needsGui
public boolean needsGui()Returns true if this context or its children needs GUI to work properly.The implementation checks the peer and all the children that implement
Visibilityto see if any of theirneedsGui()returns true, and if any of the children extendsjava.awt.Component.- Specified by:
needsGuiin interfaceVisibility- See Also:
-
okToUseGui
public void okToUseGui()- Specified by:
okToUseGuiin interfaceVisibility
-
propertyChange
- Specified by:
propertyChangein interfacePropertyChangeListener
-
readChildren
Deserializes children from the given object input stream.The implementation reads pairs of child object and
BCSChildobject according toserializableproperty. For each pair, it is added to thechildrenmap and thechildDeserializedHook()is called. If the child implementsBeanContextChild, itssetBeanContext()is also called.This method is called by
readObject()if the context works standalone. Or if this support object is a delegate of anotherBeanContextimplementation, then this method should be called by the peer. Doing this means that derialization can proceed without any circular dependency problems.- Parameters:
ois- the object input stream- Throws:
IOException- if I/O exception occursClassNotFoundException- if class of read object is not found
-
remove
Removes the given child from this context.Delegates to
remove(child, true).- Specified by:
removein interfaceCollection- Parameters:
child- a child of this context- Returns:
- true if the child is removed; or false if it is not a child of this context
- Throws:
IllegalArgumentException- if the child is nullIllegalStateException- if the child is not valid to remove- See Also:
-
remove
Removes the given child from this context.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'sbeanContextproperty 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.- Parameters:
child- a child of this contextsetChildBC- whether to callsetBeanContext()on the child or not- Returns:
- true if the child is removed; or false if it is not a child of this context
- Throws:
IllegalArgumentException- if the child is nullIllegalStateException- if the child is not valid to remove
-
removeAll
This method is unsupported, throwsUnsupportedOperationException.- Specified by:
removeAllin interfaceCollection- See Also:
-
removeBeanContextMembershipListener
- Specified by:
removeBeanContextMembershipListenerin interfaceBeanContext
-
retainAll
This method is unsupported, throwsUnsupportedOperationException.- Specified by:
retainAllin interfaceCollection- See Also:
-
serialize
Serializes the given collection.First writes a
intindicating the number of all serializable elements (implementsSerializable, then objects are writtern one by one.- Parameters:
oos- the stream where the collection is writtern tocollection- the collection to serialize- Throws:
IOException- if I/O exception occurs
-
setDesignTime
public void setDesignTime(boolean designTime) - Specified by:
setDesignTimein interfaceDesignMode
-
setLocale
Sets the locale of this context.VetoableChangeListeners andPropertyChangeListeners are notified.- Parameters:
newLocale- the new locale to set- Throws:
PropertyVetoException- if anyVetoableChangeListenervetos this change
-
size
public int size()Returns the number children of this context.- Specified by:
sizein interfaceCollection- Returns:
- the number children of this context
- See Also:
-
toArray
Returns an array of children of this context.- Specified by:
toArrayin interfaceCollection- Returns:
- an array of children of this context
- See Also:
-
toArray
Returns an array of children of this context.- Specified by:
toArrayin interfaceCollection- Returns:
- an array of children of this context
- See Also:
-
validatePendingAdd
Validates the pending add of child.Default implementation always returns true.
- Parameters:
child- the child to be added- Returns:
- true if it is valid to add the child
-
validatePendingRemove
Validates the pending removal of child.Default implementation always returns true.
- Parameters:
child- the child to be removed- Returns:
- true if it is valid to remove the child
-
vetoableChange
- Specified by:
vetoableChangein interfaceVetoableChangeListener- Throws:
PropertyVetoException
-
writeChildren
Serializes children to the given object input stream.The implementation iterates through all children and writes out pairs of child object and
BCSChildobject if the child is serializable (implementsSerialization.This method is called by
writeObject()if the context works standalone. Or if this support object is a delegate of anotherBeanContextimplementation, then this method should be called by the peer to avoid the 'chicken and egg' problem during deserialization.- Parameters:
oos- the stream to write- Throws:
IOException- if I/O exception occurs
-