|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--java.lang.ClassLoader
|
+--net.yagga.util.ResourceMgr
A class to retrieve resource no matter where they are: on the file system, in a JAR, in the currently executing JAR or in a JAR inside the currently executing JAR. This class can extract resources as ImageIcon, String or raw InputStream, given a file name, and also classes. This class applies to these cases:
| Where the class that uses ResourceMgr resides | Where the Resource file can be |
| free (as a .class file) | in the file system |
| in a JAR the file system | |
| in a JAR (as a .class in the JAR we are invoking) | in the file system (not tested) |
| in the same JAR as a plain file | |
| in a JAR (as a .class in a JAR we are calling from the JAR we are invoking) | in the same JAR as a plain file |
| in the top level JAR |
FOO.jar
+- Main.class
+- Support classes ..
+- BUNDLE1.JAR
+- Display.class
+- ResourceMgr.class
+- IMG/
+- test.gif
If Main.classes uses classes in BUNDLE.jar (loaded with MetaJarClassLoader) and one
such class (Display.class) must load a resource form the same JAR, say IMG/test.gif
it can load it using ResourceMgr.retrieveImageIcon, thus ignoring its execution
environment.
MetaJarResources,
MetaJarClassLoader| Inner classes inherited from class java.lang.ClassLoader |
java.lang.ClassLoader.NativeLibrary |
| Field Summary | |
static boolean |
debug
toggles debugging |
private static MetaJarResources |
mjr
MetaJarResource used to read meta-jar data. |
| Fields inherited from class java.lang.ClassLoader |
bootstrapClassPath, classes, defaultDomain, defaultPermissions, domains, getClassLoaderPerm, initialized, loadedLibraryNames, nativeLibraries, nativeLibraryContext, nocerts, package2certs, packages, parent, scl, sclSet, sys_paths, systemNativeLibraries, usr_paths |
| Constructor Summary | |
ResourceMgr()
|
|
| Method Summary | |
protected java.lang.Class |
findClass(java.lang.String className)
Method that reads the class from everywhere, file system jarred inside me etc.. |
static java.io.InputStream |
openResource(java.lang.String filename)
gets the InputSream associated with a given file. |
static java.lang.Class |
retrieveClass(java.lang.String className)
|
static java.lang.String |
retrieveFile(java.lang.String fileName)
retrieve a (text) file as a String. |
static javax.swing.ImageIcon |
retrieveImageIcon(java.lang.String image)
retrieve an ImageIcon given a filename. |
static javax.swing.ImageIcon |
retrieveImageIcon2(java.lang.String image)
|
static java.lang.String |
toHexString(byte[] orig,
java.lang.String prefix,
java.lang.String newLineSep,
int limit)
Write a String in HEXadecimal format. |
| Methods inherited from class java.lang.ClassLoader |
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
| Field Detail |
public static boolean debug
private static MetaJarResources mjr
| Constructor Detail |
public ResourceMgr()
| Method Detail |
public static javax.swing.ImageIcon retrieveImageIcon(java.lang.String image)
image - the name of the image file. If the name refers to a file
or an entry in a JAR/ZIP file, please be sure to specify also the directory, if
there is one (speaking relatively...(public static javax.swing.ImageIcon retrieveImageIcon2(java.lang.String image)
public static java.lang.String retrieveFile(java.lang.String fileName)
fileName - the name of the (text) file. If the name refers to a file
or an entry in a JAR/ZIP file, please be sure to specify also the directory.public static java.io.InputStream openResource(java.lang.String filename)
fileName - the name of the file. If the name refers to a file
or an entry in a JAR/ZIP file, please be sure to specify also the directory.
public static java.lang.Class retrieveClass(java.lang.String className)
throws java.lang.ClassNotFoundException
protected java.lang.Class findClass(java.lang.String className)
throws java.lang.ClassNotFoundException
findClass in class java.lang.ClassLoaderclassName - the classname (fully qualified with "."). Teh name is then read
friom the jar file substituting "." with "/" and appending ".class"
public static java.lang.String toHexString(byte[] orig,
java.lang.String prefix,
java.lang.String newLineSep,
int limit)
'a' = 0x0060
'b' = 0x0061
Between lines the paraemter "newLineSep"is written.orig - string to decodeprefix - a prefix for every "line"newLineSep - string to use as line-separator
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||