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

The following examples show how to use com.alibaba.dubbo.common.utils.ClassHelper. These examples are extracted from open source projects. 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 Project: dubbo-2.6.5   Source File: Version.java    License: 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 2
Source Project: dubbo-2.6.5   Source File: JdkCompiler.java    License: 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 Project: dubbox   Source File: Version.java    License: 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 Project: dubbox   Source File: JdkCompiler.java    License: 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 Project: dubbox-hystrix   Source File: Version.java    License: 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 Project: dubbox-hystrix   Source File: JdkCompiler.java    License: 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 Project: dubbo3   Source File: Version.java    License: 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 Project: dubbo3   Source File: JdkCompiler.java    License: 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 9
Source Project: dubbox   Source File: Version.java    License: 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 Project: dubbox   Source File: JdkCompiler.java    License: 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 Project: dubbox   Source File: Version.java    License: 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 Project: dubbox   Source File: JdkCompiler.java    License: 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 Project: dubbo-2.6.5   Source File: ClassGenerator.java    License: Apache License 2.0 4 votes vote down vote up
public Class<?> toClass() {
    return toClass(ClassHelper.getClassLoader(ClassGenerator.class), getClass().getProtectionDomain());
}
 
Example 14
Source Project: dubbo-2.6.5   Source File: CompactedObjectInputStream.java    License: 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 Project: dubbox   Source File: CompactedObjectInputStream.java    License: 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 Project: dubbox-hystrix   Source File: CompactedObjectInputStream.java    License: 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 Project: dubbo3   Source File: CompactedObjectInputStream.java    License: 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 18
Source Project: dubbox   Source File: CompactedObjectInputStream.java    License: 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 Project: dubbox   Source File: CompactedObjectInputStream.java    License: 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 Project: dubbo-2.6.5   Source File: Mixin.java    License: 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 Project: dubbo-2.6.5   Source File: Proxy.java    License: 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 22
Source Project: dubbox   Source File: Mixin.java    License: 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 23
Source Project: dubbox   Source File: Proxy.java    License: 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 24
Source Project: dubbox-hystrix   Source File: Mixin.java    License: 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 25
Source Project: dubbox-hystrix   Source File: Proxy.java    License: 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 Project: dubbo3   Source File: Mixin.java    License: 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 Project: dubbo3   Source File: Proxy.java    License: 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 Project: dubbox   Source File: Mixin.java    License: 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 Project: dubbox   Source File: Proxy.java    License: 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 Project: dubbox   Source File: Mixin.java    License: 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));
}