org.ceryle.xml
Class Services

java.lang.Object
  extended by org.ceryle.xml.Services
All Implemented Interfaces:
Constants

public class Services
extends Object
implements Constants

A singleton class providing a set of core services to a Ceryle processor or class. This includes (in the order of instantiation):

org.ceryle.util.MessageHandler
message and error handling services
org.ceryle.util.log.Logger
system log (optional, from MessageHandler)
org.ceryle.util.idle.Idler
idle listener (optional, from MessageHandler)
org.ceryle.xml.XMLProcessor
XML services (document creation, validation)
org.ceryle.xml.PropertyManager
set and get properties from XML file
org.ceryle.xnode.XNodeStoreImpl
XML native database services (optional)
as well as the current settings (stored internally as an int, available via several methods).

To obtain the instance of this class:

      Services srvs = Services.getInstance();
  

Since:
JDK1.3
Version:
$Id: Services.java,v 3.34 2007-06-20 01:28:39 altheim Exp $
Author:
Murray Altheim
See Also:
Constants, MessageHandler, PropertyManager, XMLProcessor, XNodeStoreImpl

Field Summary
static String defaultCatalogPath
          The default relative pathname for the XML Catalog file.
static String FORM_TEMPLATE_ID
          A String constant containing the ID of the default form template for a given Collection.
 File homeDirectory
          The Ceryle application home directory.
 URL homeDirectoryURL
          The Ceryle application home directory as a URL.
protected  org.apache.xml.resolver.tools.CatalogResolver m_catalogResolver
          The CatalogResolver used to resolve XML entity references.
protected  Hashtable m_ext2HAPath
          The lookup table for file extension to Helper Application path.
protected  Hashtable m_mime2HAPath
          The lookup table for MIME type (as String) to Helper Application path.
static File resourceDir
          The Ceryle resource directory.
 
Fields inherited from interface org.ceryle.util.Constants
Amp, AMP, Apos, APOS, APP_NAME, APP_VERSION_NAME, APP_VERSION_NUMBER, AT, BANG, BAR, BIT_dev, BIT_http, BIT_ignoreCom, BIT_merge, BIT_none, BIT_noPreload, BIT_simple, BIT_ui, BIT_unused1, BIT_unused2, BIT_unused3, BIT_validating, BIT_verbose, BIT_xcatalog, BIT_xlink, BIT_xmlnsAware, BIT_xsd, BROKB, BSlash, BSLASH, CERYLE_CREDITS_FILE, CERYLE_DATA_DIR, CERYLE_HIST_FILE, CERYLE_LICENSE_FILE, CERYLE_PREF_FILE, CERYLE_PROP, CERYLE_PROP_BASE, CERYLE_PROP_FILE, CERYLE_RSRC_DIR, CERYLE_THANKS_FILE, CFLEX, Colon, COLON, Comma, COMMA, CR, CRet, Dash, DASH, DEFAULT_DIRECTORY, DEVELOPER, DOLR, Dot, DOT, EIGHT, Ellip, EOF, EqQuot, EQUAL, Equals, False, FALSE, FileProt, Filesep, FileURL, Five, FIVE, FONTSIZES, Four, FOUR, FSchar, GCOL_PROP, GRAPH_PROP, GRAVE, GT, Hash, HASH, HOME_DIRECTORY, HOME_DIRECTORY_PATH, HOME_DIRECTORY_URL, HTML, HttpProt, HttpURL, INDENT, INDENT_0, INDENT_1, INDENT_10, INDENT_2, INDENT_3, INDENT_4, INDENT_5, INDENT_6, INDENT_7, INDENT_8, INDENT_9, INIT, LCURL, LCurly, LF, LFS, Localhost, LPAR, LParen, LS, LSBrkt, LSBrkt2, LSQB, LT, MT, NBSP, NEL, NINE, NL, NL20x, NLchar, No, Null, NULL, NULL_STATE, NumParams, One, ONE, Pathsep, Percent, PERO, PLUS, Prcnt, PS, QMark, QMARK, Quot, QUOT, RCURL, RCurly, RESOURCE_BUNDLE, RPAR, RParen, RSBrkt, RSBrkt2, RSQB, Semi, SEMI, SEVEN, SIX, Slash, SLASH, SP, SPACE, Stago, Star, STAR, Tab, TAB, Tee, Three, THREE, Tilde, TILDE, TM_PROP, True, TRUE, Two, TWO, Under, UNDER, URI, URL, VBar, WIKI_PROP, XNodePfx, XNodeURL, XtmExt, Yes, Zero, ZERO
 
