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