org.mmbase.bridge.implementation
Class BasicNode

java.lang.Object
  extended byorg.mmbase.bridge.util.AbstractNode
      extended byorg.mmbase.bridge.implementation.BasicNode
All Implemented Interfaces:
Comparable, Node, SizeMeasurable
Direct Known Subclasses:
BasicNodeManager, BasicRelation

public class BasicNode
extends AbstractNode
implements Node, Comparable, SizeMeasurable

Basic implementation of Node. Wraps MMObjectNodes, adds security.

Version:
$Id: BasicNode.java,v 1.204 2006/07/14 18:55:14 nklasens Exp $
Author:
Rob Vermeulen, Pierre van Rooden, Michiel Meeuwissen
See Also:
Node, MMObjectNode

Field Summary
protected  BasicCloud cloud
          Reference to the Cloud.
protected  BasicNodeManager nodeManager
          Reference to the NodeManager
protected  MMObjectNode noderef
          Reference to actual MMObjectNode object.
 
Fields inherited from class org.mmbase.bridge.util.AbstractNode
ACTION_COMMIT, ACTION_CREATE, ACTION_DELETE, ACTION_EDIT
 
Method Summary
 void cancel()
          Cancel changes to a node This fails if the current node is not in edit mode.
 void commit()
          Commit the node to the database.
 int countRelatedNodes(NodeManager otherNodeManager, String role, String direction)
           
 int countRelatedNodes(String type)
          Returns the number of related nodes that have a specific node manager.
 void createAlias(String aliasName)
          Create an alias for this node.
protected  FieldValue createFunctionValue(Object result)
           
 Parameters createParameters(String functionName)
          Creates a parameter list for a function.
 void delete(boolean deleteRelations)
          Removes the Node.
 void deleteAlias(String aliasName)
          Delete an alias for this node.
 void deleteRelations(String type)
          Removes all relation nodes with a certain relation manager that are attached to this node.
protected  void edit(int action)
          Edit this node.
protected  void finalize()
          Reverse the buffers, when changed and not stored...
 StringList getAliases()
          Returns all aliases for this node.
 boolean getBooleanValue(String fieldName)
          Returns the value of the specified field as a boolean.
 int getByteSize()
          Determines the byte-size of this object
 int getByteSize(SizeOf sizeof)
          Determines the byte-size of this object using the given SizeOf instance.
 byte[] getByteValue(String fieldName)
          Returns the value of the specified field as a byte array.
 Set getChanged()
          A Set of Strings containing the names of all changed fields.
 Cloud getCloud()
          Returns the cloud this node belongs to.
 String getContext()
          Get the security context of the current Node
 Date getDateValue(String fieldName)
           
 double getDoubleValue(String fieldName)
          Returns the value of the specified field as a double.
 float getFloatValue(String fieldName)
          Returns the value of the specified field as a float.
 Collection getFunctions()
          Returns all the Function objects of this Node
 InputStream getInputStreamValue(String fieldName)
          Returns the value of the specified field as a java.io.InputStream This is especially usefull for large byte-array fields.
 int getIntValue(String fieldName)
          Returns the value of the specified field as an int.
 List getListValue(String fieldName)
           
 long getLongValue(String fieldName)
          Returns the value of the specified field as a long.
protected  MMObjectNode getNode()
          Obtains a reference to the underlying MMObjectNode.
