1 7 package org.jboss.cache.factories; 8 9 import org.jboss.cache.CacheSPI; 10 import org.jboss.cache.Fqn; 11 import org.jboss.cache.Node; 12 import org.jboss.cache.NodeSPI; 13 import org.jboss.cache.UnversionedNode; 14 import org.jboss.cache.VersionedNode; 15 import org.jboss.cache.optimistic.TransactionWorkspace; 16 import org.jboss.cache.optimistic.WorkspaceNode; 17 import org.jboss.cache.optimistic.WorkspaceNodeImpl; 18 19 import java.util.Map ; 20 21 26 public class NodeFactory 27 { 28 public enum NodeType 29 { 30 UNVERSIONED_NODE, VERSIONED_NODE, WORKSPACE_NODE 31 } 32 33 private CacheSPI cache; 34 private boolean optimistic; 35 36 39 public NodeFactory(CacheSPI cache) 40 { 41 this.cache = cache; 42 init(); 43 } 44 45 48 public void init() 49 { 50 optimistic = cache.getConfiguration().isNodeLockingOptimistic(); 51 } 52 53 54 67 public NodeSPI createDataNode(Object childName, Fqn fqn, NodeSPI parent, Map data, boolean mapSafe) 68 { 69 return optimistic ? new VersionedNode(childName, fqn, parent, data, cache) : new UnversionedNode(childName, fqn, data, mapSafe, cache); 70 } 71 72 public Node createNode(Object childName, Node parent, Map data) 73 { 74 return createNodeOfType(parent, childName, parent, data); 75 } 76 77 public Node createNodeOfType(Node template, Object childName, Node parent, Map data) 78 { 79 if (template instanceof WorkspaceNode) 80 { 81 NodeSPI dataNodeParent = ((WorkspaceNode) parent).getNode(); 82 TransactionWorkspace workspace = ((WorkspaceNode) template).getTransactionWorkspace(); 83 return createWorkspaceNode(dataNodeParent, workspace); 84 } 85 86 return createDataNode(childName, new Fqn(parent.getFqn(), childName), (NodeSPI) parent, data, false); 88 } 89 90 public WorkspaceNode createWorkspaceNode(NodeSPI dataNode, TransactionWorkspace workspace) 91 { 92 return new WorkspaceNodeImpl(dataNode, workspace); 93 } 94 95 public NodeSPI createRootDataNode() 96 { 97 return createDataNode(null, Fqn.ROOT, null, null, false); 98 } 99 100 } 101 | Popular Tags |