org.mmbase.module.core
Class MMBase

java.lang.Object
  extended byorg.mmbase.module.Module
      extended byorg.mmbase.module.ProcessorModule
          extended byorg.mmbase.module.core.MMBase
All Implemented Interfaces:
ProcessorInterface

public class MMBase
extends ProcessorModule

The module which provides access to the MMBase database defined by the provided name/setup. It holds the overal object cloud made up of builders, objects and relations and all the needed tools to use them.

Version:
$Id: MMBase.java,v 1.113.2.3 2004/07/16 11:23:34 pierre Exp $
Author:
Daniel Ockeloen, Pierre van Rooden, Johannes Verelst

Field Summary
 java.lang.String baseName
          Base name for the database to be accessed using this instance of MMBase.
 InsRel InsRel
          Reference to the InsRel builder.
 MMBaseChangeInterface mmc
          Builds a MultiCast Thread to receive and send changes from other MMBase Servers.
 java.util.Hashtable mmobjs
          The table that contains all loaded builders.
 OAlias OAlias
          Reference to the OALias builder.
 RelDef RelDef
          Reference to the RelDef builder.
static int startTime
          Time in seconds, when mmbase was started.
 TypeDef TypeDef
          Reference to the TypeDef builder.
 TypeRel TypeRel
          Reference to the TypeRel builder.
 
Constructor Summary
MMBase()
          Constructor to create the MMBase root module.
 
Method Summary
 boolean addLocalObserver(java.lang.String type, MMBaseObserver obs)
          Adds a local observer to a specified builder.
 boolean addRemoteObserver(java.lang.String type, MMBaseObserver obs)
          Adds a remote observer to a specified builder.
protected  void assertUp()
          Locks until init of mmbase is finished.
 MMObjectNode castNode(MMObjectNode node)
          Deprecated. Not necessary in most cases, with the possible exception of lists obtained from InsRel. However, in the later case using this method is probably too costly.
 void checkUserLevel()
          Checks and switches the user/grouplevel in which MMBase runs.
 void closeConnection(MultiConnection con, java.sql.Statement stmt)
          Safely close a database connection and/or a database statement.
 java.lang.String doGetAgeMarker(java.util.StringTokenizer tok)
          Deprecated. SCAN related, should not be in this module.
 void doProbeRun()
          Callback method, called from MMBaseProbe.
 java.lang.String getAuthType()
          Retrieves the autorisation type.
 java.lang.Object getBaseModule(java.lang.String name)
          Retrieves a (mmbase) module by name.
 java.lang.String getBaseName()
          Retrieves the database base name
 MMObjectBuilder getBuilder(java.lang.String name)
          Retrieves a specified builder.
 java.lang.String getBuilderPath(java.lang.String builder, java.lang.String path)
          Locate one specific builder within a given path, relative to the main builder config path, including sub-paths.
 ClusterBuilder getClusterBuilder()
          Returns a reference to the cluster builder, a virtual builder used to perform multilevel searches.
 MultiConnection getConnection()
          Get a database connection that is multiplexed and checked.
 java.lang.String getCookieDomain()
          Retrieves the cookiedomain (whatever that is) This value is set using the configuration file.
 MMJdbc2NodeInterface getDatabase()
          Returns a reference to the database used.
 int getDBKey()
          Retrieves an unique key to use for a new node's number.
 java.sql.Connection getDirectConnection()
          Get a direct database connection.
 java.lang.String getDTDBase()
          Deprecated. keesj: This method is not used. Document type definitions should contain a fully qualified url. I think the author was thinking of a dtdpath wich makes sence
 java.lang.String getEncoding()
          Retrieves the encoding.
 java.lang.String getHost()
          Retrieves the host name or ip number This value is set using the configuration file.
 InsRel getInsRel()
          Returns a reference to the InsRel builder.
 JDBCInterface getJDBC()
          Get the JDBC module used by this MMBase.
 java.lang.String getLanguage()
          Retrieves the current language.
 java.util.Locale getLocale()
          Retrieves the current locale.
 java.lang.String getMachineName()
          Retrieves the machine name.
