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

📄 4.mht

📁 Enterprise Java Bean的PPT文档,很好的东西.
💻 MHT
📖 第 1 页 / 共 5 页
字号:
  <COLGROUP>
  <COL width=3D180>
  <COL width=3D76>
  <THEAD>
  <TR vAlign=3Dtop>
    <TD width=3D"70%">
      <P><B>EJB interfaces and helper classes are generated under =
'ejbsrc'=20
      directory as shown on the right. </B></P>
      <P>Seven files are generated. </P>
      <P>StoreAccessState is our remote object interface.</P>
      <P>StoreAccessLocal is our local object interface.</P>
      <P>StoreAccessStateSession extends our bean class named=20
      StoreAccesStateBean.</P>
      <P>StoreAccessStateHome is our remote home interface.</P>
      <P>StoreAcessStateLocalHome is our local home interface.</P>
      <P>StoreAccessStateUtil is a helper class which has methods for =
accessing=20
      Home and LocalHome interface along with generating GUID.</P>
      <P>StoreAccesStateDAO is the DAO interface, which be implemented =
by=20
      StoreAccessDAOImpl under au.com.tusc.dao.</P>
      <P><B>StoreAccessStateDAO is generated by this tag declared in=20
      StoreAccesStateBean as shown below. If you don't declare this tag =
in that=20
      file it won't generate this interface.</B></P><PRE><FONT =
color=3D#3f5fbf> <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>@ejb.dao =
class=3Dau.com.tusc.sessionState.StoreAccessStateDAO</FONT></FONT></FONT>=

<FONT color=3D#3f5fbf> <FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
face=3DSans>impl-class=3Dau.com.tusc.dao.StoreAccessDAOImpl</FONT></FONT>=
</FONT></PRE>
      <P>Other files of interest which are generated are ejb-jar.xml' =
and=20
      jboss.xml' under MyStoreMgr/META-INF. </P></TD>
    <TD width=3D"30%">
      <P><IMG height=3D230=20
      =
src=3D"http://www.tusc.com.au/tutorial/images/chap4/GeneratedEJBFilesandD=
escriptors.png"=20
      width=3D258 align=3Dleft border=3D0 name=3DGraphic7><BR=20
  clear=3Dleft><BR></P></TD></TR></THEAD>
  <TBODY></TBODY></TABLE>
<TABLE cellSpacing=3D4 cellPadding=3D3 width=3D"100%" border=3D0>
  <COLGROUP>
  <COL width=3D106>
  <COL width=3D150>
  <THEAD>
  <TR vAlign=3Dtop>
    <TD width=3D"42%">
      <P><B>As shown in figure at right, a few descriptors are generated =
in the=20
      'ejb-jar.xml' file.</B></P>
      <P><B>These descriptors are generated by the following tag =
declared in the=20
      StoreAccessBean file, which was generated by Lomboz.</B></P><PRE =
style=3D"MARGIN-BOTTOM: 0.2in"><FONT color=3D#3f5fbf><FONT =
face=3DSans><FONT size=3D3>@ejb.bean name =
=3DStoreAccessSate</FONT></FONT></FONT>
<FONT color=3D#3f5fbf><FONT face=3DSans><FONT =
size=3D3>jndi-name=3DStoreAccessStateBean</FONT></FONT></FONT>
<FONT color=3D#3f5fbf><FONT face=3DSans><FONT =
size=3D3>type=3DStateful</FONT></FONT></FONT></PRE></TD>
    <TD width=3D"58%">
      <P align=3Dright><IMG height=3D242=20
      src=3D"http://www.tusc.com.au/tutorial/images/chap4/ejb-jar.png" =
width=3D532=20
      align=3Dleft border=3D0 name=3DGraphic8><BR =
clear=3Dleft><BR></P></TD></TR></THEAD>
  <TBODY></TBODY></TABLE>
