/** * Get the called that is matchLevel stack frames before the call, * ignoring MOP frames. * * @param matchLevel how may call stacks down to look. * If it is less than 1 it is treated as though it was 1. * @return The Class of the matched caller, or null if there aren't * enough stackframes to satisfy matchLevel */ public static Class getCallingClass(int matchLevel) { return getCallingClass(matchLevel, Collections.EMPTY_SET); }
/** * Get the immediate calling class, ignoring MOP frames. * * @return The Class of the caller */ public static Class getCallingClass() { return getCallingClass(1); }
/** * Works exactly like ResourceBundle.getBundle(String, Locale). This is needed * because the java method depends on a particular stack configuration that * is not guaranteed in Groovy when calling the Java method. * * @param self placeholder variable used by Groovy categories; ignored for default static methods * @param bundleName the name of the bundle. * @param locale the specific locale * @return the resource bundle * @see java.util.ResourceBundle#getBundle(java.lang.String, java.util.Locale) * @since 1.6.0 */ public static ResourceBundle getBundle(ResourceBundle self, String bundleName, Locale locale) { Class c = ReflectionUtils.getCallingClass(); ClassLoader targetCL = c != null ? c.getClassLoader() : null; if (targetCL == null) targetCL = ClassLoader.getSystemClassLoader(); return ResourceBundle.getBundle(bundleName, locale, targetCL); }
public Class instanceCaller() { return ReflectionUtils.getCallingClass(); } }
public static Class staticClassCaller() { return ReflectionUtils.getCallingClass(); }
/** * Get the immediate calling class, ignoring MOP frames. * @return The Class of the caller */ public static Class getCallingClass() { return getCallingClass(1); }
/** * Get the called that is matchLevel stack frames before the call, * ignoring MOP frames. * @param matchLevel how may call stacks down to look. * If it is less than 1 it is treated as though it was 1. * @return The Class of the matched caller, or null if there aren't * enough stackframes to satisfy matchLevel */ public static Class getCallingClass(int matchLevel) { return getCallingClass(matchLevel, Collections.EMPTY_SET); }
/** * Get the immediate calling class, ignoring MOP frames. * @return The Class of the caller */ public static Class getCallingClass() { return getCallingClass(1); }
/** * Get the called that is matchLevel stack frames before the call, * ignoring MOP frames. * * @param matchLevel how may call stacks down to look. * If it is less than 1 it is treated as though it was 1. * @return The Class of the matched caller, or null if there aren't * enough stackframes to satisfy matchLevel */ public static Class getCallingClass(int matchLevel) { return getCallingClass(matchLevel, Collections.EMPTY_SET); }
/** * Get the immediate calling class, ignoring MOP frames. * * @return The Class of the caller */ public static Class getCallingClass() { return getCallingClass(1); }
/** * Get the called that is matchLevel stack frames before the call, * ignoring MOP frames. * @param matchLevel how may call stacks down to look. * If it is less than 1 it is treated as though it was 1. * @return The Class of the matched caller, or null if there aren't * enough stackframes to satisfy matchLevel */ public static Class getCallingClass(int matchLevel) { return getCallingClass(matchLevel, Collections.EMPTY_SET); }
@Override public Object run() { final Map map = (Map) arguments[0]; if (map.get("refObject") == null && map.get("classLoader") == null) { final Class callingClass = ReflectionUtils.getCallingClass(2); final ClassLoader classLoader = callingClass.getClassLoader(); map.put("classLoader", classLoader); } return GrapeMetaClass.super.invokeStaticMethod(object, methodName, arguments); } });
/** * Works exactly like ResourceBundle.getBundle(String, Locale). This is needed * because the java method depends on a particular stack configuration that * is not guaranteed in Groovy when calling the Java method. * * @see ResourceBundle#getBundle(String, Locale) * @param self placeholder variable used by Groovy categories; ignored for default static methods * @param bundleName the name of the bundle. * @param locale the speficic locale * @return the resource bundle * @since 1.6.0 */ public static ResourceBundle getBundle(ResourceBundle self, String bundleName, Locale locale) { ClassLoader targetCL = ReflectionUtils.getCallingClass().getClassLoader(); if (targetCL == null) targetCL = ClassLoader.getSystemClassLoader(); return ResourceBundle.getBundle(bundleName, locale, targetCL); } }
/** * Works exactly like ResourceBundle.getBundle(String, Locale). This is needed * because the java method depends on a particular stack configuration that * is not guaranteed in Groovy when calling the Java method. * * @param self placeholder variable used by Groovy categories; ignored for default static methods * @param bundleName the name of the bundle. * @param locale the specific locale * @return the resource bundle * @see java.util.ResourceBundle#getBundle(java.lang.String, java.util.Locale) * @since 1.6.0 */ public static ResourceBundle getBundle(ResourceBundle self, String bundleName, Locale locale) { Class c = ReflectionUtils.getCallingClass(); ClassLoader targetCL = c != null ? c.getClassLoader() : null; if (targetCL == null) targetCL = ClassLoader.getSystemClassLoader(); return ResourceBundle.getBundle(bundleName, locale, targetCL); }
/** * Works exactly like ResourceBundle.getBundle(String, Locale). This is needed * because the java method depends on a particular stack configuration that * is not guaranteed in Groovy when calling the Java method. * * @see ResourceBundle#getBundle(String, Locale) * @param self placeholder variable used by Groovy categories; ignored for default static methods * @param bundleName the name of the bundle. * @param locale the speficic locale * @return the resource bundle * @since 1.6.0 */ public static ResourceBundle getBundle(ResourceBundle self, String bundleName, Locale locale) { ClassLoader targetCL = ReflectionUtils.getCallingClass().getClassLoader(); if (targetCL == null) targetCL = ClassLoader.getSystemClassLoader(); return ResourceBundle.getBundle(bundleName, locale, targetCL); } }
@Override public ClassLoader chooseClassLoader( @SuppressWarnings("rawtypes") final Map args) { ClassLoader loader = (ClassLoader) args.get("classLoader"); if (this.isValidTargetClassLoader(loader)) { if (args.get("refObject") == null) { if (!args.containsKey("calleeDepth")) { loader = ReflectionUtils.getCallingClass((int) args.get( "calleeDepth")).getClassLoader(); } else { loader = ReflectionUtils.getCallingClass(1).getClassLoader(); } } while (loader != null && !this.isValidTargetClassLoader(loader)) { loader = loader.getParent(); } // if (!isValidTargetClassLoader(loader)) { // loader = Thread.currentThread().contextClassLoader // } // if (!isValidTargetClassLoader(loader)) { // loader = GrapeIvy.class.classLoader // } if (!isValidTargetClassLoader(loader)) { throw new RuntimeException("No suitable ClassLoader found for grab"); } } return loader; }