org.jcrom
Class Jcrom

java.lang.Object
  extended by org.jcrom.Jcrom

public class Jcrom
extends java.lang.Object

This is the main entry class for JCROM. To use JCROM, you create an instance of this class, and add the classes you want to be mapped to it. Jcrom will validate that the classes you add can be mapped to/from JCR.

Instances of this class are thread-safe.

Author:
Olafur Gauti Gudmundsson

Constructor Summary
Jcrom()
          Create a new Jcrom instance that cleans node names, but with dynamic instantiation turned off.
Jcrom(boolean cleanNames)
          Create a new Jcrom instance with dynamic instantiation turned off.
Jcrom(boolean cleanNames, boolean dynamicInstantiation)
          Create a new Jcrom instance.
Jcrom(boolean cleanNames, boolean dynamicInstantiation, java.util.Set<java.lang.Class> classesToMap)
          Create a new Jcrom instance.
Jcrom(boolean cleanNames, java.util.Set<java.lang.Class> classesToMap)
          Create a new Jcrom instance with dynamic instantiation turned off.
Jcrom(java.util.Set<java.lang.Class> classesToMap)
          Create a new Jcrom instance with name cleaning set to true, and dynamic instantiation off.
 
Method Summary
 javax.jcr.Node addNode(javax.jcr.Node parentNode, java.lang.Object entity)
          Maps the entity supplied to a JCR node, and adds that node as a child to the parent node supplied.
 javax.jcr.Node addNode(javax.jcr.Node parentNode, java.lang.Object entity, java.lang.String[] mixinTypes)
          Maps the entity supplied to a JCR node, and adds that node as a child to the parent node supplied.
<T> T
fromNode(java.lang.Class<T> entityClass, javax.jcr.Node node)
          Maps the node supplied to an instance of the entity class.
<T> T
fromNode(java.lang.Class<T> entityClass, javax.jcr.Node node, NodeFilter nodeFilter)
          Maps the node supplied to an instance of the entity class.
<T> T
fromNode(java.lang.Class<T> entityClass, javax.jcr.Node node, java.lang.String childNodeFilter, int maxDepth)
          Maps the node supplied to an instance of the entity class.
 java.util.Set<java.lang.Class> getMappedClasses()
          Get a set of all classes that are mapped by this instance.
 java.lang.String getName(java.lang.Object object)
           
 java.lang.String getPath(java.lang.Object object)
           
 boolean isMapped(java.lang.Class entityClass)
          Check whether a specific class is mapped by this instance.
 Jcrom map(java.lang.Class entityClass)
          Add a class that this instance can map to/from JCR nodes.
 Jcrom mapPackage(java.lang.String packageName)
          Tries to map all classes in the package specified.
 Jcrom mapPackage(java.lang.String packageName, boolean ignoreInvalidClasses)
          Tries to map all classes in the package specified.
 void setBaseVersionInfo(java.lang.Object object, java.lang.String name, java.util.Calendar created)
           
 java.lang.String updateNode(javax.jcr.Node node, java.lang.Object entity)
          Update an existing JCR node with the entity supplied.
 java.lang.String updateNode(javax.jcr.Node node, java.lang.Object entity, NodeFilter nodeFilter)
          Update an existing JCR node with the entity supplied.
 java.lang.String updateNode(javax.jcr.Node node, java.lang.Object entity, java.lang.String childNodeFilter, int maxDepth)
          Update an existing JCR node with the entity supplied.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Jcrom

public Jcrom()
Create a new Jcrom instance that cleans node names, but with dynamic instantiation turned off.


Jcrom

public Jcrom(boolean cleanNames)
Create a new Jcrom instance with dynamic instantiation turned off.

Parameters:
cleanNames - specifies whether to clean names of new nodes, that is, replace illegal characters and spaces automatically

Jcrom

public Jcrom(boolean cleanNames,
             boolean dynamicInstantiation)
Create a new Jcrom instance.

Parameters:
cleanNames - specifies whether to clean names of new nodes, that is, replace illegal characters and spaces automatically
dynamicInstantiation - if set to true, then Jcrom will try to retrieve the name of the class to instantiate from a node property (see @JcrNode(classNameProperty)).

Jcrom

public Jcrom(java.util.Set<java.lang.Class> classesToMap)
Create a new Jcrom instance with name cleaning set to true, and dynamic instantiation off.

Parameters:
classesToMap - a set of classes to map by this instance

Jcrom

public Jcrom(boolean cleanNames,
             java.util.Set<java.lang.Class> classesToMap)
Create a new Jcrom instance with dynamic instantiation turned off.

Parameters:
cleanNames - specifies whether to clean names of new nodes, that is, replace illegal characters and spaces automatically
classesToMap - a set of classes to map by this instance

Jcrom

public Jcrom(boolean cleanNames,
             boolean dynamicInstantiation,
             java.util.Set<java.lang.Class> classesToMap)
Create a new Jcrom instance.

Parameters:
cleanNames - specifies whether to clean names of new nodes, that is, replace illegal characters and spaces automatically
dynamicInstantiation - if set to true, then Jcrom will try to retrieve the name of the class to instantiate from a node property (see @JcrNode(classNameProperty)).
classesToMap - a set of classes to map by this instance
Method Detail

map

public Jcrom map(java.lang.Class entityClass)
Add a class that this instance can map to/from JCR nodes. This method will validate the class, and all mapped JcrEntity implementations referenced from this class.

Parameters:
entityClass - the class that will be mapped
Returns:
the Jcrom instance

mapPackage

