Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
org.mozilla.xpcom.internal.XPCOMJavaProxy Class Reference

This class is used to pass XPCOM objects to Java functions. More...

Inheritance diagram for org.mozilla.xpcom.internal.XPCOMJavaProxy:
Inheritance graph
[legend]
Collaboration diagram for org.mozilla.xpcom.internal.XPCOMJavaProxy:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 XPCOMJavaProxy (long aXPCOMInstance)
 Default constructor.
Object invoke (Object aProxy, Method aMethod, Object[] aParams) throws Throwable
 All calls to the Java proxy are forwarded to this method.

Protected Member Functions

void finalizeProxy (Object aProxy) throws Throwable
 Called when the proxy is garbage collected by the JVM.

Static Protected Member Functions

static long getNativeXPCOMInstance (Object aProxy)
 Returns the XPCOM object that the given proxy references.
static Object createProxy (Class aInterface, long aXPCOMInstance)
 Creates a Proxy for the given XPCOM object.
static Integer proxyHashCode (Object aProxy)
 Handles method calls of java.lang.Object.hashCode
static Boolean proxyEquals (Object aProxy, Object aOther)
 Handles method calls of java.lang.Object.equals
static boolean isXPCOMJavaProxy (Object aObject)
 Indicates whether the given object is an XPCOMJavaProxy.
static native boolean isSameXPCOMObject (Object aProxy1, Object aProxy2)
 Checks if the two given XPCOMJavaProxy objects are proxies for the same XPCOM object.
static String proxyToString (Object aProxy)
 Handles method calls of java.lang.Object.toString
static native void finalizeProxyNative (Object aProxy)
static native Object callXPCOMMethod (Object aProxy, String aMethodName, Object[] aParams)
 Calls the XPCOM object referenced by the proxy with the given method.

Protected Attributes

long nativeXPCOMPtr
 Pointer to the XPCOM object for which we are a proxy.

Detailed Description

This class is used to pass XPCOM objects to Java functions.

A java.lang.reflect.Proxy instance is created using the expected interface, and all calls to the proxy are forwarded to the XPCOM object.

Definition at line 52 of file XPCOMJavaProxy.java.


Constructor & Destructor Documentation

Default constructor.

Parameters:
aXPCOMInstanceaddress of XPCOM object as a long

Definition at line 64 of file XPCOMJavaProxy.java.

                                             {
    nativeXPCOMPtr = aXPCOMInstance;
  }

Here is the caller graph for this function:


Member Function Documentation

static native Object org.mozilla.xpcom.internal.XPCOMJavaProxy.callXPCOMMethod ( Object  aProxy,
String  aMethodName,
Object[]  aParams 
) [static, protected]

Calls the XPCOM object referenced by the proxy with the given method.

Parameters:
aProxyProxy created by createProxy
aMethodNamename of method that we want to call
aParamsarray of params passed to method
Returns:
return value as defined by given method
Exceptions:
XPCOMExceptionif XPCOM method failed. Values of XPCOMException are defined by the method called.

Here is the caller graph for this function:

static Object org.mozilla.xpcom.internal.XPCOMJavaProxy.createProxy ( Class  aInterface,
long  aXPCOMInstance 
) [inline, static, protected]

Creates a Proxy for the given XPCOM object.

Parameters:
aInterfaceinterface from which to create Proxy
aXPCOMInstanceaddress of XPCOM object as a long
Returns:
Proxy of given XPCOM object

Definition at line 88 of file XPCOMJavaProxy.java.

                                                                             {
    // XXX We should really get the class loader from |aInterface|.  However,
    //     that class loader doesn't know about |XPCOMJavaProxyBase|.  So for
    //     now, we get the class loader that loaded |XPCOMJavaProxy|.  When
    //     we get rid of the "XPCOMJavaProxyBase.java" class, we can revert
    //     to the old method below.
//    return Proxy.newProxyInstance(aInterface.getClassLoader(),
    return Proxy.newProxyInstance(XPCOMJavaProxy.class.getClassLoader(),
            new Class[] { aInterface, XPCOMJavaProxyBase.class },
            new XPCOMJavaProxy(aXPCOMInstance));
  }

Here is the call graph for this function:

void org.mozilla.xpcom.internal.XPCOMJavaProxy.finalizeProxy ( Object  aProxy) throws Throwable [inline, protected]

Called when the proxy is garbage collected by the JVM.

Allows us to clean up any references to the XPCOM object.

Parameters:
aProxyreference to Proxy that is being garbage collected

