1 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 ; 18 import javax.transaction.SystemException ; 19 import javax.transaction.HeuristicMixedException ; 20 import javax.transaction.HeuristicRollbackException ; 21 import javax.transaction.RollbackException ; 22 import java.util.Map ; 23 24 30 public class SessionImpl implements Session 31 { 32 33 private final TreeImpl model; 34 private Transaction tx; 35 36 SessionImpl(TreeImpl model, Transaction 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 (); 52 } 53 try 54 { 55 tx.rollback(); 56 tx = null; 57 } 58 catch (SystemException e) 59 { 60 e.printStackTrace(); 61 } 62 } 63 64 public void commit() 65 { 66 if (tx == null) 67 { 68 throw new IllegalStateException (); 69 } 70 try 71 { 72 tx.commit(); 73 tx = null; 74 } 75 catch (SystemException e) 76 { 77 e.printStackTrace(); 78 } 79 catch (HeuristicMixedException e) 80 { 81 e.printStackTrace(); 82 } 83 catch (HeuristicRollbackException e) 84 { 85 e.printStackTrace(); 86 } 87 catch (RollbackException e) 88 { 89 e.printStackTrace(); 90 } 91 } 92 93 public void setProperty(Node node, String key, Object value) 94 { 95 model.setProperty((NodeImpl)node, key, value); 96 } 97 98 public void removeProperty(Node node, String key) 99 { 100 model.removeProperty((NodeImpl)node, key); 101 } 102 103 public Node addChild(Node parent, String key, Map properties) 104 { 105 return model.addChild((NodeImpl)parent, key, properties); 106 } 107 108 public Node createNode(FQN fqn, Map properties) throws TreeException, IllegalArgumentException , IllegalStateException 109 { 110 return model.addNode(fqn, properties); 111 } 112 113 public void removeChild(Node parent, String key) 114 { 115 model.removeChild((NodeImpl)parent, key); 116 } 117 } 118 | Popular Tags |