001 /* java.beans.beancontext.BeanContext
002 Copyright (C) 1999 Free Software Foundation, Inc.
003
004 This file is part of GNU Classpath.
005
006 GNU Classpath is free software; you can redistribute it and/or modify
007 it under the terms of the GNU General Public License as published by
008 the Free Software Foundation; either version 2, or (at your option)
009 any later version.
010
011 GNU Classpath is distributed in the hope that it will be useful, but
012 WITHOUT ANY WARRANTY; without even the implied warranty of
013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 General Public License for more details.
015
016 You should have received a copy of the GNU General Public License
017 along with GNU Classpath; see the file COPYING. If not, write to the
018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019 02110-1301 USA.
020
021 Linking this library statically or dynamically with other modules is
022 making a combined work based on this library. Thus, the terms and
023 conditions of the GNU General Public License cover the whole
024 combination.
025
026 As a special exception, the copyright holders of this library give you
027 permission to link this library with independent modules to produce an
028 executable, regardless of the license terms of these independent
029 modules, and to copy and distribute the resulting executable under
030 terms of your choice, provided that you also meet, for each linked
031 independent module, the terms and conditions of the license of that
032 module. An independent module is a module which is not derived from
033 or based on this library. If you modify this library, you may extend
034 this exception to your version of the library, but you are not
035 obligated to do so. If you do not wish to do so, delete this
036 exception statement from your version. */
037
038
039 package java.beans.beancontext;
040
041 import java.beans.DesignMode;
042 import java.beans.Visibility;
043 import java.io.IOException;
044 import java.io.InputStream;
045 import java.net.URL;
046 import java.util.Collection;
047
048 /**
049 * Acts as a container for sub-beans and as a sub-bean,
050 * so that an entire hierarchy of beans can be made up of
051 * <code>BeanContext</code>s.
052 * <P>
053 *
054 * Since I can't sprinkle the <code>Collections</code> interface
055 * documentation with special information for <code>BeanContext</code>
056 * implementors, I'll have to document special requirements for
057 * implementors of those functions here.
058 * <P>
059 *
060 * <code><strong>add()</strong></code> or <code>addAll()</code>:
061 * <br>
062 * <OL>
063 * <LI>
064 * May add any <code>Object</code> into the hierarchy as well as a
065 * <code>BeanContextChild</code>, <code>BeanContext</code> or
066 * <code>BeanContextProxy</code> object.
067 * This way, any Bean can be in the hierarchy.
068 * </LI>
069 * <LI>
070 * Must synchronize on <code>BeanContext.globalHierarchyLock</code>.
071 * </LI>
072 * <LI>
073 * Don't add the <code>Object</code> if it's already there (only once
074 * per <code>BeanContext</code>).
075 * </LI>
076 * <LI>
077 * If it is a <code>BeanContextChild</code> implementor, call
078 * <code>setBeanContext()</code> on it. If it's a
079 * <code>BeanContextProxy</code> implementor, call
080 * <code>getBeanContextProxy().setBeanContext()</code> on it.
081 * If <code>setBeanContext()</code> vetoes the change, back out
082 * all changes so far and throw <code>IllegalStateException</code>.
083 * </LI>
084 * <LI>
085 * If it (or its proxy) implements <code>Visibility</code>, call
086 * <code>dontUseGui()</code> or <code>okToUseGui()</code> on it,
087 * depending on whether you (the <code>BeanContext</code>) feel like
088 * allowing it to use the GUI or not.
089 * </LI>
090 * <LI>
091 * If it implements <code>BeanContextChild</code> or
092 * <code>BeanContextProxy</code>, register yourself (the
093 * <code>BeanContext</code>) as both a
094 * <code>PropertyChangeListener</code> and
095 * <code>VetoableChangeListener</code> on the "beanContext"
096 * property (it may also add itself on any other properties it wishes
097 * to).
098 * </LI>
099 * <LI>
100 * If it is a listener or event source that you (the
101 * <code>BeanContext</code>) are interested in, you may register
102 * yourself to it or register it to you.
103 * </LI>
104 * <LI>
105 * Fire a <code>java.beans.beancontext.BeanContextMembershipEvent</code>
106 * before exiting. <code>addAll()</code> should wait until everything
107 * is done changing before firing the event (or events) so that if a
108 * failure occurs, the backing-out process can proceed without any
109 * events being fired at all.
110 * </LI>
111 * </OL>
112 * <P>
113 *
114 * <code><strong>remove()</strong></code> or <code>removeAll()</code>:
115 * <br>
116 * <OL>
117 * <LI>
118 * Must synchronize on <code>BeanContext.globalHierarchyLock</code>.
119 * </LI>
120 * <LI>
121 * If the specified <code>Object</code> is not a child of this
122 * <code>BeanContext</code>, just exit without performing any actions.
123 * </LI>
124 * <LI>
125 * Remove the <code>Object</code> from your collection of children.
126 * </LI>
127 * <LI>
128 * If it is a <code>BeanContextChild</code> implementor, call
129 * <code>setBeanContext(null)</code> on it. If it's a
130 * <code>BeanContextProxy</code> implementor, call
131 * <code>getBeanContextProxy().setBeanContext(null)</code> on it.
132 * If <code>setBeanContext()</code> vetoes the change, back out
133 * all changes so far and throw <code>IllegalStateException</code>.
134 * </LI>
135 * <LI>
136 * If you registered the <code>Object</code> to listen to you or
137 * registered yourself as a listener on the <code>Object</code> during
138 * <code>add()</code> or <code>addAll()</code>, undo the registration
139 * bycalling the appropriate <code>removeListener()</code> method.
140 * </LI>
141 * <LI>
142 * Fire a <code>java.beans.beancontext.BeanContextMembershipEvent</code>
143 * before exiting. <code>removeAll()</code> should wait until
144 * everything is done changing before firing the event (or events) so
145 * that if a failure occurs, the backing-out process can proceed
146 * without any events being fired at all.
147 * </LI>
148 * </OL>
149 * <P>
150 *
151 * <code>addAll()</code>, <code>removeAll()</code>,
152 * <code>retainAll()</code> and <code>clear()</code> do not need to be
153 * implemented, but may be if so desired.
154 * <P>
155 *
156 * Similarly, <code>Visibility</code> and <code>DesignMode</code> methods
157 * should propagate changed values to children that implement interfaces
158 * of the same name.
159 * <P>
160 *
161 * A hierarchy of beans is mainly useful so that different sets of beans
162 * can be established, each with their own set of resources.
163 *
164 * @author John Keiser
165 * @since JDK1.2
166 */
167
168 public interface BeanContext
169 extends Collection, BeanContextChild, Visibility, DesignMode {
170
171 /**
172 * The global lock on changing any BeanContext hierarchy.
173 * It kinda sucks that there is only one lock, since there can be
174 * multiple hierarchies. Oh well, I didn't design, I just code.
175 * <P>
176 *
177 * Methods that must (or do) synchronize on the global lock:
178 * <BR>
179 * <UL>
180 * <LI>
181 * Implementors of <CODE>BeanContext.add()</CODE> and <code>addAll()</code>
182 * </LI>
183 * </UL>
184 * @fixme fill in the rest of the methods which use the global lock.
185 */
186 Object globalHierarchyLock = new Object();
187
188 /**
189 * Instantiate a Bean using this Bean's <code>ClassLoader</code>
190 * and this <code>BeanContext</code> as the parent.
191 * <P>
192 *
193 * This method exists mainly so that <code>BeanContext</code>
194 * implementations can perform extra actions on Beans that are
195 * created within them.
196 *
197 * @param beanName the name of the bean to instantiate
198 * @return the created Bean
199 *
200 * @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String)
201 * @see java.beans.Beans#instantiate(java.lang.ClassLoader,java.lang.String,java.beans.beancontext.BeanContext)
202 * @exception IOException if there is an I/O problem during
203 * instantiation.
204 * @exception ClassNotFoundException if a serialized Bean's class
205 * is not found.
206 */
207 Object instantiateChild(String beanName)
208 throws IOException,
209 ClassNotFoundException;
210
211 /**
212 * Get a resource. The <code>BeanContext</code> will typically
213 * call <code>ClassLoader.getResource()</code>, but may do it any
214 * way it wants to. This allows a <code>BeanContext</code> to
215 * have its own set of resources separate from the rest of the
216 * system.
217 * <P>
218 *
219 * Beans should call this method on their parent rather than the
220 * associated <code>ClassLoader</code> method.
221 * <P>
222 *
223 * I am assuming, but am not entirely sure, that if a
224 * <code>BeanContext</code> cannot find a resource, its
225 * responsibility is to call the <code>getResource</code> method
226 * of its parent <code>BeanContext</code>.
227 *
228 * @return a URL to the requested resource.
229 * @param resourceName the name of the resource requested.
230 * @param requestor a reference to the child requesting the resource.
231 * @see java.lang.ClassLoader#getResource(java.lang.String)
232 */
233 URL getResource(String resourceName, BeanContextChild requestor);
234
235 /**
236 * Get a resource as a stream. The <code>BeanContext</code> will
237 * typically call <code>ClassLoader.getResourceAsStream()</code>,
238 * but may do it any way it wants to. This allows a
239 * <code>BeanContext</code>'s children to have their own set of
240 * resources separate from the rest of the system.
241 * <P>
242 *
243 * Beans should call this method on their parent rather than the
244 * associated <code>ClassLoader</code> method.
245 * <P>
246 *
247 * I am assuming, but am not entirely sure, that if a
248 * <code>BeanContext</code> cannot find a resource, its
249 * responsibility is to call the <code>getResourceAsStream</code>
250 * method of its parent <code>BeanContext</code>.
251 *
252 * @return the requested resource as a stream.
253 * @param resourceName the name of the resource requested.
254 * @param requestor a reference to the child requesting the resource.
255 * @see java.lang.ClassLoader#getResourceAsStream(java.lang.String)
256 */
257 InputStream getResourceAsStream(String resourceName, BeanContextChild requestor);
258
259 /**
260 * Add a listener on changes to the membership of this
261 * <code>BeanContext</code> object.
262 * @param listener the listener to add.
263 */
264 void addBeanContextMembershipListener(BeanContextMembershipListener listener);
265
266 /**
267 * Remove a listener on changes to the membership of this
268 * <code>BeanContext</code> object.
269 * @param listener the listener to remove.
270 */
271 void removeBeanContextMembershipListener(BeanContextMembershipListener listener);
272 }