Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1.    public static AccessibleObject findInjectionTarget(ClassLoader loader, ResourceInjectionTargetMetaData target)
  2.    {
  3.       Class<?> clazz = null;
  4.       try
  5.       {
  6.          clazz = loader.loadClass(target.getInjectionTargetClass());
  7.       }
  8.       catch (ClassNotFoundException e)
  9.       {
  10.          throw new RuntimeException("<injection-target> class: " + target.getInjectionTargetClass() + " was not found in deployment");
  11.       }
  12.  
  13.       for (Field field : clazz.getDeclaredFields())
  14.       {
  15.          if (target.getInjectionTargetName().equals(field.getName())) return field;
  16.       }
  17.  
  18.       for (java.lang.reflect.Method method : clazz.getDeclaredMethods())
  19.       {
  20.          if (method.getName().equals(target.getInjectionTargetName())) return method;
  21.       }
  22.  
  23.       throw new RuntimeException("<injection-target> could not be found: " + target.getInjectionTargetClass() + "." + target.getInjectionTargetName());
  24.  
  25.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement