Example usage for java.lang.reflect Proxy newProxyInstance

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

Introduction

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

Prototype

private static Object newProxyInstance(Class<?> caller, 
            Constructor<?> cons, InvocationHandler h) 

Source Link

Usage

From source file:org.cloudfoundry.tools.timeout.monitor.BridgedHttpServletResponseMonitorFactory.java

@SuppressWarnings("unchecked")
public T getMonitor() {
    return (T) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { getProxyClass() },
            new InvocationHandlerImpl());
}

From source file:com.bekioui.jaxrs.client.factory.ResteasyClientFactory.java

@Override
@SuppressWarnings("unchecked")
public <T> T create(Class<T> clazz) {
    return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), new Class[] { clazz },
            new ProxyInvocationHandler(target.proxy(clazz)));
}

From source file:org.zenoss.zep.dao.impl.HeartbeatDaoImpl.java

public HeartbeatDaoImpl(DataSource ds) {
    this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(),
            new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(ds));
}

From source file:org.force66.beantester.utils.GenericProxyHandlerTest.java

private Object makeProxy(Class<?> interfaceType) {
    return Proxy.newProxyInstance(interfaceType.getClassLoader(), new Class[] { interfaceType },
            new GenericProxyHandler(interfaceType));
}

From source file:org.jsconf.core.impl.ProxyPostProcessor.java

public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    if (bean.getClass().getInterfaces().length > 0) {
        BeanProxy proxy = this.proxyRef.get(beanName);
        if (proxy == null) {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            List<Class<?>> asList = new ArrayList<>();
            asList.addAll(Arrays.asList(bean.getClass().getInterfaces()));
            asList.add(BeanProxy.class);
            Class<?>[] interfaces = asList.toArray(new Class<?>[asList.size()]);
            proxy = (BeanProxy) Proxy.newProxyInstance(cl, interfaces, new ProxyHandler());
            this.proxyRef.put(beanName, proxy);
        }//from   w w  w  . ja v  a 2s  .co  m
        proxy.setBean(bean);
        return proxy;
    } else {
        throw new BeanCreationException(beanName,
                String.format("Only bean with interface can be proxy : %s", beanName));
    }
}

From source file:org.apache.hadoop.hive.metastore.RawStoreProxy.java

public static RawStore getProxy(HiveConf hiveConf, Configuration conf, String rawStoreClassName, int id)
        throws MetaException {

    Class<? extends RawStore> baseClass = (Class<? extends RawStore>) MetaStoreUtils
            .getClass(rawStoreClassName);

    RawStoreProxy handler = new RawStoreProxy(hiveConf, conf, baseClass, id);

    // Look for interfaces on both the class and all base classes.
    return (RawStore) Proxy.newProxyInstance(RawStoreProxy.class.getClassLoader(), getAllInterfaces(baseClass),
            handler);//from ww  w  .j ava 2  s  .  co  m
}

From source file:org.kuali.rice.ksb.messaging.serviceproxies.AsynchronousServiceCallProxy.java

public static Object createInstance(List<Endpoint> endpoints, AsynchronousCallback callback,
        Serializable context, String value1, String value2) {
    if (endpoints == null || endpoints.isEmpty()) {
        throw new RuntimeException("Cannot create service proxy, no service(s) passed in.");
    }/*from ww w  .java 2 s.co  m*/
    try {
        return Proxy.newProxyInstance(ClassLoaderUtils.getDefaultClassLoader(),
                ContextClassLoaderProxy.getInterfacesToProxy(endpoints.get(0).getService()),
                new AsynchronousServiceCallProxy(endpoints, callback, context, value1, value2));
    } catch (Exception e) {
        throw new RiceRuntimeException(e);
    }
}

From source file:org.code_house.service.jolokia.Jolokia.java

public static <T> T newMBeanProxy(J4pClient connection, ObjectName objectName, Class<T> interfaceClass) {
    return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass },
            new Jolokia(connection, objectName));
}

From source file:org.kuali.rice.kew.validation.RuleValidationAttributeResolverImpl.java

@Override
public RuleValidationAttribute resolveRuleValidationAttribute(final String attributeName, String applicationId)
        throws Exception {
    final RuleValidationAttributeExporterService service = findRuleValidationAttributeExporterService(
            applicationId);/*from   w w  w .  ja va2  s.  c  o  m*/
    return (RuleValidationAttribute) Proxy.newProxyInstance(this.getClass().getClassLoader(),
            new Class<?>[] { RuleValidationAttribute.class }, new RuleValidationAttributeInvocationHandler() {
                @Override
                protected ValidationResults invokeValidate(RuleValidationContext context) throws Exception {
                    return service.validate(attributeName, context);
                }
            });
}

From source file:com.futureplatforms.kirin.internal.attic.ProxyGenerator.java

public <T> T javascriptProxyForModule(Class<T> baseInterface, Class<?>... otherClasses) {
    Class<?>[] allClasses;//from  w  ww  .  j a  v  a2s.  c  o  m

    if (otherClasses.length == 0) {
        allClasses = new Class[] { baseInterface };
    } else {
        allClasses = new Class[otherClasses.length + 1];
        allClasses[0] = baseInterface;
        System.arraycopy(otherClasses, 0, allClasses, 1, otherClasses.length);
    }
    InvocationHandler h = new InvocationHandler() {
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            mKirinHelper.jsMethod(method.getName(), (Object[]) args);
            return null;
        }
    };

    Object proxy = Proxy.newProxyInstance(baseInterface.getClassLoader(), allClasses, h);
    return baseInterface.cast(proxy);
}