com.alibaba.dubbo.common.utils.ClassHelper Java Examples

The following examples show how to use com.alibaba.dubbo.common.utils.ClassHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdkCompiler.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(final String qualifiedClassName) throws ClassNotFoundException {
    JavaFileObject file = classes.get(qualifiedClassName);
    if (file != null) {
        byte[] bytes = ((JavaFileObjectImpl) file).getByteCode();
        return defineClass(qualifiedClassName, bytes, 0, bytes.length);
    }
    try {
        return ClassHelper.forNameWithCallerClassLoader(qualifiedClassName, getClass());
    } catch (ClassNotFoundException nf) {
        return super.findClass(qualifiedClassName);
    }
}
 
Example #2
Source File: JdkCompiler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(final String qualifiedClassName) throws ClassNotFoundException {
    JavaFileObject file = classes.get(qualifiedClassName);
    if (file != null) {
        byte[] bytes = ((JavaFileObjectImpl) file).getByteCode();
        return defineClass(qualifiedClassName, bytes, 0, bytes.length);
    }
    try {
        return ClassHelper.forNameWithCallerClassLoader(qualifiedClassName, getClass());
    } catch (ClassNotFoundException nf) {
        return super.findClass(qualifiedClassName);
    }
}
 
Example #3
Source File: Version.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void checkDuplicate(String path, boolean failOnError) {
	try {
		// 在ClassPath搜文件
		Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path);
		Set<String> files = new HashSet<String>();
		while (urls.hasMoreElements()) {
			URL url = urls.nextElement();
			if (url != null) {
				String file = url.getFile();
				if (file != null && file.length() > 0) {
					files.add(file);
				}
			}
		}
		// 如果有多个,就表示重复
		if (files.size() > 1) {
               String error = "Duplicate class " + path + " in " + files.size() + " jar " + files;
               if (failOnError) {
                   throw new IllegalStateException(error);
               } else {
			    logger.error(error);
               }
		}
	} catch (Throwable e) { // 防御性容错
		logger.error(e.getMessage(), e);
	}
}
 
Example #4
Source File: JdkCompiler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(final String qualifiedClassName) throws ClassNotFoundException {
    JavaFileObject file = classes.get(qualifiedClassName);
    if (file != null) {
        byte[] bytes = ((JavaFileObjectImpl) file).getByteCode();
        return defineClass(qualifiedClassName, bytes, 0, bytes.length);
    }
    try {
        return ClassHelper.forNameWithCallerClassLoader(qualifiedClassName, getClass());
    } catch (ClassNotFoundException nf) {
        return super.findClass(qualifiedClassName);
    }
}
 
Example #5
Source File: Version.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void checkDuplicate(String path, boolean failOnError) {
	try {
		// 在ClassPath搜文件
		Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path);
		Set<String> files = new HashSet<String>();
		while (urls.hasMoreElements()) {
			URL url = urls.nextElement();
			if (url != null) {
				String file = url.getFile();
				if (file != null && file.length() > 0) {
					files.add(file);
				}
			}
		}
		// 如果有多个,就表示重复
		if (files.size() > 1) {
               String error = "Duplicate class " + path + " in " + files.size() + " jar " + files;
               if (failOnError) {
                   throw new IllegalStateException(error);
               } else {
			    logger.error(error);
               }
		}
	} catch (Throwable e) { // 防御性容错
		logger.error(e.getMessage(), e);
	}
}
 
Example #6
Source File: JdkCompiler.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(final String qualifiedClassName) throws ClassNotFoundException {
    JavaFileObject file = classes.get(qualifiedClassName);
    if (file != null) {
        byte[] bytes = ((JavaFileObjectImpl) file).getByteCode();
        return defineClass(qualifiedClassName, bytes, 0, bytes.length);
    }
    try {
        return ClassHelper.forNameWithCallerClassLoader(qualifiedClassName, getClass());
    } catch (ClassNotFoundException nf) {
        return super.findClass(qualifiedClassName);
    }
}
 
Example #7
Source File: Version.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public static void checkDuplicate(String path, boolean failOnError) {
    try {
        // 在ClassPath搜文件
        Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path);
        Set<String> files = new HashSet<String>();
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            if (url != null) {
                String file = url.getFile();
                if (file != null && file.length() > 0) {
                    files.add(file);
                }
            }
        }
        // 如果有多个,就表示重复
        if (files.size() > 1) {
            String error = "Duplicate class " + path + " in " + files.size() + " jar " + files;
            if (failOnError) {
                throw new IllegalStateException(error);
            } else {
                logger.error(error);
            }
        }
    } catch (Throwable e) { // 防御性容错
        logger.error(e.getMessage(), e);
    }
}
 
