public boolean checkAssign(ItemType to, ItemType from) { TypeHierarchy th = processor.getUnderlyingConfiguration().getTypeHierarchy(); return th.isSubType(from, to); }
/** * Determine whether type A is type B or one of its subtypes, recursively * * @param subtype identifies the first type * @param supertype identifies the second type * @return true if the first type is the second type or a (direct or * indirect) subtype of the second type */ public boolean isSubType(ItemType subtype, ItemType supertype) { int relation = relationship(subtype, supertype); return (relation==SAME_TYPE || relation==SUBSUMED_BY); }
/** * Get the TypeHierarchy: a cache holding type information * * @return the type hierarchy cache */ public TypeHierarchy getTypeHierarchy() { if (typeHierarchy == null) { typeHierarchy = new TypeHierarchy(this); } return typeHierarchy; }
throw new NullPointerException(); t1 = stabilize(t1); t2 = stabilize(t2); if (t1.equals(t2)) { return SAME_TYPE; Integer result = map.get(pair); if (result == null) { result = computeRelationship(t1, t2); map.put(pair, result);
if (relationship(suppliedItemType, BuiltInAtomicType.UNTYPED_ATOMIC) != DISJOINT && !isSubType(BuiltInAtomicType.UNTYPED_ATOMIC, requiredItemType)) { final boolean nsSensitive = ((SimpleType) requiredItemType).isNamespaceSensitive(); ItemMappingFunction<Item<?>, Item<?>> converter; relationship(suppliedItemType, BuiltInAtomicType.ANY_URI) != DISJOINT) { ItemMappingFunction<Item<?>, Item<?>> promoter = item -> { if (item instanceof AnyURIValue) { iterator = applyFunctionCoercion(iterator, suppliedItemType, requiredItemType, locator); int relation = relationship(suppliedItemType, requiredItemType);
if (t1 instanceof DocumentNodeTest) { if (t2 instanceof DocumentNodeTest) { contentRelationship = relationship(((DocumentNodeTest) t1).getElementTest(), ((DocumentNodeTest) t2).getElementTest()); } else { SchemaType s1 = ((NodeTest) t1).getContentType(); SchemaType s2 = ((NodeTest) t2).getContentType(); contentRelationship = schemaTypeRelationship(s1, s2);
Configuration config = th.getConfiguration(); if (getSchemaType() != null) { int e = th.relationship(selectItemType, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ELEMENT, getSchemaType(), config, false); int a = th.relationship(selectItemType, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ATTRIBUTE, getSchemaType(), config, false); return selectItemType; case Validation.STRIP: { int e = th.relationship(selectItemType, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ELEMENT, Untyped.getInstance(), config, false); int a = th.relationship(selectItemType, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ATTRIBUTE, BuiltInAtomicType.UNTYPED_ATOMIC, config, false); int fp = ((NodeTest) selectItemType).getFingerprint(); if (fp != -1) { int e = th.relationship(selectItemType, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { SchemaDeclaration elem = config.getElementDeclaration(fp); int a = th.relationship(selectItemType, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { SchemaDeclaration attr = config.getElementDeclaration(fp);
/** * Test whether a given item conforms to this type * * @param item The item to be tested * @param th the type hierarchy cache * @return true if the item is an instance of this type; false otherwise */ @Override public boolean matches(Item item, TypeHierarchy th) throws XPathException { return item instanceof Function && checkAnnotationAssertions(assertions, (Function) item, th.getConfiguration()); }
/** * Determine whether this node has the is-id property * @return true if the node is an ID */ public boolean isId() { TypeHierarchy th = getConfiguration().getTypeHierarchy(); return th.isIdCode(typeCode); }
/** * Determine whether this node has the is-idref property * @return true if the node is an IDREF or IDREFS element or attribute */ public boolean isIdref() { TypeHierarchy th = getConfiguration().getTypeHierarchy(); return th.isIdrefsCode(typeCode); }
private boolean matchesAnnotation(SchemaType annotation) { if (annotation == null) { return false; } if (schemaType == AnyType.getInstance()) { return true; } if (annotation.equals(schemaType)) { return true; } // see if the type annotation is a subtype of the required type int r = config.getTypeHierarchy().schemaTypeRelationship(annotation, schemaType); return r == TypeHierarchy.SAME_TYPE || r == TypeHierarchy.SUBSUMED_BY; }
/** * Determine the relationship of one item type to another. * @param t1 the first item type * @param t2 the second item type * @return {@link #SAME_TYPE} if the types are the same; {@link #SUBSUMES} if the first * type subsumes the second (that is, all instances of the second type are also instances * of the first); {@link #SUBSUMED_BY} if the second type subsumes the first; * {@link #OVERLAPS} if the two types overlap (have a non-empty intersection, but neither * subsumes the other); {@link #DISJOINT} if the two types are disjoint (have an empty intersection) */ public int relationship(ItemType t1, ItemType t2) { if (t1 == null) { throw new NullPointerException(); } if (t1.equals(t2)) { return SAME_TYPE; } ItemTypePair pair = new ItemTypePair(t1, t2); Integer result = (Integer)map.get(pair); if (result == null) { final int r = computeRelationship(t1, t2); result = new Integer(r); map.put(pair, result); } return result.intValue(); }
if (relationship(suppliedItemType, BuiltInAtomicType.UNTYPED_ATOMIC) != DISJOINT && !isSubType(BuiltInAtomicType.UNTYPED_ATOMIC, requiredItemType)) { final boolean nsSensitive = ((SimpleType) requiredItemType).isNamespaceSensitive(); ItemMappingFunction<Item<?>, Item<?>> converter; relationship(suppliedItemType, BuiltInAtomicType.ANY_URI) != DISJOINT) { ItemMappingFunction<Item<?>, Item<?>> promoter = item -> { if (item instanceof AnyURIValue) { iterator = applyFunctionCoercion(iterator, suppliedItemType, requiredItemType, locator); int relation = relationship(suppliedItemType, requiredItemType);
if (t1 instanceof DocumentNodeTest) { if (t2 instanceof DocumentNodeTest) { contentRelationship = relationship(((DocumentNodeTest) t1).getElementTest(), ((DocumentNodeTest) t2).getElementTest()); } else { SchemaType s1 = ((NodeTest) t1).getContentType(); SchemaType s2 = ((NodeTest) t2).getContentType(); contentRelationship = schemaTypeRelationship(s1, s2);
Configuration config = th.getConfiguration(); if (getSchemaType() != null) { int e = th.relationship(selectItemType, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ELEMENT, getSchemaType(), config, false); int a = th.relationship(selectItemType, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ATTRIBUTE, getSchemaType(), config, false); return selectItemType; case Validation.STRIP: { int e = th.relationship(selectItemType, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ELEMENT, Untyped.getInstance(), config, false); int a = th.relationship(selectItemType, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ATTRIBUTE, BuiltInAtomicType.UNTYPED_ATOMIC, config, false); int fp = ((NodeTest) selectItemType).getFingerprint(); if (fp != -1) { int e = th.relationship(selectItemType, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { SchemaDeclaration elem = config.getElementDeclaration(fp); int a = th.relationship(selectItemType, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { SchemaDeclaration attr = config.getElementDeclaration(fp);
/** * Test whether a given item conforms to this type * * @param item The item to be tested * @param th the type hierarchy cache * @return true if the item is an instance of this type; false otherwise */ @Override public boolean matches(Item item, TypeHierarchy th) throws XPathException { return item instanceof Function && checkAnnotationAssertions(assertions, (Function) item, th.getConfiguration()); }
/** * Determine whether a given attribute has the is-ID property set */ public boolean isId(int index) { return (codes[index * RECSIZE] & NamePool.FP_MASK) == StandardNames.XML_ID || config.getTypeHierarchy().isIdCode(getTypeAnnotation(index)); // return getType(index).equals("ID") || // ((getNameCode(index) & NamePool.FP_MASK) == StandardNames.XML_ID); }
throw new NullPointerException(); t1 = stabilize(t1); t2 = stabilize(t2); if (t1.equals(t2)) { return SAME_TYPE; Integer result = map.get(pair); if (result == null) { result = computeRelationship(t1, t2); map.put(pair, result);
/** * Determine whether a given attribute has the is-idref property set */ public boolean isIdref(int index) { return config.getTypeHierarchy().isIdrefsCode(getTypeAnnotation(index)); }
private boolean matchesAnnotation(SchemaType annotation) { if (annotation == null) { return false; } if (schemaType == AnyType.getInstance()) { return true; } if (annotation.equals(schemaType)) { return true; } // see if the type annotation is a subtype of the required type int r = config.getTypeHierarchy().schemaTypeRelationship(annotation, schemaType); return r == TypeHierarchy.SAME_TYPE || r == TypeHierarchy.SUBSUMED_BY; }