org.mmbase.bridge.util
Class MapNode<V>

Package class diagram package MapNode
java.lang.Object
  extended by org.mmbase.bridge.util.AbstractNode
      extended by org.mmbase.bridge.util.MapNode<V>
All Implemented Interfaces:
Serializable, Comparable<Node>, Node
Direct Known Subclasses:
MockNode

public class MapNode<V>
extends AbstractNode
implements Node, Serializable

A bridge Node based on a Map. It can come in handy sometimes to be able to present any Map as an MMBase Node. E.g. because then it can be accessed in MMBase taglib using mm:field tags. Don't confuse this with NodeMap.

Since:
MMBase-1.8
Version:
$Id: MapNode.java 44265 2010-12-24 22:21:26Z michiel $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Field Summary
(package private)  boolean implicitCreate
           
protected  NodeManager nodeManager
          This is normally, but not always, a VirtualBuilder.
protected  Map<String,V> originals
           
protected  Map<String,Long> sizes
           
protected  Map<String,V> values
           
protected  Map<String,V> wrapper
           
 
Fields inherited from interface org.mmbase.bridge.Node
CLOUD_COMMITNODE_KEY
 
Constructor Summary
MapNode(Map<String,V> v)
          This allows you to create a Node object even without having a Cloud object.
MapNode(Map<String,V> v, Cloud cloud)
           
MapNode(Map<String,V> v, Cloud cloud, boolean implicitCreate)
          A node with a 'virtual' nodemanager will be constructed.
MapNode(Map<String,V> v, NodeManager nm)
          This constructor explicitely specifies the node manager of the Node.
 
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.
 Relation createRelation(Node destinationNode, RelationManager relationManager)
          Adds a relation between this node and a specified node to the cloud.
protected static NodeManager createVirtualNodeManager(Cloud cloud, Map map, boolean implicitCreate)
           
 void delete(boolean deleteRelations)
          Removes the Node.
 void deleteRelations(String type)
          Removes all relation nodes with a certain relation manager that are attached to this node.
protected  void edit(int i)
           
 StringList getAliases()
          Returns all aliases for this node.
 Cloud getCloud()
          Returns the cloud this node belongs to.
 NodeManager getNodeManager()
          Returns the node manager for this node.
 int getNumber()
          Returns the unique number for this node.
 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)
           
 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.
 Object getValueWithoutProcess(String fieldName)
          Like getObjectValue, but skips any processing that MMBase would normally perform on a field.
 boolean hasRelations()
          Checks whether this node has any relations.
 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()
          Whether this Node is new (not yet committed).
 boolean isNull(String fieldName)
          Whether the value for the specified field is null.
 boolean mayChangeContext()
          Check context-change rights on this node.
 boolean mayWrite()
          Check write rights on this node.
 void setNodeManager(NodeManager nm)
          Sets the node manager of this node.
protected  void setSize(String fieldName, long size)
           
 void setValueWithoutChecks(String fieldName, Object value)
           
 void setValueWithoutProcess(String fieldName, Object value)
          Like setObjectValue, but without processing, this is called by the other set-values.
 String toString()
          Converts the node to a string
 
Methods inherited from class org.mmbase.bridge.util.AbstractNode
checkWrite, compareTo, countRelations, countRelations, createAlias, createFunctionValue, createParameters, delete, deleteAlias, deleteRelations, equals, getBooleanValue, getByteValue, getChanged, getContext, getDateValue, getDecimalValue, getDoubleValue, getFieldValue, getFieldValue, getFloatValue, getFunction, getFunctionMap, getFunctions, getFunctionValue, getInputStreamValue, getIntValue, getListValue, getLongValue, getNodeFunction, getNodeValue, getObjectValue, getPossibleContexts, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getStringValue, getValue, getXMLValue, getXMLValue, hashCode, isNodeManager, isRelation, isRelationManager, mayDelete, processNull, setBooleanValue, setByteValue, setContext, setDateValue, setDecimalValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeValue, setObjectValue, setStringValue, setValue, setXMLValue, toNodeManager, toNodeNumber, toRelation, toRelationManager, validate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.bridge.Node
countRelations, countRelations, createAlias, createParameters, delete, deleteAlias, deleteRelations, getBooleanValue, getByteValue, getChanged, getContext, getDateValue, getDecimalValue, getDoubleValue, getFieldValue, getFieldValue, getFloatValue, getFunction, getFunctions, getFunctionValue, getInputStreamValue, getIntValue, getListValue, getLongValue, getNodeValue, getObjectValue, getPossibleContexts, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getStringValue, getValue, getXMLValue, getXMLValue, isNodeManager, isRelation, isRelationManager, mayDelete, setBooleanValue, setByteValue, setContext, setDateValue, setDecimalValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeValue, setObjectValue, setStringValue, setValue, setXMLValue, toNodeManager, toRelation, toRelationManager, validate
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

nodeManager

protected transient NodeManager nodeManager
This is normally, but not always, a VirtualBuilder. It is not for some builders which have besides real nodes also virtual nodes, like typedef (cluster nodes) and typerel (allowed relations because of inheritance).


