KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > inject > Inject


1 /**
2  * Copyright (C) 2006 Google Inc.
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
17 package com.google.inject;
18
19 import static java.lang.annotation.ElementType.CONSTRUCTOR JavaDoc;
20 import static java.lang.annotation.ElementType.FIELD JavaDoc;
21 import static java.lang.annotation.ElementType.METHOD JavaDoc;
22 import java.lang.annotation.Retention JavaDoc;
23 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
24 import java.lang.annotation.Target JavaDoc;
25
26 /**
27  * Annotates members of your implementation class (constructors, methods
28  * and fields) into which the {@link Injector} should inject values.
29  * The Injector fulfills injection requests for:
30  *
31  * <ul>
32  * <li>Every instance it constructs. The class being constructed must have
33  * exactly one of its constructors marked with {@code @Inject} or must have a
34  * constructor taking no parameters. The Injector then proceeds to perform
35  * method and field injections.
36  *
37  * <li>Pre-constructed instances passed to {@link Injector#injectMembers},
38  * {@link com.google.inject.binder.LinkedBindingBuilder#toInstance(Object)} and
39  * {@link com.google.inject.binder.LinkedBindingBuilder#toProvider(Provider)}.
40  * In this case all constructors are, of course, ignored.
41  *
42  * <li>Static fields and methods of classes which any {@link Module} has
43  * specifically requested static injection for, using
44  * {@link Binder#requestStaticInjection}.
45  * </ul>
46  *
47  * In all cases, a member can be injected regardless of its Java access
48  * specifier (private, default, protected, public).
49  *
50  * @author crazybob@google.com (Bob Lee)
51  */

52 @Target JavaDoc({ METHOD, CONSTRUCTOR, FIELD })
53 @Retention JavaDoc(RUNTIME)
54 public @interface Inject {
55
56   /**
57    * If true, and the appropriate binding is not found,
58    * the Injector will skip injection of this method or field rather than
59    * produce an error. When applied to a field, any default value already
60    * assigned to the field will remain (guice will not actively null out the
61    * field). When applied to a method, the method will only be invoked if
62    * bindings for <i>all</i> parameters are found. When applied to a
63    * constructor, an error will result upon Injector creation.
64    */

65   boolean optional() default false;
66 }
67
Popular Tags