|
Cramfull Compiled Resources v2.00 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--java.util.ResourceBundle
|
+--be.arci.cramfull.Cramfull
The abstract class Cramfull is a framework for it's subclasses to encapsulate resources in their .class-file itself. These subclasses are not coded by the application programmer, but generated and compiled by a ClassCompiler.
Being also a subclass of ResourceBundle, a generated Cramfull subclass MyCramfull can either be instantiated individualy and directly by invoking the no-args constructor as new MyCramfull() or as Class.forName("MyCramfull").newInstance(), or either be organized into a Locale hierarchy by a invoking ResourceBundle.getBundle("MyCramfull", someLocale). When loading a locale hierarchy through ResourceBundle.getBundle(), Cramfull subclasses should not be mixed with other ResourceBundle implementations; all extra functionality stops at the first non-Cramfull ResourceBundle. See java.util.ResourceBundle for more information about resource bundles in general.
Getter Methods
Cramfull offers a set of getter methods that should be used in
preference to ResourceBundle.getObject(String). These getter methods
retrieve resources as a byte[], as a java.io.InputStream, or
as a deserialized Object,
but also as the commonly used types java.awt.Image, java.applet.AudioClip
and java.util.Properties. Cramfull subclasses that are organized
in a locale hierarchy by ResourceBundle.getBundle("MyCramfull") can even
restore a .properties file hierarchy from the contained resources in the same
way as ResourceBundle.getBundle("MyProperties") would have done from the file
system.
Because speed and memory usage are important when managing lots of resources, the getter methods have a retention option to enable caching a resource in the retrieved type after decoding, or removing the reference to the resource from the Cramfull that contains it. Both options enable garbage collection of the encoded resource data.
Note: Cramfull is a subclass of java.util.ResourceBundle to exploit the facilities for loading locale hierarchies. However, the following methods, which we cannot override because they are final, should not be invoked. They will either throw a typecasting error or give access to encoded resource data only:
Note: With be.arci.pub.ResourceViewer we provide a utility to view the resources contained in a Cramfull subclass. With be.arci.pub.ResourceViewer you can also list the names of these resources to the console, or extract them as normal files again.
Evaluation version
ClassCompiler,
be.arci.pub.ResourceCompiler,
be.arci.pub.ResourceViewer,
getByteArray(String sResource, int iRetetention),
getInputStream(String sResource, int iRetetention),
getDeserialized(String sResource, int iRetetention),
getProperties(String sResource, int iRetetention),
getLocalizedProperties(String sResource, int iRetetention),
getImage(String sResource, int iRetetention),
getAudioClip(String sResource, int iRetetention)| Field Summary | |
static int |
RET_CACHE
Resource retention: cache the decoded resource in the retrieved format, by replacing it's encoded form in the Cramfull subclass that stored it. |
static int |
RET_CACHE_ALL
Resource retention: cache a decoded resource and it's parents in their respective containing Cramfull subclass as the java.util.Properties object each is loaded in. |
static int |
RET_CACHE_AND_REMOVE_PARENTS
Resource retention: combination of RET_CACHE and RET_REMOVE_PARENTS |
static int |
RET_ENCODED
Resource retention: keep encoded resource data (does nothing with the resource store, in fact). |
static int |
RET_REMOVE
Resource retention: remove the reference to the resource from the Cramfull subclass that stores it. |
static int |
RET_REMOVE_ALL
Resource retention: remove the reference to the resource from the Cramfull subclass that stores it and all it's eventual parent Cramfull-s. |
static int |
RET_REMOVE_PARENTS
Resource retention: remove eventual references to the resource from all parent Cramfull-s of the Cramfull subclass that stores the resource. |
static java.lang.String |
sCopy
Copyright notice; none of the Cramfull Compiled Resources license types allows you to change this. |
| Fields inherited from class java.util.ResourceBundle |
parent |
| Constructor Summary | |
protected |
Cramfull(java.util.Hashtable htResources)
Initializes a Cramfull subclass with a set of key-value pairs. |
| Method Summary | |
java.applet.AudioClip |
getAudioClip(java.lang.String sResource)
Returns an AudioClip object created from the named resource's data. |
java.applet.AudioClip |
getAudioClip(java.lang.String sResource,
int iRetention)
Returns an AudioClip object loaded from the named resource's data. |
byte[] |
getByteArray(java.lang.String sResource)
Returns the named resource as a byte[] containing the resource's decoded data as read from the original resource file. |
byte[] |
getByteArray(java.lang.String sResource,
int iRetention)
Returns the named resource as a byte[] containing the resource's decoded data as read from the original resource file. |
java.lang.Object |
getDeserialized(java.lang.String sResource)
Returns the named resource as an Object deserialized from the encoded resource. |
java.lang.Object |
getDeserialized(java.lang.String sResource,
int iRetention)
Returns the named resource as an Object deserialized from the encoded resource. |
java.awt.Image |
getImage(java.lang.String sResource)
Returns an Image object created from the named resource's data. |
java.awt.Image |
getImage(java.lang.String sResource,
int iRetention)
Returns a Image object created from the named resource's data. |
java.io.InputStream |
getInputStream(java.lang.String sResource)
Returns the named resource as an InputStream from which the resource's decoded data can be read, just as if an InputStream had been opened on the original resource file. |
java.io.InputStream |
getInputStream(java.lang.String sResource,
int iRetention)
Returns the named resource as an InputStream from which the resource's decoded data can be read, just as if an InputStream had been opened on the original resource file. |
java.util.Enumeration |
getKeys()
Implementation of ResourceBundle.getKeys(). |
java.lang.String |
getLocaleSuffix()
Tries to get the locale of a Cramfull subclass by calling the Java2-added method ResourceBundle.getLocale(). |
java.lang.String |
getLocaleSuffix(java.lang.String sResource)
Returns the locale suffix of the first Cramfull subclass in the locale hierarchy obtained by java.util.ResourceBundle.getBundle() that contains the named resource. |
java.util.Properties |
getLocalizedProperties(java.lang.String sBaseName)
Returns a Properties object for the given basename, with a locale hierarchy that reflects that of this Cramfull object and it's parents, in as far as this Cramfull object was instantiated by ResourceBundle.getBundle(). |
java.util.Properties |
getLocalizedProperties(java.lang.String sBaseName,
int iRetention)
Returns a Properties object for the given basename, with a locale hierarchy that reflects that of this Cramfull object and it's parents, in as far as this Cramfull object was instantiated by ResourceBundle.getBundle(). |
java.util.Properties |
getProperties(java.lang.String sResource)
Returns a java.util.Properties object loaded from the named resource's data. |
java.util.Properties |
getProperties(java.lang.String sResource,
int iRetention)
Returns a java.util.Properties object loaded from the named resource's data. |
java.lang.String |
guessMIMEType(java.lang.String sResource)
Tries to determine the content type of a resource, based on it's decoded data. |
static java.lang.String |
guessMIMETypeFromName(java.lang.String sResource)
Tries to determine the content type of a resource, based on it's name. |
protected java.lang.Object |
handleGetObject(java.lang.String sResource)
Retrieves the named resource from this Cramfull's set of compiled resources, in it's encoded or cached form. |
void |
remove(java.lang.String sResource,
boolean swRecursive)
Remove the reference to the named resource from this Cramfull subclass or the first parent in the locale hierarchy that contains the resource. |
static void |
setAudioClipCandidates(java.lang.String[] asAudioClipClass)
Sets the possible java.applet.AudioClip implementations to search for. |
| Methods inherited from class java.util.ResourceBundle |
getBundle,
getBundle,
getBundle,
getLocale,
getObject,
getString,
getStringArray,
setParent |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public static final int RET_ENCODED
public static final int RET_CACHE
public static final int RET_REMOVE
public static final int RET_REMOVE_PARENTS
public static final int RET_CACHE_AND_REMOVE_PARENTS
RET_CACHE,
RET_REMOVE_PARENTSpublic static final int RET_REMOVE_ALL
RET_REMOVE,
RET_REMOVE_PARENTSpublic static final int RET_CACHE_ALL
Note: This retention option applies to getLocalizedProperties only.
getLocalizedProperties(String sResource, int iRetention)public static final java.lang.String sCopy
| Constructor Detail |
protected Cramfull(java.util.Hashtable htResources)
| Method Detail |
public static java.lang.String guessMIMETypeFromName(java.lang.String sResource)
REMARK: We guess that normally the application programmer will know what the type of his resources is; this method's purpose is mainly for use by utility classes like be.arci.pub.ResourceViewer.
Note:This implementation builds on java.net.URLConntection.guessContentTypeFromName(); in some earlier JVM's this method always returns "unknown/unknown". For a list of available content types, look for files like "content-types.properties" in Sun's standard JDK distribution.
sResource - the (file) name of a resource
guessMIMEType(String sResource)public static void setAudioClipCandidates(java.lang.String[] asAudioClipClass)
Rationale: Standard Java classes can only load audioclip resources from an URL (in JDK1.1 applications, there is even no standard Java class that can load audioclip resources). In browser JVM-s we cannot define new URL protocols for opening an URL on a resource in a Cramfull subclass. Hence we have to trie diferent java.applet.AudioClip implementations to load audio resources. The current java.applet.AudioClip implementations are (in the order they are tried)
asAudioClipClass - qualified Java class names of java.applet.AudioClip
implementations to search for.
getAudioClip(String sResource)public java.lang.String getLocaleSuffix()
Example:
MyCramfull_nl_BE would give the locale suffix "_nl_BE".
getLocaleSuffix(String sResource)public java.lang.String getLocaleSuffix(java.lang.String sResource)
sResource - the resource namegetLocaleSuffix()protected final java.lang.Object handleGetObject(java.lang.String sResource)
REMARK: This method is protected for access by java.util.ResourceBundle only. Application programmers could invoke getObject(String) instead; we recommend however to invoke the getter methods instead.
getByteArray(String sResource),
getInputStream(String sResource),
getDeserialized(String sResource),
getProperties(String sResource),
getLocalizedProperties(String sResource),
getImage(String sResource),
getAudioClip(String sResource)public java.util.Enumeration getKeys()
While enumerating, retrieving resources via the getter methods with any other retention than RET_ENCODED will disturb the enumeration, as the underlying collection is changed by caching or removing resources.
RET_ENCODED,
getByteArray(String sResource, int iRetention),
getInputStream(String sResource, int iRetention),
getDeserialized(String sResource),
getProperties(String sResource, int iRetention),
getImage(String sResource, int iRetention),
getAudioClip(String sResource, int iRetention)
public java.lang.String guessMIMEType(java.lang.String sResource)
throws java.util.MissingResourceException,
ResourceDecodingException
REMARK: We guess that normally the application programmer will know what the type of his resources is; this method's purpose is mainly for use by utility classes like be.arci.pub.ResourceViewer.
If the resource is cached as Image or AudioClip object, this method will try to delegate to guessMIMETypeFromName. If that does not return an "image/..." or "audio/..." type respectively, the type "image/unknown" or "audio/unknown" is returned, without determining the exact subtype. If the resource is cached as deserialized Object, and guessMIMETypeFromName does not return a "application/..." type, the type "application/octet-stream" is returned. If the resource is cached as Properties object, and guessMIMETypeFromName does not return a "text/..." type, the self-defined type "text/properties" is returned.
If the resource is cached as InputStream, that InputStream will be reset during this call and in the next call to getInputStream().
sResource - the name of a resource.guessMIMETypeFromName(String sResource)
public byte[] getByteArray(java.lang.String sResource)
throws java.util.MissingResourceException,
ResourceDecodingException
sResource - the resource namegetByteArray(String sResource, int iRetention)
public byte[] getByteArray(java.lang.String sResource,
int iRetention)
throws java.util.MissingResourceException,
ResourceDecodingException
sResource - the resource nameiRetention - the retention option; allows optimization of memory usage and
retrieval time for repeated retrievalgetByteArray(String sResource),
RET_CACHE,
RET_REMOVE etcetera
public java.io.InputStream getInputStream(java.lang.String sResource)
throws java.util.MissingResourceException,
ResourceDecodingException
sResource - the resource namegetInputStream(String sResource, int iRetention)
public java.io.InputStream getInputStream(java.lang.String sResource,
int iRetention)
throws java.util.MissingResourceException,
ResourceDecodingException
sResource - the resource nameiRetention - the retention option; allows optimization of memory usage and
retrieval time for repeated retrievalgetInputStream(String sResource),
RET_CACHE,
RET_REMOVE etcetera
public java.lang.Object getDeserialized(java.lang.String sResource)
throws java.util.MissingResourceException,
ResourceDecodingException
This method will also handle objects that where serialized individually to a file and compiled into this Cramfull subclass by ClassCompiler's addResource(CompilerEntry) method from that file. Such serialized file should:
sResource - the resource namegetDeserialized(String sResource, int iRetention),
ClassCompiler.addSerialized()
public java.lang.Object getDeserialized(java.lang.String sResource,
int iRetention)
throws java.util.MissingResourceException,
ResourceDecodingException
This method will also handle objects that where serialized individually to a file and compiled into this Cramfull subclass by ClassCompiler's addResource(CompilerEntry) method from that file. Such serialized file should:
sResource - the resource nameiRetention - the retention option; allows optimization of memory usage and
retrieval time for repeated retrievalgetDeserialized(String sResource),
ClassCompiler.addSerialized(),
RET_CACHE,
RET_REMOVE etcetera
public java.util.Properties getProperties(java.lang.String sResource)
throws java.util.MissingResourceException,
ResourceDecodingException
Note: (from java.util.Properties documentation)
When loading properties from a resource, the ISO 8859-1 character encoding
is used (ISO 8859-1 is also known as the Latin 1 or ANSI character set). For
characters that cannot be directly represented in this encoding, Unicode
escapes should be used; however, only a single 'u' character is allowed in
an escape sequence.
JDK's native2ascii tool can be used to convert
the original .properties-files from other character encodings.
sResource - the resource name
getProperties(String sResource, int iRetention),
getLocalizedProperties(String sResource)
public java.util.Properties getProperties(java.lang.String sResource,
int iRetention)
throws java.util.MissingResourceException,
ResourceDecodingException
Note: (from java.util.Properties documentation)
When loading properties from a resource, the ISO 8859-1 character encoding
is used (ISO 8859-1 is also known as the Latin 1 or ANSI character set). For
characters that cannot be directly represented in this encoding, Unicode
escapes should be used; however, only a single 'u' character is allowed in
an escape sequence.
JDK's native2ascii tool can be used to convert
the original .properties-files from other character encodings.
sResource - the resource nameiRetention - the retention option; allows optimization of memory usage and
retrieval time for repeated retrieval
getLocalizedProperties(String sResource, int iRetention),
getProperties(String sResource),
RET_CACHE,
RET_REMOVE etcetera
public java.util.Properties getLocalizedProperties(java.lang.String sBaseName)
throws java.util.MissingResourceException,
ResourceDecodingException
For example, if ResourceBundle.getBundle("MyCramfull") loaded the following locale hierarchy of Cramfull subclasses:
then a call to getLocalizedProperties("settings/SomeSettings") will try to load java.util.Properties objects from the resources :
| from MyCramfull_fr_CH | |
| from MyCramfull_fr | |
| from MyCramfull_en_US | |
| from MyCramfull_en | |
| from MyCramfull |
and set the defaults of each loaded java.util.Properties object to it's nearest found parent.
Note: (from java.util.Properties documentation)
When loading properties from a resource, the ISO 8859-1 character encoding
is used (ISO 8859-1 is also known as the Latin 1 or ANSI character set). For
characters that cannot be directly represented in this encoding, Unicode
escapes should be used; however, only a single 'u' character is allowed in
an escape sequence.
JDK's native2ascii tool can be used to convert
the original .properties-files from other character encodings.
sBasename - the basename for the resource hierarchy; if this name has no
.properties suffix, that will be appended.
getLocalizedProperties(String sBaseName, int iRetention),
getProperties(String sResource),
getLocaleSuffix()
public java.util.Properties getLocalizedProperties(java.lang.String sBaseName,
int iRetention)
throws java.util.MissingResourceException,
ResourceDecodingException
For example, if ResourceBundle.getBundle("MyCramfull") loaded the following locale hierarchy of Cramfull subclasses:
then a call to getLocalizedProperties("settings/SomeSettings") will try to load java.util.Properties objects from the resources :
| from MyCramfull_fr_CH | |
| from MyCramfull_fr | |
| from MyCramfull_en_US | |
| from MyCramfull_en | |
| from MyCramfull |
and set the defaults of each loaded java.util.Properties object to it's nearest found parent.
Note: (from java.util.Properties documentation)
When loading properties from a resource, the ISO 8859-1 character encoding
is used (ISO 8859-1 is also known as the Latin 1 or ANSI character set). For
characters that cannot be directly represented in this encoding, Unicode
escapes should be used; however, only a single 'u' character is allowed in
an escape sequence.
JDK's native2ascii tool can be used to convert
the original .properties-files from other character encodings.
sBasename - the basename for the resource hierarchy; if this name has no
.properties suffix, that will be appended.iRetention - the retention option; allows optimization of memory usage and
retrieval time for repeated retrieval. This method is the only one for which the
retention code RET_CACHE_ALL is allowed: the resource and each of it's
localized parents in their containing Cramfull subclass will be loaded
in a Properties object and cached in their respective Cramfull
subclass.
getProperties(String sResource, int iRetention),
getLocalizedProperties(String sBaseName),
getLocaleSuffix(),
RET_CACHE,
RET_CACHE_ALL,
RET_REMOVE etcetera
public java.awt.Image getImage(java.lang.String sResource)
throws java.util.MissingResourceException,
ResourceDecodingException
This method creates an image from the resource data using Toolkit.getDefaultToolkit().createImage(). Toolkit.createImage() need not load the data before returning, nor check it to be valid image data. Hence the return value can be non-null, even if the named resource is not an image file.
sResource - the resource namegetImage(String sResource, int iRetention)
public java.awt.Image getImage(java.lang.String sResource,
int iRetention)
throws java.util.MissingResourceException,
ResourceDecodingException
This method creates an image from the resource data using Toolkit.getDefaultToolkit().createImage(). Toolkit.createImage() need not load the data before returning, nor check it to be valid image data. Hence the return value can be non-null, even if the named resource is not an image file.
sResource - the resource nameiRetention - the retention option; allows optimization of memory usage and
retrieval time for repeated retrievalgetImage(String sResource),
RET_CACHE,
RET_REMOVE etcetera
public java.applet.AudioClip getAudioClip(java.lang.String sResource)
throws java.util.MissingResourceException,
ResourceDecodingException
sResource - the resource namegetAudioClip(String sResource, int iRetention),
setAudioClipCandidates(String[] asAudioClipClass)
public java.applet.AudioClip getAudioClip(java.lang.String sResource,
int iRetention)
throws java.util.MissingResourceException,
ResourceDecodingException
sResource - the resource nameiRetention - the retention option; allows optimization of memory usage and
retrieval time for repeated retrievalgetAudioClip(String sResource),
setAudioClipCandidates(String[] asAudioClipClass),
RET_CACHE,
RET_REMOVE etcetera
public void remove(java.lang.String sResource,
boolean swRecursive)
Note: In current JVM's the memory saving of removing an encoded resource is not visible in the return value of Runtime.getRuntime().freeMemory(): as that method seems not to report about memory taken by all class constants. But the memory saving is not less real.
sResource - the resource to remove ofswRecursive - if true, the reference to this resource is removed from the
containing Cramfull subclass and it's parents (as loaded through
java.util.ResourceBundle.getBundle()).RET_REMOVE,
RET_REMOVE_ALL,
and RET_REMOVE_PARENTS
|
Cramfull Compiled Resources v2.00 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||