KickJava   Java API By Example, From Geeks To Geeks.

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


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
24 package org.xquark.extractor.algebra;
25
26
27 import java.util.ArrayList JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.xquark.extractor.common.Debug;
34
35 public final class SqlTypeStructure extends SqlType{
36     protected String JavaDoc _name = null;
37     protected List JavaDoc _attributes = null;
38
39     private static Log log = LogFactory.getLog(SqlTypeStructure.class);
40
41     public SqlTypeStructure()
42     {
43     }
44
45     public SqlTypeStructure(String JavaDoc name, List JavaDoc attributes,int multiplicity )
46     {
47         setName(name);
48         setAttributes (attributes);
49         setMultiplicity (multiplicity);
50     }
51
52     public SqlTypeStructure(List JavaDoc attributes,int multiplicity )
53     {
54         setAttributes (attributes);
55         setMultiplicity (multiplicity);
56     }
57
58     public SqlTypeStructure(List JavaDoc attributes )
59     {
60         setAttributes (attributes);
61     }
62
63     public Object JavaDoc clone() {
64         //Trace.enter(this, "clone()");
65
try {
66             SqlTypeStructure retVal = (SqlTypeStructure)super.clone();
67             if (null != _attributes) {
68                 retVal.setAttributes( AlgebraTools.clone(_attributes));
69             }
70             //Trace.exit(this, "clone()");
71
return retVal;
72         }
73         catch (CloneNotSupportedException JavaDoc ex) {
74             Debug.assertTrue(false, "error in implementation of clone");
75             //Trace.exit(this, "clone()");
76
return null;
77         }
78
79     }
80
81     public String JavaDoc getName()
82     {
83         return _name;
84     }
85
86     public void setName(String JavaDoc aName)
87     {
88         _name = aName;
89     }
90
91     public List JavaDoc getAttributes()
92     {
93         return _attributes;
94     }
95
96
97     public void setAttributes(List JavaDoc aAttributes)
98     {
99         _attributes = aAttributes;
100     }
101
102     public void addAttribute (SqlTypeAtom atom )
103     {
104         if (null==_attributes){
105             _attributes = new ArrayList JavaDoc();
106         }
107         _attributes.add(atom);
108     }
109
110     public void addAttributes (List JavaDoc attributes)
111     {
112         if (null==_attributes){
113             _attributes = new ArrayList JavaDoc();
114         }
115         _attributes.addAll(attributes);
116     }
117
118
119     public List JavaDoc getTypes()
120     {
121         ArrayList JavaDoc retVal = new ArrayList JavaDoc();
122
123         Iterator JavaDoc iter = _attributes.iterator();
124         while (iter.hasNext()) {
125             retVal.add( ((SqlTypeAtom)iter.next()).getType() );
126         }
127         return retVal;
128     }
129
130
131     public List JavaDoc getNames()
132     {
133         ArrayList JavaDoc retVal = new ArrayList JavaDoc();
134         SqlTypeAtom atom ;
135         Iterator JavaDoc iter = _attributes.iterator();
136         while (iter.hasNext()) {
137             atom = (SqlTypeAtom)iter.next();
138             retVal.add( atom.getName() );
139         }
140         return retVal;
141     }
142
143     public boolean isRelation()
144     {
145         return MANY == _multiplicity;
146     }
147
148     public boolean isTuple()
149     {
150         return ONE == _multiplicity;
151     }
152
153     public boolean isColumn()
154     {
155      return false;
156     }
157
158     public boolean isAtom()
159     {
160      return false;
161     }
162
163     public boolean isBoolean()
164     {
165         Iterator JavaDoc iter = _attributes.iterator();
166         SqlTypeAtom attr;
167         while (iter.hasNext()) {
168             attr = (SqlTypeAtom)iter.next();
169             if (!attr.isBoolean()) {
170                 return false;
171             }
172         }
173         return true ;
174     };
175
176     public boolean isNumeric()
177     {
178         Iterator JavaDoc iter = _attributes.iterator();
179         SqlTypeAtom attr;
180         while (iter.hasNext()) {
181             attr = (SqlTypeAtom)iter.next();
182             if (!attr.isNumeric()) {
183                 return false;
184             }
185         }
186         return true ;
187     };
188     public boolean isInteger()
189     {
190         Iterator JavaDoc iter = _attributes.iterator();
191         SqlTypeAtom attr;
192         while (iter.hasNext()) {
193             attr = (SqlTypeAtom)iter.next();
194             if (!attr.isInteger()) {
195                 return false;
196             }
197         }
198         return true ;
199     };
200     public boolean isString()
201     {
202         Iterator JavaDoc iter = _attributes.iterator();
203         SqlTypeAtom attr;
204         while (iter.hasNext()) {
205             attr = (SqlTypeAtom)iter.next();
206             if (!attr.isString()) {
207                 return false;
208             }
209         }
210         return true ;
211     };
212     public boolean isDataTime()
213     {
214         Iterator JavaDoc iter = _attributes.iterator();
215         SqlTypeAtom attr;
216         while (iter.hasNext()) {
217             attr = (SqlTypeAtom)iter.next();
218             if (!attr.isDataTime()) {
219                 return false;
220             }
221         }
222         return true ;
223     };
224
225     public String JavaDoc pprint ()
226     {
227         StringBuffer JavaDoc retVal = null;
228         if ( MANY == _multiplicity) {
229             retVal.append("Relation(");
230         }
231         else {
232             retVal.append("Tuple(");
233         }
234
235         for (int i = 0; i < _attributes.size(); i++) {
236             retVal.append(((SqlTypeAtom)_attributes.get(i)).ppprint());
237             retVal.append(",");
238         }
239         retVal.append(")");
240         return retVal.toString();
241     }
242
243     public boolean isCompatibleTo(SqlType type)
244     {
245         log.warn("isCompatibleTo(SqlType type) not yet implemented.");
246         return true;
247     }
248 }
249
Popular Tags