org.mmbase.bridge.implementation
Class BasicNode

Package class diagram package BasicNode
java.lang.Object
  extended by org.mmbase.bridge.util.AbstractNode
      extended by org.mmbase.bridge.implementation.BasicNode
All Implemented Interfaces:
Comparable<Node>, Node, SizeMeasurable
Direct Known Subclasses:
BasicNodeManager, BasicRelation

public class BasicNode
extends AbstractNode
implements Node, SizeMeasurable

Basic implementation of Node. Wraps MMObjectNodes, adds security.

Version:
$Id: BasicNode.java 45315 2011-02-18 20:23:11Z michiel $
Author:
Rob Vermeulen, Pierre van Rooden, Michiel Meeuwissen
See Also:
Node, MMObjectNode
To Do:
This class has large overlap with VirtualNode. They probably should share an ancestor (AbstractBasicNode or so) (MMB-1870)

Field Summary
protected  BasicCloud cloud
          Reference to the Cloud.
protected  BasicNodeManager nodeManager
          Reference to the NodeManager
protected  MMObjectNode noderef
          Reference to actual MMObjectNode object.
protected  MMObjectNode originalNoderef
           
protected  int temporaryNodeId
          Temporary node ID.
 
Fields inherited from interface org.mmbase.bridge.Node
CLOUD_COMMITNODE_KEY
 
Constructor Summary
BasicNode(BasicCloud cloud)
           
BasicNode(MMObjectNode node, BasicCloud cloud)
          Instantiates a node, linking it to a specified cloud The NodeManager for the node is requested from the Cloud.
BasicNode(MMObjectNode node, BasicCloud cloud, int id)
          Instantiates a new node (for insert), using a specified nodeManager.
BasicNode(MMObjectNode node, BasicNodeManager nodeManager)
          Instantiates a node, linking it to a specified node manager.
 
Method Summary
 void cancel()
           
protected  void checkAccount()
           
protected  void checkCommit()
           
protected  void checkCreate()
           
protected  void checkDelete()
           
protected  void checkWrite()
           
 void commit()
           This implementation checks create rights, then validates the values, then processes the 'commit processors' and then calls BasicCloud.afterCommit(BasicNode)
 int countRelatedNodes(NodeManager otherNodeManager, String role, String direction)
           
 int countRelatedNodes(String type)
           
 void createAlias(String aliasName)
           
protected  FieldValue createFunctionValue(Object result)
           
 Parameters createParameters(String functionName)
           
 void delete(boolean deleteRelations)
           
 void deleteAlias(String aliasName)
           
 void deleteRelations(String type)
           
protected  void finalize()
          Reverse the buffers, when changed and not stored...
 StringList getAliases()
           
 boolean getBooleanValue(String fieldName)
           
 int getByteSize()
           
 int getByteSize(SizeOf sizeof)
           
 byte[] getByteValue(String fieldName)
           
 Set<String> getChanged()
           
 Cloud getCloud()
           
 String getContext()
           
 Date getDateValue(String fieldName)
           
 double getDoubleValue(String fieldName)
           
 float getFloatValue(String fieldName)
           
 Collection<Function<?>> getFunctions()
           
 InputStream getInputStreamValue(String fieldName)
           
 int getIntValue(String fieldName)
           
 List getListValue(String fieldName)
           
 long getLongValue(String fieldName)
           
protected  MMObjectNode getNode()
          Obtains a reference to the underlying MMObjectNode.
protected  Function<?> getNodeFunction(String functionName)
           
 NodeManager getNodeManager()
           
 Node getNodeValue(String fieldName)
           
 int getNumber()
           
 StringList getPossibleContexts()
           
protected  NodeList getRelatedNodes(NodeManager otherManager, String role)
          Get related nodes for this node
 NodeList getRelatedNodes(NodeManager otherManager, String role, String searchDir)
           
 RelationList getRelations(String role, NodeManager nodeManager, String searchDir)
          Returns a list of relations of the given node.
 RelationList getRelations(String role, String otherNodeManager)
           
 long getSize(String fieldName)
           
 String getStringValue(String fieldName)
           
 Object getValueWithoutProcess(String fieldName)
          Like getObjectValue, but skips any processing that MMBase would normally perform on a field.
 Document getXMLValue(String fieldName)
           
 boolean hasRelations()
           
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()
           
 boolean isChanged(String fieldName)
           
 boolean isNew()
          Returns whether this is a new (not yet committed) node.
 boolean isNull(String fieldName)
           
 boolean mayChangeContext()
           
 boolean mayDelete()
           
 boolean mayWrite()
           
 void setContext(String context)
           
