org.jinterop.dcom.impls
Class JIObjectFactory

java.lang.Object
  extended by org.jinterop.dcom.impls.JIObjectFactory

public class JIObjectFactory
extends java.lang.Object

Factory class for creating COM objects.

Sample Usage:-
//Assume comObject is the reference to IJIComObject, obtained earlier...
newComObject = (IJIComObject)comObject.queryInterface("76A6415B-CB41-11d1-8B02-00600806D9B6");//ISWbemLocator
//This will obtain the dispatch interface
dispatch = (IJIDispatch)JIObjectFactory.narrowObject(newComObject.queryInterface(IJIDispatch.IID));

Since:
2.0 (formerly JIComFactory)

Constructor Summary
JIObjectFactory()
           
 
Method Summary
static java.lang.String attachEventHandler(IJIComObject comObject, java.lang.String sourceUUID, IJIComObject eventListener)
           Attaches an event handler to comObject for the source event interface of COM , identified by the sourceUUID.
static IJIComObject buildObject(JISession session, byte[] rawBytes)
          Returns a COM Object from raw bytes.
static IJIComObject buildObject(JISession session, byte[] rawBytes, java.lang.String ipAddress)
          Returns a COM Object from raw bytes.
static IJIComObject buildObject(JISession session, JILocalCoClass javaComponent)
          Returns a local COM Object representation for the Java component.
static void detachEventHandler(IJIComObject comObject, java.lang.String identifier)
          Detaches the event handler identified by identifier and associated with this comObject.
static IJIComObject narrowObject(IJIComObject comObject)
          Narrows the comObject into its right type based on it's IID.
static IJIComObject narrowObject(JISession session, IJIComObject comObject)
          Typically used in the Man-In-The-Middle scenario.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JIObjectFactory

public JIObjectFactory()
Method Detail

attachEventHandler

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

Attaches an event handler to comObject for the source event interface of COM , identified by the sourceUUID. The event listener is itself identified by eventListener. An exception will be raised if sourceUUID is not supported by the COM Server.

Parameters:
comObject - object to which the listener will be attached.
sourceUUID - IID of the call back interface.
eventListener - IJIComObject obtained using buildObject(JISession, JILocalCoClass)
Returns:
string identifier for this connection, please save this for eventual release using detachEventHandler(IJIComObject, String)
Throws:
JIException
java.lang.IllegalArgumentException - if any parameter is null or sourceUUID is empty.

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. This method will raise an exception if the identifier is invalid.

Parameters:
comObject -
identifier -
Throws:
JIException

narrowObject

public static IJIComObject narrowObject(IJIComObject comObject)
                                 throws JIException
Narrows the comObject into its right type based on it's IID. For example, passing a comObject which is a COM IDispatch reference will return a reference which can be safely casted to IJIDispatch interface.

Parameters:
comObject -
Returns:
Throws:
JIException
java.lang.IllegalArgumentException - if comObject is null or a local reference.

buildObject

public static IJIComObject buildObject(JISession session,
                                       JILocalCoClass javaComponent)
                                throws JIException
Returns a local COM Object representation for the Java component. IJIComObject.IsLocalReference() method will return true for all objects built by this method. Another important point to note is that a javaComponent can only export one reference to itself. Reusing the same javaComponent in another call to this method will raise an exception.

Parameters:
session - session to attach comObject to.
javaComponent -
Returns:
Throws:
JIException

buildObject

public static IJIComObject buildObject(JISession session,
                                       byte[] rawBytes)
                                throws JIException
Returns a COM Object from raw bytes. These bytes must conform to the Marshalled Interface Pointer template as per DCOM specifications.

Parameters:
session - session to attach comObject to. If required the framework will create a new session for this comObject and link the session to the new one. This new session will be destroyed when the parent session is destroyed.
rawBytes - bytes representing the interface pointer.
Returns:
Throws:
JIException
java.lang.IllegalArgumentException - if rawBytes is an invalid representation.

buildObject

public static IJIComObject buildObject(JISession session,
                                       byte[] rawBytes,
                                       java.lang.String ipAddress)
                                throws JIException
Returns a COM Object from raw bytes. These bytes must conform to the Marshalled Interface Pointer template as per DCOM specifications.

Parameters:
session - session to attach comObject to. If required the framework will create a new session for this comObject and link the session to the new one. This new session will be destroyed when the parent session is destroyed.
rawBytes - bytes representing the interface pointer.
ipAddress - can be null. Sometimes there are many adapters (virtual as well) on the Target machine to which this interface pointer belongs, which may get sent as part of the interface pointer and consequently this call will fail since it is a possibility that IP is not reachable via this machine. The developer can send in the valid IP and if found in the interface pointer list will be used to talk to the target machine, overriding the other IP addresses present in the interface pointer. If this IP is not found then the "machine name" binding will be used. If this param is null then the first binding obtained from the interface pointer is used.
Returns:
Throws:
JIException
java.lang.IllegalArgumentException - if rawBytes is an invalid representation.

narrowObject

public static IJIComObject narrowObject(JISession session,
                                        IJIComObject comObject)
                                 throws JIException
Typically used in the Man-In-The-Middle scenario.

Some possible use-cases :-

Parameters:
session - session to attach comObject to. If required the framework will create a new session for this comObject and link the session to the new one. This new session will be destroyed when the parent session is destroyed.
comObject - drifting object.
Returns:
Throws:
JIException
java.lang.IllegalArgumentException - if comObject is null or a local reference.
See Also:
IJIComObject.isLocalReference()