Method Summary
 void dbAction(XNodeState state)
          Uses an XNodeState as a directive to control the database.
 void disposeWelcomeWindow(MessageWriter messagewriter)
          Closes and disposes of the WelcomeWindow, if it is displayed.
static String error(String id)
          A static convenience method that passes the error off to the MessageHandler.
static String error(String id, String arg)
          A static convenience method that passes the error off to the MessageHandler.
static String error(String id, String arg1, String arg2)
          A static convenience method that passes the error off to the MessageHandler.
static String error(String id, String arg1, String arg2, String arg3)
          A static convenience method that passes the error off to the MessageHandler.
 List getAvailableFonts()
          Returns an unmodifiable List containing the available Fonts.
 String[] getBaseOntologies()
          Loads the URLs of the three base ontologies: minimal, upper, and middle.
 org.apache.xml.resolver.tools.CatalogResolver getCatalogResolver()
          This returns the single instance of a CatalogResolver, to be reused by all XMLProcessors.
 SetModel getCollectionIndex()
          Returns the list of database Collections as a SetModel, an empty SetModel (rather than null) if no database * connection is available.
 int getCollectionSize()
          Returns the count of database Collections as a int.
 File getDefaultDirectory()
          Returns the default (user) directory for file operations.
 Font getFont(int fontNumber)
          Return an existing application font based on index.
 Font getFont(String basename)
          Return a Font provided its property base name and style.
 GroovyService getGroovyService()
          Returns a GroovyService object, providing Groovy interpretation and console services.
 String getHelperFromExt(String ext)
          Returns a path to a Helper Application provided a file extension, null if none has been registered for that extension.
 String getHelperFromMIME(String mime)
          Returns a path to a Helper Application provided a MIME type, null if none has been registered for that type.
 String getHelperFromPath(String systemId)
          Returns a path to a Helper Application provided a file extension, null if none has been registered for that extension.
 IDFactory getIDFactory()
          Returns a reusable IDFactory that produces XML Name-compatible random words.
 String getImagePath()
          Returns the path to the image directory (used for building a GUI, etc.).
static Services getInstance()
          As this is a singleton class, this returns the single instance of this class using the defaults for the properties file and settings (ui,merge,xmlns-aware,validating).
static Services getInstance(MessageHandlerImpl messagehandler, String propertiesFile, int settings)
          As this is a singleton class, this returns the single instance of this class provided with the optional MessageHandlerImpl, the property file filename and bit-wise application settings.
 MessageHandler getMessageHandler()
          Returns the current MessageHandler.
 MessageHandlerImpl getMessageHandlerImpl()
          Returns the current MessageHandler as its implementing class MessageHandlerImpl (which has more features).
 PropertyManager getPropertyManager()
          Returns the current PropertyManager.
 int getSettings()
          Returns the current settings as an int.
 ThreadGroup getThreadGroup()
          Returns the ThreadGroup used with Ceryle (named "Ceryle").
 TopicMapProcessor getTopicMapProcessor()
          Returns the TopicMapProcessor providing topic map processing services.
 TopicMapProcessor getTopicMapProcessor(boolean create)
          Returns the TopicMapProcessor providing topic map processing services.
 String getXDatabaseURI(String cid, String nid)
          Returns a URI-like String representing the Collection ID cid and Node ID id using the currently available database (if DB services are unavailable, returns null).
 XMLProcessor getXMLProcessor()
          Returns the current XMLProcessor, whose validation status is set by the current validation setting.
 XMLProcessor getXMLProcessor(boolean validating)
          Returns a well-formed or validating XML processor based on the boolean value of validating, creating the processor if it doesn't yet exist.
 XNodeStore getXNodeStore()
          Returns a lazily-instantiated XNodeStore, providing database services.
 void importTinyFont()
          Imports the tiny font as a set of resources.
 boolean isConnected()
          Returns true if a database connection is currently available.
 boolean isDeveloper()
          Returns true if operating in developer mode.
 boolean isVerbose()
          Returns the current "verbose" setting.
