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