KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > optimistic > TransactionWorkspaceImpl


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.optimistic;
8
9 import org.jboss.cache.Fqn;
10
11 import java.util.Map JavaDoc;
12 import java.util.SortedMap JavaDoc;
13 import java.util.TreeMap JavaDoc;
14 import java.util.concurrent.ConcurrentHashMap JavaDoc;
15
16 /**
17  * Contains a mapping of Fqn to {@link WorkspaceNode}s.
18  * Each entry corresponds to a series of changed nodes within the transaction.
19  *
20  * @author Manik Surtani (<a HREF="mailto:manik@jboss.org">manik@jboss.org</a>)
21  * @author Steve Woodcock (<a HREF="mailto:stevew@jofti.com">stevew@jofti.com</a>)
22  */

23 public class TransactionWorkspaceImpl implements TransactionWorkspace
24 {
25
26    private Map JavaDoc<Fqn, WorkspaceNode> nodes;
27    private boolean versioningImplicit = true;
28
29    public TransactionWorkspaceImpl()
30    {
31       nodes = new ConcurrentHashMap JavaDoc<Fqn, WorkspaceNode>();
32    }
33
34    /**
35     * Returns the nodes.
36     */

37    public Map JavaDoc<Fqn, WorkspaceNode> getNodes()
38    {
39       return nodes;
40    }
41
42    /**
43     * Sets the nodes.
44     */

45    public void setNodes(Map JavaDoc<Fqn, WorkspaceNode> nodes)
46    {
47       this.nodes = nodes;
48    }
49
50    public WorkspaceNode getNode(Fqn fqn)
51    {
52       return nodes.get(fqn);
53    }
54
55    public void addNode(WorkspaceNode node)
56    {
57       nodes.put(node.getFqn(), node);
58    }
59
60    public Object JavaDoc removeNode(Fqn fqn)
61    {
62       return nodes.remove(fqn);
63    }
64
65    public SortedMap JavaDoc<Fqn, WorkspaceNode> getNodesAfter(Fqn fqn)
66    {
67       SortedMap JavaDoc<Fqn, WorkspaceNode> sm = new TreeMap JavaDoc<Fqn, WorkspaceNode>();
68       sm.putAll(nodes);
69       return sm.tailMap(fqn);
70    }
71
72    public boolean isVersioningImplicit()
73    {
74       return versioningImplicit;
75    }
76
77    public void setVersioningImplicit(boolean versioningImplicit)
78    {
79       this.versioningImplicit = versioningImplicit;
80    }
81
82    public boolean hasNode(Fqn fqn)
83    {
84       return nodes.containsKey(fqn);
85    }
86
87    /**
88     * Returns debug information.
89     */

90    public String JavaDoc toString()
91    {
92       return "Workspace nodes=" + nodes;
93    }
94 }
95
Popular Tags