JNDI 备忘录

来源:互联网 发布:mac双系统安装win10 编辑:程序博客网 时间:2024/06/10 01:42
0. java:comp/env means java:component/environment

1. example, the JNDI LinkRef mechanism to create a symbolic link to the actual JNDI name of the target object.

2. The env-entry element consists of:

  • an optional description of the environment entry
  • the environment entry name relative to the java:comp/env context
  • the expected Java programming language type of the environment entry value (the type of the object returned from the JNDI lookup method)
  • and an optional environment entry value.

3. An environment entry is scoped to the application component whose declaration contains the env-entry element. This means that:

  • the environment entry is not accessible from other application components at runtime
  • and that other application components may define env-entry elements with the same env-entry-name without causing a name conflict.

4. This specification recommends, but does not require, that all resource manager connection factory references be organized in the subcontexts of the application component’s environment, using a different subcontext for each resource manager type

all enterprise beans references java:comp/env/ejb all JDBC™ DataSource references java:comp/env/jdbc all JMS connection factories java:comp/env/jms all JavaMail connection factories java:comp/env/mail all URL connection factories java:comp/env/url

5. the Application Component Provider must declare all the EJB references using the ejb-ref elements of the deployment descriptor.

<ejb-ref>

    <description>This is a reference to ... </description>

    <ejb-ref-name>ejb/Product</ejb-ref-name>

    <ejb-ref-type>Entity</ejb-ref-type>

    <home>com.acme.products.ProductHome</home>

    <remote>com.acme.products.Product</remote>

    <ejb-link>../products/product.jar#ProductEJB</ejb-link>

</ejb-ref>

6. The Application Component Provider must use the

  • javax.sql.DataSource resource manager connection factory type for obtaining JDBC API connections.
  • javax.jms.QueueConnectionFactory, the javax.jms.TopicConnectionFactory, or the javax.jms.ConnectionFactory for obtaining JMS connections.
  • javax.mail.Session resource manager connection factory type for obtaining JavaMail API connections.
  • java.net.URL resource manager connection factory type for obtaining URL connections.

7. The Application Component Provider can specify that connections obtained from a resource manager connection factory reference are not shareable by specifying the value of the res-sharing-scope deployment descriptor element to be Unshareable.

8. the Application Component Provider must declare all the resource manager connection factory references in the deployment descriptor using the resource-ref elements.

<resource-ref>

    <description>A data source for the database in which the EmployeeService enterprise bean will record a log of all transactions. </description>

    <res-ref-name>jdbc/EmployeeAppDB</res-ref-name>

    <res-type>javax.sql.DataSource</res-type>

    <res-auth>Container</res-auth>

    <res-sharing-scope>Shareable</res-sharing-scope>

</resource-ref>

9. the Application Component Provider must declare all references to administered objects associated with resources using the resource-env-ref elements of the deployment descriptor.

10. the Application Component Provider should declare all references to message destinations using the message-destination-ref elements of the deployment descriptor.

11. public void updateData(...) {

    // Context initCtx = new InitialContext();

    // Look up the UserTransaction object.

    UserTransaction tx = (UserTransaction)initCtx.lookup("java:comp/UserTransaction");

    // Start a transaction.

    tx.begin();

    // Perform transactional operations on data.

    // Commit the transaction.

    tx.commit();

}

12. The container is required to provide the java:comp/ORB name for all components except applets.

13. The simple name binding is guaranteed to succeed if lookup is within the same server or when connected directly to the name space of the server containing the target of the lookup. It can be used in a servlet or EJB, if it is certain that the object is located on the same application server.

14. The application component environment is referred to as the ENC, the enterprise naming context.An application component instance locates the ENC using the JNDI API. An application component instance creates a javax.naming.InitialContext object by using the no argument constructor and then looks up the naming environment under the name java:comp/env. The application component's environment entries are stored directly in the ENC, or in its subcontexts.
An application component environment is a local environment that is accessible only by the component when the application server container thread of control is interacting with the application component. This means that an EJB Bean1 cannot access the ENC elements of EJB Bean2, and vice versa. Similarly, Web application Web1 cannot access the ENC elements of Web application Web2 or Bean1 or Bean2 for that matter. Also, arbitrary client code, whether it is executing inside of the application server VM or externally cannot access a component's java:comp JNDI context. The purpose of the ENC is to provide an isolated, read-only namespace that the application component can rely on regardless of the type of environment in which the component is deployed. The ENC must be isolated from other components because each component defines its own ENC content. Components A and B, for example,may define the same name to refer to different objects.

 
原创粉丝点击