protected  Function getNodeFunction(String functionName)
           
 NodeManager getNodeManager()
          Returns the node manager for this node.
 Node getNodeValue(String fieldName)
          Returns the value of the specified field as a Node.
 int getNumber()
          Returns the unique number for this node.
 StringList getPossibleContexts()
          Contacts the security implementation to find out to which other possible contexts the context of this node may be set.
 NodeList getRelatedNodes(NodeManager nodeManager, String role, String searchDir)
          Returns all related nodes that have a specific node manager and role.
 RelationList getRelations(String role, NodeManager nodeManager, String searchDir)
          Returns a list of relations of the given node.
 RelationList getRelations(String role, String nodeManager)
          Returns all relation nodes attached to this node that have a specific role, or refer a node from a specific nodemanager
 long getSize(String fieldName)
          Returns the 'size' (e.g.
 String getStringValue(String fieldName)
          Returns the value of the specified field as a String.
 Object getValueWithoutProcess(String fieldName)
          Like getObjectValue, but skips any processing that MMBase would normally perform on a field.
 Document getXMLValue(String fieldName)
          Returns the value of the specified field as a dom.Document If the node value is not itself a Document, the method attempts to attempts to convert the String value into an XML.
 int hashCode()
           
 boolean hasRelations()
          Checks whether this node has any relations.
protected  void init()
          Initializes state in case of a transaction.
protected  void invalidateNode()
          Invalidates the reference to the underlying MMObjectNode, replacing it with a virtual node that only inherits the number field.
 boolean isChanged()
          Whether field values were changed since the last commit.
 boolean isChanged(String fieldName)
          Whether a certain field's value was changed since the last commit.
 boolean isNew()
          Returns whether this is a new (not yet committed) node.
 boolean isNull(String fieldName)
          Whether the value for the speficied field is null.
 boolean mayChangeContext()
          Check context-change rights on this node.
 boolean mayDelete()
          Check delete rights on this node.
 boolean mayWrite()
          Check write rights on this node.
 void setContext(String context)
          Sets the security context of this Node (AKA the 'owner' field)
protected  void setNode(MMObjectNode n)
          Sets the reference to the underlying MMObjectNode.
protected  void setNodeManager(MMObjectNode node)
           
protected  void setSize(String fieldName, long size)
           
protected  void setValueWithoutChecks(String fieldName, Object value)
          Protected method to be able to set rnumber when creating a relation.
protected  Integer toNodeNumber(Object v)
          A method to convert an object to an node number.
 String toString()
          Converts the node to a string
 
Methods inherited from class org.mmbase.bridge.util.AbstractNode
compareTo, countRelations, countRelations, createRelation, delete, deleteRelations, equals, getFieldValue, getFieldValue, getFunction, getFunctionValue, getObjectValue, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getValue, getXMLValue, isNodeManager, isRelation, isRelationManager, processCommit, setBooleanValue, setByteValue, setDateValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeValue, setObjectValue, setStringValue, setValue, setValueWithoutProcess, setXMLValue, toNodeManager, toRelation, toRelationManager, validate
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.bridge.Node
countRelations, countRelations, createRelation, delete, deleteRelations, getFieldValue, getFieldValue, getFunction, getFunctionValue, getObjectValue, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getValue, getXMLValue, isNodeManager, isRelation, isRelationManager, setBooleanValue, setByteValue, setDateValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeValue, setObjectValue, setStringValue, setValue, setValueWithoutProcess, setXMLValue, toNodeManager, toRelation, toRelationManager, validate
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

nodeManager

protected BasicNodeManager nodeManager
Reference to the NodeManager


cloud

protected final BasicCloud cloud
Reference to the Cloud.


noderef

protected MMObjectNode noderef
Reference to actual MMObjectNode object.

Method Detail

setNodeManager

protected void setNodeManager(MMObjectNode node)
Since:
MMBase-1.8

init

protected void init()
Initializes state in case of a transaction.


getByteSize

public int getByteSize()
Description copied from interface: SizeMeasurable
Determines the byte-size of this object

Specified by:
getByteSize in interface SizeMeasurable

getByteSize

public int getByteSize(SizeOf sizeof)
Description copied from interface: SizeMeasurable
Determines the byte-size of this object using the given SizeOf instance. A SizeOf instance stores a Set already counted objects. So this method is typically called by SizeOf itself (recursion).

Specified by:
getByteSize in interface SizeMeasurable

getNode

protected final MMObjectNode getNode()
Obtains a reference to the underlying MMObjectNode. If the underlying node was deleted, this returns a virtual node with no info except the (original) node number.

Returns:
the underlying MMObjectNode
Throws:
NotFoundException - if no node was specified.

invalidateNode

protected void invalidateNode()
Invalidates the reference to the underlying MMObjectNode, replacing it with a virtual node that only inherits the number field.

Since:
MMBase-1.6.4

setNode

protected void setNode(MMObjectNode n)
Sets the reference to the underlying MMObjectNode.

Parameters:
n - the node to set a reference to.
Throws:
IllegalArgumentException - is n is null
Since:
MMBase-1.6.4

getCloud

public Cloud getCloud()
Description copied from interface: Node
Returns the cloud this node belongs to.

Specified by:
getCloud in interface Node
Returns:
the Cloud

getNodeManager

public NodeManager getNodeManager()
Description copied from interface: Node
Returns the node manager for this node.

Specified by:
getNodeManager in interface Node
Returns:
the node manager

getNumber

public int getNumber()
Description copied from interface: Node
Returns the unique number for this node. Every node has a unique number which can be used to refer to it. In addition to this number a node can have one or more aliases. A value of -1 indicates an invalid number. Other negative values may be used for temporary ids (but not true node numbers). This may differ by implementation.

Specified by:
getNumber in interface Node
Overrides:
getNumber in class AbstractNode

isNew

public boolean isNew()
Returns whether this is a new (not yet committed) node.

Specified by:
isNew in interface Node
Overrides:
isNew in class AbstractNode
Returns:
is a new node

isChanged

public boolean isChanged(String fieldName)
Description copied from interface: Node
Whether a certain field's value was changed since the last commit.

Specified by:
isChanged in interface Node
Overrides:
isChanged in class AbstractNode

isChanged

public boolean isChanged()
Description copied from interface: Node
Whether field values were changed since the last commit.

Specified by:
isChanged in interface Node
Overrides:
isChanged in class AbstractNode

getChanged

public Set getChanged()
Description copied from interface: Node
A Set of Strings containing the names of all changed fields.

Specified by:
getChanged in interface Node
Overrides:
getChanged in class AbstractNode

edit

protected void edit(int action)
Edit this node. Check whether edits are allowed and prepare a node for edits if needed. The type of edit is determined by the action specified, and one of:
ACTION_CREATE (create a node),
ACTION_EDIT (edit node, or change aliasses),
ACTION_DELETE (delete node),
ACTION_COMMIT (commit a node after changes)

Specified by:
edit in class AbstractNode
Parameters:
action - The action to perform.

setValueWithoutChecks

protected void setValueWithoutChecks(String fieldName,
                                     Object value)
Protected method to be able to set rnumber when creating a relation.

Specified by:
setValueWithoutChecks in class AbstractNode
Parameters:
fieldName - name of field
value - new value of field
Since:
MMBase-1.7

toNodeNumber

protected Integer toNodeNumber(Object v)
Description copied from class: AbstractNode
A method to convert an object to an node number. Default impelmentation is reasonable, but does not support core objects.

Overrides:
toNodeNumber in class AbstractNode

setSize

protected void setSize(String fieldName,
                       long size)
Specified by:
setSize in class AbstractNode

isNull

public boolean isNull(String fieldName)
Description copied from interface: Node
Whether the value for the speficied field is null. This avoids acquiring the complete value if you only want to check if for emptyness.

Specified by:
isNull in interface Node
Overrides:
isNull in class AbstractNode

getSize

public long getSize(String fieldName)
Description copied from interface: Node
Returns the 'size' (e.g. the number of bytes of a byte array) for the specified field. This avoids acquiring the complete value if you only want to know how big the value of the field is.

Specified by:
getSize in interface Node

getValueWithoutProcess

public Object getValueWithoutProcess(String fieldName)
Like getObjectValue, but skips any processing that MMBase would normally perform on a field. You can use this to get data from a field for validation purposes.

Specified by:
getValueWithoutProcess in interface Node
Parameters:
fieldName - name of field
Since:
MMBase-1.8

getBooleanValue

public boolean getBooleanValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a boolean. 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 considered 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.

Specified by:
getBooleanValue in interface Node
Overrides:
getBooleanValue in class AbstractNode

getDateValue

public Date getDateValue(String fieldName)
Specified by:
getDateValue in interface Node
Overrides:
getDateValue in class AbstractNode

getListValue

public List getListValue(String fieldName)
Specified by:
getListValue in interface Node
Overrides:
getListValue in class AbstractNode

getNodeValue

public Node getNodeValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a Node. If the value is not itself a Node, this call attempts to convert the original field value to a Node, by trying to retrieve a Node using the field value as a Node number or alias.
For instance, getNodeValue("destination"), when run on a OAlias object, returns the referenced destination node (instead of the number, which is what it normally holds).
Mostly, this call is used in cluster nodes (nodes retrieved by using the Cloud.getList method. A cluster node returns one of its compound nodes when an appropriate nodemanager name (name from the nodepath) is specified. I.e. getNodeValue("people") will return the people-node in the cluster. If this fails, the method returns null.
Notes: the behavior of getNodeValue when called on a field that is not intended to be a node reference is currently undefined and is not encouraged.
Calling this method with field "number" or null lets the Node return a reference to itself, regardless of the actual value of the number field or status of the Node.

Specified by:
getNodeValue in interface Node
Overrides:
getNodeValue in class AbstractNode

getIntValue

public int getIntValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as an int. Numeric fields are simply converted. Double and float values may be truncated. For Node values, the numeric key is returned. Long values return -1 of the value is too large. Boolean fields return 0 if false, and 1 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1

Specified by:
getIntValue in interface Node
Overrides:
getIntValue in class AbstractNode

getFloatValue

public float getFloatValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a float. This function attempts to convert the value to a float. Numeric fields are simply converted. Boolean fields return 0.0 if false, and 1.0 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1.0.

Specified by:
getFloatValue in interface Node
Overrides:
getFloatValue in class AbstractNode

getLongValue

public long getLongValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a long. This function attempts to convert the value to a long. Numeric fields are simply converted. Double and float values may be truncated. Boolean fields return 0 if false, and 1 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1

Specified by:
getLongValue in interface Node
Overrides:
getLongValue in class AbstractNode

getDoubleValue

public double getDoubleValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a double. This function attempts to convert the value to a double. Numeric fields are simply converted. Double may be truncated. Boolean fields return 0.0 if false, and 1.0 if true. String fields are parsed. If a parsed string contains an error, ot the field value is not of a type that can be converted (i.e. a byte array), this function returns -1.0.

Specified by:
getDoubleValue in interface Node
Overrides:
getDoubleValue in class AbstractNode

getByteValue

public byte[] getByteValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a byte array. This function returns either the value of a byte field, or the byte value of a string (converted using the default encoding, i.e. UTF8) Other types of values return an empty byte-array.

Specified by:
getByteValue in interface Node
Overrides:
getByteValue in class AbstractNode

getInputStreamValue

public InputStream getInputStreamValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a java.io.InputStream This is especially usefull for large byte-array fields. By this you can avoid them to be completely stored in memory.

Specified by:
getInputStreamValue in interface Node
Overrides:
getInputStreamValue in class AbstractNode

getStringValue

public String getStringValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a String. Byte arrays are converted to string using the default encoding (UTF8). Node values return a string representation of their numeric key. For other values the result is calling the toString() method on the actual object.

Specified by:
getStringValue in interface Node
Overrides:
getStringValue in class AbstractNode

getXMLValue

public Document getXMLValue(String fieldName)
Description copied from interface: Node
Returns the value of the specified field as a dom.Document If the node value is not itself a Document, the method attempts to attempts to convert the String value into an XML. This included the empty string, but not the 'null' value. If the value is null, this method returns null

Specified by:
getXMLValue in interface Node
Overrides:
getXMLValue in class AbstractNode

commit

public void commit()
Description copied from interface: Node
Commit the node to the database. Prior to committing, the values are processed by any commit-processors associated with the datatype of the node's fields), then validated. Makes this node and/or the changes made to this node visible to the cloud. If this method is called for the first time on this node it will make this node visible to the cloud, otherwise the modifications made to this node using the set methods will be made visible to the cloud. This action fails if the current node is not in edit mode. If the node is in a transaction, nothing happens - actual committing occurs through the transaction.

Specified by:
commit in interface Node
Overrides:
commit in class AbstractNode

cancel

public void cancel()
Description copied from interface: Node
Cancel changes to a node This fails if the current node is not in edit mode. If the node is in a transaction, nothing happens - actual committing occurs through the transaction.

Specified by:
cancel in interface Node
Overrides:
cancel in class AbstractNode

delete

public void delete(boolean deleteRelations)
Description copied from interface: Node
Removes the Node.

Specified by:
delete in interface Node
Overrides:
delete in class AbstractNode

toString

public String toString()
Description copied from interface: Node
Converts the node to a string

Specified by:
toString in interface Node

deleteRelations

public void deleteRelations(String type)
                     throws NotFoundException
Description copied from interface: Node
Removes all relation nodes with a certain relation manager that are attached to this node.

Specified by:
deleteRelations in interface Node
Overrides:
deleteRelations in class AbstractNode
Throws:
NotFoundException

getRelations

public RelationList getRelations(String role,
                                 String nodeManager)
                          throws NotFoundException
Description copied from interface: Node
Returns all relation nodes attached to this node that have a specific role, or refer a node from a specific nodemanager

Specified by:
getRelations in interface Node
Overrides:
getRelations in class AbstractNode
Throws:
NotFoundException

getRelations

public RelationList getRelations(String role,
                                 NodeManager nodeManager,
                                 String searchDir)
                          throws NotFoundException
Returns a list of relations of the given node.

Specified by:
getRelations in interface Node
Overrides:
getRelations in class AbstractNode
Parameters:
role - role of the relation
nodeManager - node manager on the other side of the relation
searchDir - direction of the relation
Returns:
list of relations
Throws:
NotFoundException
See Also:
Should perhaps be implemented with that

hasRelations

public boolean hasRelations()
Description copied from interface: Node
Checks whether this node has any relations.

Specified by:
hasRelations in interface Node
Overrides:
hasRelations in class AbstractNode

countRelatedNodes

public int countRelatedNodes(NodeManager otherNodeManager,
                             String role,
                             String direction)
Specified by:
countRelatedNodes in interface Node
Overrides:
countRelatedNodes in class AbstractNode

getRelatedNodes

public NodeList getRelatedNodes(NodeManager nodeManager,
                                String role,
                                String searchDir)
Description copied from interface: Node
Returns all related nodes that have a specific node manager and role. 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.

Specified by:
getRelatedNodes in interface Node
Overrides:
getRelatedNodes in class AbstractNode
Parameters:
nodeManager - node manager on the other side of the relation
role - role of the relation
searchDir - direction of the relation
Returns:
List of related nodes
Since:
MMBase-1.6
See Also:
Should perhaps be implemented with that.

countRelatedNodes

public int countRelatedNodes(String type)
Description copied from interface: Node
Returns the number of related nodes that have a specific node manager. The counted nodes are not the nodes directly attached to this node (the relation nodes) but the nodes attached to the relation nodes of this node.

Specified by:
countRelatedNodes in interface Node
Overrides:
countRelatedNodes in class AbstractNode

getAliases

public StringList getAliases()
Description copied from interface: Node
Returns all aliases for this node.

Specified by:
getAliases in interface Node
Overrides:
getAliases in class AbstractNode

createAlias

public void createAlias(String aliasName)
Description copied from interface: Node
Create an alias for this node. An alias can be used to refer to a node in addition to his number.

Specified by:
createAlias in interface Node
Overrides:
createAlias in class AbstractNode

deleteAlias

public void deleteAlias(String aliasName)
Description copied from interface: Node
Delete an alias for this node.

Specified by:
deleteAlias in interface Node
Overrides:
deleteAlias in class AbstractNode

setContext

public void setContext(String context)
Description copied from interface: Node
Sets the security context of this Node (AKA the 'owner' field)

Specified by:
setContext in interface Node
Overrides:
setContext in class AbstractNode

getContext

public String getContext()
Description copied from interface: Node
Get the security context of the current Node

Specified by:
getContext in interface Node
Overrides:
getContext in class AbstractNode

getPossibleContexts

public StringList getPossibleContexts()
Description copied from interface: Node
Contacts the security implementation to find out to which other possible contexts the context of this node may be set.

Specified by:
getPossibleContexts in interface Node
Overrides:
getPossibleContexts in class AbstractNode

mayWrite

public boolean mayWrite()
Description copied from interface: Node
Check write rights on this node.

Specified by:
mayWrite in interface Node
Overrides:
mayWrite in class AbstractNode

mayDelete

public boolean mayDelete()
Description copied from interface: Node
Check delete rights on this node.

Specified by:
mayDelete in interface Node
Overrides:
mayDelete in class AbstractNode

mayChangeContext

public boolean mayChangeContext()
Description copied from interface: Node
Check context-change rights on this node.

Specified by:
mayChangeContext in interface Node
Overrides:
mayChangeContext in class AbstractNode

finalize

protected void finalize()
Reverse the buffers, when changed and not stored...


hashCode

public int hashCode()
Since:
MMBase-1.6.2
See Also:
Object.hashCode()

getFunctions

public Collection getFunctions()
Description copied from interface: Node
Returns all the Function objects of this Node

Specified by:
getFunctions in interface Node
Returns:
a Collection of Function objects.

getNodeFunction

protected Function getNodeFunction(String functionName)
Overrides:
getNodeFunction in class AbstractNode

createParameters

public Parameters createParameters(String functionName)
Description copied from interface: Node
Creates a parameter list for a function. The list can be filled with parameter values by either using the List set(int, Object) method, to set values for parameters by psoition, or by using the set(String, Object) method to set parameters by name.
This object can then be passed to the getFunctionValue method. Note that adding extra parameters (with the add(Object) method) won't work and may cause exceptions.

Specified by:
createParameters in interface Node
Overrides:
createParameters in class AbstractNode

createFunctionValue

protected FieldValue createFunctionValue(Object result)
Overrides:
createFunctionValue in class AbstractNode


MMBase build 1.8.1.20060716