Definition at line 235 of file XPCOMJavaProxy.java.

                                                               {
    finalizeProxyNative(aProxy);
    super.finalize();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static native void org.mozilla.xpcom.internal.XPCOMJavaProxy.finalizeProxyNative ( Object  aProxy) [static, protected]

Here is the caller graph for this function:

static long org.mozilla.xpcom.internal.XPCOMJavaProxy.getNativeXPCOMInstance ( Object  aProxy) [inline, static, protected]

Returns the XPCOM object that the given proxy references.

Parameters:
aProxyProxy created by createProxy
Returns:
address of XPCOM object as a long

Definition at line 75 of file XPCOMJavaProxy.java.

                                                              {
    XPCOMJavaProxy proxy = (XPCOMJavaProxy) Proxy.getInvocationHandler(aProxy);
    return proxy.nativeXPCOMPtr;
  }

Here is the call graph for this function:

Object org.mozilla.xpcom.internal.XPCOMJavaProxy.invoke ( Object  aProxy,
Method  aMethod,
Object[]  aParams 
) throws Throwable [inline]

All calls to the Java proxy are forwarded to this method.

This method takes care of a few of the Object method calls; all other calls are forwarded to the XPCOM object.

Parameters:
aProxyProxy created by createProxy
aMethodobject that describes the called method
aParamsarray of the arguments passed to the method
Returns:
return value as defined by given aMethod

Definition at line 111 of file XPCOMJavaProxy.java.

                           {
    String methodName = aMethod.getName();

    // Handle the three java.lang.Object methods that are passed to us.
    if (aMethod.getDeclaringClass() == Object.class)  {
      if (methodName.equals("hashCode"))  {
        return proxyHashCode(aProxy);
      }
      if (methodName.equals("equals")) {
        return proxyEquals(aProxy, aParams[0]);
      }
      if (methodName.equals("toString")) {
        return proxyToString(aProxy);
      }
      System.err.println("WARNING: Unhandled Object method [" +
                         methodName + "]");
      return null;
    }

    // Handle the 'finalize' method called during garbage collection
    if (aMethod.getDeclaringClass() == XPCOMJavaProxyBase.class) {
      if (methodName.equals("finalize")) {
        finalizeProxy(aProxy);
      } else {
        System.err.println("WARNING: Unhandled XPCOMJavaProxyBase method [" +
                           methodName + "]");
      }
      return null;
    }

    // If not already handled, pass method calls to XPCOM object.
    return callXPCOMMethod(aProxy, methodName, aParams);
  }

Here is the call graph for this function:

static native boolean org.mozilla.xpcom.internal.XPCOMJavaProxy.isSameXPCOMObject ( Object  aProxy1,
Object  aProxy2 
) [static, protected]

Checks if the two given XPCOMJavaProxy objects are proxies for the same XPCOM object.

Parameters:
aProxy1XPCOMJavaProxy created by createProxy
aProxy2XPCOMJavaProxy created by createProxy
Returns:
true if both proxies represent the same XPCOM object; false otherwise

Here is the caller graph for this function:

static boolean org.mozilla.xpcom.internal.XPCOMJavaProxy.isXPCOMJavaProxy ( Object  aObject) [inline, static, protected]

Indicates whether the given object is an XPCOMJavaProxy.

Parameters:
aObjectobject to check
Returns:
true if the given object is an XPCOMJavaProxy; false otherwise

Definition at line 192 of file XPCOMJavaProxy.java.

                                                            {
    if (aObject != null && Proxy.isProxyClass(aObject.getClass())) {
      InvocationHandler h = Proxy.getInvocationHandler(aObject);
      if (h instanceof XPCOMJavaProxy) {
        return true;
      }
    }
    return false;
  }

Here is the caller graph for this function:

static Boolean org.mozilla.xpcom.internal.XPCOMJavaProxy.proxyEquals ( Object  aProxy,
Object  aOther 
) [inline, static, protected]

Handles method calls of java.lang.Object.equals

Parameters:
aProxyProxy created by createProxy
aOtheranother object
Returns:
true if the given objects are the same; false otherwise
See also:
Object::equals(Object)

Definition at line 170 of file XPCOMJavaProxy.java.

                                                                     {
    // See if the two are the same Java object
    if (aProxy == aOther) {
      return Boolean.TRUE;
    } else {
      // If not, then see if they represent the same XPCOM object.  But first,
      // we need to check if |aOther| is an XPCOMJavaProxy.
      if (isXPCOMJavaProxy(aOther) && isSameXPCOMObject(aProxy, aOther)) {
        return Boolean.TRUE;
      }
    }
    return Boolean.FALSE;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static Integer org.mozilla.xpcom.internal.XPCOMJavaProxy.proxyHashCode ( Object  aProxy) [inline, static, protected]

Handles method calls of java.lang.Object.hashCode

Parameters:
aProxyProxy created by createProxy
Returns:
Integer object representing hash code of given object
See also:
Object::hashCode()

Definition at line 155 of file XPCOMJavaProxy.java.

                                                        {
    return new Integer(System.identityHashCode(aProxy));
  }

Here is the caller graph for this function:

static String org.mozilla.xpcom.internal.XPCOMJavaProxy.proxyToString ( Object  aProxy) [inline, static, protected]

Handles method calls of java.lang.Object.toString

Parameters:
aProxyProxy created by createProxy
Returns:
String representation of given object
See also:
Object::toString()

Definition at line 224 of file XPCOMJavaProxy.java.

                                                       {
    return aProxy.getClass().getInterfaces()[0].getName() + '@' +
           Integer.toHexString(aProxy.hashCode());
  }

Here is the caller graph for this function:


Member Data Documentation

Pointer to the XPCOM object for which we are a proxy.

Definition at line 57 of file XPCOMJavaProxy.java.


The documentation for this class was generated from the following file: