public class Loader extends Object
Modifier and Type | Field and Description |
---|---|
static String |
PROPERTIES_FILE
Name of the file in the user's home directory from which properties
are loaded.
|
Constructor and Description |
---|
Loader() |
Modifier and Type | Method and Description |
---|---|
static void |
checkJ2se()
Checks that the JRE contains classes that you'd expect it to.
|
static void |
checkJ2seVendor()
Checks the reported vendor for this J2SE.
|
static <T> T |
getClassInstance(String classSpec,
Class<T> type)
Attempts to obtain an instance of a class with a given name which
is an instance of a given type.
|
static <T> List<T> |
getClassInstances(String[] defaultNames,
String propertyName,
Class<T> type)
Returns a list of class instances got from a combination of a
default list of classnames and the name of a property which
may contain a colon-separated list of other classnames.
|
static <T> List<T> |
getClassInstances(String propertyName,
Class<T> type)
Attempts to obtain instances of a class from a colon-separated list
of classnames in a named system property.
|
static File |
getPropertiesFile()
Returns the name of the file from which properties will be loaded
by this class.
|
static boolean |
is64Bit()
Tests whether the JVM appears to be 64-bit or not.
|
static void |
loadLibrary(String libname)
Loads a native library given its name.
|
static void |
loadProperties()
Ensures that the user's customised properties have been loaded;
these are read once from the file returned by the
getPropertiesFile() method and incorporated into
the System properties. |
static void |
setDefaultProperty(String key,
String value)
Sets a system property to a given value unless it has already been set.
|
static void |
setHttpAgent(String productTokens)
Configures the "http.agent" system property.
|
static File |
starjavaDirectory()
Returns the location of the main Starlink java directory which
contains the lib, bin, etc, source directories and others.
|
static void |
tweakGuiForMac()
Unless it's been set already, sets the value of the
apple.laf.useScreenMenuBar system property to true. |
public static final String PROPERTIES_FILE
public static File starjavaDirectory()
If for some reason the directory cannot be located, null is returned.
null
if it can't be foundpublic static void loadLibrary(String libname) throws SecurityException, UnsatisfiedLinkError
libname
- the name of the library (not including system-specifics
such as 'lib' or '.so')SecurityException
- if a security manager exists and its
checkLink
method doesn't allow loading of the
specified dynamic libraryUnsatisfiedLinkError
- if the library does not existSystem.loadLibrary(java.lang.String)
public static File getPropertiesFile() throws SecurityException
PROPERTIES_FILE
in the directory
given by the System property "user.home
".SecurityException
public static void loadProperties()
getPropertiesFile()
method and incorporated into
the System properties.
Calling this method after the first time has no effect.System.getProperties()
public static <T> T getClassInstance(String classSpec, Class<T> type)
className
is null or
empty, null is returned directly. Otherwise, if the class
className
can be found using the default class loader, and if it is assignable
from type
, and if it has a no-arg constructor, an instance
of it is constructed and returned. Otherwise, null
is
returned, and a message may be written through the logging system.
A bean configuration parenthesis may be optionally appended,
as per BeanConfig
.
classSpec
- name of the class to instantiatetype
- class which the instantiated class must be assignable
fromclassName
instance, or null
public static <T> List<T> getClassInstances(String propertyName, Class<T> type)
getClassInstance(java.lang.String, java.lang.Class<T>)
is called on each colon-separated
element of the property value, and if there is a non-null return,
it is added to the return list. For colon-separated elements which
do not correspond to usable classes, a message may be written
through the logging system.propertyName
- name of a system property containing
colon-separated classnamestype
- class which instantiated classes must be assignable fromtype
instances
(may be empty, but not null)public static <T> List<T> getClassInstances(String[] defaultNames, String propertyName, Class<T> type)
type
and which have no-arg constructors.defaultNames
- array of stringpublic static boolean is64Bit()
public static void setDefaultProperty(String key, String value)
key
- property namevalue
- suggested property valuepublic static void tweakGuiForMac()
apple.laf.useScreenMenuBar
system property to true.
This has the effect on Macintosh displays of causing menus to
appear at the top of the screen rather than the top of the
windows they belong in. This doesn't work on Dialog windows.
Setting this property has no effect on non-Mac platforms.
Probably(?) this call must be made before starting up the GUI
(haven't got a Mac to hand, can't test it).public static void setHttpAgent(String productTokens)
According to RFC2616 sections 14.43 and 3.8, this string should
be a whitespace-separated sequence of product tokens.
A product token is of the form product-name/product-version
.
This method must be called before the current JVM has opened any HTTP connections to have an effect.
productTokens
- one or more (whitespace-separated) name/version
application identifierspublic static void checkJ2se() throws ClassNotFoundException
ClassNotFoundException
- in case of a defective JREpublic static void checkJ2seVendor()
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.