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

📄 connect the enterprise with the jca, part 2.htm

📁 本人收集的关于Java Connector Architecture的资料
💻 HTM
📖 第 1 页 / 共 4 页
字号:
desc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;public void 
setDescription(String 
desc)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.desc 
= desc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;public void 
setReference(Reference 
reference)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.reference 
= reference;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;public 
Reference 
getReference()<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 
reference;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>}<BR></CODE>
<P><FONT size=+1><STRONG>Compile and build myjca.rar </STRONG></FONT><BR>Now 
that you've seen the adapter' source code, it's time to build the 
<CODE>myjca.rar</CODE> file. First, I assume you have a source directory 
containing two subdirectories: <CODE>myjca</CODE> containing the 
<CODE>.java</CODE> files, and <CODE>META-INF</CODE> containing the configuration 
files. 
<P>To compile and build the rar file: 
<OL>
  <LI>Compile the class files by typing <CODE>javac *.java</CODE> in the 
  <CODE>myjca</CODE> directory 
  <LI>Build the <CODE>myjca.jar</CODE> from the source directory by entering 
  <CODE>jar cvf myjca.jar myjca</CODE> 
  <LI>Create the rar file using the <CODE>myjca.jar</CODE> and the 
  <CODE>META-INF</CODE> directory by typing <CODE>jar cvf myjca.rar myjca.jar 
  META-INF</CODE> </LI></OL>
