Example usage for java.lang.reflect Proxy isProxyClass

List of usage examples for java.lang.reflect Proxy isProxyClass

Introduction

In this page you can find the example usage for java.lang.reflect Proxy isProxyClass.

Prototype

public static boolean isProxyClass(Class<?> cl) 

Source Link

Document

Returns true if the given class is a proxy class.

Usage

From source file:com.exadel.flamingo.flex.messaging.amf.io.util.DefaultClassGetter.java

protected Class<?> extractFromProxy(Class<?> clazz) {
    if (Proxy.isProxyClass(clazz)) {
        clazz = extractFromProxy(clazz.getInterfaces()[0]);
    } else {/*from  w  w w .j  a va2 s  . c om*/
        try {
            if (Class.forName("javassist.util.proxy.ProxyObject").isAssignableFrom(clazz)) {
                clazz = extractFromProxy(clazz.getSuperclass());
            }
        } catch (ClassNotFoundException ex) {
            if (log.isDebugEnabled())
                log.debug("Class javassist.util.proxy.ProxyObject can not be located");
        }
    }
    return clazz;
}

From source file:org.springframework.aop.support.AopUtils.java

/**
 * Return whether the given object is a J2SE dynamic proxy.
 * @param object the object to check//from   www  .java 2s  . c  om
 * @see java.lang.reflect.Proxy#isProxyClass
 */
public static boolean isJdkDynamicProxy(Object object) {
    return (object != null && Proxy.isProxyClass(object.getClass()));
}

From source file:com.laxser.blitz.web.impl.thread.ControllerEngine.java

public ControllerEngine(Module module, ControllerRef controllerRef) {
    this.module = module;
    this.controller = controllerRef.getControllerObject();
    this.controllerClass = controllerRef.getControllerClass();
    this.viewPrefix = controllerRef.getControllerName() + "-";
    this.proxiedController = Proxy.isProxyClass(this.controller.getClass());
    if (proxiedController && logger.isDebugEnabled()) {
        logger.debug("it's a proxied controller: " + controllerClass.getName());
    }//from w ww .  ja  va 2  s.c o m
}

From source file:org.bytesoft.openjtcc.supports.marshall.TerminatorMarshallerImpl.java

@Override
public TerminatorInfo marshallTerminator(RemoteTerminator terminator) throws IOException {
    if (Proxy.isProxyClass(terminator.getClass())) {
        InvocationHandler obj = Proxy.getInvocationHandler(terminator);
        if (RemoteTerminatorHandler.class.isInstance(obj)) {
            RemoteTerminatorHandler handler = (RemoteTerminatorHandler) obj;
            return handler.getRemoteTerminatorInfo();
        }/*  w  w w  . j  a v  a 2  s .c  o  m*/
    }
    return null;
}

From source file:org.qi4j.runtime.value.ValueInstance.java

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }/*from w  w w  .  j  a v  a 2 s  .c om*/
    if (o == null || !Proxy.isProxyClass(o.getClass())) {
        return false;
    }

    try {
        ValueInstance that = (ValueInstance) Proxy.getInvocationHandler(o);
        return state.equals(that.state);
    } catch (ClassCastException e) {
        return false;
    }
}

From source file:com.liferay.arkadiko.test.TestFive.java

public void testExcludeClassNames() throws Exception {
    Bundle installedBundle = installAndStart(_context, "/bundles/bundle-one/bundle-one.jar");

    InterfaceOne interfaceOne = null;/*from  www  . j a  v  a2s  .co m*/

    HasDependencyOnInterfaceOne bean = (HasDependencyOnInterfaceOne) _context
            .getBean(HasDependencyOnInterfaceOne.class.getName());

    try {
        interfaceOne = bean.getInterfaceOne();

        assertFalse("interfaceOne is a proxy", Proxy.isProxyClass(interfaceOne.getClass()));
    } finally {
        installedBundle.uninstall();
    }

    assertFalse("interfaceOne is a proxy", Proxy.isProxyClass(interfaceOne.getClass()));
}

From source file:com.liferay.arkadiko.test.TestFour.java

public void testExcludeBeanName() throws Exception {
    Bundle installedBundle = installAndStart(_context, "/bundles/bundle-one/bundle-one.jar");

    InterfaceOne interfaceOne = null;//w w w.java2  s  .  c  o  m

    HasDependencyOnInterfaceOne bean = (HasDependencyOnInterfaceOne) _context
            .getBean(HasDependencyOnInterfaceOne.class.getName());

    try {
        interfaceOne = bean.getInterfaceOne();

        assertFalse("interfaceOne is a proxy", Proxy.isProxyClass(interfaceOne.getClass()));
    } finally {
        installedBundle.uninstall();
    }

    interfaceOne = bean.getInterfaceOne();

    assertFalse("interfaceOne is a proxy", Proxy.isProxyClass(interfaceOne.getClass()));
}

From source file:org.kuali.rice.core.api.util.ClassLoaderUtils.java

/**
 * Unwraps the underlying object from the given proxy (which may itself be a proxy).  If the
 * given object is not a valid proxy, then null is returned.
 *///  w w  w  .  j  av  a  2s.  c o  m
private static Object unwrapFromProxyOnce(Object proxy) {
    if (proxy != null && Proxy.isProxyClass(proxy.getClass())) {
        InvocationHandler invocationHandler = Proxy.getInvocationHandler(proxy);
        if (invocationHandler instanceof TargetedInvocationHandler) {
            return ((TargetedInvocationHandler) invocationHandler).getTarget();
        }
    }
    return null;
}

From source file:com.liferay.arkadiko.test.TestTwo.java

public void testDeployBundleWithImplementation() throws Exception {
    InterfaceOne interfaceOne = null;//from w w  w .  j  a  v a 2  s.c  om

    HasDependencyOnInterfaceOne bean = (HasDependencyOnInterfaceOne) _context
            .getBean(HasDependencyOnInterfaceOne.class.getName());

    // Test if the original impl is used

    interfaceOne = bean.getInterfaceOne();

    assertTrue("interfaceOne is not a proxy", Proxy.isProxyClass(interfaceOne.getClass()));

    InvocationHandler ih = Proxy.getInvocationHandler(interfaceOne);

    assertTrue("ih not instanceof AKServiceTrackerInvocationHandler",
            ih instanceof ServiceTrackerInvocationHandler);

    ServiceTrackerInvocationHandler akih = (ServiceTrackerInvocationHandler) ih;

    assertTrue("currentService not equal to originalService",
            akih.getCurrentService() == akih.getOriginalService());

    // Install the bundle with the alternative impl

    Bundle installedBundle = installAndStart(_context, "/bundles/bundle-one/bundle-one.jar");

    try {
        // Test that the alternative impl is used

        interfaceOne = bean.getInterfaceOne();

        assertTrue("interfaceOne is not a proxy", Proxy.isProxyClass(interfaceOne.getClass()));

        ih = Proxy.getInvocationHandler(interfaceOne);

        assertTrue("ih not instanceof AKServiceTrackerInvocationHandler",
                ih instanceof ServiceTrackerInvocationHandler);

        akih = (ServiceTrackerInvocationHandler) ih;

        assertFalse("currentService() is equal to originalService",
                akih.getCurrentService() == akih.getOriginalService());
    } finally {
        // Uninstall the bundle

        installedBundle.uninstall();
    }

    // Test again if the original impl is used

    interfaceOne = bean.getInterfaceOne();

    assertTrue("interfaceOne is not a proxy", Proxy.isProxyClass(interfaceOne.getClass()));

    ih = Proxy.getInvocationHandler(interfaceOne);

    assertTrue("ih not instanceof AKServiceTrackerInvocationHandler",
            ih instanceof ServiceTrackerInvocationHandler);

    akih = (ServiceTrackerInvocationHandler) ih;

    assertTrue("currentService() is equal to originalService",
            akih.getCurrentService() == akih.getOriginalService());
}

From source file:com.liferay.arkadiko.test.TestSeven.java

public void testLoadOSGiOnlyDepedency() throws Exception {
    InterfaceOne interfaceOne = null;//from   w  ww.j a  v a  2  s.c  om

    HasDependencyOnInterfaceOne bean = (HasDependencyOnInterfaceOne) _context
            .getBean(HasDependencyOnInterfaceOne.class.getName());

    interfaceOne = bean.getInterfaceOne();

    assertTrue("interfaceOne is not a proxy", Proxy.isProxyClass(interfaceOne.getClass()));

    InvocationHandler ih = Proxy.getInvocationHandler(interfaceOne);

    assertTrue("ih not instanceof AKServiceTrackerInvocationHandler",
            ih instanceof ServiceTrackerInvocationHandler);

    ServiceTrackerInvocationHandler akih = (ServiceTrackerInvocationHandler) ih;

    assertTrue("currentService not equal to originalService",
            akih.getCurrentService() == akih.getOriginalService());

    try {
        interfaceOne.getValue();

        Assert.fail("Should have thrown exception");
    } catch (Exception e) {
        assertTrue(e instanceof IllegalStateException);
    }

    // Install the bundle with the dependency impl

    Bundle installedBundle = installAndStart(_context, "/bundles/bundle-one/bundle-one.jar");

    try {
        // Test to see that the dependency impl is used

        interfaceOne = bean.getInterfaceOne();

        assertTrue("interfaceOne is not a proxy", Proxy.isProxyClass(interfaceOne.getClass()));

        ih = Proxy.getInvocationHandler(interfaceOne);

        assertTrue("ih not instanceof AKServiceTrackerInvocationHandler",
                ih instanceof ServiceTrackerInvocationHandler);

        akih = (ServiceTrackerInvocationHandler) ih;

        assertFalse("currentService is equal to originalService",
                akih.getCurrentService() == akih.getOriginalService());

        String testString = "test string";

        interfaceOne.setValue(testString);

        assertEquals("dependency impl returns the incorrect value", interfaceOne.getValue(), testString);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        installedBundle.uninstall();
    }

    interfaceOne = bean.getInterfaceOne();

    assertTrue("interfaceOne is not a proxy", Proxy.isProxyClass(interfaceOne.getClass()));

    ih = Proxy.getInvocationHandler(interfaceOne);

    assertTrue("ih not instanceof AKServiceTrackerInvocationHandler",
            ih instanceof ServiceTrackerInvocationHandler);

    akih = (ServiceTrackerInvocationHandler) ih;

    assertTrue("currentService is equal to originalService",
            akih.getCurrentService() == akih.getOriginalService());

    try {
        interfaceOne.getValue();

        Assert.fail("Should have thrown an exception");
    } catch (Exception e) {
        assertTrue(e instanceof IllegalStateException);
    }
}