1 22 23 24 package org.xquark.extractor.algebra; 25 26 27 import java.util.ArrayList ; 28 import java.util.Iterator ; 29 import java.util.List ; 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 _name = null; 37 protected List _attributes = null; 38 39 private static Log log = LogFactory.getLog(SqlTypeStructure.class); 40 41 public SqlTypeStructure() 42 { 43 } 44 45 public SqlTypeStructure(String name, List attributes,int multiplicity ) 46 { 47 setName(name); 48 setAttributes (attributes); 49 setMultiplicity (multiplicity); 50 } 51 52 public SqlTypeStructure(List attributes,int multiplicity ) 53 { 54 setAttributes (attributes); 55 setMultiplicity (multiplicity); 56 } 57 58 public SqlTypeStructure(List attributes ) 59 { 60 setAttributes (attributes); 61 } 62 63 public Object clone() { 64 try { 66 SqlTypeStructure retVal = (SqlTypeStructure)super.clone(); 67 if (null != _attributes) { 68 retVal.setAttributes( AlgebraTools.clone(_attributes)); 69 } 70 return retVal; 72 } 73 catch (CloneNotSupportedException ex) { 74 Debug.assertTrue(false, "error in implementation of clone"); 75 return null; 77 } 78 79 } 80 81 public String getName() 82 { 83 return _name; 84 } 85 86 public void setName(String aName) 87 { 88 _name = aName; 89 } 90 91 public List getAttributes() 92 { 93 return _attributes; 94 } 95 96 97 public void setAttributes(List aAttributes) 98 { 99 _attributes = aAttributes; 100 } 101 102 public void addAttribute (SqlTypeAtom atom ) 103 { 104 if (null==_attributes){ 105 _attributes = new ArrayList (); 106 } 107 _attributes.add(atom); 108 } 109 110 public void addAttributes (List attributes) 111 { 112 if (null==_attributes){ 113 _attributes = new ArrayList (); 114 } 115 _attributes.addAll(attributes); 116 } 117 118 119 public List getTypes() 120 { 121 ArrayList retVal = new ArrayList (); 122 123 Iterator iter = _attributes.iterator(); 124 while (iter.hasNext()) { 125 retVal.add( ((SqlTypeAtom)iter.next()).getType() ); 126 } 127 return retVal; 128 } 129 130 131 public List getNames() 132 { 133 ArrayList retVal = new ArrayList (); 134 SqlTypeAtom atom ; 135 Iterator 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 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 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 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 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 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 pprint () 226 { 227 StringBuffer 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 |