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.apache.ibatis.plugin.Plugin.java

public static Object wrap(Object target, Interceptor interceptor) {
    Map<Class<?>, Set<Method>> signatureMap = getSignatureMap(interceptor);
    Class<?> type = target.getClass();
    Class<?>[] interfaces = getAllInterfaces(type, signatureMap);
    if (interfaces.length > 0) {
        return Proxy.newProxyInstance(type.getClassLoader(), interfaces,
                new Plugin(target, interceptor, signatureMap));
    }/*from w  w  w .  ja  v  a 2s . c o m*/
    return target;
}

From source file:org.reusables.jpa.HibernateEntityManagerFactoryBean.java

@Override
public HibernateEntityManager getObject() throws Exception {
    return (HibernateEntityManager) Proxy.newProxyInstance(getClass().getClassLoader(),
            new Class<?>[] { HibernateEntityManager.class }, this);
}

From source file:MBeanTyper.java

/**
 * create a typed object from an mbean//ww w.j  a v a 2 s  .  co m
 */
public static final Object typeMBean(MBeanServer server, ObjectName mbean, Class mainInterface)
        throws Exception {
    List interfaces = new ArrayList();
    if (mainInterface.isInterface()) {
        interfaces.add(mainInterface);
    }
    addInterfaces(mainInterface.getInterfaces(), interfaces);
    Class cl[] = (Class[]) interfaces.toArray(new Class[interfaces.size()]);
    if (DEBUG) {
        System.err
                .println("typeMean->server=" + server + ",mbean=" + mbean + ",mainInterface=" + mainInterface);
        for (int c = 0; c < cl.length; c++) {
            System.err.println("     :" + cl[c]);
        }
    }

    return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), cl,
            new MBeanTyperInvoker(server, mbean));
}

From source file:org.kuali.rice.ksb.messaging.BusClientFailureProxy.java

public static Object wrap(Object target, ServiceConfiguration serviceConfiguration) {
    return Proxy.newProxyInstance(ClassLoaderUtils.getDefaultClassLoader(),
            ContextClassLoaderProxy.getInterfacesToProxy(target),
            new BusClientFailureProxy(target, serviceConfiguration));
}

From source file:org.apache.sentry.service.thrift.SentryServiceClientPoolFactory.java

@Override
public SentryPolicyServiceClient create() throws Exception {
    LOGGER.debug("Creating Sentry Service Client...");
    boolean haEnabled = conf.getBoolean(ClientConfig.SERVER_HA_ENABLED, false);
    if (haEnabled) {
        return (SentryPolicyServiceClient) Proxy.newProxyInstance(
                SentryPolicyServiceClientDefaultImpl.class.getClassLoader(),
                SentryPolicyServiceClientDefaultImpl.class.getInterfaces(),
                new HAClientInvocationHandler(conf));
    } else {//from w ww.  ja  va2  s  . com
        return new SentryPolicyServiceClientDefaultImpl(conf);
    }
}

From source file:com.taobao.common.tedis.group.TedisGroup.java

@Override
public void init() {
    if (!inited) {
        if (this.cm == null) {
            this.cm = new DiamondConfigManager(appName, version);
        }//from   www.  j  av a2  s. c o m
        try {
            tedis = (RedisCommands) Proxy.newProxyInstance(RedisCommands.class.getClassLoader(),
                    new Class[] { RedisCommands.class }, new RedisGroupInvocationHandler());
        } catch (Exception e) {
            throw new TedisException("init failed", e);
        }
        inited = true;
    }
}

From source file:com.guang.eunormia.atomic.EunormiaSingle.java

public EunormiaSingle(ServerProperties prop) {
    this.prop = prop;

    this.pool_size = prop.pool_size;
    this.eunormia = (RedisCommands) Proxy.newProxyInstance(RedisCommands.class.getClassLoader(),
            new Class[] { RedisCommands.class }, new EunormiaInvocationHandler());

    for (int i = 0; i < pool_size; i++) {
        Eunormia eunormia = new Eunormia(prop.server.addr, prop.server.port, prop.timeout);
        if (null != prop.password && !"".equals(prop.password)) {
            eunormia.auth(prop.password);
        } else {//from ww w. ja v  a  2s.c  o  m
            eunormia.ping();
        }

        BatchThread thread = new BatchThread(i, eunormia);
        threadPool.add(thread);
        thread.start();
    }
}

From source file:org.broadleafcommerce.common.extension.ExtensionManager.java

/**
 * Should take in a className that matches the ExtensionHandler interface being managed.
 * @param className//from  www .j a  v a2 s . c  o m
 */
@SuppressWarnings("unchecked")
public ExtensionManager(Class<T> _clazz) {
    extensionHandler = (T) Proxy.newProxyInstance(_clazz.getClassLoader(), new Class[] { _clazz }, this);
}

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

public EventTimeDaoImpl(DataSource dataSource, PartitionConfig partitionConfig,
        DatabaseCompatibility databaseCompatibility) {
    this.template = (SimpleJdbcOperations) Proxy.newProxyInstance(SimpleJdbcOperations.class.getClassLoader(),
            new Class<?>[] { SimpleJdbcOperations.class }, new SimpleJdbcTemplateProxy(dataSource));
    this.partitionTableConfig = partitionConfig.getConfig(TABLE_EVENT_TIME);
    this.databaseCompatibility = databaseCompatibility;
    this.partitioner = databaseCompatibility.getRangePartitioner(dataSource, TABLE_EVENT_TIME, COLUMN_PROCESSED,
            partitionTableConfig.getPartitionDuration(), partitionTableConfig.getPartitionUnit());
    this.uuidConverter = databaseCompatibility.getUUIDConverter();
}

From source file:net.sourceforge.pmd.lang.java.ParserTstUtil.java

public static <E> Set<E> getNodes(LanguageVersion languageVersion, Class<E> clazz, String javaCode) {
    Collector<E> coll = new Collector<>(clazz);
    LanguageVersionHandler languageVersionHandler = languageVersion.getLanguageVersionHandler();
    ASTCompilationUnit cu = (ASTCompilationUnit) languageVersionHandler
            .getParser(languageVersionHandler.getDefaultParserOptions())
            .parse(null, new StringReader(javaCode));
    JavaParserVisitor jpv = (JavaParserVisitor) Proxy.newProxyInstance(JavaParserVisitor.class.getClassLoader(),
            new Class[] { JavaParserVisitor.class }, coll);
    jpv.visit(cu, null);/* w  w  w . jav  a 2s. c om*/
    return (Set<E>) coll.getCollection();
}