<P><FONT size=+1><STRONG>Deployment output </STRONG></FONT><BR>Once you deploy 
the adapter rar file (using the steps outlined in the beginning of the article), 
you should see the output of the <CODE>println</CODE> statements contained in 
most of the adapter's methods. You should see output similar to the following as 
the adapter deploys: 
<P><CODE>
<P><BR>In MyManagedConnectionFactory.constructor<BR>In 
MyManagedConnectionFactory.createManagedConnection<BR>In 
MyManagedConnection<BR>In MyConnectionEventListener<BR>In 
MyManagedConnection.getMetaData<BR>In MyConnectionMetaData.constructor<BR>In 
MyConnectionMetaData.getEISProductName<BR>In 
MyConnectionMetaData.getEISProductVersion<BR>In 
MyConnectionMetaData.getMaxConnections<BR></CODE>
<P>The output above shows the <CODE>ManagedConnectionFactory</CODE>'s creation, 
which then invoked the <CODE>ManagedConnection</CODE>, which in turn created the 
<CODE>ConnectionEventListener</CODE>. Finally, you see that the application 
server called the <CODE>ConnectionMetaData</CODE>. 
<P><FONT size=+1><STRONG>Get a connection </STRONG></FONT><BR>Now that you've 
deployed the adapter successfully, let's use the adapter to obtain a connection. 
The following JSP (JavaServer Pages) file does just that, by looking up the 
connection using JNDI (Java Naming and Directory Interface), then calling the 
<CODE>getConnection()</CODE> method on the <CODE>DataSource</CODE>: 
<P><CODE>
<P><BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&lt;title&gt;Connector example&lt;/title&gt;<BR>&lt;/head&gt;<BR>&lt;body 
bgcolor=#ffffff&gt;<BR>&lt;%@ page import="javax.naming.*, java.sql.*, 
javax.sql.*" %&gt;<BR>&lt;% <BR>&nbsp;&nbsp;&nbsp;&nbsp;InitialContext initCtx = 
null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;Object obj = 
null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;try 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initCtx = new 
InitialContext();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataSource ds = 
(javax.sql.DataSource)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;initCtx.lookup("MyConnector");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj 
= ds.getConnection();<BR>&nbsp;&nbsp;&nbsp;&nbsp;} catch(NamingException ne) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("Error 
with context: " + 
ne);&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>%&gt;<BR>&lt;h2&gt;Performed 
a lookup and got a connection&lt;/h2&gt;<BR>&lt;/body&gt;<BR>&lt;/html&gt; 
<BR></CODE>
<P>You'll see the following output when the adapter acquires the connection: 
<P><CODE>
<P><BR>In MyManagedConnectionFactory.createConnectionFactory,1<BR>In 
MyDataSource<BR>In MyDataSource.getConnection,1<BR>In 
MyManagedConnectionFactory.matchManagedConnections<BR>In 
MyManagedConnectionFactory.createManagedConnection<BR>In 
MyManagedConnection<BR>In MyConnectionEventListener<BR>In 
MyManagedConnection.getMetaData<BR>In MyConnectionMetaData.constructor<BR>In 
MyConnectionMetaData.getEISProductName<BR>In 
MyConnectionMetaData.getEISProductVersion<BR>In 
MyConnectionMetaData.getMaxConnections<BR>In 
MyManagedConnection.getUserName<BR>In MyManagedConnection.getConnection<BR>In 
MyConnection<BR>In MyManagedConnection.addMyConnection<BR>In 
MyManagedConnection.addConnectionEventListener<BR></CODE>
<P>As you can see, many classes help obtain the connection. 
<P><FONT size=+1><STRONG>Lessons learned </STRONG></FONT><BR>As you've likely 
figured out, the JCA specification's complexity makes implementing even a basic 
adapter a large undertaking. Moreover, the task grows larger when you add the 
transaction and security contracts (not implemented for this sample adapter), as 
well as the CCI interfaces. 
<P>The complexity shows that the JCA specification is really oriented towards 
commercial software vendors implementing adapters and their consulting/IT 
customers using them. In this context, the JCA interfaces' complexity makes 
sense, although a less flexible, simpler interface version would be nice. 
<P>Therefore, if you are considering using JCA to connect to a legacy system in 
your enterprise, you'd benefit from leveraging an off-the-shelf adapter rather 
than developing your own. If the system to which you need connectivity does not 
have a JCA adapter (that is, for a homegrown system), consider an alternative 
approach. Using Web services to connect to such a system may offer the best 
solution. 
<P>For its part, while JCA is still a new standard, it shows promise for making 
the task of integrating with an EIS less daunting. <IMG height=12 
src="Connect the enterprise with the JCA, Part 2.files/jw-dingbat.gif" width=22>
<P><BR></P>
<P><STRONG>About the author</STRONG><BR><A href="javascript:openBrWindow()">Dirk 
Reinshagen</A>, an architect at Zaplet, Inc., a commercial software vendor in 
the San Francisco Bay Area, has more than eight years of software architecture 
and development experience. He holds a B.S. in computer science from Tufts 
University. <BR></P>
<P>
<UL><A name=resources></A><STRONG>Resources</STRONG> <BR>
  <LI>To obtain the myjca.rar source code file (contained in jw-0201-jca2.zip), 
  go to: <BR><A 
  href="http://www.javaworld.com/javaworld/jw-02-2002/jca/jw-0201-jca2.zip">http://www.javaworld.com/javaworld/jw-02-2002/jca/jw-0201-jca2.zip</A><BR>
  <LI>"Connect the Enterprise with the JCA," Dirk Reinshagen 
  (<EM>JavaWorld</EM>) 
  <UL>
    <LI><A 
    href="http://www.javaworld.com/javaworld/jw-11-2001/jw-1121-jca.html">Part 
    1. A look at the J2EE Connector Architecture</A> (November 2001) 
    <LI><A 
    href="http://www.javaworld.com/javaworld/jw-02-2002/jw-0201-jca2.html">Part 
    2. Build your own J2EE Connector Architecture adapter</A> (February 2002) 
    </LI></UL>
  <LI>Dirk Reinshagen's "XML Messaging" series <EM>(JavaWorld):</EM> 
  <UL>
    <LI><A 
    href="http://www.javaworld.com/javaworld/jw-03-2001/jw-0302-xmlmessaging.html">Part 
    1: Write a simple XML message broker for custom XML messages</A> (March 
    2001) 
    <LI><A 
    href="http://www.javaworld.com/javaworld/jw-06-2001/jw-0622-xmlmessaging2.html">Part 
    2: XML messaging the SOAP way</A> (June 2001) 
    <LI><A 
    href="http://www.javaworld.com/javaworld/jw-09-2001/jw-0914-xmlmessage3.html?">Part 
    3: JAXM and ebXML set the new standard for XML messaging</A> (September 
    2001) </LI></UL>
  <LI>The JCA page from java.sun.com: <BR><A 
  href="http://java.sun.com/j2ee/connector/">http://java.sun.com/j2ee/connector/</A><BR>
  <LI>The Java Community Process's JSR 112 page, from which JCA 2.0 will spring: 
  <BR><A 
  href="http://www.jcp.org/jsr/detail/112.jsp">http://www.jcp.org/jsr/detail/112.jsp</A><BR>
  <LI>For more Java 2 Platform, Enterprise Edition stories, visit the 
  <STRONG>J2EE</STRONG> section of <EM>JavaWorld</EM>'s Topical Index: <BR><A 
  href="http://www.javaworld.com/channel_content/jw-j2ee-index.shtml">http://www.javaworld.com/channel_content/jw-j2ee-index.shtml</A><BR>
  <LI>Talk about the JCA in our <STRONG>Enterprise Java</STRONG> discussion: 
  <BR><A 
  href="http://forums.devworld.com/webx?50@@.ee6b80a">http://forums.devworld.com/webx?50@@.ee6b80a</A><BR>
  <LI>Sign up for <EM>JavaWorld</EM>'s free weekly <EM>Enterprise Java</EM> 
  email newsletter: <BR><A 
  href="http://www.javaworld.com/subscribe">http://www.javaworld.com/subscribe</A><BR>
  <LI>You'll find a wealth of IT-related articles from our sister publications 
  at <A href="http://www.idg.net/jump?id=1100">IDG.net</A> </LI></UL><BR>
