论坛登陆 用户名:  密 码:
设为首页  加入收藏
08年北京名校秋季招生
名牌院校免试入学宽进严出,突破考分限制,名校与你零距离,以下院校按报名先后顺序录取,24小时网上报名覆盖全国
  您现在的位置: 中国教育招生在线 >> IT >> JAVA认证 >> IT正文
Tutorial for building J2EE Applications using JBOSS and ECLIPSE(3)
 作者:佚名     2007-3-14 16:17:59        来源:不详  浏览次数:

 

 

 

 

 

 

 

 

Chapter 3.

Creating a Stateless Session Bean

This chapter covers how to create a stateless session EJB component. This bean will be responsible for authenticating the user by communicating with the database using Data Access Object (DAO) which encapsulates Java Database Connectivity (JDBC) code. A DAO has all attributes (fields) and behavior (methods) corresponding to the bean it is being used for.






All customers, supplier and manager of MyStore have been assigned a unique username and userid to access services of MyStore, but in order to access these services all these entities have to first login into the system (MyStore). The method for authentication is named loginUser, which takes two String parameters, username and password and returns the userID if authentication is successful.

Note : This method loginUser is a business method, normally business methods carry out operations or processing on values EJB components. From clients perspective, clients can see only business methods and invoke them on bean.

Tasks :

  1. Create a J2EE project named MyStore.

  2. Create a Stateless Session Bean named StoreAccess.

  3. Add a business method in bean named loginUser with the following signature

    public String loginUser (String username, String password)

  4. Create a DAO named StoreAccessDAOImpl under package au.com.tusc.dao. Generate the DAO interface.

  5. Implement the method named loginUser, generated in DAO interface, in StoreAccessDAOImpl. Method signature is

    public String loginUser (String username, String password)

  6. Add callback methods and implement them.

  7. Deploy StoreAccess bean.

  8. Create your test client named SessionClient under package au.com.tusc.client.

  9. Run your client and test the bean.

Create J2EE Project :

Now, lets start to write our first component of this tutorial.

Go to File > New > LombozJ2EE Project, project creation wizard will pop up.

Insert Project Name MyStore > Next .

Under Java Settings Check source, should be MyStore/src , libraries pointing to $JAVA_HOME > Go Next as shown in fig below.

Note: This step is shown in chapter1, as there is a bug in eclipse 2.1, so its important that you check your library settings are right.




Under Create J2EE Module, select Web Modules tab > Add.., enter Module name as OnlineStore > OK as shown in figure below.




Under Create J2EE Module, select EJB Modules tab > Add.., enter Module name as MyStoreMgr > OK .

Under Create J2EE Module, select Targeted Servers tab > Select JBOSS 3.2.1 ALL > Add.. > Finish.



Create Stateless Bean :


Go To Package Explorer > Expand Mystore (project) node > select src, right click and menu will pop up.

On pop up menu > New > Lomboz EJB Creation Wizard.

Enter package name au.com.tusc.session, bean name StoreAccess and select bean type as stateless > Finish.

This will create a package named au.com.tusc.session under src and StoreAccessBean under that package as shown in the figure below.




As we can see from the figure below it has created a class level tag @ejb.bean, which has assigned the bean type, name and its JNDI name which will be generated in Home interface. This tag will also generate deployment descriptors in ejb-jar.xml and jboss.xml file as well once you generate your EJB classes, which is covered later on in this chapter.




Note: It will generate the bean name, jndi-name and type of bean in the file. Also, the name of file is appended with word 'Bean' as you gave the name of the bean as StoreAccess only. Again, be careful with naming conventions, specifying the bean name only in the wizard without adding the word 'Bean' to the name as the wizard appends that for you.

Expand MyStoreMgr/META-INF node under Package Explorer. You will find there are seven files which are generated by Lomboz using Xdoclet as shown in the figure below.




Now we are going to generate all the interfaces including Home, Remote, DAO and other helper classes. We will explain why later on, but for the time being just follow the steps.

