org.mmbase.module.core
Class MMObjectNode

java.lang.Object
  |
  +--org.mmbase.module.core.MMObjectNode
Direct Known Subclasses:
VirtualNode

public class MMObjectNode
extends java.lang.Object

MMObjectNode is the core of the MMBase system. This class is what its all about, because the instances of this class hold the content we are using. All active Nodes with data and relations are MMObjectNodes and make up the object world that is MMBase (Creating, searching, removing is done by the node's parent, which is a class extended from MMObjectBuilder)

Version:
11 May 2001
Author:
Daniel Ockeloen, Pierre van Rooden

Field Summary
protected  java.lang.String alias
          Alias name of this node.
 java.util.Vector changed
          Vector whcih stores the key's of the fields that were changed since the last commit.
 MMObjectBuilder parent
          Pointer to the parent builder that is responsible for this node.
 java.lang.String prefix
          Used to make fields from multiple nodes (for multilevel for example) possible.
 java.util.Hashtable properties
          Holds the 'extra' name-value pairs (the node's properties) which are retrieved from the 'properties' table.
 java.util.Hashtable values
          Holds the name - value pairs of this node (the node's fields).
protected  boolean virtual
          Deternmines whether this node is virtual.
 
Constructor Summary
MMObjectNode()
          Deprecated. Unused. Should be removed.
MMObjectNode(MMObjectBuilder parent)
          Main constructor.
 
Method Summary
 boolean clearChanged()
          Clear the 'signal' Vector with the changed keys since last commit/insert.
 boolean commit()
          Commit the node to the database or other storage system.
 void delPropertiesCache()
          Deletes the propertie cache for this node.
 void delRelationsCache()
          Delete the relation cache for this node.
 int getAge()
          Returns the node's age
 java.lang.String getAlias()
          Returns the node's alias.
 java.util.Enumeration getAllRelations()
          Return all the relations of this node.
 boolean getBooleanValue(java.lang.String fieldname)
          Get a value of a certain field.
 byte[] getByteValue(java.lang.String fieldname)
          Get a binary value of a certain field.
 java.util.Vector getChanged()
          Return all the names of fields that were changed.
 int getDBState(java.lang.String fieldname)
          Returns the DBState of a field.
 int getDBType(java.lang.String fieldname)
          Returns the DBType of a field.
 double getDoubleValue(java.lang.String fieldname)
          Get a value of a certain field.
 java.lang.String getDutchSName()
          Return the Single name for this node in the currently selected language (accoridng to the configuration).
 float getFloatValue(java.lang.String fieldname)
          Get a value of a certain field.
 java.lang.String getGUIIndicator()
          Return the GUI indicator for this node.
 java.lang.Integer getIntegerValue(java.lang.String fieldname)
          Get a value of a certain field.
 int getIntValue(java.lang.String fieldname)
          Get a value of a certain field.
 long getLongValue(java.lang.String fieldname)
          Get a value of a certain field.
 java.lang.String getName()
          Return the buildername of this node
 MMObjectNode getNodeValue(java.lang.String fieldname)
          Get a value of a certain field.
 int getNumber()
          Retrieve an object's number.
 int getOType()
          Retrieve an object's object type.
 java.util.Hashtable getProperties()
          Return a the properties for this node.
 MMObjectNode getProperty(java.lang.String key)
          Returns a specified property of this node.
 java.util.Vector getRelatedNodes()
          Get all related nodes.
 java.util.Vector getRelatedNodes(java.lang.String type)
          Get the related nodes of a certain type.
static int getRelationCacheHits()
           
static int getRelationCacheMiss()
           
 int getRelationCount()
          Returns the number of relations of this node.
 int getRelationCount(java.lang.String wantedtype)
          Return the number of relations of this node, filtered on a specified type.
 java.util.Enumeration getRelations()
          Return the relations of this node.
 java.util.Enumeration getRelations(int otype)
          Return the relations of this node, filtered on a specified type.
 java.util.Enumeration getRelations(java.lang.String wantedtype)
          Return the relations of this node, filtered on a specified type.
 java.lang.String getStringValue(java.lang.String fieldname)
          Get a value of a certain field.
 java.lang.String getTableName()
          Deprecated. use getName instead
 java.lang.Object getValue(java.lang.String fieldname)
          Get a value of a certain field.
 java.lang.String getValueAsString(java.lang.String fieldName)
          Deprecated. use getStringValue(java.lang.String) instead.
 java.util.Hashtable getValues()
          Return the values of this node as a hashtable (name-value pair).
 boolean hasRelations()
          Returns whether this node has relations.
 int insert(java.lang.String userName)
          Insert this node into the database or other storage system.
 int insertDone(EditState ed)
          Deprecated. This method doesn't seem to fit here, as it references a gui/html object (EditState), endangering the separation between content and layout, and has an undefined return value.
 boolean isChanged()
          Tests whether one of the values of this node was changed since the last commit/insert.
 boolean isVirtual()
          Determines whether the node is virtual.
 int preEdit(EditState ed)
          Deprecated. This method doesn't seem to fit here, as it references a gui/html object (EditState), endangering the separation between content and layout. It also has an undefined return value (as well as a confusing name).
 void putProperty(MMObjectNode node)
          Sets a specified property for this node.
 void removeRelations()
          Remove the relations of the node.
protected  java.lang.Object retrieveValue(java.lang.String fieldname)
          Retrieves a value from the values hashtable.
 boolean sendFieldChangeSignal(java.lang.String fieldname)
          Sends a field-changed signal.
 void setAlias(java.lang.String alias)
          Sets the node's alias.
 void setParent(MMObjectBuilder bul)
          Deprecated. Unused. Should be removed.
 boolean setValue(java.lang.String fieldname, boolean fieldvalue)
          Sets a key/value pair in the main values of this node.
 boolean setValue(java.lang.String fieldname, double fieldvalue)
          Sets a key/value pair in the main values of this node.
 boolean setValue(java.lang.String fieldname, int fieldvalue)
          Sets a key/value pair in the main values of this node.
 boolean setValue(java.lang.String fieldName, int type, java.lang.String value)
          Sets a key/value pair in the main values of this node.
 boolean setValue(java.lang.String fieldname, java.lang.Object fieldvalue)
          Sets a key/value pair in the main values of this node.
protected  void storeValue(java.lang.String fieldname, java.lang.Object fieldvalue)
          Stores a value in the values hashtable.
 void testValidData()
          Tests whether the data in a node is valid (throws an exception if this is not the case).
 java.lang.String toString()
          Returns the core of this node in a string.
 java.lang.String toXML()
          Return the node as a string in XML format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

values

public java.util.Hashtable values
Holds the name - value pairs of this node (the node's fields). Most nodes will have a 'number' and an 'otype' field, and fields which will differ by builder. This collection should not be directly queried or changed - use the SetValue and getXXXValue methods instead. (question: so why is this public?)

properties

public java.util.Hashtable properties
Holds the 'extra' name-value pairs (the node's properties) which are retrieved from the 'properties' table.

changed

public java.util.Vector changed
Vector whcih stores the key's of the fields that were changed since the last commit.

parent

public MMObjectBuilder parent
Pointer to the parent builder that is responsible for this node.

prefix

public java.lang.String prefix
Used to make fields from multiple nodes (for multilevel for example) possible. This is a 'default' value. XXX: specifying the prefix in the fieldname SHOULD override this field.

virtual

protected boolean virtual
Deternmines whether this node is virtual. A virtual node is not persistent (that is, not stored in a table).

alias

protected java.lang.String alias
Alias name of this node. XXX: nodes can have multiple aliases.
Constructor Detail

MMObjectNode

public MMObjectNode()
Deprecated. Unused. Should be removed.

Empty constructor added for javadoc

MMObjectNode

public MMObjectNode(MMObjectBuilder parent)
Main constructor.
Parameters:
parent - the node's parent, an instance of the node's builder.
Method Detail

testValidData

public void testValidData()
                   throws InvalidDataException
Tests whether the data in a node is valid (throws an exception if this is not the case).
Throws:
InvalidDataException - If the data was unrecoverably invalid (the references did not point to existing objects)

commit

public boolean commit()
Commit the node to the database or other storage system. This can only be done on a existing (inserted) node. It will use the changed Vector as its base of what to commit/change.
Returns:
true if the commit was succesfull, false is it failed

insert

public int insert(java.lang.String userName)
Insert this node into the database or other storage system.
Returns:
the new node key (number field), or -1 if the insert failed

insertDone

public int insertDone(EditState ed)
Deprecated. This method doesn't seem to fit here, as it references a gui/html object (EditState), endangering the separation between content and layout, and has an undefined return value.

Once an insert is done in the editors, this method is called.
Parameters:
ed - Contains the current edit state (editor info). The main function of this object is to pass 'settings' and 'parameters' - value pairs that have been set during the edit process.
Returns:
An int value. It's meaning is undefined. The basic routine returns -1.

preEdit

public int preEdit(EditState ed)
Deprecated. This method doesn't seem to fit here, as it references a gui/html object (EditState), endangering the separation between content and layout. It also has an undefined return value (as well as a confusing name).

Check and make last changes before calling commit() or insert(java.lang.String). This method is called by the editor. This differs from MMObjectBuilder.preCommit(org.mmbase.module.core.MMObjectNode), which is called by the database system during the call to commit or insert.
Parameters:
ed - Contains the current edit state (editor info). The main function of this object is to pass 'settings' and 'parameters' - value pairs that have been the during the edit process.
Returns:
An int value. It's meaning is undefined. The basic routine returns -1.

toString

public java.lang.String toString()
Returns the core of this node in a string. Used for debugging. For data exchange use toXML() and getDTD().
Overrides:
toString in class java.lang.Object
Returns:
the contents of the node as a string.

toXML

public java.lang.String toXML()
Return the node as a string in XML format. Used for data exchange, though, oddly enough, not by application export. (?)
Returns:
the contents of the node as a xml-formatted string.

storeValue

protected void storeValue(java.lang.String fieldname,
                          java.lang.Object fieldvalue)
Stores a value in the values hashtable.
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign

retrieveValue

protected java.lang.Object retrieveValue(java.lang.String fieldname)
Retrieves a value from the values hashtable.
Parameters:
fieldname - the name of the field to change
Returns:
the value of the field

isVirtual

public boolean isVirtual()
Determines whether the node is virtual. A virtual node is not persistent (that is, stored in a database table).

setValue

public boolean setValue(java.lang.String fieldname,
                        java.lang.Object fieldvalue)
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.
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign
Returns:
always true

setValue

public boolean setValue(java.lang.String fieldname,
                        boolean fieldvalue)
Sets a key/value pair in the main values of this node. The value to set is of type boolean. 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.
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign
Returns:
always true

setValue

public boolean setValue(java.lang.String fieldname,
                        int fieldvalue)
Sets a key/value pair in the main values of this node. The value to set is of type int. 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.
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign
Returns:
always true

setValue

public boolean setValue(java.lang.String fieldname,
                        double fieldvalue)
Sets a key/value pair in the main values of this node. The value to set is of type double. 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.
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign
Returns:
always true

setValue

public boolean setValue(java.lang.String fieldName,
                        int type,
                        java.lang.String value)
Sets a key/value pair in the main values of this node. The value to set is converted to the indicated type. 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.
Parameters:
fieldname - the name of the field to change
fieldValue - the value to assign
Returns:
false if the value is not of the indicated type, true otherwise

getNumber

public int getNumber()
Retrieve an object's number. In case of a new node that is not committed, this will return -1.
Returns:
the number of the node

getOType

public int getOType()
Retrieve an object's object type. This is a number (an index in the typedef builer), rather than a name.
Returns:
the object type number of the node

getValue

public java.lang.Object getValue(java.lang.String fieldname)
Get a value of a certain field.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an Object

getStringValue

public java.lang.String getStringValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as a String. Non-string values are automatically converted to String.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as a String

getByteValue

public byte[] getByteValue(java.lang.String fieldname)
Get a binary value of a certain field.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an byte [] (binary/blob field)

getNodeValue

public MMObjectNode getNodeValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as an MMObjectNode. If the field contains an Numeric value, the method tries to obtrain the object with that number. If it is a String, the method tries to obtain the object with that alias. The only other possible values are those created by certain virtual fields. All remaining situations return null.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an int

getIntValue

public int getIntValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as an int value. Values of non-int, numeric fields are converted if possible. Booelan fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. If a value is an MMObjectNode, it's numberfield is returned. All remaining field values return -1.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an int

getBooleanValue

public boolean getBooleanValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as an boolean value. If the actual value is numeric, this call returns true if the value is a positive, non-zero, value. In other words, values '0' and '-1' are concidered false. If the value is a string, this call returns true if the value is "true" or "yes" (case-insensitive). In all other cases (including calling byte fields), false is returned. Note that there is currently no basic MMBase boolean type, but some excecuteFunction calls may return a Boolean result.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an int

getIntegerValue

public java.lang.Integer getIntegerValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as an Integer value. Values of non-Integer, numeric fields are converted if possible. Booelan fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as an Integer

getLongValue

public long getLongValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as a long value. Values of non-long, numeric fields are converted if possible. Booelan fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as a long

getFloatValue

public float getFloatValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as a float value. Values of non-float, numeric fields are converted if possible. Booelan fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as a float

getDoubleValue

public double getDoubleValue(java.lang.String fieldname)
Get a value of a certain field. The value is returned as a double value. Values of non-double, numeric fields are converted if possible. Booelan fields return 0 for false, 1 for true. String fields are parsed to a number, if possible. All remaining field values return -1.
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as a double

getValueAsString

public java.lang.String getValueAsString(java.lang.String fieldName)
Deprecated. use getStringValue(java.lang.String) instead.

Get a value of a certain field and return is in string form (regardless of actual type).
Parameters:
fieldname - the name of the field who's data to return
Returns:
the field's value as a String

getDBType

public int getDBType(java.lang.String fieldname)
Returns the DBType of a field.
Parameters:
fieldname - the name of the field who's type to return
Returns:
the field's DBType

getDBState

public int getDBState(java.lang.String fieldname)
Returns the DBState of a field.
Parameters:
fieldname - the name of the field who's state to return
Returns:
the field's DBState

getChanged

public java.util.Vector getChanged()
Return all the names of fields that were changed. Note that this is a direct reference. Changes (i.e. clearing the vector) will affect the node's status.
Parameters:
a - Vector containing all the fieldnames

isChanged

public boolean isChanged()
Tests whether one of the values of this node was changed since the last commit/insert.
Returns:
true if changes have been made, false otherwise

clearChanged

public boolean clearChanged()
Clear the 'signal' Vector with the changed keys since last commit/insert. Marks the node as 'unchanged'. Does not affect the values of the fields, nor does it commit the node.
Returns:
always true

getValues

public java.util.Hashtable getValues()
Return the values of this node as a hashtable (name-value pair). Note that this is a direct reference. Changes will affect the node. Used by various export routines.
Returns:
the values as a Hashtable

delPropertiesCache

public void delPropertiesCache()
Deletes the propertie cache for this node. Forces a reload of the properties on next use.

getProperties

public java.util.Hashtable getProperties()
Return a the properties for this node.
Returns:
the properties as a Hashtable

getProperty

public MMObjectNode getProperty(java.lang.String key)
Returns a specified property of this node.
Parameters:
key - the name of the property to retrieve
Returns:
the property object as a MMObjectNode

putProperty

public void putProperty(MMObjectNode node)
Sets a specified property for this node. This method does not commit anything - it merely updates the node's propertylist.
Parameters:
node - the property object as a MMObjectNode

getGUIIndicator

public java.lang.String getGUIIndicator()
Return the GUI indicator for this node. The GUI indicator is a string that represents the contents of this node. By default it is the string-representation of the first non-system field of the node. Individual builders can alter this behavior.
Returns:
the GUI iddicator as a String

getDutchSName

public java.lang.String getDutchSName()
Return the Single name for this node in the currently selected language (accoridng to the configuration). The 'dutch' in the method name is a bit misleading.
Returns:
the String value

getName

public java.lang.String getName()
Return the buildername of this node
Returns:
the builder table name

setParent

public void setParent(MMObjectBuilder bul)
Deprecated. Unused. Should be removed.

Set the parent builder for this node.
Parameters:
bul - the builder

delRelationsCache

public void delRelationsCache()
Delete the relation cache for this node. This means it will be reloaded from the database/storage on next use.

hasRelations

public boolean hasRelations()
Returns whether this node has relations. This includes unidirection relations which would otherwise not be counted.
Returns:
true if any relations exist, false otherwise.

getAllRelations

public java.util.Enumeration getAllRelations()
Return all the relations of this node. Use only to delete the relations of a node. Note that this returns the nodes describing the relation - not the nodes 'related to'.
Returns:
An Enumeration containing the nodes

getRelations

public java.util.Enumeration getRelations()
Return the relations of this node. Note that this returns the nodes describing the relation - not the nodes 'related to'.
Returns:
An Enumeration containing the nodes

removeRelations

public void removeRelations()
Remove the relations of the node.

getRelationCount

public int getRelationCount()
Returns the number of relations of this node.
Returns:
An int indicating the number of nodes found

getRelations

public java.util.Enumeration getRelations(int otype)
Return the relations of this node, filtered on a specified type. Note that this returns the nodes describing the relation - not the nodes 'related to'.
Parameters:
otype - the 'type' of relations to return. The type identifies a relation (InsRel-derived) builder, not a reldef object.
Returns:
An Enumeration containing the nodes

getRelations

public java.util.Enumeration getRelations(java.lang.String wantedtype)
Return the relations of this node, filtered on a specified type. Note that this returns the nodes describing the relation - not the nodes 'related to'.
Parameters:
wantedtype - the 'type' of relations to return. The type identifies a relation (InsRel-derived) builder, not a reldef object.
Returns:
An Enumeration containing the nodes

getRelationCount

public int getRelationCount(java.lang.String wantedtype)
Return the number of relations of this node, filtered on a specified type.
Parameters:
wantedtype - the 'type' of related nodes (NOT the relations!).
Returns:
An int indicating the number of nodes found

getAge

public int getAge()
Returns the node's age
Returns:
the age in days

getTableName

public java.lang.String getTableName()
Deprecated. use getName instead

Returns the node's builder tablename.
Returns:
the tablename of the builder as a String

sendFieldChangeSignal

public boolean sendFieldChangeSignal(java.lang.String fieldname)
Sends a field-changed signal.
Parameters:
fieldname - the name of the changed field.
Returns:
always true

setAlias

public void setAlias(java.lang.String alias)
Sets the node's alias. The code only sets a (memory) property, it does not actually add the alias to the database. Does not support multiple aliases.

getAlias

public java.lang.String getAlias()
Returns the node's alias. Does not support multiple aliases.
Returns:
the alias as a String

getRelatedNodes

public java.util.Vector getRelatedNodes()
Get all related nodes. The returned nodes are not the nodes directly attached to this node (the relation nodes) but the nodes attached to the relation nodes of this node.
Returns:
a Vector containing MMObjectNodes

getRelatedNodes

public java.util.Vector getRelatedNodes(java.lang.String type)
Get the related nodes of a certain type. The returned nodes are not the nodes directly attached to this node (the relation nodes) but the nodes attached to the relation nodes of this node.
Parameters:
type - the type of objects to be returned
Returns:
a Vector containing MMObjectNodes

getRelationCacheHits

public static int getRelationCacheHits()

getRelationCacheMiss

public static int getRelationCacheMiss()


MMBase 2001