KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > impl > tree > SessionImpl


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.core.impl.tree;
10
11 import org.jboss.portal.common.tree.Session;
12 import org.jboss.portal.common.tree.Tree;
13 import org.jboss.portal.common.tree.Node;
14 import org.jboss.portal.common.tree.TreeException;
15 import org.jboss.portal.common.FQN;
16
17 import javax.transaction.Transaction JavaDoc;
18 import javax.transaction.SystemException JavaDoc;
19 import javax.transaction.HeuristicMixedException JavaDoc;
20 import javax.transaction.HeuristicRollbackException JavaDoc;
21 import javax.transaction.RollbackException JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * Implementation of Session.
26  *
27  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
28  * @version $Revision: 1.1 $
29  */

30 public class SessionImpl implements Session
31 {
32
33    private final TreeImpl model;
34    private Transaction JavaDoc tx;
35
36    SessionImpl(TreeImpl model, Transaction JavaDoc tx)
37    {
38       this.model = model;
39       this.tx = tx;
40    }
41
42    public Tree getTree()
43    {
44       return model;
45    }
46
47    public void rollback()
48    {
49       if (tx == null)
50       {
51          throw new IllegalStateException JavaDoc();
52       }
53       try
54       {
55          tx.rollback();
56          tx = null;
57       }
58       catch (SystemException JavaDoc e)
59       {
60          e.printStackTrace();
61       }
62    }
63
64    public void commit()
65    {
66       if (tx == null)
67       {
68          throw new IllegalStateException JavaDoc();
69       }
70       try
71       {
72          tx.commit();
73          tx = null;
74       }
75       catch (SystemException JavaDoc e)
76       {
77          e.printStackTrace();
78       }
79       catch (HeuristicMixedException JavaDoc e)
80       {
81          e.printStackTrace();
82       }
83       catch (HeuristicRollbackException JavaDoc e)
84       {
85          e.printStackTrace();
86       }
87       catch (RollbackException JavaDoc e)
88       {
89          e.printStackTrace();
90       }
91    }
92
93    public void setProperty(Node node, String JavaDoc key, Object JavaDoc value)
94    {
95       model.setProperty((NodeImpl)node, key, value);
96    }
97
98    public void removeProperty(Node node, String JavaDoc key)
99    {
100       model.removeProperty((NodeImpl)node, key);
101    }
102
103    public Node addChild(Node parent, String JavaDoc key, Map JavaDoc properties)
104    {
105       return model.addChild((NodeImpl)parent, key, properties);
106    }
107
108    public Node createNode(FQN fqn, Map JavaDoc properties) throws TreeException, IllegalArgumentException JavaDoc, IllegalStateException JavaDoc
109    {
110       return model.addNode(fqn, properties);
111    }
112
113    public void removeChild(Node parent, String JavaDoc key)
114    {
115       model.removeChild((NodeImpl)parent, key);
116    }
117 }
118
Popular Tags