org.mmbase.util
Class MMBaseContext

Package class diagram package MMBaseContext
java.lang.Object
  extended by org.mmbase.util.MMBaseContext
All Implemented Interfaces:
EventListener, ServletContextListener

public class MMBaseContext
extends Object
implements ServletContextListener

Using MMBaseContext class you can retrieve the servletContext from anywhere using the get method. (This class used to be MMBaseContext before MMBase 2.0).

Version:
$Id: MMBaseContext.java 45415 2011-02-24 12:57:16Z michiel $
Author:
Daniel Ockeloen, David van Zeventer, Jaco de Groot

Field Summary
static Logger INITLOG
           
static int startTime
           
 
Constructor Summary
MMBaseContext()
           
 
Method Summary
 void contextDestroyed(ServletContextEvent sce)
           
 void contextInitialized(ServletContextEvent sce)
           
static String getConfigPath()
          Deprecated. use ResourceLoader.getConfigurationRoot() with relative path
static File getDataDir()
           
static String getEncoding()
           
static String getHost()
          The host or ip number of the machine this module is running on.
static String getHtmlRoot()
          Returns a string representing the mmbase.htmlroot parameter without a final File.separator.
static String getHtmlRootUrlPath()
          Returns a string representing the HtmlRootUrlPath, this is the path under the webserver, what is the root for this instance.
static String getMachineName()
          Returns the unique identifier for the MMBase instance.
static String getOutputFile()
          Deprecated. use logging system
static ServletContext getServletContext()
          Returns the ServletContext used to initialize MMBase.
static ThreadGroup getThreadGroup()
          Returns the MMBase thread group.
static void init()
          Initialize MMBase using system properties only.
static void init(ServletContext servletContext)
          Initialize MMBase using a ServletContext.
static void init(String configPath, boolean initLogging)
          Initialize MMBase using a config path.
static void initHtmlRoot()
          Initialize mmbase.htmlroot parameter.
static boolean isHtmlRootInitialized()
           
static boolean isInitialized()
          Returns whether this class has been initialized.
static boolean isShutdown()
           
static void setDataDir(String setting)
           
static void setEncoding(String e)
           
static void setHost(String h)
           
static void setMachineName(String nm)
           
static void shutdown()
           
static Thread startThread(Runnable task, String name)
          Starts a daemon thread using the MMBase thread group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITLOG

public static final Logger INITLOG

startTime

public static final int startTime
Constructor Detail

MMBaseContext

public MMBaseContext()
Method Detail

init

public static void init(ServletContext servletContext)
Initialize MMBase using a ServletContext. This method will check the servlet configuration for context parameters mmbase.outputfile and mmbase.config. If not found it will look for system properties.

Throws:
ServletException - if mmbase.config is not set or is not a directory or doesn't contain the expected config files.

init

public static void init(String configPath,
                        boolean initLogging)
                 throws Exception
Initialize MMBase using a config path. Useful when testing MMBase classes with a main. You can also configure to init logging or not.

Throws:
Exception - if mmbase.config is not set or is not a directory or doesn't contain the expected config files.

init

public static void init()
                 throws Exception
Initialize MMBase using system properties only. This may be useful in cases where MMBase is used without a servlet. For example when running JUnit tests.

Throws:
Exception - if mmbase.config is not set or is not a directory or doesn't contain the expected config files.

getThreadGroup

public static ThreadGroup getThreadGroup()
Returns the MMBase thread group.

Since:
MMBase-1.8

startThread

public static Thread startThread(Runnable task,
                                 String name)
Starts a daemon thread using the MMBase thread group.

Parameters:
task - the task to run as a thread
name - the thread's name
Since:
MMBase-1.8

initHtmlRoot

public static void initHtmlRoot()
                         throws ServletException
Initialize mmbase.htmlroot parameter. If the mmbase.htmlroot parameter is not found in the servlet context or system prooperties this method will try to set it to the root directory of the webapp.

Throws:
ServletException - if mmbase.htmlroot is not set or is not a directory

getServletContext

public static ServletContext getServletContext()
Returns the ServletContext used to initialize MMBase. Before calling this method the init method should be called.

Returns:
the ServletContext used to initialize MMBase or null if MMBase was initialized without ServletContext

getConfigPath

public static String getConfigPath()
Deprecated. use ResourceLoader.getConfigurationRoot() with relative path

Returns a string representing the mmbase.config parameter without a final File.separator. Before calling this method the init method should be called to make sure this parameter is set.

Returns:
the mmbase.config parameter or WEB-INF/config

getHtmlRoot

public static String getHtmlRoot()
Returns a string representing the mmbase.htmlroot parameter without a final File.separator. Before calling this method the initHtmlRoot method should be called to make sure this parameter is set.

Returns:
the mmbase.htmlroot parameter or null if not initialized

isHtmlRootInitialized

public static boolean isHtmlRootInitialized()
Since:
MMBase-2.0

getOutputFile

public static String getOutputFile()
Deprecated. use logging system

Returns a string representing the mmbase.outputfile parameter. If set, this is the file to wich all System.out and System.err output is redirected. Before calling this method the init method should be called.

Returns:
the mmbase.outputFile parameter or null if not set

getHtmlRootUrlPath

public static String getHtmlRootUrlPath()
Returns a string representing the HtmlRootUrlPath, this is the path under the webserver, what is the root for this instance. this will return '/' or something like '/mmbase/' or so... This information should be requested from the ServletRequest, but if for some reason you don't have one handy, this method can be used. When using Servlet 2.5, this is the same as getServletContext().getContextPath() + "/", so this also ends in a /

Returns:
the HtmlRootUrlPath

isInitialized

public static boolean isInitialized()
Returns whether this class has been initialized. This can be used to determine whether MMBase specific configuration data is accessible.


getMachineName

public static String getMachineName()
Returns the unique identifier for the MMBase instance. Used for clustering.

Returns:
'machine name' to identify this web app or null if not yet determined.
Since:
MMBase-1.8.7

setMachineName

public static void setMachineName(String nm)
Since:
MMBase-2.0

shutdown

public static void shutdown()
Since:
MMBase-2.0

isShutdown

public static boolean isShutdown()
Since:
MMBase-2.0

getEncoding

public static String getEncoding()
Since:
MMBase-2.0

setEncoding

public static void setEncoding(String e)
Since:
MMBase-2.0

getHost

public static String getHost()
The host or ip number of the machine this module is running on. Its important that this name is set correctly because it is used for communication between mmbase nodes and external devices

Since:
MMBase-2.0

setHost

public static void setHost(String h)
Since:
MMBase-2.0

getDataDir

public static File getDataDir()
Since:
MMBase-2.0

setDataDir

public static void setDataDir(String setting)
Since:
MMBase-2.0

contextDestroyed

public void contextDestroyed(ServletContextEvent sce)
Specified by:
contextDestroyed in interface ServletContextListener
Since:
MMBase-2.0

contextInitialized

public void contextInitialized(ServletContextEvent sce)
Specified by:
contextInitialized in interface ServletContextListener
Since:
MMBase-2.0


MMBase2 Utils 2.0-SNAPSHOT - 2013-05-29T22:03