org.mmbase.module.core
Class MMBaseContext

java.lang.Object
  extended by org.mmbase.module.core.MMBaseContext

public class MMBaseContext
extends Object

Using MMBaseContext class you can retrieve the servletContext from anywhere using the get method.

Version:
$Id: MMBaseContext.java 42210 2010-05-18 11:50:32Z michiel $
Author:
Daniel Ockeloen, David van Zeventer, Jaco de Groot

Field Summary
(package private) static boolean htmlRootInitialized
           
(package private) static String machineName
          Name of the machine used in the mmbase cluster.
static int startTime
           
 
Constructor Summary
MMBaseContext()
           
 
Method Summary
static String getConfigPath()
          Deprecated. use ResourceLoader.getConfigurationRoot() with relative path
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()
          Static version of MMBase.getMachineName()
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 isInitialized()
          Returns whether this class has been initialized.
static boolean isShutdown()
           
static void shutdown()
           
static DaemonThread startThread(DaemonTask task, String name)
          Deprecated. Use ThreadPools.scheduler.
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

htmlRootInitialized

static boolean htmlRootInitialized

startTime

public static final int startTime

machineName

static String machineName
Name of the machine used in the mmbase cluster. it is used for the mmservers objects. Make sure that this is different for each node in your cluster. This is not the machines dns name (as defined by host as name or ip number).

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

startThread

public static DaemonThread startThread(DaemonTask task,
                                       String name)
Deprecated. Use ThreadPools.scheduler.

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. This method is only needed for SCAN related servlets and should be called after the init(ServletContext) method. 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

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()
Static version of MMBase.getMachineName()

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

shutdown

public static void shutdown()
Since:
MMBase-2.0

isShutdown

public static boolean isShutdown()
Since:
MMBase-2.0


MMBase 2.0-SNAPSHOT - null