1 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 ; 20 import java.util.HashMap ; 21 22 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 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 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 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 props = new HashMap (); 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 e) 100 { 101 e.printStackTrace(); 102 } 103 finally 104 { 105 if (!commited) 106 { 107 session.rollback(); 108 } 109 } 110 } 111 } 112 | Popular Tags |