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.kuali.rice.ksb.messaging.KSBClientProxy.java

public static <T> T newInstance(String serviceQName, Class<T> interfaceClass)
        throws InstantiationException, IllegalAccessException {
    if (StringUtils.isBlank(serviceQName)) {
        throw new IllegalArgumentException("the qname was blank");
    }//w  w  w. j  av a  2s  .co  m

    if (interfaceClass == null) {
        throw new IllegalArgumentException("the interfaceClass was null");
    }

    @SuppressWarnings("unchecked")
    final T t = (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass },
            new KSBClientProxy(serviceQName));
    return t;
}

From source file:com.baidu.drapi.autosdk.core.JsonProxy.java

/**
 * Create the proxy instance of api client stub. Proxied by JsonProxy.
 * //w w  w  .j a  v  a 2  s. c o  m
 * @param <T> The proxy instannce type.
 * @param interfaces The proxy instannce type class.
 * @param service The original object.
 * @return The proxied object.
 * @throws ApiException 
 * @throws Throwable 
 */
@SuppressWarnings("unchecked")
public static <T> T createProxy(Class<T> interfaces, CommonService service) throws ApiException {
    JsonProxy<T> proxy = new JsonProxy<T>(interfaces, service);
    service.generateHeader();
    return (T) Proxy.newProxyInstance(JsonProxy.class.getClassLoader(), new Class<?>[] { interfaces }, proxy);
}

From source file:org.apache.olingo.ext.proxy.utils.ProxyUtils.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Object getEntityCollectionProxy(final AbstractService<?> service, final Class<?> typeRef,
        final Class<?> typeCollectionRef, final URI targetEntitySetURI, final ClientEntitySet entitySet,
        final URI uri, final boolean checkInTheContext) {

    final List<Object> items = extractItems(service, typeRef, entitySet, uri, checkInTheContext);

    return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
            new Class<?>[] { typeCollectionRef },
            new EntityCollectionInvocationHandler(service, items, typeCollectionRef, targetEntitySetURI,
                    uri == null ? null : service.getClient().newURIBuilder(uri.toASCIIString())));
}

From source file:com.github.bjoern2.yolotyrion.spring.xml.PropertyRepoFactoryBean.java

@Override
public PropertyRepository getObject() throws Exception {
    return (PropertyRepository) Proxy.newProxyInstance(repositoryInterface.getClassLoader(),
            new Class<?>[] { repositoryInterface }, getHandler());
}

From source file:com.github.bjoern2.yolotyrion.spring.xml.TemplateRepoFactoryBean.java

@Override
public TemplateRepository getObject() throws Exception {
    return (TemplateRepository) Proxy.newProxyInstance(repositoryInterface.getClassLoader(),
            new Class<?>[] { repositoryInterface }, getHandler());
}

From source file:org.gradle.model.internal.manage.state.ManagedModelElementInstanceFactory.java

public <T> T create(ManagedModelElement<T> element) {
    Class<T> type = element.getType();
    Object instance = Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[] { type },
            new ManagedModelElementInvocationHandler(element, store));
    store.add(instance);/*from  w w w . ja v a2  s  . co m*/
    @SuppressWarnings("unchecked")
    T typedInstance = (T) instance;
    return typedInstance;
}

From source file:com.nominanuda.hyperapi.HttpClientHyperApiFactory.java

public <T> T getInstance(String instanceHint, Class<? extends T> cl) {
    InvocationHandler handler = new HyperApiHttpInvocationHandler(cl, client,
            ifNull(uriPrefix, "") + ifNull(instanceHint, ""));
    Object p = Proxy.newProxyInstance(cl.getClassLoader(), new Class[] { cl }, handler);
    return cl.cast(p);
}

From source file:org.gradle.model.internal.manage.instance.ManagedProxyFactory.java

public <T> T createProxy(ModelElementState state, ClassLoader classLoader, Class<?>... interfaces) {
    StateBackedInvocationHandler invocationHandler = new StateBackedInvocationHandler(state);
    return Cast.uncheckedCast(Proxy.newProxyInstance(classLoader, interfaces, invocationHandler));
}

From source file:org.apache.openejb.assembler.classic.LazyValidatorTest.java

@Test
public void serialize() {
    final Serializable obj = Serializable.class.cast(Proxy.newProxyInstance(
            Thread.currentThread().getContextClassLoader(), new Class<?>[] { ValidatorFactory.class },
            new LazyValidator(Validation.buildDefaultValidatorFactory())));
    final LazyValidator deserialized = LazyValidator.class.cast(
            Proxy.getInvocationHandler(SerializationUtils.deserialize(SerializationUtils.serialize(obj))));
    final Validator validator = deserialized.getValidator();
    assertNotNull(validator);//from www .ja va 2 s .c o  m
}

From source file:ws.antonov.config.api.consumer.ConfigClientFactoryBean.java

@Override
protected T createInstance() throws Exception {
    return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass },
            new ConfigClientInvocationHandler(configClient));
}