Clover coverage report -
Coverage timestamp: Thu Jul 5 2007 20:02:32 EDT
file stats: LOC: 94   Methods: 7
NCLOC: 49   Classes: 2
 
 Source file Conditionals Statements Methods TOTAL
NodeFactory.java 75% 75% 100% 82.6%
coverage coverage
 1    /*
 2    * JBoss, Home of Professional Open Source
 3    *
 4    * Distributable under LGPL license.
 5    * See terms of license at gnu.org.
 6    */
 7    package org.jboss.cache;
 8   
 9    import org.jboss.cache.optimistic.TransactionWorkspace;
 10    import org.jboss.cache.optimistic.WorkspaceNode;
 11    import org.jboss.cache.optimistic.WorkspaceNodeImpl;
 12   
 13    import java.util.Map;
 14   
 15    /**
 16    * Generates new nodes based on the {@link CacheSPI} configuration.
 17    *
 18    * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a>
 19    */
 20    public class NodeFactory<K, V>
 21    {
 22    public enum NodeType
 23    {
 24    UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE
 25    }
 26   
 27    private CacheSPI<K, V> cache;
 28    private boolean optimistic;
 29   
 30    /**
 31    * Constructs an instance of the factory
 32    */
 33  2806 public NodeFactory(CacheSPI<K, V> cache)
 34    {
 35  2806 this.cache = cache;
 36  2806 init();
 37    }
 38   
 39    /**
 40    * Initialises the node factory with the configuration from the cache.
 41    */
 42  2832 public void init()
 43    {
 44  2832 optimistic = cache.getConfiguration().isNodeLockingOptimistic();
 45    }
 46   
 47   
 48    /**
 49    * Creates a new {@link Node} instance.
 50    *
 51    * @param childName the new node's name
 52    * @param fqn the new node's Fqn
 53    * @param parent the new node's parent
 54    * @param data the new node's attribute map
 55    * @param mapSafe <code>true</code> if param <code>data</code> can safely
 56    * be directly assigned to the new node's data field;
 57    * <code>false</code> if param <code>data</code>'s contents
 58    * should be copied into the new node's data field.
 59    * @return the new node
 60    */
 61  181022 public NodeSPI<K, V> createDataNode(Object childName, Fqn fqn, NodeSPI<K, V> parent, Map<K, V> data, boolean mapSafe)
 62    {
 63  181022 return optimistic ? new VersionedNode<K, V>(fqn, parent, data, cache) : new UnversionedNode<K, V>(childName, fqn, data, mapSafe, cache);
 64    }
 65   
 66  166116 public Node<K, V> createNode(Object childName, Node<K, V> parent, Map<K, V> data)
 67    {
 68  166125 return createNodeOfType(parent, childName, parent, data);
 69    }
 70   
 71  167528 public Node<K, V> createNodeOfType(Node<K, V> template, Object childName, Node<K, V> parent, Map<K, V> data)
 72    {
 73  167528 if (template instanceof WorkspaceNode)
 74    {
 75  0 NodeSPI<K, V> dataNodeParent = ((WorkspaceNode<K, V>) parent).getNode();
 76  0 TransactionWorkspace workspace = ((WorkspaceNode) template).getTransactionWorkspace();
 77  0 return createWorkspaceNode(dataNodeParent, workspace);
 78    }
 79   
 80    // not a workspace node.
 81  167528 return createDataNode(childName, new Fqn(parent.getFqn(), childName), (NodeSPI<K, V>) parent, data, false);
 82    }
 83   
 84  1053958 public WorkspaceNode<K, V> createWorkspaceNode(NodeSPI<K, V> dataNode, TransactionWorkspace workspace)
 85    {
 86  1053958 return new WorkspaceNodeImpl<K, V>(dataNode, workspace);
 87    }
 88   
 89  2832 public NodeSPI<K, V> createRootDataNode()
 90    {
 91  2832 return createDataNode(null, Fqn.ROOT, null, null, false);
 92    }
 93   
 94    }