static MMBase getMMBase()
          Retrieves the MMBase module('mmbaseroot').
 MMBaseCop getMMBaseCop()
          Retrieves the loaded security manager(MMBaseCop).
 MMObjectBuilder getMMObject(java.lang.String name)
          Retrieves a specified builder.
 java.util.Enumeration getMMObjects()
          Retrieves the loaded builders.
 OAlias getOAlias()
          Returns a reference to the OAlias builder.
 RelDef getRelDef()
          Returns a reference to the RelDef builder.
 MMObjectBuilder getRootBuilder()
          Returns a reference to the Object builder.
 int getRootType()
          Returns the otype of the Object builder, or -1 if it is not known.
 java.util.Hashtable getSearchHash(java.util.Vector se, java.lang.String mapper)
          Converts a vector containing nodes to a hashmap, using a specified (unique) integer field as the hash key.
 SendMailInterface getSendMail()
          Deprecated. use getModule("sendmail") instead SendMail will become a separate application. In MMBase 1.8. this method will be removed
 boolean getState()
          Retrieves whether this mmbase module is running.
 StorageManager getStorageManager()
          Returns a StorageManager to access the storage..
 StorageManagerFactory getStorageManagerFactory()
          Returns StorageManagerFactory class used to access the storage configuration.
 TypeDef getTypeDef()
          Returns a reference to the TypeDef builder.
 TypeRel getTypeRel()
          Returns a reference to the TypeRel builder.
 java.lang.String getWhereList(java.util.Vector se, java.lang.String mapper)
          Converts a vector containing nodes to a comma seperated list of values, obtained from a specified integer field.
 void init()
          Initalizes the MMBase module.
 void initBuilder(MMObjectBuilder builder)
          inits a builder
protected  void initializeStorage()
          Loads either the storage manager factory or the appropriate support class using the configuration parameters.
 boolean isShutdown()
           
 MMObjectBuilder loadBuilderFromXML(java.lang.String builder, java.lang.String ipath)
          Create a new builder object using a xml configfile located in a given path relative to the main builder config path, and return the builder object.
 void maintainance()
          Performs periodic maintenance.
 void onload()
          Started when the module is loaded.
protected  void shutdown()
          Shuts down the module.
 void stop()
           
 void unload()
          What should this do, when is this called? (MM)
 void unloadBuilder(MMObjectBuilder builder)
          Unloads a builders from MMBase.
 
Methods inherited from class org.mmbase.module.ProcessorModule
cacheCheck, getList, getListBuilder, getNodeList, process, reload, replace, replace
 
Methods inherited from class org.mmbase.module.Module
getInitParameter, getInitParameters, getMaintainer, getMimeType, getMimeTypeFile, getModule, getModule, getModuleInfo, getModules, getName, getProperties, getProperty, getVersion, hasStarted, loadModulesFromDisk, setInitParameter, setMaintainer, setName, setVersion, shutdownModules, startModule, startModules, state
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

startTime

public static final int startTime
Time in seconds, when mmbase was started.

Since:
MMBase-1.7

mmc

public MMBaseChangeInterface mmc
Builds a MultiCast Thread to receive and send changes from other MMBase Servers.

Warning: Scope will be changed to:
private

baseName

public java.lang.String baseName
Base name for the database to be accessed using this instance of MMBase. Retrieved from the mmbaseroot module configuration setUser If not specified the default is "def1" Should be made private and accessed instead using getBaseName()

Warning: Scope will be changed to:
private

TypeDef

public TypeDef TypeDef
Reference to the TypeDef builder. Should be made private and accessed instead using getTypeDef()

Warning: Scope will be changed to:
private

RelDef

public RelDef RelDef
Reference to the RelDef builder. Should be made private and accessed instead using getRelDef()

Warning: Scope will be changed to:
private

OAlias

public OAlias OAlias
Reference to the OALias builder. Should be made private and accessed instead using getOAlias()

Warning: Scope will be changed to:
private

InsRel

public InsRel InsRel
Reference to the InsRel builder. Should be made private and accessed instead using getInsRel()

