KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * com.mckoi.database.GTProductDataSource 23 Mar 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 import java.util.ArrayList JavaDoc;
28 import com.mckoi.database.global.StandardMessages;
29
30 /**
31  * An implementation of MutableTableDataSource that models information about
32  * the software.
33  * <p>
34  * NOTE: This is not designed to be a long kept object. It must not last
35  * beyond the lifetime of a transaction.
36  *
37  * @author Tobias Downer
38  */

39
40 final class GTProductDataSource extends GTDataSource {
41
42   /**
43    * The list of info keys/values in this object.
44    */

45   private ArrayList JavaDoc key_value_pairs;
46
47   /**
48    * Constructor.
49    */

50   public GTProductDataSource(Transaction transaction) {
51     super(transaction.getSystem());
52     this.key_value_pairs = new ArrayList JavaDoc();
53   }
54
55   /**
56    * Initialize the data source.
57    */

58   public GTProductDataSource init() {
59
60     // Set up the product variables.
61
key_value_pairs.add("name");
62     key_value_pairs.add(StandardMessages.NAME);
63
64     key_value_pairs.add("version");
65     key_value_pairs.add(StandardMessages.VERSION);
66
67     key_value_pairs.add("copyright");
68     key_value_pairs.add(StandardMessages.COPYRIGHT);
69
70     return this;
71   }
72
73   // ---------- Implemented from GTDataSource ----------
74

75   public DataTableDef getDataTableDef() {
76     return DEF_DATA_TABLE_DEF;
77   }
78
79   public int getRowCount() {
80     return key_value_pairs.size() / 2;
81   }
82
83   public TObject getCellContents(final int column, final int row) {
84     switch (column) {
85       case 0: // var
86
return columnValue(column, (String JavaDoc) key_value_pairs.get(row * 2));
87       case 1: // value
88
return columnValue(column,
89                            (String JavaDoc) key_value_pairs.get((row * 2) + 1));
90       default:
91         throw new Error JavaDoc("Column out of bounds.");
92     }
93   }
94
95   // ---------- Overwritten from GTDataSource ----------
96

97   public void dispose() {
98     super.dispose();
99     key_value_pairs = null;
100   }
101
102   // ---------- Static ----------
103

104   /**
105    * The data table def that describes this table of data source.
106    */

107   static final DataTableDef DEF_DATA_TABLE_DEF;
108
109   static {
110
111     DataTableDef def = new DataTableDef();
112     def.setTableName(
113              new TableName(Database.SYSTEM_SCHEMA, "sUSRProductInfo"));
114
115     // Add column definitions
116
def.addColumn(stringColumn("var"));
117     def.addColumn(stringColumn("value"));
118
119     // Set to immutable
120
def.setImmutable();
121
122     DEF_DATA_TABLE_DEF = def;
123
124   }
125
126 }
127
Popular Tags