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