Warning: Scope will be changed to:
private

TypeRel

public TypeRel TypeRel
Reference to the TypeRel builder. Should be made private and accessed instead using getTypeRel()

Warning: Scope will be changed to:
private

mmobjs

public java.util.Hashtable mmobjs
The table that contains all loaded builders. Includes virtual builders such as "multirelations". Should be made private and accessed using getMMObjects()

Warning: Scope will be changed to:
private
Constructor Detail

MMBase

public MMBase()
Constructor to create the MMBase root module.

Method Detail

init

public void init()
Initalizes the MMBase module. Evaluates the parameters loaded from the configuration file. Sets parameters (authorisation, language), loads the builders, and starts MultiCasting.

Overrides:
init in class ProcessorModule

shutdown

protected void shutdown()
Description copied from class: Module
Shuts down the module. This method is called by shutdownModules.

Overrides:
shutdown in class Module

isShutdown

public boolean isShutdown()
Since:
MMBase-1.7

onload

public void onload()
Started when the module is loaded.

Overrides:
onload in class ProcessorModule

unload

public void unload()
Description copied from class: ProcessorModule
What should this do, when is this called? (MM)

Overrides:
unload in class ProcessorModule

getBuilder

public MMObjectBuilder getBuilder(java.lang.String name)
                           throws CircularReferenceException
Retrieves a specified builder. If the builder is not loaded, but the system is in the 'startup' state (i.e. it is in the process of loading builders), an attempt is made to directly load the builder. This allows for dependencies between builders to exist (i.e. inheritance). When circular reference occurs between two loading buidlers, an exception is thrown.

Parameters:
name - The name of the builder to retrieve
Returns:
a MMObjectBuilder for the specified builder
Throws:
CircularReferenceException - when circular reference is detected
BuilderConfigurationException - if the builder config file does not exist
Since:
MMBase-1.6

getMMObject

public MMObjectBuilder getMMObject(java.lang.String name)
Retrieves a specified builder. Note: may get deprecated in the future - use getBuilder instead.

Parameters:
name - The name of the builder to retrieve
Returns:
a MMObjectBuilder if found, null otherwise

getMMBase

public static MMBase getMMBase()
Retrieves the MMBase module('mmbaseroot').

Returns:
the active MMBase module

getMMBaseCop

public MMBaseCop getMMBaseCop()
Retrieves the loaded security manager(MMBaseCop).

Returns:
the loaded security manager(MMBaseCop)

getMMObjects

public java.util.Enumeration getMMObjects()
Retrieves the loaded builders.

Returns:
an Enumeration listing the loaded builders

getInsRel

public InsRel getInsRel()
Returns a reference to the InsRel builder.

Returns:
the InsRel builder if defined, null otherwise

getRelDef

public RelDef getRelDef()
Returns a reference to the RelDef builder.

Returns:
the RelDef builder if defined, null otherwise

getTypeDef

public TypeDef getTypeDef()
Returns a reference to the TypeDef builder.

Returns:
the TypeDef builder if defined, null otherwise

getTypeRel

public TypeRel getTypeRel()
Returns a reference to the TypeRel builder.

Returns:
the TypeRel builder if defined, null otherwise

getOAlias

public OAlias getOAlias()
Returns a reference to the OAlias builder.

Returns:
the OAlias builder if defined, null otherwise

getRootBuilder

public MMObjectBuilder getRootBuilder()
Returns a reference to the Object builder. The Object builder is the builder from which all other builders eventually extend. If the builder is not defined in the MMbase configuration, the system creates one.

Returns:
the Object builder.
Since:
MMBase1,6

getRootType

public int getRootType()
Returns the otype of the Object builder, or -1 if it is not known. The Object builder is the builder from which all other builders eventually extend.

Since:
MMBase1,6

getClusterBuilder

public ClusterBuilder getClusterBuilder()
Returns a reference to the cluster builder, a virtual builder used to perform multilevel searches.

Returns:
The cluster builder.
See Also:
ClusterBuilder

getJDBC

public JDBCInterface getJDBC()
Get the JDBC module used by this MMBase.


closeConnection

