Search in sources :

Example 11 with Proxy

use of java.lang.reflect.Proxy in project VirtualApp by asLody.

the class ProviderHook method createProxy.

public static IInterface createProxy(boolean external, String authority, IInterface provider) {
    if (provider instanceof Proxy && Proxy.getInvocationHandler(provider) instanceof ProviderHook) {
        return provider;
    }
    ProviderHook.HookFetcher fetcher = ProviderHook.fetchHook(authority);
    if (fetcher != null) {
        ProviderHook hook = fetcher.fetch(external, provider);
        IInterface proxyProvider = ProviderHook.createProxy(provider, hook);
        if (proxyProvider != null) {
            provider = proxyProvider;
        }
    }
    return provider;
}
Also used : Proxy(java.lang.reflect.Proxy) IInterface(android.os.IInterface)

Example 12 with Proxy

use of java.lang.reflect.Proxy in project core by asyncj.

the class ActorManager method unblockResult.

public void unblockResult(Object actor1) {
    Proxy proxy = (Proxy) getReference(actor1);
    ((MethodHandler) Proxy.getInvocationHandler(proxy)).unblockResult();
}
Also used : Proxy(java.lang.reflect.Proxy)

Example 13 with Proxy

use of java.lang.reflect.Proxy in project robovm by robovm.

the class ProxyTest method test_isProxyClassLjava_lang_Class.

/**
     * java.lang.reflect.Proxy#isProxyClass(java.lang.Class)
     */
public void test_isProxyClassLjava_lang_Class() {
    Class proxy = Proxy.getProxyClass(Support_Proxy_I1.class.getClassLoader(), new Class[] { Support_Proxy_I1.class });
    class Fake extends Proxy {

        Fake() {
            super(null);
        }
    }
    Proxy fake = new Proxy(new InvocationHandler() {

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return null;
        }
    }) {
    };
    assertTrue("Does not believe its a Proxy class ", Proxy.isProxyClass(proxy));
    assertTrue("Proxy subclasses do not count ", !Proxy.isProxyClass(Fake.class));
    assertTrue("Is not a runtime generated Proxy class ", !Proxy.isProxyClass(fake.getClass()));
    boolean thrown = false;
    try {
        Proxy.isProxyClass(null);
    } catch (NullPointerException ex) {
        thrown = true;
    }
    assertTrue("NPE not thrown.", thrown);
}
Also used : Proxy(java.lang.reflect.Proxy) Support_Proxy_I1(tests.support.Support_Proxy_I1) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 14 with Proxy

use of java.lang.reflect.Proxy in project intellij-community by JetBrains.

the class BaseGradleProjectResolverExtension method printToolingProxyDiagnosticInfo.

private static void printToolingProxyDiagnosticInfo(@Nullable Object obj) {
    if (!LOG.isDebugEnabled() || obj == null)
        return;
    LOG.debug(String.format("obj: %s", obj));
    final Class<?> aClass = obj.getClass();
    LOG.debug(String.format("obj class: %s", aClass));
    LOG.debug(String.format("classloader: %s", aClass.getClassLoader()));
    for (Method m : aClass.getDeclaredMethods()) {
        LOG.debug(String.format("obj m: %s", m));
    }
    if (obj instanceof Proxy) {
        try {
            final Field hField = ReflectionUtil.findField(obj.getClass(), null, "h");
            hField.setAccessible(true);
            final Object h = hField.get(obj);
            final Field delegateField = ReflectionUtil.findField(h.getClass(), null, "delegate");
            delegateField.setAccessible(true);
            final Object delegate = delegateField.get(h);
            LOG.debug(String.format("delegate: %s", delegate));
            LOG.debug(String.format("delegate class: %s", delegate.getClass()));
            LOG.debug(String.format("delegate classloader: %s", delegate.getClass().getClassLoader()));
            for (Method m : delegate.getClass().getDeclaredMethods()) {
                LOG.debug(String.format("delegate m: %s", m));
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            LOG.debug(e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) Proxy(java.lang.reflect.Proxy) GroovyObject(groovy.lang.GroovyObject) Method(java.lang.reflect.Method)

Example 15 with Proxy

use of java.lang.reflect.Proxy in project jdk8u_jdk by JetBrains.

the class MBeanServerInvocationHandler method doLocally.

private Object doLocally(Object proxy, Method method, Object[] args) {
    final String methodName = method.getName();
    if (methodName.equals("equals")) {
        if (this == args[0]) {
            return true;
        }
        if (!(args[0] instanceof Proxy)) {
            return false;
        }
        final InvocationHandler ihandler = Proxy.getInvocationHandler(args[0]);
        if (ihandler == null || !(ihandler instanceof MBeanServerInvocationHandler)) {
            return false;
        }
        final MBeanServerInvocationHandler handler = (MBeanServerInvocationHandler) ihandler;
        return connection.equals(handler.connection) && objectName.equals(handler.objectName) && proxy.getClass().equals(args[0].getClass());
    } else if (methodName.equals("toString")) {
        return (isMXBean() ? "MX" : "M") + "BeanProxy(" + connection + "[" + objectName + "])";
    } else if (methodName.equals("hashCode")) {
        return objectName.hashCode() + connection.hashCode();
    } else if (methodName.equals("finalize")) {
        // ignore the finalizer invocation via proxy
        return null;
    }
    throw new RuntimeException("Unexpected method name: " + methodName);
}
Also used : Proxy(java.lang.reflect.Proxy) MXBeanProxy(com.sun.jmx.mbeanserver.MXBeanProxy) InvocationHandler(java.lang.reflect.InvocationHandler)

Aggregations

Proxy (java.lang.reflect.Proxy)19 InvocationHandler (java.lang.reflect.InvocationHandler)10 Method (java.lang.reflect.Method)3 IOException (java.io.IOException)2 Constructor (java.lang.reflect.Constructor)2 URLClassLoader (java.net.URLClassLoader)2 RMIClassLoader (java.rmi.server.RMIClassLoader)2 MBeanServerInvocationHandler (javax.management.MBeanServerInvocationHandler)2 ObjectName (javax.management.ObjectName)2 IInterface (android.os.IInterface)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargetFactory (com.facebook.buck.model.BuildTargetFactory)1 TestCellBuilder.createCellRoots (com.facebook.buck.rules.TestCellBuilder.createCellRoots)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 Preconditions (com.google.common.base.Preconditions)1 MXBeanProxy (com.sun.jmx.mbeanserver.MXBeanProxy)1 DATE (com.sun.jna.platform.win32.OaIdl.DATE)1 SAFEARRAY (com.sun.jna.platform.win32.OaIdl.SAFEARRAY)1 VARIANT_BOOL (com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL)1