static String message(String id)
          A static convenience method that passes the message off to the MessageHandler.
protected static void postInstantiation(Services srvs)
          This starts up any application services that can only be created after the Services object is available.
static String printMemoryUsage()
          Returns a string containing the current free memory statistic.
 String printStackTrace(Throwable t)
          Prints the stack trace from the provided Throwable (usually, an Exception) to the MessageHandler.
 boolean ready()
          Returns true if the system services are ready.
 void resetHelperApplications()
          Resets the Helper Application lookup table.
 File resolvePath(String filename)
          Provided with a filename, returns a File.
protected  void setAvailableFonts()
          Sets the ArrayList to contain the list of fonts available in the current environment.
protected  void setCatalogResolverProperties()
          Sets CatalogResolver (System-based) properties.
 void setDefaultDirectory(File dir)
          Sets the default (user) directory for file operations to the supplied File.
 void setDefaultDirectory(String path)
          Sets the default (user) directory for file operations based on the supplied path.
 void setFont(int fontNumber, Font font)
          Set the application font at index to Font font.
 void setProperties()
          Sets 'global' system properties based on the properties file, including those for XML processing and the database store.
 boolean setThreadPriority(String groupname, int priority)
          Set the priority of all active threads within the ThreadGroup whose name is groupname to priority.
static String warning(String msg)
          A static convenience method that passes the warning off to the MessageHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORM_TEMPLATE_ID

public static final String FORM_TEMPLATE_ID
A String constant containing the ID of the default form template for a given Collection.

See Also:
Constant Field Values

homeDirectory

public final File homeDirectory
The Ceryle application home directory. In documentation this is described as $CERYLE_HOME.


resourceDir

public static File resourceDir
The Ceryle resource directory. By default, $CERYLE_HOME/resource/.


homeDirectoryURL

public URL homeDirectoryURL
The Ceryle application home directory as a URL.


defaultCatalogPath

public static String defaultCatalogPath
The default relative pathname for the XML Catalog file. The default value is "resource/ceryle.xcat".


m_ext2HAPath

protected Hashtable m_ext2HAPath
The lookup table for file extension to Helper Application path.


m_mime2HAPath

protected Hashtable m_mime2HAPath
The lookup table for MIME type (as String) to Helper Application path.


m_catalogResolver

protected org.apache.xml.resolver.tools.CatalogResolver m_catalogResolver
The CatalogResolver used to resolve XML entity references. This is shared by all XMLProcessor instances.

Method Detail

getInstance

public static Services getInstance()
As this is a singleton class, this returns the single instance of this class using the defaults for the properties file and settings (ui,merge,xmlns-aware,validating). If the Services object has already been created, this method returns it.

This is not the recommended method for instantiating the class as normally an existing MessageHandler is provided in the constructor; inthis case it will be created using default properties.


getInstance

public static Services getInstance(MessageHandlerImpl messagehandler,
                                   String propertiesFile,
                                   int settings)
As this is a singleton class, this returns the single instance of this class provided with the optional MessageHandlerImpl, the property file filename and bit-wise application settings.

Generally, this is the method used to initially create the Services instance, as it allows for external settings. This also calls a protected method postInstantiation(Services) to start up application services that can only be created after there is a Services object.


postInstantiation

protected static void postInstantiation(Services srvs)
This starts up any application services that can only be created after the Services object is available.


getCatalogResolver

public org.apache.xml.resolver.tools.CatalogResolver getCatalogResolver()
This returns the single instance of a CatalogResolver, to be reused by all XMLProcessors. Because this class' characteristics are set by System properties, these should be set prior to instantiation.


setCatalogResolverProperties

protected void setCatalogResolverProperties()
Sets CatalogResolver (System-based) properties.


ready

public boolean ready()
Returns true if the system services are ready.


disposeWelcomeWindow

