1 23 24 package org.xquark.xquery.typing; 25 26 import org.xquark.schema.SimpleType; 27 import org.xquark.schema.datatypes.PrimitiveType; 28 import org.xquark.xquery.parser.XQueryException; 29 30 public class QTypeAtom extends QTypeItem implements QTypeVisitable { 31 private static final String RCSRevision = "$Revision: 1.6 $"; 32 private static final String RCSName = "$Name: $"; 33 34 public QTypeAtom(SimpleType simpleType) { 35 setType(simpleType); 36 subclass = ATOM; 37 occurence = OCC_1_1; 38 } 39 public QTypeAtom(SimpleType simpleType, byte occurence) { 40 setType(simpleType); 41 subclass = ATOM; 42 this.occurence = occurence; 43 } 44 45 49 public void accept(QTypeVisitor visitor) throws XQueryException { 50 visitor.visit(this); 51 } 52 53 58 60 public boolean equals(Object qtype) { 61 if (!(qtype instanceof QTypeAtom)) 62 return false; 63 return compare(type, ((QTypeAtom) qtype).getSimpleType()); 66 } 67 68 public boolean isNumeric() { 70 if (type == null) 71 return false; 72 else 73 return isNumeric(type); 74 } 75 76 public boolean isBoolean() { 78 if (type == null) 79 return false; 80 else 81 return isBoolean(type); 82 } 83 84 public boolean isInteger() { 86 if (type == null) 87 return false; 88 else 89 return isInteger(type); 90 } 91 92 public boolean isString() { 94 if (type == null) 95 return false; 96 else 97 return isString(type); 98 } 99 100 public boolean isAtom() { 102 return true; 103 } 104 105 110 public boolean isDate() { 112 if (type == null) 113 return false; 114 else 115 return isDate(type); 116 } 117 118 123 128 133 138 143 148 153 public boolean isAtomic() { 155 if (type == null) 156 return false; 157 else 158 return !isMultiple(); 159 } 160 161 166 171 public boolean isQName() { 173 if (type == null) 174 return false; 175 else 176 return isQName(type); 177 } 178 179 public boolean canBeComparedTo(QType compType) { 180 if (compType == null) 181 return false; 182 if (!(compType instanceof QTypeAtom)) 183 return compType.canBeComparedTo(this); 184 if (type == null) 185 return true; 186 if (((QTypeAtom) compType).getSimpleType() == null) 187 return true; 188 return canBeCompared(((SimpleType) type).getPrimitive().getType(), ((QTypeAtom) compType).getSimpleType().getPrimitive().getType()); 189 } 190 191 public boolean canBeCastedInto(int castType) { 192 if (castType == -1) 193 return false; 194 int myCastType = getCastType(); 195 if (myCastType == -1) 196 return false; 197 return QType.castTab[myCastType][castType]; 198 } 199 200 public int getCastType() { 201 if (type == null) 202 return QType.PRIMITIVE_anySimpleType; 203 switch (((SimpleType) type).getPrimitive().getType()) { 204 case PrimitiveType.ANYSIMPLETYPE : 206 return QType.PRIMITIVE_anySimpleType; 207 case PrimitiveType.STRING : 208 return QType.PRIMITIVE_string; 209 case PrimitiveType.BOOLEAN : 210 return QType.PRIMITIVE_boolean; 211 case PrimitiveType.DECIMAL : 212 return QType.PRIMITIVE_decimal; 213 case PrimitiveType.DOUBLE : 214 return QType.PRIMITIVE_double; 215 case PrimitiveType.FLOAT : 216 return QType.PRIMITIVE_float; 217 case PrimitiveType.DURATION : 218 return QType.PRIMITIVE_duration; 219 case PrimitiveType.DATE_TIME : 220 return QType.PRIMITIVE_dateTime; 221 case PrimitiveType.TIME : 222 return QType.PRIMITIVE_time; 223 case PrimitiveType.DATE : 224 return QType.PRIMITIVE_date; 225 case PrimitiveType.GYEAR_MONTH : 226 return QType.PRIMITIVE_gYearMonth; 227 case PrimitiveType.GYEAR : 228 return QType.PRIMITIVE_gYear; 229 case PrimitiveType.GMONTH_DAY : 230 return QType.PRIMITIVE_gMonthDay; 231 case PrimitiveType.GDAY : 232 return QType.PRIMITIVE_gDay; 233 case PrimitiveType.GMONTH : 234 return QType.PRIMITIVE_gMonth; 235 case PrimitiveType.HEX_BINARY : 236 return QType.PRIMITIVE_hexBinary; 237 case PrimitiveType.BASE64_BINARY : 238 return QType.PRIMITIVE_base64Binary; 239 case PrimitiveType.ANY_URI : 240 return QType.PRIMITIVE_anyURI; 241 case PrimitiveType.QNAME : 242 return QType.PRIMITIVE_Qname; 243 case PrimitiveType.NOTATION : 244 return QType.PRIMITIVE_NOTATION; 245 } 246 return -1; 247 } 248 254 255 public Object clone() throws CloneNotSupportedException { 257 QTypeAtom newObj = new QTypeAtom((SimpleType) type, occurence); 258 return newObj; 259 } 260 public String toSimpleString() { 262 if (type == null) 263 return "QTypeAtom(anySimpleType)"; 264 else 265 return "QTypeAtom(" + type.getName() + ")"; 266 } 267 268 public String toString() { 269 return "QTypeAtom(\n" + type + ")"; 270 } 271 272 } 273 | Popular Tags |