org.mmbase.bridge.util
Class MapNode

java.lang.Object
  extended byorg.mmbase.bridge.util.AbstractNode
      extended byorg.mmbase.bridge.util.MapNode
All Implemented Interfaces:
Comparable, Node

public class MapNode
extends AbstractNode
implements Node

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.

Since:
MMBase-1.8
Version:
$Id: MapNode.java,v 1.6 2006/06/20 20:05:32 michiel Exp $
Author:
Michiel Meeuwissen

Field Summary
protected  NodeManager nodeManager
          This is normally, but not always, a VirtualBuilder.
protected  Map originalValues
           
protected  Map sizes
           
protected  Map values
           
 
Fields inherited from class org.mmbase.bridge.util.AbstractNode
ACTION_COMMIT, ACTION_CREATE, ACTION_DELETE, ACTION_EDIT
 
Constructor Summary
MapNode(Map v)
          This allows you to create a Node object even without having a Cloud object.
MapNode(Map v, Cloud cloud)
          A node with a 'virtual' nodemanager will be constructed.
MapNode(Map 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.
 void createAlias(String aliasName)
          Create an alias for this node.
 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)
           
 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 i)
           
 StringList getAliases()
          Returns all aliases for this node.
 Cloud getCloud()
          Returns the cloud this node belongs to.
 String getContext()
          Get the security context of the current Node
 Collection getFunctions()
          Returns all the Function objects of this Node
protected  Function getNodeFunction(String functionName)
           
 NodeManager getNodeManager()
          Returns the node manager for this 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)
           
 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 commited).
 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 setSize(String fieldName, long size)
           
 void setValueWithoutChecks(String fieldName, Object value)
           
 void setValueWithoutProcess(String fieldName, Object value)
          Like setValue, but skips any processing that MMBase would normally perform on a field.
 String toString()
          Converts the node to a string
 
Methods inherited from class org.mmbase.bridge.util.AbstractNode
compareTo, countRelations, countRelations, createFunctionValue, createParameters, delete, deleteRelations, equals, getBooleanValue, getByteValue, getChanged, getDateValue, getDoubleValue, getFieldValue, getFieldValue, getFloatValue, getFunction, getFunctionValue, getInputStreamValue, getIntValue, getListValue, getLongValue, getNodeValue, getObjectValue, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getStringValue, getValue, getXMLValue, getXMLValue, isNodeManager, isRelation, isRelationManager, processCommit, setBooleanValue, setByteValue, setDateValue, 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, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.bridge.Node
countRelations, countRelations, createParameters, delete, deleteRelations, getBooleanValue, getByteValue, getChanged, getDateValue, getDoubleValue, getFieldValue, getFieldValue, getFloatValue, getFunction, getFunctionValue, getInputStreamValue, getIntValue, getListValue, getLongValue, getNodeValue, getObjectValue, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getStringValue, getValue, getXMLValue, getXMLValue, isNodeManager, isRelation, isRelationManager, setBooleanValue, setByteValue, setDateValue, 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 final 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 values

sizes

protected final Map sizes

originalValues

protected final Map originalValues
Constructor Detail

MapNode

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


MapNode

public MapNode(Map v,
               Cloud cloud)
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 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)

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()
Description copied from interface: Node
Whether this Node is new (not yet commited).

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

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

edit

protected void edit(int i)
Specified by:
edit in class AbstractNode

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

setValueWithoutProcess

public void setValueWithoutProcess(String fieldName,
                                   Object value)
Description copied from interface: Node
Like setValue, but skips any processing that MMBase would normally perform on a field. You can use this to set data on fields that are 'system' defined, to prevent (among other things) infinite recursion. Use with care - in general processing of a field has a purpose!

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 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

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

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,
                                 NodeManager nodeManager,
                                 String searchDir)
                          throws NotFoundException
Specified by:
getRelations in interface Node
Overrides:
getRelations 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

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

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

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

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

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


MMBase build 1.8.1.20060716