/* java.beans.beancontext.BeanContext
Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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 for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.beans.beancontext;
import java.util.Collection;
import java.beans.Visibility;
import java.beans.DesignMode;
import java.net.URL;
import java.io.InputStream;
import java.io.IOException;
/**
* Acts as a container for sub-beans and as a sub-bean,
* so that an entire hierarchy of beans can be made up of
* BeanContext
s.
*
*
* Since I can't sprinkle the Collections
interface
* documentation with special information for BeanContext
* implementors, I'll have to document special requirements for
* implementors of those functions here.
*
*
* add()
or addAll()
:
*
*
Object
into the hierarchy as well as a
* BeanContextChild
, BeanContext
or
* BeanContextProxy
object.
* This way, any Bean can be in the hierarchy.
* BeanContext.globalHierarchyLock
.
* Object
if it's already there (only once
* per BeanContext
).
* BeanContextChild
implementor, call
* setBeanContext()
on it. If it's a
* BeanContextProxy
implementor, call
* getBeanContextProxy().setBeanContext()
on it.
* If setBeanContext()
vetoes the change, back out
* all changes so far and throw IllegalStateException
.
* Visibility
, call
* dontUseGui()
or okToUseGui()
on it,
* depending on whether you (the BeanContext
) feel like
* allowing it to use the GUI or not.
* BeanContextChild
or
* BeanContextProxy
, register yourself (the
* BeanContext
) as both a
* PropertyChangeListener
and
* VetoableChangeListener
on the "beanContext"
* property (it may also add itself on any other properties it wishes
* to).
* BeanContext
) are interested in, you may register
* yourself to it or register it to you.
* java.beans.beancontext.BeanContextMembershipEvent
* before exiting. addAll()
should wait until everything
* is done changing before firing the event (or events) so that if a
* failure occurs, the backing-out process can proceed without any
* events being fired at all.
*
*
* remove()
or removeAll()
:
*
*
BeanContext.globalHierarchyLock
.
* Object
is not a child of this
* BeanContext
, just exit without performing any actions.
* Object
from your collection of children.
* BeanContextChild
implementor, call
* setBeanContext(null)
on it. If it's a
* BeanContextProxy
implementor, call
* getBeanContextProxy().setBeanContext(null)
on it.
* If setBeanContext()
vetoes the change, back out
* all changes so far and throw IllegalStateException
.
* Object
to listen to you or
* registered yourself as a listener on the Object
during
* add()
or addAll()
, undo the registration
* bycalling the appropriate removeListener()
method.
* java.beans.beancontext.BeanContextMembershipEvent
* before exiting. removeAll()
should wait until
* everything is done changing before firing the event (or events) so
* that if a failure occurs, the backing-out process can proceed
* without any events being fired at all.
*
*
* addAll()
, removeAll()
,
* retainAll()
and clear()
do not need to be
* implemented, but may be if so desired.
*
*
* Similarly, Visibility
and DesignMode
methods
* should propagate changed values to children that implement interfaces
* of the same name.
*
* * A hierarchy of beans is mainly useful so that different sets of beans * can be established, each with their own set of resources. * * @author John Keiser * @since JDK1.2 */ public interface BeanContext extends Collection, BeanContextChild, Visibility, DesignMode { /** * The global lock on changing any BeanContext hierarchy. * It kinda sucks that there is only one lock, since there can be * multiple hierarchies. Oh well, I didn't design, I just code. *
*
* Methods that must (or do) synchronize on the global lock:
*
*
BeanContext.add()
and addAll()
* ClassLoader
* and this BeanContext
as the parent.
*
*
* This method exists mainly so that BeanContext
* implementations can perform extra actions on Beans that are
* created within them.
*
* @param beanName the name of the bean to instantiate
* @return the created Bean
*
* @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String)
* @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String,java.lang.BeanContext)
* @exception IOException if there is an I/O problem during
* instantiation.
* @exception ClassNotFoundException if a serialized Bean's class
* is not found.
*/
public Object instantiateChild(String beanName)
throws IOException,
ClassNotFoundException;
/**
* Get a resource. The BeanContext
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
.
*
* @return a URL to the requested resource.
* @param resourceName the name of the resource requested.
* @param requestor a reference to the child requesting the resource.
* @see java.lang.ClassLoader#getResource(java.lang.String)
*/
public URL getResource(String resourceName, BeanContextChild requestor);
/**
* Get a resource as a stream. The BeanContext
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
.
*
* @return the requested resource as a stream.
* @param resourceName the name of the resource requested.
* @param requestor a reference to the child requesting the resource.
* @see java.lang.ClassLoader#getResourceAsStream(java.lang.String)
*/
public InputStream getResourceAsStream(String resourceName, BeanContextChild requestor);
/**
* Add a listener on changes to the membership of this
* BeanContext
object.
* @param listener the listener to add.
*/
public void addBeanContextMembershipListener(BeanContextMembershipListener listener);
/**
* Remove a listener on changes to the membership of this
* BeanContext
object.
* @param listener the listener to remove.
*/
public void removeBeanContextMembershipListener(BeanContextMembershipListener listener);
}