Bug 305815 - Better organize Java interfaces. Implement getGREPathWithProperties(). r=bsmedberg, r=lbustelo. Not part of default build.
git-svn-id: svn://10.0.0.236/trunk@183165 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -35,9 +35,10 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package org.mozilla.xpcom;
|
||||
package org.mozilla.xpcom.internal;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import org.mozilla.xpcom.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -45,7 +46,7 @@ import java.lang.reflect.*;
|
||||
* <code>java.lang.reflect.Proxy</code> instance is created using the expected
|
||||
* interface, and all calls to the proxy are forwarded to the XPCOM object.
|
||||
*/
|
||||
public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
public class XPCOMJavaProxy implements InvocationHandler {
|
||||
|
||||
/**
|
||||
* Pointer to the XPCOM object for which we are a proxy.
|
||||
@@ -57,11 +58,22 @@ public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
*
|
||||
* @param aXPCOMInstance address of XPCOM object as a long
|
||||
*/
|
||||
public XPCOMJavaProxy(long aXPCOMInstance)
|
||||
{
|
||||
public XPCOMJavaProxy(long aXPCOMInstance) {
|
||||
nativeXPCOMPtr = aXPCOMInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XPCOM object that the given proxy references.
|
||||
*
|
||||
* @param aProxy Proxy created by <code>createProxy</code>
|
||||
*
|
||||
* @return address of XPCOM object as a long
|
||||
*/
|
||||
protected static long getNativeXPCOMInstance(Object aProxy) {
|
||||
XPCOMJavaProxy proxy = (XPCOMJavaProxy) Proxy.getInvocationHandler(aProxy);
|
||||
return proxy.nativeXPCOMPtr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Proxy for the given XPCOM object.
|
||||
*
|
||||
@@ -70,12 +82,10 @@ public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
*
|
||||
* @return Proxy of given XPCOM object
|
||||
*/
|
||||
protected static Object createProxy(Class aInterface, long aXPCOMInstance)
|
||||
{
|
||||
protected static Object createProxy(Class aInterface, long aXPCOMInstance) {
|
||||
return Proxy.newProxyInstance(aInterface.getClassLoader(),
|
||||
new Class[] { aInterface,
|
||||
XPCOMJavaProxyBase.class },
|
||||
new XPCOMJavaProxy(aXPCOMInstance));
|
||||
new Class[] { aInterface, XPCOMJavaProxyBase.class },
|
||||
new XPCOMJavaProxy(aXPCOMInstance));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +100,7 @@ public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
* @return return value as defined by given <code>aMethod</code>
|
||||
*/
|
||||
public Object invoke(Object aProxy, Method aMethod, Object[] aParams)
|
||||
throws Throwable
|
||||
{
|
||||
throws Throwable {
|
||||
String methodName = aMethod.getName();
|
||||
|
||||
// Handle the three java.lang.Object methods that are passed to us.
|
||||
@@ -134,8 +143,7 @@ public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
*
|
||||
* @see Object#hashCode()
|
||||
*/
|
||||
protected static Integer proxyHashCode(Object aProxy)
|
||||
{
|
||||
protected static Integer proxyHashCode(Object aProxy) {
|
||||
return new Integer(System.identityHashCode(aProxy));
|
||||
}
|
||||
|
||||
@@ -150,11 +158,28 @@ public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
*
|
||||
* @see Object#equals(Object)
|
||||
*/
|
||||
protected static Boolean proxyEquals(Object aProxy, Object aOther)
|
||||
{
|
||||
protected static Boolean proxyEquals(Object aProxy, Object aOther) {
|
||||
return (aProxy == aOther ? Boolean.TRUE : Boolean.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the given object is an XPCOMJavaProxy.
|
||||
*
|
||||
* @param aObject object to check
|
||||
*
|
||||
* @return <code>true</code> if the given object is an XPCOMJavaProxy;
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
protected static boolean isXPCOMJavaProxy(Object aObject) {
|
||||
if (Proxy.isProxyClass(aObject.getClass())) {
|
||||
InvocationHandler h = Proxy.getInvocationHandler(aObject);
|
||||
if (h instanceof XPCOMJavaProxy) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles method calls of <code>java.lang.Object.toString</code>
|
||||
*
|
||||
@@ -164,44 +189,23 @@ public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
*
|
||||
* @see Object#toString()
|
||||
*/
|
||||
protected static String proxyToString(Object aProxy)
|
||||
{
|
||||
protected static String proxyToString(Object aProxy) {
|
||||
return aProxy.getClass().getInterfaces()[0].getName() + '@' +
|
||||
Integer.toHexString(aProxy.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the given object is an XPCOMJavaProxy.
|
||||
* Called when the proxy is garbage collected by the JVM. Allows us to clean
|
||||
* up any references to the XPCOM object.
|
||||
*
|
||||
* @param aObject object to check
|
||||
*
|
||||
* @return <code>true</code> if the given object is an XPCOMJavaProxy;
|
||||
* <code>false</code> otherwise
|
||||
* @param aProxy reference to Proxy that is being garbage collected
|
||||
*/
|
||||
protected static boolean isXPCOMJavaProxy(Object aObject)
|
||||
{
|
||||
Class objectClass = aObject.getClass();
|
||||
if (Proxy.isProxyClass(objectClass)) {
|
||||
Class[] interfaces = objectClass.getInterfaces();
|
||||
if (interfaces[interfaces.length-1] == XPCOMJavaProxyBase.class) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
protected void finalizeProxy(Object aProxy) throws Throwable {
|
||||
finalizeProxyNative(aProxy);
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the XPCOM object that the given proxy references.
|
||||
*
|
||||
* @param aProxy Proxy created by <code>createProxy</code>
|
||||
*
|
||||
* @return address of XPCOM object as a long
|
||||
*/
|
||||
protected static long getNativeXPCOMInstance(Object aProxy)
|
||||
{
|
||||
XPCOMJavaProxy proxy = (XPCOMJavaProxy) Proxy.getInvocationHandler(aProxy);
|
||||
return proxy.nativeXPCOMPtr;
|
||||
}
|
||||
protected static native void finalizeProxyNative(Object aProxy);
|
||||
|
||||
/**
|
||||
* Calls the XPCOM object referenced by the proxy with the given method.
|
||||
@@ -215,16 +219,8 @@ public final class XPCOMJavaProxy implements InvocationHandler {
|
||||
* @exception XPCOMException if XPCOM method failed. Values of XPCOMException
|
||||
* are defined by the method called.
|
||||
*/
|
||||
protected static native
|
||||
Object callXPCOMMethod(Object aProxy, String aMethodName, Object[] aParams);
|
||||
|
||||
/**
|
||||
* Called when the proxy is garbage collected by the JVM. Allows us to clean
|
||||
* up any references to the XPCOM object.
|
||||
*
|
||||
* @param aProxy reference to Proxy that is being garbage collected
|
||||
*/
|
||||
protected static native
|
||||
void finalizeProxy(Object aProxy);
|
||||
protected static native Object callXPCOMMethod(Object aProxy,
|
||||
String aMethodName, Object[] aParams);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user