The COMProxy object allows us to call COM Automation components from Java™. Java Native Interface (JNI) makes native calls into the COM and Win32 libraries. COMProxy makes use of Object Linking and Embedding (OLE) Automation under the wraps (also knows as late binding) to make calls to COM objects/interfaces. COMProxy also supports Moniker URLs. To obtain a handle to a COMProxy instance use the system.createCOMInstance( ) method.
Notes:
The COMProxy object is described by way of an example; the Connector described here is a re-implementation in JavaScript™ of an older Outlook Connector written in VBScript. We can find the code in the TDI_install_dir/examples/MSOutlook directory.
This example shows how we can manipulate your Outlook Contacts using COMProxy. It is an example of an ibmdi.scriptconnector, and shows how we can create a script connector that supports add, iterate, update, lookup, and delete modes.
The script code is provided below if you would like to create your own script connector and input this data. The file msoutlook.xml is a TDI Config file with the Connector already entered for you. If we open msoutlook.xml we will find a scriptconnector called msoutlook that contains this script information ("config"->"script").
We can also copy the MSOutlook.jar file to the TDI_install_dir//jars/connectors directory, after which it will appear in your list of available connectors to inherit from.
// // This script implements all the necessary functions for accessing // the Contacts register in MS Outlook. // Assumes that the number of entries in contact folder is constant for the run ol = system.createCOMInstance("Outlook.Application"); ns = COMProxy.call(ol,"GetNameSpace","MAPI"); contacts = COMProxy.call(ns.toObject(),"getDefaultFolder",10); var item; var counter = 0; var oldstring=""; var decode=""; var outlookEntry = system.newEntry(); function selectEntries(){ counter = 0; } function getNextEntry (){ ol = system.createCOMInstance("Outlook.Application"); ns = COMProxy.call(ol,"GetNameSpace","MAPI"); contacts = COMProxy.call(ns.toObject(),"getDefaultFolder",10); items = COMProxy.call(contacts.toObject(),"Items"); count = COMProxy.get(items.toObject(),"count"); counter++; if(counter > count){ result.setStatus(0); result.setMessage("End of input"); }else{ item = COMProxy.call(items.toObject(),"Item",counter); populateEntry(); } } function findEntry (){ flt = "[" + search.getFirstCriteriaName() + "] = " + search.getFirstCriteriaValue(); items = COMProxy.call(contacts.toObject(),"Items"); item = COMProxy.call(items.toObject(),"Find",flt); if (item == null){ result.setStatus(0) result.setMessage("Not found" + "--->["+ flt + "]"); } else populateEntry(); } function modEntry (){ populateItem(); COMProxy.call(item.toObject(),"Save"); } function deleteEntry (){ COMProxy.call(item.toObject(),"Delete"); } function putEntry (){ items = COMProxy.call(contacts.toObject(),"Items"); item = COMProxy.get(items.toObject(),"Add"); if(item==null){ result.setStatus(2) result.setMessage("Unabled to create item"); return; } oldString = entry.getString("FullName"); COMProxy.put(item.toObject(),"FileAs",oldString); populateItem(); COMProxy.call(item.toObject(),"Save"); } function populateEntry (){ entry.setAttribute("FileAs", COMProxy.get(item.toObject(),"FileAs")); entry.setAttribute("FullName", COMProxy.get(item.toObject(),"FullName")); entry.setAttribute("Email1Address", COMProxy.get(item.toObject(),"Email1Address")); entry.setAttribute("Birthday", COMProxy.get(item.toObject(),"Birthday")); entry.setAttribute("BusinessAddress", COMProxy.get(item.toObject(),"BusinessAddress")); entry.setAttribute("BusinessTelephoneNumber", COMProxy.get(item.toObject(),"BusinessTelephoneNumber")); entry.setAttribute("BusinessFaxNumber", COMProxy.get(item.toObject(),"BusinessFaxNumber")); entry.setAttribute("CompanyName", COMProxy.get(item.toObject(),"CompanyName")); entry.setAttribute("JobTitle", COMProxy.get(item.toObject(),"JobTitle")); entry.setAttribute("HomeAddress", COMProxy.get(item.toObject(),"HomeAddress")); entry.setAttribute("HomeTelephoneNumber", COMProxy.get(item.toObject(),"HomeTelephoneNumber")); entry.setAttribute("HomeFaxNumber", COMProxy.get(item.toObject(),"HomeFaxNumber")); entry.setAttribute("MobileTelephoneNumber", COMProxy.get(item.toObject(),"MobileTelephoneNumber")); entry.setAttribute("Categories", COMProxy.get(item.toObject(),"Categories")); entry.setAttribute("LastModificationTime", COMProxy.get(item.toObject(),"LastModificationTime")); outlookEntry = entry.clone(entry); } function populateItem (){ outlookEntry.merge(entry); COMProxy.put(item.toObject(),"FileAs", outlookEntry.getString("FileAs")); COMProxy.put(item.toObject(),"FullName", outlookEntry.getString("FullName")); COMProxy.put(item.toObject(),"Email1Address", outlookEntry.getString("Email1Address")); COMProxy.put(item.toObject(),"BusinessAddress", outlookEntry.getString("BusinessAddress")); COMProxy.put(item.toObject(),"BusinessTelephoneNumber", outlookEntry.getString("BusinessTelephoneNumber")); COMProxy.put(item.toObject(),"BusinessFaxNumber",outlookEntry.getString("BusinessFaxNumber")); COMProxy.put(item.toObject(),"JobTitle", outlookEntry.getString("JobTitle")) ; COMProxy.put(item.toObject(),"CompanyName", outlookEntry.getString("CompanyName")) ; COMProxy.put(item.toObject(),"HomeAddress",outlookEntry.getString("HomeAddress")) ; COMProxy.put(item.toObject(),"HomeTelephoneNumber", outlookEntry.getString("HomeTelephoneNumber")) ; COMProxy.put(item.toObject(),"HomeFaxNumber", outlookEntry.getString("HomeFaxNumber")) ; COMProxy.put(item.toObject(),"Categories", outlookEntry.getString("Categories")); if (outlookEntry.getString("Birthday")!=null && !outlookEntry.getString("Birthday").equals(" ")) COMProxy.put(item.toObject(),"Birthday", outlookEntry.getString("Birthday")); }