protected  void setNode(MMObjectNode n)
          Sets the reference to the underlying MMObjectNode.
protected  void setNodeManager(MMObjectNode node)
          Set nodemanager for node
 void setNodeManager(NodeManager nm)
           
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)
           
 String toString()
           
 
Methods inherited from class org.mmbase.bridge.util.AbstractNode
compareTo, countRelations, countRelations, createRelation, delete, deleteRelations, equals, getDecimalValue, getFieldValue, getFieldValue, getFunction, getFunctionMap, getFunctionValue, getObjectValue, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getValue, getXMLValue, hashCode, isNodeManager, isRelation, isRelationManager, processNull, setBooleanValue, setByteValue, setDateValue, setDecimalValue, 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, getDecimalValue, getFieldValue, getFieldValue, getFunction, getFunctionValue, getObjectValue, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getValue, getXMLValue, isNodeManager, isRelation, isRelationManager, setBooleanValue, setByteValue, setDateValue, setDecimalValue, 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.


originalNoderef

protected MMObjectNode originalNoderef

temporaryNodeId

protected int temporaryNodeId
Temporary node ID. This is necessary since there is otherwise no sure (and quick) way to determine whether a node is in 'edit' mode (i.e. has a temporary node). Basically, a temporarynodeid is either -1 (invalid), or a negative number smaller than -1 (a temporary number assigned by the system).

Constructor Detail

BasicNode

BasicNode(BasicCloud cloud)

BasicNode

BasicNode(MMObjectNode node,
          BasicNodeManager nodeManager)
Instantiates a node, linking it to a specified node manager. Use this constructor if the node you create uses a NodeManager that is not readily available from the cloud (such as a temporary nodemanager for a result list).

Parameters:
node - the MMObjectNode to base the node on
nodeManager - the NodeManager to use for administrating this Node
Throws:
IllegalArgumentException - If node is null

BasicNode

BasicNode(MMObjectNode node,
          BasicCloud cloud)
Instantiates a node, linking it to a specified cloud The NodeManager for the node is requested from the Cloud.

Parameters:
node - the MMObjectNode to base the node on
cloud - the cloud to which this node belongs
Throws:
IllegalArgumentException - If node is null

BasicNode

BasicNode(MMObjectNode node,
          BasicCloud cloud,
          int id)
Instantiates a new node (for insert), using a specified nodeManager.

Parameters:
node - a temporary MMObjectNode that is the base for the node
cloud - the cloud to create the node in
id - the id of the node in the temporary cloud
Method Detail

setNodeManager

protected void setNodeManager(MMObjectNode node)
Set nodemanager for node

Parameters:
node - node to derive nodemanager from.
Since:
MMBase-1.8

init

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


getByteSize

public int getByteSize()
Specified by:
getByteSize in interface SizeMeasurable

getByteSize

public int getByteSize(SizeOf sizeof)
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()
Specified by:
getCloud in interface Node

getNodeManager

public NodeManager getNodeManager()
Specified by:
getNodeManager in interface Node

setNodeManager

public void setNodeManager(NodeManager nm)
Specified by:
setNodeManager in interface Node
Overrides:
setNodeManager in class AbstractNode

getNumber

public int getNumber()
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)
Specified by:
isChanged in interface Node
Overrides:
isChanged in class AbstractNode

isChanged

public boolean isChanged()
Specified by:
isChanged in interface Node
Overrides:
isChanged in class AbstractNode

getChanged

public Set<String> getChanged()
Specified by:
getChanged in interface Node
Overrides:
getChanged in class AbstractNode

checkAccount

protected void checkAccount()

checkDelete

protected void checkDelete()

checkWrite

protected void checkWrite()
Overrides:
checkWrite in class AbstractNode

checkCreate

protected void checkCreate()

checkCommit

protected void checkCommit()

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)
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)
Specified by:
isNull in interface Node
Overrides:
isNull in class AbstractNode

getSize

public long getSize(String fieldName)
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
Returns:
the value without processing
Since:
MMBase-1.8

getBooleanValue

public boolean getBooleanValue(String fieldName)
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)
Specified by:
getNodeValue in interface Node
Overrides:
getNodeValue in class AbstractNode

