
The application client model enables you to access enterprise beans and other resources (for example, JMS or database) from an application client. To use these resources (that is, to be able to invoke their methods), you must first obtain a reference to them. The resource and enterprise bean references are bound in the JNDI namespace and are obtained by performing a lookup operation in a relevant location in the naming.
To look up an enterprise bean or other resource reference (JMS, JDBC), use the following names:
The following code illustrates how you obtain the InitialContext:
try{context= new InitialContext(); }catch (NamingException ne) {System.out.println("Could not obtain naming: "+ ne.getMessage());return; } |
TheBeanHomebeanHome = (AppClientHome) context.lookup("java:comp/env/ejb/<ejb-ref-name>");TheBeanbean = beanHome.create(); |
The following code illustrates how to lookup a Queue- or a TopicConnectionFactory:
QueueConnectionFactoryqueueConnectionFactory = (QueueConnectionFactory) ctx.lookup("java:comp/env/<res-ref-name>");TopicConnectionFactorytopicConnectionFactory = (TopicConnectionFactory) ctx.lookup("java:comp/env/<res-ref-name"); |
To look up a Queue or a Topic destination, use the following model:
}TopictheTopic = (Topic) ctx.lookup("java:comp/env/<resource-env-ref-name");QueuetheQueue = (Queue) ctx.lookup("java:comp/env/<resource-env-ref-name"); |
The following code illustrates how to lookup a DataSource object:
DataSourceds = (DataSource) ctx.lookup("java:comp/env/<res-ref-name>"); |
You can invoke methods on the referenced enterprise bean, JMS or DataSource resource.
See also appclient-j2ee-engine.dtd