values

protected final Map<String,V> values

sizes

protected final Map<String,Long> sizes

wrapper

protected final Map<String,V> wrapper

originals

protected final Map<String,V> originals

implicitCreate

boolean implicitCreate
Constructor Detail

MapNode

public MapNode(Map<String,V> v,
               NodeManager nm)
This constructor explicitely specifies the node manager of the Node. This is used for {#getNodeManager} and {#getCloud}.


MapNode

public MapNode(Map<String,V> v,
               Cloud cloud,
               boolean implicitCreate)
A node with a 'virtual' nodemanager will be constructed. This virtual node manager will have fields which are guessed based on the keys and values of the given map.


MapNode

public MapNode(Map<String,V> v,
               Cloud cloud)

MapNode

public MapNode(Map<String,V> v)
This allows you to create a Node object even without having a Cloud object. 'Class' security is used to acquire a Cloud, because every bridge node must be associated with some Cloud object.

Method Detail

createVirtualNodeManager

protected static NodeManager createVirtualNodeManager(Cloud cloud,
                                                      Map map,
                                                      boolean implicitCreate)

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
Returns:
the unique number for this node
See Also:
Node.createAlias(String alias)

isNew

public boolean isNew()
Description copied from interface: Node
Whether this Node is new (not yet committed).

Specified by:
isNew in interface Node
Overrides:
isNew in class AbstractNode
Returns:
true when new

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
Parameters:
fieldName - the name of the field
Returns:
true when field's value was changed

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
Returns:
true when changed

edit

protected void edit(int i)

getValueWithoutProcess

public Object getValueWithoutProcess(String fieldName)
Description copied from interface: Node
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:
value without processing

setValueWithoutProcess

public void setValueWithoutProcess(String fieldName,
                                   Object value)
Description copied from class: AbstractNode
Like setObjectValue, but without processing, this is called by the other set-values.

Specified by:
setValueWithoutProcess in interface Node
Overrides:
setValueWithoutProcess in class AbstractNode
Parameters:
fieldName - name of field
value - new value of the field

setValueWithoutChecks

public void setValueWithoutChecks(String fieldName,
                                  Object value)
Specified by:
setValueWithoutChecks in class AbstractNode

isNull

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

Specified by:
isNull in interface Node
Overrides:
isNull in class AbstractNode
Parameters:
fieldName - the name of the field
Returns:
true when value is null

setSize

protected void setSize(String fieldName,
                       long size)
Specified by:
setSize 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
Parameters:
fieldName - the name of the field
Returns:
the 'size'

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
Parameters:
deleteRelations - a boolean. If true, then first all existing relations with this node will be removed.

toString

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

Specified by:
toString in interface Node
Overrides:
toString in class Object
Returns:
string representation of a 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
Parameters:
type - the name of the relation manager the removed relation nodes should have
Throws:
NotFoundException

getRelations

public RelationList getRelations(String role,
                                 NodeManager nodeManager,
                                 String searchDir)
                          throws NotFoundException
Specified by:
getRelations in interface Node
Overrides:
getRelations in class AbstractNode
Parameters:
role - forward role of a relation
nodeManager - node manager on the other side of the relation
searchDir - the direction of the relation
Returns:
List of relations
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
Parameters:
role - the name of the role the returned relation nodes should have
nodeManager - the name of the nodemanager for the nodes the returned relation nodes should have a relation to
Returns:
a list of relation nodes
Throws:
NotFoundException

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
Returns:
true if the node has relations

countRelatedNodes

public int countRelatedNodes(NodeManager otherNodeManager,
                             String role,
                             String direction)
Specified by:
countRelatedNodes in interface Node
Overrides:
countRelatedNodes in class AbstractNode
Parameters:
otherNodeManager - the node manager the nodes should have
role - the role of the relation
direction - the direction of the relation
Returns:
number of related nodes

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 - the node manager the returned nodes should have
role - the role of the relation
searchDir - the direction of the relation
Returns:
a list of related nodes

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
Parameters:
type - the name of the node manager the counted nodes should have
Returns:
the number of related nodes that have a specific node manager

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
Returns:
a list of alias names for this node

createRelation

public Relation createRelation(Node destinationNode,
                               RelationManager relationManager)
Description copied from interface: Node
Adds a relation between this node and a specified node to the cloud.

Specified by:
createRelation in interface Node
Overrides:
createRelation in class AbstractNode
Parameters:
destinationNode - the node to which you want to relate this node
relationManager - the relation manager you want to use
Returns:
the added relation

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
Returns:
Whether the node may be changed by the current user

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
Returns:
Whether the current user may change the context of this node

setNodeManager

public void setNodeManager(NodeManager nm)
Description copied from interface: Node
Sets the node manager of this node. Note that if this nodemanager is not a descendant of the current node manager, information may get lost!

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


MMBase2 Bridge 2.0-SNAPSHOT - 2013-03-30T06:34