org.mmbase.module.corebuilders
Class TypeDef

Package class diagram package TypeDef
java.lang.Object
  extended by org.mmbase.util.functions.FunctionProvider
      extended by org.mmbase.module.core.MMTable
          extended by org.mmbase.module.core.MMObjectBuilder
              extended by org.mmbase.module.corebuilders.TypeDef
All Implemented Interfaces:
EventListener, NodeEventListener, RelationEventListener

public class TypeDef
extends MMObjectBuilder

TypeDef is used to define the* object types (builders). Nodes of this builder have a virtual 'config' field. This field contains the xml-Document of the builder represented by the node. The filename used to reference the xml document is derived by extending the field 'name'. Creating a new typedef node automatically creates a new xml file and loads a new builder. Removing a node drops and unloads a builder (including the xml). Changes to the config will also be active on commit of the node.

Version:
$Id: TypeDef.java 45376 2011-02-23 13:28:21Z michiel $
Author:
Daniel Ockeloen, Pierre van Rooden

Field Summary
(package private)  String defaultDeploy
           
static String PROPERTY_DEPLOY_DIR
          The property in the builder file ('deploy-dir') that sets the directory where new builder configuration files are to be deployed.
 
Fields inherited from class org.mmbase.module.core.MMObjectBuilder
AGE_PARAMETERS, broadCastChanges, DEFAULT_ALINEA, DEFAULT_EOL, description, descriptions, EVENT_TYPE_LOCAL, EVENT_TYPE_REMOTE, FIELD_NUMBER, FIELD_OBJECT_TYPE, FIELD_OWNER, fields, genericBlobCache, getFunctionsFunction, GUI_INDICATOR, GUI_PARAMETERS, guiFunction, infoFunction, internalVersion, nodeCache, oType, pluralNames, searchAge, singularNames, SYSTEM_OWNER, TEMPNODE_DEFAULT_SIZE, TMP_FIELD_EXISTS, TMP_FIELD_NUMBER, virtual, WRAP_PARAMETERS, wrapFunction
 
Fields inherited from class org.mmbase.module.core.MMTable
maxNodesFromQuery, mmb, storageConnector, tableName
 
Fields inherited from class org.mmbase.util.functions.FunctionProvider
functions, getFunctions
 
Constructor Summary
TypeDef()
           
 
Method Summary
 boolean commit(MMObjectNode node)
          Commit changes to this node to the database.
protected  boolean deleteBuilderConfiguration(MMObjectNode node)
           
protected  Object executeFunction(MMObjectNode node, String function, List<?> args)
          Executes a function on the field of a node, and returns the result.
 boolean fieldLocalChanged(String number, String builder, String field, String value)
          Called when a local field is changed.
 MMObjectBuilder getBuilder(MMObjectNode node)
          Returns the MMObjectBuilder which is represented by the node.
protected  String getBuilderConfiguration(MMObjectNode node)
          Returns the path, where the builderfile can be found, for not exising builders, a path will be generated.
protected  String getBuilderPath(MMObjectNode node)
          Returns the path, where the builder configuration file can be found, for not exising builders, a path will be generated.
 String getGUIIndicator(MMObjectNode node)
          What should a GUI display for this node.
 int getIntValue(String builderName)
          Obtain the type value of the requested builder
 Vector<String> getList(PageInfo sp, StringTagger tagger, StringTokenizer tok)
          Obtains a list of string values by performing the provided command and parameters.
protected  String getLocaleGUIIndicator(Locale locale, MMObjectNode node)
          The GUIIndicator can depend on the locale.
protected  String getLocaleGUIIndicator(Locale locale, String field, MMObjectNode node)
          The GUIIndicator can depend on the locale.
protected  Map<String,Integer> getNameToNumberCache()
           
protected  Map<Integer,String> getNumberToNameCache()
           
 String getSingularName(String builderName, String language)
           
 String getValue(int type)
          Obtain the buildername of the requested type
 Object getValue(MMObjectNode node, String field)
          Provides additional functionality when obtaining field values.
 String getValue(String type)
          Deprecated. use getValue(int)
 boolean init()
          Sets the default deploy directory for the builders.
 int insert(String owner, MMObjectNode node)
          Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided).
 int insert(String owner, MMObjectNode node, boolean loadBuilder)
          Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided).
 boolean isRelationTable(String name)
           
