History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/java/beans/beancontext (47 of 18352 files). Show all

Unified · Split

47 files
  1. java/pkg/java/beans/beancontext/BeanContext.class +0 −0
  2. java/pkg/java/beans/beancontext/BeanContext.java +132 −0
  3. java/pkg/java/beans/beancontext/BeanContextChild.class +0 −0
  4. java/pkg/java/beans/beancontext/BeanContextChild.java +137 −0
  5. java/pkg/java/beans/beancontext/BeanContextChildComponentProxy.class +0 −0
  6. java/pkg/java/beans/beancontext/BeanContextChildComponentProxy.java +54 −0
  7. java/pkg/java/beans/beancontext/BeanContextChildSupport.class +0 −0
  8. java/pkg/java/beans/beancontext/BeanContextChildSupport.java +373 −0
  9. java/pkg/java/beans/beancontext/BeanContextContainerProxy.class +0 −0
  10. java/pkg/java/beans/beancontext/BeanContextContainerProxy.java +52 −0
  11. java/pkg/java/beans/beancontext/BeanContextEvent.class +0 −0
  12. java/pkg/java/beans/beancontext/BeanContextEvent.java +104 −0
  13. java/pkg/java/beans/beancontext/BeanContextMembershipEvent.class +0 −0
  14. java/pkg/java/beans/beancontext/BeanContextMembershipEvent.java +131 −0
  15. java/pkg/java/beans/beancontext/BeanContextMembershipListener.class +0 −0
  16. java/pkg/java/beans/beancontext/BeanContextMembershipListener.java +61 −0
  17. java/pkg/java/beans/beancontext/BeanContextProxy.class +0 −0
  18. java/pkg/java/beans/beancontext/BeanContextProxy.java +85 −0
  19. java/pkg/java/beans/beancontext/BeanContextServiceAvailableEvent.class +0 −0
  20. java/pkg/java/beans/beancontext/BeanContextServiceAvailableEvent.java +86 −0
  21. java/pkg/java/beans/beancontext/BeanContextServiceProvider.class +0 −0
  22. java/pkg/java/beans/beancontext/BeanContextServiceProvider.java +104 −0
  23. java/pkg/java/beans/beancontext/BeanContextServiceProviderBeanInfo.class +0 −0
  24. java/pkg/java/beans/beancontext/BeanContextServiceProviderBeanInfo.java +47 −0
  25. java/pkg/java/beans/beancontext/BeanContextServiceRevokedEvent.class +0 −0
  26. java/pkg/java/beans/beancontext/BeanContextServiceRevokedEvent.java +99 −0
  27. java/pkg/java/beans/beancontext/BeanContextServiceRevokedListener.class +0 −0
  28. java/pkg/java/beans/beancontext/BeanContextServiceRevokedListener.java +46 −0
  29. java/pkg/java/beans/beancontext/BeanContextServices.class +0 −0
  30. java/pkg/java/beans/beancontext/BeanContextServices.java +159 −0
  31. java/pkg/java/beans/beancontext/BeanContextServicesListener.class +0 −0
  32. java/pkg/java/beans/beancontext/BeanContextServicesListener.java +46 −0
  33. java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSChild$BCSSCServiceClassRef.class +0 −0
  34. java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSChild$BCSSCServiceRef.class +0 −0
  35. java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSChild.class +0 −0
  36. java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSProxyServiceProvider.class +0 −0
  37. java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSServiceProvider.class +0 −0
  38. java/pkg/java/beans/beancontext/BeanContextServicesSupport.class +0 −0
  39. java/pkg/java/beans/beancontext/BeanContextServicesSupport.java +1238 −0
  40. java/pkg/java/beans/beancontext/BeanContextSupport$1.class +0 −0
  41. java/pkg/java/beans/beancontext/BeanContextSupport$2.class +0 −0
  42. java/pkg/java/beans/beancontext/BeanContextSupport$BCSChild.class +0 −0
  43. java/pkg/java/beans/beancontext/BeanContextSupport$BCSIterator.class +0 −0
  44. java/pkg/java/beans/beancontext/BeanContextSupport.class +0 −0
  45. java/pkg/java/beans/beancontext/BeanContextSupport.java +1393 −0
  46. java/pkg/java/beans/beancontext/mkfile +25 −0
  47. java/pkg/java/beans/beancontext/package.html +55 −0