<P><BR><BR></P>
<P><B>This tag also generates the following descriptors in jboss.xml as =
shown=20
below.</B></P>
<P><IMG height=3D104 =
src=3D"http://www.tusc.com.au/tutorial/images/chap4/jboss.png"=20
width=3D420 align=3Dleft border=3D0 name=3DGraphic9><BR =
clear=3Dleft><BR><BR></P>
<H3>Add Business Method :</H3>
<P>The next step is to add a business method to the bean.</P>
<P><B>Go to StoreAccesStateBean node &gt; right click &gt; select New on =
pop up=20
menu.</B></P>
<P><B>Select Lomboz EJB Method Wizard.</B></P>
<P><FONT color=3D#800000><I>Note : This step is covered in the previous=20
chapter.</I></FONT></P>
<P><B>Add a business method with the following signature..</B></P>
<P><B>public String loginUser (String username, String =
password).</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Select Method Type as Business and =
Interface as=20
Remote as shown below..</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D329=20
src=3D"http://www.tusc.com.au/tutorial/images/chap3/AddBusinessBMethod.pn=
g"=20
width=3D502 align=3Dleft border=3D0 name=3DGraphic6><BR =
clear=3Dleft><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>This wizard generates a loginUser =
method in our=20
bean class, with the method level tag' @ejb.interface' shown =
below.</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D103=20
src=3D"http://www.tusc.com.au/tutorial/images/chap3/SessionBeanInterfaceT=
ag.png"=20
width=3D359 align=3Dleft border=3D0 name=3DGraphic22><BR =
clear=3Dleft><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>This tag is responsible for =
generating this=20
method in the Remote Interface (in this case it is StoreAccessSate which =
will be=20
created once you generate your classes). </B></P>
<TABLE cellSpacing=3D0 cellPadding=3D4 width=3D"100%" border=3D0>
  <COLGROUP>
  <COL width=3D132>
  <COL width=3D124>
  <THEAD>
  <TR vAlign=3Dtop>
    <TD width=3D"52%">
      <P align=3Dleft><B>Now, this business method needs to invoke a =
method on the=20
      DAO, which encapsulates access to the database.</B></P>
      <P align=3Dleft><B>So, add another tag on this method so that a =
method with=20
      this signature is generated in the DAO interface. We can then =
implement=20
      that method in our DAOImpl class so that our business method can =
get the=20
      desired result.</B></P><PRE style=3D"MARGIN-BOTTOM: 0.2in"><FONT =
color=3D#3f5fbf><FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2>@dao.call name=3DloginUser</FONT></FONT></FONT></PRE>
      <P><B>Add this tag at the method level as shown on the =
right.</B></P>
      <P><B>Now generate your EJB classes again as shown in the steps=20
      earlier.</B></P>
      <P><FONT color=3D#800000><I>OK, for reference these are the steps =
you have=20
      to follow:</I></FONT></P>
      <P><FONT color=3D#800000><I>Expand 'MyStoreMgr' node under =
'MyStore' Project=20
      in Package Explorer.</I></FONT></P>
      <P><FONT color=3D#800000><I>Right click &gt; pop up =
menu.</I></FONT></P>
      <P><FONT color=3D#800000><I>Go to Lomboz J2EE &gt; Generate EJB=20
      Classes.</I></FONT></P></TD>
    <TD width=3D"48%">
      <P><IMG height=3D410=20
      =
src=3D"http://www.tusc.com.au/tutorial/images/chap4/loginUserAddDAOTag.pn=
g"=20
      width=3D452 align=3Dleft border=3D0 name=3DGraphic10><BR=20
  clear=3Dleft><BR></P></TD></TR></THEAD>
  <TBODY></TBODY></TABLE>
<P><BR><BR></P>
<H3>Add Callback Methods :</H3>
<P><B>In contrast to the Stateless bean, the ejbCreate method will have =
an=20
argument. This will be used to initialize a persistent field in the=20
bean.</B></P>
<P><B>Add that field, and add accessor and mutator methods to access =
that field=20
as shown below.</B></P><PRE><FONT size=3D3><B><FONT =
color=3D#7f0055>public</FONT></B> <B><FONT =
color=3D#7f0055>abstract</FONT></B> <B><FONT =
color=3D#7f0055>class</FONT></B> <FONT =
color=3D#000000>StoreAccessStateBean</FONT> <B><FONT =
color=3D#7f0055>implements</FONT></B> <FONT =
color=3D#000000>SessionBean</FONT> <FONT color=3D#000000>{</FONT></FONT>

<FONT color=3D#7f0055>   <B><FONT size=3D3>private</FONT></B> <FONT =
color=3D#000000>String</FONT> <FONT color=3D#000000>userID;</FONT>   =
</FONT>
<FONT color=3D#7f0055>   </FONT>
<FONT color=3D#3f5fbf>   <FONT size=3D3>/**</FONT></FONT>
    <FONT size=3D3><FONT color=3D#3f5fbf>*</FONT> <FONT =
color=3D#3f5fbf>@ejb.interface</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>method</FONT> </FONT>
    <FONT size=3D3><FONT color=3D#3f5fbf>*</FONT>  <FONT =