protected  MMObjectBuilder loadBuilder(MMObjectNode node)
           
 void loadTypeDef(String name)
           
 boolean reloadBuilder(String objectname)
           
 void removeNode(MMObjectNode node)
          Remove a node from the cloud, when the represented builder was active it will also be unloaded
 boolean setValue(MMObjectNode node, String fieldName, Object originalValue)
          Sets a key/value pair in the main values of this node.
protected  void storeBuilderConfiguration(MMObjectNode node)
           
protected  MMObjectBuilder unloadBuilder(MMObjectNode node)
           
 void unloadTypeDef(String name)
           
 
Methods inherited from class org.mmbase.module.core.MMObjectBuilder
addEventListener, addField, addLocalObserver, addRemoteObserver, broadcastChanges, checkAddTmpField, clearBlobCache, create, createAlias, createAlias, createIfNotExists, delete, equals, equals, executeFunction, getAncestors, getBlobCache, getClassName, getConfigFile, getConfigResource, getDataTypeCollector, getDBState, getDBType, getDefaultTeaser, getDefaultUrl, getDescendants, getDescription, getDescription, getDescriptions, getEmptyNode, getField, getFieldNames, getFields, getFields, getFunction, getFunctionParameters, getFunctions, getGUIIndicator, getGUIIndicator, getHTML, getInitParameter, getInitParameters, getInitParameters, getInternalVersion, getMachineName, getMaintainer, getNewNode, getNewTmpNode, getNextField, getNextField, getNode, getNode, getNode, getNodeFromCache, getNodeGUIIndicator, getNumber, getObjectType, getObjectValue, getParentBuilder, getPluralName, getPluralName, getPluralNames, getRelations_main, getSearchAge, getShort, getShortedByte, getShortedInputStream, getShortedText, getSingularName, getSingularName, getSingularNames, getSmartPath, getTmpNode, getURLEncode, getVersion, getWAP, getXMLPath, hasField, hashCode, hashCode, hostname_function, insert, isExtensionOf, isNodeCached, isNull, isVirtual, loadInitParameters, newFunctionInstance, nodeLocalChanged, nodeRemoteChanged, notify, notify, preCommit, process, removeEventListener, removeField, removeLocalObserver, removeRelations, removeRemoteObserver, removeSyncNodes, replace, safeCache, sendFieldChangeSignal, setDefaults, setDescription, setDescriptions, setFields, setInitParameter, setMaintainer, setPluralNames, setSearchAge, setSingularNames, setUniqueValue, setUniqueValue, setValue, setVersion, setXMLPath, shutdown, testValidData, toString, toString, update, updateFields, wrap
 
Methods inherited from class org.mmbase.module.core.MMTable
count, count, created, getFullTableName, getMMBase, getNode, getNodes, getNodes, getNodes, getNodeType, getStorageConnector, getTableName, search, searchVector, setMMBase, setTableName, size
 
Methods inherited from class org.mmbase.util.functions.FunctionProvider
addFunction, createParameters, getFunction, getFunctions, getFunctionValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_DEPLOY_DIR

public static final String PROPERTY_DEPLOY_DIR
The property in the builder file ('deploy-dir') that sets the directory where new builder configuration files are to be deployed.

See Also:
Constant Field Values

defaultDeploy

String defaultDeploy
Constructor Detail

TypeDef

public TypeDef()
Method Detail

init

public boolean init()
Sets the default deploy directory for the builders.

Overrides:
init in class MMObjectBuilder
Returns:
true if init was completed, false if uncompleted.
See Also:
MMObjectBuilder.create()

getNumberToNameCache

protected Map<Integer,String> getNumberToNameCache()

getNameToNumberCache

protected Map<String,Integer> getNameToNumberCache()

insert

public int insert(String owner,
                  MMObjectNode node)
Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided). This method indirectly calls MMObjectBuilder.preCommit(org.mmbase.module.core.MMObjectNode). Asside from that, this method loads the builder this node represents, and initalizes it. If you do not wish to load the builder (i.e. because it is already loaded), use insert(String, MMObjectNode, boolean)

