Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package javax.annotation; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import java.lang.annotation.*; |
aoqi@0 | 29 | import static java.lang.annotation.ElementType.*; |
aoqi@0 | 30 | import static java.lang.annotation.RetentionPolicy.*; |
aoqi@0 | 31 | |
aoqi@0 | 32 | /** |
aoqi@0 | 33 | * The Resource annotation marks a resource that is needed |
aoqi@0 | 34 | * by the application. This annotation may be applied to an |
aoqi@0 | 35 | * application component class, or to fields or methods of the |
aoqi@0 | 36 | * component class. When the annotation is applied to a |
aoqi@0 | 37 | * field or method, the container will inject an instance |
aoqi@0 | 38 | * of the requested resource into the application component |
aoqi@0 | 39 | * when the component is initialized. If the annotation is |
aoqi@0 | 40 | * applied to the component class, the annotation declares a |
aoqi@0 | 41 | * resource that the application will look up at runtime. <p> |
aoqi@0 | 42 | * |
aoqi@0 | 43 | * Even though this annotation is not marked Inherited, deployment |
aoqi@0 | 44 | * tools are required to examine all superclasses of any component |
aoqi@0 | 45 | * class to discover all uses of this annotation in all superclasses. |
aoqi@0 | 46 | * All such annotation instances specify resources that are needed |
aoqi@0 | 47 | * by the application component. Note that this annotation may |
aoqi@0 | 48 | * appear on private fields and methods of superclasses; the container |
aoqi@0 | 49 | * is required to perform injection in these cases as well. |
aoqi@0 | 50 | * |
aoqi@0 | 51 | * @since Common Annotations 1.0 |
aoqi@0 | 52 | */ |
aoqi@0 | 53 | @Target({TYPE, FIELD, METHOD}) |
aoqi@0 | 54 | @Retention(RUNTIME) |
aoqi@0 | 55 | public @interface Resource { |
aoqi@0 | 56 | /** |
aoqi@0 | 57 | * The JNDI name of the resource. For field annotations, |
aoqi@0 | 58 | * the default is the field name. For method annotations, |
aoqi@0 | 59 | * the default is the JavaBeans property name corresponding |
aoqi@0 | 60 | * to the method. For class annotations, there is no default |
aoqi@0 | 61 | * and this must be specified. |
aoqi@0 | 62 | */ |
aoqi@0 | 63 | String name() default ""; |
aoqi@0 | 64 | |
aoqi@0 | 65 | /** |
aoqi@0 | 66 | * The name of the resource that the reference points to. It can |
aoqi@0 | 67 | * link to any compatible resource using the global JNDI names. |
aoqi@0 | 68 | * |
aoqi@0 | 69 | * @since Common Annotations 1.1 |
aoqi@0 | 70 | */ |
aoqi@0 | 71 | |
aoqi@0 | 72 | String lookup() default ""; |
aoqi@0 | 73 | |
aoqi@0 | 74 | /** |
aoqi@0 | 75 | * The Java type of the resource. For field annotations, |
aoqi@0 | 76 | * the default is the type of the field. For method annotations, |
aoqi@0 | 77 | * the default is the type of the JavaBeans property. |
aoqi@0 | 78 | * For class annotations, there is no default and this must be |
aoqi@0 | 79 | * specified. |
aoqi@0 | 80 | */ |
aoqi@0 | 81 | Class<?> type() default java.lang.Object.class; |
aoqi@0 | 82 | |
aoqi@0 | 83 | /** |
aoqi@0 | 84 | * The two possible authentication types for a resource. |
aoqi@0 | 85 | */ |
aoqi@0 | 86 | enum AuthenticationType { |
aoqi@0 | 87 | CONTAINER, |
aoqi@0 | 88 | APPLICATION |
aoqi@0 | 89 | } |
aoqi@0 | 90 | |
aoqi@0 | 91 | /** |
aoqi@0 | 92 | * The authentication type to use for this resource. |
aoqi@0 | 93 | * This may be specified for resources representing a |
aoqi@0 | 94 | * connection factory of any supported type, and must |
aoqi@0 | 95 | * not be specified for resources of other types. |
aoqi@0 | 96 | */ |
aoqi@0 | 97 | AuthenticationType authenticationType() default AuthenticationType.CONTAINER; |
aoqi@0 | 98 | |
aoqi@0 | 99 | /** |
aoqi@0 | 100 | * Indicates whether this resource can be shared between |
aoqi@0 | 101 | * this component and other components. |
aoqi@0 | 102 | * This may be specified for resources representing a |
aoqi@0 | 103 | * connection factory of any supported type, and must |
aoqi@0 | 104 | * not be specified for resources of other types. |
aoqi@0 | 105 | */ |
aoqi@0 | 106 | boolean shareable() default true; |
aoqi@0 | 107 | |
aoqi@0 | 108 | /** |
aoqi@0 | 109 | * A product specific name that this resource should be mapped to. |
aoqi@0 | 110 | * The name of this resource, as defined by the <code>name</code> |
aoqi@0 | 111 | * element or defaulted, is a name that is local to the application |
aoqi@0 | 112 | * component using the resource. (It's a name in the JNDI |
aoqi@0 | 113 | * <code>java:comp/env</code> namespace.) Many application servers |
aoqi@0 | 114 | * provide a way to map these local names to names of resources |
aoqi@0 | 115 | * known to the application server. This mapped name is often a |
aoqi@0 | 116 | * <i>global</i> JNDI name, but may be a name of any form. <p> |
aoqi@0 | 117 | * |
aoqi@0 | 118 | * Application servers are not required to support any particular |
aoqi@0 | 119 | * form or type of mapped name, nor the ability to use mapped names. |
aoqi@0 | 120 | * The mapped name is product-dependent and often installation-dependent. |
aoqi@0 | 121 | * No use of a mapped name is portable. |
aoqi@0 | 122 | */ |
aoqi@0 | 123 | String mappedName() default ""; |
aoqi@0 | 124 | |
aoqi@0 | 125 | /** |
aoqi@0 | 126 | * Description of this resource. The description is expected |
aoqi@0 | 127 | * to be in the default language of the system on which the |
aoqi@0 | 128 | * application is deployed. The description can be presented |
aoqi@0 | 129 | * to the Deployer to help in choosing the correct resource. |
aoqi@0 | 130 | */ |
aoqi@0 | 131 | String description() default ""; |
aoqi@0 | 132 | } |