⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch01s11.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
字号:
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Review the EJB Classes</title><link rel="stylesheet" href="styles.css" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets Vimages/callouts/"><link rel="home" href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html" title="JBoss 3.0 Documentation"><link rel="up" href="ch01.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01.html" title="Chapter 1. First steps"><link rel="previous" href="ch01s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s10.html" title="EJBs: review"><link rel="next" href="ch01s12.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s12.html" title="The deployment descriptor"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="jboss.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss.gif" border="0"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch01.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch01s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s10.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch01s12.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s12.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table><div class="section"><a name="d0e274"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="d0e274"></a>Review the EJB Classes</h2></div></div><p>We need three classes: the remote interface, the home interface, and the bean implementation.
The remote interface in this example is very simple and given in the following figure.</p><div class="figure"><p><a name="d0e279"></a><b>Figure 1.3. Remote interface for the interest EJB, file name Interest.java</b></p><pre class="programlisting">package org.jboss.docs.interest;

import javax.ejb.EJBObject;
import java.rmi.RemoteException;

/**
This interface defines the `Remote' interface for the `Interest' EJB. Its
single method is the only method exposed to the outside world. The class
InterestBean implements the method.
*/
public interface Interest extends EJBObject 
{
   /**
   Calulates the compound interest on the sum `principle', with interest rate per
   period `rate' over `periods' time periods. This method also prints a message to
   standard output; this is picked up by the EJB server and logged. In this way we
   can demonstrate that the method is actually being executed on the server,
   rather than the client.
   */
   public double calculateCompoundInterest(double principle, 
				double rate, double periods) throws RemoteException;
}</pre></div><p> The remote interface specifies only one `business method' 
calculateCompoundInterest.   The home interface is even simpler and is given in the next figure. </p><div class="figure"><p><a name="d0e286"></a><b>Figure 1.4. Home interface for the interest EJB, file name InterestHome.java</b></p><pre class="programlisting">package org.jboss.docs.interest;

import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

/**
This interface defines the 'home' interface for the 'Interest' EJB. 
*/
public interface InterestHome extends EJBHome 
{
   /**
   Creates an instance of the `InterestBean' class on the server, and returns a
   remote reference to an Interest interface on the client. 
   */
   Interest create() throws RemoteException, CreateException;
}</pre></div><p>Finally, the bean implementation class is given in the next figure.</p><div class="figure"><p><a name="d0e293"></a><b>Figure 1.5. Implementation class for the interest EJB, file name InterestBean.java</b></p><pre class="programlisting">package org.jboss.docs.interest;

import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

/**
 This class contains the implementation for the 'calculateCompoundInterest'
 method exposed by this Bean. It includes empty method bodies for the methods
 prescribe by the SessionBean interface; these don't need to do anything in this
 simple example.
 */
public class InterestBean implements SessionBean
{
   /**
   Calulates the compound interest on the sum `principle', with interest rate per
   period `rate' over `periods' time periods. This method also prints a message to
   standard output; this is picked up by the EJB server and logged. In this way we
   can demonstrate that the method is actually being executed on the server,
   rather than the client.
    */
   public double calculateCompoundInterest(double principle,
      double rate, double periods)
   {
      System.out.println("Someone called `calculateCompoundInterest!'");
      return principle * Math.pow(1+rate, periods) - principle;
   }

   /** Empty method body
    */
   public void ejbCreate()
   {}
   /** Every ejbCreate() method ALWAYS needs a corresponding 
       ejbPostCreate() method with exactly the same parameter types.
    */
   public void ejbPostCreate()
   {}
   /** Empty method body
    */
   public void ejbRemove()
   {}
   /** Empty method body
    */
   public void ejbActivate()
   {}
   /** Empty method body
    */
   public void ejbPassivate()
   {}
   /** Empty method body
    */
   public void setSessionContext(SessionContext sc)
   {}
}</pre></div><p>Notice that most of the methods are empty; they have to exist because 
they're specified by the SessionBean interface, but they not needed for
this simple example EJB.</p></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch01.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch01s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s10.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch01s12.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch01s12.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -