private static String getStartingNodeDescription(SchemaType type) { String s = type.getDescription(); if (s.startsWith("of element")) { return "a valid element named" + s.substring("of element".length()); } else if (s.startsWith("of attribute")) { return "a valid attribute named" + s.substring("of attribute".length()); } else { return "a node with " + (type.isSimpleType() ? "simple" : "complex") + " type " + s; } }
/** * This method returns true if there is a derivation between the reference type definition, that is the TypeInfo * on which the method is being called, and the other type definition, that is the one passed as parameters. * This method implements the DOM Level 3 TypeInfo interface. It must be called only on a valid type. * * @param typeNamespaceArg the namespace of the "other" type * @param typeNameArg the local name of the "other" type * @param derivationMethod the derivation method: zero or more of {@link SchemaType#DERIVATION_RESTRICTION}, * {@link SchemaType#DERIVATION_EXTENSION}, {@link SchemaType#DERIVATION_LIST}, or {@link SchemaType#DERIVATION_UNION}. * Zero means derived by any possible route. */ public boolean isDerivedFrom(String typeNamespaceArg, String typeNameArg, int derivationMethod) throws IllegalStateException { SchemaType base = schemaType.getBaseType(); int fingerprint = config.getNamePool().allocateFingerprint(typeNamespaceArg, typeNameArg); if (derivationMethod == 0 || (derivationMethod & schemaType.getDerivationMethod()) != 0) { if (base.getFingerprint() == fingerprint) { return true; } else if (base instanceof AnyType) { return false; } else { return new TypeInfoImpl(config, base).isDerivedFrom(typeNamespaceArg, typeNameArg, derivationMethod); } } return false; // Note: if derivationMethod is RESTRICTION, this interpretation requires every step to be derived // by restriction. An alternative interpretation is that at least one step must be derived by restriction. }
/** * Ask whether values of this type are atomizable * * @return true unless it is known that these items will be elements with element-only * content, in which case return false * @param th The type hierarchy cache */ public boolean isAtomizable(TypeHierarchy th) { return !(schemaType.isComplexType() && ((ComplexType) schemaType).getVariety() == ComplexType.VARIETY_ELEMENT_ONLY); }
/** * Get the nearest named type in the type hierarchy, that is, the nearest type that * is not anonymous. (In practice, since types cannot be derived from anonymous types, * this will either the type itself, or its immediate base type). * @return the nearest type, found by following the {@code getBaseType()} relation * recursively, that is not an anonymous type */ default SchemaType getNearestNamedType() { SchemaType type = this; while (type.isAnonymousType()) { type = type.getBaseType(); } return type; }
if (s1.isSameType(s2)) { return SAME_TYPE; t1 = t1.getBaseType(); if (t1 == null) { break; if (t1.isSameType(s2)) { return SUBSUMED_BY; t2 = t2.getBaseType(); if (t2 == null) { break; if (t2.isSameType(s1)) { return SUBSUMES;
if (parentType instanceof SimpleType) { XPathException err = new XPathException("Element " + elementName.getDisplayName() + " is not permitted here: the containing element is of simple type " + parentType.getDescription()); err.setIsTypeError(true); err.setLocation(getLocation()); Expression parent = getParentExpression(); Block block = new Block(new Expression[]{this}); parentType.analyzeContentExpression(block, Type.ELEMENT); setParentExpression(parent); XPathException err = new XPathException("Element " + elementName.getDisplayName() + " is not permitted in the content model of the complex type " + parentType.getDescription()); err.setIsTypeError(true); err.setLocation(getLocation());
public boolean isAvailable(SymbolicName.F functionName) { if (functionName.getArity() != 1) { return false; } final String uri = functionName.getComponentName().getURI(); final String localName = functionName.getComponentName().getLocalPart(); final SchemaType type = config.getSchemaType(new StructuredQName("", uri, localName)); if (type == null || type.isComplexType()) { return false; } if (type.isAtomicType() && ((AtomicType) type).isAbstract()) { return false; } return type != AnySimpleType.getInstance(); }
/** * Check that this type is validly derived from a given type * * @param type the type from which this type is derived * @param block the derivations that are blocked by the relevant element declaration * @throws SchemaException if the derivation is not allowed */ public void checkTypeDerivationIsOK(SchemaType type, int block) throws SchemaException { if (type == AnySimpleType.getInstance()) { // OK } else if (isSameType(type)) { // OK } else { SchemaType base = getBaseType(); if (base == null) { throw new SchemaException("The type " + getDescription() + " is not validly derived from the type " + type.getDescription()); } try { base.checkTypeDerivationIsOK(type, block); } catch (SchemaException se) { throw new SchemaException("The type " + getDescription() + " is not validly derived from the type " + type.getDescription()); } } }
/** * Get the type annotation to use for a given schema type * @param schemaType the schema type * @return the corresponding numeric type annotation */ public int getTypeAnnotation(SchemaType schemaType) { if (schemaType != null) { return schemaType.getFingerprint(); } else { return -1; } }
private void computeSingleValued(TypeHierarchy th) { singleValued = untyped; if (!singleValued) { ItemType nodeType = operand.getItemType(th); if (nodeType instanceof NodeTest) { SchemaType st = ((NodeTest)nodeType).getContentType(); if (st == AnyType.getInstance() || st.isAtomicType()) { singleValued = true; } } } }
/** * Get the typed value. * * @return the typed value. * @since 8.5 */ public AtomicSequence atomize() throws XPathException { if (getNodeKind() == Type.ELEMENT) { return getSchemaType().atomize(this); } else { return node.atomize(); } }
public void startElement (int nameCode, int typeCode, int locationId, int properties) throws XPathException { // System.err.println("startElement " + nameCode); nextReceiver.startElement(nameCode, typeCode, locationId, properties); byte preserveParent = stripStack[top]; byte preserve = (byte)(preserveParent & PRESERVE_PARENT); byte elementStrip = isSpacePreserving(nameCode); if (elementStrip == ALWAYS_PRESERVE) { preserve |= ALWAYS_PRESERVE; } else if (elementStrip == ALWAYS_STRIP) { preserve |= ALWAYS_STRIP; } if (preserve == 0 && typeCode != -1 && typeCode != StandardNames.XS_UNTYPED) { // if the element has simple content, whitespace stripping is disabled SchemaType type = getConfiguration().getSchemaType(typeCode); if (type.isSimpleType() || ((ComplexType)type).isSimpleContent()) { preserve |= CANNOT_STRIP; } } // put "preserve" value on top of stack top++; if (top >= stripStack.length) { byte[] newStack = new byte[top*2]; System.arraycopy(stripStack, 0, newStack, 0, top); stripStack = newStack; } stripStack[top] = preserve; }
public String toString() { return (kind == Type.ELEMENT ? "element(*, " : "attribute(*, ") + schemaType.getDescription() + ')'; }
/** * Simplify type so that hierarchy comparison could be accurate. */ private ItemType simplify(ItemType it) { TypeHierarchy th = processor.getUnderlyingConfiguration().getTypeHierarchy(); if (it instanceof CombinedNodeTest) { CombinedNodeTest n = (CombinedNodeTest) it; __log.debug(n.getComponentNodeTests()); return simplify(n.getComponentNodeTests()[1]); } else if (it instanceof NodeTest) { NodeTest n = (NodeTest) it; __log.debug(n); SchemaType t = n.getContentType(); if (t.isSimpleType() || t.equals(AnyType.getInstance())) { AtomicType at = it.getAtomizedItemType(); while (!at.isBuiltInType()) at = at.getSuperType(th).getAtomizedItemType(); return at; } else if (t.isComplexType()) { return n; } else { return AnyItemType.getInstance(); } } else { if (it == null) return null; else return it.getAtomizedItemType(); } }
/** * Get the content type allowed by this NodeTest (that is, the type annotation of the matched nodes). * Return AnyType if there are no restrictions. The default implementation returns AnyType. */ public SchemaType getContentType() { SchemaType type1 = nodetest1.getContentType(); SchemaType type2 = nodetest2.getContentType(); if (type1.isSameType(type2)) { return type1; } if (operator == Token.INTERSECT) { if (type2 instanceof AnyType || (type2 instanceof AnySimpleType && type1.isSimpleType())) { return type1; } if (type1 instanceof AnyType || (type1 instanceof AnySimpleType && type2.isSimpleType())) { return type2; } } return AnyType.getInstance(); }
if (typedValueArray == null || typedValueArray[nodeNr] == null) { SchemaType stype = getSchemaType(nodeNr); int annotation = stype.getFingerprint(); if (annotation == StandardNames.XS_UNTYPED_ATOMIC || annotation == StandardNames.XS_UNTYPED) { CharSequence stringValue = TinyParentNodeImpl.getStringValueCS(this, nodeNr); } else { TinyNodeImpl element = getNode(nodeNr); AtomicSequence value = stype.atomize(element); if (allowTypedValueCache) { if (typedValueArray == null) {
/** * Get the local name of the type (a system-allocated name if anonymous). Needed to implement the * DOM level 3 TypeInfo interface. */ public String getTypeName() { return schemaType.getStructuredQName().getLocalPart(); }
StructuredQName name = null; while (true) { name = st.getStructuredQName(); if (name != null) { return marker + name.getEQName(); } else { marker = "<"; st = st.getBaseType(); if (st == null) { return "Q{" + NamespaceConstant.SCHEMA + "}anyType";
public Expression simplify(ExpressionVisitor visitor) throws XPathException { elementName = visitor.simplify(elementName); namespace = visitor.simplify(namespace); Configuration config = visitor.getConfiguration(); setLazyConstruction(config.isLazyConstructionMode()); preservingTypes |= !config.isSchemaAware(Configuration.XML_SCHEMA); if (getSchemaType() != null) { itemType = new ContentTypeTest(Type.ELEMENT, getSchemaType(), config); getSchemaType().analyzeContentExpression(content, Type.ELEMENT, visitor.getStaticContext()); } else if (validation == Validation.STRIP || !config.isSchemaAware(Configuration.XML_SCHEMA)) { itemType = new ContentTypeTest(Type.ELEMENT, Untyped.getInstance(), config); } else { // paradoxically, we know less about the type if validation="strict" is specified! // We know that it won't be untyped, but we have no way of representing that. itemType = NodeKindTest.ELEMENT; } return super.simplify(visitor); }
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; }