KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mckoi > database > AbstractInternalTableInfo


1 /**
2  * com.mckoi.database.AbstractInternalTableInfo 23 Aug 2002
3  *
4  * Mckoi SQL Database ( http://www.mckoi.com/database )
5  * Copyright (C) 2000, 2001, 2002 Diehl and Associates, Inc.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * Version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License Version 2 for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * Version 2 along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  *
20  * Change Log:
21  *
22  *
23  */

24
25 package com.mckoi.database;
26
27 /**
28  * An implementation of InternalTableInfo that provides a number of methods to
29  * aid in the productions of the InternalTableInfo interface.
30  * <p>
31  * This leaves the 'createInternalTable' method implementation to the derived
32  * class.
33  *
34  * @author Tobias Downer
35  */

36
37 abstract class AbstractInternalTableInfo implements InternalTableInfo {
38
39     /**
40    * The list of table names (as TableName) that this object maintains.
41    */

42   private TableName[] table_list;
43
44   /**
45    * The list of DataTableDef objects that descibe each table in the above
46    * list.
47    */

48   private DataTableDef[] table_def_list;
49
50   /**
51    * The table type of table objects returned by this method.
52    */

53   private String JavaDoc table_type;
54   
55   /**
56    * Constructs the container than manages the creation of the given table
57    * objects.
58    */

59   AbstractInternalTableInfo(String JavaDoc type, DataTableDef[] table_def_list) {
60     this.table_def_list = table_def_list;
61     this.table_type = type;
62     table_list = new TableName[table_def_list.length];
63     for (int i = 0; i < table_list.length; ++i) {
64       table_list[i] = table_def_list[i].getTableName();
65     }
66   }
67
68   /**
69    * Returns the number of internal table sources that this object is
70    * maintaining.
71    */

72   public int getTableCount() {
73     return table_list.length;
74   }
75
76   /**
77    * Finds the index in this container of the given table name, otherwise
78    * returns -1.
79    */

80   public int findTableName(TableName name) {
81     for (int i = 0; i < table_list.length; ++i) {
82       if (table_list[i].equals(name)) {
83         return i;
84       }
85     }
86     return -1;
87   }
88
89   /**
90    * Returns the name of the table at the given index in this container.
91    */

92   public TableName getTableName(int i) {
93     return table_list[i];
94   }
95
96   /**
97    * Returns the DataTableDef object that describes the table at the given
98    * index in this container.
99    */

100   public DataTableDef getDataTableDef(int i) {
101     return table_def_list[i];
102   }
103
104   /**
105    * Returns true if this container contains a table with the given name.
106    */

107   public boolean containsTableName(TableName name) {
108     return findTableName(name) != -1;
109   }
110
111   /**
112    * Returns a String that describes the type of the table at the given index.
113    */

114   public String JavaDoc getTableType(int i) {
115     return table_type;
116   }
117   
118 }
119
120
Popular Tags