public ItemType getItemType(TypeHierarchy th) { if (schemaType != null) { Configuration config = getExecutable().getConfiguration(); ItemType in = select.getItemType(th); int e = th.relationship(in, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ELEMENT, schemaType, config); } int a = th.relationship(in, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ATTRIBUTE, schemaType, config); } } return select.getItemType(th); }
public String toString() { if (isGlobalComponentTest) { if (nodetest1 instanceof SubstitutionGroupTest) { return nodetest1.toString(); } else { final int kind = nodetest1.getPrimitiveType(); final String skind = (kind == Type.ELEMENT ? "schema-element(" : "schema-attribute("); final String name = nodetest1.toString(); return skind + name + ')'; } } else if (nodetest1 instanceof NameTest && operator==Token.INTERSECT) { int kind = nodetest1.getPrimitiveType(); String skind = (kind == Type.ELEMENT ? "element(" : "attribute("); String content = ""; if (nodetest2 instanceof ContentTypeTest) { final SchemaType schemaType = ((ContentTypeTest)nodetest2).getSchemaType(); content = ", " + schemaType.getFingerprint(); } String name = nodetest1.toString(); return skind + name + content + ')'; } else { String nt1 = (nodetest1==null ? "true()" : nodetest1.toString()); String nt2 = (nodetest2==null ? "true()" : nodetest2.toString()); return '(' + nt1 + ' ' + Token.tokens[operator] + ' ' + nt2 + ')'; } }
/** * Test whether this node test is satisfied by a given node * @param nodeKind The type of node to be matched * @param fingerprint identifies the expanded name of the node to be matched * @param annotation The actual content type of the node */ public boolean matches(int nodeKind, int fingerprint, int annotation) { if (kind != nodeKind) { return false; } return matchesAnnotation(annotation); }
/** * Determine whether this (attribute) node is an ID. This method is introduced * in DOM Level 3. */ public boolean isId() { ContentTypeTest idTest = new ContentTypeTest(Type.ATTRIBUTE, BuiltInAtomicType.ID, node.getConfiguration()); idTest.setMatchDTDTypes(true); return idTest.matches(node); }
throw new SaxonApiException("Unknown schema type " + schemaType.getClarkName()); contentTest = new ContentTypeTest(Type.ELEMENT, type, config); contentTest.setNillable(nillable);
/** * Generate Javascript code to test whether an item conforms to this item type * * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns a boolean indication whether the value of the * variable "item" is an instance of this item type. * @throws XPathException if JS code cannot be generated for this item type, for example because * the test is schema-aware. * @param knownToBe An item type that the supplied item is known to conform to; the generated code * can assume that the item is an instance of this type. * @param targetVersion The version of Saxon-JS for which code is being generated. Currently either 1 or 2. */ @Override public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) throws XPathException { if (kind == Type.ELEMENT) { if (schemaType == Untyped.getInstance() || schemaType == AnyType.getInstance()) { return NodeKindTest.makeNodeKindTest(getNodeKind()).generateJavaScriptItemTypeTest(AnyItemType.getInstance(), targetVersion); } else if (schemaType == BuiltInAtomicType.UNTYPED_ATOMIC || schemaType == BuiltInAtomicType.ANY_ATOMIC) { return "return false;"; } } else if (kind == Type.ATTRIBUTE) { if (schemaType == Untyped.getInstance() || schemaType == AnyType.getInstance() || schemaType == BuiltInAtomicType.UNTYPED_ATOMIC || schemaType == BuiltInAtomicType.ANY_ATOMIC) { return NodeKindTest.makeNodeKindTest(getNodeKind()).generateJavaScriptItemTypeTest(AnyItemType.getInstance(), targetVersion); } } throw new XPathException("Cannot generate JS code to test type annotations", SaxonErrorCode.SXJS0001); }
contentTest = new ContentTypeTest(primaryType, schemaType, env.getConfiguration()); contentTest.setNillable(nillable); warning("An attribute cannot have a complex type"); ContentTypeTest typeTest = new ContentTypeTest(primaryType, schemaType, env.getConfiguration()); if (nameCode == -1) { typeTest.setNillable(true); nextToken(); nextToken(); if (t.currentToken == Token.QMARK) { typeTest.setNillable(true); nextToken();
/** * Generate Javascript code to test whether an item conforms to this item type * * @return a Javascript instruction or sequence of instructions, which can be used as the body * of a Javascript function, and which returns a boolean indication whether the value of the * variable "item" is an instance of this item type. * @throws XPathException if JS code cannot be generated for this item type, for example because * the test is schema-aware. * @param knownToBe An item type that the supplied item is known to conform to; the generated code * can assume that the item is an instance of this type. * @param targetVersion The version of Saxon-JS for which code is being generated. Currently either 1 or 2. */ @Override public String generateJavaScriptItemTypeTest(ItemType knownToBe, int targetVersion) throws XPathException { if (kind == Type.ELEMENT) { if (schemaType == Untyped.getInstance() || schemaType == AnyType.getInstance()) { return NodeKindTest.makeNodeKindTest(getNodeKind()).generateJavaScriptItemTypeTest(AnyItemType.getInstance(), targetVersion); } else if (schemaType == BuiltInAtomicType.UNTYPED_ATOMIC || schemaType == BuiltInAtomicType.ANY_ATOMIC) { return "return false;"; } } else if (kind == Type.ATTRIBUTE) { if (schemaType == Untyped.getInstance() || schemaType == AnyType.getInstance() || schemaType == BuiltInAtomicType.UNTYPED_ATOMIC || schemaType == BuiltInAtomicType.ANY_ATOMIC) { return NodeKindTest.makeNodeKindTest(getNodeKind()).generateJavaScriptItemTypeTest(AnyItemType.getInstance(), targetVersion); } } throw new XPathException("Cannot generate JS code to test type annotations", SaxonErrorCode.SXJS0001); }
public ItemType getItemType(TypeHierarchy th) { if (schemaType != null) { Configuration config = getExecutable().getConfiguration(); ItemType in = select.getItemType(th); int e = th.relationship(in, NodeKindTest.ELEMENT); if (e == TypeHierarchy.SAME_TYPE || e == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ELEMENT, schemaType, config); } int a = th.relationship(in, NodeKindTest.ATTRIBUTE); if (a == TypeHierarchy.SAME_TYPE || a == TypeHierarchy.SUBSUMED_BY) { return new ContentTypeTest(Type.ATTRIBUTE, schemaType, config); } } return select.getItemType(th); }
contentTest = new ContentTypeTest(primaryType, schemaType, env.getConfiguration()); contentTest.setNillable(nillable); warning("An attribute cannot have a complex type"); ContentTypeTest typeTest = new ContentTypeTest(primaryType, schemaType, env.getConfiguration()); if (nameCode == -1) { typeTest.setNillable(true); nextToken(); nextToken(); if (t.currentToken == Token.QMARK) { typeTest.setNillable(true); nextToken();
/** * Test whether this node test is satisfied by a given node * @param nodeKind The type of node to be matched * @param fingerprint identifies the expanded name of the node to be matched * @param annotation The actual content type of the node */ public boolean matches(int nodeKind, int fingerprint, int annotation) { if (kind != nodeKind) { return false; } return matchesAnnotation(annotation); }
public String toString() { if (isGlobalComponentTest) { if (nodetest1 instanceof SubstitutionGroupTest) { return nodetest1.toString(); } else { final int kind = nodetest1.getPrimitiveType(); final String skind = (kind == Type.ELEMENT ? "schema-element(" : "schema-attribute("); final String name = nodetest1.toString(); return skind + name + ')'; } } else if (nodetest1 instanceof NameTest && operator==Token.INTERSECT) { int kind = nodetest1.getPrimitiveType(); String skind = (kind == Type.ELEMENT ? "element(" : "attribute("); String content = ""; if (nodetest2 instanceof ContentTypeTest) { final SchemaType schemaType = ((ContentTypeTest)nodetest2).getSchemaType(); content = ", " + schemaType.getFingerprint(); } String name = nodetest1.toString(); return skind + name + content + ')'; } else { String nt1 = (nodetest1==null ? "true()" : nodetest1.toString()); String nt2 = (nodetest2==null ? "true()" : nodetest2.toString()); return '(' + nt1 + ' ' + Token.tokens[operator] + ' ' + nt2 + ')'; } }
private boolean matchesAnnotation(int annotation) { if (requiredType == StandardNames.XS_ANY_TYPE) { return true; } if (annotation == -1) { annotation = (kind==Type.ATTRIBUTE ? StandardNames.XS_UNTYPED_ATOMIC : StandardNames.XS_UNTYPED); } if (matchDTDTypes) { annotation = annotation & NamePool.FP_MASK; } else if (((annotation & NodeInfo.IS_DTD_TYPE) != 0)) { return (requiredType == StandardNames.XS_UNTYPED_ATOMIC); } if (annotation == requiredType) { return true; } // see if the type annotation is a subtype of the required type try { SchemaType type = config.getSchemaType(annotation & NamePool.FP_MASK).getBaseType(); if (type == null) { // only true if annotation = XS_ANY_TYPE return false; } ItemType actual = new ContentTypeTest(kind, type, config); return config.getTypeHierarchy().isSubType(actual, this); } catch (UnresolvedReferenceException e) { throw new IllegalStateException(e.getMessage()); } //return false; }
warning("An attribute cannot have a complex type"); ContentTypeTest typeTest = new ContentTypeTest(primaryType, schemaType, env.getConfiguration(), false); if (fp == -1) { typeTest.setNillable(true); nextToken(); typeTest.setNillable(true); nextToken();
/** * Test whether this node test is satisfied by a given node. This method is only * fully supported for a subset of NodeTests, because it doesn't provide all the information * needed to evaluate all node tests. In particular (a) it can't be used to evaluate a node * test of the form element(N,T) or schema-element(E) where it is necessary to know whether the * node is nilled, and (b) it can't be used to evaluate a node test of the form * document-node(element(X)). This in practice means that it is used (a) to evaluate the * simple node tests found in the XPath 1.0 subset used in XML Schema, and (b) to evaluate * node tests where the node kind is known to be an attribute. * * @param nodeKind The kind of node to be matched * @param name identifies the expanded name of the node to be matched. * The value should be null for a node with no name. * @param annotation The actual content type of the node */ @Override public boolean matches(int nodeKind, NodeName name, SchemaType annotation) { return kind == nodeKind && matchesAnnotation(annotation); }
private String makeString(boolean forExport) { if (nodetest1 instanceof NameTest && operator == Token.INTERSECT) { int kind = nodetest1.getPrimitiveType(); String skind = kind == Type.ELEMENT ? "element(" : "attribute("; String content = ""; if (nodetest2 instanceof ContentTypeTest) { SchemaType schemaType = ((ContentTypeTest) nodetest2).getSchemaType(); if (forExport) { schemaType = schemaType.getNearestNamedType(); } content = ", " + schemaType.getEQName(); if (nodetest2.isNillable()) { content += "?"; } } String name; if (nodetest1 instanceof NameTest) { name = nodetest1.getMatchingNodeName().getEQName(); } else { name = nodetest1.toString(); } return skind + name + content + ')'; } else { String nt1 = nodetest1 == null ? "item()" : nodetest1.toString(); String nt2 = nodetest2 == null ? "item()" : nodetest2.toString(); return '(' + nt1 + ' ' + Token.tokens[operator] + ' ' + nt2 + ')'; } }
new NameTest(Type.ELEMENT, nameCode, getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ELEMENT, getConfiguration().getSchemaType(typeCode), getConfiguration())); checkItemType(type, locationId); } else { new NameTest(Type.ELEMENT, nameCode, getNamePool()), Token.INTERSECT, new ContentTypeTest(Type.ELEMENT, getConfiguration().getSchemaType(typeCode), getConfiguration())); checkItemType(type, locationId); checkedElements.add(key);
warning("An attribute cannot have a complex type"); ContentTypeTest typeTest = new ContentTypeTest(primaryType, schemaType, env.getConfiguration(), false); if (fp == -1) { typeTest.setNillable(true); nextToken(); typeTest.setNillable(true); nextToken();
/** * Test whether this node test is satisfied by a given node. This method is only * fully supported for a subset of NodeTests, because it doesn't provide all the information * needed to evaluate all node tests. In particular (a) it can't be used to evaluate a node * test of the form element(N,T) or schema-element(E) where it is necessary to know whether the * node is nilled, and (b) it can't be used to evaluate a node test of the form * document-node(element(X)). This in practice means that it is used (a) to evaluate the * simple node tests found in the XPath 1.0 subset used in XML Schema, and (b) to evaluate * node tests where the node kind is known to be an attribute. * * @param nodeKind The kind of node to be matched * @param name identifies the expanded name of the node to be matched. * The value should be null for a node with no name. * @param annotation The actual content type of the node */ @Override public boolean matches(int nodeKind, NodeName name, SchemaType annotation) { return kind == nodeKind && matchesAnnotation(annotation); }
private String makeString(boolean forExport) { if (nodetest1 instanceof NameTest && operator == Token.INTERSECT) { int kind = nodetest1.getPrimitiveType(); String skind = kind == Type.ELEMENT ? "element(" : "attribute("; String content = ""; if (nodetest2 instanceof ContentTypeTest) { SchemaType schemaType = ((ContentTypeTest) nodetest2).getSchemaType(); if (forExport) { schemaType = schemaType.getNearestNamedType(); } content = ", " + schemaType.getEQName(); if (nodetest2.isNillable()) { content += "?"; } } String name = nodetest1.getMatchingNodeName().getEQName(); return skind + name + content + ')'; } else { String nt1 = nodetest1 == null ? "item()" : nodetest1.toString(); String nt2 = nodetest2 == null ? "item()" : nodetest2.toString(); return '(' + nt1 + ' ' + Token.tokens[operator] + ' ' + nt2 + ')'; } }