org.mmbase.bridge.util
Class AbstractNodeManager

java.lang.Object
  extended by org.mmbase.bridge.util.AbstractNode
      extended by org.mmbase.bridge.util.AbstractNodeManager
All Implemented Interfaces:
Comparable<Node>, Node, NodeManager
Direct Known Subclasses:
MapNodeManager, MockNodeManager, VirtualNodeManager

public abstract class AbstractNodeManager
extends AbstractNode
implements NodeManager

Abstract implementation of NodeManager, to minimalize the implementation of a virtual one. Most methods throw UnsupportOperationException (like in VirtualNodeManager).

Since:
MMBase-1.8
Version:
$Id: AbstractNodeManager.java 42922 2010-07-15 17:40:25Z michiel $
Author:
Michiel Meeuwissen
See Also:
NodeManager

Field Summary
protected  Cloud cloud
           
protected  Map<String,Object> values
           
 
Fields inherited from interface org.mmbase.bridge.NodeManager
GUI_PLURAL, GUI_SINGULAR, ORDER_CREATE, ORDER_EDIT, ORDER_LIST, ORDER_NONE, ORDER_SEARCH
 
Fields inherited from interface org.mmbase.bridge.Node
CLOUD_COMMITNODE_KEY
 
Constructor Summary
protected AbstractNodeManager(Cloud c)
           
 
Method Summary
 FieldList createFieldList()
          Returns a new, empty field list for this nodemanager
 Node createNode()
          Creates a new node.
 NodeList createNodeList()
          Returns a new, empty node list for this nodemanager
 NodeQuery createQuery()
          Creates a query for this NodeNanager.
 RelationList createRelationList()
          Returns a new, empty relation list for this nodemanager
protected  void edit(int action)
           
 RelationManagerList getAllowedRelations()
          Retrieve all relation managers that can be used to create relations for objects of this nodemanager.
 RelationManagerList getAllowedRelations(NodeManager nodeManager, String role, String direction)
          Retrieve all relation managers that can be used to create relations for objects from this nodemanager, to the specified manager, using the specified role and direction.
 RelationManagerList getAllowedRelations(String nodeManager, String role, String direction)
          Retrieve all relation managers that can be used to create relations for objects from this nodemanager, to the specified manager, using the specified role and direction.
 Cloud getCloud()
          Returns the cloud to which this manager belongs.
 NodeManagerList getDescendants()
          Retrieve a list of descendant nodemanagers (the nodemanagers that - possibly indirectly - extend from this nodemanager)
 String getDescription()
          Returns the description of this node manager.
 String getDescription(Locale locale)
          Returns the description of this node manager in a specified language.
 Field getField(String fieldName)
          Returns the field with the specified name.
 FieldList getFields()
          Returns a list of all fields defined for this node manager.
 FieldList getFields(int sortOrder)
          Retrieve a subset of field types of this NodeManager, depending on a given order.
protected abstract  Map<String,Field> getFieldTypes()
           
 Collection<Function<?>> getFunctions()
          This default implementation is based on Node.getNodeManager().Node.getFunctions().
 String getGUIName()
          Returns the descriptive name of this node manager.
 String getGUIName(int plurality)
          Returns the descriptive name of this node manager.
 String getGUIName(int plurality, Locale locale)
          Returns the descriptive name of this node manager ina a specified language.
 String getInfo(String command)
          Retrieve info from a node manager based on a command string.
 String getInfo(String command, ServletRequest req, ServletResponse resp)
          Retrieve info from a node manager based on a command string Similar to the $MOD command in SCAN.
 NodeList getList(NodeQuery query)
          Executes a query and returns the result as nodes of this NodeManager (or of extensions)
 NodeList getList(String command, Map parameters)
          Retrieve info (as a list of virtual nodes) from a node manager based on a command string.
 NodeList getList(String command, Map parameters, ServletRequest req, ServletResponse resp)
          Retrieve info from a node manager based on a command string Similar to the LIST command in SCAN.
 NodeList getList(String constraints, String sorted, String directions)
          Returns a list of nodes belonging to this node manager.
 String getName()
          Returns the name of this node manager.
 NodeManager getNodeManager()
          Returns the node manager for this node.
 NodeManager getParent()
          Retrieve the parent of this NodeManager (the Nodemanager that this nodemanager extends from)
 Map<String,String> getProperties()
          Retrieve a copy of the node manager's properties
 String getProperty(String name)
          Retrieve a property of the node manager.
 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 hasField(String fieldName)
          Tests whether the field with the specified name exists in this nodemanager.
 boolean isNodeManager()
          Determine whether this Node is a NodeManager.
 boolean mayCreateNode()
          Check if the current user may create a new node of this type.
 void setNodeManager(NodeManager nm)
          Sets the node manager of this node.