public void closeConnection(MultiConnection con,
                            java.sql.Statement stmt)
Safely close a database connection and/or a database statement.

Parameters:
con - The connection to close. Can be null.
stmt - The statement to close, prior to closing the connection. Can be null.

assertUp

protected void assertUp()
Locks until init of mmbase is finished.

Since:
MMBase-1.7

getConnection

public MultiConnection getConnection()
Get a database connection that is multiplexed and checked.

Returns:
a MultiConnection

getDirectConnection

public java.sql.Connection getDirectConnection()
Get a direct database connection. Should only be used if you want to do database specific things that use non-jdbc interface calls. Use very sparingly.


getBaseName

public java.lang.String getBaseName()
Retrieves the database base name

Returns:
the base name as a String

doProbeRun

public void doProbeRun()
Callback method, called from MMBaseProbe. The probe is a seperate thread that is created every 10 minutes by the module's maintainance() call.

To Do:
Evaluate whether presence of daymarks is required
Warning: Performance Issues
daymarks should be loaded at initialization.

maintainance

public void maintainance()
Performs periodic maintenance. Starts a separate thread that probes the builders by calling doProbeRun(). The reference to the thread is cleared when it dies (scheduled every 10 minutes), prompting the system to start a new thread.

Overrides:
maintainance in class Module
See Also:
MMBaseProbe

getSearchHash

public java.util.Hashtable getSearchHash(java.util.Vector se,
                                         java.lang.String mapper)
Converts a vector containing nodes to a hashmap, using a specified (unique) integer field as the hash key.

Parameters:
se - The vector containing the nodes
mapper - the name of the (integer) field that determines the hash key, i.e. "number"
Returns:
the node list mapped to a Hashtable

getWhereList

public java.lang.String getWhereList(java.util.Vector se,
                                     java.lang.String mapper)
Converts a vector containing nodes to a comma seperated list of values, obtained from a specified integer field.

Parameters:
se - The vector containing the nodes
mapper - the name of the (integer) field whose value to include in the list
Returns:
a parenthised, comma-seperated list of values, as a String

getSendMail

public SendMailInterface getSendMail()
Deprecated. use getModule("sendmail") instead SendMail will become a separate application. In MMBase 1.8. this method will be removed

Retrieves a reference to the sendmail module.

Returns:
a SendMailInterface object if the module was loaded, null otherwise.

getMachineName

public java.lang.String getMachineName()
Retrieves the machine name. This value is set using the configuration file.

Returns:
the machine name as a String

getHost

public java.lang.String getHost()
Retrieves the host name or ip number This value is set using the configuration file.

Returns:
the host name as a String

getCookieDomain

public java.lang.String getCookieDomain()
Retrieves the cookiedomain (whatever that is) This value is set using the configuration file.

Returns:
the cookie domain as a String

addRemoteObserver

public boolean addRemoteObserver(java.lang.String type,
                                 MMBaseObserver obs)
Adds a remote observer to a specified builder. The observer is notified whenever an object of that builder is changed, added, or removed.

Returns:
true if adding the observer succeeded, false otherwise.

addLocalObserver

public boolean addLocalObserver(java.lang.String type,
                                MMBaseObserver obs)
Adds a local observer to a specified builder. The observer is notified whenever an object of that builder is changed, added, or removed.

Returns:
true if adding the observer succeeded, false otherwise.

doGetAgeMarker

public java.lang.String doGetAgeMarker(java.util.StringTokenizer tok)
Deprecated. SCAN related, should not be in this module.

Returns the number of marked days from a specified daycount (?)


getDBKey

public int getDBKey()
Retrieves an unique key to use for a new node's number. Calls the database to request the key. Sychronized so the same number cannot be dealt out to different nodes. Does possibly not work well with multiple mmbase systems that work on the same database.

Returns:
the new unique key as an int value

getBaseModule

public java.lang.Object getBaseModule(java.lang.String name)
Retrieves a (mmbase) module by name.

Returns:
the module as an Object if it exists, null otherwise

stop

public void stop()

initBuilder

public void initBuilder(MMObjectBuilder builder)
inits a builder