getIntValue

public int getIntValue(String fieldName)
Specified by:
getIntValue in interface Node
Overrides:
getIntValue in class AbstractNode

getFloatValue

public float getFloatValue(String fieldName)
Specified by:
getFloatValue in interface Node
Overrides:
getFloatValue in class AbstractNode

getLongValue

public long getLongValue(String fieldName)
Specified by:
getLongValue in interface Node
Overrides:
getLongValue in class AbstractNode

getDoubleValue

public double getDoubleValue(String fieldName)
Specified by:
getDoubleValue in interface Node
Overrides:
getDoubleValue in class AbstractNode

getByteValue

public byte[] getByteValue(String fieldName)
Specified by:
getByteValue in interface Node
Overrides:
getByteValue in class AbstractNode

getInputStreamValue

public InputStream getInputStreamValue(String fieldName)
Specified by:
getInputStreamValue in interface Node
Overrides:
getInputStreamValue in class AbstractNode

getStringValue

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

getXMLValue

public Document getXMLValue(String fieldName)
Specified by:
getXMLValue in interface Node
Overrides:
getXMLValue in class AbstractNode

commit

public void commit()
This implementation checks create rights, then validates the values, then processes the 'commit processors' and then calls BasicCloud.afterCommit(BasicNode)

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

cancel

public void cancel()
Specified by:
cancel in interface Node
Overrides:
cancel in class AbstractNode

delete

public void delete(boolean deleteRelations)
Specified by:
delete in interface Node
Overrides:
delete in class AbstractNode

toString

public String toString()
Specified by:
toString in interface Node
Overrides:
toString in class Object

deleteRelations

public void deleteRelations(String type)
                     throws NotFoundException
Specified by:
deleteRelations in interface Node
Overrides:
deleteRelations in class AbstractNode
Throws:
NotFoundException

getRelations

public RelationList getRelations(String role,
                                 String otherNodeManager)
                          throws NotFoundException
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 Queries.createRelationNodesQuery(Node, NodeManager, String, String) Should perhaps be implemented with that

hasRelations

public boolean hasRelations()
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

protected NodeList getRelatedNodes(NodeManager otherManager,
                                   String role)
Get related nodes for this node

Parameters:
otherManager - nodemanager on the other side of the relation
role - name of the relation
Returns:
List of related nodes
Since:
MMBase-1.8.2

getRelatedNodes

public NodeList getRelatedNodes(NodeManager otherManager,
                                String role,
                                String searchDir)
Specified by:
getRelatedNodes in interface Node
Overrides:
getRelatedNodes in class AbstractNode
Parameters:
otherManager - 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)
Specified by:
countRelatedNodes in interface Node
Overrides:
countRelatedNodes in class AbstractNode

getAliases

public StringList getAliases()
Specified by:
getAliases in interface Node
Overrides:
getAliases in class AbstractNode

createAlias

public void createAlias(String aliasName)
Specified by:
createAlias in interface Node
Overrides:
createAlias in class AbstractNode

deleteAlias

public void deleteAlias(String aliasName)
Specified by:
deleteAlias in interface Node
Overrides:
deleteAlias in class AbstractNode

setContext

public void setContext(String context)
Specified by:
setContext in interface Node
Overrides:
setContext in class AbstractNode

getContext

public String getContext()
Specified by:
getContext in interface Node
Overrides:
getContext in class AbstractNode

getPossibleContexts

public StringList getPossibleContexts()
Specified by:
getPossibleContexts in interface Node
Overrides:
getPossibleContexts in class AbstractNode

mayWrite

public boolean mayWrite()
Specified by:
mayWrite in interface Node
Overrides:
mayWrite in class AbstractNode

mayDelete

public boolean mayDelete()
Specified by:
mayDelete in interface Node
Overrides:
mayDelete in class AbstractNode

mayChangeContext

public boolean mayChangeContext()
Specified by:
mayChangeContext in interface Node
Overrides:
mayChangeContext in class AbstractNode

finalize

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

Overrides:
finalize in class Object

getFunctions

public Collection<Function<?>> getFunctions()
Specified by:
getFunctions in interface Node
Overrides:
getFunctions in class AbstractNode

getNodeFunction

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

createParameters

public Parameters createParameters(String functionName)
Specified by:
createParameters in interface Node
Overrides:
createParameters in class AbstractNode

createFunctionValue

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


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