<P></P><!-- REPLACE SIDEBAR --></FONT><!-- ## MAIN CONTENT ENDS HERE ### --></TD><TD 
width="8"><IMG height=1 
src="Connect the enterprise with the JCA, Part 2.files/spacer.gif" width=8 
border=0></TD> </TR></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
  <TBODY>
  <TR>
    <TD align=middle width=186 bgColor=#006699><NOBR><FONT 
      face=Verdana,Geneva,Arial,Helvetica,sans-serif size=1></FONT></NOBR><A 
      href="http://www.javaworld.com/"><IMG height=81 
      src="Connect the enterprise with the JCA, Part 2.files/top_jwlogo.gif" 
      width=186 border=0></A></TD>
    <TD vAlign=bottom width=8 bgColor=#cccccc><IMG height=8 
      src="Connect the enterprise with the JCA, Part 2.files/c_blgrylftbottom.gif" 
      width=8 border=0></TD>
    <TD vAlign=center align=middle width="100%" bgColor=#cccccc><!-- BOTTOM 468x60 AD STARTS HERE jw-articles-bottom-ad.txt -->
      <TABLE cellSpacing=0 cellPadding=0 border=0>
        <TBODY>
        <TR>
          <TD><FONT face=Arial,Helvetica,Sans-serif color=#000000 
            size=-2>Advertisement: Support JavaWorld, click here!</FONT><BR>
            <SCRIPT language=JavaScript 
            src="Connect the enterprise with the JCA, Part 2.files/spinbox.macworld[2]"></SCRIPT>
            <NOSCRIPT><A href="http://spinbox.macworld.com/?SHT=jw-BottomBanner" 
            target=_top><IMG 
            src="Connect the enterprise with the JCA, Part 2.files/jw_house468x60.gif"></A> 
            </NOSCRIPT></TD></TR></TBODY></TABLE><!-- BOTTOM 468x60 AD ENDS HERE --></TD>
    <TD width=8><IMG height=8 
      src="Connect the enterprise with the JCA, Part 2.files/spacer.gif" width=8 
      border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center bgColor=#006699 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle width="100%"><FONT 
      face=Verdana,Geneva,Arial,Helvetica,sans-serif color=#ffffff size=1>
      <P><BR><A href="http://www.javaworld.com/"><FONT 
      color=#ffffff>HOME</FONT></A>&nbsp;|&nbsp; <A 
      href="http://www.javaworld.com/features/index.shtml"><FONT 
      color=#ffffff>FEATURED TUTORIALS</FONT></A>&nbsp;|&nbsp; <A 
      href="http://www.javaworld.com/columns/index.shtml"><FONT 
      color=#ffffff>COLUMNS</FONT></A>&nbsp;|&nbsp; <A 
      href="http://www.javaworld.com/news-reviews/index.shtml"><FONT 
      color=#ffffff>NEWS &amp; REVIEWS</FONT></A>&nbsp;|&nbsp; <A 
      href="http://forums.devworld.com/webx?13@@.ee6b802"><FONT 
      color=#ffffff>FORUM</FONT></A>&nbsp;|&nbsp; <A 
      href="http://www.javaworld.com/resources/index.shtml"><FONT 
      color=#ffffff>JW RESOURCES</FONT></A>&nbsp;|&nbsp; <A 
      href="http://www.javaworld.com/info/jw-about-index.shtml"><FONT 
      color=#ffffff>ABOUT JW</FONT></A>&nbsp;|&nbsp; <A 
      href="http://www.javaworld.com/feedback"><FONT 
      color=#ffffff>FEEDBACK</FONT></A> </P>
      <P><A 
      href="http://www.javaworld.com/javaworld/common/jw-copyright.html"><FONT 
      color=#ffffff>Copyright 

⌨️ 快捷键说明

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