Example #8
Source File: Version.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public static void checkDuplicate(String path, boolean failOnError) {
    try {
        // search in caller's classloader
        Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path);
        Set<String> files = new HashSet<String>();
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            if (url != null) {
                String file = url.getFile();
                if (file != null && file.length() > 0) {
                    files.add(file);
                }
            }
        }
        // duplicated jar is found
        if (files.size() > 1) {
            String error = "Duplicate class " + path + " in " + files.size() + " jar " + files;
            if (failOnError) {
                throw new IllegalStateException(error);
            } else {
                logger.error(error);
            }
        }
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
    }
}
 
Example #9
Source File: Version.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public static void checkDuplicate(String path, boolean failOnError) {
	try {
		// 在ClassPath搜文件
		Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path);
		Set<String> files = new HashSet<String>();
		while (urls.hasMoreElements()) {
			URL url = urls.nextElement();
			if (url != null) {
				String file = url.getFile();
				if (file != null && file.length() > 0) {
					files.add(file);
				}
			}
		}
		// 如果有多个,就表示重复
		if (files.size() > 1) {
               String error = "Duplicate class " + path + " in " + files.size() + " jar " + files;
               if (failOnError) {
                   throw new IllegalStateException(error);
               } else {
			    logger.error(error);
               }
		}
	} catch (Throwable e) { // 防御性容错
		logger.error(e.getMessage(), e);
	}
}
 
Example #10
Source File: JdkCompiler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(final String qualifiedClassName) throws ClassNotFoundException {
    JavaFileObject file = classes.get(qualifiedClassName);
    if (file != null) {
        byte[] bytes = ((JavaFileObjectImpl) file).getByteCode();
        return defineClass(qualifiedClassName, bytes, 0, bytes.length);
    }
    try {
        return ClassHelper.forNameWithCallerClassLoader(qualifiedClassName, getClass());
    } catch (ClassNotFoundException nf) {
        return super.findClass(qualifiedClassName);
    }
}
 
Example #11
Source File: Version.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static void checkDuplicate(String path, boolean failOnError) {
	try {
		// 在ClassPath搜文件
		Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path);
		Set<String> files = new HashSet<String>();
		while (urls.hasMoreElements()) {
			URL url = urls.nextElement();
			if (url != null) {
				String file = url.getFile();
				if (file != null && file.length() > 0) {
					files.add(file);
				}
			}
		}
		// 如果有多个,就表示重复
		if (files.size() > 1) {
               String error = "Duplicate class " + path + " in " + files.size() + " jar " + files;
               if (failOnError) {
                   throw new IllegalStateException(error);
               } else {
			    logger.error(error);
               }
		}
	} catch (Throwable e) { // 防御性容错
		logger.error(e.getMessage(), e);
	}
}
 
Example #12
Source File: JdkCompiler.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
protected Class<?> findClass(final String qualifiedClassName) throws ClassNotFoundException {
    JavaFileObject file = classes.get(qualifiedClassName);
    if (file != null) {
        byte[] bytes = ((JavaFileObjectImpl) file).getByteCode();
        return defineClass(qualifiedClassName, bytes, 0, bytes.length);
    }
    try {
        return ClassHelper.forNameWithCallerClassLoader(qualifiedClassName, getClass());
    } catch (ClassNotFoundException nf) {
        return super.findClass(qualifiedClassName);
    }
}
 
Example #13
Source File: CompactedObjectInputStream.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public CompactedObjectInputStream(InputStream in, ClassLoader cl) throws IOException
{
	super(in);
	mClassLoader = cl == null ? ClassHelper.getClassLoader() : cl;
}
 
Example #14
Source File: CompactedObjectInputStream.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public CompactedObjectInputStream(InputStream in, ClassLoader cl) throws IOException
{
	super(in);
	mClassLoader = cl == null ? ClassHelper.getClassLoader() : cl;
}
 
Example #15
Source File: CompactedObjectInputStream.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public CompactedObjectInputStream(InputStream in, ClassLoader cl) throws IOException
{
	super(in);
	mClassLoader = cl == null ? ClassHelper.getClassLoader() : cl;
}
 
Example #16
Source File: CompactedObjectInputStream.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public CompactedObjectInputStream(InputStream in, ClassLoader cl) throws IOException
{
	super(in);
	mClassLoader = cl == null ? ClassHelper.getClassLoader() : cl;
}
 
Example #17
Source File: ClassGenerator.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public Class<?> toClass() {
    return toClass(ClassHelper.getClassLoader(ClassGenerator.class), getClass().getProtectionDomain());
}
 
Example #18
Source File: CompactedObjectInputStream.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public CompactedObjectInputStream(InputStream in, ClassLoader cl) throws IOException {
    super(in);
    mClassLoader = cl == null ? ClassHelper.getClassLoader() : cl;
}
 