protected  void setSize(String fieldName, long size)
           
protected  void setValueWithoutChecks(String fieldName, Object value)
           
 NodeManager toNodeManager()
          Returns this as a NodeManager.
 String toString()
          Converts the node to a string
 
Methods inherited from class org.mmbase.bridge.util.AbstractNode
cancel, checkWrite, commit, compareTo, countRelatedNodes, countRelatedNodes, countRelations, countRelations, createAlias, createFunctionValue, createParameters, createRelation, delete, delete, deleteAlias, deleteRelations, deleteRelations, equals, getAliases, getBooleanValue, getByteValue, getChanged, getContext, getDateValue, getDecimalValue, getDoubleValue, getFieldValue, getFieldValue, getFloatValue, getFunction, getFunctionMap, getFunctionValue, getInputStreamValue, getIntValue, getListValue, getLongValue, getNodeFunction, getNodeValue, getNumber, getObjectValue, getPossibleContexts, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getRelations, getRelations, getStringValue, getValue, getXMLValue, getXMLValue, hashCode, hasRelations, isChanged, isChanged, isNew, isNull, isRelation, isRelationManager, mayChangeContext, mayDelete, mayWrite, processNull, setBooleanValue, setByteValue, setContext, setDateValue, setDecimalValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeValue, setObjectValue, setStringValue, setValue, setValueWithoutProcess, setXMLValue, 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
cancel, commit, countRelatedNodes, countRelatedNodes, countRelations, countRelations, createAlias, createParameters, createRelation, delete, delete, deleteAlias, deleteRelations, deleteRelations, getAliases, getBooleanValue, getByteValue, getChanged, getContext, getDateValue, getDecimalValue, getDoubleValue, getFieldValue, getFieldValue, getFloatValue, getFunction, getFunctionValue, getInputStreamValue, getIntValue, getListValue, getLongValue, getNodeValue, getNumber, getObjectValue, getPossibleContexts, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getRelations, getRelations, getStringValue, getValue, getXMLValue, getXMLValue, hasRelations, isChanged, isChanged, isNew, isNull, isRelation, isRelationManager, mayChangeContext, mayDelete, mayWrite, setBooleanValue, setByteValue, setContext, setDateValue, setDecimalValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeValue, setObjectValue, setStringValue, setValue, setValueWithoutProcess, setXMLValue, toRelation, toRelationManager, validate
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

values

protected Map<String,Object> values

cloud

protected final Cloud cloud
Constructor Detail

AbstractNodeManager

protected AbstractNodeManager(Cloud c)
Method Detail

setValueWithoutChecks

protected void setValueWithoutChecks(String fieldName,
                                     Object value)
Specified by:
setValueWithoutChecks 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
Returns:
value without processing

edit

protected void edit(int action)

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'

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

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

getCloud

public Cloud getCloud()
Description copied from interface: NodeManager
Returns the cloud to which this manager belongs.

Specified by:
getCloud in interface Node
Specified by:
getCloud in interface NodeManager
Returns:
the cloud to which this manager belongs

isNodeManager

public boolean isNodeManager()
Description copied from interface: Node
Determine whether this Node is a NodeManager.

Specified by:
isNodeManager in interface Node
Overrides:
isNodeManager in class AbstractNode
Returns:
true if this Node is a NodeManager.

toNodeManager

public NodeManager toNodeManager()
Description copied from interface: Node
Returns this as a NodeManager.

