1 package net.sf.saxon.type; 2 3 import net.sf.saxon.expr.*; 4 import net.sf.saxon.functions.NormalizeSpace; 5 import net.sf.saxon.om.*; 6 import net.sf.saxon.style.StandardNames; 7 import net.sf.saxon.trans.DynamicError; 8 import net.sf.saxon.trans.XPathException; 9 import net.sf.saxon.value.StringValue; 10 import net.sf.saxon.value.Whitespace; 11 import net.sf.saxon.value.Value; 12 import net.sf.saxon.value.SequenceExtent; 13 import net.sf.saxon.ConversionContext; 14 15 import java.io.Serializable ; 16 17 23 24 public class BuiltInListType implements ListType, Serializable { 25 26 private int fingerprint; 27 28 34 35 public int getWhitespaceAction() { 36 return Whitespace.COLLAPSE; 37 } 38 39 42 43 private BuiltInAtomicType itemType = null; 44 45 50 51 public AtomicType getCommonAtomicType() { 52 return itemType; 53 } 54 55 58 59 public BuiltInListType(int fingerprint) { 60 this.fingerprint = fingerprint; 61 switch (fingerprint) { 62 case StandardNames.XS_ENTITIES: 63 itemType = (BuiltInAtomicType)BuiltInSchemaFactory.getSchemaType(StandardNames.XS_ENTITY); 64 break; 65 case StandardNames.XS_IDREFS: 66 itemType = (BuiltInAtomicType)BuiltInSchemaFactory.getSchemaType(StandardNames.XS_IDREF); 67 break; 68 case StandardNames.XS_NMTOKENS: 69 itemType = (BuiltInAtomicType)BuiltInSchemaFactory.getSchemaType(StandardNames.XS_NMTOKEN); 70 break; 71 } 72 } 73 74 77 public int getValidationStatus() { 78 return VALIDATED; 79 } 80 81 86 87 public SchemaType getBaseType() { 88 return AnySimpleType.getInstance(); 89 } 90 91 95 96 public boolean isAtomicType() { 97 return false; 98 } 99 100 101 105 106 public boolean isListType() { 107 return true; 108 } 109 110 public boolean isUnionType() { 111 return false; 112 } 113 114 public SchemaType getBuiltInBaseType() throws ValidationException { 115 return this; 116 } 117 118 public boolean isNamespaceSensitive() { 119 return false; 120 } 121 122 126 127 public int getFingerprint() { 128 return fingerprint; 129 } 130 131 135 136 public int getNameCode() { 137 return fingerprint; 138 } 139 140 145 146 public String getDisplayName() { 147 return StandardNames.getDisplayName(fingerprint); 148 } 149 150 155 156 public boolean isComplexType() { 157 return false; 158 } 159 160 164 165 public boolean isSimpleType() { 166 return true; 167 } 168 169 175 176 public int getBlock() { 177 return 0; } 179 180 188 189 public SchemaType getKnownBaseType() throws IllegalStateException { 190 return AnySimpleType.getInstance(); 191 } 192 193 199 200 public int getDerivationMethod() { 201 return SchemaType.DERIVATION_LIST; 202 } 203 204 211 212 public boolean allowsDerivation(int derivation) { 213 return true; 214 } 215 216 224 225 public SequenceIterator getTypedValue(NodeInfo node) throws XPathException { 226 try { 227 return getTypedValue(node.getStringValue(), new InscopeNamespaceResolver(node), node.getConfiguration()); 228 } catch (ValidationException err) { 229 throw new DynamicError("Internal error: value doesn't match its type annotation. " + err.getMessage()); 230 } 231 } 232 233 242 243 public Value atomize(NodeInfo node) throws XPathException { 244 return new SequenceExtent(getTypedValue(node)).simplify(); 245 } 246 247 252 253 public boolean isSameType(SchemaType other) { 254 return other.getFingerprint() == this.getFingerprint(); 255 } 256 257 public String getDescription() { 258 return getDisplayName(); 259 } 260 261 269 270 public void isTypeDerivationOK(SchemaType type, int block) throws SchemaException, ValidationException { 271 } 273 274 278 279 public String getLocalName() { 280 return getDisplayName().substring(3); 281 } 282 283 287 288 public SimpleType getItemType() { 289 return itemType; 290 } 291 292 297 298 public String applyWhitespaceNormalization(String value) { 299 return NormalizeSpace.normalize(value).toString(); 300 } 301 302 313 314 public void analyzeContentExpression(Expression expression, int kind, StaticContext env) throws XPathException { 315 BuiltInAtomicType.analyzeContentExpression(this, expression, env, kind); 316 } 317 318 328 329 public ValidationException validateContent(CharSequence value, NamespaceResolver nsResolver, ConversionContext conversion) { 330 SimpleType base = getItemType(); 331 SequenceIterator iter = new StringTokenIterator(value.toString()); 332 ValidationException result = null; 333 try { 334 while (true) { 335 StringValue val = (StringValue)iter.next(); 336 if (val == null) break; 337 ValidationException v = base.validateContent(val.getStringValue(), nsResolver, conversion); 338 if (v != null) { 339 return v; 340 } 341 } 342 } catch (ValidationException err) { 343 result = err; 344 } catch (XPathException err) { 345 result = new ValidationException(err); 346 } 347 return result; 348 } 349 350 357 358 public SequenceIterator getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionContext conversion) throws ValidationException { 359 SequenceIterator iter = new StringTokenIterator(value.toString()); 360 ListTypeMappingFunction map = new ListTypeMappingFunction(); 361 map.resolver = resolver; 362 map.atomicType = (AtomicType)getItemType(); 363 return new MappingIterator(iter, map, null); 364 } 365 366 private static class ListTypeMappingFunction implements MappingFunction { 367 368 public NamespaceResolver resolver; 369 public AtomicType atomicType; 370 371 377 378 public Object map(Item item, XPathContext context) throws XPathException { 379 try { 380 return atomicType.getTypedValue(item.getStringValue(), resolver, context); 381 } catch (ValidationException err) { 382 return new DynamicError(err); 383 } 384 } 385 } 386 387 } 388 389 407 408 | Popular Tags |