Overrides:
insert in class MMObjectBuilder
Parameters:
owner - The administrator creating the node
node - The object to insert. The object need be of the same type as the current builder.
Returns:
An int value which is the new object's unique number, -1 if the insert failed.

insert

public int insert(String owner,
                  MMObjectNode node,
                  boolean loadBuilder)
Insert a new object (content provided) in the cloud, including an entry for the object alias (if provided). This method indirectly calls MMObjectBuilder.preCommit(org.mmbase.module.core.MMObjectNode).

Parameters:
owner - The administrator creating the node
node - The object to insert. The object need be of the same type as the current builder.
loadBuilder - if true, the builder should be loaded. This method is set to false when it is called from the init() method of MMObjectBuilder to prevent it from being loaded twice
Returns:
An int value which is the new object's unique number, -1 if the insert failed.

commit

public boolean commit(MMObjectNode node)
Commit changes to this node to the database. This method indirectly calls MMObjectBuilder.preCommit(org.mmbase.module.core.MMObjectNode). Use only to commit changes - for adding node, use insert(java.lang.String, org.mmbase.module.core.MMObjectNode).

Overrides:
commit in class MMObjectBuilder
Parameters:
node - The node to be committed
Returns:
true if commit successful

removeNode

public void removeNode(MMObjectNode node)
Remove a node from the cloud, when the represented builder was active it will also be unloaded

Overrides:
removeNode in class MMObjectBuilder
Parameters:
node - The node to remove.
Throws:
RuntimeException - When the operation could not be performed

getIntValue

public int getIntValue(String builderName)
Obtain the type value of the requested builder

Parameters:
builderName - name of the builder
Returns:
the object type as an int, -1 if not defined.
To Do:
smarter cache update

getValue

public String getValue(int type)
Obtain the buildername of the requested type

Parameters:
type - the object type
Returns:
the name of the builder as a string, null if not found

getValue

public String getValue(String type)
Deprecated. use getValue(int)

Obtain the buildername of the requested type

Parameters:
type - the object type
Returns:
the name of the builder as a string, "unknown" if not found

getSingularName

public String getSingularName(String builderName,
                              String language)
Javadoc:

isRelationTable

public boolean isRelationTable(String name)
Javadoc:

getValue

public Object getValue(MMObjectNode node,
                       String field)
Provides additional functionality when obtaining field values. This method is called whenever a Node of the builder's type fails at evaluating a getValue() request (generally when a fieldname is supplied that doesn't exist). It allows the system to add 'functions' to be included with a field name, such as 'html(body)' or 'time(lastmodified)'. This method will parse the fieldname, determining functions and calling the executeFunction(org.mmbase.module.core.MMObjectNode, java.lang.String, java.util.List) method to handle it. Functions in fieldnames can be given in the format 'functionname(fieldname)'. An old format allows 'functionname_fieldname' instead, though this only applies to the text functions 'short', 'html', and 'wap'. Functions can be nested, i.e. 'html(shorted(body))'. Derived builders should override this method only if they want to provide virtual fieldnames. To provide addiitonal functions, override executeFunction(org.mmbase.module.core.MMObjectNode, java.lang.String, java.util.List) instead.

Overrides:
getValue in class MMObjectBuilder
Parameters:
node - the node whos efields are queries
field - the fieldname that is requested
Returns:
the result of the 'function', or null if no valid functions could be determined.

setValue

public boolean setValue(MMObjectNode node,
                        String fieldName,
                        Object originalValue)
Sets a key/value pair in the main values of this node. Note that if this node is a node in cache, the changes are immediately visible to everyone, even if the changes are not committed. The fieldname is added to the (public) 'changed' vector to track changes.

Overrides:
setValue in class MMObjectBuilder
Parameters:
node -
fieldName - the name of the field to change
originalValue - the value which was original in the field
Returns:
true When an update is required(when changed), false if original value was set back into the field.

fieldLocalChanged

public boolean fieldLocalChanged(String number,
                                 String builder,
                                 String field,
                                 String value)