Example #19
Source File: CompactedObjectInputStream.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public CompactedObjectInputStream(InputStream in, ClassLoader cl) throws IOException
{
	super(in);
	mClassLoader = cl == null ? ClassHelper.getClassLoader() : cl;
}
 
Example #20
Source File: Mixin.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
/**
 * mixin interface and delegates.
 * all class must be public.
 *
 * @param ics interface class array.
 * @param dcs delegate class array.
 * @return Mixin instance.
 */
public static Mixin mixin(Class<?>[] ics, Class<?>[] dcs) {
    return mixin(ics, dcs, ClassHelper.getCallerClassLoader(Mixin.class));
}
 
Example #21
Source File: Proxy.java    From dubbox with Apache License 2.0 2 votes vote down vote up
/**
 * Get proxy.
 * 
 * @param ics interface class array.
 * @return Proxy instance.
 */
public static Proxy getProxy(Class<?>... ics)
{
	return getProxy(ClassHelper.getCallerClassLoader(Proxy.class), ics);
}
 
Example #22
Source File: Proxy.java    From dubbox with Apache License 2.0 2 votes vote down vote up
/**
 * Get proxy.
 * 
 * @param ics interface class array.
 * @return Proxy instance.
 */
public static Proxy getProxy(Class<?>... ics)
{
	return getProxy(ClassHelper.getCallerClassLoader(Proxy.class), ics);
}
 
Example #23
Source File: Mixin.java    From dubbox with Apache License 2.0 2 votes vote down vote up
/**
 * mixin interface and delegates.
 * all class must be public.
 * 
 * @param ics interface class array.
 * @param dcs delegate class array.
 * @return Mixin instance.
 */
public static Mixin mixin(Class<?>[] ics, Class<?>[] dcs)
{
	return mixin(ics, dcs, ClassHelper.getCallerClassLoader(Mixin.class));
}
 
Example #24
Source File: Proxy.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
/**
 * Get proxy.
 *
 * @param ics interface class array.
 * @return Proxy instance.
 */
public static Proxy getProxy(Class<?>... ics) {
    return getProxy(ClassHelper.getClassLoader(Proxy.class), ics);
}
 
Example #25
Source File: Proxy.java    From dubbox with Apache License 2.0 2 votes vote down vote up
/**
 * Get proxy.
 * 
 * @param ics interface class array.
 * @return Proxy instance.
 */
public static Proxy getProxy(Class<?>... ics)
{
	return getProxy(ClassHelper.getCallerClassLoader(Proxy.class), ics);
}
 
Example #26
Source File: Mixin.java    From dubbox with Apache License 2.0 2 votes vote down vote up
/**
 * mixin interface and delegates.
 * all class must be public.
 * 
 * @param ics interface class array.
 * @param dcs delegate class array.
 * @return Mixin instance.
 */
public static Mixin mixin(Class<?>[] ics, Class<?>[] dcs)
{
	return mixin(ics, dcs, ClassHelper.getCallerClassLoader(Mixin.class));
}
 
Example #27
Source File: Proxy.java    From dubbo3 with Apache License 2.0 2 votes vote down vote up
/**
 * Get proxy.
 *
 * @param ics interface class array.
 * @return Proxy instance.
 */
public static Proxy getProxy(Class<?>... ics) {
    return getProxy(ClassHelper.getCallerClassLoader(Proxy.class), ics);
}
 
Example #28
Source File: Mixin.java    From dubbo3 with Apache License 2.0 2 votes vote down vote up
/**
 * mixin interface and delegates.
 * all class must be public.
 * 
 * @param ics interface class array.
 * @param dcs delegate class array.
 * @return Mixin instance.
 */
public static Mixin mixin(Class<?>[] ics, Class<?>[] dcs)
{
	return mixin(ics, dcs, ClassHelper.getCallerClassLoader(Mixin.class));
}
 
Example #29
Source File: Proxy.java    From dubbox-hystrix with Apache License 2.0 2 votes vote down vote up
/**
 * Get proxy.
 * 
 * @param ics interface class array.
 * @return Proxy instance.
 */
public static Proxy getProxy(Class<?>... ics)
{
	return getProxy(ClassHelper.getCallerClassLoader(Proxy.class), ics);
}
 
Example #30
Source File: Mixin.java    From dubbox-hystrix with Apache License 2.0 2 votes vote down vote up
/**
 * mixin interface and delegates.
 * all class must be public.
 * 
 * @param ics interface class array.
 * @param dcs delegate class array.
 * @return Mixin instance.
 */
public static Mixin mixin(Class<?>[] ics, Class<?>[] dcs)
{
	return mixin(ics, dcs, ClassHelper.getCallerClassLoader(Mixin.class));
}