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

📄 ch10s29.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>How to generate Enterprise Java Beans with EJBDoclet (XDoclet)</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="ch10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10.html" title="Chapter 10. Development Tools and IDE Integration"><link rel="previous" href="ch10s25.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s25.html" title="Using Verifier in Ant"><link rel="next" href="ch11.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch11.html" title="Chapter 11. JBoss in production"></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="ch10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch10s25.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s25.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch11.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch11.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="howtoejbdoclet"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="howtoejbdoclet"></a>How to generate Enterprise Java Beans with EJBDoclet (XDoclet)</h2></div><div><h2 class="subtitle">Under construction(!)</h2></div></div><p>Author:
      <span class="author">Ingo Bruell</span>
      <tt>&lt;<a href="mailto:ibruell@gmx.de">ibruell@gmx.de</a>&gt;</tt>
   </p><p>
    EJBDoclet is a tool that facilitates coding Enterprise Java Beans. You only
    have to code <span class="emphasis"><i>one</i></span> file to generate automatically the needed
    interfaces and descriptor files. By using <tt>ant</tt>
    and the <tt>verifier</tt> it is very easy to produce correct beans.
  </p><p>
    EJBDoclet is an OpenSource project started by Rickard Oberg and located at
    <a href="javascript:if(confirm('http://sourceforge.net/projects/ejbdoclet  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://sourceforge.net/projects/ejbdoclet'" tppabs="http://sourceforge.net/projects/ejbdoclet" target="_top">
    http://sourceforge.net/projects/ejbdoclet</a>.
  </p><p>
    EJBDoclet has been renamed XDoclet and a new project with this name has been started.
    XDoclet 1.0 was released in September 2001. Any questions about
    EJBDoclet and XDoclet must go to the new XDoclet mailing lists
    hosted at <a href="javascript:if(confirm('http://sourceforge.net/projects/xdoclet  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://sourceforge.net/projects/xdoclet'" tppabs="http://sourceforge.net/projects/xdoclet" target="_top">
    http://sourceforge.net/projects/xdoclet</a>
  </p><div class="section"><a name="ejbdoclet-requirements"></a><div class="titlepage"><div><h3 class="title"><a name="ejbdoclet-requirements"></a>Requirements</h3></div></div><p>
      You need to download the <tt>ejbdoclet.jar</tt> file and
      put it somewhere in you classpath. I think that the use of Ant is highly recommended
      (and, for now, it is the only way to use EJBDoclet!).
    </p><p>
      The <tt>tools.jar</tt> file from the J2SDK is also needed to
      call Javadoc, so place it in the classpath, too.
    </p></div><div class="section"><a name="ejbdoclet-createingthebean"></a><div class="titlepage"><div><h3 class="title"><a name="ejbdoclet-createingthebean"></a>Creating the Bean as a Template</h3></div></div><p>
      EJBDoclet uses Javadoc tags and the Javadoc mechanism to generate the needed files
      out of a <span class="emphasis"><i>template</i></span>. Here there is an example of a section for an
      Entity Bean class:

      <pre class="programlisting">
/**
 *   This is an account bean. It is an example of how to use the EJBDoclet tags.
 *
 *   @ejb:entity-cmp <a name="ejbdoclet-entity-cmp"></a><img src="1.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/1.png" alt="1" border="0">
 *   @ejb:ejb-name bank/Account
 *   @ejb:jndi-name ejb/bank/Account
 *   @ejb:finder Collection findAll() <a name="ejbdoclet-finder"></a><img src="2.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/2.png" alt="2" border="0">
 *   @ejb:finder Collection findByOwner(Customer owner)
 *   @ejb:finder Collection findLargeAccounts(int balance)
 *   @ejb:env-entry foo 1234 java.lang.Integer <a name="ejbdoclet-envvar"></a><img src="3.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/3.png" alt="3" border="0">
 *   @ejb:ejb-ref bank/Customer <a name="ejbdoclet-ref"></a><img src="4.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/4.png" alt="4" border="0">
 *   @ejb:security-role-ref admin Administrator
 *   @ejb:permission Teller
 *   @ejb:transaction Required
 *   @ejb:use-soft-locking
 *
 *   JBoss specific <a name="ejbdoclet-jboss"></a><img src="5.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/5.png" alt="5" border="0">
 *   @jboss:container-configuration Standard CMP EntityBean
 *
 *   JBoss/JAWS CMP specific <a name="ejbdoclet-jaws"></a><img src="6.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/6.png" alt="6" border="0">
 *   @jboss:table-name account
 *   @jboss:create-table true
 *   @jboss:remove-table true
 *   @jboss:tuned-updates true
 *   @jboss:read-only false
 *   @jboss:finder-query findLargeAccounts $1 &gt; 1000
 *   @jboss:finder-order findLargeAccounts balance
 */
