return true; // short cut if (t1.isPrimitiveNumeric()) { return t2.isPrimitiveNumeric(); if (t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t1.equals(BuiltInAtomicType.ANY_URI)) { t1 = BuiltInAtomicType.STRING; if (t2.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_URI)) { t2 = BuiltInAtomicType.STRING; if (t1.equals(BuiltInAtomicType.DAY_TIME_DURATION)) { t1 = BuiltInAtomicType.DURATION; if (t2.equals(BuiltInAtomicType.DAY_TIME_DURATION)) { t2 = BuiltInAtomicType.DURATION; if (t1.equals(BuiltInAtomicType.YEAR_MONTH_DURATION)) { t1 = BuiltInAtomicType.DURATION; if (t2.equals(BuiltInAtomicType.YEAR_MONTH_DURATION)) { t2 = BuiltInAtomicType.DURATION;
/** * Produce a representation of this type name for use in error messages. * Where this is a QName, it will use conventional prefixes */ public String toString(NamePool pool) { return getDisplayName(); }
/** * Analyze an expression to see whether the expression is capable of delivering a value of this * type. * * @param expression the expression that delivers the content * @param kind the node kind whose content is being delivered: {@link Type#ELEMENT}, * {@link Type#ATTRIBUTE}, or {@link Type#DOCUMENT} * @throws net.sf.saxon.trans.XPathException * if the expression will never deliver a value of the correct type */ public void analyzeContentExpression(Expression expression, int kind) throws XPathException { analyzeContentExpression(this, expression, kind); }
/** * Returns the built-in base type this type is derived from. * * @return the first built-in type found when searching up the type hierarchy */ public SchemaType getBuiltInBaseType() { BuiltInAtomicType base = this; while ((base != null) && (base.getFingerprint() > 1023)) { base = (BuiltInAtomicType)base.getBaseType(); } return base; }
/** * Determine whether this type is supported in a basic XSLT processor * * @return true if this type is permitted in a basic XSLT processor */ public boolean isAllowedInBasicXSLT() { return (isPrimitiveType() && getFingerprint() != StandardNames.XS_NOTATION); }
/** * Check that a value is in range for the specified subtype of xs:integer * * @param value the value to be checked * @param type the required item type, a subtype of xs:integer * @return true if successful, false if value is out of range for the subtype */ public static boolean checkRange(long value, /*@NotNull*/ BuiltInAtomicType type) { int fp = type.getFingerprint(); for (int i = 0; i < ranges.length; i += 3) { if (ranges[i] == fp) { long min = ranges[i + 1]; if (min != NO_LIMIT && value < min) { return false; } long max = ranges[i + 2]; return max == NO_LIMIT || max == MAX_UNSIGNED_LONG || value <= max; } } throw new IllegalArgumentException( "No range information found for integer subtype " + type.getDescription()); }
/** * Internal factory method to create a BuiltInAtomicType. There is one instance for each of the * built-in atomic types * * @param fingerprint The name of the type * @param baseType The base type from which this type is derived * @return the newly constructed built in atomic type */ private static BuiltInAtomicType makeAtomicType(int fingerprint, SimpleType baseType, boolean ordered) { BuiltInAtomicType t = new BuiltInAtomicType(fingerprint); t.setBaseTypeFingerprint(baseType.getFingerprint()); if (t.isPrimitiveType()) { t.primitiveFingerprint = fingerprint; } else { t.primitiveFingerprint = ((AtomicType)baseType).getPrimitiveType(); } t.ordered = ordered; BuiltInType.register(fingerprint, t); return t; } }
/** * Internal factory method to create a BuiltInAtomicType. There is one instance for each of the * built-in atomic types * * @param fingerprint The name of the type * @param baseType The base type from which this type is derived * @return the newly constructed built in atomic type */ private static BuiltInAtomicType makeAtomicType(int fingerprint, SimpleType baseType) { BuiltInAtomicType t = new BuiltInAtomicType(fingerprint); t.setBaseTypeFingerprint(baseType.getFingerprint()); if (t.isPrimitiveType()) { t.primitiveFingerprint = fingerprint; } else { t.primitiveFingerprint = ((AtomicType)baseType).getPrimitiveType(); } if (baseType instanceof BuiltInAtomicType) { t.ordered = ((BuiltInAtomicType)baseType).ordered; } BuiltInType.register(t.getFingerprint(), t); return t; } }
if (p0.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { p0 = BuiltInAtomicType.STRING; if (p1.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { p1 = BuiltInAtomicType.STRING; p0.equals(BuiltInAtomicType.ANY_ATOMIC) || p1.equals(BuiltInAtomicType.ANY_ATOMIC); if (!p0.isOrdered()) { XPathException err = new XPathException("Type " + t0.toString(env.getNamePool()) + " is not an ordered type"); err.setErrorCode("XPTY0004"); throw err; if (!p1.isOrdered()) { XPathException err = new XPathException("Type " + t1.toString(env.getNamePool()) + " is not an ordered type"); err.setErrorCode("XPTY0004");
/** * Determine the data type of the items returned by the expression, if possible * @return a value such as Type.STRING, Type.BOOLEAN, Type.NUMBER, Type.NODE, * or Type.ITEM (meaning not known in advance) * @param th the type hierarchy cache */ public ItemType getItemType(TypeHierarchy th) { if (requiredType.equals(BuiltInAtomicType.DOUBLE)) { return BuiltInAtomicType.DOUBLE; } else { return BuiltInAtomicType.FLOAT; } }
if (t0.isPrimitiveNumeric() || t1.isPrimitiveNumeric()) { DoubleValue v0 = Number_1.convert(a0, context.getConfiguration()); DoubleValue v1 = Number_1.convert(a1, context.getConfiguration()); if (t0.equals(BuiltInAtomicType.STRING) || t1.equals(BuiltInAtomicType.STRING) || (t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC) && t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC))) { StringValue s0 = StringValue.makeStringValue(a0.getStringValueCS()); StringValue s1 = StringValue.makeStringValue(a1.getStringValueCS()); if (t0.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { a0 = t1.getStringConverter(rules).convert((StringValue)a0).asAtomic(); if (t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { a1 = t0.getStringConverter(rules).convert((StringValue)a1).asAtomic();
private void mustBeOrdered(PlainType t1, BuiltInAtomicType p1) throws XPathException { if (!p1.isOrdered(true)) { XPathException err = new XPathException("Type " + t1.toString() + " is not an ordered type"); err.setErrorCode("XPTY0004"); err.setIsTypeError(true); err.setLocation(getLocation()); throw err; } }
/** * Get the typed value corresponding to a given string value, assuming it is * valid against this type (and that the containing node is not nilled) * * @param value the string value * @param resolver a namespace resolver used to resolve any namespace prefixes appearing * in the content of values. Can supply null, in which case any namespace-sensitive content * will be rejected. * @param rules the conversion rules to be used * @return an iterator over the atomic sequence comprising the typed value. The objects * returned by this SequenceIterator will all be of type {@link AtomicValue} * @throws ValidationException This method should be called only if it is known that the value is * valid. If the value is not valid, there is no guarantee that this method will perform validation, * but if it does detect a validity error, then it MAY throw a ValidationException. */ /*@NotNull*/ public AtomicSequence getTypedValue(CharSequence value, NamespaceResolver resolver, ConversionRules rules) throws ValidationException { // Fast path for common cases if (fingerprint == StandardNames.XS_STRING) { return StringValue.makeStringValue(value); } else if (fingerprint == StandardNames.XS_UNTYPED_ATOMIC) { return new UntypedAtomicValue(value); } StringConverter converter = getStringConverter(rules); if (isNamespaceSensitive()) { converter = (StringConverter) converter.setNamespaceResolver(resolver); } return converter.convertString(value).asAtomic(); }
/** * Two types are equal if they have the same fingerprint. * Note: it is normally safe to use ==, because we always use the static constants, one instance * for each built in atomic type. However, after serialization and deserialization a different instance * can appear. */ public boolean equals(Object obj) { return obj instanceof BuiltInAtomicType && getFingerprint() == ((BuiltInAtomicType) obj).getFingerprint(); }
/** * This class allows subtypes of xs:integer to be held, as well as xs:integer values. * This method sets the required type label. Note that this method modifies the value in situ. * * @param type the subtype of integer required * @return null if the operation succeeds, or a ValidationException if the value is out of range */ /*@Nullable*/ public ValidationFailure validateAgainstSubType(/*@NotNull*/ BuiltInAtomicType type) { if (checkRange(value, type)) { return null; } else { ValidationFailure err = new ValidationFailure("Value " + value + " cannot be converted to integer subtype " + type.getDescription()); err.setErrorCode("FORG0001"); return err; } }
private boolean subsumesUnderlyingType(AtomicType type) { BuiltInAtomicType builtIn = type instanceof BuiltInAtomicType ? (BuiltInAtomicType) type : (BuiltInAtomicType) type.getBuiltInBaseType(); while (true) { if (builtIn.isSameType(underlyingType)) { return true; } SchemaType base = builtIn.getBaseType(); if (!(base instanceof BuiltInAtomicType)) { return false; } builtIn = (BuiltInAtomicType) base; } }
int f = getFingerprint(); if (f == StandardNames.XS_STRING || f == StandardNames.XS_ANY_SIMPLE_TYPE || converter = getStringConverter(rules); if (isNamespaceSensitive()) { if (nsResolver == null) { throw new UnsupportedOperationException("Cannot validate a QName without a namespace resolver");
/** * Determine whether a given built-in type is disallowed in a given environment, and in the * case where it is disallowed, return a string explaining why * * @param pack the containing package * @param type the built-in type to be tested * @return null if the type is OK to be used; or a string explaining why not. */ public static String whyDisallowedType(PackageData pack, BuiltInAtomicType type) { if (!type.isAllowedInXSD10() && pack.getConfiguration().getXsdVersion() == Configuration.XSD10) { return "The built-in atomic type " + type.getDisplayName() + " is not recognized unless XSD 1.1 is enabled"; } return null; }
/** * Check whether the content of an attribute is namespace-sensitive * * * @param type the type annotation of the node * @param nodeNr the the node number of the elemente * @throws XPathException if an error occurs */ private void checkNotNamespaceSensitiveAttribute(SimpleType type, int nodeNr) throws XPathException { if (type.isNamespaceSensitive()) { if (type.isAtomicType()) { throw new CopyNamespaceSensitiveException( "Cannot copy QName or NOTATION values without copying namespaces"); } else { // For a union or list type, we need to check whether the actual value is namespace-sensitive AtomicSequence value = tree.getTypedValueOfAttribute(null, nodeNr); for (AtomicValue val : value) { if (val.getPrimitiveType().isNamespaceSensitive()) { throw new CopyNamespaceSensitiveException( "Cannot copy QName or NOTATION values without copying namespaces"); } } } } }
/** * Returns the base type that this type inherits from. This method can be used to get the * base type of a type that is known to be valid. * If this type is a Simpletype that is a built in primitive type then null is returned. * * @return the base type. * @throws IllegalStateException if this type is not valid. */ /*@Nullable*/ public SchemaType getKnownBaseType() { return getBaseType(); }