org.mmbase.bridge.implementation
Class VirtualNode

java.lang.Object
  extended by org.mmbase.bridge.util.AbstractNode
      extended by org.mmbase.bridge.implementation.VirtualNode
All Implemented Interfaces:
Serializable, Comparable<Node>, Node

public class VirtualNode
extends AbstractNode
implements Node, Serializable

Implementation of Node. Simply wraps virtual node of core into an bridge Node. This class can be used even if you don't know the precise implementation of the Cloud object (in contradiction to BasicNode, and therefore has a public constructor VirtualNode(org.mmbase.module.core.VirtualNode, Cloud).

Since:
MMBase-1.8
Version:
$Id: VirtualNode.java 42692 2010-06-24 15:26:50Z michiel $
Author:
Michiel Meeuwissen
See Also:
Node, VirtualNode, Serialized Form
To Do:
This class has large overlap with BasicNode. They probably should share an ancestor (AbstractBasicNode or so). (MMB-1870)

Field Summary
protected  Cloud cloud
           
protected  NodeManager nodeManager
          This is normally, but not always, a VirtualBuilder.
protected  VirtualNode noderef
           
 
Fields inherited from interface org.mmbase.bridge.Node
CLOUD_COMMITNODE_KEY
 
Constructor Summary
protected VirtualNode(Cloud cloud, VirtualNode node, NodeManager nm)
           
  VirtualNode(Map<String,?> values, Cloud cloud)
          Makes a Node from a map of values.
  VirtualNode(VirtualNode node, Cloud cloud)
           
 
Method Summary
protected  FieldValue createFunctionValue(Object result)
           
 Parameters createParameters(String functionName)
          Creates a parameter list for a function.
protected  void edit(int action)
           
protected  org.mmbase.bridge.implementation.VirtualNode.NodeAndField getActualNodeForField(String fieldName)
           
 boolean getBooleanValue(String fieldName)
          Returns the value of the specified field as a boolean.
 byte[] getByteValue(String fieldName)
          Returns the value of the specified field as a byte array.
 Cloud getCloud()
          Returns the cloud this node belongs to.
 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<Function<?>> getFunctions()
          This default implementation is based on Node.getNodeManager().Node.getFunctions().
 InputStream getInputStreamValue(String fieldName)
          Returns the value of the specified field as a java.io.InputStream This is especially useful 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)
          Based on getFunctions.
 NodeManager getNodeManager()
          Returns the node manager for this node.
 VirtualNode getNodeRef()
          Returns the MMObjectNode on which the VirtualNode was based
 Node getNodeValue(String fieldName)
          Returns the Node value of a certain field, but in the case of a VirtualNode this can also occasionally be null because the node can have been deleted.
 int getNumber()
          Returns the unique number for this node.
 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.
protected static VirtualNode getVirtualNode(Map<String,?> values)
           
 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.
 boolean isNodeManager()
          Determine whether this Node is a NodeManager.
 boolean isNull(String fieldName)
          Whether the value for the specified field is null.
 boolean isRelation()
          Determine whether this Node is a Relation.
 boolean isRelationManager()
          Determine whether this Node is a RelationManager.
 void setSize(String fieldName, long size)
           
protected  void setValueWithoutChecks(String fieldName, Object value)
           
 NodeManager toNodeManager()
          Returns this as a NodeManager.
 Relation toRelation()
          Returns this as a Relation.
 RelationManager toRelationManager()
          Returns this as a RelationManager.
 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, createRelation, delete, delete, deleteAlias, deleteRelations, deleteRelations, equals, getAliases, getChanged, getContext, getDecimalValue, getFieldValue, getFieldValue, getFunction, getFunctionMap, getFunctionValue, getObjectValue, getPossibleContexts, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getRelations, getRelations, getValue, getXMLValue, hashCode, hasRelations, isChanged, isChanged, isNew, mayChangeContext, mayDelete, mayWrite, processNull, setBooleanValue, setByteValue, setContext, setDateValue, setDecimalValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeManager, setNodeValue, setObjectValue, setStringValue, setValue, setValueWithoutProcess, setXMLValue, toNodeNumber, 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, createRelation, delete, delete, deleteAlias, deleteRelations, deleteRelations, getAliases, getChanged, getContext, getDecimalValue, getFieldValue, getFieldValue, getFunction, getFunctionValue, getObjectValue, getPossibleContexts, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelatedNodes, getRelations, getRelations, getRelations, getRelations, getRelations, getValue, getXMLValue, hasRelations, isChanged, isChanged, isNew, mayChangeContext, mayDelete, mayWrite, setBooleanValue, setByteValue, setContext, setDateValue, setDecimalValue, setDoubleValue, setFloatValue, setInputStreamValue, setIntValue, setListValue, setLongValue, setNodeManager, setNodeValue, setObjectValue, setStringValue, setValue, setValueWithoutProcess, setXMLValue, validate
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

noderef

protected final VirtualNode noderef

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


cloud

protected final Cloud cloud
Constructor Detail

VirtualNode

protected VirtualNode(Cloud cloud,
                      VirtualNode node,
                      NodeManager nm)

VirtualNode

public VirtualNode(VirtualNode node,
                   Cloud cloud)

VirtualNode

public VirtualNode(Map<String,?> values,
                   Cloud cloud)
Makes a Node from a map of values. Sadly, this uses a local MMBase, so you can't use this with e.g. RMMCI, but I didn't feel like reimplementating Node completely.. See MapNode, which is a complete reimplementation (with no core dependencies).

Method Detail

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

getVirtualNode

protected static VirtualNode getVirtualNode(Map<String,?> values)

getNodeRef

public VirtualNode getNodeRef()
Returns the MMObjectNode on which the VirtualNode was based


isRelation

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

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

toRelation

public Relation toRelation()
Description copied from interface: Node
Returns this as a Relation.

Specified by:
toRelation in interface Node
Overrides:
toRelation in class AbstractNode
Returns:
a Relation object

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

isRelationManager

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

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

toRelationManager

public RelationManager toRelationManager()
Description copied from interface: Node
Returns this as a RelationManager.

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

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. This generally means the

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)

edit

protected void edit(int action)

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

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

getActualNodeForField

protected org.mmbase.bridge.implementation.VirtualNode.NodeAndField getActualNodeForField(String fieldName)
Since:
MMBase-1.9.2

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

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

getDateValue

public Date getDateValue(String fieldName)
Specified by:
getDateValue in interface Node
Overrides:
getDateValue in class AbstractNode
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

getListValue

public List getListValue(String fieldName)
Specified by:
getListValue in interface Node
Overrides:
getListValue in class AbstractNode
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

getNodeValue

public Node getNodeValue(String fieldName)
Returns the Node value of a certain field, but in the case of a VirtualNode this can also occasionally be null because the node can have been deleted.

Specified by:
getNodeValue in interface Node
Overrides:
getNodeValue in class AbstractNode
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field
See Also:
Cloud.getList(String, String, String, String, String, String, String, boolean)

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

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 useful 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
Parameters:
fieldName - the name of the field
Returns:
value of field as a input stream

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field

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
Parameters:
fieldName - the name of the field to be returned
Returns:
the value of the specified field as a DOM Element or null

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.

getNodeFunction

protected Function<?> getNodeFunction(String functionName)
Description copied from class: AbstractNode
Based on getFunctions.

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
Parameters:
functionName - name of the function
Returns:
a Parameters object.

createFunctionValue

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


MMBase 2.0-SNAPSHOT - null