org.axonframework.mongo3.serializer.bson
Class BSONNode

java.lang.Object
  extended by org.axonframework.mongo3.serializer.bson.BSONNode

public class BSONNode
extends Object

Represents a node in a BSON structure. This class provides for an XML like abstraction around BSON for use by the XStream Serializer.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
BSONNode(String name)
          Creates a node with given "code" name.
 
Method Summary
 BSONNode addChildNode(String name)
          Adds a child node to the current node.
 com.mongodb.DBObject asDBObject()
          Returns the current BSON structure as DBObject.
 Map<String,String> attributes()
          Returns a map containing the attributes of the current node.
 Iterator<BSONNode> children()
          Returns an iterator providing access to the child nodes of the current node.
static BSONNode fromDBObject(com.mongodb.DBObject node)
          Constructrs a BSONNode structure from the given DBObject structure.
 String getAttribute(String name)
          Returns the value of the attribute with given name.
 String getName()
          Returns the name of the current node
 String getValue()
          Returns the value of the current node
 void setAttribute(String attributeName, String attributeValue)
          Sets an attribute to this node.
 void setValue(String value)
          Sets the value of this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BSONNode

public BSONNode(String name)
Creates a node with given "code" name. Generally, this constructor is used for the root node. For child nodes, see the convenience method addChildNode(String).

Note that the given name is encoded in a BSON compatible way. That means that periods (".") are replaced by forward slashes "/", and any slashes are prefixes with additional slash. For example, the String "some.period/slash" would become "some/period//slash". This is only imporant when querying BSON structures directly.

Parameters:
name - The name of this node
Method Detail

fromDBObject

public static BSONNode fromDBObject(com.mongodb.DBObject node)
Constructrs a BSONNode structure from the given DBObject structure. The node returned is the root node.

Parameters:
node - The root DBObject node containing the BSON Structure
Returns:
The BSONNode representing the root of the BSON structure

asDBObject

public com.mongodb.DBObject asDBObject()
Returns the current BSON structure as DBObject.

Returns:
the current BSON structure as DBObject

setValue

public void setValue(String value)
Sets the value of this node. Note that a node can contain either a value, or child nodes

Parameters:
value - The value to set for this node

setAttribute

public void setAttribute(String attributeName,
                         String attributeValue)
Sets an attribute to this node. Since JSON (and BSON) do not have the notion of attributes, these are modelled as child nodes with their name prefixed with "attr_". Attributes are represented as nodes that always exclusively contain a value.

Parameters:
attributeName - The name of the attribute to add
attributeValue - The value of the attribute

addChildNode

public BSONNode addChildNode(String name)
Adds a child node to the current node. Note that the name of a child node must not be null and may not start with "attr_", in order to differentiate between child nodes and attributes.

Parameters:
name - The name of the child node
Returns:
A BSONNode representing the newly created child node.

children

public Iterator<BSONNode> children()
Returns an iterator providing access to the child nodes of the current node. Changes to the node structure made after this iterator is returned may not be reflected in that iterator.

Returns:
an iterator providing access to the child nodes of the current node

attributes

public Map<String,String> attributes()
Returns a map containing the attributes of the current node. Changes to the node's attributes made after this iterator is returned may not be reflected in that iterator.

Returns:
a Map containing the attributes of the current node

getAttribute

public String getAttribute(String name)
Returns the value of the attribute with given name.

Parameters:
name - The name of the attribute to get the value for
Returns:
the value of the attribute, or null if the attribute was not found

getValue

public String getValue()
Returns the value of the current node

Returns:
the value of the current node, or null if this node has no value.

getName

public String getName()
Returns the name of the current node

Returns:
the name of the current node


Copyright © 2010-2016. All Rights Reserved.