/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This helper class provides a utility implementation of the
* java.beans.beancontext.BeanContext interface.
* </p>
* <p>
* Since this class directly implements the BeanContext interface, the class
* can, and is intended to be used either by subclassing this implementation,
* or via ad-hoc delegation of an instance of this class from another.
* </p>
*
* @author Laurence P. G. Cable
* @since 1.2
*/
implements BeanContext,
// Fix for bug 4282900 to pass JCK regression test
/**
*
* Construct a BeanContextSupport instance
*
*
* @param peer The peer <tt>BeanContext</tt> we are
* supplying an implementation for,
* or <tt>null</tt>
* if this object is its own peer
* @param lcle The current Locale for this BeanContext. If
* <tt>lcle</tt> is <tt>null</tt>, the default locale
* is assigned to the <tt>BeanContext</tt> instance.
* @param dTime The initial state,
* <tt>true</tt> if in design mode,
* <tt>false</tt> if runtime.
* @param visible The initial visibility.
* @see java.util.Locale#getDefault()
* @see java.util.Locale#setDefault(java.util.Locale)
*/
super(peer);
designTime = dTime;
initialize();
}
/**
* Create an instance using the specified Locale and design mode.
*
* @param peer The peer <tt>BeanContext</tt> we
* are supplying an implementation for,
* or <tt>null</tt> if this object is its own peer
* @param lcle The current Locale for this <tt>BeanContext</tt>. If
* <tt>lcle</tt> is <tt>null</tt>, the default locale
* is assigned to the <tt>BeanContext</tt> instance.
* @param dtime The initial state, <tt>true</tt>
* if in design mode,
* <tt>false</tt> if runtime.
* @see java.util.Locale#getDefault()
* @see java.util.Locale#setDefault(java.util.Locale)
*/
}
/**
* Create an instance using the specified locale
*
* @param peer The peer BeanContext we are
* supplying an implementation for,
* or <tt>null</tt> if this object
* is its own peer
* @param lcle The current Locale for this
* <tt>BeanContext</tt>. If
* <tt>lcle</tt> is <tt>null</tt>,
* the default locale
* is assigned to the <tt>BeanContext</tt>
* instance.
* @see java.util.Locale#getDefault()
* @see java.util.Locale#setDefault(java.util.Locale)
*/
}
/**
* Create an instance using with a default locale
*
* @param peer The peer <tt>BeanContext</tt> we are
* supplying an implementation for,
* or <tt>null</tt> if this object
* is its own peer
*/
}
/**
* Create an instance that is not a delegate of another object
*/
public BeanContextSupport() {
}
/**
* Gets the instance of <tt>BeanContext</tt> that
* this object is providing the implementation for.
* @return the BeanContext instance
*/
/**
* <p>
* The instantiateChild method is a convenience hook
* in BeanContext to simplify
* the task of instantiating a Bean, nested,
* into a <tt>BeanContext</tt>.
* </p>
* <p>
* The semantics of the beanName parameter are defined by java.beans.Beans.instantate.
* </p>
*
* @param beanName the name of the Bean to instantiate within this BeanContext
* @throws IOException if there is an I/O error when the bean is being deserialized
* @throws ClassNotFoundException if the class
* identified by the beanName parameter is not found
* @return the new object
*/
throws IOException, ClassNotFoundException {
}
/**
* Gets the number of children currently nested in
* this BeanContext.
*
* @return number of children
*/
public int size() {
synchronized(children) {
}
}
/**
* Reports whether or not this
* <tt>BeanContext</tt> is empty.
* A <tt>BeanContext</tt> is considered
* empty when it contains zero
* nested children.
* @return if there are not children
*/
public boolean isEmpty() {
synchronized(children) {
}
}
/**
* Determines whether or not the specified object
* is currently a child of this <tt>BeanContext</tt>.
* @param o the Object in question
* @return if this object is a child
*/
synchronized(children) {
return children.containsKey(o);
}
}
/**
* Determines whether or not the specified object
* is currently a child of this <tt>BeanContext</tt>.
* @param o the Object in question
* @return if this object is a child
*/
synchronized(children) {
return children.containsKey(o);
}
}
/**
* Gets all JavaBean or <tt>BeanContext</tt> instances
* currently nested in this <tt>BeanContext</tt>.
* @return an <tt>Iterator</tt> of the nested children
*/
synchronized(children) {
}
}
/**
* Gets all JavaBean or <tt>BeanContext</tt>
* instances currently nested in this BeanContext.
*/
synchronized(children) {
}
}
/**
* Gets an array containing all children of
* this <tt>BeanContext</tt> that match
* the types contained in arry.
* @param arry The array of object
* types that are of interest.
* @return an array of children
*/
synchronized(children) {
}
}
/************************************************************************/
/**
* protected final subclass that encapsulates an iterator but implements
* a noop remove() method.
*/
}
/************************************************************************/
/*
* protected nested class containing per child information, an instance
* of which is associated with each child in the "children" hashtable.
* subclasses can extend this class to include their own per-child state.
*
* Note that this 'value' is serialized with the corresponding child 'key'
* when the BeanContextSupport is serialized.
*/
super();
}
/*
* fields
*/
private transient boolean removePending;
}
/**
* <p>
* Subclasses can override this method to insert their own subclass
* of Child without having to override add() or the other Collection
* methods that add children to the set.
* </p>
*
* @param targetChild the child to create the Child on behalf of
* @param peer the peer if the tragetChild and the peer are related by an implementation of BeanContextProxy
*/
}
/************************************************************************/
/**
* <p>
* Invoked as a side effect of java.beans.Beans.instantiate().
* If the child object is not valid for adding then this method
* throws an IllegalStateException.
* </p>
*
*
* @param targetChild The child objects to nest
* within this <tt>BeanContext</tt>
* @return true if the child was added successfully.
* @see #validatePendingAdd
*/
// The specification requires that we do nothing if the child
// is already nested herein.
synchronized(BeanContext.globalHierarchyLock) {
if (!validatePendingAdd(targetChild)) {
throw new IllegalStateException();
}
// The specification requires that we invoke setBeanContext() on the
// newly added child if it implements the java.beans.beancontext.BeanContextChild interface
synchronized(targetChild) {
if (targetChild instanceof BeanContextProxy) {
}
synchronized (children) {
}
try {
} catch (PropertyVetoException pve) {
synchronized (children) {
}
throw new IllegalStateException();
}
}
if (v != null) {
if (okToUseGui)
v.okToUseGui();
else
v.dontUseGui();
}
v = getChildVisibility(bccp);
if (v != null) {
if (okToUseGui)
v.okToUseGui();
else
v.dontUseGui();
}
}
}
// The specification requires that we fire a notification of the change
fireChildrenAdded(new BeanContextMembershipEvent(getBeanContextPeer(), bccp == null ? new Object[] { targetChild } : new Object[] { targetChild, bccp } ));
}
return true;
}
/**
* Removes a child from this BeanContext. If the child object is not
* for adding then this method throws an IllegalStateException.
* @param targetChild The child objects to remove
* @see #validatePendingRemove
*/
return remove(targetChild, true);
}
/**
* internal remove used when removal caused by
* unexpected <tt>setBeanContext</tt> or
* by <tt>remove()</tt> invocation.
* @param targetChild the JavaBean, BeanContext, or Object to be removed
* @param callChildSetBC used to indicate that
* the child should be notified that it is no
* longer nested in this <tt>BeanContext</tt>.
*/
synchronized(BeanContext.globalHierarchyLock) {
if (!containsKey(targetChild)) return false;
if (!validatePendingRemove(targetChild)) {
throw new IllegalStateException();
}
// we are required to notify the child that it is no longer nested here if
// it implements java.beans.beancontext.BeanContextChild
synchronized(targetChild) {
if (callChildSetBC) {
try {
} catch (PropertyVetoException pve1) {
throw new IllegalStateException();
}
}
}
synchronized (children) {
if (bcsc.isProxyPeer()) {
}
}
}
}
fireChildrenRemoved(new BeanContextMembershipEvent(getBeanContextPeer(), peer == null ? new Object[] { targetChild } : new Object[] { targetChild, peer } ));
}
return true;
}
/**
* Tests to see if all objects in the
* specified <tt>Collection</tt> are children of
* this <tt>BeanContext</tt>.
* @param c the specified <tt>Collection</tt>
*
* @return <tt>true</tt> if all objects
* in the collection are children of
* this <tt>BeanContext</tt>, false if not.
*/
synchronized(children) {
while (i.hasNext())
return false;
return true;
}
}
/**
* add Collection to set of Children (Unsupported)
* implementations must synchronized on the hierarchy lock and "children" protected field
* @throws UnsupportedOperationException
*/
throw new UnsupportedOperationException();
}
/**
* remove all specified children (Unsupported)
* implementations must synchronized on the hierarchy lock and "children" protected field
* @throws UnsupportedOperationException
*/
throw new UnsupportedOperationException();
}
/**
* retain only specified children (Unsupported)
* implementations must synchronized on the hierarchy lock and "children" protected field
* @throws UnsupportedOperationException
*/
throw new UnsupportedOperationException();
}
/**
* clear the children (Unsupported)
* implementations must synchronized on the hierarchy lock and "children" protected field
* @throws UnsupportedOperationException
*/
public void clear() {
throw new UnsupportedOperationException();
}
/**
* Adds a BeanContextMembershipListener
*
* @param bcml the BeanContextMembershipListener to add
* @throws NullPointerException
*/
synchronized(bcmListeners) {
return;
else
}
}
/**
* Removes a BeanContextMembershipListener
*
* @param bcml the BeanContextMembershipListener to remove
* @throws NullPointerException
*/
synchronized(bcmListeners) {
return;
else
}
}
/**
* @param name the name of the resource requested.
* @param bcc the child object making the request.
*
* @return the requested resource as an InputStream
* @throws NullPointerException
*/
if (containsKey(bcc)) {
} else throw new IllegalArgumentException("Not a valid child");
}
/**
* @param name the name of the resource requested.
* @param bcc the child object making the request.
*
* @return the requested resource as an InputStream
*/
if (containsKey(bcc)) {
} else throw new IllegalArgumentException("Not a valid child");
}
/**
* Sets the new design time value for this <tt>BeanContext</tt>.
* @param dTime the new designTime value
*/
if (designTime != dTime) {
designTime = dTime;
}
}
/**
* Reports whether or not this object is in
* currently in design time mode.
* @return <tt>true</tt> if in design time mode,
* <tt>false</tt> if not
*/
/**
* Sets the locale of this BeanContext.
* @param newLocale the new locale. This method call will have
* no effect if newLocale is <CODE>null</CODE>.
* @throws PropertyVetoException if the new value is rejected
*/
}
}
/**
* Gets the locale for this <tt>BeanContext</tt>.
*
* @return the current Locale of the <tt>BeanContext</tt>
*/
/**
* <p>
* This method is typically called from the environment in order to determine
* if the implementor "needs" a GUI.
* </p>
* <p>
* The algorithm used herein tests the BeanContextPeer, and its current children
* to determine if they are either Containers, Components, or if they implement
* Visibility and return needsGui() == true.
* </p>
* @return <tt>true</tt> if the implementor needs a GUI
*/
public synchronized boolean needsGui() {
if (bc != this) {
return true;
}
synchronized(children) {
try {
return ((Visibility)c).needsGui();
} catch (ClassCastException cce) {
// do nothing ...
}
return true;
}
}
return false;
}
/**
* notify this instance that it may no longer render a GUI.
*/
public synchronized void dontUseGui() {
if (okToUseGui) {
okToUseGui = false;
// lets also tell the Children that can that they may not use their GUI's
synchronized(children) {
if (v != null) v.dontUseGui();
}
}
}
}
/**
* Notify this instance that it may now render a GUI
*/
public synchronized void okToUseGui() {
if (!okToUseGui) {
okToUseGui = true;
// lets also tell the Children that can that they may use their GUI's
synchronized(children) {
if (v != null) v.okToUseGui();
}
}
}
}
/**
* Used to determine if the <tt>BeanContext</tt>
* child is avoiding using its GUI.
* @return is this instance avoiding using its GUI?
* @see Visibility
*/
public boolean avoidingGui() {
return !okToUseGui && needsGui();
}
/**
* Is this <tt>BeanContext</tt> in the
* process of being serialized?
* @return if this <tt>BeanContext</tt> is
* currently being serialized
*/
/**
* Returns an iterator of all children
* of this <tt>BeanContext</tt>.
* @return an iterator for all the current BCSChild values
*/
protected Iterator bcsChildren() { synchronized(children) { return children.values().iterator(); } }
/**
* called by writeObject after defaultWriteObject() but prior to
* serialization of currently serializable children.
*
* This method may be overridden by subclasses to perform custom
* serialization of their state prior to this superclass serializing
* the children.
*
* This method should not however be used by subclasses to replace their
* own implementation (if any) of writeObject().
*/
}
/**
* called by readObject after defaultReadObject() but prior to
* deserialization of any children.
*
* This method may be overridden by subclasses to perform custom
* deserialization of their state prior to this superclass deserializing
* the children.
*
* This method should not however be used by subclasses to replace their
* own implementation (if any) of readObject().
*/
protected void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException {
}
/**
* Called by readObject with the newly deserialized child and BCSChild.
* @param child the newly deserialized child
* @param bcsc the newly deserialized BCSChild
*/
synchronized(children) {
}
}
/**
* Used by writeObject to serialize a Collection.
* @param oos the <tt>ObjectOutputStream</tt>
* to use during serialization
* @param coll the <tt>Collection</tt> to serialize
* @throws IOException if serialization failed
*/
int count = 0;
if (objects[i] instanceof Serializable)
count++;
else
}
if (o != null) {
oos.writeObject(o);
count--;
}
}
}
/**
* used by readObject to deserialize a collection.
* @param ois the ObjectInputStream to use
* @param coll the Collection
*/
protected final void deserialize(ObjectInputStream ois, Collection coll) throws IOException, ClassNotFoundException {
int count = 0;
while (count-- > 0) {
}
}
/**
* Used to serialize all children of
* this <tt>BeanContext</tt>.
* @param oos the <tt>ObjectOutputStream</tt>
* to use during serialization
* @throws IOException if serialization failed
*/
if (serializable <= 0) return;
boolean prev = serializing;
serializing = true;
int count = 0;
synchronized(children) {
try {
} catch (IOException ioe) {
serializing = prev;
throw ioe;
}
count++;
}
}
}
serializing = prev;
if (count != serializable) {
throw new IOException("wrote different number of children than expected");
}
}
/**
* Serialize the BeanContextSupport, if this instance has a distinct
* peer (that is this object is acting as a delegate for another) then
* the children of this instance are not serialized here due to a
* 'chicken and egg' problem that occurs on deserialization of the
* children at the same time as this instance.
*
* Therefore in situations where there is a distinct peer to this instance
* it should always call writeObject() followed by writeChildren() and
* readObject() followed by readChildren().
*
* @param oos the ObjectOutputStream
*/
private synchronized void writeObject(ObjectOutputStream oos) throws IOException, ClassNotFoundException {
serializing = true;
synchronized (BeanContext.globalHierarchyLock) {
try {
} finally {
serializing = false;
}
}
}
/**
* When an instance of this class is used as a delegate for the
* implementation of the BeanContext protocols (and its subprotocols)
* there exists a 'chicken and egg' problem during deserialization
*/
int count = serializable;
while (count-- > 0) {
try {
} catch (IOException ioe) {
continue;
} catch (ClassNotFoundException cnfe) {
continue;
}
synchronized(child) {
try {
} catch (ClassCastException cce) {
// do nothing;
}
try {
} catch (PropertyVetoException pve) {
continue;
}
}
}
}
}
/**
* deserialize contents ... if this instance has a distinct peer the
* children are *not* serialized here, the peer's readObject() must call
* readChildren() after deserializing this instance.
*/
private synchronized void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
synchronized(BeanContext.globalHierarchyLock) {
initialize();
}
}
/**
* subclasses may envelope to monitor veto child property changes.
*/
synchronized(children) {
containsKey(source) &&
) {
if (!validatePendingRemove(source)) {
}
}
}
/**
* subclasses may envelope to monitor child property changes.
*/
synchronized(children) {
containsKey(source) &&
} else {
}
}
}
}
/**
* <p>
* Subclasses of this class may override, or envelope, this method to
* add validation behavior for the BeanContext to examine child objects
* immediately prior to their being added to the BeanContext.
* </p>
*
* @return true iff the child may be added to this BeanContext, otherwise false.
*/
return true;
}
/**
* <p>
* Subclasses of this class may override, or envelope, this method to
* add validation behavior for the BeanContext to examine child objects
* immediately prior to their being removed from the BeanContext.
* </p>
*
* @return true iff the child may be removed from this BeanContext, otherwise false.
*/
return true;
}
/**
* subclasses may override this method to simply extend add() semantics
* after the child has been added and before the event notification has
* occurred. The method is called with the child synchronized.
*/
}
/**
* subclasses may override this method to simply extend remove() semantics
* after the child has been removed and before the event notification has
* occurred. The method is called with the child synchronized.
*/
}
/**
* Gets the Component (if any) associated with the specified child.
* @param child the specified child
* @return the Component (if any) associated with the specified child.
*/
try {
return (Visibility)child;
} catch (ClassCastException cce) {
return null;
}
}
/**
* Gets the Serializable (if any) associated with the specified Child
* @param child the specified child
* @return the Serializable (if any) associated with the specified Child
*/
try {
return (Serializable)child;
} catch (ClassCastException cce) {
return null;
}
}
/**
* Gets the PropertyChangeListener
* (if any) of the specified child
* @param child the specified child
* @return the PropertyChangeListener (if any) of the specified child
*/
try {
return (PropertyChangeListener)child;
} catch (ClassCastException cce) {
return null;
}
}
/**
* Gets the VetoableChangeListener
* (if any) of the specified child
* @param child the specified child
* @return the VetoableChangeListener (if any) of the specified child
*/
try {
return (VetoableChangeListener)child;
} catch (ClassCastException cce) {
return null;
}
}
/**
* Gets the BeanContextMembershipListener
* (if any) of the specified child
* @param child the specified child
* @return the BeanContextMembershipListener (if any) of the specified child
*/
protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object child) {
try {
return (BeanContextMembershipListener)child;
} catch (ClassCastException cce) {
return null;
}
}
/**
* Gets the BeanContextChild (if any) of the specified child
* @param child the specified child
* @return the BeanContextChild (if any) of the specified child
* @throws IllegalArgumentException if child implements both BeanContextChild and BeanContextProxy
*/
try {
throw new IllegalArgumentException("child cannot implement both BeanContextChild and BeanContextProxy");
else
return bcc;
} catch (ClassCastException cce) {
try {
} catch (ClassCastException cce1) {
return null;
}
}
}
/**
* Fire a BeanContextshipEvent on the BeanContextMembershipListener interface
*/
}
/**
* Fire a BeanContextshipEvent on the BeanContextMembershipListener interface
*/
}
/**
* protected method called from constructor and readObject to initialize
* transient state of BeanContextSupport instance.
*
* This class uses this method to instantiate inner class listeners used
* to monitor PropertyChange and VetoableChange events on children.
*
* subclasses may envelope this method to add their own initialization
* behavior
*/
protected synchronized void initialize() {
childPCL = new PropertyChangeListener() {
/*
* this adaptor is used by the BeanContextSupport class to forward
* property changes from a child to the BeanContext, avoiding
* accidential serialization of the BeanContext by a badly
* behaved Serializable child.
*/
}
};
childVCL = new VetoableChangeListener() {
/*
* this adaptor is used by the BeanContextSupport class to forward
* vetoable changes from a child to the BeanContext, avoiding
* accidential serialization of the BeanContext by a badly
* behaved Serializable child.
*/
}
};
}
/**
* Gets a copy of the this BeanContext's children.
* @return a copy of the current nested children
*/
}
/**
* Tests to see if two class objects,
* or their names are equal.
* @param first the first object
* @param second the second object
* @return true if equal, false if not
*/
}
/*
* fields
*/
/**
* all accesses to the <code> protected HashMap children </code> field
* shall be synchronized on that object.
*/
/**
* all accesses to the <code> protected ArrayList bcmListeners </code> field
* shall be synchronized on that object.
*/
//
/**
* The current locale of this BeanContext.
*/
/**
* A <tt>boolean</tt> indicating if this
* instance may now render a GUI.
*/
protected boolean okToUseGui;
/**
* A <tt>boolean</tt> indicating whether or not
* this object is currently in design time mode.
*/
protected boolean designTime;
/*
* transient
*/
private transient boolean serializing;
}