WebLogic Server to COM Communication

Now you will look at this communication from the other direction, for example, between a Java application or component deployed on WebLogic Server that needs to access a COM component, as shown in Figure 20.4.

Figure 20.4. Block diagram of WebLogic Server application to COM component communication.

graphics/20fig04.gif

For example, if you needed to open a Microsoft Word document and extract its contents in a Java application in WebLogic Server, how would you do it? Microsoft has modularized the Microsoft Office suite into COM-compliant applications. Hence, accessing a Word document is essentially the same as accessing an instance of a Word COM component. This is also called Office automation because it involves accessing the COM components in Microsoft Office to leverage the existing COM functionality.

The interfaces of the Word COM component are defined in a library file called the type library file. For Microsoft Word (in either Office 97 or Office 2000), the type library file is named MSWORD9.OLB, where OLB stands for object library. You can locate this file in the C:\Program Files\Microsoft Office\Office directory (or whichever directory Microsoft Office is installed in). There will be a set of .olb files in this directory (for Word, Excel, PowerPoint, and so on).

Because the jCOM software bridge supports bi-directional communication, it proves quite helpful in this scenario, as well. The Word document is an instance of a COM component. Hence, in order to access it, you need to generate Java wrapper classes that act as a proxy for accessing the Word COM component. For this purpose, you will use the com2java tool.

As seen in Figure 20.5, the com2java tool can read the type library (that is, the MSWORD9.OLB object library file) of a COM component and generate the interface and Java COM proxy classes.

Figure 20.5. Generating COM Proxy classes and interfaces for MSWORD9.OLB using com2java.

graphics/20fig05.jpg

After this, you need to enable the jCOM bridge within WebLogic Server using the Admin Server console. This will start the jCOM bridge the next time WebLogic Server starts up. The jCOM bridge is now ready to intercept and translate calls to the COM component from Java objects and back. Here's a code snippet of DocumentsProxy.java that implements the Documents interface to demonstrate how the interface and proxy classes are generated:

 package myword;  import com.bea.jcom.*; /**  * Proxy for COM Interface 'Documents'. Generated 6/10/2002 11:14:36 PM  * from 'C:|Program Files|Microsoft Office|Office|MSWORD9.OLB'<P>  * Generated using version 7.0 of <B>jCOM</B> -- pure Java/COM integration          technology from BEA Systems, Inc.   * See <A HREF="http://www.bea.com/products/weblogic/server/datasheet.shtml">           http://www.bea.com/products/weblogic/server/datasheet.shtml</A><P>  *  * Generator Options:  * PromptForTypeLibraries = False  * AttemptNonDual = True  * ClashPrefix = zz_  * LowerCaseMemberNames = True  * IDispatchOnly = False  * RetryOnReject = False  * AwtForOcxs = False  * GenerateDeprecatedConstructors = True  * ArraysAsObjects = False  * DontGenerateDisp = False  * DontRenameSameMethods = False  * IgnoreConflictingInterfaces = True  */ public class DocumentsProxy extends com.bea.jcom.Dispatch         implements Documents, java.io.Serializable {   protected String getJCOMVersion() { return "7.0"; }   static { JCOMInit.init(); }   public static final Class targetClass = myword.Documents.class;   public DocumentsProxy(String CLSID, String host, AuthInfo authInfo)           throws java.net.UnknownHostException, java.io.IOException{     super(CLSID, Documents.IID, host, authInfo);   }   /** For internal use only */   public DocumentsProxy() {}   public DocumentsProxy(Object obj) throws java.io.IOException {     super(obj, Documents.IID);   }   protected DocumentsProxy(Object obj, String iid) throws java.io.IOException {     super(obj, iid);   }   public DocumentsProxy(String CLSID, String host, boolean deferred)           throws java.net.UnknownHostException, java.io.IOException{     super(CLSID, Documents.IID, host, null);   }   protected DocumentsProxy           (String CLSID, String iid, String host, AuthInfo authInfo)           throws java.io.IOException {     super(CLSID, iid, host, authInfo);   }   public void addListener(String iidStr, Object theListener, Object theSource)           throws java.io.IOException {     super.addListener(iidStr, theListener, theSource);   }   public void removeListener(String iidStr, Object theListener)           throws java.io.IOException {     super.removeListener(iidStr, theListener);   }   ... 

So far, you have studied the jCOM bi-directional software bridge and how it can be used to establish communication between the Java classes or components deployed on WebLogic Server and COM components or COM clients. Now you'll move on and learn a few concepts of XML.



Sams Teach Yourself BEA WebLogic Server 7. 0 in 21 Days
Sams Teach Yourself BEA WebLogic Server 7.0 in 21 Days
ISBN: 0672324334
EAN: 2147483647
Year: 2002
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net