选择显示字体大小

ejb interface


  在开始写代码之前请在你的磁盘上建立一个目录,这个目录中存放所有的程序的源代码和编绎后的代码和压缩包以及所有的xml配置文件。 在我这里是这样的,我在c盘的根目录下建立了一个目录叫做hdsite,同时在这个目录中建立一个目录叫做src的存放所有的源代码和工程中需要的配置文件。在src下建立一个java的目录存放所有的java源文件,建立一个xml目录,存放所有的xml配置文件。所建的目录具体如下:

  hdsite/
  hdsite/src/
  hdsite/src/java/
  hdsite/src/java.net/chinacode/hello/
  hdsite/src/java.net/chinacode/hello/sejb/
  hdsite/src/java.net/chinacode/hello/web/
  hdsite/src/xml/
  hdsite/src/xml/ejb/
  hdsite/src/xml/web/

  首先我们来完成home interface,因为home interface只是简单的完成了一个固定的工作,所以一个session bean的home interface差不多都一个样子:

  package.net.chinacode.hello;

  import java.rmi.*;
  import javax.ejb.*;

  public interface hellohome extends ejbhome
  {
    public hello create() throws createexception, remoteexception;
  }

  我们将它存为hdsite/src/java.net/chinacode/hello中的hellohome.java。它继承了ejbhome的create方法,它返回hello这个ejb remote interface。哪么remote interface怎么写呢?我们首先需要确定我们的ejb要完成客户的什么样的功能。我们希望向ejb输入一个人名,由ejb返回hello 人名。调用ejb的方法名就叫做sayhello,哪么这个方法就应体现到remote interface中去,代码如下:

  package.net.chinacode.hello;

  import java.rmi.*;
  import javax.ejb.*;

  public interface hello extends ejbobject
  {
    public string sayhello(string strname) throws remoteexception;
  }

  我们将它存为hdsite/src/java.net/chinacode/hello中的hello.java。它只是说明了在ejb中会向用户提供的方法。哪么具体的实现则由ejb中的bean实体来完成,其代码如下:

  package.net.chinacode.hello;

  import java.rmi.*;
  import javax.ejb.*;

  public class hellobean extends object implements sessionbean{

  public string sayhello(string strname) {
  return "hello " + strname + "...";
  }

  public void ejbcreate() throws ejbexception, remoteexception {
  }

  public void ejbactivate() throws ejbexception, remoteexception {
  }

  public void ejbpassivate() throws ejbexception, remoteexception {
  }

  public void ejbremove() throws ejbexception, remoteexception {
  }

  public void setsessioncontext(sessioncontext context) throws ejbexception, remoteexception {
  }

  }

  我们将这个文件存为hdsite/src/java.net/chinacode/hello/hellobean.java。这里除了sayhello方法之外都是继承sessionbean类来实现的方法,一般情况下都是固定的。如果你需要在服务器ejb进行相关操作时要在bean中进行一些操作,哪么你可以在相应的ejbcreate、ejbremove这样的方法中写入自己的代码。好了,这三个就是我们的ejb的三个组成部分了,我们还需要给orion一个xml文件,在这个xml文件中说明我们要使用的ejb框架。这个xml文件的内容如下:

  <?xml version="1.0"?>
  

  <ejb-jar>
  <display-name>hd test ejb (ejb module)</display-name>
  <description>hd ejb sampale</description>
  <enterprise-beans>
  <session>
  <display-name>the helloejb session bean</display-name>
  <ejb-name.net.chinacode.hello.hello</ejb-name>
  <home.net.chinacode.hello.hellohome</home>
  <remote.net.chinacode.hello.hello</remote>
  <ejb-class.net.chinacode.hello.hellobean</ejb-class>
  <session-type>stateless</session-type>
  </session>
  </enterprise-beans>
  <assembly-descriptor>
  <security-role>
  <description>users</description>
  <role-name>users</role-name>
  </security-role>
  </assembly-descriptor>

  </ejb-jar>

  这个xml文件说明.net.chinacode.hello.hello这个ejb框架。我来看看在enterprise-beans段中的一个session段说明了一个session bean的结构,说明了这个ejb的home internface、bean class、remote interface,同时也向orion说明这个session bean的类型是stateless。我们把这个文件存入hdsite/src/xml/ejb/ejb-jar.xml文件中。这样我们就完成了一个系统中的ejb这部分。


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons