|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.flexdock.util.ResourceManager
public class ResourceManager
This class provides static convenience methods for resource
management, including resource lookups and image, icon, and cursor creation.
| Field Summary | |
|---|---|
static String |
LIBRARY_EXTENSION
Defines the file extension used by native shared libraries on the current system. |
| Method Summary | |
|---|---|
static void |
close(InputStream in)
Calls close() on the specified InputStream. |
static void |
close(OutputStream out)
Calls close() on the specified OutputStream. |
static void |
close(Socket socket)
Calls close() on the specified Socket. |
static Cursor |
createCursor(String url,
Point hotPoint,
String name)
Returns a Cursor object based on the specified resource URL. |
static Cursor |
createCursor(URL imageURL,
Point hotPoint,
String name)
Returns a Cursor object based on the specified resource URL. |
static ImageIcon |
createIcon(String url)
Returns an ImageIcon object based on the specified resource URL. |
static Image |
createImage(String url)
Returns an Image object based on the specified resource URL. |
static Image |
createImage(URL imageLocation)
Returns an Image object based on the specified resource URL. |
static Document |
getDocument(String uri)
Returns a Document object based on the specified resource
uri. |
static Document |
getDocument(URL url)
Returns a Document object based on the specified resource
URL. |
static Properties |
getProperties(String uri)
Returns a Properties object based on the specified resource
uri. |
static Properties |
getProperties(String uri,
boolean failSilent)
Returns a Properties object based on the specified resource
uri. |
static Properties |
getProperties(URL url)
Returns a Properties object based on the specified resource
URL. |
static Properties |
getProperties(URL url,
boolean failSilent)
Returns a Properties object based on the specified resource
url. |
static URL |
getResource(String uri)
Performs resource lookups using the ClassLoader and classpath. |
static boolean |
isWindowsPlatform()
Returns true if the JVM is currently running on Windows;
false otherwise. |
static void |
loadLibrary(String library,
String classpathResource)
Attempts to load the specified native library, using
classpathResource and the filesystem to implement several
fallback mechanisms in the event the library cannot be loaded. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String LIBRARY_EXTENSION
| Method Detail |
|---|
public static boolean isWindowsPlatform()
true if the JVM is currently running on Windows;
false otherwise.
true if the JVM is currently running on Windows;
false otherwise.public static URL getResource(String uri)
ClassLoader and classpath.
This method attemps to consolidate several techniques used for resource
lookup in different situations, providing a common API that works the
same from standalone applications to applets to multiple-classloader
container-managed applications. Returns null if specified
resource cannot be found.
uri - the String describing the resource to be looked up
URL representing the resource that has been looked up.public static Image createImage(String url)
Image object based on the specified resource URL. Does
not perform any caching on the Image object, so a new object will
be created with each call to this method.
url - the String describing the resource to be looked up
Image created from the specified resource URL
NullPointerException - if specified resource cannot be found.public static Image createImage(URL imageLocation)
Image object based on the specified resource URL. Does
not perform any caching on the Image object, so a new object will
be created with each call to this method.
imageLocation - the URL indicating where the image resource may be
found.
Image created from the specified resource URL
NullPointerException - if specified resource cannot be found.public static ImageIcon createIcon(String url)
ImageIcon object based on the specified resource URL.
Uses the ImageIcon constructor internally instead of dispatching
to createImage(String url), so Image objects are cached
via the MediaTracker.
url - the String describing the resource to be looked up
ImageIcon created from the specified resource URL
NullPointerException - if specified resource cannot be found.
public static Cursor createCursor(URL imageURL,
Point hotPoint,
String name)
Cursor object based on the specified resource URL.
Throws a NullPointerException if specified resource cannot be
found. Dispatches to createImage(URL imageLocation), so
Image objects are not cached via theMediaTracker.
imageURL - the URL indicating where the image resource may be
found.hotPoint - the X and Y of the large cursor's hot spot. The hotSpot values
must be less than the Dimension returned by
getBestCursorSize().name - a localized description of the cursor, for Java Accessibility
use.
Cursor created from the specified resource URL
NullPointerException - if specified resource cannot be found.
IndexOutOfBoundsException - if the hotSpot values are outside
public static Cursor createCursor(String url,
Point hotPoint,
String name)
Cursor object based on the specified resource URL.
Throws a NullPointerException if specified resource cannot be
found. Dispatches to createImage(String url), so Image
objects are not cached via theMediaTracker.
url - the String describing the resource to be looked uphotPoint - the X and Y of the large cursor's hot spot. The hotSpot values
must be less than the Dimension returned by
getBestCursorSize().name - a localized description of the cursor, for Java Accessibility
use.
Cursor created from the specified resource URL
NullPointerException - if specified resource cannot be found.
IndexOutOfBoundsException - if the hotSpot values are outside
public static void loadLibrary(String library,
String classpathResource)
library, using
classpathResource and the filesystem to implement several
fallback mechanisms in the event the library cannot be loaded. This
method should provide seamless installation and loading of native
libraries from within the classpath so that native libraries may be
packaged within the relavant library JAR, rather than requiring separate
user installation of the native libraries into the system $PATH.
If the specified library is null, then this method
returns with no action taken.
This method will first attempt to call
System.loadLibrary(library). If this call is successful, then
the method will exit here. If an UnsatisfiedLinkError is
encountered, then this method attempts to locate a FlexDock-specific
filesystem resource for the native library, called the "FlexDock
Library".
The FlexDock Library will reside on the filesystem under the user's home
directory with the path ${user.home}/flexdock/${library}${native.lib.extension}.
Thus, if this method is called with an argument of "foo" for the
library, then under windows the FlexDock Library should be
C:\Documents and Settings\${user.home}\flexdock\foo.dll. Under
any type of Unix system, the FlexDock library should be
/home/${user.home}/flexdock/foo.so.
If the FlexDock Library exists on the filesystem, then this method will
attempt to load it by calling System.load(String filename) with
the FlexDock Library's absolute path. If this call is successful, then
the method exits here.
If the FlexDock Library cannot be loaded, then the specified
classpathResource is checked. If classpathResource is
null, then there is no more information available to attempt to
resolve the requested library and this method throws the last
UnsatisfiedLinkError encountered.
If classpathResource is non-null, then an
InputStream to the specified resource is resolved from the class
loader. The contents of the InputStream are read into a
byte array and written to disk as the FlexDock Library file. The
FlexDock Library is then loaded with a call to
System.load(String filename) with the FlexDock Library's absolute
path. If the specified classpathResource cannot be resolved by
the class loader, if any errors occur during this process of extracting
and writing to disk, or if the resulting FlexDock Library file cannot be
loaded as a native library, then this method throws an appropriate
UnsatisfiedLinkError specific to the situation that prevented the
native library from loading.
Note that because this method may extract resources from the classpath and install to the filesystem as a FlexDock Library, subsequent calls to this method across JVM sessions will find the FlexDock Library on the filesystem and bypass the extraction process.
library - the native library to loadclasspathResource - the fallback location within the classpath from which to
extract the desired native library in the event it is not
already installed on the target system
UnsatisfiedLinkError - if the library cannot be loadedpublic static Document getDocument(String uri)
Document object based on the specified resource
uri. This method resolves a URL from the specified
String via getResource(String uri) and dispatches to
getDocument(URL url). If the specified uri is
null, then this method returns null.
uri - the String describing the resource to be looked up
Document object based on the specified resource
urigetResource(String),
getDocument(URL)public static Document getDocument(URL url)
Document object based on the specified resource
URL. This method will open an InputStream to the
specified URL and construct a Document instance. If any
Exceptions are encountered in the process, this method returns
null. If the specified URL is null, then this
method returns null.
url - the URL describing the resource to be looked up
Document object based on the specified resource
URLpublic static Properties getProperties(String uri)
Properties object based on the specified resource
uri. This method resolves a URL from the specified
String via getResource(String uri) and dispatches to
getProperties(URL url, boolean failSilent) with an argument of
false for failSilent. If the specified uri is
null, then this method will print a stack trace for the ensuing
NullPointerException and return null.
uri - the String describing the resource to be looked up
Properties object based on the specified resource
uri.getResource(String),
getProperties(URL, boolean)
public static Properties getProperties(String uri,
boolean failSilent)
Properties object based on the specified resource
uri. This method resolves a URL from the specified
String via getResource(String uri) and dispatches to
getProperties(URL url, boolean failSilent), passing the
specified failSilent parameter. If the specified uri is
null, this method will return null. If
failSilent is false, then the ensuing
NullPointerException's stacktrace will be printed to the
System.err before returning.
uri - the String describing the resource to be looked upfailSilent - true if no errors are to be reported to the
System.err before returning; false otherwise.
Properties object based on the specified resource
uri.getResource(String),
getProperties(URL, boolean)public static Properties getProperties(URL url)
Properties object based on the specified resource
URL. This method dispatches to
getProperties(URL url, boolean failSilent), with an argument of
false for failSilent. If the specified uri is
null, this method will print the ensuing
NullPointerException stack tracke to the System.err and
return null.
url - the URL describing the resource to be looked up
Properties object based on the specified resource
url.getProperties(URL, boolean)
public static Properties getProperties(URL url,
boolean failSilent)
Properties object based on the specified resource
url. If the specified uri is null, this method
will return null. If any errors are encountered during the
properties-load process, this method will return null. If
failSilent is false, then the any encoutered error
stacktraces will be printed to the System.err before returning.
url - the URL describing the resource to be looked upfailSilent - true if no errors are to be reported to the
System.err before returning; false otherwise.
Properties object based on the specified resource
url.public static void close(InputStream in)
close() on the specified InputStream. Any
Exceptions encountered will be printed to the System.err.
If in is null, then no Exception is thrown and
no action is taken.
in - the InputStream to closeInputStream.close()public static void close(OutputStream out)
close() on the specified OutputStream. Any
Exceptions encountered will be printed to the System.err.
If out is null, then no Exception is thrown and
no action is taken.
out - the OutputStream to closeOutputStream.close()public static void close(Socket socket)
close() on the specified Socket. Any
Exceptions encountered will be printed to the System.err.
If socket is null, then no Exception is thrown
and no action is taken.
socket - the Socket to closeSocket.close()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||