Specified by:
toNodeManager in interface Node
Overrides:
toNodeManager in class AbstractNode
Returns:
a NodeManager object

createNode

public Node createNode()
Description copied from interface: NodeManager
Creates a new node. The returned node will not be visible in the cloud until the commit() method is called on this node. Until then it will have a temporary node number.

Specified by:
createNode in interface NodeManager
Returns:
the new Node

getList

public NodeList getList(String constraints,
                        String sorted,
                        String directions)
Description copied from interface: NodeManager
Returns a list of nodes belonging to this node manager. Constraints can be given to exclude nodes from the returned list. These constraints follow the syntax of the SQL where clause. It's a good practice to use uppercase letters for the operators and lowercase letters for the fieldnames. Example constraints are:
 "number = 100" (!=, <, >, <= and >= can also be used)
 "name = 'admin'",
 "email IS NULL" (indicating the email field is empty)
 "email LIKE '%.org'" (indication the email should end with .org)
 "number BETWEEN 99 AND 101"
 "name IN ('admin', 'anonymous')"
 
The NOT operator can be used to get the opposite result like:
 "NOT (number = 100)"
 "NOT (name = 'admin')",
 "email IS NOT NULL"
 "email NOT LIKE '%.org'" (indication the email should not end with .org)
 "number NOT BETWEEN 99 AND 101"
 "name NOT IN ('admin', 'anonymous')"
 
Some special functions (not part of standard SQL, but most databases support them) can be used like:
 "LOWER(name) = 'admin'" (to also allow 'Admin' to be selected)
 "LENGTH(name) > 5" (to only select names longer then 5 characters)
 
Constraints can be linked together using AND and OR:
 "((number=100) OR (name='admin') AND email LIKE '%.org')"
 