public Jcrom mapPackage(java.lang.String packageName)
Tries to map all classes in the package specified. Fails if one of the classes is not valid for mapping.

Parameters:
packageName - the name of the package to process
Returns:
the Jcrom instance

mapPackage

public Jcrom mapPackage(java.lang.String packageName,
                        boolean ignoreInvalidClasses)
Tries to map all classes in the package specified.

Parameters:
packageName - the name of the package to process
ignoreInvalidClasses - specifies whether to ignore classes in the package that cannot be mapped
Returns:
the Jcrom instance

getMappedClasses

public java.util.Set<java.lang.Class> getMappedClasses()
Get a set of all classes that are mapped by this instance.

Returns:
all classes that are mapped by this instance

isMapped

public boolean isMapped(java.lang.Class entityClass)
Check whether a specific class is mapped by this instance.

Parameters:
entityClass - the class we want to check
Returns:
true if the class is mapped, else false

getName

public java.lang.String getName(java.lang.Object object)
                         throws JcrMappingException
Throws:
JcrMappingException

getPath

public java.lang.String getPath(java.lang.Object object)
                         throws JcrMappingException
Throws:
JcrMappingException

setBaseVersionInfo

public void setBaseVersionInfo(java.lang.Object object,
                               java.lang.String name,
                               java.util.Calendar created)
                        throws JcrMappingException
Throws:
JcrMappingException

fromNode

public <T> T fromNode(java.lang.Class<T> entityClass,
                      javax.jcr.Node node)
           throws JcrMappingException
Maps the node supplied to an instance of the entity class. Loads all child nodes, to infinite depth.

Parameters:
entityClass - the class of the entity to be instantiated from the node (in the case of dynamic instantiation, the instance class may be read from the document, but will be cast to this class)
node - the JCR node from which to create the object
Returns:
an instance of the JCR entity class, mapped from the node
Throws:
JcrMappingException

fromNode

public <T> T fromNode(java.lang.Class<T> entityClass,
                      javax.jcr.Node node,
                      java.lang.String childNodeFilter,
                      int maxDepth)
           throws JcrMappingException
Maps the node supplied to an instance of the entity class.

Parameters:
entityClass - the class of the entity to be instantiated from the node (in the case of dynamic instantiation, the instance class may be read from the document, but will be cast to this class)
node - the JCR node from which to create the object
childNodeFilter - comma separated list of names of child nodes to load ("*" loads all, while "none" loads no children)
maxDepth - the maximum depth of loaded child nodes (0 means no child nodes are loaded, while a negative value means that no restrictions are set on the depth).
Returns:
an instance of the JCR entity class, mapped from the node
Throws:
JcrMappingException

fromNode

public <T> T fromNode(java.lang.Class<T> entityClass,
                      javax.jcr.Node node,
                      NodeFilter nodeFilter)
           throws JcrMappingException
Maps the node supplied to an instance of the entity class.

Parameters:
entityClass - the class of the entity to be instantiated from the node (in the case of dynamic instantiation, the instance class may be read from the document, but will be cast to this class)
node - the JCR node from which to create the object
nodeFilter - the NodeFilter to apply when loading child nodes and references
Returns:
an instance of the JCR entity class, mapped from the node
Throws:
JcrMappingException

addNode

public javax.jcr.Node addNode(javax.jcr.Node parentNode,
                              java.lang.Object entity)
                       throws JcrMappingException
Maps the entity supplied to a JCR node, and adds that node as a child to the parent node supplied.

Parameters:
parentNode - the parent node to which the entity node will be added
entity - the entity to be mapped to the JCR node
Returns:
the newly created JCR node
Throws:
JcrMappingException

addNode

public javax.jcr.Node addNode(javax.jcr.Node parentNode,
                              java.lang.Object entity,
                              java.lang.String[] mixinTypes)
                       throws JcrMappingException
Maps the entity supplied to a JCR node, and adds that node as a child to the parent node supplied.

Parameters:
parentNode - the parent node to which the entity node will be added
entity - the entity to be mapped to the JCR node
mixinTypes - an array of mixin type that will be added to the new node
Returns:
the newly created JCR node
Throws:
JcrMappingException

updateNode

public java.lang.String updateNode(javax.jcr.Node node,
                                   java.lang.Object entity)
                            throws JcrMappingException
Update an existing JCR node with the entity supplied.

Parameters:
node - the JCR node to be updated
entity - the entity that will be mapped to the existing node
Returns:
the name of the updated node
Throws:
JcrMappingException

updateNode

public java.lang.String updateNode(javax.jcr.Node node,
                                   java.lang.Object entity,
                                   java.lang.String childNodeFilter,
                                   int maxDepth)
                            throws JcrMappingException
Update an existing JCR node with the entity supplied.

Parameters:
node - the JCR node to be updated
entity - the entity that will be mapped to the existing node
childNodeFilter - comma separated list of names of child nodes to update ("*" updates all, while "none" updates no children)
maxDepth - the maximum depth of updated child nodes (0 means no child nodes are updated, while a negative value means that no restrictions are set on the depth).
Returns:
the name of the updated node
Throws:
JcrMappingException

updateNode

public java.lang.String updateNode(javax.jcr.Node node,
                                   java.lang.Object entity,
                                   NodeFilter nodeFilter)
                            throws JcrMappingException
Update an existing JCR node with the entity supplied.

Parameters:
node - the JCR node to be updated
entity - the entity that will be mapped to the existing node
nodeFilter - the NodeFilter to apply when updating child nodes and references
Returns:
the name of the updated node
Throws:
JcrMappingException


Copyright © 2009. All Rights Reserved.