KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jinterop > dcom > test > MSTypeLibraryBrowser


1 package org.jinterop.dcom.test;
2
3 import java.net.UnknownHostException JavaDoc;
4
5 import org.jinterop.dcom.common.JIException;
6 import org.jinterop.dcom.core.IJIComObject;
7 import org.jinterop.dcom.core.JIComServer;
8 import org.jinterop.dcom.core.JIProgId;
9 import org.jinterop.dcom.core.JISession;
10 import org.jinterop.dcom.core.JIString;
11 import org.jinterop.dcom.win32.ComFactory;
12 import org.jinterop.dcom.win32.FuncDesc;
13 import org.jinterop.dcom.win32.IJIDispatch;
14 import org.jinterop.dcom.win32.IJITypeInfo;
15 import org.jinterop.dcom.win32.IJITypeLib;
16 import org.jinterop.dcom.win32.TypeAttr;
17 import org.jinterop.dcom.win32.VarDesc;
18
19 public class MSTypeLibraryBrowser {
20     
21     private JIComServer comServer = null;
22     private IJIDispatch dispatch = null;
23     private IJIComObject unknown = null;
24     
25     public MSTypeLibraryBrowser(String JavaDoc address, String JavaDoc args[]) throws JIException, UnknownHostException JavaDoc
26     {
27         JISession session = JISession.createSession(args[1],args[2],args[3]);
28         comServer = new JIComServer(JIProgId.valueOf(session,"Excel.Application"),address,session);
29     }
30     
31     public void start() throws JIException
32     {
33         unknown = comServer.createInstance();
34         dispatch = (IJIDispatch)ComFactory.createCOMInstance(ComFactory.IID_IDispatch,unknown);
35         IJITypeInfo typeInfo = dispatch.getTypeInfo(0);
36         IJITypeLib typeLib = (IJITypeLib)((Object JavaDoc[])typeInfo.getContainingTypeLib())[0];
37         Object JavaDoc[] result = typeLib.getDocumentation(-1);
38         System.out.println(((JIString)result[0]).getString());
39         System.out.println(((JIString)result[1]).getString());
40         System.out.println(((JIString)result[3]).getString());
41         System.out.println("-------------------------------");
42         int typeInfoCount = typeLib.getTypeInfoCount();
43         int i = 0;
44         String JavaDoc g_arrClassification[] = { "Enum","Struct","Module","Interface",
45             "Dispinterface","Coclass","Typedef","Union"};
46         for(; i < typeInfoCount;i++)
47         {
48             result = typeLib.getDocumentation(i);
49             int j = typeLib.getTypeInfoType(i);
50             
51             
52             System.out.println(((JIString)result[0]).getString());
53             System.out.println(((JIString)result[1]).getString());
54             System.out.println(((JIString)result[3]).getString());
55             System.out.println(g_arrClassification[j]);
56             
57             IJITypeInfo typeInfo2 = typeLib.getTypeInfo(i);
58             TypeAttr typeAttr = typeInfo2.getTypeAttr();
59             for(j = 0;j < typeAttr.cFuncs;j++)
60             {
61                 FuncDesc funcDesc = typeInfo2.getFuncDesc(j);
62                 result = typeInfo2.getDocumentation(funcDesc.memberId);
63                 System.out.println(((JIString)result[0]).getString());
64                 System.out.println(((JIString)result[1]).getString());
65                 System.out.println(((JIString)result[3]).getString());
66             }
67             
68             for(j = 0;j < typeAttr.cVars;j++)
69             {
70                 if(j == 77)
71                 {
72                     int kk = 0;
73                 }
74                 VarDesc varDesc = typeInfo2.getVarDesc(j);
75                 result = typeInfo2.getDocumentation(varDesc.memberId);
76                 System.out.println(((JIString)result[0]).getString());
77                 System.out.println(((JIString)result[1]).getString());
78                 System.out.println(((JIString)result[3]).getString());
79                 //System.out.println(j);
80
}
81             
82             
83             System.out.println("***************************************");
84         }
85         JISession.destroySession(dispatch.getAssociatedSession());
86     }
87     
88     public static void main(String JavaDoc[] args) {
89         try {
90             if (args.length < 4)
91             {
92                 System.out.println("Please provide address domain username password");
93                 return;
94             }
95             MSTypeLibraryBrowser typeLibraryBrowser = new MSTypeLibraryBrowser(args[0],args);
96             typeLibraryBrowser.start();
97         } catch (Exception JavaDoc e) {
98             // TODO Auto-generated catch block
99
e.printStackTrace();
100         }
101         
102     }
103     
104 }
105
Popular Tags