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