public void disposeWelcomeWindow(MessageWriter messagewriter)
Closes and disposes of the WelcomeWindow, if it is displayed. This also sets the new recipient of system messages to the MessageWriter messagewriter. This is performed by the Desktop in a hand-off of system messaging.


isDeveloper

public boolean isDeveloper()
Returns true if operating in developer mode. This can also be determined from the System property "http://purl.org/ceryle/prop/developer-mode".

See Also:
Constants.DEVELOPER

getAvailableFonts

public List getAvailableFonts()
Returns an unmodifiable List containing the available Fonts. This can only be called after setAvailableFonts(). If empty, returns an empty List (not null).


setAvailableFonts

protected void setAvailableFonts()
Sets the ArrayList to contain the list of fonts available in the current environment.


importTinyFont

public void importTinyFont()
Imports the tiny font as a set of resources.


setFont

public void setFont(int fontNumber,
                    Font font)
Set the application font at index to Font font. See getFont(int).


getFont

public Font getFont(int fontNumber)
Return an existing application font based on index. Where:


getFont

public Font getFont(String basename)
Return a Font provided its property base name and style. The property name for font family is determined by adding "Face" to the base name, its property for size by adding "Size" to the base name. Sizes between 6 and 72 are allowed. If a property lookup fails or the indicated family is unavailable, the default of 10 pt "SansSerif" will be used.


setProperties

public void setProperties()
Sets 'global' system properties based on the properties file, including those for XML processing and the database store.


getImagePath

public String getImagePath()
Returns the path to the image directory (used for building a GUI, etc.).


getMessageHandler

public MessageHandler getMessageHandler()
Returns the current MessageHandler.


getMessageHandlerImpl

public MessageHandlerImpl getMessageHandlerImpl()
Returns the current MessageHandler as its implementing class MessageHandlerImpl (which has more features).


getPropertyManager

public PropertyManager getPropertyManager()
Returns the current PropertyManager.


getSettings

public int getSettings()
Returns the current settings as an int.


isVerbose

public boolean isVerbose()
Returns the current "verbose" setting.


getThreadGroup

public ThreadGroup getThreadGroup()
Returns the ThreadGroup used with Ceryle (named "Ceryle").


setThreadPriority

public boolean setThreadPriority(String groupname,
                                 int priority)
Set the priority of all active threads within the ThreadGroup whose name is groupname to priority. Note that due to Thread security, Threads outside of the calling Thread tree will not be able to alter (or even see) the priority of Threads from other branches.

Returns:
true if one or more Threads from the specified group were reprioritized.

getBaseOntologies

public String[] getBaseOntologies()
Loads the URLs of the three base ontologies: minimal, upper, and middle. If any these can't be loaded from the property file, this will attempt to locate them in their canonical location and then updates (fixes) the stored property. If they are file: URLs an attempt will be made to locate the file; if not found a null value is returned for that element.

Returns:
a String array of three values (never null); if a specific value can't be obtained a null value is used for that element.

message

public static String message(String id)
A static convenience method that passes the message off to the MessageHandler.

See Also:
MessageHandler

error

public static String error(String id)
A static convenience method that passes the error off to the MessageHandler.

See Also:
MessageHandler

error

public static String error(String id,
                           String arg)
A static convenience method that passes the error off to the MessageHandler.

See Also:
MessageHandler

error

public static String error(String id,
                           String arg1,
                           String arg2)
A static convenience method that passes the error off to the MessageHandler.

See Also:
MessageHandler

error

public static String error(String id,
                           String arg1,
                           String arg2,
                           String arg3)
A static convenience method that passes the error off to the MessageHandler.

See Also:
MessageHandler

warning

public static String warning(String msg)
A static convenience method that passes the warning off to the MessageHandler.

See Also:
MessageHandler

getXMLProcessor

public XMLProcessor getXMLProcessor()
                             throws ProcessException
Returns the current XMLProcessor, whose validation status is set by the current validation setting.

Throws:
ProcessException

getXMLProcessor

public XMLProcessor getXMLProcessor(boolean validating)
                             throws ProcessException
Returns a well-formed or validating XML processor based on the boolean value of validating, creating the processor if it doesn't yet exist. Note: currently doesn't check to see if such a processor already exists, simply creates one.