The single quote can be escaped using it twice for every single occurence:
 "name='aaa''bbb'" (if we want to find the string aaa'bbb)
 
For more info consult a SQL tutorial like Jim Hoffman's introduction to Structured Query Language.

Specified by:
getList in interface NodeManager
Parameters:
constraints - Constraints to prevent nodes from being included in the resulting list which would normally by included or null if no constraints should be applied .
sorted - A comma separated list of field names on which the returned list should be sorted or null if the order of the returned virtual nodes doesn't matter.
directions - A comma separated list of values indicating wether to sort up (ascending) or down (descending) on the corresponding field in the orderby parameter or null if sorting on all fields should be up. The value DOWN (case insensitive) indicates that sorting on the corresponding field should be down, all other values (including the empty value) indicate that sorting on the corresponding field should be up. If the number of values found in this parameter are less than the number of fields in the orderby parameter, all fields that don't have a corresponding direction value are sorted according to the last specified direction value.
Returns:
a list of nodes belonging to this node manager

createFieldList

public FieldList createFieldList()
Description copied from interface: NodeManager
Returns a new, empty field list for this nodemanager

Specified by:
createFieldList in interface NodeManager
Returns:
The empty list

createNodeList

public NodeList createNodeList()
Description copied from interface: NodeManager
Returns a new, empty node list for this nodemanager

Specified by:
createNodeList in interface NodeManager
Returns:
The empty list

createRelationList

public RelationList createRelationList()
Description copied from interface: NodeManager
Returns a new, empty relation list for this nodemanager

Specified by:
createRelationList in interface NodeManager
Returns:
The empty list

mayCreateNode

public boolean mayCreateNode()
Description copied from interface: NodeManager
Check if the current user may create a new node of this type.

Specified by:
mayCreateNode in interface NodeManager
Returns:
Check if the current user may create a new node of this type.

getList

public NodeList getList(NodeQuery query)
Description copied from interface: NodeManager
Executes a query and returns the result as nodes of this NodeManager (or of extensions)

Specified by:
getList in interface NodeManager
Parameters:
query - query to execute
Returns:
list of nodes

createQuery

public NodeQuery createQuery()
Description copied from interface: NodeManager
Creates a query for this NodeNanager. The nodemanager is added as a step, and also all (non byte array) fields are added. The query can be used by getList of Cloud. You can not add steps to this NodeQuery.

Specified by:
createQuery in interface NodeManager
Returns:
query for this NodeNanager
See Also:
NodeManager.getList(NodeQuery), Cloud.createNodeQuery()

getList

public NodeList getList(String command,
                        Map parameters,
                        ServletRequest req,
                        ServletResponse resp)
Description copied from interface: NodeManager
Retrieve info from a node manager based on a command string Similar to the LIST command in SCAN. The values retrieved are represented as fields of a virtual node, named following the fieldnames listed in the fields paramaters..

Specified by:
getList in interface NodeManager
Parameters:
command - the info to obtain, i.e. "USER-OS".
parameters - a hashtable containing the named parameters of the list.
req - the Request item to use for obtaining user information. For backward compatibility.
resp - the Response item to use for redirecting users. For backward compatibility.
Returns:
info from a node manager (as a list of virtual nodes)

getList

public NodeList getList(String command,
                        Map parameters)
Description copied from interface: NodeManager
Retrieve info (as a list of virtual nodes) from a node manager based on a command string. Similar to the LIST command in SCAN. The values retrieved are represented as fields of a virtual node, named following the fieldnames listed in the fields paramaters..

Specified by:
getList in interface NodeManager
Parameters:
command - the info to obtain, i.e. "USER-OS".
parameters - a hashtable containing the named parameters of the list.
Returns:
info from a node manager (as a list of virtual nodes)

getAllowedRelations

public RelationManagerList getAllowedRelations()
Description copied from interface: NodeManager
Retrieve all relation managers that can be used to create relations for objects of this nodemanager.

Specified by:
getAllowedRelations in interface NodeManager
Returns:
the relation manager list

getAllowedRelations

public RelationManagerList getAllowedRelations(String nodeManager,
                                               String role,
                                               String direction)
Description copied from interface: NodeManager
Retrieve all relation managers that can be used to create relations for objects from this nodemanager, to the specified manager, using the specified role and direction.

Specified by:
getAllowedRelations in interface NodeManager
Parameters:
nodeManager - the name of the nodemanger with which to make a relation, can be null
role - the role with which to make a relation, can be null
direction - the search direction ("source", "destination", "both"), can be null
Returns:
the relation manager list

getAllowedRelations

public RelationManagerList getAllowedRelations(NodeManager nodeManager,
                                               String role,
                                               String direction)
Description copied from interface: NodeManager
Retrieve all relation managers that can be used to create relations for objects from this nodemanager, to the specified manager, using the specified role and direction.

Specified by:
getAllowedRelations in interface NodeManager
Parameters:
nodeManager - the nodemanger with which to make a relation, can be null
role - the role with which to make a relation, can be null
direction - the search direction ("source", "destination", "both"), can be null
Returns:
the relation manager list

getInfo

public String getInfo(String command)
Description copied from interface: NodeManager
Retrieve info from a node manager based on a command string. Similar to the $MOD command in SCAN.

Specified by:
getInfo in interface NodeManager
Parameters:
command - the info to obtain, i.e. "USER-OS".
Returns:
info from a node manager

getInfo

public String getInfo(String command,
                      ServletRequest req,
                      ServletResponse resp)
Description copied from interface: NodeManager
Retrieve info from a node manager based on a command string Similar to the $MOD command in SCAN.

Specified by:
getInfo in interface NodeManager
Parameters:
command - the info to obtain, i.e. "USER-OS".
req - the Request item to use for obtaining user information. For backward compatibility.
resp - the Response item to use for redirecting users. For backward compatibility.
Returns:
info from a node manager

getFieldTypes

protected abstract Map<String,Field> getFieldTypes()

hasField

public boolean hasField(String fieldName)
Description copied from interface: NodeManager
Tests whether the field with the specified name exists in this nodemanager.

Specified by:
hasField in interface NodeManager
Parameters:
fieldName - the name of the field to be returned
Returns:
true if the field with the requested name exists

getFields

public final FieldList getFields()
Description copied from interface: NodeManager
Returns a list of all fields defined for this node manager.

Specified by:
getFields in interface NodeManager
Returns:
a list of all fields defined for this node manager

getFields

public final FieldList getFields(int sortOrder)
Description copied from interface: NodeManager
Retrieve a subset of field types of this NodeManager, depending on a given order. The order is a integer constant which symbolizes `none', `create', `edit', `list' or `search'. These last three one may recognize from builder XML's. `none' means `all fields'. The actual integer contants are present as the ORDER contants in this interface.

Specified by:
getFields in interface NodeManager
Parameters:
sortOrder - the order in which to list the fields
Returns:
a FieldList object, which is a specialized List of Field objects.
See Also:
NodeManager.ORDER_NONE, NodeManager.ORDER_CREATE, NodeManager.ORDER_EDIT, NodeManager.ORDER_LIST, NodeManager.ORDER_SEARCH

getField

public Field getField(String fieldName)
               throws IllegalArgumentException
Description copied from interface: NodeManager
Returns the field with the specified name.

Specified by:
getField in interface NodeManager
Parameters:
fieldName - the name of the field to be returned
Returns:
the field with the requested name
Throws:
IllegalArgumentException

getGUIName

public String getGUIName()
Description copied from interface: NodeManager
Returns the descriptive name of this node manager. This name will be in the language of the current cloud (defined in cloud.getLocale()).

Specified by:
getGUIName in interface NodeManager
Returns:
the descriptive name of this node manager

getGUIName

public String getGUIName(int plurality)
Description copied from interface: NodeManager
Returns the descriptive name of this node manager. This name will be in the language of the current cloud (defined in cloud.getLocale()).

Specified by:
getGUIName in interface NodeManager
Parameters:
plurality - the plurality (number of objects) for which to return a description (NodeManager.GUI_SINGULAR or NodeManager.GUI_PLURAL)
Returns:
the descriptive name of this node manager

getGUIName

public String getGUIName(int plurality,
                         Locale locale)
Description copied from interface: NodeManager
Returns the descriptive name of this node manager ina a specified language.

Specified by:
getGUIName in interface NodeManager
Parameters:
plurality - the plurality (number of objects) for which to return a description (NodeManager.GUI_SINGULAR or NodeManager.GUI_PLURAL)
locale - the locale that determines the language for the GUI name
Returns:
the descriptive name of this node manager

getName

public String getName()
Description copied from interface: NodeManager
Returns the name of this node manager. This name is a unique name.

Specified by:
getName in interface NodeManager
Returns:
the name of this node manager.

getDescription

public String getDescription()
Description copied from interface: NodeManager
Returns the description of this node manager.

Specified by:
getDescription in interface NodeManager
Returns:
the description of this node manager

getDescription

public String getDescription(Locale locale)
Description copied from interface: NodeManager
Returns the description of this node manager in a specified language.

Specified by:
getDescription in interface NodeManager
Parameters:
locale - the locale that determines the language for the description
Returns:
the description of this node manager

getParent

public NodeManager getParent()
Description copied from interface: NodeManager
Retrieve the parent of this NodeManager (the Nodemanager that this nodemanager extends from)

Specified by:
getParent in interface NodeManager
Returns:
the NodeManager's parent

getProperty

public String getProperty(String name)
Description copied from interface: NodeManager
Retrieve a property of the node manager.

Specified by:
getProperty in interface NodeManager
Parameters:
name - the name of the property
Returns:
the property value (null if not given)

getProperties

public Map<String,String> getProperties()
Description copied from interface: NodeManager
Retrieve a copy of the node manager's properties

Specified by:
getProperties in interface NodeManager
Returns:
a map of node manager properties

getDescendants

public NodeManagerList getDescendants()
Description copied from interface: NodeManager
Retrieve a list of descendant nodemanagers (the nodemanagers that - possibly indirectly - extend from this nodemanager)

Specified by:
getDescendants in interface NodeManager
Returns:
a list of NodeManagers

getFunctions

public Collection<Function<?>> getFunctions()
Description copied from class: AbstractNode
This default implementation is based on Node.getNodeManager().Node.getFunctions().

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

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


MMBase 2.0-SNAPSHOT - null