org.jinterop.dcom.win32
Class JIComFactory

java.lang.Object
  extended by org.jinterop.dcom.win32.JIComFactory

public class JIComFactory
extends java.lang.Object

Helper class for creating COM interfaces.
Sample Usage:-
//Assume comStub is the reference to JIComServer, obtained earlier...
IJIUnknown unknown = comStub.createInstance();
// This call will result into a QueryInterface for the IDispatch
IJIDispatch dispatch = (IJIDispatch)JIComFactory.createCOMInstance(JIComFactory.IID_IDispatch,unknown);

Another example:-
//From MSExcel2 example
int dispId = dispatch.getIDsOfNames("Workbooks");
JIVariant outVal = dispatch.get(dispId);
JIInterfacePointer ptr = outVal.getObjectAsInterfacePointer();
// This call wraps the JIInterfacePointer into it's actual type, based on it's IID (ptr.getIID())
IJIDispatch dispatchOfWorkBooks =(IJIDispatch)JIComFactory.createCOMInstance(unknown,ptr);

Since:
1.0

Field Summary
static java.lang.String IID_IDispatch
          IID of IDispatch [IJIDispatch].
static java.lang.String IID_IEnumVARIANT
          IID of IEnumVARIANT [IJIEnumVARIANT].
static java.lang.String IID_ITypeInfo
          IID of ITypeInfo [IJITypeInfo].
static java.lang.String IID_ITypeLib
          IID of ITypeLib [IJITypeLib].
 
Constructor Summary
JIComFactory()
           
 
Method Summary
static java.lang.String attachEventHandler(IJIComObject comObject, java.lang.String sourceUUID, JIInterfacePointer eventListener)
           Attaches an Event Handler to this comObject for the source event interface of COM , identified by the sourceUUID.
static IJIComObject createCOMInstance(IJIComObject template, JIInterfacePointer ptr)
          Returns an IJIComObject as reference to the interface defined by ptr.getIID().
static IJIComObject createCOMInstance(java.lang.String IID, IJIComObject iUnknown)
          Returns an IJIComObject as reference to the interface defined by IID.
static void detachEventHandler(IJIComObject comObject, java.lang.String identifier)
          Detaches the event handler identified by identifier and associated with this comObject.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IID_IDispatch

public static final java.lang.String IID_IDispatch
IID of IDispatch [IJIDispatch].

See Also:
Constant Field Values

IID_ITypeInfo

public static final java.lang.String IID_ITypeInfo
IID of ITypeInfo [IJITypeInfo].

See Also:
Constant Field Values

IID_ITypeLib

public static final java.lang.String IID_ITypeLib
IID of ITypeLib [IJITypeLib].

See Also:
Constant Field Values

IID_IEnumVARIANT

public static final java.lang.String IID_IEnumVARIANT
IID of IEnumVARIANT [IJIEnumVARIANT].

See Also:
Constant Field Values
Constructor Detail

JIComFactory

public JIComFactory()
Method Detail

createCOMInstance

public static IJIComObject createCOMInstance(java.lang.String IID,
                                             IJIComObject iUnknown)
                                      throws JIException
Returns an IJIComObject as reference to the interface defined by IID. Performs a QueryInterface on the iUnknown parameter for this IID.

Parameters:
IID - interface identifier of the requested interface.
iUnknown - unknown reference to queryInterface on.
Returns:
IJIComObject , null if IID is null
Throws:
JIException

createCOMInstance

public static IJIComObject createCOMInstance(IJIComObject template,
                                             JIInterfacePointer ptr)
                                      throws JIException

Returns an IJIComObject as reference to the interface defined by ptr.getIID(). This API creates a IJIComObject based on the ptr, the JISession and JIComServer
is taken from the template. No QueryInterface is performed in this case. The new object will belong to the session to which the template belongs.

Parameters:
template - IJIComObject whose basic parameters such as JIComServer will be used while creating the new Instance.
ptr - reference used for creating the new instance.
Returns:
IJIComObject , if template or ptr is null then an exception will be thrown
Throws:
JIException

attachEventHandler

public static java.lang.String attachEventHandler(IJIComObject comObject,
                                                  java.lang.String sourceUUID,
                                                  JIInterfacePointer eventListener)
                                           throws JIException

Attaches an Event Handler to this comObject for the source event interface of COM , identified by the sourceUUID. The event listener is itself identified by eventListener. It is obtained by JIInterfacePointer.getInterfacePointer(JISession,JIJavaCoClass) api. A JIException will get thrown if sourceUUID is not supported by the COM Server.

Parameters:
comObject -
sourceUUID -
eventListener -
Returns:
String identifier for this connection, please save this for eventual release using detachEventHandler
Throws:
JIException

detachEventHandler

public static void detachEventHandler(IJIComObject comObject,
                                      java.lang.String identifier)
                               throws JIException
Detaches the event handler identified by identifier and associated with this comObject.

Parameters:
comObject -
identifier -
Throws:
JIException