Throws:
ProcessException

getTopicMapProcessor

public TopicMapProcessor getTopicMapProcessor()
                                       throws TopicMapException
Returns the TopicMapProcessor providing topic map processing services. The processor is not created until the first time this method is called.

This is a convenience method that passes the message off to the TopicMapManager.

Throws:
TopicMapException

getTopicMapProcessor

public TopicMapProcessor getTopicMapProcessor(boolean create)
                                       throws TopicMapException
Returns the TopicMapProcessor providing topic map processing services. The processor is not created until the first time this method is called. If the boolean create is true, this will create and return a new processor.

This is a convenience method that passes the message off to the TopicMapManager.

Throws:
TopicMapException

isConnected

public boolean isConnected()
Returns true if a database connection is currently available. This is a convenience method.


getXNodeStore

public XNodeStore getXNodeStore()
Returns a lazily-instantiated XNodeStore, providing database services.


getCollectionIndex

public SetModel getCollectionIndex()
Returns the list of database Collections as a SetModel, an empty SetModel (rather than null) if no database * connection is available. This is a convenience method that wraps the XNodeStore.getCollectionIndex() method from XNodeStore, casts it as a SetModel (its backing class), and traps any exceptions. For UI purposes, returning an empty Set under all conditions is better (with the error handler catching any messages).

See Also:
XNodeStore, SetModel

getCollectionSize

public int getCollectionSize()
Returns the count of database Collections as a int. This returns zero if the database service is unavailable.


getXDatabaseURI

public String getXDatabaseURI(String cid,
                              String nid)
Returns a URI-like String representing the Collection ID cid and Node ID id using the currently available database (if DB services are unavailable, returns null). If nid is null, a URI for the Collection alone is returned. If both cid and nid are null, null is returned.


dbAction

public void dbAction(XNodeState state)
Uses an XNodeState as a directive to control the database. The accepted states include:
XNodeState.START
A directive to start the database kernel (if not already running).
XNodeState.STOP
A directive to stop the database kernel (if running).
XNodeState.STATUS
Print the status of the database.
Other XNodeStates are ignored.


resetHelperApplications

public void resetHelperApplications()
Resets the Helper Application lookup table.


getHelperFromMIME

public String getHelperFromMIME(String mime)
Returns a path to a Helper Application provided a MIME type, null if none has been registered for that type.

If this is the Helper Application for HTML or XHTML, or for any MIME that uses the same browser, the remote command is appended (if available).


getHelperFromPath

public String getHelperFromPath(String systemId)
Returns a path to a Helper Application provided a file extension, null if none has been registered for that extension.

If this is the Helper Application for HTML or XHTML, or for any MIME that uses the same browser, the remote command is appended (if available).


getHelperFromExt

public String getHelperFromExt(String ext)
Returns a path to a Helper Application provided a file extension, null if none has been registered for that extension.

If this is the Helper Application for HTML or XHTML, or for any MIME that uses the same browser, the remote command is appended (if available).


getGroovyService

public GroovyService getGroovyService()
Returns a GroovyService object, providing Groovy interpretation and console services.


setDefaultDirectory

public void setDefaultDirectory(String path)
Sets the default (user) directory for file operations based on the supplied path. A file separator (e.g., '/' in unix) will be added to the end of the path if it is not included with the specification.


setDefaultDirectory

public void setDefaultDirectory(File dir)
Sets the default (user) directory for file operations to the supplied File.


getDefaultDirectory

public File getDefaultDirectory()
Returns the default (user) directory for file operations. If this is not set, returns the directory provided by the System.


resolvePath

public File resolvePath(String filename)
Provided with a filename, returns a File. If the File cannot be found, after trying various locations, queries the user for it. If any of this fails or the user cancels, returns null. This only returns files, not directories.


printStackTrace

public String printStackTrace(Throwable t)
Prints the stack trace from the provided Throwable (usually, an Exception) to the MessageHandler. Also returns it as a value.


printMemoryUsage

public static String printMemoryUsage()
Returns a string containing the current free memory statistic.


getIDFactory

public IDFactory getIDFactory()
Returns a reusable IDFactory that produces XML Name-compatible random words.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.