|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.beans.beancontext.BeanContextChildSupport
java.beans.beancontext.BeanContextSupport
public class BeanContextSupport
This is a helper class for implementing a bean context. It is intended to be used either by subclassing or by calling methods of this implementation from another.
| Nested Class Summary | |
|---|---|
protected class |
BeanContextSupport.BCSChild
|
protected static class |
BeanContextSupport.BCSIterator
|
| Field Summary | |
|---|---|
protected ArrayList |
bcmListeners
|
protected HashMap |
children
|
protected boolean |
designTime
|
protected Locale |
locale
|
protected boolean |
okToUseGui
|
| Fields inherited from class java.beans.beancontext.BeanContextChildSupport |
|---|
beanContext, beanContextChildPeer, pcSupport, rejectedSetBCOnce, vcSupport |
| Fields inherited from interface java.beans.beancontext.BeanContext |
|---|
globalHierarchyLock |
| Fields inherited from interface java.beans.DesignMode |
|---|
PROPERTYNAME |
| Constructor Summary | |
|---|---|
BeanContextSupport()
Construct a BeanContextSupport instance. |
|
BeanContextSupport(BeanContext peer)
Construct a BeanContextSupport instance. |
|
BeanContextSupport(BeanContext peer,
Locale locale)
Construct a BeanContextSupport instance. |
|
BeanContextSupport(BeanContext peer,
Locale locale,
boolean dtime)
Construct a BeanContextSupport instance. |
|
BeanContextSupport(BeanContext peer,
Locale locale,
boolean dtime,
boolean visible)
Construct a BeanContextSupport instance. |
|
| Method Summary | |
|---|---|
boolean |
add(Object targetChild)
Add a child to the bean context. |
boolean |
addAll(Collection c)
Add the contents of a given collection to this collection. |
void |
addBeanContextMembershipListener(BeanContextMembershipListener listener)
Add a listener on changes to the membership of this BeanContext object. |
boolean |
avoidingGui()
Returns true if this bean needs a GUI but is being prevented from using one. |
protected Iterator |
bcsChildren()
|
protected void |
bcsPreDeserializationHook(ObjectInputStream ois)
Subclasses may use this method to perform their own deserialization after the default deserialization process has taken place, but prior to the deserialization of the children. |
protected void |
bcsPreSerializationHook(ObjectOutputStream oos)
Subclasses may use this method to perform their own serialization after the default serialization process has taken place, but prior to the serialization of the children. |
protected void |
childDeserializedHook(Object child,
BeanContextSupport.BCSChild bcsc)
Called when a child is deserialized. |
protected void |
childJustAddedHook(Object child,
BeanContextSupport.BCSChild bcsc)
|
protected void |
childJustRemovedHook(Object child,
BeanContextSupport.BCSChild bcsc)
|
protected static boolean |
classEquals(Class first,
Class second)
|
void |
clear()
Clear the collection, such that a subsequent call to isEmpty() would return true. |
boolean |
contains(Object o)
Test whether this collection contains a given object as one of its elements. |
boolean |
containsAll(Collection c)
Test whether this collection contains every element in a given collection. |
boolean |
containsKey(Object o)
|
protected Object[] |
copyChildren()
|
protected BeanContextSupport.BCSChild |
createBCSChild(Object targetChild,
Object peer)
|
protected void |
deserialize(ObjectInputStream ois,
Collection coll)
Deserializes objects (written by serialize(ObjectOutputStream,
Collection)) and adds them to the specified collection. |
void |
dontUseGui()
Informs this bean that is should not make use of the GUI. |
protected void |
fireChildrenAdded(BeanContextMembershipEvent bcme)
|
protected void |
fireChildrenRemoved(BeanContextMembershipEvent bcme)
|
BeanContext |
getBeanContextPeer()
Returns the bean context peer. |
protected static BeanContextChild |
getChildBeanContextChild(Object child)
Returns the BeanContextChild implementation for the given child. |
protected static BeanContextMembershipListener |
getChildBeanContextMembershipListener(Object child)
Returns child as an instance of
BeanContextMembershipListener, or null if
child does not implement that interface. |
protected static PropertyChangeListener |
getChildPropertyChangeListener(Object child)
Returns child as an instance of
PropertyChangeListener, or null if child
does not implement that interface. |
protected static Serializable |
getChildSerializable(Object child)
Returns child as an instance of Serializable, or
null if child does not implement that
interface. |
protected static VetoableChangeListener |
getChildVetoableChangeListener(Object child)
Returns child as an instance of
VetoableChangeListener, or null if child
does not implement that interface. |
protected static Visibility |
getChildVisibility(Object child)
Returns child as an instance of Visibility, or
null if child does not implement that interface. |
Locale |
getLocale()
|
URL |
getResource(String name,
BeanContextChild bcc)
Get a resource. |
InputStream |
getResourceAsStream(String name,
BeanContextChild bcc)
Get a resource as a stream. |
protected void |
initialize()
|
Object |
instantiateChild(String beanName)
This is a convenience method for instantiating a bean inside this context. |
boolean |
isDesignTime()
Returns true if the BeanContext is in
design time mode, and false if it is in runtime mode. |
boolean |
isEmpty()
Returns true if this bean context has no children. |
boolean |
isSerializing()
Returns true if the bean context is in the process of being serialized. |
Iterator |
iterator()
Obtain an Iterator over this collection. |
boolean |
needsGui()
Returns false as this bean does not a GUI for its operation. |
void |
okToUseGui()
Informs this bean that it is okay to make use of the GUI. |
void |
propertyChange(PropertyChangeEvent pce)
Subclasses may use this method to catch property changes arising from the children of this context. |
void |
readChildren(ObjectInputStream ois)
Deserializes the children using the #deserialize(ObjectInputStream, Collection method
and then calls childDeserializedHook(Object, BCSChild)
for each child deserialized. |
boolean |
remove(Object targetChild)
Remove the specified child from the context. |
protected boolean |
remove(Object targetChild,
boolean callChildSetBC)
Removes a child from the bean context. |
boolean |
removeAll(Collection c)
Remove all elements of a given collection from this collection. |
void |
removeBeanContextMembershipListener(BeanContextMembershipListener bcml)
Remove a listener on changes to the membership of this BeanContext object. |
boolean |
retainAll(Collection c)
Remove all elements of this collection that are not contained in a given collection. |
protected void |
serialize(ObjectOutputStream oos,
Collection coll)
Writes the items in the collection to the specified output stream. |
void |
setDesignTime(boolean dtime)
Sets the flag that indicates whether or not the BeanContext is in design mode. |
void |
setLocale(Locale newLocale)
|
int |
size()
Get the number of elements in this collection. |
Object[] |
toArray()
Returns an array containing the children of this BeanContext. |
Object[] |
toArray(Object[] array)
Populates, then returns, the supplied array with the children of this BeanContext. |
protected boolean |
validatePendingAdd(Object targetChild)
|
protected boolean |
validatePendingRemove(Object targetChild)
|
void |
vetoableChange(PropertyChangeEvent pce)
Subclasses may use this method to veto changes arising from the children of this context. |
void |
writeChildren(ObjectOutputStream oos)
Serializes the children using the #serialize(ObjectOutputStream, Collection method. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
equals, hashCode |
| Methods inherited from interface java.beans.beancontext.BeanContextChild |
|---|
addPropertyChangeListener, addVetoableChangeListener, getBeanContext, removePropertyChangeListener, removeVetoableChangeListener, setBeanContext |
| Field Detail |
|---|
protected transient ArrayList bcmListeners
protected transient HashMap children
protected transient boolean designTime
protected transient Locale locale
protected transient boolean okToUseGui
| Constructor Detail |
|---|
public BeanContextSupport()
public BeanContextSupport(BeanContext peer)
peer - the bean context peer (null permitted).
public BeanContextSupport(BeanContext peer,
Locale locale)
peer - the bean context peer (null permitted).locale - the locale (null permitted, equivalent to
the default locale).
public BeanContextSupport(BeanContext peer,
Locale locale,
boolean dtime)
peer - the bean context peer (null permitted).locale - the locale (null permitted, equivalent to
the default locale).dtime - a flag indicating whether or not the bean context is in
design time mode.
public BeanContextSupport(BeanContext peer,
Locale locale,
boolean dtime,
boolean visible)
peer - the bean context peer (null permitted).locale - the locale (null permitted, equivalent to
the default locale).dtime - a flag indicating whether or not the bean context is in
design time mode.visible - initial value of the okToUseGui flag.| Method Detail |
|---|
public boolean add(Object targetChild)
Add a child to the bean context. A child can be a simple
Object, a BeanContextChild
or another BeanContext.
The children of a BeanContext form a set. As
a result, this method returns false if the given
object is already a child of this context.
If the child is a BeanContextChild, or a proxy
for such a child, the setBeanContext() method
is invoked on the child. If this operation is vetoed by the
child, via throwing a PropertyVetoException,
then the current completion state of the add()
operation is rolled back and a IllegalStateException
is thrown. If the BeanContextChild is successfully
added, then the context registers with its
PropertyChangeListener and
VetoableChangeListener for "beanContext" events.
If the child implements java.beans.Visibility,
then its ability to use a GUI is set based on that of
this context.
A BeanContextMembershipEvent is fired when the
child is successfully added to the bean context.
This method is synchronized over the global hierarchy lock.
add in interface CollectiontargetChild - the child to add.
IllegalArgumentException - if the child is null.
IllegalStateException - if the child vetos the setting
of its context.public boolean addAll(Collection c)
Collection
addAll in interface Collectionc - the collection to add.
public void addBeanContextMembershipListener(BeanContextMembershipListener listener)
BeanContextBeanContext object.
addBeanContextMembershipListener in interface BeanContextlistener - the listener to add.public boolean avoidingGui()
avoidingGui in interface VisibilityneedsGui()
is true but the bean has been
told not to use it.protected Iterator bcsChildren()
protected void bcsPreDeserializationHook(ObjectInputStream ois)
throws ClassNotFoundException,
IOException
readObject
in the subclass.
ois - the input stream.
ClassNotFoundException - if the class of an object being deserialized
could not be found.
IOException - if an I/O error occurs.
protected void bcsPreSerializationHook(ObjectOutputStream oos)
throws IOException
writeObject
in the subclass.
oos - the output stream.
IOException - if an I/O error occurs.
protected void childDeserializedHook(Object child,
BeanContextSupport.BCSChild bcsc)
child - the deserialized child.bcsc - the deserialized context wrapper for the child.
protected void childJustAddedHook(Object child,
BeanContextSupport.BCSChild bcsc)
protected void childJustRemovedHook(Object child,
BeanContextSupport.BCSChild bcsc)
protected static final boolean classEquals(Class first,
Class second)
public void clear()
Collection
clear in interface Collectionpublic boolean contains(Object o)
Collection
contains in interface Collectiono - the element to look for.
o == null ? e == null : o.equals(e).public boolean containsAll(Collection c)
Collection
containsAll in interface Collectionc - the collection to test for.
public boolean containsKey(Object o)
protected final Object[] copyChildren()
protected BeanContextSupport.BCSChild createBCSChild(Object targetChild,
Object peer)
protected final void deserialize(ObjectInputStream ois,
Collection coll)
throws ClassNotFoundException,
IOException
serialize(ObjectOutputStream,
Collection)) and adds them to the specified collection.
ois - the input stream (null not permitted).coll - the collection to add the objects to (null not
permitted).
ClassNotFoundException
IOExceptionserialize(ObjectOutputStream, Collection)public void dontUseGui()
dontUseGui in interface Visibilityprotected final void fireChildrenAdded(BeanContextMembershipEvent bcme)
protected final void fireChildrenRemoved(BeanContextMembershipEvent bcme)
public BeanContext getBeanContextPeer()
BeanContextChildSupport.beanContextChildPeerprotected static final BeanContextChild getChildBeanContextChild(Object child)
BeanContextChild implementation for the given child.
child - the child (null permitted).
IllegalArgumentException - if child implements both
the BeanContextChild and BeanContextProxy interfaces.protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object child)
child as an instance of
BeanContextMembershipListener, or null if
child does not implement that interface.
child - the child (null permitted).
BeanContextMembershipListener.protected static final PropertyChangeListener getChildPropertyChangeListener(Object child)
child as an instance of
PropertyChangeListener, or null if child
does not implement that interface.
child - the child (null permitted).
PropertyChangeListener.protected static final Serializable getChildSerializable(Object child)
child as an instance of Serializable, or
null if child does not implement that
interface.
child - the child (null permitted).
Serializable.protected static final VetoableChangeListener getChildVetoableChangeListener(Object child)
child as an instance of
VetoableChangeListener, or null if child
does not implement that interface.
child - the child (null permitted).
VetoableChangeListener.protected static final Visibility getChildVisibility(Object child)
child as an instance of Visibility, or
null if child does not implement that interface.
child - the child (null permitted).
Visibility.public Locale getLocale()
public URL getResource(String name,
BeanContextChild bcc)
BeanContextBeanContext will typically
call ClassLoader.getResource(), but may do it any
way it wants to. This allows a BeanContext to
have its own set of resources separate from the rest of the
system.
Beans should call this method on their parent rather than the
associated ClassLoader method.
I am assuming, but am not entirely sure, that if a
BeanContext cannot find a resource, its
responsibility is to call the getResource method
of its parent BeanContext.
getResource in interface BeanContextname - the name of the resource requested.bcc - a reference to the child requesting the resource.
ClassLoader.getResource(java.lang.String)
public InputStream getResourceAsStream(String name,
BeanContextChild bcc)
BeanContextBeanContext will
typically call ClassLoader.getResourceAsStream(),
but may do it any way it wants to. This allows a
BeanContext's children to have their own set of
resources separate from the rest of the system.
Beans should call this method on their parent rather than the
associated ClassLoader method.
I am assuming, but am not entirely sure, that if a
BeanContext cannot find a resource, its
responsibility is to call the getResourceAsStream
method of its parent BeanContext.
getResourceAsStream in interface BeanContextname - the name of the resource requested.bcc - a reference to the child requesting the resource.
ClassLoader.getResourceAsStream(java.lang.String)protected void initialize()
public Object instantiateChild(String beanName)
throws IOException,
ClassNotFoundException
java.beans.Beans using the context's classloader.
instantiateChild in interface BeanContextbeanName - the name of the class of bean to instantiate.
IOException - if an I/O error occurs in loading the class.
ClassNotFoundException - if the class, beanName,
can not be found.Beans.instantiate(java.lang.ClassLoader,java.lang.String),
Beans.instantiate(java.lang.ClassLoader,java.lang.String,java.beans.beancontext.BeanContext)public boolean isDesignTime()
true if the BeanContext is in
design time mode, and false if it is in runtime mode.
isDesignTime in interface DesignModesetDesignTime(boolean)public boolean isEmpty()
isEmpty in interface Collectionpublic boolean isSerializing()
public Iterator iterator()
Collection
iterator in interface Iterableiterator in interface Collectionpublic boolean needsGui()
needsGui in interface Visibilitypublic void okToUseGui()
okToUseGui in interface Visibilitypublic void propertyChange(PropertyChangeEvent pce)
propertyChange in interface PropertyChangeListenerpce - the property change event.
public final void readChildren(ObjectInputStream ois)
throws IOException,
ClassNotFoundException
#deserialize(ObjectInputStream, Collection method
and then calls childDeserializedHook(Object, BCSChild)
for each child deserialized.
ois - the input stream.
IOException - if an I/O error occurs.
ClassNotFoundExceptionpublic boolean remove(Object targetChild)
remove(Object,boolean)
with a request for the setBeanContext() method
of the child to be called (i.e. the second argument is true).
remove in interface CollectiontargetChild - the child to remove.
protected boolean remove(Object targetChild,
boolean callChildSetBC)
Removes a child from the bean context. A child can be a simple
Object, a BeanContextChild
or another BeanContext. If the given child is not
a child of this context, this method returns false.
If the child is a BeanContextChild, or a proxy
for such a child, the setBeanContext() method
is invoked on the child (if specified). If this operation is vetoed
by the child, via throwing a PropertyVetoException,
then the current completion state of the remove()
operation is rolled back and a IllegalStateException
is thrown. If the BeanContextChild is successfully
removed, then the context deregisters with its
PropertyChangeListener and
VetoableChangeListener for "beanContext" events.
A BeanContextMembershipEvent is fired when the
child is successfully removed from the bean context.
This method is synchronized over the global hierarchy lock.
targetChild - the child to remove.callChildSetBC - true if the setBeanContext()
method of the child should be called.
IllegalArgumentException - if the child is null.
IllegalStateException - if the child vetos the setting
of its context.public boolean removeAll(Collection c)
Collection
removeAll in interface Collectionc - The collection of objects to be removed.
public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml)
BeanContextBeanContext object.
removeBeanContextMembershipListener in interface BeanContextbcml - the listener to remove.public boolean retainAll(Collection c)
Collection
retainAll in interface Collectionc - The collection of objects to be retained.
protected final void serialize(ObjectOutputStream oos,
Collection coll)
throws IOException
Serializable
(this includes null) are simply ignored.
oos - the output stream (null not permitted).coll - the collection (null not permitted).
IOExceptiondeserialize(ObjectInputStream, Collection)public void setDesignTime(boolean dtime)
BeanContext is in design mode. If the flag changes
value, a PropertyChangeEvent (with the property name 'designMode')
is sent to registered listeners. Note that the property name used here
does NOT match the specification in the DesignMode interface, we
match the reference implementation instead - see bug parade entry 4295174.
setDesignTime in interface DesignModedtime - the new value for the flag.isDesignTime()
public void setLocale(Locale newLocale)
throws PropertyVetoException
PropertyVetoExceptionpublic int size()
Collection
size in interface Collectionpublic Object[] toArray()
BeanContext.
toArray in interface Collectionpublic Object[] toArray(Object[] array)
BeanContext. If the array is too short to hold the
children, a new array is allocated and returned. If the array is too
long, it is padded with null items at the end.
toArray in interface Collectionarray - an array to populate (null not permitted).
protected boolean validatePendingAdd(Object targetChild)
protected boolean validatePendingRemove(Object targetChild)
public void vetoableChange(PropertyChangeEvent pce)
throws PropertyVetoException
vetoableChange in interface VetoableChangeListenerpce - the vetoable property change event fired.
PropertyVetoException - if the change is vetoed by the listener
public final void writeChildren(ObjectOutputStream oos)
throws IOException
#serialize(ObjectOutputStream, Collection method.
oos - the output stream.
IOException - if an I/O error occurs.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||