/dbmigrate/src/main/java/com/agimatec/commons/util/ClassUtils.java

http://agimatec-tools.googlecode.com/ · Java · 32 lines · 10 code · 3 blank · 19 comment · 1 complexity · 1b6893ac0b062d97b6dfecd9977269ee MD5 · raw file

  1. package com.agimatec.commons.util;
  2. /**
  3. * <p>Title: Agimatec GmbH</p>
  4. * <p>Description: Reflection util for class access.</p>
  5. * <p>Copyright (c) 2007</p>
  6. * <p>Company: Agimatec GmbH </p>
  7. *
  8. * @author Roman Stumm
  9. */
  10. public class ClassUtils {
  11. /**
  12. * @return contextclassloader or the caller classLoader
  13. */
  14. public static ClassLoader getClassLoader() {
  15. final ClassLoader cl = Thread.currentThread().getContextClassLoader();
  16. // if Reflection.getCallerClass(3) is not the correct stuff, just drop it.
  17. // return cl == null ? Reflection.getCallerClass(3).getClassLoader() : cl;
  18. return cl == null ? ClassUtils.class.getClassLoader() : cl;
  19. }
  20. /**
  21. * @param className
  22. * @return a Class
  23. * @throws ClassNotFoundException
  24. * @see Class#forName(String)
  25. */
  26. public static Class forName(String className) throws ClassNotFoundException {
  27. return Class.forName(className, true, getClassLoader());
  28. }
  29. }