KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > CollectionName


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.extractor.algebra;
24
25 import org.xquark.extractor.common.SqlWrapperException;
26
27 public final class CollectionName {
28
29     private static final String JavaDoc RCSRevision = "$Revision: 1.4 $";
30     private static final String JavaDoc RCSName = "$Name: $";
31
32
33     private String JavaDoc _dataSource = null;
34     private String JavaDoc _catalog = null;
35     private String JavaDoc _schema = null;
36     private String JavaDoc _table = null;
37
38     public CollectionName(String JavaDoc source, String JavaDoc collection) throws SqlWrapperException{
39         //Trace.enter(this, " Collection_Name(String name)",""/*source+":"+collection*/);
40
// change LARS 07/04/04
41
_dataSource = source;
42         int index = -1;
43         String JavaDoc [] steps = new String JavaDoc[3];
44         int newIndex = -1;
45         int stepCursor = 0;
46         while (true) {
47             newIndex = collection.indexOf(".", index + 1);
48             if (-1 != newIndex) {
49                 steps [stepCursor] = collection.substring(index + 1, newIndex);
50                 if (0 ==steps [stepCursor].length()) {
51                     throw new SqlWrapperException("Collection name string is not valid.");
52                 }
53                 index = newIndex;
54                 stepCursor ++;
55             }
56             else {
57                 steps [stepCursor] = collection.substring(index + 1, collection.length());
58                 if (0 ==steps [stepCursor].length()) {
59                     throw new SqlWrapperException("Collection name string is not valid.");
60                 }
61                 stepCursor ++;
62                 break;
63             }
64         }
65         if (1 == stepCursor) {
66             _table = steps[0];
67         }
68         else if (2 == stepCursor) {
69             _schema = steps[0];
70             _table = steps[1];
71         }
72         else if (3 == stepCursor) {
73             _catalog = steps[0];
74             _schema = steps[1];
75             _table = steps[2];
76         }
77         else {
78             throw new SqlWrapperException("Collection name string is not valid.");
79         }
80         //Trace.exit(this, " Collection_Name(String name)", source+":"+collection);
81
}
82
83     public String JavaDoc getDataSource() { return _dataSource;}
84
85     public String JavaDoc getCatalog() { return _catalog;}
86
87     public String JavaDoc getSchema() { return _schema; }
88     public void setSchema(String JavaDoc schema) { _schema = schema; }
89
90     public boolean dataSourceIsWildCard()
91     {
92         boolean retVal = false;
93         if (null != _dataSource){
94             if (_dataSource.equals("*")) {
95                 retVal = true;
96             }
97         }
98         return retVal;
99     }
100
101     public boolean catalogIsWildCard()
102     {
103         boolean retVal = false;
104         if (null != _catalog){
105             if (_catalog.equals("*")) {
106                 retVal = true;
107             }
108         }
109         return retVal;
110     }
111
112     public boolean schemaIsWildCard()
113     {
114         boolean retVal = false;
115         if (null != _schema){
116             if (_schema.equals("*")) {
117                 retVal = true;
118             }
119         }
120         return retVal;
121     }
122
123     public boolean tableIsWildCard()
124     {
125         boolean retVal = false;
126         if (null != _table){
127             if (_table.equals("*")) {
128                 retVal = true;
129             }
130         }
131         return retVal;
132     }
133
134     public String JavaDoc getTable() { return _table; }
135
136     public void setTable(String JavaDoc table) { _table = table; }
137
138     public String JavaDoc pprint() {
139         //Trace.enter(this, "pprint()");
140

141         StringBuffer JavaDoc retVal = new StringBuffer JavaDoc();
142         if (null != _dataSource) {
143             retVal.append(_dataSource);
144             retVal.append(":");
145         }
146
147         if (null != _catalog) {
148             retVal.append(_catalog);
149             retVal.append(".");
150         }
151
152         if (null != _schema) {
153             retVal.append(_schema);
154             retVal.append(".");
155         }
156
157         if (null != _table) {
158             retVal.append(_table);
159             retVal.append(".");
160         }
161
162         //Trace.exit(this, "pprint()");
163
return retVal.toString();
164     }
165
166 // public static void main(String args[]) throws Exception {
167
// CollectionName cn = new CollectionName("extractor:pubs.dbo.jobs");
168
// System.out.println(cn.pprint());
169
// }
170

171     public boolean equals(Object JavaDoc o) {
172         if (o instanceof CollectionName) {
173             CollectionName cast = (CollectionName) o;
174             return _dataSource.equalsIgnoreCase(cast.getDataSource())
175                 && _catalog.equalsIgnoreCase(cast.getDataSource())
176                 && _schema.equalsIgnoreCase(cast.getSchema())
177                 && _table.equalsIgnoreCase(cast.getTable());
178         }
179         return false;
180     }
181 }
182
Popular Tags