java/pkg/java/beans/beancontext/BeanContext.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContext.java+132−0
@@ -0,0 +1,132 @@
1/*
2 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.DesignMode;
29import java.beans.Visibility;
30
31import java.io.InputStream;
32import java.io.IOException;
33
34import java.net.URL;
35
36import java.util.Collection;
37import java.util.Locale;
38
39/**
40 * <p>
41 * The BeanContext acts a logical hierarchical container for JavaBeans.
42 * </p>
43 *
44 * @author Laurence P. G. Cable
45 * @since 1.2
46 *
47 * @see java.beans.Beans
48 * @see java.beans.beancontext.BeanContextChild
49 * @see java.beans.beancontext.BeanContextMembershipListener
50 * @see java.beans.PropertyChangeEvent
51 * @see java.beans.DesignMode
52 * @see java.beans.Visibility
53 * @see java.util.Collection
54 */
55
56public interface BeanContext extends BeanContextChild, Collection, DesignMode, Visibility {
57
58 /**
59 * Instantiate the javaBean named as a
60 * child of this <code>BeanContext</code>.
61 * The implementation of the JavaBean is
62 * derived from the value of the beanName parameter,
63 * and is defined by the
64 * <code>java.beans.Beans.instantiate()</code> method.
65 *
66 * @param beanName The name of the JavaBean to instantiate
67 * as a child of this <code>BeanContext</code>
68 * @throws <code>IOException</code>
69 * @throws <code>ClassNotFoundException</code> if the class identified
70 * by the beanName parameter is not found
71 */
72 Object instantiateChild(String beanName) throws IOException, ClassNotFoundException;
73
74 /**
75 * Analagous to <code>java.lang.ClassLoader.getResourceAsStream()</code>,
76 * this method allows a <code>BeanContext</code> implementation
77 * to interpose behavior between the child <code>Component</code>
78 * and underlying <code>ClassLoader</code>.
79 *
80 * @param name the resource name
81 * @param bcc the specified child
82 * @return an <code>InputStream</code> for reading the resource,
83 * or <code>null</code> if the resource could not
84 * be found.
85 * @throws <code>IllegalArgumentException</code> if
86 * the resource is not valid
87 */
88 InputStream getResourceAsStream(String name, BeanContextChild bcc) throws IllegalArgumentException;
89
90 /**
91 * Analagous to <code>java.lang.ClassLoader.getResource()</code>, this
92 * method allows a <code>BeanContext</code> implementation to interpose
93 * behavior between the child <code>Component</code>
94 * and underlying <code>ClassLoader</code>.
95 *
96 * @param name the resource name
97 * @param bcc the specified child
98 * @return a <code>URL</code> for the named
99 * resource for the specified child
100 * @throws <code>IllegalArgumentException</code>
101 * if the resource is not valid
102 */
103 URL getResource(String name, BeanContextChild bcc) throws IllegalArgumentException;
104
105 /**
106 * Adds the specified <code>BeanContextMembershipListener</code>
107 * to receive <code>BeanContextMembershipEvents</code> from
108 * this <code>BeanContext</code> whenever it adds
109 * or removes a child <code>Component</code>(s).
110 *
111 * @param bcml the <code>BeanContextMembershipListener</code> to be added
112 */
113 void addBeanContextMembershipListener(BeanContextMembershipListener bcml);
114
115 /**
116 * Removes the specified <code>BeanContextMembershipListener</code>
117 * so that it no longer receives <code>BeanContextMembershipEvent</code>s
118 * when the child <code>Component</code>(s) are added or removed.
119 *
120 * @param bcml the <code>BeanContextMembershipListener</code>
121 * to be removed
122 */
123 void removeBeanContextMembershipListener(BeanContextMembershipListener bcml);
124
125 /**
126 * This global lock is used by both <code>BeanContext</code>
127 * and <code>BeanContextServices</code> implementors
128 * to serialize changes in a <code>BeanContext</code>
129 * hierarchy and any service requests etc.
130 */
131 public static final Object globalHierarchyLock = new Object();
132}
java/pkg/java/beans/beancontext/BeanContextChild.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextChild.java+137−0
@@ -0,0 +1,137 @@
1/*
2 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.PropertyChangeListener;
29import java.beans.VetoableChangeListener;
30import java.beans.PropertyVetoException;
31
32import java.beans.beancontext.BeanContext;
33
34/**
35 * <p>
36 * JavaBeans wishing to be nested within, and obtain a reference to their
37 * execution environment, or context, as defined by the BeanContext
38 * sub-interface shall implement this interface.
39 * </p>
40 * <p>
41 * Conformant BeanContexts shall as a side effect of adding a BeanContextChild
42 * object shall pass a reference to itself via the setBeanContext() method of
43 * this interface.
44 * </p>
45 * <p>
46 * Note that a BeanContextChild may refuse a change in state by throwing
47 * PropertyVetoedException in response.
48 * </p>
49 * <p>
50 * In order for persistence mechanisms to function properly on BeanContextChild
51 * instances across a broad variety of scenarios, implementing classes of this
52 * interface are required to define as transient, any or all fields, or
53 * instance variables, that may contain, or represent, references to the
54 * nesting BeanContext instance or other resources obtained
55 * from the BeanContext via any unspecified mechanisms.
56 * </p>
57 *
58 * @author Laurence P. G. Cable
59 * @since 1.2
60 *
61 * @see java.beans.beancontext.BeanContext
62 * @see java.beans.PropertyChangeEvent
63 * @see java.beans.PropertyChangeListener
64 * @see java.beans.PropertyVetoException
65 * @see java.beans.VetoableChangeListener
66 */
67
68public interface BeanContextChild {
69
70 /**
71 * <p>
72 * Objects that implement this interface,
73 * shall fire a java.beans.PropertyChangeEvent, with parameters:
74 *
75 * propertyName "beanContext", oldValue (the previous nesting
76 * <code>BeanContext</code> instance, or <code>null</code>),
77 * newValue (the current nesting
78 * <code>BeanContext</code> instance, or <code>null</code>).
79 * <p>
80 * A change in the value of the nesting BeanContext property of this
81 * BeanContextChild may be vetoed by throwing the appropriate exception.
82 * </p>
83 * @param bc The <code>BeanContext</code> with which
84 * to associate this <code>BeanContextChild</code>.
85 * @throws <code>PropertyVetoException</code> if the
86 * addition of the specified <code>BeanContext</code> is refused.
87 */
88 void setBeanContext(BeanContext bc) throws PropertyVetoException;
89
90 /**
91 * Gets the <code>BeanContext</code> associated
92 * with this <code>BeanContextChild</code>.
93 * @return the <code>BeanContext</code> associated
94 * with this <code>BeanContextChild</code>.
95 */
96 BeanContext getBeanContext();
97
98 /**
99 * Adds a <code>PropertyChangeListener</code>
100 * to this <code>BeanContextChild</code>
101 * in order to receive a <code>PropertyChangeEvent</code>
102 * whenever the specified property has changed.
103 * @param name the name of the property to listen on
104 * @param pcl the <code>PropertyChangeListener</code> to add
105 */
106 void addPropertyChangeListener(String name, PropertyChangeListener pcl);
107
108 /**
109 * Removes a <code>PropertyChangeListener</code> from this
110 * <code>BeanContextChild</code> so that it no longer
111 * receives <code>PropertyChangeEvents</code> when the
112 * specified property is changed.
113 *
114 * @param name the name of the property that was listened on
115 * @param pcl the <code>PropertyChangeListener</code> to remove
116 */
117 void removePropertyChangeListener(String name, PropertyChangeListener pcl);
118
119 /**
120 * Adds a <code>VetoableChangeListener</code> to
121 * this <code>BeanContextChild</code>
122 * to receive events whenever the specified property changes.
123 * @param name the name of the property to listen on
124 * @param vcl the <code>VetoableChangeListener</code> to add
125 */
126 void addVetoableChangeListener(String name, VetoableChangeListener vcl);
127
128 /**
129 * Removes a <code>VetoableChangeListener</code> from this
130 * <code>BeanContextChild</code> so that it no longer receives
131 * events when the specified property changes.
132 * @param name the name of the property that was listened on.
133 * @param vcl the <code>VetoableChangeListener</code> to remove.
134 */
135 void removeVetoableChangeListener(String name, VetoableChangeListener vcl);
136
137}
java/pkg/java/beans/beancontext/BeanContextChildComponentProxy.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextChildComponentProxy.java+54−0
@@ -0,0 +1,54 @@
1/*
2 * Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.awt.Component;
29
30/**
31 * <p>
32 * This interface is implemented by
33 * <code>BeanContextChildren</code> that have an AWT <code>Component</code>
34 * associated with them.
35 * </p>
36 *
37 * @author Laurence P. G. Cable
38 * @since 1.2
39 *
40 * @see java.beans.beancontext.BeanContext
41 * @see java.beans.beancontext.BeanContextSupport
42 */
43
44public interface BeanContextChildComponentProxy {
45
46 /**
47 * Gets the <code>java.awt.Component</code> associated with
48 * this <code>BeanContextChild</code>.
49 * @return the AWT <code>Component</code> associated with
50 * this <code>BeanContextChild</code>
51 */
52
53 Component getComponent();
54}
java/pkg/java/beans/beancontext/BeanContextChildSupport.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextChildSupport.java+373−0
@@ -0,0 +1,373 @@
1/*
2 * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.PropertyChangeEvent;
29import java.beans.PropertyChangeListener;
30import java.beans.PropertyChangeSupport;
31
32import java.beans.VetoableChangeListener;
33import java.beans.VetoableChangeSupport;
34
35import java.beans.PropertyVetoException;
36
37import java.io.IOException;
38import java.io.ObjectInputStream;
39import java.io.ObjectOutputStream;
40import java.io.Serializable;
41
42/**
43 * <p>
44 * This is a general support class to provide support for implementing the
45 * BeanContextChild protocol.
46 *
47 * This class may either be directly subclassed, or encapsulated and delegated
48 * to in order to implement this interface for a given component.
49 * </p>
50 *
51 * @author Laurence P. G. Cable
52 * @since 1.2
53 *
54 * @see java.beans.beancontext.BeanContext
55 * @see java.beans.beancontext.BeanContextServices
56 * @see java.beans.beancontext.BeanContextChild
57 */
58
59public class BeanContextChildSupport implements BeanContextChild, BeanContextServicesListener, Serializable {
60
61 static final long serialVersionUID = 6328947014421475877L;
62
63 /**
64 * construct a BeanContextChildSupport where this class has been
65 * subclassed in order to implement the JavaBean component itself.
66 */
67
68 public BeanContextChildSupport() {
69 super();
70
71 beanContextChildPeer = this;
72
73 pcSupport = new PropertyChangeSupport(beanContextChildPeer);
74 vcSupport = new VetoableChangeSupport(beanContextChildPeer);
75 }
76
77 /**
78 * construct a BeanContextChildSupport where the JavaBean component
79 * itself implements BeanContextChild, and encapsulates this, delegating
80 * that interface to this implementation
81 */
82
83 public BeanContextChildSupport(BeanContextChild bcc) {
84 super();
85
86 beanContextChildPeer = (bcc != null) ? bcc : this;
87
88 pcSupport = new PropertyChangeSupport(beanContextChildPeer);
89 vcSupport = new VetoableChangeSupport(beanContextChildPeer);
90 }
91
92 /**
93 * Sets the <code>BeanContext</code> for
94 * this <code>BeanContextChildSupport</code>.
95 * @param bc the new value to be assigned to the <code>BeanContext</code>
96 * property
97 * @throws <code>PropertyVetoException</code> if the change is rejected
98 */
99 public synchronized void setBeanContext(BeanContext bc) throws PropertyVetoException {
100 if (bc == beanContext) return;
101
102 BeanContext oldValue = beanContext;
103 BeanContext newValue = bc;
104
105 if (!rejectedSetBCOnce) {
106 if (rejectedSetBCOnce = !validatePendingSetBeanContext(bc)) {
107 throw new PropertyVetoException(
108 "setBeanContext() change rejected:",
109 new PropertyChangeEvent(beanContextChildPeer, "beanContext", oldValue, newValue)
110 );
111 }
112
113 try {
114 fireVetoableChange("beanContext",
115 oldValue,
116 newValue
117 );
118 } catch (PropertyVetoException pve) {
119 rejectedSetBCOnce = true;
120
121 throw pve; // re-throw
122 }
123 }
124
125 if (beanContext != null) releaseBeanContextResources();
126
127 beanContext = newValue;
128 rejectedSetBCOnce = false;
129
130 firePropertyChange("beanContext",
131 oldValue,
132 newValue
133 );
134
135 if (beanContext != null) initializeBeanContextResources();
136 }
137
138 /**
139 * Gets the nesting <code>BeanContext</code>
140 * for this <code>BeanContextChildSupport</code>.
141 * @return the nesting <code>BeanContext</code> for
142 * this <code>BeanContextChildSupport</code>.
143 */
144 public synchronized BeanContext getBeanContext() { return beanContext; }
145
146 /**
147 * Add a PropertyChangeListener for a specific property.
148 * The same listener object may be added more than once. For each
149 * property, the listener will be invoked the number of times it was added
150 * for that property.
151 * If <code>name</code> or <code>pcl</code> is null, no exception is thrown
152 * and no action is taken.
153 *
154 * @param name The name of the property to listen on
155 * @param pcl The <code>PropertyChangeListener</code> to be added
156 */
157 public void addPropertyChangeListener(String name, PropertyChangeListener pcl) {
158 pcSupport.addPropertyChangeListener(name, pcl);
159 }
160
161 /**
162 * Remove a PropertyChangeListener for a specific property.
163 * If <code>pcl</code> was added more than once to the same event
164 * source for the specified property, it will be notified one less time
165 * after being removed.
166 * If <code>name</code> is null, no exception is thrown
167 * and no action is taken.
168 * If <code>pcl</code> is null, or was never added for the specified
169 * property, no exception is thrown and no action is taken.
170 *
171 * @param name The name of the property that was listened on
172 * @param pcl The PropertyChangeListener to be removed
173 */
174 public void removePropertyChangeListener(String name, PropertyChangeListener pcl) {
175 pcSupport.removePropertyChangeListener(name, pcl);
176 }
177
178 /**
179 * Add a VetoableChangeListener for a specific property.
180 * The same listener object may be added more than once. For each
181 * property, the listener will be invoked the number of times it was added
182 * for that property.
183 * If <code>name</code> or <code>vcl</code> is null, no exception is thrown
184 * and no action is taken.
185 *
186 * @param name The name of the property to listen on
187 * @param vcl The <code>VetoableChangeListener</code> to be added
188 */
189 public void addVetoableChangeListener(String name, VetoableChangeListener vcl) {
190 vcSupport.addVetoableChangeListener(name, vcl);
191 }
192
193 /**
194 * Removes a <code>VetoableChangeListener</code>.
195 * If <code>pcl</code> was added more than once to the same event
196 * source for the specified property, it will be notified one less time
197 * after being removed.
198 * If <code>name</code> is null, no exception is thrown
199 * and no action is taken.
200 * If <code>vcl</code> is null, or was never added for the specified
201 * property, no exception is thrown and no action is taken.
202 *
203 * @param name The name of the property that was listened on
204 * @param vcl The <code>VetoableChangeListener</code> to be removed
205 */
206 public void removeVetoableChangeListener(String name, VetoableChangeListener vcl) {
207 vcSupport.removeVetoableChangeListener(name, vcl);
208 }
209
210 /**
211 * A service provided by the nesting BeanContext has been revoked.
212 *
213 * Subclasses may override this method in order to implement their own
214 * behaviors.
215 * @param bcsre The <code>BeanContextServiceRevokedEvent</code> fired as a
216 * result of a service being revoked
217 */
218 public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) { }
219
220 /**
221 * A new service is available from the nesting BeanContext.
222 *
223 * Subclasses may override this method in order to implement their own
224 * behaviors
225 * @param bcsae The BeanContextServiceAvailableEvent fired as a
226 * result of a service becoming available
227 *
228 */
229 public void serviceAvailable(BeanContextServiceAvailableEvent bcsae) { }
230
231 /**
232 * Gets the <tt>BeanContextChild</tt> associated with this
233 * <tt>BeanContextChildSupport</tt>.
234 *
235 * @return the <tt>BeanContextChild</tt> peer of this class
236 */
237 public BeanContextChild getBeanContextChildPeer() { return beanContextChildPeer; }
238
239 /**
240 * Reports whether or not this class is a delegate of another.
241 *
242 * @return true if this class is a delegate of another
243 */
244 public boolean isDelegated() { return !this.equals(beanContextChildPeer); }
245
246 /**
247 * Report a bound property update to any registered listeners. No event is
248 * fired if old and new are equal and non-null.
249 * @param name The programmatic name of the property that was changed
250 * @param oldValue The old value of the property
251 * @param newValue The new value of the property
252 */
253 public void firePropertyChange(String name, Object oldValue, Object newValue) {
254 pcSupport.firePropertyChange(name, oldValue, newValue);
255 }
256
257 /**
258 * Report a vetoable property update to any registered listeners.
259 * If anyone vetos the change, then fire a new event
260 * reverting everyone to the old value and then rethrow
261 * the PropertyVetoException. <P>
262 *
263 * No event is fired if old and new are equal and non-null.
264 * <P>
265 * @param name The programmatic name of the property that is about to
266 * change
267 *
268 * @param oldValue The old value of the property
269 * @param newValue - The new value of the property
270 *
271 * @throws PropertyVetoException if the recipient wishes the property
272 * change to be rolled back.
273 */
274 public void fireVetoableChange(String name, Object oldValue, Object newValue) throws PropertyVetoException {
275 vcSupport.fireVetoableChange(name, oldValue, newValue);
276 }
277
278 /**
279 * Called from setBeanContext to validate (or otherwise) the
280 * pending change in the nesting BeanContext property value.
281 * Returning false will cause setBeanContext to throw
282 * PropertyVetoException.
283 * @param newValue the new value that has been requested for
284 * the BeanContext property
285 * @return <code>true</code> if the change operation is to be vetoed
286 */
287 public boolean validatePendingSetBeanContext(BeanContext newValue) {
288 return true;
289 }
290
291 /**
292 * This method may be overridden by subclasses to provide their own
293 * release behaviors. When invoked any resources held by this instance
294 * obtained from its current BeanContext property should be released
295 * since the object is no longer nested within that BeanContext.
296 */
297
298 protected void releaseBeanContextResources() {
299 // do nothing
300 }
301
302 /**
303 * This method may be overridden by subclasses to provide their own
304 * initialization behaviors. When invoked any resources requried by the
305 * BeanContextChild should be obtained from the current BeanContext.
306 */
307
308 protected void initializeBeanContextResources() {
309 // do nothing
310 }
311
312 /**
313 * Write the persistence state of the object.
314 */
315
316 private void writeObject(ObjectOutputStream oos) throws IOException {
317
318 /*
319 * dont serialize if we are delegated and the delegator isnt also
320 * serializable.
321 */
322
323 if (!equals(beanContextChildPeer) && !(beanContextChildPeer instanceof Serializable))
324 throw new IOException("BeanContextChildSupport beanContextChildPeer not Serializable");
325
326 else
327 oos.defaultWriteObject();
328
329 }
330
331
332 /**
333 * Restore a persistent object, must wait for subsequent setBeanContext()
334 * to fully restore any resources obtained from the new nesting
335 * BeanContext
336 */
337
338 private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
339 ois.defaultReadObject();
340 }
341
342 /*
343 * fields
344 */
345
346 /**
347 * The <code>BeanContext</code> in which
348 * this <code>BeanContextChild</code> is nested.
349 */
350 public BeanContextChild beanContextChildPeer;
351
352 /**
353 * The <tt>PropertyChangeSupport</tt> associated with this
354 * <tt>BeanContextChildSupport</tt>.
355 */
356 protected PropertyChangeSupport pcSupport;
357
358 /**
359 * The <tt>VetoableChangeSupport</tt> associated with this
360 * <tt>BeanContextChildSupport</tt>.
361 */
362 protected VetoableChangeSupport vcSupport;
363
364 protected transient BeanContext beanContext;
365
366 /**
367 * A flag indicating that there has been
368 * at least one <code>PropertyChangeVetoException</code>
369 * thrown for the attempted setBeanContext operation.
370 */
371 protected transient boolean rejectedSetBCOnce;
372
373}
java/pkg/java/beans/beancontext/BeanContextContainerProxy.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextContainerProxy.java+52−0
@@ -0,0 +1,52 @@
1/*
2 * Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.awt.Container;
29
30/**
31 * <p>
32 * This interface is implemented by BeanContexts' that have an AWT Container
33 * associated with them.
34 * </p>
35 *
36 * @author Laurence P. G. Cable
37 * @since 1.2
38 *
39 * @see java.beans.beancontext.BeanContext
40 * @see java.beans.beancontext.BeanContextSupport
41 */
42
43public interface BeanContextContainerProxy {
44
45 /**
46 * Gets the <code>java.awt.Container</code> associated
47 * with this <code>BeanContext</code>.
48 * @return the <code>java.awt.Container</code> associated
49 * with this <code>BeanContext</code>.
50 */
51 Container getContainer();
52}
java/pkg/java/beans/beancontext/BeanContextEvent.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextEvent.java+104−0
@@ -0,0 +1,104 @@
1/*
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.util.EventObject;
29
30import java.beans.beancontext.BeanContext;
31
32/**
33 * <p>
34 * <code>BeanContextEvent</code> is the abstract root event class
35 * for all events emitted
36 * from, and pertaining to the semantics of, a <code>BeanContext</code>.
37 * This class introduces a mechanism to allow the propagation of
38 * <code>BeanContextEvent</code> subclasses through a hierarchy of
39 * <code>BeanContext</code>s. The <code>setPropagatedFrom()</code>
40 * and <code>getPropagatedFrom()</code> methods allow a
41 * <code>BeanContext</code> to identify itself as the source
42 * of a propagated event.
43 * </p>
44 *
45 * @author Laurence P. G. Cable
46 * @since 1.2
47 * @see java.beans.beancontext.BeanContext
48 */
49
50public abstract class BeanContextEvent extends EventObject {
51 private static final long serialVersionUID = 7267998073569045052L;
52
53 /**
54 * Contruct a BeanContextEvent
55 *
56 * @param bc The BeanContext source
57 */
58 protected BeanContextEvent(BeanContext bc) {
59 super(bc);
60 }
61
62 /**
63 * Gets the <code>BeanContext</code> associated with this event.
64 * @return the <code>BeanContext</code> associated with this event.
65 */
66 public BeanContext getBeanContext() { return (BeanContext)getSource(); }
67
68 /**
69 * Sets the <code>BeanContext</code> from which this event was propagated.
70 * @param bc the <code>BeanContext</code> from which this event
71 * was propagated
72 */
73 public synchronized void setPropagatedFrom(BeanContext bc) {
74 propagatedFrom = bc;
75 }
76
77 /**
78 * Gets the <code>BeanContext</code> from which this event was propagated.
79 * @return the <code>BeanContext</code> from which this
80 * event was propagated
81 */
82 public synchronized BeanContext getPropagatedFrom() {
83 return propagatedFrom;
84 }
85
86 /**
87 * Reports whether or not this event is
88 * propagated from some other <code>BeanContext</code>.
89 * @return <code>true</code> if propagated, <code>false</code>
90 * if not
91 */
92 public synchronized boolean isPropagated() {
93 return propagatedFrom != null;
94 }
95
96 /*
97 * fields
98 */
99
100 /**
101 * The <code>BeanContext</code> from which this event was propagated
102 */
103 protected BeanContext propagatedFrom;
104}
java/pkg/java/beans/beancontext/BeanContextMembershipEvent.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextMembershipEvent.java+131−0
@@ -0,0 +1,131 @@
1/*
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.util.EventObject;
29
30import java.beans.beancontext.BeanContext;
31import java.beans.beancontext.BeanContextEvent;
32
33import java.util.Arrays;
34import java.util.Collection;
35import java.util.Iterator;
36
37/**
38 * A <code>BeanContextMembershipEvent</code> encapsulates
39 * the list of children added to, or removed from,
40 * the membership of a particular <code>BeanContext</code>.
41 * An instance of this event is fired whenever a successful
42 * add(), remove(), retainAll(), removeAll(), or clear() is
43 * invoked on a given <code>BeanContext</code> instance.
44 * Objects interested in receiving events of this type must
45 * implement the <code>BeanContextMembershipListener</code>
46 * interface, and must register their intent via the
47 * <code>BeanContext</code>'s
48 * <code>addBeanContextMembershipListener(BeanContextMembershipListener bcml)
49 * </code> method.
50 *
51 * @author Laurence P. G. Cable
52 * @since 1.2
53 * @see java.beans.beancontext.BeanContext
54 * @see java.beans.beancontext.BeanContextEvent
55 * @see java.beans.beancontext.BeanContextMembershipListener
56 */
57public class BeanContextMembershipEvent extends BeanContextEvent {
58 private static final long serialVersionUID = 3499346510334590959L;
59
60 /**
61 * Contruct a BeanContextMembershipEvent
62 *
63 * @param bc The BeanContext source
64 * @param changes The Children affected
65 * @throws NullPointerException if <CODE>changes</CODE> is <CODE>null</CODE>
66 */
67
68 public BeanContextMembershipEvent(BeanContext bc, Collection changes) {
69 super(bc);
70
71 if (changes == null) throw new NullPointerException(
72 "BeanContextMembershipEvent constructor: changes is null.");
73
74 children = changes;
75 }
76
77 /**
78 * Contruct a BeanContextMembershipEvent
79 *
80 * @param bc The BeanContext source
81 * @param changes The Children effected
82 * @exception NullPointerException if changes associated with this
83 * event are null.
84 */
85
86 public BeanContextMembershipEvent(BeanContext bc, Object[] changes) {
87 super(bc);
88
89 if (changes == null) throw new NullPointerException(
90 "BeanContextMembershipEvent: changes is null.");
91
92 children = Arrays.asList(changes);
93 }
94
95 /**
96 * Gets the number of children affected by the notification.
97 * @return the number of children affected by the notification
98 */
99 public int size() { return children.size(); }
100
101 /**
102 * Is the child specified affected by the event?
103 * @return <code>true</code> if affected, <code>false</code>
104 * if not
105 */
106 public boolean contains(Object child) {
107 return children.contains(child);
108 }
109
110 /**
111 * Gets the array of children affected by this event.
112 * @return the array of children affected
113 */
114 public Object[] toArray() { return children.toArray(); }
115
116 /**
117 * Gets the array of children affected by this event.
118 * @return the array of children effected
119 */
120 public Iterator iterator() { return children.iterator(); }
121
122 /*
123 * fields
124 */
125
126 /**
127 * The list of children affected by this
128 * event notification.
129 */
130 protected Collection children;
131}
java/pkg/java/beans/beancontext/BeanContextMembershipListener.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextMembershipListener.java+61−0
@@ -0,0 +1,61 @@
1/*
2 * Copyright (c) 1997, 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.beancontext.BeanContextMembershipEvent;
29
30import java.util.EventListener;
31
32/**
33 * <p>
34 * Compliant BeanContexts fire events on this interface when the state of
35 * the membership of the BeanContext changes.
36 * </p>
37 *
38 * @author Laurence P. G. Cable
39 * @since 1.2
40 * @see java.beans.beancontext.BeanContext
41 */
42
43public interface BeanContextMembershipListener extends EventListener {
44
45 /**
46 * Called when a child or list of children is added to a
47 * <code>BeanContext</code> that this listener is registered with.
48 * @param bcme The <code>BeanContextMembershipEvent</code>
49 * describing the change that occurred.
50 */
51 void childrenAdded(BeanContextMembershipEvent bcme);
52
53 /**
54 * Called when a child or list of children is removed
55 * from a <code>BeanContext</code> that this listener
56 * is registered with.
57 * @param bcme The <code>BeanContextMembershipEvent</code>
58 * describing the change that occurred.
59 */
60 void childrenRemoved(BeanContextMembershipEvent bcme);
61}
java/pkg/java/beans/beancontext/BeanContextProxy.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextProxy.java+85−0
@@ -0,0 +1,85 @@
1/*
2 * Copyright (c) 1998, 2002, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28/**
29 * <p>
30 * This interface is implemented by a JavaBean that does
31 * not directly have a BeanContext(Child) associated with
32 * it (via implementing that interface or a subinterface thereof),
33 * but has a public BeanContext(Child) delegated from it.
34 * For example, a subclass of java.awt.Container may have a BeanContext
35 * associated with it that all Component children of that Container shall
36 * be contained within.
37 * </p>
38 * <p>
39 * An Object may not implement this interface and the
40 * BeanContextChild interface
41 * (or any subinterfaces thereof) they are mutually exclusive.
42 * </p>
43 * <p>
44 * Callers of this interface shall examine the return type in order to
45 * obtain a particular subinterface of BeanContextChild as follows:
46 * <code>
47 * BeanContextChild bcc = o.getBeanContextProxy();
48 *
49 * if (bcc instanceof BeanContext) {
50 * // ...
51 * }
52 * </code>
53 * or
54 * <code>
55 * BeanContextChild bcc = o.getBeanContextProxy();
56 * BeanContext bc = null;
57 *
58 * try {
59 * bc = (BeanContext)bcc;
60 * } catch (ClassCastException cce) {
61 * // cast failed, bcc is not an instanceof BeanContext
62 * }
63 * </code>
64 * </p>
65 * <p>
66 * The return value is a constant for the lifetime of the implementing
67 * instance
68 * </p>
69 * @author Laurence P. G. Cable
70 * @since 1.2
71 *
72 * @see java.beans.beancontext.BeanContextChild
73 * @see java.beans.beancontext.BeanContextChildSupport
74 */
75
76public interface BeanContextProxy {
77
78 /**
79 * Gets the <code>BeanContextChild</code> (or subinterface)
80 * associated with this object.
81 * @return the <code>BeanContextChild</code> (or subinterface)
82 * associated with this object
83 */
84 BeanContextChild getBeanContextProxy();
85}
java/pkg/java/beans/beancontext/BeanContextServiceAvailableEvent.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServiceAvailableEvent.java+86−0
@@ -0,0 +1,86 @@
1/*
2 * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.beancontext.BeanContextChild;
29import java.beans.beancontext.BeanContextEvent;
30
31import java.beans.beancontext.BeanContextServices;
32
33import java.util.Iterator;
34
35/**
36 * <p>
37 * This event type is used by the BeanContextServicesListener in order to
38 * identify the service being registered.
39 * </p>
40 */
41
42public class BeanContextServiceAvailableEvent extends BeanContextEvent {
43 private static final long serialVersionUID = -5333985775656400778L;
44
45 /**
46 * Construct a <code>BeanContextAvailableServiceEvent</code>.
47 * @param bcs The context in which the service has become available
48 * @param sc A <code>Class</code> reference to the newly available service
49 */
50 public BeanContextServiceAvailableEvent(BeanContextServices bcs, Class sc) {
51 super((BeanContext)bcs);
52
53 serviceClass = sc;
54 }
55
56 /**
57 * Gets the source as a reference of type <code>BeanContextServices</code>.
58 * @return The context in which the service has become available
59 */
60 public BeanContextServices getSourceAsBeanContextServices() {
61 return (BeanContextServices)getBeanContext();
62 }
63
64 /**
65 * Gets the service class that is the subject of this notification.
66 * @return A <code>Class</code> reference to the newly available service
67 */
68 public Class getServiceClass() { return serviceClass; }
69
70 /**
71 * Gets the list of service dependent selectors.
72 * @return the current selectors available from the service
73 */
74 public Iterator getCurrentServiceSelectors() {
75 return ((BeanContextServices)getSource()).getCurrentServiceSelectors(serviceClass);
76 }
77
78 /*
79 * fields
80 */
81
82 /**
83 * A <code>Class</code> reference to the newly available service
84 */
85 protected Class serviceClass;
86}
java/pkg/java/beans/beancontext/BeanContextServiceProvider.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServiceProvider.java+104−0
@@ -0,0 +1,104 @@
1/*
2 * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.util.Iterator;
29
30/**
31 * <p>
32 * One of the primary functions of a BeanContext is to act a as rendezvous
33 * between JavaBeans, and BeanContextServiceProviders.
34 * </p>
35 * <p>
36 * A JavaBean nested within a BeanContext, may ask that BeanContext to
37 * provide an instance of a "service", based upon a reference to a Java
38 * Class object that represents that service.
39 * </p>
40 * <p>
41 * If such a service has been registered with the context, or one of its
42 * nesting context's, in the case where a context delegate to its context
43 * to satisfy a service request, then the BeanContextServiceProvider associated with
44 * the service is asked to provide an instance of that service.
45 * </p>
46 * <p>
47 * The ServcieProvider may always return the same instance, or it may
48 * construct a new instance for each request.
49 * </p>
50 */
51
52public interface BeanContextServiceProvider {
53
54 /**
55 * Invoked by <code>BeanContextServices</code>, this method
56 * requests an instance of a
57 * service from this <code>BeanContextServiceProvider</code>.
58 *
59 * @param bcs The <code>BeanContextServices</code> associated with this
60 * particular request. This parameter enables the
61 * <code>BeanContextServiceProvider</code> to distinguish service
62 * requests from multiple sources.
63 *
64 * @param requestor The object requesting the service
65 *
66 * @param serviceClass The service requested
67 *
68 * @param serviceSelector the service dependent parameter
69 * for a particular service, or <code>null</code> if not applicable.
70 *
71 * @return a reference to the requested service
72 */
73 Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector);
74
75 /**
76 * Invoked by <code>BeanContextServices</code>,
77 * this method releases a nested <code>BeanContextChild</code>'s
78 * (or any arbitrary object associated with a
79 * <code>BeanContextChild</code>) reference to the specified service.
80 *
81 * @param bcs the <code>BeanContextServices</code> associated with this
82 * particular release request
83 *
84 * @param requestor the object requesting the service to be released
85 *
86 * @param service the service that is to be released
87 */
88 public void releaseService(BeanContextServices bcs, Object requestor, Object service);
89
90 /**
91 * Invoked by <code>BeanContextServices</code>, this method
92 * gets the current service selectors for the specified service.
93 * A service selector is a service specific parameter,
94 * typical examples of which could include: a
95 * parameter to a constructor for the service implementation class,
96 * a value for a particular service's property, or a key into a
97 * map of existing implementations.
98 *
99 * @param bcs the <code>BeanContextServices</code> for this request
100 * @param serviceClass the specified service
101 * @return the current service selectors for the specified serviceClass
102 */
103 Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass);
104}
java/pkg/java/beans/beancontext/BeanContextServiceProviderBeanInfo.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServiceProviderBeanInfo.java+47−0
@@ -0,0 +1,47 @@
1/*
2 * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.BeanInfo;
29
30/**
31 * A BeanContextServiceProvider implementor who wishes to provide explicit
32 * information about the services their bean may provide shall implement a
33 * BeanInfo class that implements this BeanInfo subinterface and provides
34 * explicit information about the methods, properties, events, etc, of their
35 * services.
36 */
37
38public interface BeanContextServiceProviderBeanInfo extends BeanInfo {
39
40 /**
41 * Gets a <code>BeanInfo</code> array, one for each
42 * service class or interface statically available
43 * from this ServiceProvider.
44 * @return the <code>BeanInfo</code> array
45 */
46 BeanInfo[] getServicesBeanInfo();
47}
java/pkg/java/beans/beancontext/BeanContextServiceRevokedEvent.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServiceRevokedEvent.java+99−0
@@ -0,0 +1,99 @@
1/*
2 * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.beancontext.BeanContextEvent;
29
30import java.beans.beancontext.BeanContextServices;
31
32/**
33 * <p>
34 * This event type is used by the
35 * <code>BeanContextServiceRevokedListener</code> in order to
36 * identify the service being revoked.
37 * </p>
38 */
39public class BeanContextServiceRevokedEvent extends BeanContextEvent {
40 private static final long serialVersionUID = -1295543154724961754L;
41
42 /**
43 * Construct a <code>BeanContextServiceEvent</code>.
44 * @param bcs the <code>BeanContextServices</code>
45 * from which this service is being revoked
46 * @param sc the service that is being revoked
47 * @param invalidate <code>true</code> for immediate revocation
48 */
49 public BeanContextServiceRevokedEvent(BeanContextServices bcs, Class sc, boolean invalidate) {
50 super((BeanContext)bcs);
51
52 serviceClass = sc;
53 invalidateRefs = invalidate;
54 }
55
56 /**
57 * Gets the source as a reference of type <code>BeanContextServices</code>
58 * @return the <code>BeanContextServices</code> from which
59 * this service is being revoked
60 */
61 public BeanContextServices getSourceAsBeanContextServices() {
62 return (BeanContextServices)getBeanContext();
63 }
64
65 /**
66 * Gets the service class that is the subject of this notification
67 * @return A <code>Class</code> reference to the
68 * service that is being revoked
69 */
70 public Class getServiceClass() { return serviceClass; }
71
72 /**
73 * Checks this event to determine whether or not
74 * the service being revoked is of a particular class.
75 * @param service the service of interest (should be non-null)
76 * @return <code>true</code> if the service being revoked is of the
77 * same class as the specified service
78 */
79 public boolean isServiceClass(Class service) {
80 return serviceClass.equals(service);
81 }
82
83 /**
84 * Reports if the current service is being forcibly revoked,
85 * in which case the references are now invalidated and unusable.
86 * @return <code>true</code> if current service is being forcibly revoked
87 */
88 public boolean isCurrentServiceInvalidNow() { return invalidateRefs; }
89
90 /**
91 * fields
92 */
93
94 /**
95 * A <code>Class</code> reference to the service that is being revoked.
96 */
97 protected Class serviceClass;
98 private boolean invalidateRefs;
99}
java/pkg/java/beans/beancontext/BeanContextServiceRevokedListener.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServiceRevokedListener.java+46−0
@@ -0,0 +1,46 @@
1/*
2 * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25package java.beans.beancontext;
26
27import java.beans.beancontext.BeanContextServiceRevokedEvent;
28
29import java.util.EventListener;
30
31/**
32 * The listener interface for receiving
33 * <code>BeanContextServiceRevokedEvent</code> objects. A class that is
34 * interested in processing a <code>BeanContextServiceRevokedEvent</code>
35 * implements this interface.
36 */
37public interface BeanContextServiceRevokedListener extends EventListener {
38
39 /**
40 * The service named has been revoked. getService requests for
41 * this service will no longer be satisifed.
42 * @param bcsre the <code>BeanContextServiceRevokedEvent</code> received
43 * by this listener.
44 */
45 void serviceRevoked(BeanContextServiceRevokedEvent bcsre);
46}
java/pkg/java/beans/beancontext/BeanContextServices.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServices.java+159−0
@@ -0,0 +1,159 @@
1/*
2 * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.util.Iterator;
29
30import java.util.TooManyListenersException;
31
32import java.beans.beancontext.BeanContext;
33
34import java.beans.beancontext.BeanContextServiceProvider;
35
36import java.beans.beancontext.BeanContextServicesListener;
37
38
39/**
40 * <p>
41 * The BeanContextServices interface provides a mechanism for a BeanContext
42 * to expose generic "services" to the BeanContextChild objects within.
43 * </p>
44 */
45public interface BeanContextServices extends BeanContext, BeanContextServicesListener {
46
47 /**
48 * Adds a service to this BeanContext.
49 * <code>BeanContextServiceProvider</code>s call this method
50 * to register a particular service with this context.
51 * If the service has not previously been added, the
52 * <code>BeanContextServices</code> associates
53 * the service with the <code>BeanContextServiceProvider</code> and
54 * fires a <code>BeanContextServiceAvailableEvent</code> to all
55 * currently registered <code>BeanContextServicesListeners</code>.
56 * The method then returns <code>true</code>, indicating that
57 * the addition of the service was successful.
58 * If the given service has already been added, this method
59 * simply returns <code>false</code>.
60 * @param serviceClass the service to add
61 * @param serviceProvider the <code>BeanContextServiceProvider</code>
62 * associated with the service
63 */
64 boolean addService(Class serviceClass, BeanContextServiceProvider serviceProvider);
65
66 /**
67 * BeanContextServiceProviders wishing to remove
68 * a currently registered service from this context
69 * may do so via invocation of this method. Upon revocation of
70 * the service, the <code>BeanContextServices</code> fires a
71 * <code>BeanContextServiceRevokedEvent</code> to its
72 * list of currently registered
73 * <code>BeanContextServiceRevokedListeners</code> and
74 * <code>BeanContextServicesListeners</code>.
75 * @param serviceClass the service to revoke from this BeanContextServices
76 * @param serviceProvider the BeanContextServiceProvider associated with
77 * this particular service that is being revoked
78 * @param revokeCurrentServicesNow a value of <code>true</code>
79 * indicates an exceptional circumstance where the
80 * <code>BeanContextServiceProvider</code> or
81 * <code>BeanContextServices</code> wishes to immediately
82 * terminate service to all currently outstanding references
83 * to the specified service.
84 */
85 void revokeService(Class serviceClass, BeanContextServiceProvider serviceProvider, boolean revokeCurrentServicesNow);
86
87 /**
88 * Reports whether or not a given service is
89 * currently available from this context.
90 * @param serviceClass the service in question
91 * @return true if the service is available
92 */
93 boolean hasService(Class serviceClass);
94
95 /**
96 * A <code>BeanContextChild</code>, or any arbitrary object
97 * associated with a <code>BeanContextChild</code>, may obtain
98 * a reference to a currently registered service from its
99 * nesting <code>BeanContextServices</code>
100 * via invocation of this method. When invoked, this method
101 * gets the service by calling the getService() method on the
102 * underlying <code>BeanContextServiceProvider</code>.
103 * @param child the <code>BeanContextChild</code>
104 * associated with this request
105 * @param requestor the object requesting the service
106 * @param serviceClass class of the requested service
107 * @param serviceSelector the service dependent parameter
108 * @param bcsrl the
109 * <code>BeanContextServiceRevokedListener</code> to notify
110 * if the service should later become revoked
111 * @throws TooManyListenersException
112 * @return a reference to this context's named
113 * Service as requested or <code>null</code>
114 */
115 Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException;
116
117 /**
118 * Releases a <code>BeanContextChild</code>'s
119 * (or any arbitrary object associated with a BeanContextChild)
120 * reference to the specified service by calling releaseService()
121 * on the underlying <code>BeanContextServiceProvider</code>.
122 * @param child the <code>BeanContextChild</code>
123 * @param requestor the requestor
124 * @param service the service
125 */
126 void releaseService(BeanContextChild child, Object requestor, Object service);
127
128 /**
129 * Gets the currently available services for this context.
130 * @return an <code>Iterator</code> consisting of the
131 * currently available services
132 */
133 Iterator getCurrentServiceClasses();
134
135 /**
136 * Gets the list of service dependent service parameters
137 * (Service Selectors) for the specified service, by
138 * calling getCurrentServiceSelectors() on the
139 * underlying BeanContextServiceProvider.
140 * @param serviceClass the specified service
141 * @return the currently available service selectors
142 * for the named serviceClass
143 */
144 Iterator getCurrentServiceSelectors(Class serviceClass);
145
146 /**
147 * Adds a <code>BeanContextServicesListener</code> to this BeanContext
148 * @param bcsl the <code>BeanContextServicesListener</code> to add
149 */
150 void addBeanContextServicesListener(BeanContextServicesListener bcsl);
151
152 /**
153 * Removes a <code>BeanContextServicesListener</code>
154 * from this <code>BeanContext</code>
155 * @param bcsl the <code>BeanContextServicesListener</code>
156 * to remove from this context
157 */
158 void removeBeanContextServicesListener(BeanContextServicesListener bcsl);
159}
java/pkg/java/beans/beancontext/BeanContextServicesListener.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServicesListener.java+46−0
@@ -0,0 +1,46 @@
1/*
2 * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.beans.beancontext.BeanContextServiceAvailableEvent;
29import java.beans.beancontext.BeanContextServiceRevokedEvent;
30import java.beans.beancontext.BeanContextServiceRevokedListener;
31
32/**
33 * The listener interface for receiving
34 * <code>BeanContextServiceAvailableEvent</code> objects.
35 * A class that is interested in processing a
36 * <code>BeanContextServiceAvailableEvent</code> implements this interface.
37 */
38public interface BeanContextServicesListener extends BeanContextServiceRevokedListener {
39
40 /**
41 * The service named has been registered. getService requests for
42 * this service may now be made.
43 * @param bcsae the <code>BeanContextServiceAvailableEvent</code>
44 */
45 void serviceAvailable(BeanContextServiceAvailableEvent bcsae);
46}
java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSChild$BCSSCServiceClassRef.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSChild$BCSSCServiceRef.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSChild.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSProxyServiceProvider.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServicesSupport$BCSSServiceProvider.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServicesSupport.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextServicesSupport.java+1238−0
@@ -0,0 +1,1238 @@
1/*
2 * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.util.ArrayList;
29import java.util.Collection;
30import java.util.HashMap;
31import java.util.HashSet;
32import java.util.Iterator;
33import java.util.Map;
34import java.util.Map.Entry;
35
36import java.io.IOException;
37import java.io.ObjectInputStream;
38import java.io.ObjectOutputStream;
39import java.io.Serializable;
40
41import java.util.TooManyListenersException;
42
43import java.util.Locale;
44
45/**
46 * <p>
47 * This helper class provides a utility implementation of the
48 * java.beans.beancontext.BeanContextServices interface.
49 * </p>
50 * <p>
51 * Since this class directly implements the BeanContextServices interface,
52 * the class can, and is intended to be used either by subclassing this
53 * implementation, or via delegation of an instance of this class
54 * from another through the BeanContextProxy interface.
55 * </p>
56 *
57 * @author Laurence P. G. Cable
58 * @since 1.2
59 */
60
61public class BeanContextServicesSupport extends BeanContextSupport
62 implements BeanContextServices {
63 private static final long serialVersionUID = -8494482757288719206L;
64
65 /**
66 * <p>
67 * Construct a BeanContextServicesSupport instance
68 * </p>
69 *
70 * @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
71 * @param lcle The current Locale for this BeanContext.
72 * @param dTime The initial state, true if in design mode, false if runtime.
73 * @param visible The initial visibility.
74 *
75 */
76
77 public BeanContextServicesSupport(BeanContextServices peer, Locale lcle, boolean dTime, boolean visible) {
78 super(peer, lcle, dTime, visible);
79 }
80
81 /**
82 * Create an instance using the specified Locale and design mode.
83 *
84 * @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
85 * @param lcle The current Locale for this BeanContext.
86 * @param dtime The initial state, true if in design mode, false if runtime.
87 */
88
89 public BeanContextServicesSupport(BeanContextServices peer, Locale lcle, boolean dtime) {
90 this (peer, lcle, dtime, true);
91 }
92
93 /**
94 * Create an instance using the specified locale
95 *
96 * @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
97 * @param lcle The current Locale for this BeanContext.
98 */
99
100 public BeanContextServicesSupport(BeanContextServices peer, Locale lcle) {
101 this (peer, lcle, false, true);
102 }
103
104 /**
105 * Create an instance with a peer
106 *
107 * @param peer The peer BeanContext we are supplying an implementation for, if null the this object is its own peer
108 */
109
110 public BeanContextServicesSupport(BeanContextServices peer) {
111 this (peer, null, false, true);
112 }
113
114 /**
115 * Create an instance that is not a delegate of another object
116 */
117
118 public BeanContextServicesSupport() {
119 this (null, null, false, true);
120 }
121
122 /**
123 * called by BeanContextSupport superclass during construction and
124 * deserialization to initialize subclass transient state.
125 *
126 * subclasses may envelope this method, but should not override it or
127 * call it directly.
128 */
129
130 public void initialize() {
131 super.initialize();
132
133 services = new HashMap(serializable + 1);
134 bcsListeners = new ArrayList(1);
135 }
136
137 /**
138 * Gets the <tt>BeanContextServices</tt> associated with this
139 * <tt>BeanContextServicesSupport</tt>.
140 *
141 * @return the instance of <tt>BeanContext</tt>
142 * this object is providing the implementation for.
143 */
144 public BeanContextServices getBeanContextServicesPeer() {
145 return (BeanContextServices)getBeanContextChildPeer();
146 }
147
148 /************************************************************************/
149
150 /*
151 * protected nested class containing per child information, an instance
152 * of which is associated with each child in the "children" hashtable.
153 * subclasses can extend this class to include their own per-child state.
154 *
155 * Note that this 'value' is serialized with the corresponding child 'key'
156 * when the BeanContextSupport is serialized.
157 */
158
159 protected class BCSSChild extends BeanContextSupport.BCSChild {
160
161 private static final long serialVersionUID = -3263851306889194873L;
162
163 /*
164 * private nested class to map serviceClass to Provider and requestors
165 * listeners.
166 */
167
168 class BCSSCServiceClassRef {
169
170 // create an instance of a service ref
171
172 BCSSCServiceClassRef(Class sc, BeanContextServiceProvider bcsp, boolean delegated) {
173 super();
174
175 serviceClass = sc;
176
177 if (delegated)
178 delegateProvider = bcsp;
179 else
180 serviceProvider = bcsp;
181 }
182
183 // add a requestor and assoc listener
184
185 void addRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
186 BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
187
188 if (cbcsrl != null && !cbcsrl.equals(bcsrl))
189 throw new TooManyListenersException();
190
191 requestors.put(requestor, bcsrl);
192 }
193
194 // remove a requestor
195
196 void removeRequestor(Object requestor) {
197 requestors.remove(requestor);
198 }
199
200 // check a requestors listener
201
202 void verifyRequestor(Object requestor, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
203 BeanContextServiceRevokedListener cbcsrl = (BeanContextServiceRevokedListener)requestors.get(requestor);
204
205 if (cbcsrl != null && !cbcsrl.equals(bcsrl))
206 throw new TooManyListenersException();
207 }
208
209 void verifyAndMaybeSetProvider(BeanContextServiceProvider bcsp, boolean isDelegated) {
210 BeanContextServiceProvider current;
211
212 if (isDelegated) { // the provider is delegated
213 current = delegateProvider;
214
215 if (current == null || bcsp == null) {
216 delegateProvider = bcsp;
217 return;
218 }
219 } else { // the provider is registered with this BCS
220 current = serviceProvider;
221
222 if (current == null || bcsp == null) {
223 serviceProvider = bcsp;
224 return;
225 }
226 }
227
228 if (!current.equals(bcsp))
229 throw new UnsupportedOperationException("existing service reference obtained from different BeanContextServiceProvider not supported");
230
231 }
232
233 Iterator cloneOfEntries() {
234 return ((HashMap)requestors.clone()).entrySet().iterator();
235 }
236
237 Iterator entries() { return requestors.entrySet().iterator(); }
238
239 boolean isEmpty() { return requestors.isEmpty(); }
240
241 Class getServiceClass() { return serviceClass; }
242
243 BeanContextServiceProvider getServiceProvider() {
244 return serviceProvider;
245 }
246
247 BeanContextServiceProvider getDelegateProvider() {
248 return delegateProvider;
249 }
250
251 boolean isDelegated() { return delegateProvider != null; }
252
253 void addRef(boolean delegated) {
254 if (delegated) {
255 delegateRefs++;
256 } else {
257 serviceRefs++;
258 }
259 }
260
261
262 void releaseRef(boolean delegated) {
263 if (delegated) {
264 if (--delegateRefs == 0) {
265 delegateProvider = null;
266 }
267 } else {
268 if (--serviceRefs <= 0) {
269 serviceProvider = null;
270 }
271 }
272 }
273
274 int getRefs() { return serviceRefs + delegateRefs; }
275
276 int getDelegateRefs() { return delegateRefs; }
277
278 int getServiceRefs() { return serviceRefs; }
279
280 /*
281 * fields
282 */
283
284 Class serviceClass;
285
286 BeanContextServiceProvider serviceProvider;
287 int serviceRefs;
288
289 BeanContextServiceProvider delegateProvider; // proxy
290 int delegateRefs;
291
292 HashMap requestors = new HashMap(1);
293 }
294
295 /*
296 * per service reference info ...
297 */
298
299 class BCSSCServiceRef {
300 BCSSCServiceRef(BCSSCServiceClassRef scref, boolean isDelegated) {
301 serviceClassRef = scref;
302 delegated = isDelegated;
303 }
304
305 void addRef() { refCnt++; }
306 int release() { return --refCnt; }
307
308 BCSSCServiceClassRef getServiceClassRef() { return serviceClassRef; }
309
310 boolean isDelegated() { return delegated; }
311
312 /*
313 * fields
314 */
315
316 BCSSCServiceClassRef serviceClassRef;
317 int refCnt = 1;
318 boolean delegated = false;
319 }
320
321 BCSSChild(Object bcc, Object peer) { super(bcc, peer); }
322
323 // note usage of service per requestor, per service
324
325 synchronized void usingService(Object requestor, Object service, Class serviceClass, BeanContextServiceProvider bcsp, boolean isDelegated, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException, UnsupportedOperationException {
326
327 // first, process mapping from serviceClass to requestor(s)
328
329 BCSSCServiceClassRef serviceClassRef = null;
330
331 if (serviceClasses == null)
332 serviceClasses = new HashMap(1);
333 else
334 serviceClassRef = (BCSSCServiceClassRef)serviceClasses.get(serviceClass);
335
336 if (serviceClassRef == null) { // new service being used ...
337 serviceClassRef = new BCSSCServiceClassRef(serviceClass, bcsp, isDelegated);
338 serviceClasses.put(serviceClass, serviceClassRef);
339
340 } else { // existing service ...
341 serviceClassRef.verifyAndMaybeSetProvider(bcsp, isDelegated); // throws
342 serviceClassRef.verifyRequestor(requestor, bcsrl); // throws
343 }
344
345 serviceClassRef.addRequestor(requestor, bcsrl);
346 serviceClassRef.addRef(isDelegated);
347
348 // now handle mapping from requestor to service(s)
349
350 BCSSCServiceRef serviceRef = null;
351 Map services = null;
352
353 if (serviceRequestors == null) {
354 serviceRequestors = new HashMap(1);
355 } else {
356 services = (Map)serviceRequestors.get(requestor);
357 }
358
359 if (services == null) {
360 services = new HashMap(1);
361
362 serviceRequestors.put(requestor, services);
363 } else
364 serviceRef = (BCSSCServiceRef)services.get(service);
365
366 if (serviceRef == null) {
367 serviceRef = new BCSSCServiceRef(serviceClassRef, isDelegated);
368
369 services.put(service, serviceRef);
370 } else {
371 serviceRef.addRef();
372 }
373 }
374
375 // release a service reference
376
377 synchronized void releaseService(Object requestor, Object service) {
378 if (serviceRequestors == null) return;
379
380 Map services = (Map)serviceRequestors.get(requestor);
381
382 if (services == null) return; // oops its not there anymore!
383
384 BCSSCServiceRef serviceRef = (BCSSCServiceRef)services.get(service);
385
386 if (serviceRef == null) return; // oops its not there anymore!
387
388 BCSSCServiceClassRef serviceClassRef = serviceRef.getServiceClassRef();
389 boolean isDelegated = serviceRef.isDelegated();
390 BeanContextServiceProvider bcsp = isDelegated ? serviceClassRef.getDelegateProvider() : serviceClassRef.getServiceProvider();
391
392 bcsp.releaseService(BeanContextServicesSupport.this.getBeanContextServicesPeer(), requestor, service);
393
394 serviceClassRef.releaseRef(isDelegated);
395 serviceClassRef.removeRequestor(requestor);
396
397 if (serviceRef.release() == 0) {
398
399 services.remove(service);
400
401 if (services.isEmpty()) {
402 serviceRequestors.remove(requestor);
403 serviceClassRef.removeRequestor(requestor);
404 }
405
406 if (serviceRequestors.isEmpty()) {
407 serviceRequestors = null;
408 }
409
410 if (serviceClassRef.isEmpty()) {
411 serviceClasses.remove(serviceClassRef.getServiceClass());
412 }
413
414 if (serviceClasses.isEmpty())
415 serviceClasses = null;
416 }
417 }
418
419 // revoke a service
420
421 synchronized void revokeService(Class serviceClass, boolean isDelegated, boolean revokeNow) {
422 if (serviceClasses == null) return;
423
424 BCSSCServiceClassRef serviceClassRef = (BCSSCServiceClassRef)serviceClasses.get(serviceClass);
425
426 if (serviceClassRef == null) return;
427
428 Iterator i = serviceClassRef.cloneOfEntries();
429
430 BeanContextServiceRevokedEvent bcsre = new BeanContextServiceRevokedEvent(BeanContextServicesSupport.this.getBeanContextServicesPeer(), serviceClass, revokeNow);
431 boolean noMoreRefs = false;
432
433 while (i.hasNext() && serviceRequestors != null) {
434 Map.Entry entry = (Map.Entry)i.next();
435 BeanContextServiceRevokedListener listener = (BeanContextServiceRevokedListener)entry.getValue();
436
437 if (revokeNow) {
438 Object requestor = entry.getKey();
439 Map services = (Map)serviceRequestors.get(requestor);
440
441 if (services != null) {
442 Iterator i1 = services.entrySet().iterator();
443
444 while (i1.hasNext()) {
445 Map.Entry tmp = (Map.Entry)i1.next();
446
447 BCSSCServiceRef serviceRef = (BCSSCServiceRef)tmp.getValue();
448 if (serviceRef.getServiceClassRef().equals(serviceClassRef) && isDelegated == serviceRef.isDelegated()) {
449 i1.remove();
450 }
451 }
452
453 if (noMoreRefs = services.isEmpty()) {
454 serviceRequestors.remove(requestor);
455 }
456 }
457
458 if (noMoreRefs) serviceClassRef.removeRequestor(requestor);
459 }
460
461 listener.serviceRevoked(bcsre);
462 }
463
464 if (revokeNow && serviceClasses != null) {
465 if (serviceClassRef.isEmpty())
466 serviceClasses.remove(serviceClass);
467
468 if (serviceClasses.isEmpty())
469 serviceClasses = null;
470 }
471
472 if (serviceRequestors != null && serviceRequestors.isEmpty())
473 serviceRequestors = null;
474 }
475
476 // release all references for this child since it has been unnested.
477
478 void cleanupReferences() {
479
480 if (serviceRequestors == null) return;
481
482 Iterator requestors = serviceRequestors.entrySet().iterator();
483
484 while(requestors.hasNext()) {
485 Map.Entry tmp = (Map.Entry)requestors.next();
486 Object requestor = tmp.getKey();
487 Iterator services = ((Map)tmp.getValue()).entrySet().iterator();
488
489 requestors.remove();
490
491 while (services.hasNext()) {
492 Map.Entry entry = (Map.Entry)services.next();
493 Object service = entry.getKey();
494 BCSSCServiceRef sref = (BCSSCServiceRef)entry.getValue();
495
496 BCSSCServiceClassRef scref = sref.getServiceClassRef();
497
498 BeanContextServiceProvider bcsp = sref.isDelegated() ? scref.getDelegateProvider() : scref.getServiceProvider();
499
500 scref.removeRequestor(requestor);
501 services.remove();
502
503 while (sref.release() >= 0) {
504 bcsp.releaseService(BeanContextServicesSupport.this.getBeanContextServicesPeer(), requestor, service);
505 }
506 }
507 }
508
509 serviceRequestors = null;
510 serviceClasses = null;
511 }
512
513 void revokeAllDelegatedServicesNow() {
514 if (serviceClasses == null) return;
515
516 Iterator serviceClassRefs =
517 new HashSet(serviceClasses.values()).iterator();
518
519 while (serviceClassRefs.hasNext()) {
520 BCSSCServiceClassRef serviceClassRef = (BCSSCServiceClassRef)serviceClassRefs.next();
521
522 if (!serviceClassRef.isDelegated()) continue;
523
524 Iterator i = serviceClassRef.cloneOfEntries();
525 BeanContextServiceRevokedEvent bcsre = new BeanContextServiceRevokedEvent(BeanContextServicesSupport.this.getBeanContextServicesPeer(), serviceClassRef.getServiceClass(), true);
526 boolean noMoreRefs = false;
527
528 while (i.hasNext()) {
529 Map.Entry entry = (Map.Entry)i.next();
530 BeanContextServiceRevokedListener listener = (BeanContextServiceRevokedListener)entry.getValue();
531
532 Object requestor = entry.getKey();
533 Map services = (Map)serviceRequestors.get(requestor);
534
535 if (services != null) {
536 Iterator i1 = services.entrySet().iterator();
537
538 while (i1.hasNext()) {
539 Map.Entry tmp = (Map.Entry)i1.next();
540
541 BCSSCServiceRef serviceRef = (BCSSCServiceRef)tmp.getValue();
542 if (serviceRef.getServiceClassRef().equals(serviceClassRef) && serviceRef.isDelegated()) {
543 i1.remove();
544 }
545 }
546
547 if (noMoreRefs = services.isEmpty()) {
548 serviceRequestors.remove(requestor);
549 }
550 }
551
552 if (noMoreRefs) serviceClassRef.removeRequestor(requestor);
553
554 listener.serviceRevoked(bcsre);
555
556 if (serviceClassRef.isEmpty())
557 serviceClasses.remove(serviceClassRef.getServiceClass());
558 }
559 }
560
561 if (serviceClasses.isEmpty()) serviceClasses = null;
562
563 if (serviceRequestors != null && serviceRequestors.isEmpty())
564 serviceRequestors = null;
565 }
566
567 /*
568 * fields
569 */
570
571 private transient HashMap serviceClasses;
572 private transient HashMap serviceRequestors;
573 }
574
575 /**
576 * <p>
577 * Subclasses can override this method to insert their own subclass
578 * of Child without having to override add() or the other Collection
579 * methods that add children to the set.
580 * </p>
581 *
582 * @param targetChild the child to create the Child on behalf of
583 * @param peer the peer if the targetChild and peer are related by BeanContextProxy
584 */
585
586 protected BCSChild createBCSChild(Object targetChild, Object peer) {
587 return new BCSSChild(targetChild, peer);
588 }
589
590 /************************************************************************/
591
592 /**
593 * subclasses may subclass this nested class to add behaviors for
594 * each BeanContextServicesProvider.
595 */
596
597 protected static class BCSSServiceProvider implements Serializable {
598 private static final long serialVersionUID = 861278251667444782L;
599
600 BCSSServiceProvider(Class sc, BeanContextServiceProvider bcsp) {
601 super();
602
603 serviceProvider = bcsp;
604 }
605
606 protected BeanContextServiceProvider getServiceProvider() {
607 return serviceProvider;
608 }
609
610 /*
611 * fields
612 */
613
614 protected BeanContextServiceProvider serviceProvider;
615 }
616
617 /**
618 * subclasses can override this method to create new subclasses of
619 * BCSSServiceProvider without having to overrride addService() in
620 * order to instantiate.
621 */
622
623 protected BCSSServiceProvider createBCSSServiceProvider(Class sc, BeanContextServiceProvider bcsp) {
624 return new BCSSServiceProvider(sc, bcsp);
625 }
626
627 /************************************************************************/
628
629 /**
630 * add a BeanContextServicesListener
631 *
632 * @throws NullPointerException
633 */
634
635 public void addBeanContextServicesListener(BeanContextServicesListener bcsl) {
636 if (bcsl == null) throw new NullPointerException("bcsl");
637
638 synchronized(bcsListeners) {
639 if (bcsListeners.contains(bcsl))
640 return;
641 else
642 bcsListeners.add(bcsl);
643 }
644 }
645
646 /**
647 * remove a BeanContextServicesListener
648 */
649
650 public void removeBeanContextServicesListener(BeanContextServicesListener bcsl) {
651 if (bcsl == null) throw new NullPointerException("bcsl");
652
653 synchronized(bcsListeners) {
654 if (!bcsListeners.contains(bcsl))
655 return;
656 else
657 bcsListeners.remove(bcsl);
658 }
659 }
660
661 /**
662 * add a service
663 */
664
665 public boolean addService(Class serviceClass, BeanContextServiceProvider bcsp) {
666 return addService(serviceClass, bcsp, true);
667 }
668
669 /**
670 * add a service
671 */
672
673 protected boolean addService(Class serviceClass, BeanContextServiceProvider bcsp, boolean fireEvent) {
674
675 if (serviceClass == null) throw new NullPointerException("serviceClass");
676 if (bcsp == null) throw new NullPointerException("bcsp");
677
678 synchronized(BeanContext.globalHierarchyLock) {
679 if (services.containsKey(serviceClass))
680 return false;
681 else {
682 services.put(serviceClass, createBCSSServiceProvider(serviceClass, bcsp));
683
684 if (bcsp instanceof Serializable) serializable++;
685
686 if (!fireEvent) return true;
687
688
689 BeanContextServiceAvailableEvent bcssae = new BeanContextServiceAvailableEvent(getBeanContextServicesPeer(), serviceClass);
690
691 fireServiceAdded(bcssae);
692
693 synchronized(children) {
694 Iterator i = children.keySet().iterator();
695
696 while (i.hasNext()) {
697 Object c = i.next();
698
699 if (c instanceof BeanContextServices) {
700 ((BeanContextServicesListener)c).serviceAvailable(bcssae);
701 }
702 }
703 }
704
705 return true;
706 }
707 }
708 }
709
710 /**
711 * remove a service
712 */
713
714 public void revokeService(Class serviceClass, BeanContextServiceProvider bcsp, boolean revokeCurrentServicesNow) {
715
716 if (serviceClass == null) throw new NullPointerException("serviceClass");
717 if (bcsp == null) throw new NullPointerException("bcsp");
718
719 synchronized(BeanContext.globalHierarchyLock) {
720 if (!services.containsKey(serviceClass)) return;
721
722 BCSSServiceProvider bcsssp = (BCSSServiceProvider)services.get(serviceClass);
723
724 if (!bcsssp.getServiceProvider().equals(bcsp))
725 throw new IllegalArgumentException("service provider mismatch");
726
727 services.remove(serviceClass);
728
729 if (bcsp instanceof Serializable) serializable--;
730
731 Iterator i = bcsChildren(); // get the BCSChild values.
732
733 while (i.hasNext()) {
734 ((BCSSChild)i.next()).revokeService(serviceClass, false, revokeCurrentServicesNow);
735 }
736
737 fireServiceRevoked(serviceClass, revokeCurrentServicesNow);
738 }
739 }
740
741 /**
742 * has a service, which may be delegated
743 */
744
745 public synchronized boolean hasService(Class serviceClass) {
746 if (serviceClass == null) throw new NullPointerException("serviceClass");
747
748 synchronized(BeanContext.globalHierarchyLock) {
749 if (services.containsKey(serviceClass)) return true;
750
751 BeanContextServices bcs = null;
752
753 try {
754 bcs = (BeanContextServices)getBeanContext();
755 } catch (ClassCastException cce) {
756 return false;
757 }
758
759 return bcs == null ? false : bcs.hasService(serviceClass);
760 }
761 }
762
763 /************************************************************************/
764
765 /*
766 * a nested subclass used to represent a proxy for serviceClasses delegated
767 * to an enclosing BeanContext.
768 */
769
770 protected class BCSSProxyServiceProvider implements BeanContextServiceProvider, BeanContextServiceRevokedListener {
771
772 BCSSProxyServiceProvider(BeanContextServices bcs) {
773 super();
774
775 nestingCtxt = bcs;
776 }
777
778 public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) {
779 Object service = null;
780
781 try {
782 service = nestingCtxt.getService(bcs, requestor, serviceClass, serviceSelector, this);
783 } catch (TooManyListenersException tmle) {
784 return null;
785 }
786
787 return service;
788 }
789
790 public void releaseService(BeanContextServices bcs, Object requestor, Object service) {
791 nestingCtxt.releaseService(bcs, requestor, service);
792 }
793
794 public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) {
795 return nestingCtxt.getCurrentServiceSelectors(serviceClass);
796 }
797
798 public void serviceRevoked(BeanContextServiceRevokedEvent bcsre) {
799 Iterator i = bcsChildren(); // get the BCSChild values.
800
801 while (i.hasNext()) {
802 ((BCSSChild)i.next()).revokeService(bcsre.getServiceClass(), true, bcsre.isCurrentServiceInvalidNow());
803 }
804 }
805
806 /*
807 * fields
808 */
809
810 private BeanContextServices nestingCtxt;
811 }
812
813 /************************************************************************/
814
815 /**
816 * obtain a service which may be delegated
817 */
818
819 public Object getService(BeanContextChild child, Object requestor, Class serviceClass, Object serviceSelector, BeanContextServiceRevokedListener bcsrl) throws TooManyListenersException {
820 if (child == null) throw new NullPointerException("child");
821 if (serviceClass == null) throw new NullPointerException("serviceClass");
822 if (requestor == null) throw new NullPointerException("requestor");
823 if (bcsrl == null) throw new NullPointerException("bcsrl");
824
825 Object service = null;
826 BCSSChild bcsc;
827 BeanContextServices bcssp = getBeanContextServicesPeer();
828
829 synchronized(BeanContext.globalHierarchyLock) {
830 synchronized(children) { bcsc = (BCSSChild)children.get(child); }
831
832 if (bcsc == null) throw new IllegalArgumentException("not a child of this context"); // not a child ...
833
834 BCSSServiceProvider bcsssp = (BCSSServiceProvider)services.get(serviceClass);
835
836 if (bcsssp != null) {
837 BeanContextServiceProvider bcsp = bcsssp.getServiceProvider();
838 service = bcsp.getService(bcssp, requestor, serviceClass, serviceSelector);
839 if (service != null) { // do bookkeeping ...
840 try {
841 bcsc.usingService(requestor, service, serviceClass, bcsp, false, bcsrl);
842 } catch (TooManyListenersException tmle) {
843 bcsp.releaseService(bcssp, requestor, service);
844 throw tmle;
845 } catch (UnsupportedOperationException uope) {
846 bcsp.releaseService(bcssp, requestor, service);
847 throw uope; // unchecked rt exception
848 }
849
850 return service;
851 }
852 }
853
854
855 if (proxy != null) {
856
857 // try to delegate ...
858
859 service = proxy.getService(bcssp, requestor, serviceClass, serviceSelector);
860
861 if (service != null) { // do bookkeeping ...
862 try {
863 bcsc.usingService(requestor, service, serviceClass, proxy, true, bcsrl);
864 } catch (TooManyListenersException tmle) {
865 proxy.releaseService(bcssp, requestor, service);
866 throw tmle;
867 } catch (UnsupportedOperationException uope) {
868 proxy.releaseService(bcssp, requestor, service);
869 throw uope; // unchecked rt exception
870 }
871
872 return service;
873 }
874 }
875 }
876
877 return null;
878 }
879
880 /**
881 * release a service
882 */
883
884 public void releaseService(BeanContextChild child, Object requestor, Object service) {
885 if (child == null) throw new NullPointerException("child");
886 if (requestor == null) throw new NullPointerException("requestor");
887 if (service == null) throw new NullPointerException("service");
888
889 BCSSChild bcsc;
890
891 synchronized(BeanContext.globalHierarchyLock) {
892 synchronized(children) { bcsc = (BCSSChild)children.get(child); }
893
894 if (bcsc != null)
895 bcsc.releaseService(requestor, service);
896 else
897 throw new IllegalArgumentException("child actual is not a child of this BeanContext");
898 }
899 }
900
901 /**
902 * @return an iterator for all the currently registered service classes.
903 */
904
905 public Iterator getCurrentServiceClasses() {
906 return new BCSIterator(services.keySet().iterator());
907 }
908
909 /**
910 * @return an iterator for all the currently available service selectors
911 * (if any) available for the specified service.
912 */
913
914 public Iterator getCurrentServiceSelectors(Class serviceClass) {
915
916 BCSSServiceProvider bcsssp = (BCSSServiceProvider)services.get(serviceClass);
917
918 return bcsssp != null ? new BCSIterator(bcsssp.getServiceProvider().getCurrentServiceSelectors(getBeanContextServicesPeer(), serviceClass)) : null;
919 }
920
921 /**
922 * BeanContextServicesListener callback, propagates event to all
923 * currently registered listeners and BeanContextServices children,
924 * if this BeanContextService does not already implement this service
925 * itself.
926 *
927 * subclasses may override or envelope this method to implement their
928 * own propagation semantics.
929 */
930
931 public void serviceAvailable(BeanContextServiceAvailableEvent bcssae) {
932 synchronized(BeanContext.globalHierarchyLock) {
933 if (services.containsKey(bcssae.getServiceClass())) return;
934
935 fireServiceAdded(bcssae);
936
937 Iterator i;
938
939 synchronized(children) {
940 i = children.keySet().iterator();
941 }
942
943 while (i.hasNext()) {
944 Object c = i.next();
945
946 if (c instanceof BeanContextServices) {
947 ((BeanContextServicesListener)c).serviceAvailable(bcssae);
948 }
949 }
950 }
951 }
952
953 /**
954 * BeanContextServicesListener callback, propagates event to all
955 * currently registered listeners and BeanContextServices children,
956 * if this BeanContextService does not already implement this service
957 * itself.
958 *
959 * subclasses may override or envelope this method to implement their
960 * own propagation semantics.
961 */
962
963 public void serviceRevoked(BeanContextServiceRevokedEvent bcssre) {
964 synchronized(BeanContext.globalHierarchyLock) {
965 if (services.containsKey(bcssre.getServiceClass())) return;
966
967 fireServiceRevoked(bcssre);
968
969 Iterator i;
970
971 synchronized(children) {
972 i = children.keySet().iterator();
973 }
974
975 while (i.hasNext()) {
976 Object c = i.next();
977
978 if (c instanceof BeanContextServices) {
979 ((BeanContextServicesListener)c).serviceRevoked(bcssre);
980 }
981 }
982 }
983 }
984
985 /**
986 * Gets the <tt>BeanContextServicesListener</tt> (if any) of the specified
987 * child.
988 *
989 * @param child the specified child
990 * @return the BeanContextServicesListener (if any) of the specified child
991 */
992 protected static final BeanContextServicesListener getChildBeanContextServicesListener(Object child) {
993 try {
994 return (BeanContextServicesListener)child;
995 } catch (ClassCastException cce) {
996 return null;
997 }
998 }
999
1000 /**
1001 * called from superclass child removal operations after a child
1002 * has been successfully removed. called with child synchronized.
1003 *
1004 * This subclass uses this hook to immediately revoke any services
1005 * being used by this child if it is a BeanContextChild.
1006 *
1007 * subclasses may envelope this method in order to implement their
1008 * own child removal side-effects.
1009 */
1010
1011 protected void childJustRemovedHook(Object child, BCSChild bcsc) {
1012 BCSSChild bcssc = (BCSSChild)bcsc;
1013
1014 bcssc.cleanupReferences();
1015 }
1016
1017 /**
1018 * called from setBeanContext to notify a BeanContextChild
1019 * to release resources obtained from the nesting BeanContext.
1020 *
1021 * This method revokes any services obtained from its parent.
1022 *
1023 * subclasses may envelope this method to implement their own semantics.
1024 */
1025
1026 protected synchronized void releaseBeanContextResources() {
1027 Object[] bcssc;
1028
1029 super.releaseBeanContextResources();
1030
1031 synchronized(children) {
1032 if (children.isEmpty()) return;
1033
1034 bcssc = children.values().toArray();
1035 }
1036
1037
1038 for (int i = 0; i < bcssc.length; i++) {
1039 ((BCSSChild)bcssc[i]).revokeAllDelegatedServicesNow();
1040 }
1041
1042 proxy = null;
1043 }
1044
1045 /**
1046 * called from setBeanContext to notify a BeanContextChild
1047 * to allocate resources obtained from the nesting BeanContext.
1048 *
1049 * subclasses may envelope this method to implement their own semantics.
1050 */
1051
1052 protected synchronized void initializeBeanContextResources() {
1053 super.initializeBeanContextResources();
1054
1055 BeanContext nbc = getBeanContext();
1056
1057 if (nbc == null) return;
1058
1059 try {
1060 BeanContextServices bcs = (BeanContextServices)nbc;
1061
1062 proxy = new BCSSProxyServiceProvider(bcs);
1063 } catch (ClassCastException cce) {
1064 // do nothing ...
1065 }
1066 }
1067
1068 /**
1069 * Fires a <tt>BeanContextServiceEvent</tt> notifying of a new service.
1070 */
1071 protected final void fireServiceAdded(Class serviceClass) {
1072 BeanContextServiceAvailableEvent bcssae = new BeanContextServiceAvailableEvent(getBeanContextServicesPeer(), serviceClass);
1073
1074 fireServiceAdded(bcssae);
1075 }
1076
1077 /**
1078 * Fires a <tt>BeanContextServiceAvailableEvent</tt> indicating that a new
1079 * service has become available.
1080 *
1081 * @param bcssae the <tt>BeanContextServiceAvailableEvent</tt>
1082 */
1083 protected final void fireServiceAdded(BeanContextServiceAvailableEvent bcssae) {
1084 Object[] copy;
1085
1086 synchronized (bcsListeners) { copy = bcsListeners.toArray(); }
1087
1088 for (int i = 0; i < copy.length; i++) {
1089 ((BeanContextServicesListener)copy[i]).serviceAvailable(bcssae);
1090 }
1091 }
1092
1093 /**
1094 * Fires a <tt>BeanContextServiceEvent</tt> notifying of a service being revoked.
1095 *
1096 * @param bcsre the <tt>BeanContextServiceRevokedEvent</tt>
1097 */
1098 protected final void fireServiceRevoked(BeanContextServiceRevokedEvent bcsre) {
1099 Object[] copy;
1100
1101 synchronized (bcsListeners) { copy = bcsListeners.toArray(); }
1102
1103 for (int i = 0; i < copy.length; i++) {
1104 ((BeanContextServiceRevokedListener)copy[i]).serviceRevoked(bcsre);
1105 }
1106 }
1107
1108 /**
1109 * Fires a <tt>BeanContextServiceRevokedEvent</tt>
1110 * indicating that a particular service is
1111 * no longer available.
1112 */
1113 protected final void fireServiceRevoked(Class serviceClass, boolean revokeNow) {
1114 Object[] copy;
1115 BeanContextServiceRevokedEvent bcsre = new BeanContextServiceRevokedEvent(getBeanContextServicesPeer(), serviceClass, revokeNow);
1116
1117 synchronized (bcsListeners) { copy = bcsListeners.toArray(); }
1118
1119 for (int i = 0; i < copy.length; i++) {
1120 ((BeanContextServicesListener)copy[i]).serviceRevoked(bcsre);
1121 }
1122 }
1123
1124 /**
1125 * called from BeanContextSupport writeObject before it serializes the
1126 * children ...
1127 *
1128 * This class will serialize any Serializable BeanContextServiceProviders
1129 * herein.
1130 *
1131 * subclasses may envelope this method to insert their own serialization
1132 * processing that has to occur prior to serialization of the children
1133 */
1134
1135 protected synchronized void bcsPreSerializationHook(ObjectOutputStream oos) throws IOException {
1136
1137 oos.writeInt(serializable);
1138
1139 if (serializable <= 0) return;
1140
1141 int count = 0;
1142
1143 Iterator i = services.entrySet().iterator();
1144
1145 while (i.hasNext() && count < serializable) {
1146 Map.Entry entry = (Map.Entry)i.next();
1147 BCSSServiceProvider bcsp = null;
1148
1149 try {
1150 bcsp = (BCSSServiceProvider)entry.getValue();
1151 } catch (ClassCastException cce) {
1152 continue;
1153 }
1154
1155 if (bcsp.getServiceProvider() instanceof Serializable) {
1156 oos.writeObject(entry.getKey());
1157 oos.writeObject(bcsp);
1158 count++;
1159 }
1160 }
1161
1162 if (count != serializable)
1163 throw new IOException("wrote different number of service providers than expected");
1164 }
1165
1166 /**
1167 * called from BeanContextSupport readObject before it deserializes the
1168 * children ...
1169 *
1170 * This class will deserialize any Serializable BeanContextServiceProviders
1171 * serialized earlier thus making them available to the children when they
1172 * deserialized.
1173 *
1174 * subclasses may envelope this method to insert their own serialization
1175 * processing that has to occur prior to serialization of the children
1176 */
1177
1178 protected synchronized void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException {
1179
1180 serializable = ois.readInt();
1181
1182 int count = serializable;
1183
1184 while (count > 0) {
1185 services.put(ois.readObject(), ois.readObject());
1186 count--;
1187 }
1188 }
1189
1190 /**
1191 * serialize the instance
1192 */
1193
1194 private synchronized void writeObject(ObjectOutputStream oos) throws IOException {
1195 oos.defaultWriteObject();
1196
1197 serialize(oos, (Collection)bcsListeners);
1198 }
1199
1200 /**
1201 * deserialize the instance
1202 */
1203
1204 private synchronized void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
1205
1206 ois.defaultReadObject();
1207
1208 deserialize(ois, (Collection)bcsListeners);
1209 }
1210
1211
1212 /*
1213 * fields
1214 */
1215
1216 /**
1217 * all accesses to the <code> protected transient HashMap services </code>
1218 * field should be synchronized on that object
1219 */
1220 protected transient HashMap services;
1221
1222 /**
1223 * The number of instances of a serializable <tt>BeanContextServceProvider</tt>.
1224 */
1225 protected transient int serializable = 0;
1226
1227
1228 /**
1229 * Delegate for the <tt>BeanContextServiceProvider</tt>.
1230 */
1231 protected transient BCSSProxyServiceProvider proxy;
1232
1233
1234 /**
1235 * List of <tt>BeanContextServicesListener</tt> objects.
1236 */
1237 protected transient ArrayList bcsListeners;
1238}
java/pkg/java/beans/beancontext/BeanContextSupport$1.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextSupport$2.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextSupport$BCSChild.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextSupport$BCSIterator.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextSupport.class+0−0

