当前位置: 首页>>代码示例>>Java>>正文


Java Proxy.getProxyClass方法代码示例

本文整理汇总了Java中java.lang.reflect.Proxy.getProxyClass方法的典型用法代码示例。如果您正苦于以下问题:Java Proxy.getProxyClass方法的具体用法?Java Proxy.getProxyClass怎么用?Java Proxy.getProxyClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.reflect.Proxy的用法示例。


在下文中一共展示了Proxy.getProxyClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
public void run() throws Exception {
    boolean hasAccess = loader != null || hasAccess();
    try {
        proxyClass = Proxy.getProxyClass(loader, interfaces);
        if (!hasAccess) {
            throw new RuntimeException("should have no permission to create proxy class");
        }
    } catch (AccessControlException e) {
        if (hasAccess) {
            throw e;
        }
        if (e.getPermission().getClass() != RuntimePermission.class ||
                !e.getPermission().getName().equals("getClassLoader")) {
            throw e;
        }
        return;
    }

    if (Modifier.isPublic(proxyClass.getModifiers())) {
        throw new RuntimeException(proxyClass + " must be non-public");
    }
    newProxyInstance();
    newInstanceFromConstructor(proxyClass);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:NonPublicProxyClass.java

示例2: genArrays

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Generate proxy arrays.
 */
Proxy[][] genArrays(int size, int narrays) throws Exception {
    Class proxyClass =
        Proxy.getProxyClass(DummyInterface.class.getClassLoader(),
                new Class[] { DummyInterface.class });
    Constructor proxyCons =
        proxyClass.getConstructor(new Class[] { InvocationHandler.class });
    Object[] consArgs = new Object[] { new DummyHandler() };
    Proxy[][] arrays = new Proxy[narrays][size];
    for (int i = 0; i < narrays; i++) {
        for (int j = 0; j < size; j++) {
            arrays[i][j] = (Proxy) proxyCons.newInstance(consArgs);
        }
    }
    return arrays;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ProxyArrays.java

示例3: getInterfaceProxyHelper

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
@Override
protected Object getInterfaceProxyHelper(ContextFactory cf,
                                         Class<?>[] interfaces)
{
    // XXX: How to handle interfaces array withclasses from different
    // class loaders? Using cf.getApplicationClassLoader() ?
    ClassLoader loader = interfaces[0].getClassLoader();
    Class<?> cl = Proxy.getProxyClass(loader, interfaces);
    Constructor<?> c;
    try {
        c = cl.getConstructor(new Class[] { InvocationHandler.class });
    } catch (NoSuchMethodException ex) {
        // Should not happen
        throw Kit.initCause(new IllegalStateException(), ex);
    }
    return c;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:18,代码来源:VMBridge_jdk15.java

示例4: verifyProxyClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
void verifyProxyClass() throws Exception {
    Class<?> c = Proxy.getProxyClass(loader, interfaces);
    Module m = c.getModule();
    if (target != null && m != target) {
        throw new RuntimeException(c.getModule() + " not expected: " + target);
    }
    // expect dynamic module
    if (target == null && (!m.isNamed() || !m.getName().startsWith("jdk.proxy"))) {
        throw new RuntimeException("Unexpected:" + m);
    }

    Module module = c.getModule();
    try {
        Constructor<?> cons = c.getConstructor(InvocationHandler.class);
        cons.newInstance(ih);
        if (module.isNamed()) {
            throw new RuntimeException("expected IAE not thrown");
        }
    } catch (IllegalAccessException e) {
        if (!module.isNamed()) {
            throw e;
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ProxyModuleMapping.java

示例5: resolveProxyClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Return a proxy class that implements the interfaces named in a proxy
 * class descriptor. Do this using the class loader assigned to this
 * Context.
 */
@Override
protected Class<?> resolveProxyClass(String[] interfaces)
        throws IOException, ClassNotFoundException {

    Class<?>[] cinterfaces = new Class[interfaces.length];
    for (int i = 0; i < interfaces.length; i++) {
        cinterfaces[i] = classLoader.loadClass(interfaces[i]);
    }

    try {
        return Proxy.getProxyClass(classLoader, cinterfaces);
    } catch (IllegalArgumentException e) {
        throw new ClassNotFoundException(null, e);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:21,代码来源:CustomObjectInputStream.java

示例6: resolveProxyClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Resolve a proxy class that implements the given interfaces. First
 * attempts to use the default resolution method provided by
 * ObjectInputStream. If that fails with a ClassNotFoundException then
 * tries to resolve the interfaces and create the proxy class using
 * the GATE classloader instead.
 */
@Override
protected Class<?> resolveProxyClass(String[] interfaces) throws IOException,
        ClassNotFoundException {
  try {
    return super.resolveProxyClass(interfaces);
  }
  catch(ClassNotFoundException cnfe) {
    // failed to load with the normal method, try the GATE ClassLoader
    // instead
    Class<?>[] interfaceClasses = new Class<?>[interfaces.length];
    for(int i = 0; i < interfaces.length; i++) {
      interfaceClasses[i] = Class.forName(interfaces[i], false, Gate
              .getClassLoader());
    }
    return Proxy.getProxyClass(Gate.getClassLoader(), interfaceClasses);
  }
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:25,代码来源:GateAwareObjectInputStream.java

示例7: resolveProxyClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
protected Class<?> resolveProxyClass(String[] interfaces) throws
       IOException, ClassNotFoundException {
    ClassLoader nonPublicLoader = null;
    boolean hasNonPublicInterface = false;

    // define proxy in class loader of non-public interface(s), if any
    Class<?>[] classObjs = new Class<?>[interfaces.length];
    for (int i = 0; i < interfaces.length; i++) {
        Class<?> cl = Class.forName(interfaces[i], false, classLoader);
        if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
            if (hasNonPublicInterface) {
                if (nonPublicLoader != cl.getClassLoader()) {
                    throw new IllegalAccessError(
                       "conflicting non-public interface class loaders");
                }
            } else {
                nonPublicLoader = cl.getClassLoader();
                hasNonPublicInterface = true;
            }
        }
        classObjs[i] = cl;
    }
    try {
        @SuppressWarnings("deprecation")
        Class<?> proxyClass = Proxy.getProxyClass(hasNonPublicInterface ?
               nonPublicLoader : classLoader, classObjs);
        return proxyClass;
    } catch (IllegalArgumentException e) {
        throw new ClassNotFoundException(null, e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:Obj.java

示例8: ProxyListener

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/** @param listener listener to delegate to
*/
ProxyListener(Class<?> c, Class<?> api, EventListener listener) {
    super(api, listener);

    try {
        Reference<Constructor<?>> ref = constructors.get(c);
        Constructor<?> proxyConstructor = ref == null ? null : ref.get();

        if (proxyConstructor == null) {
            Class<?> proxyClass = Proxy.getProxyClass(c.getClassLoader(), c);
            proxyConstructor = proxyClass.getConstructor(InvocationHandler.class);
            proxyConstructor.setAccessible(true);
            constructors.put(c, new SoftReference<Constructor<?>>(proxyConstructor));
        }

        Object p;

        try {
            p = proxyConstructor.newInstance(this);
        } catch (NoClassDefFoundError err) {
            // if for some reason the actual creation of the instance
            // from constructor fails, try it once more using regular
            // method, see issue 30449
            p = Proxy.newProxyInstance(c.getClassLoader(), new Class<?>[] { c }, this);
        }

        proxy = p;
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:WeakListenerImpl.java

示例9: getResultSetConstructor

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
protected Constructor<?> getResultSetConstructor() throws NoSuchMethodException {
    if (resultSetConstructor == null) {
        Class<?> proxyClass = Proxy.getProxyClass(StatementDecoratorInterceptor.class.getClassLoader(),
                new Class[] { ResultSet.class });
        resultSetConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
    }
    return resultSetConstructor;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:9,代码来源:StatementDecoratorInterceptor.java

示例10: resolveProxyClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Return a proxy class that implements the interfaces named in a proxy
 * class descriptor. Do this using the class loader assigned to this
 * Context.
 */
protected Class resolveProxyClass(String[] interfaces)
    throws IOException, ClassNotFoundException {

    Class[] cinterfaces = new Class[interfaces.length];
    for (int i = 0; i < interfaces.length; i++)
        cinterfaces[i] = classLoader.loadClass(interfaces[i]);

    try {
        return Proxy.getProxyClass(classLoader, cinterfaces);
    } catch (IllegalArgumentException e) {
        throw new ClassNotFoundException(null, e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:CustomObjectInputStream.java

示例11: wrapDataSource

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
protected Object wrapDataSource(Object datasource, String username, String password) throws NamingException {
	try {
		Class<?> proxyClass = Proxy.getProxyClass(datasource.getClass().getClassLoader(),
				datasource.getClass().getInterfaces());
		Constructor<?> proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
		DataSourceHandler handler = new DataSourceHandler((DataSource) datasource, username, password);
		return proxyConstructor.newInstance(handler);
	} catch (Exception x) {
		if (x instanceof InvocationTargetException) {
			Throwable cause = x.getCause();
			if (cause instanceof ThreadDeath) {
				throw (ThreadDeath) cause;
			}
			if (cause instanceof VirtualMachineError) {
				throw (VirtualMachineError) cause;
			}
			if (cause instanceof Exception) {
				x = (Exception) cause;
			}
		}
		if (x instanceof NamingException)
			throw (NamingException) x;
		else {
			NamingException nx = new NamingException(x.getMessage());
			nx.initCause(x);
			throw nx;
		}
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:30,代码来源:DataSourceLinkFactory.java

示例12: wrapDataSource

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
protected Object wrapDataSource(Object datasource, String username, String password) throws NamingException {
    try {
        Class<?> proxyClass = Proxy.getProxyClass(datasource.getClass().getClassLoader(), datasource.getClass().getInterfaces());
        Constructor<?> proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
        DataSourceHandler handler = new DataSourceHandler((DataSource)datasource, username, password);
        return proxyConstructor.newInstance(handler);    
    }catch (Exception x) {
        if (x instanceof InvocationTargetException) {
            Throwable cause = x.getCause();
            if (cause instanceof ThreadDeath) {
                throw (ThreadDeath) cause;
            }
            if (cause instanceof VirtualMachineError) {
                throw (VirtualMachineError) cause;
            }
            if (cause instanceof Exception) {
                x = (Exception) cause;
            }
        }
        if (x instanceof NamingException) throw (NamingException)x;
        else {
            NamingException nx = new NamingException(x.getMessage());
            nx.initCause(x);
            throw nx;
        }
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:28,代码来源:DataSourceLinkFactory.java

示例13: getConstructor

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Creates a constructor for a proxy class, if one doesn't already exist
 * @param idx - the index of the constructor
 * @param clazz - the interface that the proxy will implement
 * @return - returns a constructor used to create new instances
 * @throws NoSuchMethodException
 */
protected Constructor<?> getConstructor(int idx, Class<?> clazz) throws NoSuchMethodException {
    if (constructors[idx]==null) {
        Class<?> proxyClass = Proxy.getProxyClass(SlowQueryReport.class.getClassLoader(), new Class[] {clazz});
        constructors[idx] = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
    }
    return constructors[idx];
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:15,代码来源:AbstractQueryReport.java

示例14: loadProxyClass

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
/**
 * Define a proxy class in the given class loader.  The proxy
 * class will implement the given interfaces Classes.
 */
private static Class<?> loadProxyClass(ClassLoader loader, Class<?>[] interfaces)
    throws ClassNotFoundException
{
    try {
        return Proxy.getProxyClass(loader, interfaces);
    } catch (IllegalArgumentException e) {
        throw new ClassNotFoundException(
            "error creating dynamic proxy class", e);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:LoaderHandler.java

示例15: createProxyConstructor

import java.lang.reflect.Proxy; //导入方法依赖的package包/类
private static <T> Constructor<T> createProxyConstructor(@Nullable LoadingCache<CacheKey, ClassLoader> cache, Class<T> interfaceClass,
                                                         Class<?>... otherInterfaceClasses) {
    Class<?>[] interfaceClasses = new Class[1 + otherInterfaceClasses.length];
    interfaceClasses[0] = interfaceClass;
    ClassLoader classLoader;
    if (otherInterfaceClasses.length == 0) {
        classLoader = interfaceClass.getClassLoader();
    } else {
        System.arraycopy(otherInterfaceClasses, 0, interfaceClasses, 1, otherInterfaceClasses.length);

        List<ClassLoader> classLoaders = extractClassloaderList(interfaceClasses);
        if (classLoaders.size() == 1) {
            classLoader = classLoaders.get(0);
        } else if (cache != null) {
            classLoader = cache.getUnchecked(new CacheKey(classLoaders));
        } else {
            classLoader = createClassLoader(classLoaders);
        }
    }
    Class<?> uncheckedProxyClass = Proxy.getProxyClass(classLoader, interfaceClasses);
    Class<T> proxyClass = interfaceClass.getClass().cast(uncheckedProxyClass);
    try {
        return proxyClass.getConstructor(InvocationHandler.class);
    } catch (NoSuchMethodException e) {
        throw new StoreException(e);
    }
}
 
开发者ID:Axway,项目名称:iron,代码行数:28,代码来源:ProxyConstructorFactory.java


注:本文中的java.lang.reflect.Proxy.getProxyClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。