1 package net.sf.saxon.type; 2 3 import net.sf.saxon.expr.Expression; 4 import net.sf.saxon.expr.StaticContext; 5 import net.sf.saxon.instruct.ValueOf; 6 import net.sf.saxon.om.*; 7 import net.sf.saxon.style.StandardNames; 8 import net.sf.saxon.trans.XPathException; 9 import net.sf.saxon.value.AtomicValue; 10 import net.sf.saxon.value.ObjectValue; 11 import net.sf.saxon.value.Value; 12 import net.sf.saxon.value.Whitespace; 13 import net.sf.saxon.ConversionContext; 14 15 import java.io.Serializable ; 16 17 21 22 public class ExternalObjectType implements AtomicType, Serializable { 23 24 private Class javaClass; 25 int fingerprint; 26 int baseFingerprint = -1; 27 28 public ExternalObjectType(Class javaClass) { 29 this.javaClass = javaClass; 30 this.fingerprint = StandardNames.SAXON_JAVA_LANG_OBJECT; 31 } 32 33 37 38 public AtomicType getCommonAtomicType() { 39 return this; 40 } 41 42 45 public final int getValidationStatus() { 46 return VALIDATED; 47 } 48 49 55 56 public final int getBlock() { 57 return 0; 58 } 59 60 66 67 public final int getDerivationMethod() { 68 return SchemaType.DERIVATION_RESTRICTION; 69 } 70 71 78 79 public final boolean allowsDerivation(int derivation) { 80 return true; 81 } 82 83 88 89 public int getNameCode() { 90 return fingerprint; 91 } 92 93 98 99 public final boolean isComplexType() { 100 return false; 101 } 102 103 111 112 public final SchemaType getBaseType() { 113 return BuiltInSchemaFactory.getSchemaType(StandardNames.XDT_ANY_ATOMIC_TYPE); 114 } 115 116 124 125 public ItemType getPrimitiveItemType() { 126 return this; 127 } 128 129 137 138 public int getPrimitiveType() { 139 return Type.ATOMIC; 140 } 141 142 146 147 public String toString(NamePool pool) { 148 return getDisplayName(); 149 } 150 151 155 156 public AtomicType getAtomizedItemType() { 157 return this; 158 } 159 160 168 169 public SchemaType getKnownBaseType() { 170 return getBaseType(); 171 } 172 173 178 179 public boolean isSameType(SchemaType other) { 180 return (other.getFingerprint() == this.getFingerprint()); 181 } 182 183 public String getDescription() { 184 return getDisplayName(); 185 } 186 187 194 195 public void isTypeDerivationOK(SchemaType type, int block) throws SchemaException, ValidationException { 196 return; 197 } 198 199 204 205 public final boolean isSimpleType() { 206 return true; 207 } 208 209 213 214 public boolean isAtomicType() { 215 return true; 216 } 217 218 219 225 226 public boolean isListType() { 227 return false; 228 } 229 230 235 236 public boolean isUnionType() { 237 return false; 238 } 239 240 245 246 public int getWhitespaceAction() { 247 return Whitespace.PRESERVE; 248 } 249 250 256 257 public CharSequence applyWhitespaceNormalization(CharSequence value) throws ValidationException { 258 return value; 259 } 260 261 266 public SchemaType getBuiltInBaseType() throws ValidationException { 267 return this; 268 } 269 270 276 277 public boolean isNamespaceSensitive() { 278 return false; 279 } 280 281 288 289 public final SequenceIterator getTypedValue(NodeInfo node) { 290 throw new IllegalStateException ("The type annotation of a node cannot be an external object type"); 291 } 292 293 302 303 public Value atomize(NodeInfo node) throws XPathException { 304 throw new IllegalStateException ("The type annotation of a node cannot be an external object type"); 305 } 306 307 319 320 public SequenceIterator getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionContext conversion) 321 throws ValidationException { 322 throw new ValidationException("Cannot validate a string against an external object type"); 323 } 324 325 326 336 337 public AtomicValue makeDerivedValue(AtomicValue primValue, CharSequence lexicalValue, boolean validate) { 338 throw new UnsupportedOperationException ("makeDerivedValue is not supported for external object types"); 339 } 340 341 352 353 public void analyzeContentExpression(Expression expression, int kind, StaticContext env) throws XPathException { 354 analyzeContentExpression(this, expression, env, kind); 355 } 356 357 367 368 public static void analyzeContentExpression(SimpleType simpleType, Expression expression, StaticContext env, int kind) 369 throws XPathException { 370 if (kind == Type.ELEMENT) { 371 expression.checkPermittedContents(simpleType, env, true); 372 } else if (kind == Type.ATTRIBUTE) { 373 if (expression instanceof ValueOf || expression instanceof Value) { 375 expression.checkPermittedContents(simpleType, env, true); 376 } 377 } 378 } 379 380 381 public Class getJavaClass() { 382 return javaClass; 383 } 384 385 public boolean isBuiltIn() { 386 return true; 387 } 388 389 public boolean matchesItem(Item item) { 390 if (item instanceof ObjectValue) { 391 Object obj = ((ObjectValue)item).getObject(); 392 return javaClass.isAssignableFrom(obj.getClass()); 393 } 394 return false; 395 } 396 397 410 411 public ValidationException validateContent(CharSequence value, NamespaceResolver nsResolver, ConversionContext conversion) { 412 throw new UnsupportedOperationException ("Cannot use an external object type for validation"); 413 } 414 415 public ItemType getSuperType() { 416 return Type.ANY_ATOMIC_TYPE; 418 } 419 420 public int getFingerprint() { 421 return StandardNames.SAXON_JAVA_LANG_OBJECT; 422 } 423 424 public String toString() { 425 String name = javaClass.getName(); 426 name = name.replace('$', '-'); 427 return "java:" + name; 428 } 429 430 public String getDisplayName() { 431 return toString(); 432 } 433 } 434 435 | Popular Tags |