1 23 24 package org.xquark.xquery.typing; 25 26 import java.util.ArrayList ; 27 28 import org.xquark.schema.*; 29 import org.xquark.xquery.parser.QName; 30 import org.xquark.xquery.parser.XQueryException; 31 import org.xquark.xquery.parser.XQueryExpression; 32 33 public class QTypeAttribute extends QTypeNode implements QTypeVisitable { 34 private static final String RCSRevision = "$Revision: 1.7 $"; 35 private static final String RCSName = "$Name: $"; 36 37 QName name = null; 38 AttributeDeclaration attDecl = null; 39 40 public QTypeAttribute(QName name, SimpleType simpleType) { 41 this.name = name; 42 setType(simpleType); 43 subclass = ATTRIBUTE; 44 occurence = OCC_1_1; 45 } 46 public QTypeAttribute(QName name, SimpleType simpleType, byte occurence) { 47 this.name = name; 48 setType(simpleType); 49 subclass = ATTRIBUTE; 50 this.occurence = occurence; 51 } 52 public QTypeAttribute(QName name, AttributeDeclaration attDecl, SimpleType simpleType) { 53 this.name = name; 54 setType(simpleType); 55 setAttributeDeclaration(attDecl); 56 subclass = ATTRIBUTE; 57 occurence = OCC_1_1; 58 } 59 public QTypeAttribute(QName name, AttributeDeclaration attDecl, SimpleType simpleType, byte occurence) { 60 this.name = name; 61 setType(simpleType); 62 setAttributeDeclaration(attDecl); 63 subclass = ATTRIBUTE; 64 this.occurence = occurence; 65 } 66 67 71 public void accept(QTypeVisitor visitor) throws XQueryException { 72 visitor.visit(this); 73 } 74 75 77 public XQueryExpression getName() { 78 return name; 79 } 80 81 public AttributeDeclaration getAttributeDeclaration() { 82 return attDecl; 83 } 84 85 public void setAttributeDeclaration(AttributeDeclaration attDecl) { 86 this.attDecl = attDecl; 87 } 88 89 public boolean equals(Object qtype) { 91 if (!(qtype instanceof QTypeAttribute)) 92 return false; 93 return compare(type, ((QTypeAttribute) qtype).getSimpleType()) && name.equals(((QTypeAttribute) qtype).getName()); 96 } 97 98 public boolean isNumeric() { 100 if (type == null) 101 return false; 102 else 103 return isNumeric(type); 104 } 105 106 public boolean isBoolean() { 108 if (type == null) 109 return false; 110 else 111 return isBoolean(type); 112 } 113 114 public boolean isInteger() { 116 if (type == null) 117 return false; 118 else 119 return isInteger(type); 120 } 121 122 public boolean isString() { 124 if (type == null) 125 return false; 126 else 127 return isString(type); 128 } 129 130 133 public boolean isText() { 135 return true; 136 } 137 138 public boolean isDate() { 140 if (type == null) 141 return false; 142 else 143 return isDate(type); 144 } 145 146 public boolean isAttribute() { 148 return true; 149 } 150 151 public boolean isIDAttribute() { 153 if (type == null) 154 return false; 155 if (type.getNamespace().equals(SchemaConstants.XMLSCHEMA_URI) && (type.getName().equals("ID") || type.getName().equals("IDREF") || type.getName().equals("IDREFS"))) 156 return true; 157 return false; 158 } 159 160 public boolean isNode() { 162 return true; 163 } 164 165 public boolean isSimpleTypeNode() { 167 return true; 168 } 169 170 public boolean isAtomic() { 172 return !isMultiple(); 173 } 174 175 public boolean canBeComparedTo(QType compType) { 176 if (compType == null) 177 return false; 178 if (!(compType instanceof QTypeAttribute)) 179 return compType.canBeComparedTo(this); 180 if (type == null) 181 return true; 182 if (((QTypeAttribute) compType).getSimpleType() == null) 183 return true; 184 return canBeCompared(((SimpleType)type).getPrimitive().getType(), ((QTypeAttribute) compType).getSimpleType().getPrimitive().getType()); 185 } 186 187 public QType applyTEXTFunction(boolean inDepth, ArrayList history, SchemaManager schemamanager) throws TypeException { 188 return new QTypeAtom((SimpleType) schemamanager.getType(SchemaConstants.XMLSCHEMA_URI, TypeVisitor.SC_STRING),occurence); 189 } 190 191 public QType applyDATAFunction() throws TypeException { 192 return new QTypeAtom((SimpleType)type,occurence); 193 } 194 195 public QType applyFILTERFunction() throws TypeException { 196 return this; 197 } 198 199 public Object clone() throws CloneNotSupportedException { 201 QTypeAttribute newObj = new QTypeAttribute(name,attDecl,(SimpleType)type,occurence); 202 return newObj; 203 } 204 public String toSimpleString() { 206 return "QTypeAttribute(" + name + " , " + type.getName() + ")"; 207 } 208 209 public String toString() { 210 return "QTypeAttribute(" + name + " ,\n" + type + ")"; 211 } 212 213 } 214 | Popular Tags |