uCosminexus Application Server, API Reference Guide

[Contents][Index][Back][Next]

2.2.3 @Resource

Organization of this subsection
(1) Description
(2) Element

(1) Description

Declare the resource reference. You can specify in a class, method, and field. When specified in a method or field, the annotation becomes a target for Dependency Injection. However, the method must be the set method.

(2) Element

The following table lists the elements of @Resource:

Element name Function
name Specify the name of resource reference. The specified name is used as a JNDI name. You can omit the element description if the annotation is specified in a method or field.
type Specify the Java type of a resource. You can omit the element description if the annotation is specified in a method or field.
authenticationType Specify the authentication type used in the resource.
shareable Specify whether the resource is to be shared.
mappedName Specify the resource display name and queue name for specifying the referenced resource.
lookup Specify the Portable Global JNDI name of any other resource that you reference or a resource alias.
description Specify the resource description.

The details of each element are as follows:

(a) name element

Type
String

Description
Specify the name of resource reference. The specified name is used as a JNDI name. You can omit the element description if the annotation is specified in a method or field.
You can also specify a resource alias. For details on specifying a J2EE resource alias, see 2.6.6 Setting the optional names for the J2EE resources in the uCosminexus Application Server Common Container Functionality Guide.

Default value
  • When set in a method
    Property of the class name or set method in which the annotation is specified
  • When set in a field
    Class name or field name in which the annotation is specified
(b) type element

Type
Class

Description
Specify the Java type of a resource. You can omit the element description if the annotation is specified in a method or field.

Default value
  • When specified in a method
    Argument type of the method
  • When set in a field
    Field type

type element and the corresponding DD
As the type element differs from J2EE specifications, the corresponding DD changes depending on the set value (Java Type). The following table describes the corresponding DD that changes depending on the Java Type:

Table 2-28 Table for the corresponding DD depending on the type element

Type element DD tag corresponding to J2EE specifications DD tag supported with Cosminexus Application Server specifications#1
java.lang.String#2 Env-entry env-entry
java.lang.Character#2 env-entry env-entry
java.lang.Integer#2 env-entry env-entry
java.lang.Boolean#2 env-entry env-entry
java.lang.Double#2 env-entry env-entry
java.lang.Byte#2 env-entry env-entry
java.lang.Short#2 env-entry env-entry
java.lang.Long#2 env-entry env-entry
java.lang.Float#2 env-entry env-entry
javax.xml.rpc.Service service-ref Exception #3
javax.xml.ws.Service service-ref Exception #3
javax.jws.WebService service-ref Exception #3
javax.sql.DataSource resource-ref resource-ref
javax.jms.ConnectionFactory resource-ref resource-ref
javax.jms.QueueConnectionFactory resource-ref resource-ref
javax.jms.TopicConnectionFactory resource-ref resource-ref
javax.mail.Session resource-ref resource-ref
java.net.URL resource-ref Exception #3
javax.resource.cci.ConnectionFactory resource-ref resource-ref
org.omg.CORBA_2_3.ORB resource-ref resource-ref
Other connection factories defined by resource adapter resource-ref resource-env-ref
javax.jms.Queue message-destination-ref resource-env-ref
javax.jms.Topic message-destination-ref resource-env-ref
javax.resource.cci.InteractionSpec resource-env-ref Exception #3
javax.transaction.UserTransaction resource-env-ref resource-env-ref
javax.xml.ws.WebServiceContext Undefined resource-env-ref#4
All types other than those mentioned above#5 resource-env-ref resource-env-ref

#1
If !# is included in the mappedName element, correspond to <resource-env-ref>, irrespective of the Java Type.

#2
You cannot acquire a value from a standard DD, as a result, the value is displayed in the element file but DI is not performed.

#3
Exception in the case of import.

#4
With Application Server version 08-70 or earlier versions, this element is handled same as all types other than those mentioned above.

#5
With Application Server version 09-00, subclasses of the java.lang.Class and java.lang.Enum are not handled in the <env-entry> tag.

(c) authenticationType element

Type
AuthenticationType

Description
Specify the authentication type used in the resource.

Default value
CONTAINER
(d) shareable element

Type
boolean

Description
Specify whether the resource is to be shared.

Default value
true
(e) mappedName element

Type
String

Description
Specify the resource display name and queue name for specifying the referenced resource.
When characters other than single--byte alphanumeric characters and underscores (_) are to be included in the resource display name, replace them with underscores (_).

Default value
""

Setting conditions of the mappedName element
The setting conditions of the mappedName element change based on the type element. The following table describes the setting conditions of the mappedName element in @Resource:

Table 2-29 Setting conditions of mappedName() in @Resource

Setting condition (Java Type, resource) Availability#1
java.lang.String N
java.lang.Character N
java.lang.Integer N
java.lang.Boolean N
java.lang.Double N
java.lang.Byte N
java.lang.Short N
java.lang.Long N
java.lang.Float N
javax.xml.rpc.Service N
javax.sql.DataSource Y
javax.jms.ConnectionFactory Y
javax.jms.QueueConnectionFactory Y
javax.jms.TopicConnectionFactory Y
javax.mail.Session Y
java.net.URL N
javax.resource.cci.ConnectionFactory Y
org.omg.CORBA_2_3.ORB N
javax.jms.Queue#2 Y
javax.jms.Topic Y
javax.resource.cci.InteractionSpec N
javax.transaction.UserTransaction N
javax.ejb.EjbContext N
javax.ejb.SessionContext N
javax.ejb.TimerService N
JavaBeans resource Y

Legend:
Y: Can be used.
N: Cannot be used.

#1
Mapping to the object to be managed is established with the mappedName element, irrespective of the Java Type. Use !# to demarcate the display name of the resource adapter and the name of the object to be managed.

#2
If you use javax.jms.Queue when using TP1/Message Queue - Access or Cosminexus Reliable Messaging, use # as the delimiter of the resource adapter display name and queue display name.

(f) lookup attribute

Type
String

Description
Specify the Portable Global JNDI name of any other resource or a resource alias that you want to reference.

Default value
""
(g) description element

Type
String

Description
Specify the resource description.

Default value
""