KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > core > impl > security > SchemeStoreImpl


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.security;
10
11 import org.jboss.portal.common.tree.Tree;
12 import org.jboss.portal.common.tree.Node;
13 import org.jboss.portal.common.tree.Session;
14 import org.jboss.portal.common.tree.TreeException;
15 import org.jboss.portal.common.FQN;
16 import org.jboss.portal.core.security.SchemeStore;
17 import org.jboss.portal.core.security.Scheme;
18
19 import java.util.Map JavaDoc;
20 import java.util.HashMap JavaDoc;
21
22 /**
23  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
24  * @version $Revision: 1.2 $
25  */

26 public class SchemeStoreImpl implements SchemeStore
27 {
28
29    private Tree tree;
30    private FQN fqn;
31
32    public SchemeStoreImpl(Tree tree, FQN fqn)
33    {
34       this.tree = tree;
35       this.fqn = fqn;
36    }
37
38    public Scheme getScheme(String JavaDoc id)
39    {
40       id = "default";
41       Node node = tree.getNode(fqn);
42       if (node != null)
43       {
44          return (Scheme)node.getProperty(id);
45       }
46       return null;
47    }
48
49    public void removeScheme(String JavaDoc id)
50    {
51       id = "default";
52       Node node = tree.getNode(fqn);
53       boolean commited = false;
54       if (node != null)
55       {
56          Session session = tree.getSession();
57          try
58          {
59             session.removeChild(node, id);
60             session.commit();
61             commited = true;
62          }
63          catch (TreeException e)
64          {
65             e.printStackTrace();
66          }
67          finally
68          {
69             if (!commited)
70             {
71                session.rollback();
72             }
73          }
74       }
75    }
76
77    public void saveScheme(String JavaDoc id, Scheme scheme)
78    {
79       id = "default";
80       Session session = null;
81       boolean commited = false;
82       try
83       {
84          session = tree.getSession();
85          Node node = tree.getNode(fqn);
86          if (node == null)
87          {
88             Map JavaDoc props = new HashMap JavaDoc();
89             props.put(id, scheme);
90             node = session.createNode(fqn, props);
91          }
92          else
93          {
94             session.setProperty(node, id, scheme);
95          }
96          session.commit();
97          commited = true;
98       }
99       catch (Throwable JavaDoc e)
100       {
101          e.printStackTrace();
102       }
103       finally
104       {
105          if (!commited)
106          {
107             session.rollback();
108          }
109       }
110    }
111 }
112
Popular Tags