|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.activemath.config.Manager
public class Manager
A class to read configuration information from the configuration files and optionally offer the anchoring to factory methods that provide the implementation for standard interfaces of the abstractcontent package.
This class is filled with static calls and is meant to be called anywhere where the context is needed. In principle, loading this class should only initialize the load of the properties, any other service will be loaded on demand. As such, loading this class should only load standard classes and classes of the abstractcontent package.
In the current implementation, this reads the properties first from the classpath, the file
Manager.propertiesaside of this compiled class, then, if
activemath.homesystem property is set, from the file
conf/ActiveMath.properties, then from the file
conf/ActiveMath-managed.properties, then from the file
conf/ActiveMath-individual.propertiesand finally from system preferences for one-time shell-based modification.
Information from this class is then used in almost every part of the ActiveMath servlet world and serves as a programmatic common-ground to access configuration.
| Field Summary | |
|---|---|
protected static Matriculations |
matriculations
The loaded matriculations table. |
protected static Hashtable |
servlets
The table of registred servlets |
| Constructor Summary | |
|---|---|
Manager()
|
|
| Method Summary | |
|---|---|
static void |
clearChangedPropNames()
|
static String |
convertSlashesToSysDependent(String slashedPath)
Converts the given path, separated with slashes to the system-dependent path. |
static Object |
createConfiguredObject(String prefix)
Constructs an object of class given by the value of the property of key prefixName+".class" expecting a constructor with one Map which is guaranteed to have keys and values as string, the
result of getPropertySubtree(java.lang.String) on the given prefix. |
static Object |
createConfiguredObject(Subconfiguration config)
|
static void |
createMathWebBrokerWrapper()
Creates and stores a reference to the MathWebBrokerWrapper object
as defined by the properties. |
static void |
createMatriculations()
Ininitalizes the Matriculations
table from the class of name given by the property matriculations.class
. |
static void |
createMBaseRef()
Creates and stores the reference to an MBaseRef implementing object
as defined by the properties. |
static void |
dumpProperties()
Dumps the properties, ordered, to the Standard console |
static void |
dumpProperties(String prefix)
Dumps the properties with given prefix, ordered, to the standard-console. |
static void |
dumpProperties(Writer wout,
String prefix)
Dumps the properties, ordered, to the indicated print-stream. |
static void |
ensureProperties()
Makes sure the props member-variable is not null otherwise invokes the init() method. |
static File |
getActiveMathHome()
Gets the activemath-home property, inits the manager if needed. |
static String |
getAdvertizedLocalhostName()
Computes the name of the localhost or takes it from the advertizedLocalhost property. |
static URL |
getAdvertizedURL()
User getAdvertizedLocalhostName() to compute
the root URL of the webapp, supposed to be at host:8080/ActiveMath2/. |
static Collection |
getChangedPropNames()
|
static OJSAXBuilder |
getDefaultJdomSaxBuilder()
Returns a default SAXBuilder usable by anyone so
that no uselss construction is made. |
static MathWebBrokerWrapper |
getMathWebBroker()
Returns the initialized MathWebBrokerWrapper, initializes it if
needed. |
static Matriculations |
getMatriculations()
Gets the matriculations attribute of the Manager class |
static MBaseRef |
getOfficialMBase()
Returns the MBaseRef implementing class defined by the properties
or null if none was defined. |
static Collection |
getPackagesWithPrefix(String prefix)
Returns the list of all second package name for a given prefix. |
static File |
getPath(String key)
Reads a path given as a property. |
static String |
getProperty(String key)
This uses the properties loaded from the Manager.properties file and many others (see loadProps() to respond a property in exchange of a
string. |
static String |
getProperty(String key,
String dflt)
Return a property with getProperty(java.lang.String) or the supplied default value if not set. |
static Enumeration |
getPropertyNames()
Missing description of the gets the propertyNames attribute of the Manager class |
static Enumeration |
getPropertyNamesStartingWith(String prefix)
Returns enumeration of the properties that start with the given prefix. |
static Properties |
getPropertySubtree(String prefix)
Gets the propertySubtree attribute of the Manager class |
static String |
getRealPath(String path)
Obtains the file-path given the servlet-path |
static String |
getRealPath(String path,
String defaultAnswer)
Obtains the file-path given the servlet-path |
static InputStream |
getResourceInputStream(String directoryName,
String resourceName)
This scans the directories properties and provides an InputStream for the given resource. |
static Reader |
getResourceReader(String directoryName,
String resourceName,
String encodingName)
The equivalent of the getResourceInputStream but using the standard encoding (if encodingName is null) or the given one. |
static Object |
getService(String serviceInterfaceClassName)
Returns one of the predefined services or one configured as in SubconfImpl.PropertiesConfig. |
protected static Hashtable |
getServlets()
Obtain the servlets table. |
static Stylesheets |
getStylesheetProcessor()
returns the reference to a stylesheet processor |
static File |
getTempDir()
Returns the temporary "work" directory. |
static URL |
getURL(String key)
Reads one URI from the property files. |
static File |
getWebAppDir()
Missing description of the gets the webAppDir attribute of the Manager class |
static void |
init()
This inits the configurations reading properties from the three properties files (Manager.properties in the jar, ActiveMath.properties in conf, and ActiveMath-individual.properties in conf. |
static void |
initLog4J()
This erases the previously set log4j configurations and then reads the file conf/log4j.properties to feed it to the org.log4j.PropertyConfigurator. |
static boolean |
isInitted()
Checks wether the init() method has already run. |
static String[] |
listResources(String directoryName)
This lists the resources in the directory. |
static void |
loadProps()
|
static void |
main(String[] args)
This method is for testing the configuration, it can be be given the argument of the initialization to perform and will try to perform it, providing an output targetted to detect the possible misconfigurations. |
static Hashtable |
pathMap()
Creates the pathMap used by the FileServlet
which serves raw files, picked according to the recognized languages. |
static void |
registerServlet(String sn)
Registers the servlet in the list of initted servlet. |
static Collection |
reloadProps()
|
static void |
reportFatalError(Throwable t,
String message)
|
static void |
setActiveMathHome(File indicatedHome)
Defines the variable activemathHome, used in many other places. |
static void |
unregisterServlet(String sn)
Removeds the servlet from the initted servlet. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static Hashtable servlets
protected static Matriculations matriculations
| Constructor Detail |
|---|
public Manager()
| Method Detail |
|---|
public static void setActiveMathHome(File indicatedHome)
activemath.home can be defined.
indicatedHome - the path (supposed absolute) to the
directory ActiveMath-Home
IllegalStateException - if the variable ActiveMath-Home is already
defined.public static boolean isInitted()
init() method has already run.
public static File getActiveMathHome()
public static String getProperty(String key)
loadProps() to respond a property in exchange of a
string.
key - Missing description of Parameter
public static String getProperty(String key,
String dflt)
getProperty(java.lang.String) or the supplied default value if not set.
key - property keydflt - default value if not set
public static Enumeration getPropertyNames()
public static Enumeration getPropertyNamesStartingWith(String prefix)
Vector, so is inappropriate for very large
properties file. To get the value of the property resulting of this
enumeration, just use getProperty(java.lang.String)
prefix - the prefix for the properties
public static Collection getPackagesWithPrefix(String prefix)
This is used to enumerate all the groupings keys as well as the recbooks keys.
prefix - the prefix wished
public static Properties getPropertySubtree(String prefix)
prefix - the prefix
public static String getRealPath(String path)
path - the servlet-path
public static String getRealPath(String path,
String defaultAnswer)
path - the servlet-pathdefaultAnswer - the default path expected
public static MBaseRef getOfficialMBase()
MBaseRef implementing class defined by the properties
or null if none was defined. Attempts to create it if necessary. The object
is then null or the previous value if the initialization
failed.
public static MathWebBrokerWrapper getMathWebBroker()
MathWebBrokerWrapper, initializes it if
needed.
public static OJSAXBuilder getDefaultJdomSaxBuilder()
SAXBuilder usable by anyone so
that no uselss construction is made.
public static Stylesheets getStylesheetProcessor()
public static File getTempDir()
getPath(java.lang.String).
The existence (and writability) of this directory is ensured the first time
this method is run.
BadConfigurationError - if it is not possible to create a file in
the given directorypublic static File getWebAppDir()
public static URL getURL(String key)
throws MalformedURLException
key - The property key
MalformedURLException - Missing description of Exceptionpublic static File getPath(String key)
getProperty(String)
is that the property is checked for a given leading slash, in which case it
is appended the activemathHome variable's content, unless a property key +
".refType" is defined to be "absolute" or "inTemp" (the default being
"inActiveMathHome"). If the refType is "absolute" the path is considered absolute, it is up to the configuration author to make sure that such a path can be read from or written to.
If the refType is "inTemp", the property "directories.tempDir" is used, presumably absolute but refTypes also apply, a path is made of it, then this property's path is appended to this one.
No security check is done, yet, about the possible ".." araising here.
key - the property key
public static InputStream getResourceInputStream(String directoryName,
String resourceName)
throws IOException,
MalformedURLException,
ClassNotFoundException
file:/ no relative things here yet.
http:// prefix to which a resource-name will be
appended to get the URL of the stream to open.class:/ prefixed path meaning a resource that should
be looked for in the classpath.
directoryName - the directory nameresourceName - the resource-name
IOException - if the inputStream cannot be opened
or if the directory-name cannot be found from the properties.
MalformedURLException - if the URL was poor
ClassNotFoundException - when a class resource-identifier
was used but is not found.
public static Reader getResourceReader(String directoryName,
String resourceName,
String encodingName)
throws IOException,
MalformedURLException,
ClassNotFoundException
encodingName is null) or the given one. There is
currently no-support for in-stream or http-based encoding detection.
directoryName - the directory nameresourceName - the resource-nameencodingName - the encoding to use
IOException - if the inputStream cannot be opened
or if the directory-name cannot be found from the properties.
MalformedURLException - if the URL was poor
ClassNotFoundException - when a class resource-identifier
was used but is not found.public static Matriculations getMatriculations()
public static Object getService(String serviceInterfaceClassName)
SubconfImpl.PropertiesConfig.
public static String convertSlashesToSysDependent(String slashedPath)
slashedPath - Missing description of Parameter
public static String[] listResources(String directoryName)
directories.list.directoryName out of which a
white-space separated list is expected.
directoryName - the directory key-postfix
public static void main(String[] args)
It accepts the following arguments, the test(s) to invoke:
args - The command line argumentspublic static void init()
If a system property "activemath.home" exists, it is used as an absolute path to the named directory. Otherwise it is expected that some other calls (for example, a servlet's init call) set this variable which can only be done once in the life of the class.
public static void initLog4J()
conf/log4j.propertiesto feed it to the
org.log4j.PropertyConfigurator. Note that this step is useless if the
confdirectory is already in the classpath which is highly recommended as otherwise some logging will appear before this method is called and the log4j package will complain that it was not configured, setting every priority to
Priority.DEBUG, the
most, much too much, verbose one.
public static void dumpProperties()
public static void dumpProperties(String prefix)
prefix - the prefix wished.
public static void dumpProperties(Writer wout,
String prefix)
wout - the wished streamprefix - the possible prefix (set to empty-string if not desired)public static void ensureProperties()
public static String getAdvertizedLocalhostName()
public static URL getAdvertizedURL()
getAdvertizedLocalhostName() to compute
the root URL of the webapp, supposed to be at host:8080/ActiveMath2/.
Override with property advertizedURL.
public static Object createConfiguredObject(Subconfiguration config)
throws Exception
Exception
public static Object createConfiguredObject(String prefix)
throws Exception
prefixName+".class" expecting a constructor with one Map which is guaranteed to have keys and values as string, the
result of getPropertySubtree(java.lang.String) on the given prefix. This method is expected to be the standard way to construct objects that are of services. The argument-type of the constructor is expected to be of type Map instead of Properties so as to be able, later, to build prefix-wrappers that avoid storing the properties in memory again.
This method will be enriched with a support for shut-down able objects later.
prefix - the prefix to obtain a property subtree of
Exception - any exception in particular the ones returned by
Class.forName(java.lang.String) and Constructor.newInstance(java.lang.Object...)public static Hashtable pathMap()
FileServlet
which serves raw files, picked according to the recognized languages.
public static void createMBaseRef()
MBaseRef implementing object
as defined by the properties. Call getOfficialMBase() to get the
actual object created here.
Calling this method after initialization of the Manager has occured will
redirect all NEW calls to getOfficialMBase() to give the redirected
one. The values to adjust for this purpose are in the system properties
with the same names as the ActiveMath properties.
public static void createMathWebBrokerWrapper()
MathWebBrokerWrapper object
as defined by the properties. Call getMathWebBroker() to get the
actual object. If this initialization fails, typically if the server does
not respond, future attempts of calling getMathWebBroker will return null
or the previous value.
public static void registerServlet(String sn)
sn - the name of the servletpublic static void unregisterServlet(String sn)
sn - the name of the servlet
public static void createMatriculations()
throws Exception
Matriculations
table from the class of name given by the property matriculations.class
.
Exception - Description of Exceptionprotected static Hashtable getServlets()
public static void reportFatalError(Throwable t,
String message)
public static Collection getChangedPropNames()
public static void clearChangedPropNames()
public static Collection reloadProps()
public static void loadProps()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||