public abstract class AccountBean
{
      </pre>
      <div class="calloutlist"><a name="d0e7459"></a><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a name="d0e7460"></a><a href="#ejbdoclet-entity-cmp"><img src="1.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/1.png" alt="1" border="0"></a> </td><td valign="top" align="left"><p>
            Here is where it is specified that this is an Entity Bean
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7463"></a><a href="#ejbdoclet-finder"><img src="2.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/2.png" alt="2" border="0"></a> </td><td valign="top" align="left"><p>
            Definitions of the finder methods
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7466"></a><a href="#ejbdoclet-envvar"><img src="3.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/3.png" alt="3" border="0"></a> </td><td valign="top" align="left"><p>
            Easy definition of environment variables
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7469"></a><a href="#ejbdoclet-ref"><img src="4.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/4.png" alt="4" border="0"></a> </td><td valign="top" align="left"><p>
            Definition of references to other beans
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7472"></a><a href="#ejbdoclet-jboss"><img src="5.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/5.png" alt="5" border="0"></a> </td><td valign="top" align="left"><p>
            With these tags you can define JBoss-specific parameters
            (see the EJBDoclet documentation for more details about the tags).
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7475"></a><a href="#ejbdoclet-jaws"><img src="6.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/6.png" alt="6" border="0"></a> </td><td valign="top" align="left"><p>
            And here you can define JAWS-specific parameters
            (see the EJBDoclet documentation for more details about the tags).
          </p></td></tr></table></div>

      You can see that it is very easy to create the bean template. The JBoss- and JAWS-specific
      parts should only be used if the JBoss standard values do not fit.
    </p><p>
      Now you need to define the method level tags like this:
      <pre class="programlisting">
   /**
    * Create account.
    *
    * @ejb:permission Administrator <a name="ejbdoclet-permission"></a><img src="1.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/1.png" alt="1" border="0">
    */
   public AccountPK ejbCreate(AccountData data)
      throws CreateException
   {
   	  setId(data.getId());
      setData(data);

      return null;
   }

   /**
    * Id of this account.
    *
    * This is not remote since the primary key can be extracted by other means.
    *
    * @ejb:pk-field <a name="ejbdoclet-pk"></a><img src="2.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/2.png" alt="2" border="0">
    * @ejb:persistent-field
    *
    * @jboss:column-name pk
    */
   public abstract int getId();

   /**
    * Id of this account.
    *
    */
   public abstract void setId(int id);

   /**
    *  Owner of this account.
    *
    * @ejb:remote-method <a name="ejbdoclet-remote"></a><img src="3.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/3.png" alt="3" border="0">
    * @ejb:persistent-field <a name="ejbdoclet-persistent"></a><img src="4.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/4.png" alt="4" border="0">
    * @ejb:permission Administrator
    * @ejb:transaction Supports
    */
   public abstract Customer getOwner();

   /**
    *  Owner of this account.
    *
    */
   public abstract void setOwner(Customer owner);
      </pre>
      <div class="calloutlist"><a name="d0e7492"></a><table border="0" summary="Callout list"><tr><td width="5%" valign="top" align="left"><a name="d0e7493"></a><a href="#ejbdoclet-permission"><img src="1.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/1.png" alt="1" border="0"></a> </td><td valign="top" align="left"><p>
            Permissions can be defined at the method level with this tag
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7496"></a><a href="#ejbdoclet-pk"><img src="2.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/2.png" alt="2" border="0"></a> </td><td valign="top" align="left"><p>
            With @ejb:pk-field a primary key field is defined
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7499"></a><a href="#ejbdoclet-remote"><img src="3.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/3.png" alt="3" border="0"></a> </td><td valign="top" align="left"><p>
            @ejb:remote-method defines a remote method
          </p></td></tr><tr><td width="5%" valign="top" align="left"><a name="d0e7502"></a><a href="#ejbdoclet-persistent"><img src="4.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/4.png" alt="4" border="0"></a> </td><td valign="top" align="left"><p>
            An @ejb:persistent-field defines an attribute that should be stored
            persistently.
          </p></td></tr></table></div>
    </p></div><div class="section"><a name="ejbdoclet-calling"></a><div class="titlepage"><div><h3 class="title"><a name="ejbdoclet-calling"></a>Calling EJBDoclet</h3></div></div><p>
      For now there is no way to use EJBDoclet without Ant.
    </p></div><div class="section"><a name="ejbdoclet-ant"></a><div class="titlepage"><div><h3 class="title"><a name="ejbdoclet-ant"></a>Using EJBDoclet with Ant</h3></div></div><p>
      To use Ant you must download it from the <a href="javascript:if(confirm('http://jakarta.apache.org/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://jakarta.apache.org/'" tppabs="http://jakarta.apache.org/" target="_top">Apache
      Jakarta project</a>. For EJBDoclet only the <tt>ant.jar</tt> file is needed.
    </p><p>
      I prefer a project directory structure like the one JBoss uses:
      <pre class="programlisting">
        project
        +-build
        .  +-[...]
        +-dist
        .  +-[...]
        +-lib
        .  +-ant.jar
        .  +-ejbdoclet.jar
        .  +-[...]
        +-src
        .  +-resources
        .  .  +-test
        .  .  .  +-META-INF
        .  +-main
        .  .  +-test
        .  .  .  +-ejb
        .  .  .  .  +-AccountBean.java
        .  .  .  .  +-CustomerBean.java
      </pre>

      Here it is my Ant script (<tt>build.xml</tt>) that first
      generates the bean interfaces and the descriptor files
      and then compiles the Java files and packages them into a JAR file:

      <pre class="programlisting">
&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;!--
	$Revision: 3.0 $ $Date: 2001/11/18 20:10:58 $ $Author: gropi $
--&gt;
&lt;project name="test" default="main" basedir="../.."&gt;

   &lt;target name="init"&gt;
      &lt;property name="Name" value="TEST"/&gt;
      &lt;property name="name" value="test"/&gt;
      &lt;property name="version" value="1.0"/&gt;
      &lt;property name="encoding" value="ISO-8859-1"/&gt;
      &lt;property name="typemapping" value="Hypersonic SQL"/&gt;

⌨️ 快捷键说明

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