The EJBMetaData Class

   

The EJBMetaData Class

Another class that is generated by the tools provided by the container provider is a class that implements the javax.ejb.EJBMetaData interface. This interface, or rather the class that implements this interface, is used to discover, sort of dynamically, meta-information about the EJB object for which it is obtained. This interface and resulting container class that is created are used for two primary purposes:

  • Can be used by development tools that need to discover information about deployed EJB objects.

  • Can be used by clients using a scripting language to access EJB objects.

The interface contains the methods listed in Table 3.4.

Table 3.4. The Methods for javax.ejb.EJBMetaData Interface

Return

Method

Description

EJBHome

getEJBHome

Obtain the home object.

Class

getHomeInterfaceClass

Obtain the class for the EJB home interface.

Class

getPrimaryKeyClass

Obtain the class for the EJB primary key.

Class

getRemoteInterfaceClass

Obtain the class for the EJB remote interface.

boolean

isSession

Test whether the EJB is a session bean.

boolean

isStatelessSession

Test whether the EJB is a stateless session bean.

Caution

Some of the methods on the EJBMetaData class are specific to certain bean types and will cause exceptions if sent to the wrong bean. For example, if you call getPrimaryKeyClass on a session bean, a java.lang.RuntimeException will be thrown. You should first use the isSession method to determine the bean type before calling the getPrimaryKeyClass method.


You can obtain an instance of the EJBMetaData class by calling the getEJBMetaData method on a remote home interface of an enterprise bean.

Note

Because the EJBMetaData class is designed for remote clients specifically , it is not available to local clients.


The following code fragment gives a small example of how to do this:

 // For this code fragment, we assume that the remote home  // Interface has been acquired correctly  // Get the meta data for the bean  EJBMetaData metData = orderFulfillmentProcessorHome.getEJBMetaData(); 

The EJBMetaData object returned to a client is not a remote interface. It's a value object that is a valid RMI/IIOP value type because it's serialized to the client. In fact, the container can use the same EJBMetaData object for all enterprise beans of the same type because the metadata for all instances of the same class should be the same. However, the specification does not mandate this behavior.



Special Edition Using Enterprise JavaBeans 2.0
Special Edition Using Enterprise JavaBeans 2.0
ISBN: 0789725673
EAN: 2147483647
Year: 2000
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net