color=3D#3f5fbf>view</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>type=3D"remote"</FONT></FONT>
    <FONT size=3D3><FONT color=3D#3f5fbf>*/</FONT></FONT>
<FONT color=3D#7f0055>   <B><FONT size=3D3>public</FONT></B> <B>void</B> =
<FONT color=3D#000000>setUserID(String</FONT> <FONT =
color=3D#000000>userID)</FONT> <FONT color=3D#000000>{</FONT></FONT>
<FONT color=3D#7f0055>      <B><FONT size=3D3>this</FONT></B><FONT =
color=3D#000000>.userID</FONT> <FONT color=3D#000000>=3D</FONT> <FONT =
color=3D#000000>userID;</FONT></FONT>
<FONT color=3D#000000>   <FONT size=3D3>}</FONT></FONT>
<FONT color=3D#3f5fbf>   </FONT>
<FONT color=3D#3f5fbf>   <FONT size=3D3>/**</FONT></FONT>
    <FONT size=3D3><FONT color=3D#3f5fbf>*</FONT> <FONT =
color=3D#3f5fbf>@ejb.interface</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>method</FONT> </FONT>
    <FONT size=3D3><FONT color=3D#3f5fbf>*</FONT> <FONT =
color=3D#3f5fbf>view</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>type=3D"remote"</FONT></FONT>
    <FONT size=3D3><FONT color=3D#3f5fbf>*/</FONT></FONT>
<FONT color=3D#7f0055>   <B><FONT size=3D3>public</FONT></B> <FONT =
color=3D#000000>String</FONT> <FONT color=3D#000000>getUserID()</FONT> =
<FONT color=3D#000000>{</FONT></FONT>
<FONT color=3D#7f0055>      <B><FONT size=3D3>return</FONT></B> <FONT =
color=3D#000000>userID;</FONT></FONT>
<FONT color=3D#000000>   <FONT size=3D3>}</FONT></FONT></PRE>
<P><B>Now add the ejbCreate method with the signature<BR><BR>public void =

ejbCreate (String userID)</B></P>
<P><B>Assign userID to the persistent field userID we created above as=20
shown</B>.</P>
<P><IMG height=3D170=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/StoreAccessStateEjbCr=
eate.png"=20
width=3D478 align=3Dleft border=3D0 name=3DGraphic12><BR =
clear=3Dleft><B>Now, the other=20
two callback methods required to complete this bean are</B></P>
<P><B>1. setSessionContext.</B></P>
<P><B>2. unsetSessionContext.</B></P>
<P><B>Add a field to store sessionContext</B>.</P><PRE =
style=3D"MARGIN-BOTTOM: 0.2in"><FONT face=3DSans><FONT size=3D3><B><FONT =
color=3D#7f0055>protected</FONT></B> <FONT =
color=3D#000000>SessionContext</FONT> <FONT =
color=3D#000000>ctx;</FONT></FONT></FONT></PRE>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P><B>Add a method setSessionContext with sessionContext as its =
parameter and=20
assign that to the sessionContext variable as shown below.</B></P>
<P><IMG height=3D356=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/StoreAccessStateSetSe=
ssionContext.png"=20
width=3D474 align=3Dleft border=3D0 name=3DGraphic13><BR =
clear=3Dleft><B>Similarly, add a=20
method unsetSessionContext which sets the context variable to null as =
shown=20
above.</B></P>
<P><FONT color=3D#800000><I>Note : The StoreAccessStateSession class =
inherits the=20
StoreAccessStateBean abstract class and implements <FONT=20
face=3D"Nimbus Roman No9 L">SessionBean, which will override all methods =
of the=20
interface SessionBean. So, after completing the methods in your bean =
class,=20
generate your EJB classes again. The SessionContext methods will be =
overridden,=20
as discussed in previous chapter.</FONT></I></FONT></P>
<P><B>Generate EJB classes.</B></P>
<P><FONT color=3D#800000><I>Note : The steps to generate the EJB classes =
are=20
discussed above and in the previous chapter.</I></FONT></P>
<P><BR><BR></P>
<H3>Implement DAO Interface :</H3>
<P><B>We don't have to implement the DAO interface as we are using the=20
StoreAccessDAOImpl class created and implemented in the previous =
chapter.=20
</B></P>
<P><B>So go into the StoreAccessDAOImpl class and change the class =
declaration=20
statement, so that it implements StoreAccessStateDAO interface, as shown =

⌨️ 快捷键说明

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