Parameters:
builder - The builder which has to be initialized

unloadBuilder

public void unloadBuilder(MMObjectBuilder builder)
Unloads a builders from MMBase. After this, the builder is gone

Parameters:
builder - the builder which has to be unloaded

getBuilderPath

public java.lang.String getBuilderPath(java.lang.String builder,
                                       java.lang.String path)
Locate one specific builder within a given path, relative to the main builder config path, including sub-paths. Return the actual path.

Parameters:
builder - name of the builder to find
path - the path to start searching. The path need be closed with a File.seperator character.
Returns:
the file path to the builder xml, or null if the builder could not be created (i.e. is inactive).
Throws:
BuilderConfigurationException - if the builder config file does not exist

loadBuilderFromXML

public MMObjectBuilder loadBuilderFromXML(java.lang.String builder,
                                          java.lang.String ipath)
Create a new builder object using a xml configfile located in a given path relative to the main builder config path, and return the builder object. If the builder already exists, the existing object is returned instead. Note that the builder's init() method is NOT called (since some builders need other builders in memory when their init() is called, this method is called seperately after all builders are loaded).

Parameters:
builder - name of the builder to initialize
ipath - the path to start searching. The path need be closed with a File.seperator character.
Returns:
the loaded builder object.

getDTDBase

public java.lang.String getDTDBase()
Deprecated. keesj: This method is not used. Document type definitions should contain a fully qualified url. I think the author was thinking of a dtdpath wich makes sence

Retrieves the DTD base url. This value is set using the configuration file.

Returns:
the dtd base as a String

getDatabase

public MMJdbc2NodeInterface getDatabase()
Returns a reference to the database used. If needed, it loads the appropriate support class using the configuration parameters.

Returns:
a MMJdbc2NodeInterface which holds the appropriate database class

initializeStorage

protected void initializeStorage()
Loads either the storage manager factory or the appropriate support class using the configuration parameters.

Since:
MMBase-1.7

getStorageManagerFactory

public StorageManagerFactory getStorageManagerFactory()
Returns StorageManagerFactory class used to access the storage configuration. Note: in MMBase 1.7, this may return null if the system uses the old support classes to access the storage.

Returns:
a StorageManagerFactory class, or null if not configured
Since:
MMBase-1.7

getStorageManager

public StorageManager getStorageManager()
                                 throws StorageException
Returns a StorageManager to access the storage.. Equal to getStorageManagerFactory().getStorageManager(). Note: in MMBase 1.7, this will throw a StorageException if the system uses the old support classes to access the storage.

Returns:
a StorageManager class
Throws:
StorageException - if no storage manasger could be instantiated
Since:
MMBase-1.7

castNode

public MMObjectNode castNode(MMObjectNode node)
Deprecated. Not necessary in most cases, with the possible exception of lists obtained from InsRel. However, in the later case using this method is probably too costly.

Loads a Node again, using its 'right' parent. Reloading may retrieve extra fields if the original node was not loaded accurately.


getAuthType

public java.lang.String getAuthType()
Retrieves the autorisation type. This value is set using the configuration file. Examples are 'none' or 'basic'.

Returns:
a String identifying the type

getLanguage

public java.lang.String getLanguage()
Retrieves the current language. This value is set using the configuration file. Examples are 'en' or 'nl'.

Returns:
the language as a String

getLocale

public java.util.Locale getLocale()
Retrieves the current locale.

Since:
MMBase-1.8

getEncoding

public java.lang.String getEncoding()
Retrieves the encoding. This value is set using the configuration file. Examples are 'UTF-8' (default) or 'ISO-8859-1'.

Returns:
the coding as a String
Since:
MMBase-1.6

getState

public boolean getState()
Retrieves whether this mmbase module is running.

Returns:
true if the module has been initialized and all builders loaded, false otherwise.

checkUserLevel

public void checkUserLevel()
Checks and switches the user/grouplevel in which MMBase runs. The userlevel is set using the -Dmmbase:userlevel=user:group commandline parameter. Should probably be changed to private.



MMBase build 1.7.1.20041002