KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > frovi > ss > Tree > BaseNodeSupplier


1 package com.frovi.ss.Tree;
2
3 import java.util.Collection JavaDoc;
4
5 import org.exolab.castor.jdo.Database;
6 import org.infoglue.cms.exception.SystemException;
7
8 /**
9  * BaseNodeSupplier.java
10  * Created on 2002-sep-30
11  * @author Stefan Sik, ss@frovi.com
12  * ss
13  */

14 public abstract class BaseNodeSupplier implements INodeSupplier
15 {
16     private BaseNode rootNode = null;
17     
18     public boolean hasChildren()
19     {
20         return true;
21     }
22
23     public boolean hasChildren(Integer JavaDoc nodeId) throws SystemException, Exception JavaDoc
24     {
25         // Base functionallity, typically this method is overridden
26
// for performance reasons
27
Collection JavaDoc tmp = getChildContainerNodes(nodeId);
28         Collection JavaDoc tmp2 = getChildLeafNodes(nodeId);
29         return (tmp.size() + tmp2.size()) > 0;
30     }
31
32
33     /**
34      * Sets the rootNode.
35      * @param rootNode The rootNode to set
36      */

37     protected void setRootNode(BaseNode rootNode)
38     {
39         this.rootNode = rootNode;
40     }
41
42     /**
43      * Returns the rootNode.
44      * @return BaseNode
45      */

46     public BaseNode getRootNode()
47     {
48         return rootNode;
49     }
50
51     
52     /**
53      * Begins a transaction on the named database
54      */

55      
56     protected void beginTransaction(Database db) throws SystemException
57     {
58         try
59         {
60             db.begin();
61         }
62         catch(Exception JavaDoc e)
63         {
64             e.printStackTrace();
65             throw new SystemException("An error occurred when we tried to begin an transaction. Reason:" + e.getMessage(), e);
66         }
67     }
68     
69  
70     
71     /**
72      * Ends a transaction on the named database
73      */

74      
75     protected void commitTransaction(Database db) throws SystemException
76     {
77         try
78         {
79             db.commit();
80             db.close();
81         }
82         catch(Exception JavaDoc e)
83         {
84             e.printStackTrace();
85             throw new SystemException("An error occurred when we tried to commit an transaction. Reason:" + e.getMessage(), e);
86         }
87     }
88  
89  
90     /**
91      * Rollbacks a transaction on the named database if there is an open transaction
92      */

93      
94     protected void rollbackTransaction(Database db) throws SystemException
95     {
96         try
97         {
98             if (db.isActive())
99             {
100                 db.rollback();
101                 db.close();
102             }
103         }
104         catch(Exception JavaDoc e)
105         {
106             e.printStackTrace();
107             throw new SystemException("An error occurred when we tried to rollback an transaction. Reason:" + e.getMessage(), e);
108         }
109     }
110
111 }
112
Popular Tags