1 23 24 package org.xquark.xquery.typing; 25 26 import org.xquark.schema.*; 27 import org.xquark.xquery.parser.XQueryException; 28 import org.xquark.xquery.parser.XQueryExpression; 29 30 public class QTypeElement extends QTypeNode implements QTypeVisitable { 31 private static final String RCSRevision = "$Revision: 1.9 $"; 32 private static final String RCSName = "$Name: $"; 33 34 XQueryExpression name = null; 35 ElementDeclaration eltDecl = null; 36 37 public QTypeElement(XQueryExpression name, Type type) { 38 this.name = name; 39 setType(type); 40 subclass = ELEMENT; 41 occurence = OCC_1_1; 42 if (type == null) { 43 int i= 0; 44 } 45 } 46 public QTypeElement(XQueryExpression name, Type type, byte occurence) { 47 this.name = name; 48 setType(type); 49 subclass = ELEMENT; 50 this.occurence = occurence; 51 if (type == null) { 52 int i= 0; 53 } 54 } 55 56 public QTypeElement(XQueryExpression name, ElementDeclaration eltDecl, Type type) { 57 this.name = name; 58 setType(type); 59 setElementDeclaration(eltDecl); 60 subclass = ELEMENT; 61 occurence = OCC_1_1; 62 if (type == null) { 63 int i= 0; 64 } 65 } 66 public QTypeElement(XQueryExpression name, ElementDeclaration eltDecl, Type type, byte occurence) { 67 this.name = name; 68 setType(type); 69 setElementDeclaration(eltDecl); 70 subclass = ELEMENT; 71 this.occurence = occurence; 72 if (type == null) { 73 int i= 0; 74 } 75 } 76 77 81 public void accept(QTypeVisitor visitor) throws XQueryException { 82 visitor.visit(this); 83 } 84 85 87 public XQueryExpression getName() { 88 return name; 89 } 90 91 public ElementDeclaration getElementDeclaration() { 92 return eltDecl; 93 } 94 95 public void setElementDeclaration(ElementDeclaration eltDecl) { 96 this.eltDecl = eltDecl; 97 } 98 99 public boolean equals(Object qtype) { 101 if (!(qtype instanceof QTypeElement)) 102 return false; 103 return compare(type, ((QTypeElement) qtype).getType()) && name.equals(((QTypeElement) qtype).getName()); 107 } 108 109 public boolean isNumeric() { 111 return isNumeric(type); 112 118 } 119 120 public boolean isBoolean() { 122 return isBoolean(type); 123 } 124 125 public boolean isInteger() { 127 return isInteger(type); 128 } 129 130 public boolean isString() { 132 if (this.isMixed()) 133 return true; return isString(type); 135 } 136 137 public boolean isAtom() { 139 return false; 140 } 141 147 public boolean isText() { 149 return true; 150 } 151 152 public boolean isDate() { 154 return isDate(type); 155 } 156 157 public boolean isNode() { 159 return true; 160 } 161 162 public boolean isSimpleTypeNode() { 164 if (type.getValueType() != null) 165 return true; 166 if (type.getName() != null && type.getName().equals(Type.ANY_TYPE)) 167 return true; 168 return false; 169 } 170 171 178 public boolean isAtomic() { 180 if (type.getName() != null && type.getName().equals(TypeVisitor.SC_ANYTYPE)) 181 return true; 182 if (this.isMixed()) 183 return !isMultiple(); if (type.getValueType() != null) 185 return !isMultiple(); 186 return false; 187 } 188 189 public boolean isMixed() { 191 if (type instanceof ComplexType && ((ComplexType) type).getContentType() == SchemaConstants.MIXED) 192 return true; 193 return false; 194 } 195 196 public boolean isElement() { 198 return true; 199 } 200 201 202 public QType applyDATAFunction() throws TypeException { 203 if (type.getValueType() != null) 204 return new QTypeAtom(type.getValueType(), occurence); 205 if (type.getContentType() == Type.MIXED) { 206 return new QTypeAtom(null, occurence); 208 } 209 return null; 210 } 211 212 public Object clone() throws CloneNotSupportedException { 214 QTypeElement newObj = new QTypeElement(name, type, occurence); 215 return newObj; 216 } 217 public String toSimpleString() { 218 return "QTypeElement(" + name + " ," + type.getName() + ")"; 219 } 220 221 public String toString() { 222 return "QTypeElement(" + name + " ,\n" + type + ")"; 223 } 224 225 } 226 | Popular Tags |