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