/** * When called from a method it will return the class calling that method. * * @return the immediate calling class */ public static Class<?> getCallingClass() { return getCallingClass(1); // add 1 for this method }
/** * Creates a class loader that finds resources for the calling class that * may not be in the class' package. Use this only within classes that are * directly looking up their resources. */ CWClassLoader() { owner = CallContext.getCallingClass(); }
/** * Generic resource URL fetcher. One way or the other we'll find it! Either * as a relative or an absolute reference. * * @param search * The name of the resource (without a leading /) to find * @return The requested resource * @throws MissingResourceException * if the resource can not be found */ public static URL getResource(String search) throws MissingResourceException { return getResource(CallContext.getCallingClass(), search); }
/** * Creates a privileged class loader that finds resources for the calling * class that may not be in the class' package. Use this only within classes * that are directly looking up their resources. * * @return the CrossWire Class Loader */ public static CWClassLoader instance() { Class<? extends Object> resourceOwner = CallContext.getCallingClass(); return instance(resourceOwner); }
/** * Get and load a properties file from the writable area or if that fails * from the classpath (where a default ought to be stored) * * @param subject * The name of the desired resource (without any extension) * @return The found and loaded properties file * @throws IOException * if the resource can not be loaded */ public static PropertyMap getProperties(String subject) throws IOException { return getProperties(CallContext.getCallingClass(), subject); }
/** * Generic resource URL fetcher * * @param search * The name of the resource (without a leading /) to find * @return The requested resource * @throws IOException * if there is a problem reading the file * @throws MissingResourceException * if the resource can not be found */ public static InputStream getResourceAsStream(String search) throws IOException, MissingResourceException { return getResourceAsStream(CallContext.getCallingClass(), search); }