Class BeanContextSupport
- java.lang.Object
-
- jadex.commons.beans.beancontext.BeanContextChildSupport
-
- jadex.commons.beans.beancontext.BeanContextSupport
-
- All Implemented Interfaces:
BeanContext,BeanContextChild,BeanContextServiceRevokedListener,BeanContextServicesListener,DesignMode,PropertyChangeListener,VetoableChangeListener,Visibility,java.io.Serializable,java.lang.Iterable,java.util.Collection,java.util.EventListener
- Direct Known Subclasses:
BeanContextServicesSupport
public class BeanContextSupport extends BeanContextChildSupport implements BeanContext, PropertyChangeListener, VetoableChangeListener, java.io.Serializable
This support class implementsBeanContextinterface. This class can be used directly, or be a super class of your class, or be a delegate of your implementation that needs to supportBeanContextinterface.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classBeanContextSupport.BCSChildEvery child of context is companied with aBCSChildinstance.protected static classBeanContextSupport.BCSIteratorThis implementation wraps an iterator and overrideremove()with a noop method.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayListbcmListenersA list of registered membership listeners.protected java.util.HashMapchildrenA map of children - key is child instance, value isBCSChildinstance.protected booleandesignTimeA flag indicating whether this context is in design mode.protected java.util.LocalelocaleThe locale of this context.protected booleanokToUseGuiA flag indicating whether this context is allowed to use GUI.-
Fields inherited from class jadex.commons.beans.beancontext.BeanContextChildSupport
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport
-
Fields inherited from interface jadex.commons.beans.beancontext.BeanContext
globalHierarchyLock
-
Fields inherited from interface jadex.commons.beans.DesignMode
PROPERTYNAME
-
-
Constructor Summary
Constructors Constructor Description BeanContextSupport()Constructs a standloadBeanContextSupport.BeanContextSupport(BeanContext peer)Constructs aBeanContextSupportwhich is a delegate of the given peer.BeanContextSupport(BeanContext peer, java.util.Locale locale)Constructs aBeanContextSupportwhich is a delegate of the given peer.BeanContextSupport(BeanContext peer, java.util.Locale locale, boolean designTime)Constructs aBeanContextSupportwhich is a delegate of the given peer.BeanContextSupport(BeanContext peer, java.util.Locale locale, boolean designTime, boolean okToUseGui)Constructs aBeanContextSupportwhich is a delegate of the given peer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.Object child)Add a child to this context.booleanaddAll(java.util.Collection collection)This method is unsupported, throwsUnsupportedOperationException.voidaddBeanContextMembershipListener(BeanContextMembershipListener listener)booleanavoidingGui()protected java.util.IteratorbcsChildren()Returns an iterator of allBCSChildinstances, withremove()disabled.protected voidbcsPreDeserializationHook(java.io.ObjectInputStream ois)This method is called byreadObject()afterdefaultReadObject()and before deserializing any children or listeners.protected voidbcsPreSerializationHook(java.io.ObjectOutputStream oos)This method is called bywriteObject()afterdefaultWriteObject()and before serializing any children or listeners.protected voidchildDeserializedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)This method is called during deserialization everytime a child is read.protected voidchildJustAddedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)This method is called everytime a child is added to this context.protected voidchildJustRemovedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)This method is called everytime a child is removed from this context.protected static booleanclassEquals(java.lang.Class clz1, java.lang.Class clz2)Compares if two classes are equal or their class names are equal.voidclear()This method is unsupported, throwsUnsupportedOperationException.booleancontains(java.lang.Object child)Returns true if the given object is a child of this context.booleancontainsAll(java.util.Collection collection)Returns true if given objects are children of this context.booleancontainsKey(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.BCSChildcreateBCSChild(java.lang.Object child, java.lang.Object proxyPeer)Creates aBCSChildobject to company the given child.protected voiddeserialize(java.io.ObjectInputStream ois, java.util.Collection collection)Deserialize a collection.voiddontUseGui()protected voidfireChildrenAdded(BeanContextMembershipEvent event)Notifies registeredBeanContextMembershipListeners that a new child has been added.protected voidfireChildrenRemoved(BeanContextMembershipEvent event)Notifies registeredBeanContextMembershipListeners that a child has been removed.BeanContextgetBeanContextPeer()Returns the peer of this context casted asBeanContext.protected static BeanContextChildgetChildBeanContextChild(java.lang.Object child)Returns theBeanContextChildrelated with the given child.protected static BeanContextMembershipListenergetChildBeanContextMembershipListener(java.lang.Object child)Returns the given child casted toBeanContextMembershipListener, or null if it does not implements the interface.protected static PropertyChangeListenergetChildPropertyChangeListener(java.lang.Object child)Returns the given child casted toPropertyChangeListener, or null if it does not implements the interface.protected static java.io.SerializablegetChildSerializable(java.lang.Object child)Returns the given child casted toSerializable, or null if it does not implements the interface.protected static VetoableChangeListenergetChildVetoableChangeListener(java.lang.Object child)Returns the given child casted toVetoableChangeListener, or null if it does not implements the interface.protected static VisibilitygetChildVisibility(java.lang.Object child)Returns the given child casted toVisibility, or null if it does not implements the interface.java.util.LocalegetLocale()Returns the locale of this context.java.net.URLgetResource(java.lang.String resourceName, BeanContextChild child)java.io.InputStreamgetResourceAsStream(java.lang.String resourceName, BeanContextChild child)protected voidinitialize()Initializes all transient fields of this instance, called by constructors andreadObject().java.lang.ObjectinstantiateChild(java.lang.String beanName)booleanisDesignTime()booleanisEmpty()booleanisSerializing()Returns true if this context is currently being serialized (by another thread).java.util.Iteratoriterator()Returns an iterator of children of this context, withremove()disabled.booleanneedsGui()Returns true if this context or its children needs GUI to work properly.voidokToUseGui()voidpropertyChange(PropertyChangeEvent event)voidreadChildren(java.io.ObjectInputStream ois)Deserializes children from the given object input stream.booleanremove(java.lang.Object child)Removes the given child from this context.protected booleanremove(java.lang.Object child, boolean setChildBC)Removes the given child from this context.booleanremoveAll(java.util.Collection collection)This method is unsupported, throwsUnsupportedOperationException.voidremoveBeanContextMembershipListener(BeanContextMembershipListener listener)booleanretainAll(java.util.Collection collection)This method is unsupported, throwsUnsupportedOperationException.protected voidserialize(java.io.ObjectOutputStream oos, java.util.Collection collection)Serializes the given collection.voidsetDesignTime(boolean designTime)voidsetLocale(java.util.Locale newLocale)Sets the locale of this context.intsize()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 booleanvalidatePendingAdd(java.lang.Object child)Validates the pending add of child.protected booleanvalidatePendingRemove(java.lang.Object child)Validates the pending removal of child.voidvetoableChange(PropertyChangeEvent pce)voidwriteChildren(java.io.ObjectOutputStream oos)Serializes children to the given object input stream.-
Methods inherited from class jadex.commons.beans.beancontext.BeanContextChildSupport
addPropertyChangeListener, addVetoableChangeListener, firePropertyChange, fireVetoableChange, getBeanContext, getBeanContextChildPeer, initializeBeanContextResources, isDelegated, releaseBeanContextResources, removePropertyChangeListener, removeVetoableChangeListener, serviceAvailable, serviceRevoked, setBeanContext, validatePendingSetBeanContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jadex.commons.beans.beancontext.BeanContextChild
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext
-
-
-
-
Field Detail
-
bcmListeners
protected transient java.util.ArrayList bcmListeners
A list of registered membership listeners. All access to this object should be synchronized on itself.
-
children
protected transient java.util.HashMap children
A map of children - key is child instance, value isBCSChildinstance. All access to this object should be synchronized on itself.
-
locale
protected java.util.Locale locale
The locale of this context.
-
okToUseGui
protected boolean okToUseGui
A flag indicating whether this context is allowed to use GUI.
-
designTime
protected boolean designTime
A flag indicating whether this context is in design mode.
-
-
Constructor Detail
-
BeanContextSupport
public BeanContextSupport()
Constructs a standloadBeanContextSupport.
-
BeanContextSupport
public BeanContextSupport(BeanContext peer)
Constructs aBeanContextSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this context
-
BeanContextSupport
public BeanContextSupport(BeanContext peer, java.util.Locale locale)
Constructs aBeanContextSupportwhich is a delegate of the given peer.- Parameters:
peer- the peer of this contextlocale- the locale of this context
-
BeanContextSupport
public BeanContextSupport(BeanContext peer, java.util.Locale locale, boolean designTime)
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
public BeanContextSupport(BeanContext peer, java.util.Locale locale, boolean designTime, boolean okToUseGui)
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 Detail
-
add
public boolean add(java.lang.Object child)
Add a child to this context.validatePendingAdd(). If the add is valid, the child and its proxy (if the child implements
BeanContextProxy) 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 interfacejava.util.Collection- Parameters:
child- the child to add- Returns:
- true if the child is added to this context; otherwise false
- Throws:
java.lang.IllegalStateException- if the child is not valid to add- See Also:
Collection.add(java.lang.Object)
-
addAll
public boolean addAll(java.util.Collection collection)
This method is unsupported, throwsUnsupportedOperationException.- Specified by:
addAllin interfacejava.util.Collection- See Also:
Collection.addAll(java.util.Collection)
-
addBeanContextMembershipListener
public void addBeanContextMembershipListener(BeanContextMembershipListener listener)
- Specified by:
addBeanContextMembershipListenerin interfaceBeanContext
-
avoidingGui
public boolean avoidingGui()
- Specified by:
avoidingGuiin interfaceVisibility
-
bcsChildren
protected java.util.Iterator bcsChildren()
Returns an iterator of allBCSChildinstances, withremove()disabled.- Returns:
- an iterator of all
BCSChildinstances
-
bcsPreDeserializationHook
protected void bcsPreDeserializationHook(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundExceptionThis method is called byreadObject()afterdefaultReadObject()and before deserializing any children or listeners. Subclass can insert its specific deserialization behavior by overrideing this method.- Parameters:
ois- the object input stream- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
bcsPreSerializationHook
protected void bcsPreSerializationHook(java.io.ObjectOutputStream oos) throws java.io.IOExceptionThis method is called bywriteObject()afterdefaultWriteObject()and before serializing any children or listeners. Subclass can insert its specific serialization behavior by overrideing this method.- Parameters:
oos- the object output stream- Throws:
java.io.IOException
-
childDeserializedHook
protected void childDeserializedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)This method is called during deserialization everytime a child is read.- Parameters:
child- the child just deserializedbcsChild- theBCSChildjust deserialized
-
childJustAddedHook
protected void childJustAddedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)This method is called everytime a child is added to this context. This method is called with child synchronized.- Parameters:
child- the child just addedbcsChild- theBCSChildjust added
-
childJustRemovedHook
protected void childJustRemovedHook(java.lang.Object child, BeanContextSupport.BCSChild bcsChild)This method is called everytime a child is removed from this context. This method is called with child synchronized.- Parameters:
child- the child just removedbcsChild- theBCSChildjust removed
-
classEquals
protected static final boolean classEquals(java.lang.Class clz1, java.lang.Class clz2)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 interfacejava.util.Collection- See Also:
Collection.clear()
-
contains
public boolean contains(java.lang.Object child)
Returns true if the given object is a child of this context.- Specified by:
containsin interfacejava.util.Collection- Parameters:
child- the object to test- Returns:
- true if the given object is a child of this context
- See Also:
Collection.contains(java.lang.Object)
-
containsAll
public boolean containsAll(java.util.Collection collection)
Returns true if given objects are children of this context.- Specified by:
containsAllin interfacejava.util.Collection- Parameters:
collection- a collection of objects- Returns:
- true if given objects are children of this context
- See Also:
Collection.containsAll(java.util.Collection)
-
containsKey
public boolean containsKey(java.lang.Object child)
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
protected final java.lang.Object[] copyChildren()
Returns an array containing all children of this context.- Returns:
- an array containing all children of this context
-
createBCSChild
protected BeanContextSupport.BCSChild createBCSChild(java.lang.Object child, java.lang.Object proxyPeer)
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(java.io.ObjectInputStream ois, java.util.Collection collection) throws java.io.IOException, java.lang.ClassNotFoundExceptionDeserialize a collection.int indicating 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:
java.io.IOException- if I/O exception occursjava.lang.ClassNotFoundException- if class of any read object is not found
-
dontUseGui
public void dontUseGui()
- Specified by:
dontUseGuiin interfaceVisibility
-
fireChildrenAdded
protected final void fireChildrenAdded(BeanContextMembershipEvent event)
Notifies registeredBeanContextMembershipListeners that a new child has been added.- Parameters:
event- theBeanContextMembershipEvent
-
fireChildrenRemoved
protected final void fireChildrenRemoved(BeanContextMembershipEvent event)
Notifies registeredBeanContextMembershipListeners that a child has been removed.- Parameters:
event- theBeanContextMembershipEvent
-
getBeanContextPeer
public BeanContext getBeanContextPeer()
Returns the peer of this context casted asBeanContext.- Returns:
- the peer of this context casted as
BeanContext
-
getChildBeanContextChild
protected static final BeanContextChild getChildBeanContextChild(java.lang.Object child)
Returns theBeanContextChildrelated with the given child.BeanContextChild, it is returned. If the child implements
BeanContextProxy, the proxy is returned. Otherwise, null is returned.- Parameters:
child- a child- Returns:
- the
BeanContextChildrelated with the given child - Throws:
java.lang.IllegalStateException- if the child implements bothBeanContextChildandBeanContextProxy
-
getChildBeanContextMembershipListener
protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(java.lang.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
protected static final PropertyChangeListener getChildPropertyChangeListener(java.lang.Object child)
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
protected static final java.io.Serializable getChildSerializable(java.lang.Object child)
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
protected static final VetoableChangeListener getChildVetoableChangeListener(java.lang.Object child)
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
protected static final Visibility getChildVisibility(java.lang.Object child)
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
public java.util.Locale getLocale()
Returns the locale of this context.- Returns:
- the locale of this context
-
getResource
public java.net.URL getResource(java.lang.String resourceName, BeanContextChild child)- Specified by:
getResourcein interfaceBeanContext
-
getResourceAsStream
public java.io.InputStream getResourceAsStream(java.lang.String resourceName, BeanContextChild child) throws java.lang.IllegalArgumentException- Specified by:
getResourceAsStreamin interfaceBeanContext- Throws:
java.lang.IllegalArgumentException
-
initialize
protected void initialize()
Initializes all transient fields of this instance, called by constructors andreadObject().
-
instantiateChild
public java.lang.Object instantiateChild(java.lang.String beanName) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
instantiateChildin interfaceBeanContext- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
isDesignTime
public boolean isDesignTime()
- Specified by:
isDesignTimein interfaceDesignMode
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection
-
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
public java.util.Iterator iterator()
Returns an iterator of children of this context, withremove()disabled.- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- See Also:
Collection.iterator()
-
needsGui
public boolean needsGui()
Returns true if this context or its children needs GUI to work properly.Visibility to see if any of their
needsGui()returns true, and if any of the children extendsjava.awt.Component.- Specified by:
needsGuiin interfaceVisibility- See Also:
Visibility.needsGui()
-
okToUseGui
public void okToUseGui()
- Specified by:
okToUseGuiin interfaceVisibility
-
propertyChange
public void propertyChange(PropertyChangeEvent event)
- Specified by:
propertyChangein interfacePropertyChangeListener
-
readChildren
public final void readChildren(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundExceptionDeserializes children from the given object input stream.BCSChild object according to
readObject() if the context works standalone. Or if this support object is a delegate of anotherserializableproperty. For each pair, it is added to thechildrenmap and thechildDeserializedHook()is called. If the child implementsBeanContextChild, itssetBeanContext()is also called.BeanContextimplementation, 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:
java.io.IOException- if I/O exception occursjava.lang.ClassNotFoundException- if class of read object is not found
-
remove
public boolean remove(java.lang.Object child)
Removes the given child from this context.remove(child, true).
- Specified by:
removein interfacejava.util.Collection- 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:
java.lang.IllegalArgumentException- if the child is nulljava.lang.IllegalStateException- if the child is not valid to remove- See Also:
Collection.remove(java.lang.Object)
-
remove
protected boolean remove(java.lang.Object child, boolean setChildBC)Removes the given child from this context.validatePendingRemove() is called. If the removal is valid, the child's
beanContextproperty 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:
java.lang.IllegalArgumentException- if the child is nulljava.lang.IllegalStateException- if the child is not valid to remove
-
removeAll
public boolean removeAll(java.util.Collection collection)
This method is unsupported, throwsUnsupportedOperationException.- Specified by:
removeAllin interfacejava.util.Collection- See Also:
Collection.removeAll(java.util.Collection)
-
removeBeanContextMembershipListener
public void removeBeanContextMembershipListener(BeanContextMembershipListener listener)
- Specified by:
removeBeanContextMembershipListenerin interfaceBeanContext
-
retainAll
public boolean retainAll(java.util.Collection collection)
This method is unsupported, throwsUnsupportedOperationException.- Specified by:
retainAllin interfacejava.util.Collection- See Also:
Collection.retainAll(java.util.Collection)
-
serialize
protected final void serialize(java.io.ObjectOutputStream oos, java.util.Collection collection) throws java.io.IOExceptionSerializes the given collection.int indicating the number of all serializable elements (implements
Serializable, then objects are writtern one by one.- Parameters:
oos- the stream where the collection is writtern tocollection- the collection to serialize- Throws:
java.io.IOException- if I/O exception occurs
-
setDesignTime
public void setDesignTime(boolean designTime)
- Specified by:
setDesignTimein interfaceDesignMode
-
setLocale
public void setLocale(java.util.Locale newLocale) throws PropertyVetoExceptionSets 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 interfacejava.util.Collection- Returns:
- the number children of this context
- See Also:
Collection.size()
-
toArray
public java.lang.Object[] toArray()
Returns an array of children of this context.- Specified by:
toArrayin interfacejava.util.Collection- Returns:
- an array of children of this context
- See Also:
Collection.toArray()
-
toArray
public java.lang.Object[] toArray(java.lang.Object[] array)
Returns an array of children of this context.- Specified by:
toArrayin interfacejava.util.Collection- Returns:
- an array of children of this context
- See Also:
Collection.toArray(java.lang.Object[])
-
validatePendingAdd
protected boolean validatePendingAdd(java.lang.Object child)
Validates the pending add of child.- Parameters:
child- the child to be added- Returns:
- true if it is valid to add the child
-
validatePendingRemove
protected boolean validatePendingRemove(java.lang.Object child)
Validates the pending removal of child.- Parameters:
child- the child to be removed- Returns:
- true if it is valid to remove the child
-
vetoableChange
public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException
- Specified by:
vetoableChangein interfaceVetoableChangeListener- Throws:
PropertyVetoException
-
writeChildren
public final void writeChildren(java.io.ObjectOutputStream oos) throws java.io.IOExceptionSerializes children to the given object input stream.BCSChild object if the child is serializable (implements
writeObject() if the context works standalone. Or if this support object is a delegate of anotherSerialization.BeanContextimplementation, 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:
java.io.IOException- if I/O exception occurs
-
-