But before we get too excited, there are a few concepts to cover here.

Go to MyStoreMgr/META-INF > select and open ejbGenerate.xml.

Note: Lomboz uses this file to generate required interfaces and helper classes, so in the event that you have special needs then you will have to customize this file. See ejbdoclet under the Xdoclet documentation.

'ejbGenerate.xml' file is generated only once when you create your EJB module. So any changes made in this file will be reflected even if you modify your bean class and generate your classes again and again.

As we can see from the code snippet of file shown in figure at right, there are following tags defined.

<dataobject/> is defined for generating data Objects for holding values of EJB component's persistent fields, which correspond to columns in the associated table in the database.

Note: <dataobject/> has been deprecated in favour of Value Object which is more powerful in terms of relationships (1-1, 1-n and n-m).

<utilobject/> Creates method for generating GUID and for accessing Remote and Local Home objects.

<remoteinterface/> Generates remote interfaces for EJBs.

<localinterface/> Generates local interfaces for EJBs.

<homeinterface /> Generates remote home interfaces for EJBs.

<localhomeinterface/>Generates local home interfaces for EJBs.

<entitypk/>Generates primary key classes for entity EJBs.

<entitybmp/>Creates entity bean classes for BMP entity EJBs.

<entitycmp/>

<session/> Generates session bean class.

Note : There is no tag for generating a DAO.

So, we have to include this <dao/> tag.

For details, please refer ejbdoclet under Xdoclet documentation.


责任编辑:lss
  相关新闻
IT证书:谁OUT?谁IN?
JSFToolbox--用Dreamweaver开发JSF
WebWork拦截器(Interceptor)使用方法
Google回应维亚康母的起诉 称YouTube未侵权
Struts开发指南之Taglib的初步了解
Struts 中 html:options 的使用
允许内部用户使用Outlook Web Access
在Struts框架下使用时间类型
看看如何在Struts应用中施展AJAX魔法
媒体巨头起诉Google和YouTube 赔偿10亿美元
IT证书:谁OUT?谁IN?
Oracle发布免费数据库管理工具Raptor
在ORACLE中实现SELECT TOP N的方法
Google回应维亚康母的起诉 称YouTube未侵权
MTV网络起诉YouTube获时代华纳等同行支持
分析:TOM在线私有化给美国投资者敲警钟
媒体巨头起诉Google和YouTube 赔偿10亿美元
了解 Struts 框架的全新后代--Shale
Struts开发指南之Taglib的初步了解
在Struts框架下使用时间类型
  评论
现在有100人对本文发表评论
查看所有评论
 
推  荐
 
100本成功必读热销书
热门招生
  北京文理研修学院   前进大学
  北京明园大学   北京建设大学
  北京邮电大学世纪学院   北方工商管理学院
  联想软件定向委培班   香港数码动画学院
  青年企业管理研修学院   北京华夏管理学院
热门培训
网络化办公专家培训认证 电子科技大学软件学院
软件测试工程师培训认证 北大青鸟十大授权培训
IT硬件工程师培训认证班 北京环球雅思荷兰预科
JAVA开发工程师培训 潜能时代IT服务管理培训
网络信息化工程师培训 清华大学继续教育学院
论坛精选
 
有些细节是男人也该注意的风度!最容易读错的字
某强人手机里保存的30条短信 中国十大高薪职业
最感人的十大韩剧经典台词 嫁给工程师的N个理由
爆强!只有一句话的鬼故事 转贴教你如何做妖精
 女人一定要記住的話 女人最好别嫁给最爱的男人
城市联盟
 大连 上海 天津 广州 西安 深圳  天津  青岛  大连  福州  沈阳  青海  连云港  南京  吉林  厦门  威海  辽宁  呼和浩特
Copyright © 2006   www.edu999.com   All rights reserved. 中国教育招生在线  版权所有
北京市通信管理局[2004]字第552号函    京ICP证040442号