Binary file not shown.

java/pkg/java/beans/beancontext/BeanContextSupport.java+1393−0
@@ -0,0 +1,1393 @@
1/*
2 * Copyright (c) 1997, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.beans.beancontext;
27
28import java.awt.Component;
29import java.awt.Container;
30
31import java.beans.Beans;
32import java.beans.AppletInitializer;
33
34import java.beans.DesignMode;
35
36import java.beans.PropertyChangeEvent;
37import java.beans.PropertyChangeListener;
38import java.beans.PropertyChangeSupport;
39
40import java.beans.VetoableChangeListener;
41import java.beans.VetoableChangeSupport;
42import java.beans.PropertyVetoException;
43
44import java.beans.Visibility;
45
46import java.io.IOException;
47import java.io.InputStream;
48import java.io.ObjectInputStream;
49import java.io.ObjectOutputStream;
50import java.io.Serializable;
51
52import java.net.URL;
53
54import java.util.ArrayList;
55import java.util.Collection;
56import java.util.HashMap;
57import java.util.Iterator;
58import java.util.Locale;
59import java.util.Map;
60
61
62/**
63 * This helper class provides a utility implementation of the
64 * java.beans.beancontext.BeanContext interface.
65 * </p>
66 * <p>
67 * Since this class directly implements the BeanContext interface, the class
68 * can, and is intended to be used either by subclassing this implementation,
69 * or via ad-hoc delegation of an instance of this class from another.
70 * </p>
71 *
72 * @author Laurence P. G. Cable
73 * @since 1.2
74 */
75public class BeanContextSupport extends BeanContextChildSupport
76 implements BeanContext,
77 Serializable,
78 PropertyChangeListener,
79 VetoableChangeListener {
80
81 // Fix for bug 4282900 to pass JCK regression test
82 static final long serialVersionUID = -4879613978649577204L;
83
84 /**
85 *
86 * Construct a BeanContextSupport instance
87 *
88 *
89 * @param peer The peer <tt>BeanContext</tt> we are
90 * supplying an implementation for,
91 * or <tt>null</tt>
92 * if this object is its own peer
93 * @param lcle The current Locale for this BeanContext. If
94 * <tt>lcle</tt> is <tt>null</tt>, the default locale
95 * is assigned to the <tt>BeanContext</tt> instance.
96 * @param dTime The initial state,
97 * <tt>true</tt> if in design mode,
98 * <tt>false</tt> if runtime.
99 * @param visible The initial visibility.
100 * @see java.util.Locale#getDefault()
101 * @see java.util.Locale#setDefault(java.util.Locale)
102 */
103 public BeanContextSupport(BeanContext peer, Locale lcle, boolean dTime, boolean visible) {
104 super(peer);
105
106 locale = lcle != null ? lcle : Locale.getDefault();
107 designTime = dTime;
108 okToUseGui = visible;
109
110 initialize();
111 }
112
113 /**
114 * Create an instance using the specified Locale and design mode.
115 *
116 * @param peer The peer <tt>BeanContext</tt> we
117 * are supplying an implementation for,
118 * or <tt>null</tt> if this object is its own peer
119 * @param lcle The current Locale for this <tt>BeanContext</tt>. If
120 * <tt>lcle</tt> is <tt>null</tt>, the default locale
121 * is assigned to the <tt>BeanContext</tt> instance.
122 * @param dtime The initial state, <tt>true</tt>
123 * if in design mode,
124 * <tt>false</tt> if runtime.
125 * @see java.util.Locale#getDefault()
126 * @see java.util.Locale#setDefault(java.util.Locale)
127 */
128 public BeanContextSupport(BeanContext peer, Locale lcle, boolean dtime) {
129 this (peer, lcle, dtime, true);
130 }
131
132 /**
133 * Create an instance using the specified locale
134 *
135 * @param peer The peer BeanContext we are
136 * supplying an implementation for,
137 * or <tt>null</tt> if this object
138 * is its own peer
139 * @param lcle The current Locale for this
140 * <tt>BeanContext</tt>. If
141 * <tt>lcle</tt> is <tt>null</tt>,
142 * the default locale
143 * is assigned to the <tt>BeanContext</tt>
144 * instance.
145 * @see java.util.Locale#getDefault()
146 * @see java.util.Locale#setDefault(java.util.Locale)
147 */
148 public BeanContextSupport(BeanContext peer, Locale lcle) {
149 this (peer, lcle, false, true);
150 }
151
152 /**
153 * Create an instance using with a default locale
154 *
155 * @param peer The peer <tt>BeanContext</tt> we are
156 * supplying an implementation for,
157 * or <tt>null</tt> if this object
158 * is its own peer
159 */
160 public BeanContextSupport(BeanContext peer) {
161 this (peer, null, false, true);
162 }
163
164 /**
165 * Create an instance that is not a delegate of another object
166 */
167
168 public BeanContextSupport() {
169 this (null, null, false, true);
170 }
171
172 /**
173 * Gets the instance of <tt>BeanContext</tt> that
174 * this object is providing the implementation for.
175 * @return the BeanContext instance
176 */
177 public BeanContext getBeanContextPeer() { return (BeanContext)getBeanContextChildPeer(); }
178
179 /**
180 * <p>
181 * The instantiateChild method is a convenience hook
182 * in BeanContext to simplify
183 * the task of instantiating a Bean, nested,
184 * into a <tt>BeanContext</tt>.
185 * </p>
186 * <p>
187 * The semantics of the beanName parameter are defined by java.beans.Beans.instantate.
188 * </p>
189 *
190 * @param beanName the name of the Bean to instantiate within this BeanContext
191 * @throws IOException if there is an I/O error when the bean is being deserialized
192 * @throws ClassNotFoundException if the class
193 * identified by the beanName parameter is not found
194 * @return the new object
195 */
196 public Object instantiateChild(String beanName)
197 throws IOException, ClassNotFoundException {
198 BeanContext bc = getBeanContextPeer();
199
200 return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
201 }
202
203 /**
204 * Gets the number of children currently nested in
205 * this BeanContext.
206 *
207 * @return number of children
208 */
209 public int size() {
210 synchronized(children) {
211 return children.size();
212 }
213 }
214
215 /**
216 * Reports whether or not this
217 * <tt>BeanContext</tt> is empty.
218 * A <tt>BeanContext</tt> is considered
219 * empty when it contains zero
220 * nested children.
221 * @return if there are not children
222 */
223 public boolean isEmpty() {
224 synchronized(children) {
225 return children.isEmpty();
226 }
227 }
228
229 /**
230 * Determines whether or not the specified object
231 * is currently a child of this <tt>BeanContext</tt>.
232 * @param o the Object in question
233 * @return if this object is a child
234 */
235 public boolean contains(Object o) {
236 synchronized(children) {
237 return children.containsKey(o);
238 }
239 }
240
241 /**
242 * Determines whether or not the specified object
243 * is currently a child of this <tt>BeanContext</tt>.
244 * @param o the Object in question
245 * @return if this object is a child
246 */
247 public boolean containsKey(Object o) {
248 synchronized(children) {
249 return children.containsKey(o);
250 }
251 }
252
253 /**
254 * Gets all JavaBean or <tt>BeanContext</tt> instances
255 * currently nested in this <tt>BeanContext</tt>.
256 * @return an <tt>Iterator</tt> of the nested children
257 */
258 public Iterator iterator() {
259 synchronized(children) {
260 return new BCSIterator(children.keySet().iterator());
261 }
262 }
263
264 /**
265 * Gets all JavaBean or <tt>BeanContext</tt>
266 * instances currently nested in this BeanContext.
267 */
268 public Object[] toArray() {
269 synchronized(children) {
270 return children.keySet().toArray();
271 }
272 }
273
274 /**
275 * Gets an array containing all children of
276 * this <tt>BeanContext</tt> that match
277 * the types contained in arry.
278 * @param arry The array of object
279 * types that are of interest.
280 * @return an array of children
281 */
282 public Object[] toArray(Object[] arry) {
283 synchronized(children) {
284 return children.keySet().toArray(arry);
285 }
286 }
287
288
289 /************************************************************************/
290
291 /**
292 * protected final subclass that encapsulates an iterator but implements
293 * a noop remove() method.
294 */
295
296 protected static final class BCSIterator implements Iterator {
297 BCSIterator(Iterator i) { super(); src = i; }
298
299 public boolean hasNext() { return src.hasNext(); }
300 public Object next() { return src.next(); }
301 public void remove() { /* do nothing */ }
302
303 private Iterator src;
304 }
305
306 /************************************************************************/
307
308 /*
309 * protected nested class containing per child information, an instance
310 * of which is associated with each child in the "children" hashtable.
311 * subclasses can extend this class to include their own per-child state.
312 *
313 * Note that this 'value' is serialized with the corresponding child 'key'
314 * when the BeanContextSupport is serialized.
315 */
316
317 protected class BCSChild implements Serializable {
318
319 private static final long serialVersionUID = -5815286101609939109L;
320
321 BCSChild(Object bcc, Object peer) {
322 super();
323
324 child = bcc;
325 proxyPeer = peer;
326 }
327
328 Object getChild() { return child; }
329
330 void setRemovePending(boolean v) { removePending = v; }
331
332 boolean isRemovePending() { return removePending; }
333
334 boolean isProxyPeer() { return proxyPeer != null; }
335
336 Object getProxyPeer() { return proxyPeer; }
337 /*
338 * fields
339 */
340
341
342 private Object child;
343 private Object proxyPeer;
344
345 private transient boolean removePending;
346 }
347
348 /**
349 * <p>
350 * Subclasses can override this method to insert their own subclass
351 * of Child without having to override add() or the other Collection
352 * methods that add children to the set.
353 * </p>
354 *
355 * @param targetChild the child to create the Child on behalf of
356 * @param peer the peer if the tragetChild and the peer are related by an implementation of BeanContextProxy
357 */
358
359 protected BCSChild createBCSChild(Object targetChild, Object peer) {
360 return new BCSChild(targetChild, peer);
361 }
362
363 /************************************************************************/
364
365 /**
366 * Adds/nests a child within this <tt>BeanContext</tt>.
367 * <p>
368 * Invoked as a side effect of java.beans.Beans.instantiate().
369 * If the child object is not valid for adding then this method
370 * throws an IllegalStateException.
371 * </p>
372 *
373 *
374 * @param targetChild The child objects to nest
375 * within this <tt>BeanContext</tt>
376 * @return true if the child was added successfully.
377 * @see #validatePendingAdd
378 */
379 public boolean add(Object targetChild) {
380
381 if (targetChild == null) throw new IllegalArgumentException();
382
383 // The specification requires that we do nothing if the child
384 // is already nested herein.
385
386 if (children.containsKey(targetChild)) return false; // test before locking
387
388 synchronized(BeanContext.globalHierarchyLock) {
389 if (children.containsKey(targetChild)) return false; // check again
390
391 if (!validatePendingAdd(targetChild)) {
392 throw new IllegalStateException();
393 }
394
395
396 // The specification requires that we invoke setBeanContext() on the
397 // newly added child if it implements the java.beans.beancontext.BeanContextChild interface
398
399 BeanContextChild cbcc = getChildBeanContextChild(targetChild);
400 BeanContextChild bccp = null;
401
402 synchronized(targetChild) {
403
404 if (targetChild instanceof BeanContextProxy) {
405 bccp = ((BeanContextProxy)targetChild).getBeanContextProxy();
406
407 if (bccp == null) throw new NullPointerException("BeanContextPeer.getBeanContextProxy()");
408 }
409
410 BCSChild bcsc = createBCSChild(targetChild, bccp);
411 BCSChild pbcsc = null;
412
413 synchronized (children) {
414 children.put(targetChild, bcsc);
415
416 if (bccp != null) children.put(bccp, pbcsc = createBCSChild(bccp, targetChild));
417 }
418
419 if (cbcc != null) synchronized(cbcc) {
420 try {
421 cbcc.setBeanContext(getBeanContextPeer());
422 } catch (PropertyVetoException pve) {
423
424 synchronized (children) {
425 children.remove(targetChild);
426
427 if (bccp != null) children.remove(bccp);
428 }
429
430 throw new IllegalStateException();
431 }
432
433 cbcc.addPropertyChangeListener("beanContext", childPCL);
434 cbcc.addVetoableChangeListener("beanContext", childVCL);
435 }
436
437 Visibility v = getChildVisibility(targetChild);
438
439 if (v != null) {
440 if (okToUseGui)
441 v.okToUseGui();
442 else
443 v.dontUseGui();
444 }
445
446 if (getChildSerializable(targetChild) != null) serializable++;
447
448 childJustAddedHook(targetChild, bcsc);
449
450 if (bccp != null) {
451 v = getChildVisibility(bccp);
452
453 if (v != null) {
454 if (okToUseGui)
455 v.okToUseGui();
456 else
457 v.dontUseGui();
458 }
459
460 if (getChildSerializable(bccp) != null) serializable++;
461
462 childJustAddedHook(bccp, pbcsc);
463 }
464
465
466 }
467
468 // The specification requires that we fire a notification of the change
469
470 fireChildrenAdded(new BeanContextMembershipEvent(getBeanContextPeer(), bccp == null ? new Object[] { targetChild } : new Object[] { targetChild, bccp } ));
471
472 }
473
474 return true;
475 }
476
477 /**
478 * Removes a child from this BeanContext. If the child object is not
479 * for adding then this method throws an IllegalStateException.
480 * @param targetChild The child objects to remove
481 * @see #validatePendingRemove
482 */
483 public boolean remove(Object targetChild) {
484 return remove(targetChild, true);
485 }
486
487 /**
488 * internal remove used when removal caused by
489 * unexpected <tt>setBeanContext</tt> or
490 * by <tt>remove()</tt> invocation.
491 * @param targetChild the JavaBean, BeanContext, or Object to be removed
492 * @param callChildSetBC used to indicate that
493 * the child should be notified that it is no
494 * longer nested in this <tt>BeanContext</tt>.
495 */
496 protected boolean remove(Object targetChild, boolean callChildSetBC) {
497
498 if (targetChild == null) throw new IllegalArgumentException();
499
500 synchronized(BeanContext.globalHierarchyLock) {
501 if (!containsKey(targetChild)) return false;
502
503 if (!validatePendingRemove(targetChild)) {
504 throw new IllegalStateException();
505 }
506
507 BCSChild bcsc = (BCSChild)children.get(targetChild);
508 BCSChild pbcsc = null;
509 Object peer = null;
510
511 // we are required to notify the child that it is no longer nested here if
512 // it implements java.beans.beancontext.BeanContextChild
513
514 synchronized(targetChild) {
515 if (callChildSetBC) {
516 BeanContextChild cbcc = getChildBeanContextChild(targetChild);
517 if (cbcc != null) synchronized(cbcc) {
518 cbcc.removePropertyChangeListener("beanContext", childPCL);
519 cbcc.removeVetoableChangeListener("beanContext", childVCL);
520
521 try {
522 cbcc.setBeanContext(null);
523 } catch (PropertyVetoException pve1) {
524 cbcc.addPropertyChangeListener("beanContext", childPCL);
525 cbcc.addVetoableChangeListener("beanContext", childVCL);
526 throw new IllegalStateException();
527 }
528
529 }
530 }
531
532 synchronized (children) {
533 children.remove(targetChild);
534
535 if (bcsc.isProxyPeer()) {
536 pbcsc = (BCSChild)children.get(peer = bcsc.getProxyPeer());
537 children.remove(peer);
538 }
539 }
540
541 if (getChildSerializable(targetChild) != null) serializable--;
542
543 childJustRemovedHook(targetChild, bcsc);
544
545 if (peer != null) {
546 if (getChildSerializable(peer) != null) serializable--;
547
548 childJustRemovedHook(peer, pbcsc);
549 }
550 }
551
552 fireChildrenRemoved(new BeanContextMembershipEvent(getBeanContextPeer(), peer == null ? new Object[] { targetChild } : new Object[] { targetChild, peer } ));
553
554 }
555
556 return true;
557 }
558
559 /**
560 * Tests to see if all objects in the
561 * specified <tt>Collection</tt> are children of
562 * this <tt>BeanContext</tt>.
563 * @param c the specified <tt>Collection</tt>
564 *
565 * @return <tt>true</tt> if all objects
566 * in the collection are children of
567 * this <tt>BeanContext</tt>, false if not.
568 */
569 public boolean containsAll(Collection c) {
570 synchronized(children) {
571 Iterator i = c.iterator();
572 while (i.hasNext())
573 if(!contains(i.next()))
574 return false;
575
576 return true;
577 }
578 }
579
580 /**
581 * add Collection to set of Children (Unsupported)
582 * implementations must synchronized on the hierarchy lock and "children" protected field
583 * @throws UnsupportedOperationException
584 */
585 public boolean addAll(Collection c) {
586 throw new UnsupportedOperationException();
587 }
588
589 /**
590 * remove all specified children (Unsupported)
591 * implementations must synchronized on the hierarchy lock and "children" protected field
592 * @throws UnsupportedOperationException
593 */
594 public boolean removeAll(Collection c) {
595 throw new UnsupportedOperationException();
596 }
597
598
599 /**
600 * retain only specified children (Unsupported)
601 * implementations must synchronized on the hierarchy lock and "children" protected field
602 * @throws UnsupportedOperationException
603 */
604 public boolean retainAll(Collection c) {
605 throw new UnsupportedOperationException();
606 }
607
608 /**
609 * clear the children (Unsupported)
610 * implementations must synchronized on the hierarchy lock and "children" protected field
611 * @throws UnsupportedOperationException
612 */
613 public void clear() {
614 throw new UnsupportedOperationException();
615 }
616
617 /**
618 * Adds a BeanContextMembershipListener
619 *
620 * @param bcml the BeanContextMembershipListener to add
621 * @throws NullPointerException
622 */
623
624 public void addBeanContextMembershipListener(BeanContextMembershipListener bcml) {
625 if (bcml == null) throw new NullPointerException("listener");
626
627 synchronized(bcmListeners) {
628 if (bcmListeners.contains(bcml))
629 return;
630 else
631 bcmListeners.add(bcml);
632 }
633 }
634
635 /**
636 * Removes a BeanContextMembershipListener
637 *
638 * @param bcml the BeanContextMembershipListener to remove
639 * @throws NullPointerException
640 */
641
642 public void removeBeanContextMembershipListener(BeanContextMembershipListener bcml) {
643 if (bcml == null) throw new NullPointerException("listener");
644
645 synchronized(bcmListeners) {
646 if (!bcmListeners.contains(bcml))
647 return;
648 else
649 bcmListeners.remove(bcml);
650 }
651 }
652
653 /**
654 * @param name the name of the resource requested.
655 * @param bcc the child object making the request.
656 *
657 * @return the requested resource as an InputStream
658 * @throws NullPointerException
659 */
660
661 public InputStream getResourceAsStream(String name, BeanContextChild bcc) {
662 if (name == null) throw new NullPointerException("name");
663 if (bcc == null) throw new NullPointerException("bcc");
664
665 if (containsKey(bcc)) {
666 ClassLoader cl = bcc.getClass().getClassLoader();
667
668 return cl != null ? cl.getResourceAsStream(name)
669 : ClassLoader.getSystemResourceAsStream(name);
670 } else throw new IllegalArgumentException("Not a valid child");
671 }
672
673 /**
674 * @param name the name of the resource requested.
675 * @param bcc the child object making the request.
676 *
677 * @return the requested resource as an InputStream
678 */
679
680 public URL getResource(String name, BeanContextChild bcc) {
681 if (name == null) throw new NullPointerException("name");
682 if (bcc == null) throw new NullPointerException("bcc");
683
684 if (containsKey(bcc)) {
685 ClassLoader cl = bcc.getClass().getClassLoader();
686
687 return cl != null ? cl.getResource(name)
688 : ClassLoader.getSystemResource(name);
689 } else throw new IllegalArgumentException("Not a valid child");
690 }
691
692 /**
693 * Sets the new design time value for this <tt>BeanContext</tt>.
694 * @param dTime the new designTime value
695 */
696 public synchronized void setDesignTime(boolean dTime) {
697 if (designTime != dTime) {
698 designTime = dTime;
699
700 firePropertyChange("designMode", Boolean.valueOf(!dTime), Boolean.valueOf(dTime));
701 }
702 }
703
704
705 /**
706 * Reports whether or not this object is in
707 * currently in design time mode.
708 * @return <tt>true</tt> if in design time mode,
709 * <tt>false</tt> if not
710 */
711 public synchronized boolean isDesignTime() { return designTime; }
712
713 /**
714 * Sets the locale of this BeanContext.
715 * @param newLocale the new locale. This method call will have
716 * no effect if newLocale is <CODE>null</CODE>.
717 * @throws PropertyVetoException if the new value is rejected
718 */
719 public synchronized void setLocale(Locale newLocale) throws PropertyVetoException {
720
721 if ((locale != null && !locale.equals(newLocale)) && newLocale != null) {
722 Locale old = locale;
723
724 fireVetoableChange("locale", old, newLocale); // throws
725
726 locale = newLocale;
727
728 firePropertyChange("locale", old, newLocale);
729 }
730 }
731
732 /**
733 * Gets the locale for this <tt>BeanContext</tt>.
734 *
735 * @return the current Locale of the <tt>BeanContext</tt>
736 */
737 public synchronized Locale getLocale() { return locale; }
738
739 /**
740 * <p>
741 * This method is typically called from the environment in order to determine
742 * if the implementor "needs" a GUI.
743 * </p>
744 * <p>
745 * The algorithm used herein tests the BeanContextPeer, and its current children
746 * to determine if they are either Containers, Components, or if they implement
747 * Visibility and return needsGui() == true.
748 * </p>
749 * @return <tt>true</tt> if the implementor needs a GUI
750 */
751 public synchronized boolean needsGui() {
752 BeanContext bc = getBeanContextPeer();
753
754 if (bc != this) {
755 if (bc instanceof Visibility) return ((Visibility)bc).needsGui();
756
757 if (bc instanceof Container || bc instanceof Component)
758 return true;
759 }
760
761 synchronized(children) {
762 for (Iterator i = children.keySet().iterator(); i.hasNext();) {
763 Object c = i.next();
764
765 try {
766 return ((Visibility)c).needsGui();
767 } catch (ClassCastException cce) {
768 // do nothing ...
769 }
770
771 if (c instanceof Container || c instanceof Component)
772 return true;
773 }
774 }
775
776 return false;
777 }
778
779 /**
780 * notify this instance that it may no longer render a GUI.
781 */
782
783 public synchronized void dontUseGui() {
784 if (okToUseGui) {
785 okToUseGui = false;
786
787 // lets also tell the Children that can that they may not use their GUI's
788 synchronized(children) {
789 for (Iterator i = children.keySet().iterator(); i.hasNext();) {
790 Visibility v = getChildVisibility(i.next());
791
792 if (v != null) v.dontUseGui();
793 }
794 }
795 }
796 }
797
798 /**
799 * Notify this instance that it may now render a GUI
800 */
801
802 public synchronized void okToUseGui() {
803 if (!okToUseGui) {
804 okToUseGui = true;
805
806 // lets also tell the Children that can that they may use their GUI's
807 synchronized(children) {
808 for (Iterator i = children.keySet().iterator(); i.hasNext();) {
809 Visibility v = getChildVisibility(i.next());
810
811 if (v != null) v.okToUseGui();
812 }
813 }
814 }
815 }
816
817 /**
818 * Used to determine if the <tt>BeanContext</tt>
819 * child is avoiding using its GUI.
820 * @return is this instance avoiding using its GUI?
821 * @see Visibility
822 */
823 public boolean avoidingGui() {
824 return !okToUseGui && needsGui();
825 }
826
827 /**
828 * Is this <tt>BeanContext</tt> in the
829 * process of being serialized?
830 * @return if this <tt>BeanContext</tt> is
831 * currently being serialized
832 */
833 public boolean isSerializing() { return serializing; }
834
835 /**
836 * Returns an iterator of all children
837 * of this <tt>BeanContext</tt>.
838 * @return an iterator for all the current BCSChild values
839 */
840 protected Iterator bcsChildren() { synchronized(children) { return children.values().iterator(); } }
841
842 /**
843 * called by writeObject after defaultWriteObject() but prior to
844 * serialization of currently serializable children.
845 *
846 * This method may be overridden by subclasses to perform custom
847 * serialization of their state prior to this superclass serializing
848 * the children.
849 *
850 * This method should not however be used by subclasses to replace their
851 * own implementation (if any) of writeObject().
852 */
853
854 protected void bcsPreSerializationHook(ObjectOutputStream oos) throws IOException {
855 }
856
857 /**
858 * called by readObject after defaultReadObject() but prior to
859 * deserialization of any children.
860 *
861 * This method may be overridden by subclasses to perform custom
862 * deserialization of their state prior to this superclass deserializing
863 * the children.
864 *
865 * This method should not however be used by subclasses to replace their
866 * own implementation (if any) of readObject().
867 */
868
869 protected void bcsPreDeserializationHook(ObjectInputStream ois) throws IOException, ClassNotFoundException {
870 }
871
872 /**
873 * Called by readObject with the newly deserialized child and BCSChild.
874 * @param child the newly deserialized child
875 * @param bcsc the newly deserialized BCSChild
876 */
877 protected void childDeserializedHook(Object child, BCSChild bcsc) {
878 synchronized(children) {
879 children.put(child, bcsc);
880 }
881 }
882
883 /**
884 * Used by writeObject to serialize a Collection.
885 * @param oos the <tt>ObjectOutputStream</tt>
886 * to use during serialization
887 * @param coll the <tt>Collection</tt> to serialize
888 * @throws IOException if serialization failed
889 */
890 protected final void serialize(ObjectOutputStream oos, Collection coll) throws IOException {
891 int count = 0;
892 Object[] objects = coll.toArray();
893
894 for (int i = 0; i < objects.length; i++) {
895 if (objects[i] instanceof Serializable)
896 count++;
897 else
898 objects[i] = null;
899 }
900
901 oos.writeInt(count); // number of subsequent objects
902
903 for (int i = 0; count > 0; i++) {
904 Object o = objects[i];
905
906 if (o != null) {
907 oos.writeObject(o);
908 count--;
909 }
910 }
911 }
912
913 /**
914 * used by readObject to deserialize a collection.
915 * @param ois the ObjectInputStream to use
916 * @param coll the Collection
917 */
918 protected final void deserialize(ObjectInputStream ois, Collection coll) throws IOException, ClassNotFoundException {
919 int count = 0;
920
921 count = ois.readInt();
922
923 while (count-- > 0) {
924 coll.add(ois.readObject());
925 }
926 }
927
928 /**
929 * Used to serialize all children of
930 * this <tt>BeanContext</tt>.
931 * @param oos the <tt>ObjectOutputStream</tt>
932 * to use during serialization
933 * @throws IOException if serialization failed
934 */
935 public final void writeChildren(ObjectOutputStream oos) throws IOException {
936 if (serializable <= 0) return;
937
938 boolean prev = serializing;
939
940 serializing = true;
941
942 int count = 0;
943
944 synchronized(children) {
945 Iterator i = children.entrySet().iterator();
946
947 while (i.hasNext() && count < serializable) {
948 Map.Entry entry = (Map.Entry)i.next();
949
950 if (entry.getKey() instanceof Serializable) {
951 try {
952 oos.writeObject(entry.getKey()); // child
953 oos.writeObject(entry.getValue()); // BCSChild
954 } catch (IOException ioe) {
955 serializing = prev;
956 throw ioe;
957 }
958 count++;
959 }
960 }
961 }
962
963 serializing = prev;
964
965 if (count != serializable) {
966 throw new IOException("wrote different number of children than expected");
967 }
968
969 }
970
971 /**
972 * Serialize the BeanContextSupport, if this instance has a distinct
973 * peer (that is this object is acting as a delegate for another) then
974 * the children of this instance are not serialized here due to a
975 * 'chicken and egg' problem that occurs on deserialization of the
976 * children at the same time as this instance.
977 *
978 * Therefore in situations where there is a distinct peer to this instance
979 * it should always call writeObject() followed by writeChildren() and
980 * readObject() followed by readChildren().
981 *
982 * @param oos the ObjectOutputStream
983 */
984
985 private synchronized void writeObject(ObjectOutputStream oos) throws IOException, ClassNotFoundException {
986 serializing = true;
987
988 synchronized (BeanContext.globalHierarchyLock) {
989 try {
990 oos.defaultWriteObject(); // serialize the BeanContextSupport object
991
992 bcsPreSerializationHook(oos);
993
994 if (serializable > 0 && this.equals(getBeanContextPeer()))
995 writeChildren(oos);
996
997 serialize(oos, (Collection)bcmListeners);
998 } finally {
999 serializing = false;
1000 }
1001 }
1002 }
1003
1004 /**
1005 * When an instance of this class is used as a delegate for the
1006 * implementation of the BeanContext protocols (and its subprotocols)
1007 * there exists a 'chicken and egg' problem during deserialization
1008 */
1009
1010 public final void readChildren(ObjectInputStream ois) throws IOException, ClassNotFoundException {
1011 int count = serializable;
1012
1013 while (count-- > 0) {
1014 Object child = null;
1015 BeanContextSupport.BCSChild bscc = null;
1016
1017 try {
1018 child = ois.readObject();
1019 bscc = (BeanContextSupport.BCSChild)ois.readObject();
1020 } catch (IOException ioe) {
1021 continue;
1022 } catch (ClassNotFoundException cnfe) {
1023 continue;
1024 }
1025
1026
1027 synchronized(child) {
1028 BeanContextChild bcc = null;
1029
1030 try {
1031 bcc = (BeanContextChild)child;
1032 } catch (ClassCastException cce) {
1033 // do nothing;
1034 }
1035
1036 if (bcc != null) {
1037 try {
1038 bcc.setBeanContext(getBeanContextPeer());
1039
1040 bcc.addPropertyChangeListener("beanContext", childPCL);
1041 bcc.addVetoableChangeListener("beanContext", childVCL);
1042
1043 } catch (PropertyVetoException pve) {
1044 continue;
1045 }
1046 }
1047
1048 childDeserializedHook(child, bscc);
1049 }
1050 }
1051 }
1052
1053 /**
1054 * deserialize contents ... if this instance has a distinct peer the
1055 * children are *not* serialized here, the peer's readObject() must call
1056 * readChildren() after deserializing this instance.
1057 */
1058
1059 private synchronized void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
1060
1061 synchronized(BeanContext.globalHierarchyLock) {
1062 ois.defaultReadObject();
1063
1064 initialize();
1065
1066 bcsPreDeserializationHook(ois);
1067
1068 if (serializable > 0 && this.equals(getBeanContextPeer()))
1069 readChildren(ois);
1070
1071 deserialize(ois, bcmListeners = new ArrayList(1));
1072 }
1073 }
1074
1075 /**
1076 * subclasses may envelope to monitor veto child property changes.
1077 */
1078
1079 public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
1080 String propertyName = pce.getPropertyName();
1081 Object source = pce.getSource();
1082
1083 synchronized(children) {
1084 if ("beanContext".equals(propertyName) &&
1085 containsKey(source) &&
1086 !getBeanContextPeer().equals(pce.getNewValue())
1087 ) {
1088 if (!validatePendingRemove(source)) {
1089 throw new PropertyVetoException("current BeanContext vetoes setBeanContext()", pce);
1090 } else ((BCSChild)children.get(source)).setRemovePending(true);
1091 }
1092 }
1093 }
1094
1095 /**
1096 * subclasses may envelope to monitor child property changes.
1097 */
1098
1099 public void propertyChange(PropertyChangeEvent pce) {
1100 String propertyName = pce.getPropertyName();
1101 Object source = pce.getSource();
1102
1103 synchronized(children) {
1104 if ("beanContext".equals(propertyName) &&
1105 containsKey(source) &&
1106 ((BCSChild)children.get(source)).isRemovePending()) {
1107 BeanContext bc = getBeanContextPeer();
1108
1109 if (bc.equals(pce.getOldValue()) && !bc.equals(pce.getNewValue())) {
1110 remove(source, false);
1111 } else {
1112 ((BCSChild)children.get(source)).setRemovePending(false);
1113 }
1114 }
1115 }
1116 }
1117
1118 /**
1119 * <p>
1120 * Subclasses of this class may override, or envelope, this method to
1121 * add validation behavior for the BeanContext to examine child objects
1122 * immediately prior to their being added to the BeanContext.
1123 * </p>
1124 *
1125 * @return true iff the child may be added to this BeanContext, otherwise false.
1126 */
1127
1128 protected boolean validatePendingAdd(Object targetChild) {
1129 return true;
1130 }
1131
1132 /**
1133 * <p>
1134 * Subclasses of this class may override, or envelope, this method to
1135 * add validation behavior for the BeanContext to examine child objects
1136 * immediately prior to their being removed from the BeanContext.
1137 * </p>
1138 *
1139 * @return true iff the child may be removed from this BeanContext, otherwise false.
1140 */
1141
1142 protected boolean validatePendingRemove(Object targetChild) {
1143 return true;
1144 }
1145
1146 /**
1147 * subclasses may override this method to simply extend add() semantics
1148 * after the child has been added and before the event notification has
1149 * occurred. The method is called with the child synchronized.
1150 */
1151
1152 protected void childJustAddedHook(Object child, BCSChild bcsc) {
1153 }
1154
1155 /**
1156 * subclasses may override this method to simply extend remove() semantics
1157 * after the child has been removed and before the event notification has
1158 * occurred. The method is called with the child synchronized.
1159 */
1160
1161 protected void childJustRemovedHook(Object child, BCSChild bcsc) {
1162 }
1163
1164 /**
1165 * Gets the Component (if any) associated with the specified child.
1166 * @param child the specified child
1167 * @return the Component (if any) associated with the specified child.
1168 */
1169 protected static final Visibility getChildVisibility(Object child) {
1170 try {
1171 return (Visibility)child;
1172 } catch (ClassCastException cce) {
1173 return null;
1174 }
1175 }
1176
1177 /**
1178 * Gets the Serializable (if any) associated with the specified Child
1179 * @param child the specified child
1180 * @return the Serializable (if any) associated with the specified Child
1181 */
1182 protected static final Serializable getChildSerializable(Object child) {
1183 try {
1184 return (Serializable)child;
1185 } catch (ClassCastException cce) {
1186 return null;
1187 }
1188 }
1189
1190 /**
1191 * Gets the PropertyChangeListener
1192 * (if any) of the specified child
1193 * @param child the specified child
1194 * @return the PropertyChangeListener (if any) of the specified child
1195 */
1196 protected static final PropertyChangeListener getChildPropertyChangeListener(Object child) {
1197 try {
1198 return (PropertyChangeListener)child;
1199 } catch (ClassCastException cce) {
1200 return null;
1201 }
1202 }
1203
1204 /**
1205 * Gets the VetoableChangeListener
1206 * (if any) of the specified child
1207 * @param child the specified child
1208 * @return the VetoableChangeListener (if any) of the specified child
1209 */
1210 protected static final VetoableChangeListener getChildVetoableChangeListener(Object child) {
1211 try {
1212 return (VetoableChangeListener)child;
1213 } catch (ClassCastException cce) {
1214 return null;
1215 }
1216 }
1217
1218 /**
1219 * Gets the BeanContextMembershipListener
1220 * (if any) of the specified child
1221 * @param child the specified child
1222 * @return the BeanContextMembershipListener (if any) of the specified child
1223 */
1224 protected static final BeanContextMembershipListener getChildBeanContextMembershipListener(Object child) {
1225 try {
1226 return (BeanContextMembershipListener)child;
1227 } catch (ClassCastException cce) {
1228 return null;
1229 }
1230 }
1231
1232 /**
1233 * Gets the BeanContextChild (if any) of the specified child
1234 * @param child the specified child
1235 * @return the BeanContextChild (if any) of the specified child
1236 * @throws IllegalArgumentException if child implements both BeanContextChild and BeanContextProxy
1237 */
1238 protected static final BeanContextChild getChildBeanContextChild(Object child) {
1239 try {
1240 BeanContextChild bcc = (BeanContextChild)child;
1241
1242 if (child instanceof BeanContextChild && child instanceof BeanContextProxy)
1243 throw new IllegalArgumentException("child cannot implement both BeanContextChild and BeanContextProxy");
1244 else
1245 return bcc;
1246 } catch (ClassCastException cce) {
1247 try {
1248 return ((BeanContextProxy)child).getBeanContextProxy();
1249 } catch (ClassCastException cce1) {
1250 return null;
1251 }
1252 }
1253 }
1254
1255 /**
1256 * Fire a BeanContextshipEvent on the BeanContextMembershipListener interface
1257 */
1258
1259 protected final void fireChildrenAdded(BeanContextMembershipEvent bcme) {
1260 Object[] copy;
1261
1262 synchronized(bcmListeners) { copy = bcmListeners.toArray(); }
1263
1264 for (int i = 0; i < copy.length; i++)
1265 ((BeanContextMembershipListener)copy[i]).childrenAdded(bcme);
1266 }
1267
1268 /**
1269 * Fire a BeanContextshipEvent on the BeanContextMembershipListener interface
1270 */
1271
1272 protected final void fireChildrenRemoved(BeanContextMembershipEvent bcme) {
1273 Object[] copy;
1274
1275 synchronized(bcmListeners) { copy = bcmListeners.toArray(); }
1276
1277 for (int i = 0; i < copy.length; i++)
1278 ((BeanContextMembershipListener)copy[i]).childrenRemoved(bcme);
1279 }
1280
1281 /**
1282 * protected method called from constructor and readObject to initialize
1283 * transient state of BeanContextSupport instance.
1284 *
1285 * This class uses this method to instantiate inner class listeners used
1286 * to monitor PropertyChange and VetoableChange events on children.
1287 *
1288 * subclasses may envelope this method to add their own initialization
1289 * behavior
1290 */
1291
1292 protected synchronized void initialize() {
1293 children = new HashMap(serializable + 1);
1294 bcmListeners = new ArrayList(1);
1295
1296 childPCL = new PropertyChangeListener() {
1297
1298 /*
1299 * this adaptor is used by the BeanContextSupport class to forward
1300 * property changes from a child to the BeanContext, avoiding
1301 * accidential serialization of the BeanContext by a badly
1302 * behaved Serializable child.
1303 */
1304
1305 public void propertyChange(PropertyChangeEvent pce) {
1306 BeanContextSupport.this.propertyChange(pce);
1307 }
1308 };
1309
1310 childVCL = new VetoableChangeListener() {
1311
1312 /*
1313 * this adaptor is used by the BeanContextSupport class to forward
1314 * vetoable changes from a child to the BeanContext, avoiding
1315 * accidential serialization of the BeanContext by a badly
1316 * behaved Serializable child.
1317 */
1318
1319 public void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException {
1320 BeanContextSupport.this.vetoableChange(pce);
1321 }
1322 };
1323 }
1324
1325 /**
1326 * Gets a copy of the this BeanContext's children.
1327 * @return a copy of the current nested children
1328 */
1329 protected final Object[] copyChildren() {
1330 synchronized(children) { return children.keySet().toArray(); }
1331 }
1332
1333 /**
1334 * Tests to see if two class objects,
1335 * or their names are equal.
1336 * @param first the first object
1337 * @param second the second object
1338 * @return true if equal, false if not
1339 */
1340 protected static final boolean classEquals(Class first, Class second) {
1341 return first.equals(second) || first.getName().equals(second.getName());
1342 }
1343
1344
1345 /*
1346 * fields
1347 */
1348
1349
1350 /**
1351 * all accesses to the <code> protected HashMap children </code> field
1352 * shall be synchronized on that object.
1353 */
1354 protected transient HashMap children;
1355
1356 private int serializable = 0; // children serializable
1357
1358 /**
1359 * all accesses to the <code> protected ArrayList bcmListeners </code> field
1360 * shall be synchronized on that object.
1361 */
1362 protected transient ArrayList bcmListeners;
1363
1364 //
1365
1366 /**
1367 * The current locale of this BeanContext.
1368 */
1369 protected Locale locale;
1370
1371 /**
1372 * A <tt>boolean</tt> indicating if this
1373 * instance may now render a GUI.
1374 */
1375 protected boolean okToUseGui;
1376
1377
1378 /**
1379 * A <tt>boolean</tt> indicating whether or not
1380 * this object is currently in design time mode.
1381 */
1382 protected boolean designTime;
1383
1384 /*
1385 * transient
1386 */
1387
1388 private transient PropertyChangeListener childPCL;
1389
1390 private transient VetoableChangeListener childVCL;
1391
1392 private transient boolean serializing;
1393}
java/pkg/java/beans/beancontext/mkfile+25−0
@@ -0,0 +1,25 @@
1<../../../../../mkconfig
2
3TARG=\
4 BeanContext.dis\
5 BeanContextChild.dis\
6 BeanContextChildComponentProxy.dis\
7 BeanContextChildSupport.dis\
8 BeanContextContainerProxy.dis\
9 BeanContextEvent.dis\
10 BeanContextMembershipEvent.dis\
11 BeanContextMembershipListener.dis\
12 BeanContextProxy.dis\
13 BeanContextServiceAvailableEvent.dis\
14 BeanContextServiceProvider.dis\
15 BeanContextServiceProviderBeanInfo.dis\
16 BeanContextServiceRevokedEvent.dis\
17 BeanContextServiceRevokedListener.dis\
18 BeanContextServices.dis\
19 BeanContextServicesListener.dis\
20 BeanContextServicesSupport.dis\
21 BeanContextSupport.dis\
22
23DISBIN=$ROOT/java/dis/java/java/java/beans/beancontext
24
25<$ROOT/mkfiles/mkjava
java/pkg/java/beans/beancontext/package.html+55−0
@@ -0,0 +1,55 @@
1<!--
2 Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved.
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 This code is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License version 2 only, as
7 published by the Free Software Foundation. Oracle designates this
8 particular file as subject to the "Classpath" exception as provided
9 by Oracle in the LICENSE file that accompanied this code.
10
11 This code is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 version 2 for more details (a copy is included in the LICENSE file that
15 accompanied this code).
16
17 You should have received a copy of the GNU General Public License version
18 2 along with this work; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 or visit www.oracle.com if you need additional information or have any
23 questions.
24-->
25
26<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
27<html>
28<body bgcolor="white">
29
30Provides classes and interfaces relating to bean context.
31A bean context is a container for beans and defines the execution
32environment for the beans it contains. There can be several beans in
33a single bean context, and a bean context can be nested within another
34bean context. This package also contains events and listener
35interface for beans being added and removed from a bean context.
36
37<!--
38<h2>Package Specification</h2>
39
40##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
41<ul>
42 <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
43</ul>
44
45<h2>Related Documentation</h2>
46
47For overviews, tutorials, examples, guides, and tool documentation, please see:
48<ul>
49 <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
50</ul>
51-->
52
53@since 1.2
54</body>
55</html>