Description copied from class: MMObjectBuilder
Called when a local field is changed.

Overrides:
fieldLocalChanged in class MMObjectBuilder
Parameters:
number - Number of the changed node as a String
builder - type of the changed node
field - name of the changed field
value - value it changed to
Returns:
always true
Javadoc:

getBuilderConfiguration

protected String getBuilderConfiguration(MMObjectNode node)
Returns the path, where the builderfile can be found, for not exising builders, a path will be generated.

Parameters:
node - The node, from which we want to know it;s MMObjectBuilder
Returns:
The path where the builder should live or null in case of strange failures When the builder was not loaded.
Since:
MMBase-1.8

getBuilder

public MMObjectBuilder getBuilder(MMObjectNode node)
Returns the MMObjectBuilder which is represented by the node.

Parameters:
node - The node, from which we want to know its MMObjectBuilder
Returns:
The builder which is represented by the node, or null if the builder was not loaded.

reloadBuilder

public boolean reloadBuilder(String objectname)
Javadoc:

getGUIIndicator

public String getGUIIndicator(MMObjectNode node)
What should a GUI display for this node. This method returns the gui name (singular name) of the builder that goes with this node.

Overrides:
getGUIIndicator in class MMObjectBuilder
Parameters:
node - The node to display
Returns:
the display of the node as a String

getLocaleGUIIndicator

protected String getLocaleGUIIndicator(Locale locale,
                                       String field,
                                       MMObjectNode node)
The GUIIndicator can depend on the locale. Override this function

Overrides:
getLocaleGUIIndicator in class MMObjectBuilder
Since:
MMBase-1.6

getLocaleGUIIndicator

protected String getLocaleGUIIndicator(Locale locale,
                                       MMObjectNode node)
Description copied from class: MMObjectBuilder
The GUIIndicator can depend on the locale. Override this function You may want to override MMObjectBuilder.getNodeGUIIndicator(MMObjectNode, org.mmbase.util.functions.Parameters) for more flexibility.

Overrides:
getLocaleGUIIndicator in class MMObjectBuilder

loadTypeDef

public void loadTypeDef(String name)
Javadoc:

unloadTypeDef

public void unloadTypeDef(String name)
Javadoc:

getList

public Vector<String> getList(PageInfo sp,
                              StringTagger tagger,
                              StringTokenizer tok)
Description copied from class: MMObjectBuilder
Obtains a list of string values by performing the provided command and parameters. This method is SCAN related and may fail if called outside the context of the SCAN servlet.

Overrides:
getList in class MMObjectBuilder
Parameters:
sp - The PageInfo (containing http and user info) that calls the function
tagger - a Hashtable of parameters (name-value pairs) for the command
tok - a list of strings that describe the (sub)command to execute
Returns:
a Vector containing the result values as a String
Javadoc:

executeFunction

protected Object executeFunction(MMObjectNode node,
                                 String function,
                                 List<?> args)
Description copied from class: MMObjectBuilder
Executes a function on the field of a node, and returns the result. This method is called by the builder's MMObjectBuilder.getValue(MMObjectNode, String) method. Derived builders should override this method to provide additional functions.

Overrides:
executeFunction in class MMObjectBuilder
See Also:
MMObjectBuilder.executeFunction(MMObjectNode, String, java.util.List)

getBuilderPath

protected String getBuilderPath(MMObjectNode node)
Returns the path, where the builder configuration file can be found, for not exising builders, a path will be generated.

Parameters:
node - The node, from which we want to know it;s MMObjectBuilder
Returns:
The path where the builder should live or null in case of strange failures When the builder was not loaded.

loadBuilder

protected MMObjectBuilder loadBuilder(MMObjectNode node)

storeBuilderConfiguration

protected void storeBuilderConfiguration(MMObjectNode node)
                                  throws IOException
Throws:
IOException

unloadBuilder

protected MMObjectBuilder unloadBuilder(MMObjectNode node)

deleteBuilderConfiguration

protected boolean deleteBuilderConfiguration(MMObjectNode node)


MMBase2 Core 2.0-SNAPSHOT - 2013-03-30T06:36