1 /*
   2  * Copyright (c) 2005, 2013, 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 
  26 package javax.annotation;
  27 
  28 import java.lang.annotation.*;
  29 import static java.lang.annotation.ElementType.*;
  30 import static java.lang.annotation.RetentionPolicy.*;
  31 
  32 /**
  33  * The Resource annotation marks a resource that is needed
  34  * by the application.  This annotation may be applied to an
  35  * application component class, or to fields or methods of the
  36  * component class.  When the annotation is applied to a
  37  * field or method, the container will inject an instance
  38  * of the requested resource into the application component
  39  * when the component is initialized.  If the annotation is
  40  * applied to the component class, the annotation declares a
  41  * resource that the application will look up at runtime. <p>
  42  *
  43  * Even though this annotation is not marked Inherited, deployment
  44  * tools are required to examine all superclasses of any component
  45  * class to discover all uses of this annotation in all superclasses.
  46  * All such annotation instances specify resources that are needed
  47  * by the application component.  Note that this annotation may
  48  * appear on private fields and methods of superclasses; the container
  49  * is required to perform injection in these cases as well.
  50  *
  51  * @since 1.6, Common Annotations 1.0
  52  */
  53 @Target({TYPE, FIELD, METHOD})
  54 @Retention(RUNTIME)
  55 public @interface Resource {
  56     /**
  57      * The JNDI name of the resource.  For field annotations,
  58      * the default is the field name.  For method annotations,
  59      * the default is the JavaBeans property name corresponding
  60      * to the method.  For class annotations, there is no default
  61      * and this must be specified.
  62      */
  63     String name() default "";
  64 
  65     /**
  66      * The name of the resource that the reference points to. It can
  67      * link to any compatible resource using the global JNDI names.
  68      *
  69      * @since 1.7, Common Annotations 1.1
  70      */
  71 
  72     String lookup() default "";
  73 
  74     /**
  75      * The Java type of the resource.  For field annotations,
  76      * the default is the type of the field.  For method annotations,
  77      * the default is the type of the JavaBeans property.
  78      * For class annotations, there is no default and this must be
  79      * specified.
  80      */
  81     Class<?> type() default java.lang.Object.class;
  82 
  83     /**
  84      * The two possible authentication types for a resource.
  85      */
  86     enum AuthenticationType {
  87             CONTAINER,
  88             APPLICATION
  89     }
  90 
  91     /**
  92      * The authentication type to use for this resource.
  93      * This may be specified for resources representing a
  94      * connection factory of any supported type, and must
  95      * not be specified for resources of other types.
  96      */
  97     AuthenticationType authenticationType() default AuthenticationType.CONTAINER;
  98 
  99     /**
 100      * Indicates whether this resource can be shared between
 101      * this component and other components.
 102      * This may be specified for resources representing a
 103      * connection factory of any supported type, and must
 104      * not be specified for resources of other types.
 105      */
 106     boolean shareable() default true;
 107 
 108     /**
 109      * A product specific name that this resource should be mapped to.
 110      * The name of this resource, as defined by the <code>name</code>
 111      * element or defaulted, is a name that is local to the application
 112      * component using the resource.  (It's a name in the JNDI
 113      * <code>java:comp/env</code> namespace.)  Many application servers
 114      * provide a way to map these local names to names of resources
 115      * known to the application server.  This mapped name is often a
 116      * <i>global</i> JNDI name, but may be a name of any form. <p>
 117      *
 118      * Application servers are not required to support any particular
 119      * form or type of mapped name, nor the ability to use mapped names.
 120      * The mapped name is product-dependent and often installation-dependent.
 121      * No use of a mapped name is portable.
 122      */
 123     String mappedName() default "";
 124 
 125     /**
 126      * Description of this resource.  The description is expected
 127      * to be in the default language of the system on which the
 128      * application is deployed.  The description can be presented
 129      * to the Deployer to help in choosing the correct resource.
 130      */
 131     String description() default "";
 132 }