Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
java.beans.beancontext.BeanContextChildSupport
java.beans.beancontext.BeanContextSupport
public class BeanContextSupport
extends BeanContextChildSupport
implements BeanContext, Serializable, PropertyChangeListener, VetoableChangeListener
Nested Class Summary | |
protected class | |
protected static class |
Field Summary | |
protected ArrayList<E> | |
protected HashMap<K,V> | |
protected boolean | |
protected Locale | |
protected boolean |
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 | |
| |
| |
| |
| |
|
Method Summary | |
boolean | |
boolean | |
void |
|
boolean |
|
protected Iterator<E> | |
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected void |
|
protected static boolean |
|
void |
|
boolean | |
boolean | |
boolean | |
protected Object[] | |
protected BeanContextSupport.BCSChild |
|
protected void |
|
void |
|
protected void | |
protected void | |
BeanContext |
|
protected static BeanContextChild |
|
protected static BeanContextMembershipListener |
|
protected static PropertyChangeListener |
|
protected static Serializable |
|
protected static VetoableChangeListener |
|
protected static Visibility |
|
Locale | |
URL |
|
InputStream |
|
protected void | |
Object |
|
boolean |
|
boolean |
|
boolean |
|
Iterator<E> |
|
boolean |
|
void |
|
void |
|
void |
|
boolean | |
protected boolean | |
boolean | |
void |
|
boolean | |
protected void |
|
void |
|
void | |
int |
|
Object[] |
|
Object[] | |
protected boolean |
|
protected boolean |
|
void |
|
void |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public BeanContextSupport(BeanContext peer)
Construct a BeanContextSupport instance.
- Parameters:
peer
- the bean context peer (null
permitted).
public BeanContextSupport(BeanContext peer, Locale locale)
Construct a BeanContextSupport instance.
- Parameters:
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)
Construct a BeanContextSupport instance.
- Parameters:
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)
Construct a BeanContextSupport instance.
- Parameters:
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 theokToUseGui
flag.
public boolean add(Object targetChild)
Add a child to the bean context. A child can be a simpleObject
, aBeanContextChild
or anotherBeanContext
. The children of aBeanContext
form a set. As a result, this method returnsfalse
if the given object is already a child of this context. If the child is aBeanContextChild
, or a proxy for such a child, thesetBeanContext()
method is invoked on the child. If this operation is vetoed by the child, via throwing aPropertyVetoException
, then the current completion state of theadd()
operation is rolled back and aIllegalStateException
is thrown. If theBeanContextChild
is successfully added, then the context registers with itsPropertyChangeListener
andVetoableChangeListener
for "beanContext" events. If the child implementsjava.beans.Visibility
, then its ability to use a GUI is set based on that of this context. ABeanContextMembershipEvent
is fired when the child is successfully added to the bean context. This method is synchronized over the global hierarchy lock.
- Parameters:
targetChild
- the child to add.
- Returns:
- false if the child has already been added.
- Throws:
IllegalArgumentException
- if the child is null.IllegalStateException
- if the child vetos the setting of its context.
public void addBeanContextMembershipListener(BeanContextMembershipListener listener)
Add a listener on changes to the membership of thisBeanContext
object.
- Specified by:
- addBeanContextMembershipListener in interface BeanContext
- Parameters:
listener
- the listener to add.
public boolean avoidingGui()
Returns true if this bean needs a GUI but is being prevented from using one.
- Specified by:
- avoidingGui in interface Visibility
- Returns:
- true if
needsGui()
is true but the bean has been told not to use it.
protected void bcsPreDeserializationHook(ObjectInputStream ois) throws ClassNotFoundException, IOException
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. It should not be used to replace the implementation ofreadObject
in the subclass.
- Parameters:
ois
- the input stream.
- Throws:
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
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. It should not be used to replace the implementation ofwriteObject
in the subclass.
- Parameters:
oos
- the output stream.
- Throws:
IOException
- if an I/O error occurs.
protected void childDeserializedHook(Object child, BeanContextSupport.BCSChild bcsc)
Called when a child is deserialized.
- Parameters:
child
- the deserialized child.bcsc
- the deserialized context wrapper for the child.
protected void childJustRemovedHook(Object child, BeanContextSupport.BCSChild bcsc)
public void clear()
Clear the collection, such that a subsequent call to isEmpty() would return true.
- Specified by:
- clear in interface Collection<E>
- Throws:
UnsupportedOperationException
- if this collection does not support the clear operation.
public boolean contains(Object o)
Test whether this collection contains a given object as one of its elements.
- Specified by:
- contains in interface Collection<E>
- Parameters:
o
- the element to look for.
- Returns:
- true if this collection contains at least one element e such that
o == null ? e == null : o.equals(e)
.
- Throws:
ClassCastException
- if the type of o is not a valid type for this collection.NullPointerException
- if o is null and this collection doesn't support null values.
protected final void deserialize(ObjectInputStream ois, Collection<E> coll) throws ClassNotFoundException, IOException
Deserializes objects (written byserialize(ObjectOutputStream,Collection)
) and adds them to the specified collection.
- Parameters:
ois
- the input stream (null
not permitted).coll
- the collection to add the objects to (null
not permitted).
- Throws:
ClassNotFoundException
-IOException
-
public void dontUseGui()
Informs this bean that is should not make use of the GUI.
- Specified by:
- dontUseGui in interface Visibility
public BeanContext getBeanContextPeer()
Returns the bean context peer.
- Returns:
- The bean context peer.
protected static final BeanContextChild getChildBeanContextChild(Object child)
Returns theBeanContextChild
implementation for the given child.
- Parameters:
child
- the child (null
permitted).
- Returns:
- The bean context child.
- Throws:
IllegalArgumentException
- ifchild
implements both theBeanContextChild
andBeanContextProxy
interfaces.
protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object child)
Returnschild
as an instance ofBeanContextMembershipListener
, ornull
ifchild
does not implement that interface.
- Parameters:
child
- the child (null
permitted).
- Returns:
- The child cast to
BeanContextMembershipListener
.
protected static final PropertyChangeListener getChildPropertyChangeListener(Object child)
Returnschild
as an instance ofPropertyChangeListener
, ornull
ifchild
does not implement that interface.
- Parameters:
child
- the child (null
permitted).
- Returns:
- The child cast to
PropertyChangeListener
.
protected static final Serializable getChildSerializable(Object child)
- Parameters:
child
- the child (null
permitted).
- Returns:
- The child cast to
Serializable
.
protected static final VetoableChangeListener getChildVetoableChangeListener(Object child)
Returnschild
as an instance ofVetoableChangeListener
, ornull
ifchild
does not implement that interface.
- Parameters:
child
- the child (null
permitted).
- Returns:
- The child cast to
VetoableChangeListener
.
protected static final Visibility getChildVisibility(Object child)
- Parameters:
child
- the child (null
permitted).
- Returns:
- The child cast to
Visibility
.
public URL getResource(String name, BeanContextChild bcc)
Get a resource. TheBeanContext
will typically callClassLoader.getResource()
, but may do it any way it wants to. This allows aBeanContext
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 associatedClassLoader
method. I am assuming, but am not entirely sure, that if aBeanContext
cannot find a resource, its responsibility is to call thegetResource
method of its parentBeanContext
.
- Specified by:
- getResource in interface BeanContext
- Parameters:
- Returns:
- a URL to the requested resource.
- See Also:
ClassLoader.getResource(String)
public InputStream getResourceAsStream(String name, BeanContextChild bcc)
Get a resource as a stream. TheBeanContext
will typically callClassLoader.getResourceAsStream()
, but may do it any way it wants to. This allows aBeanContext
'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 associatedClassLoader
method. I am assuming, but am not entirely sure, that if aBeanContext
cannot find a resource, its responsibility is to call thegetResourceAsStream
method of its parentBeanContext
.
- Specified by:
- getResourceAsStream in interface BeanContext
- Parameters:
- Returns:
- the requested resource as a stream.
public Object instantiateChild(String beanName) throws IOException, ClassNotFoundException
This is a convenience method for instantiating a bean inside this context. It delegates to the appropriate method injava.beans.Beans
using the context's classloader.
- Specified by:
- instantiateChild in interface BeanContext
- Parameters:
beanName
- the name of the class of bean to instantiate.
- Throws:
IOException
- if an I/O error occurs in loading the class.ClassNotFoundException
- if the class,beanName
, can not be found.
public boolean isDesignTime()
Returnstrue
if theBeanContext
is in design time mode, andfalse
if it is in runtime mode.
- Specified by:
- isDesignTime in interface DesignMode
- Returns:
- A boolean.
- See Also:
setDesignTime(boolean)
public boolean isEmpty()
Returns true if this bean context has no children.
- Specified by:
- isEmpty in interface Collection<E>
- Returns:
- true if there are no children.
public boolean isSerializing()
Returns true if the bean context is in the process of being serialized.
- Returns:
- true if the context is being serialized.
public Iterator<E> iterator()
Obtain an Iterator over this collection.
- Specified by:
- iterator in interface Collection<E>
- iterator in interface Iterable<E>
- Returns:
- an Iterator over the elements of this collection, in any order.
public boolean needsGui()
Returns false as this bean does not a GUI for its operation.
- Specified by:
- needsGui in interface Visibility
- Returns:
- false
public void okToUseGui()
Informs this bean that it is okay to make use of the GUI.
- Specified by:
- okToUseGui in interface Visibility
public void propertyChange(PropertyChangeEvent pce)
Subclasses may use this method to catch property changes arising from the children of this context. At present, we just listen for the beans being assigned to a different context and remove them from here if such an event occurs.
- Specified by:
- propertyChange in interface PropertyChangeListener
- Parameters:
pce
- the property change event.
public final void readChildren(ObjectInputStream ois) throws IOException, ClassNotFoundException
Deserializes the children using thedeserialize(ObjectInputStream, Collection
method and then callschildDeserializedHook(Object, BCSChild)
for each child deserialized.
- Parameters:
ois
- the input stream.
- Throws:
IOException
- if an I/O error occurs.
public boolean remove(Object targetChild)
Remove the specified child from the context. This is the same as callingremove(Object,boolean)
with a request for thesetBeanContext()
method of the child to be called (i.e. the second argument is true).
- Specified by:
- remove in interface Collection<E>
- Parameters:
targetChild
- the child to remove.
protected boolean remove(Object targetChild, boolean callChildSetBC)
Removes a child from the bean context. A child can be a simpleObject
, aBeanContextChild
or anotherBeanContext
. If the given child is not a child of this context, this method returnsfalse
. If the child is aBeanContextChild
, or a proxy for such a child, thesetBeanContext()
method is invoked on the child (if specified). If this operation is vetoed by the child, via throwing aPropertyVetoException
, then the current completion state of theremove()
operation is rolled back and aIllegalStateException
is thrown. If theBeanContextChild
is successfully removed, then the context deregisters with itsPropertyChangeListener
andVetoableChangeListener
for "beanContext" events. ABeanContextMembershipEvent
is fired when the child is successfully removed from the bean context. This method is synchronized over the global hierarchy lock.
- Parameters:
targetChild
- the child to remove.callChildSetBC
- true if thesetBeanContext()
method of the child should be called.
- Returns:
- false if the child doesn't exist.
- Throws:
IllegalArgumentException
- if the child is null.IllegalStateException
- if the child vetos the setting of its context.
public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml)
Remove a listener on changes to the membership of thisBeanContext
object.
- Specified by:
- removeBeanContextMembershipListener in interface BeanContext
- Parameters:
protected final void serialize(ObjectOutputStream oos, Collection<E> coll) throws IOException
Writes the items in the collection to the specified output stream. Items in the collection that are not instances ofSerializable
(this includesnull
) are simply ignored.
- Parameters:
oos
- the output stream (null
not permitted).coll
- the collection (null
not permitted).
- Throws:
IOException
-
public void setDesignTime(boolean dtime)
Sets the flag that indicates whether or not theBeanContext
is in design mode. If the flag changes value, aPropertyChangeEvent
(with the property name 'designMode') is sent to registered listeners. Note that the property name used here does NOT match the specification in theDesignMode
interface, we match the reference implementation instead - see bug parade entry 4295174.
- Specified by:
- setDesignTime in interface DesignMode
- Parameters:
dtime
- the new value for the flag.
- See Also:
isDesignTime()
public int size()
Get the number of elements in this collection.
- Specified by:
- size in interface Collection<E>
- Returns:
- the number of elements in the collection.
public Object[] toArray()
Returns an array containing the children of thisBeanContext
.
- Specified by:
- toArray in interface Collection<E>
- Returns:
- An array containing the children.
public Object[] toArray(Object[] array)
Populates, then returns, the supplied array with the children of thisBeanContext
. 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 withnull
items at the end.
- Parameters:
array
- an array to populate (null
not permitted).
public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException
Subclasses may use this method to veto changes arising from the children of this context.
- Specified by:
- vetoableChange in interface VetoableChangeListener
- Parameters:
pce
- the vetoable property change event fired.
public final void writeChildren(ObjectOutputStream oos) throws IOException
Serializes the children using theserialize(ObjectOutputStream, Collection
method.
- Parameters:
oos
- the output stream.
- Throws:
IOException
- if an I/O error occurs.