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

📄 6.mht

📁 Enterprise Java Bean的PPT文档,很好的东西.
💻 MHT
📖 第 1 页 / 共 5 页
字号:
linking/referencing of=20
StoreAccess and Item Bean. So we will the add two tags shown=20
below.</B></FONT></FONT></P>
<P><IMG height=3D172=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/StoreAccessDeployment=
Descriptors.png"=20
width=3D446 align=3Dleft border=3D0 name=3DGraphic38><BR =
clear=3Dleft><BR><BR></P>
<P><B>First add the tag shown below at class level in StoreAccess =
Bean.</B></P><PRE><FONT color=3D#3f5fbf><FONT face=3DSans><FONT =
style=3D"FONT-SIZE: 11pt" size=3D2>@ejb.ejb<FONT =
color=3D#7f7f9f>-</FONT>ref ejb<FONT =
color=3D#7f7f9f>-</FONT>name=3D"Item"</FONT></FONT></FONT>
<FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
color=3D#3f5fbf>view</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>type=3D"local"</FONT></FONT></FONT>
<FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
color=3D#3f5fbf>ref</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"ItemLocal"</FONT></FONT></FONT></PRE>
<P><B>This tag will generate deployment descriptors in 'ejb-jar.xml', as =

StoreAccessBean has to know which bean it is referring to, what is its =
view-type=20
and ref-name. This will generate these descriptors as shown =
below.</B></P>
<P><FONT color=3D#800000><FONT face=3D"Nimbus Roman No9 L"><I>Note : =
View type is=20
local as both are in the same Java Virtual Machine, otherwise it would =
be=20
Remote. Secondly ref-name is generated as ItemLocalHome, as we are using =
that=20
rather than ItemHome (which was also generated, but is used in the =
Remote=20
case).</I></FONT></FONT></P>
<P><IMG height=3D576=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/ejbJarStoreAccess.png=
"=20
width=3D466 align=3Dleft border=3D0 name=3DGraphic39><BR =
clear=3Dleft><BR><BR></P>
<P><B>Now add a second tag (shown below) at class level in StoreAccess=20
Bean.</B></P><PRE><FONT face=3DSans><FONT size=3D3><FONT =
color=3D#3f5fbf>@jboss.ejb</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>ref</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>jndi</FONT> <FONT color=3D#3f5fbf>ref</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"ItemLocal"</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT color=3D#3f5fbf>jndi</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"ItemLocal"</FONT></FONT></FONT></PRE>
<P>This tag will generate deployment descriptors in 'jboss.xml', as the=20
application server has to know what jndi-name the Item bean has been =
registered=20
with. This will generate these descriptors as shown below.</P>
<P><FONT color=3D#800000><I>Note : Ref-name and jndi-name are used for =
bean as=20
local (in same JVM).</I></FONT></P>
<P><IMG height=3D344=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/jbossStoreAccess.png"=
=20
width=3D352 align=3Dleft border=3D0 name=3DGraphic40><BR =
clear=3Dleft><FONT=20
color=3D#800000><I>Note : We can see in the code snippet above the =
deployment=20
descriptors generated by tag @jboss. For the view type 'local' it =
generates=20
incorrect deployment descriptors, as discussed in the previous chapter. =
So every=20
time we use this tag we have to change the &lt;ejb-ref&gt; to=20
&lt;ejb-local-ref&gt; before deployment. <B>Caution here</B>, that you =
do this=20
change manually when you finally finish regenerating your EJB classes, =
because=20
every time you regenerate your classes, 'jboss.xml' will be=20
overwritten.</I></FONT></P>
<P><B>Now our Item Bean is complete after these changes, so deploy your =
bean=20
again now, from the Lomboz J2EE View, as per the steps shown above and =
in=20
previous chapters. Messages will appear in the console showing the =
status of=20
deployment.</B></P>
<P><B>Once the bean is deployed successfully, create a test client which =
will=20
invoke the loginUser method on StoreAccess Bean , getCustomerData on =
Customer=20
Bean, getManagerData on Manager Bean and getOutOfStockItems on Item=20
Beam.</B></P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><BR></H3>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Create your Test =
Client=20
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P>G<B>o to Project MytStore node &gt; select src node and expand it =
&gt; select=20
au.com.tusc.client package &gt; right click.</B></P>
<P><B>Select New on the pop up menu &gt; select Lomboz EJB Test Client=20
Wizard</B>. </P>
<P><B>Select package name au.com.tusc.client, name as SessionCMPClient =
and=20
select Ejb Home as au.com.tusc.session.StoreAccessHome and Ejb Interface =
as=20
au.com.tusc.session.StoreAccess. </B></P>
<P><B>This will generate required methods for you in your =
SessionCMPClient class=20
and you only have to invoke loginUser, getCustomerData, getManagerData =
(Manager=20
Bean was developed as part of an exercise in the previous chapter) and=20
getOutOfStockItems as shown below.</B></P>
<P><B>Now, the last step is to write the code for your client.</B></P>
<P><B>In order to access out of stock items we need an Iterator and an =
ArrayList=20
for items. So, declare two variables of these respective types, and =
import the=20
packages for these types (which are java.util.ArrayList and =
java.util.Iterator).=20
</B></P><PRE><FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>Iterator</FONT> <FONT =
color=3D#000000>itemsIterator</FONT> <FONT color=3D#000000>=3D</FONT> =
<FONT color=3D#7f0055>null</FONT><FONT =
color=3D#000000>;</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT color=3D#000000>ArrayList</FONT> =
<FONT color=3D#000000>items</FONT> <FONT color=3D#000000>=3D</FONT> =
<B><FONT color=3D#7f0055>null</FONT></B><FONT =
color=3D#000000>;</FONT></FONT></FONT></PRE>
<P><B>And now add these lines of code to invoke the methods mentioned =
above.=20
</B></P><PRE><FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>System.out.println(</FONT><FONT color=3D#2a00ff>"Request =
from client : "</FONT><FONT color=3D#000000>);</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT color=3D#000000>String</FONT> =
<FONT color=3D#000000>userID</FONT> <FONT color=3D#000000>=3D</FONT> =
<FONT color=3D#000000>myBean.loginUser(</FONT><FONT =
color=3D#2a00ff>"ANDY"</FONT><FONT color=3D#000000>,</FONT><FONT =
color=3D#2a00ff>"PASSWD"</FONT><FONT =
color=3D#000000>);</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>System.out.println(</FONT><FONT color=3D#2a00ff>"Reply =
from Server: Your userid is "</FONT> <FONT color=3D#000000>+</FONT> =
<FONT color=3D#000000>userID</FONT> <FONT =
color=3D#000000>);</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>CustomerData</FONT> <FONT color=3D#000000>cd</FONT> =
<FONT color=3D#000000>=3D</FONT> <FONT =
color=3D#000000>myBean.getCustomerData(userID);</FONT> </FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>System.out.println</FONT> <FONT =
color=3D#000000>(</FONT><FONT color=3D#2a00ff>"Andy your details with =
MyStore are "</FONT> <FONT color=3D#000000>+</FONT> <FONT =
color=3D#000000>cd</FONT> <FONT color=3D#000000>);</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3>String mgrID =3D   =
myBean.loginUser(<FONT color=3D#2a00ff>"RUSTY"</FONT>,<FONT =
color=3D#2a00ff>"PASSWD"</FONT>);</FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>System.out.println(</FONT><FONT color=3D#2a00ff>"Reply =
from Server: Your mgrid is "</FONT> <FONT color=3D#000000>+</FONT> <FONT =
color=3D#000000>mgrID</FONT> <FONT =
color=3D#000000>);</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>ManagerData</FONT> <FONT color=3D#000000>md</FONT> <FONT =
color=3D#000000>=3D</FONT> <FONT =
color=3D#000000>myBean.getManagerData(mgrID);</FONT>                  =
</FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>System.out.println</FONT> <FONT =
color=3D#000000>(</FONT><FONT color=3D#2a00ff>"Rusty your details with =
MyStore are  "</FONT> <FONT color=3D#000000>+</FONT> <FONT =
color=3D#000000>md</FONT> <FONT color=3D#000000>);</FONT>                =
     </FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>System.out.println(</FONT><FONT color=3D#2a00ff>"Manager =
Request : List items out of stock "</FONT><FONT =
color=3D#000000>);</FONT></FONT></FONT>
                                               =20
<FONT face=3DSans><FONT size=3D3><FONT color=3D#000000>items</FONT> =
<FONT color=3D#000000>=3D</FONT> <FONT =
color=3D#000000>myBean.getOutOfStockItems();</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>itemsIterator</FONT> <FONT color=3D#000000>=3D</FONT> =
<FONT color=3D#000000>items.iterator();</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT =
color=3D#000000>System.out.println(</FONT><FONT color=3D#2a00ff>"List Of =
Out Of stock Items "</FONT><FONT color=3D#000000>);</FONT>               =
       </FONT></FONT>

<FONT face=3DSans><FONT size=3D3><B><FONT =
color=3D#7f0055>while</FONT></B> <FONT color=3D#000000>(</FONT> <FONT =
color=3D#000000>itemsIterator.hasNext()</FONT> <FONT =
color=3D#000000>)</FONT> <FONT color=3D#000000>{</FONT>                  =
   </FONT></FONT>
<FONT color=3D#000000>   <FONT size=3D3><FONT =
face=3DSans>ItemData</FONT></FONT></FONT><FONT size=3D3><FONT =
face=3DSans> <FONT color=3D#000000>itemData=3D</FONT> <FONT =
color=3D#000000>(</FONT> <FONT color=3D#000000>ItemData</FONT> <FONT =
color=3D#000000>)</FONT> <FONT =
color=3D#000000>itemsIterator.next();</FONT></FONT></FONT>
<FONT color=3D#000000>   <FONT size=3D3><FONT =
face=3DSans>System.out.println</FONT></FONT></FONT><FONT size=3D3><FONT =
face=3DSans> <FONT color=3D#000000>(</FONT><FONT color=3D#2a00ff>"Item =
Data "</FONT> <FONT color=3D#000000>+</FONT> <FONT =
color=3D#000000>itemData</FONT> <FONT =
color=3D#000000>);</FONT></FONT></FONT>
<FONT color=3D#000000><FONT face=3DSans><FONT =
size=3D3>}</FONT></FONT></FONT></PRE>
<H3>Test your Client :</H3>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Now, in order to test your client, =
Select=20
SessionCMPClient node &gt; Go at top level menu and select the icon with =
the=20
'Running Man'</B>.</P>
<P><B>On that select 'Run as' &gt; select Java Application, as shown=20
below.</B></P>
<H3><IMG height=3D258=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/RunTestClient.png" =
width=3D570=20
align=3Dleft border=3D0 name=3DGraphic14><BR clear=3Dleft><BR><BR></H3>
<P><B>Now on your console, if you get a reply saying two items out of =
stock=20
which are 'CALCULATOR' and 'CLOCK', then your call is successful as =
shown=20
below</B>.</P>
<H3><IMG height=3D152=20
src=3D"http://www.tusc.com.au/tutorial/images/chap6/ResultTestClient.png"=
=20
width=3D626 align=3Dleft border=3D0 name=3DGraphic21><BR =
clear=3Dleft><BR><BR></H3>
<H3>Exercise :</H3>
<P>Now, here is an exercise for you. In order to proceed further, =
implement=20
Supplier as a CMP Entity Bean. The tasks are given below:</P>
<OL>
  <LI>
  <P><FONT face=3D"Nimbus Roman No9 L">Create a CMP Bean named Supplier =
under=20
  package au.com.tusc.cmp. </FONT></P>
  <LI>
  <P><FONT face=3D"Nimbus Roman No9 L">Implement the ejbCreate method, =
with all=20
  attributes passed as arguments and then assigned to attributes using =
mutator=20
  methods.</FONT></P>
  <LI>
  <P><FONT face=3D"Nimbus Roman No9 L">Add a find method named =
findUserID with=20
  query and signature: </FONT></P>
  <P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><FONT =
size=3D3><B>query=20
  "SELECT OBJECT(b) FROM MyStoreSupplier as b where b.userID =3D ?1"=20
  </B></FONT></FONT></FONT></P>
  <P><FONT color=3D#000000><FONT face=3D"Nimbus Roman No9 L"><B>method=20
  au.com.tusc.cmp.SupplierLocal findUserID(java.lang.String=20
  userID)</B></FONT></FONT></P>
  <P><FONT color=3D#800000><FONT face=3D"Nimbus Roman No9 L"><I>Note : =
The method=20
  signature is find&lt;cmp attribute&gt; instead of findByPrimaryKey, =
because=20
  finder methods for non-key CMP attributes use this convention. =
Accordingly the=20
  return type for finder methods will be either Collection or &lt;entity =

  type&gt;, as specified in the EJB specification, sections 10.5.6 and =
10.5.2=20
  respectively.</I></FONT></FONT></P>
  <LI>
  <P><FONT face=3D"Nimbus Roman No9 L">Add a business method to get =
supplier=20
  details with signature:</FONT></P>
  <P><FONT face=3D"Nimbus Roman No9 L"><B>public SupplierData=20
  getSupplierData()</B></FONT></P>
  <LI>
  <P><FONT face=3D"Nimbus Roman No9 L">Add a business method to get =
request items=20
  from various suppliers with signature:</FONT></P>
  <P><FONT face=3D"Nimbus Roman No9 L"><B>public void requestItem(String =
itemID,=20
  Integer quantity)</B></FONT></P>
  <LI>
  <P><FONT face=3D"Nimbus Roman No9 L">Add callback methods, required =

⌨️ 快捷键说明

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