Project

General

Profile

« Previous | Next » 

Revision 3754

Added by Jing Tao almost 17 years ago

Remove an obsolete class.

View differences:

src/edu/ucsb/nceas/metacat/FilteredSubTree.java
1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A Class that represents an XML Text node and its contents,
4
 *             and can build itself from a database connection
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Matt Jones
8
 *
9
 *   '$Author$'
10
 *     '$Date$'
11
 * '$Revision$'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28
package edu.ucsb.nceas.metacat;
29

  
30
import java.util.Enumeration;
31
import java.util.Collections;
32
import java.util.Hashtable;
33
import java.util.Stack;
34
import java.util.Vector;
35
import java.sql.PreparedStatement;
36
import java.sql.SQLException;
37
import java.sql.ResultSet;
38

  
39
import org.apache.log4j.Logger;
40

  
41

  
42
/**
43
 * A Class that represents an Filtered XML Subtree, it means a subtree which 
44
 * contains another subtree has different access behavor to it.
45
 * for example, we have subtree A, it is not readable to user John. But in 
46
 * subtree A, it contains a subtree B which is readable to user John 
47
 */
48
public class FilteredSubTree
49
{
50
  private String docId = null;
51
  private String subTreeId = null;
52
  private String startElementName = null;
53
  private long   startNodeId = -1;
54
  private long   endNodeId =   -1;
55
  private Vector sortedFilteredSubTree = new Vector();
56
  private Logger logMetacat = Logger.getLogger(FilteredSubTree.class);
57
    
58
    /**
59
     * Constructor of filteredsubtree
60
     */
61
    public FilteredSubTree(String myDocId, String mySubTreeId, 
62
                  long myStartNodeId, long myEndNodeId)
63
                  throws McdbException
64
    {
65
      this.docId = myDocId;
66
      logMetacat.info("Docid of FilteredSubtree: " + docId);
67
      this.subTreeId = mySubTreeId;
68
      logMetacat.info("id of FilteredSubtree: " + subTreeId);
69
      this.startNodeId = myStartNodeId;
70
      logMetacat.info("start node id of FilteredSubtree: " + 
71
                                startNodeId);
72
      this.endNodeId = myEndNodeId;
73
      logMetacat.info("end node id of FilteredSubtree: " + endNodeId);
74
     }
75
    
76
  
77
 
78
    /** Set the a docId */
79
    public void setDocId(String myId)
80
    {
81
      logMetacat.info("set doc id: "+myId);
82
      this.docId = myId;
83
    }
84

  
85
    /** Get the docId */
86
    public String getDocId() 
87
    {
88
      return this.docId;
89
    }
90

  
91
 
92
    /** Set the a subtreeId */
93
    public void setSubTreeId(String myId)
94
    {
95
      logMetacat.info("set sub tree id: "+myId);
96
      this.subTreeId = myId;
97
    }
98

  
99
    /** Get the subTreeId */
100
    public String getSubTreeId() 
101
    {
102
      return this.subTreeId;
103
    }
104

  
105
    /** 
106
     * Set a startElementName
107
     */
108
    public void setStartElementName(String elementName) 
109
    {
110
      logMetacat.info("set start elementname: "+elementName);
111
      this.startElementName = elementName;
112
    }
113
    
114
    /**
115
     * Get startElementName
116
     */
117
    public String getStartElementName()
118
    {
119
      return this.startElementName;
120
    }
121
    
122
    /** Set a start node id */
123
    public void setStartNodeId(long nodeId)
124
    {
125
      logMetacat.info("set start node id: "+nodeId);
126
      this.startNodeId = nodeId;
127
    }
128
    
129
    /** Get start node id */
130
    public long getStartNodeId()
131
    {
132
      return this.startNodeId;
133
    }
134
    
135
    /** Set a end node id */
136
    public void setEndNodeId(long nodeId)
137
    {
138
      logMetacat.info("set end node id: "+nodeId);
139
      this.endNodeId = nodeId;
140
    }
141
    
142
    /** Get end node id */
143
    public long getEndNodeId()
144
    {
145
      return this.endNodeId;
146
    }
147
    
148
    /** Set a filtered subtree(subtree should be merger equivlent */
149
    public void setFilteredSubTree(Hashtable  tree)
150
    {
151
       // order the subtree vector by start node id
152
       // because the subtree is mergeEquivlent, so there is no nested subtree
153
       Enumeration en = tree.elements();
154
       while (en.hasMoreElements())
155
       {
156
         SubTree sTree = (SubTree) en.nextElement();
157
         sortedFilteredSubTree.add(sTree);
158
       }
159
       Collections.sort(sortedFilteredSubTree, new SubTree());
160
    }
161
    
162
    /** Get the filted subtree vector*/
163
    public Vector getFilteredSubTree()
164
    {
165
      return sortedFilteredSubTree;
166
    }
167
    
168
   /** Get unfiltered subtree node list*/
169
    public Stack getUnfilteredSubTreeNodeList() throws McdbException
170
    {
171
       
172
       PreparedStatement pstmt = null;
173
       DBConnection dbconn = null;
174
       int serialNumber = -1;
175
       Stack nodeRecordList = new Stack();
176
       long nodeid = 0;
177
       long parentnodeid = 0;
178
       long nodeindex = 0;
179
       String nodetype = null;
180
       String nodename = null;
181
       String nodeprefix = null;
182
       String nodedata = null;
183
       String sql = "SELECT nodeid, parentnodeid, nodeindex, " +
184
                    "nodetype, nodename, nodeprefix, nodedata " +               
185
                    "FROM xml_nodes WHERE docid = ? AND ((nodeid >= ? AND ";
186
       for ( int i =0; i< sortedFilteredSubTree.size(); i++)
187
       {
188
         sql = sql + "nodeid < ? ) OR (nodeid > ? AND "; 
189
       }
190
       sql = sql + "nodeid <= ? )) ORDER BY nodeid DESC";
191
       logMetacat.info("sql command for selecting filtere subtree is: "
192
                                 +sql);
193
       
194
       try 
195
       {
196
         dbconn=DBConnectionPool.
197
                    getDBConnection("SubTree.getSubTreeNodeList");
198
         serialNumber=dbconn.getCheckOutSerialNumber();
199
         pstmt = dbconn.prepareStatement(sql);
200

  
201
         // Bind the values to the query
202
         pstmt.setString(1, docId);
203
         pstmt.setLong(2, startNodeId);
204
         int i =0;
205
         boolean inLoop = false;
206
         for (i=0; i< sortedFilteredSubTree.size(); i++)
207
         {
208
           SubTree tree = (SubTree)sortedFilteredSubTree.elementAt(i);
209
           long startId = tree.getStartNodeId();
210
           long endId   = tree.getEndNodeId();
211
           pstmt.setLong((2*i+3), startId);
212
           pstmt.setLong((2*i+4), endId);
213
           inLoop = true;
214
         }
215
         if (inLoop)
216
         {
217
           pstmt.setLong((2*i+5), endNodeId);
218
         }
219
         else
220
         {
221
           pstmt.setLong(3, endNodeId);
222
         }
223

  
224
         pstmt.execute();
225
         ResultSet rs = pstmt.getResultSet();
226
         boolean tableHasRows = rs.next();
227
        
228
         while (tableHasRows) 
229
         {
230
           nodeid = rs.getLong(1);
231
           parentnodeid = rs.getLong(2);
232
           nodeindex = rs.getLong(3);
233
           nodetype = rs.getString(4);
234
           nodename = rs.getString(5);
235
           nodeprefix = rs.getString(6);
236
           nodedata = rs.getString(7);
237
           nodedata = MetaCatUtil.normalize(nodedata);
238
           // add the data to the node record list hashtable
239
           NodeRecord currentRecord = new NodeRecord(nodeid,parentnodeid,nodeindex,
240
                                      nodetype, nodename, nodeprefix, nodedata);
241
           nodeRecordList.push(currentRecord);
242

  
243
           // Advance to the next node
244
           tableHasRows = rs.next();
245
         }//while
246
         pstmt.close();
247

  
248
      } //try
249
      catch (SQLException e) 
250
      {
251
        throw new McdbException("Error in FilteredSubTree.getSubTreeNodeList 1 " +
252
                              e.getMessage());
253
      }//catch
254
      finally
255
      {
256
        try
257
        {
258
          pstmt.close();
259
        }
260
        catch (SQLException ee)
261
        {
262
          logMetacat.error("error in FilteredSubTree.getSubTreeNodeList 2: "
263
                                    +ee.getMessage());
264
        }
265
        finally
266
        {
267
          DBConnectionPool.returnDBConnection(dbconn, serialNumber);
268
        }
269
      }//finally
270
  
271
      return nodeRecordList;
272
   
273
    }//getSubtreeNodeList
274
    
275
    public static void main (String agus)
276
    {
277
      
278
    }
279
}
280 0

  

Also available in: Unified diff