1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.di;
17
18 /**
19 * <p>
20 * Definition of an interface to be implemented by beans that need a reference
21 * to the current {@link BeanContext}.
22 * </p>
23 * <p>
24 * Sometimes beans defined using the <em>dependency injection framework</em>
25 * also want to use the framework for accessing other beans through a
26 * {@link BeanContext}. This is often the case if the dependencies of a bean are
27 * not fully known at design time, but are determined based on certain criteria
28 * at runtime. In such cases a reference to the current {@link BeanContext} must
29 * somehow be passed to the affected beans.
30 * </p>
31 * <p>
32 * This interface marks a bean as a client of a {@link BeanContext}. It defines
33 * a single method, through which the {@link BeanContext} can be passed to the
34 * object. The dependency injection framework checks for each bean that is newly
35 * created whether it implements this interface. If this is the case, the
36 * {@code setBeanContext()} method is automatically called. Thus the
37 * {@link BeanContext} becomes known to the bean and can be used later for
38 * accessing other dependencies. No additional configuration steps are required
39 * to use this feature. Every bean implementing this interface is automatically
40 * initialized with the current {@link BeanContext}.
41 * </p>
42 * <p>
43 * One big advantage of dependency injection is that it tends to be
44 * non-invasive: the beans managed by the framework need not implement specific
45 * interfaces or extend certain base classes; the framework handles their
46 * creation and initialization transparently. By implementing this interface
47 * beans define a direct dependency to this framework, which makes it harder to
48 * use them in a different context. So before making use of this feature
49 * possible alternatives should be evaluated, or at least the developer should
50 * be aware that a tight coupling to this specific dependency injection
51 * framework is introduced.
52 * </p>
53 *
54 * @author Oliver Heger
55 * @version $Id: BeanContextClient.java 205 2012-01-29 18:29:57Z oheger $
56 */
57 public interface BeanContextClient
58 {
59 /**
60 * Passes the current {@code BeanContext} to this object. This method is
61 * invoked by the framework after initialization of this object is complete.
62 * At this time all dependencies to other beans have been resolved, but
63 * {@link BeanCreationListener}s registered at the context have not yet been
64 * invoked. An implementation will typical store the passed in {@code
65 * BeanContext} for later use.
66 *
67 * @param context the current {@code BeanContext}
68 */
69 void setBeanContext(BeanContext context);
70 }