1 package org.jinterop.dcom.test; 2 3 import java.net.UnknownHostException ; 4 5 import org.jinterop.dcom.common.JIException; 6 import org.jinterop.dcom.core.IJIComObject; 7 import org.jinterop.dcom.core.JIArray; 8 import org.jinterop.dcom.core.JIComServer; 9 import org.jinterop.dcom.core.JIProgId; 10 import org.jinterop.dcom.core.JISession; 11 import org.jinterop.dcom.core.JIString; 12 import org.jinterop.dcom.core.JIVariant; 13 import org.jinterop.dcom.win32.ComFactory; 14 import org.jinterop.dcom.win32.IJIDispatch; 15 import org.jinterop.dcom.win32.IJIEnumVARIANT; 16 17 public class MSEnumVariant { 19 20 private JIComServer comServer = null; 21 private JISession session = null; 22 private IJIDispatch dispatch = null; 23 24 public MSEnumVariant(String address,String [] args) throws JIException, UnknownHostException 25 { 26 session = JISession.createSession(args[1],args[2],args[3]); 27 comServer = new JIComServer(JIProgId.valueOf(session,"StdCollection.VBCollection"),address,session); 28 IJIComObject object = comServer.createInstance(); 29 dispatch = (IJIDispatch)ComFactory.createCOMInstance(IJIDispatch.IID,object); 30 31 } 32 33 public void performOp() throws JIException 34 { 35 int i = 0; 36 for (; i < 5; i++) 37 { 38 dispatch.callMethod("Add", new Object []{new Integer (i),new JIString("Key-" + i)}); 39 } 40 41 for (; i < 10; i++) 42 { 43 dispatch.callMethod("Add", new Object []{new Integer (i),JIVariant.OPTIONAL_PARAM}); 44 } 45 46 JIVariant variant = dispatch.get("_NewEnum"); 47 48 IJIComObject object2 = ComFactory.createCOMInstance(dispatch,variant.getObjectAsInterfacePointer()); 49 51 IJIEnumVARIANT enumVARIANT = (IJIEnumVARIANT)ComFactory.createCOMInstance(IJIEnumVARIANT.IID,object2); 52 53 for (i = 0; i < 10; i++) 54 { 55 Object [] values = enumVARIANT.next(1); 56 JIArray array = (JIArray)values[0]; 57 Object [] arrayObj = (Object [])array.getArrayInstance(); 58 for (int j = 0; j < arrayObj.length; j++) 59 { 60 System.out.println(((JIVariant)arrayObj[j]).getObjectAsInt() + "," + ((Integer )values[1]).intValue()); 61 } 62 63 int j = 0; 64 } 65 66 enumVARIANT.reset(); 67 Object [] values = enumVARIANT.next(5); 68 enumVARIANT.next(1); 69 enumVARIANT.skip(2); 70 values = enumVARIANT.next(1); 71 IJIEnumVARIANT newenum = enumVARIANT.Clone(); 72 newenum.reset(); 73 values = newenum.next(10); 74 i = 0; 75 76 JISession.destroySession(session); 77 } 78 79 80 public static void main(String [] args) { 81 82 try{ 83 if (args.length < 4) 84 { 85 System.out.println("Please provide address domain username password"); 86 return; 87 } 88 MSEnumVariant enumVariant = new MSEnumVariant(args[0],args); 89 enumVariant.performOp(); 90 } 91 catch(Exception e) 92 { 93 e.printStackTrace(); 94 } 95 } 96 97 } 98 | Popular Tags |