private Calculator assignCalculator(AtomicType type0, AtomicType type1, boolean mustResolve) throws XPathException { Calculator calculator = Calculator.getCalculator(type0.getFingerprint(), type1.getFingerprint(), ArithmeticExpression.mapOpCode(operator), mustResolve); if (calculator == null) { XPathException de = new XPathException("Arithmetic operator is not defined for arguments of types (" + type0.getDescription() + ", " + type1.getDescription() + ")"); de.setLocation(getLocation()); de.setErrorCode("XPTY0004"); throw de; } return calculator; }
/** * Create a copy of this atomic value, with a different type label * * @param typeLabel the type label of the new copy. The caller is responsible for checking that * the value actually conforms to this type. */ /*@NotNull*/ public AtomicValue copyAsSubType(/*@NotNull*/ AtomicType typeLabel) { if (typeLabel.getPrimitiveType() == StandardNames.XS_INTEGER) { BigIntegerValue v = new BigIntegerValue(value); v.typeLabel = typeLabel; return v; } else { return new BigDecimalValue(new BigDecimal(value)); } }
return convertStringToBuiltInType(value, (BuiltInAtomicType)targetType, checker); } else { BuiltInAtomicType primitiveType = (BuiltInAtomicType)targetType.getPrimitiveItemType(); if (primitiveType.getFingerprint() == StandardNames.XS_STRING) { int whitespaceAction = targetType.getWhitespaceAction(null); value = Whitespace.applyWhitespaceNormalization(whitespaceAction, value); ValidationFailure vf = targetType.validate((AtomicValue)result, value, checker); if (vf != null) { return vf;
/** * Determine whether one atomic type is a subtype of another (without access to the TypeHierarchy object) * @param one the first atomic type * @param two the second atomic type * @return true if the first atomic type is equal to, or derived by restriction from, the second atomic * type */ public static boolean isSubType(AtomicType one, AtomicType two) { while (true) { if (one.getFingerprint() == two.getFingerprint()) { return true; } SchemaType s = one.getBaseType(); if (s instanceof AtomicType) { one = (AtomicType)s; } else { return false; } } }
/** * Create a cast expression * @param source expression giving the value to be converted * @param target the type to which the value is to be converted * @param allowEmpty true if the expression allows an empty sequence as input, producing * an empty sequence as output. If false, an empty sequence is a type error. */ public CastExpression(Expression source, AtomicType target, boolean allowEmpty) { super(source); this.allowEmpty = allowEmpty; targetType = target; targetPrimitiveType = (AtomicType)target.getPrimitiveItemType(); derived = (targetType.getFingerprint() != targetPrimitiveType.getFingerprint()); adoptChildExpression(source); }
if (targetType.isPrimitiveType()) { return convertPrimitive((BuiltInAtomicType)targetType, validate, context); } else if (targetType.isAbstract()) { return new ValidationFailure("Cannot convert to an abstract type"); } else if (targetType.isExternalType()) { return new ValidationFailure("Cannot convert to an external type"); } else { BuiltInAtomicType primitiveType = (BuiltInAtomicType)targetType.getPrimitiveItemType(); ConversionResult cr = convertPrimitive(primitiveType, validate, context); if (cr instanceof ValidationFailure) { int whitespaceAction = targetType.getWhitespaceAction( context == null ? null : context.getConfiguration().getTypeHierarchy()); CharSequence cs = Whitespace.applyWhitespaceNormalization( lexicalValue = getCanonicalLexicalRepresentation(); ValidationFailure vf = targetType.validate((AtomicValue)cr, lexicalValue, (context == null ? Name10Checker.getInstance() : context.getConfiguration().getNameChecker())); if (vf != null) {
if (type0.getFingerprint() == StandardNames.XS_UNTYPED_ATOMIC) { operand0 = new UntypedAtomicConverter(operand0, BuiltInAtomicType.DOUBLE, true); type0 = BuiltInAtomicType.DOUBLE; if (type1.getFingerprint() == StandardNames.XS_UNTYPED_ATOMIC) { operand1 = new UntypedAtomicConverter(operand1, BuiltInAtomicType.DOUBLE, true); type1 = BuiltInAtomicType.DOUBLE; if (type0.isExternalType() || type1.isExternalType()) { XPathException de = new XPathException("Arithmetic operators are not defined for external objects"); de.setLocator(this); type0.getFingerprint(), type1.getFingerprint(), mapOpCode(operator), mustResolve); type0.getDescription() + ", " + type1.getDescription() + ")"); de.setLocator(this); de.setErrorCode("XPTY0004");
return StringConverter.IdentityConverter.INSTANCE; } else if (source == BuiltInAtomicType.STRING || source == BuiltInAtomicType.UNTYPED_ATOMIC) { return target.getStringConverter(this); } else if (target == BuiltInAtomicType.STRING) { return Converter.ToStringConverter.INSTANCE; int key = (source.getPrimitiveType() << 20) | target.getFingerprint(); Converter converter = converterCache.get(key); if (converter == null) {
/** * Get the index associated with a particular key, a particular source document, * and a particular primitive item type * @param doc the document whose index is required * @param keyFingerprint the name of the key definition * @param itemType the primitive item type of the values being indexed * @return either an index (as a HashMap), or the String "under construction", or null */ private synchronized Object getIndex(DocumentInfo doc, int keyFingerprint, AtomicType itemType) { if (docIndexes==null) { // it's transient, so it will be null when reloading a compiled stylesheet docIndexes = new WeakHashMap(10); } WeakReference ref = (WeakReference)docIndexes.get(doc); if (ref==null) return null; HashMap indexList = (HashMap)ref.get(); if (indexList==null) return null; return indexList.get(new Long(((long)keyFingerprint)<<32 | itemType.getFingerprint())); }
throw new SaxonApiException("Requested type is not atomic"); if (((AtomicType) it).isAbstract()) { throw new SaxonApiException("Requested type is an abstract type"); if (((AtomicType) it).isNamespaceSensitive()) { throw new SaxonApiException("Requested type is namespace-sensitive"); StringConverter converter = ((AtomicType)it).getStringConverter(type.getConversionRules()); setValue(converter.convertString(lexicalForm).asAtomic()); } catch (ValidationException e) {
/** * Get the expression's dependencies. If the target type is namespace-sensitive, then the expression * has a dependency on the namespace bindings in the static context * * @return the expression's dependencies. */ @Override public int getIntrinsicDependencies() { return getTargetType().isNamespaceSensitive() ? StaticProperty.DEPENDS_ON_STATIC_CONTEXT : 0; }
expect(Token.NAME); AtomicType at = getAtomicType(t.currentTokenValue); if (at.getFingerprint() == StandardNames.XS_ANY_ATOMIC_TYPE) { grumble("Cannot cast to xs:anyAtomicType", "XPST0080"); if (at.getFingerprint() == StandardNames.XS_NOTATION) { grumble("Cannot cast to xs:NOTATION", "XPST0080"); nextToken(); if (at.isNamespaceSensitive() && exp instanceof StringLiteral) { try { String source = ((StringLiteral)exp).getStringValue();
StringConverter sc = a1.getItemType().getPrimitiveItemType().getStringConverter(rules); if (a1 instanceof QualifiedNameValue) { sc = (StringConverter) sc.setNamespaceResolver(nsResolver); a0 = ((UntypedAtomicValue) a0).obtainConversionResult(a1.getItemType().getPrimitiveType(), sc).asAtomic(); StringConverter sc = a0.getItemType().getPrimitiveItemType().getStringConverter(rules); if (a0 instanceof QualifiedNameValue) { sc = (StringConverter) sc.setNamespaceResolver(nsResolver); a1 = ((UntypedAtomicValue) a1).obtainConversionResult(a0.getItemType().getPrimitiveType(), sc).asAtomic();
/** * Create a cast expression * * @param source expression giving the value to be converted * @param target the type to which the value is to be converted * @param allowEmpty true if the expression allows an empty sequence as input, producing * an empty sequence as output. If false, an empty sequence is a type error. */ public CastingExpression(Expression source, AtomicType target, boolean allowEmpty) { super(source); this.allowEmpty = allowEmpty; targetType = target; targetPrimitiveType = (AtomicType) target.getPrimitiveItemType(); //derived = (targetType.getFingerprint() != targetPrimitiveType.getFingerprint()); }
AtomicType t1 = operand1.getItemType(th).getAtomizedItemType(); if (t0.isExternalType() || t1.isExternalType()) { XPathException err = new XPathException("Cannot perform comparisons involving external objects"); err.setIsTypeError(true); BuiltInAtomicType p0 = (BuiltInAtomicType)t0.getPrimitiveItemType(); if (p0.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { p0 = BuiltInAtomicType.STRING; BuiltInAtomicType p1 = (BuiltInAtomicType)t1.getPrimitiveItemType(); if (p1.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { p1 = BuiltInAtomicType.STRING;
public ValidationFailure validate( CharSequence input) { if (NameChecker.isValidNCName(Whitespace.trimWhitespace(input))) { return null; } else { return new ValidationFailure("The value '" + input + "' is not a valid " + targetType.getDisplayName()); } } }
if (t0.isExternalType() || t1.isExternalType()) { XPathException err = new XPathException("Cannot perform comparisons involving external objects"); err.setIsTypeError(true); BuiltInAtomicType p0 = (BuiltInAtomicType)t0.getPrimitiveItemType(); if (p0.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { p0 = BuiltInAtomicType.STRING; BuiltInAtomicType p1 = (BuiltInAtomicType)t1.getPrimitiveItemType(); if (p1.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) { p1 = BuiltInAtomicType.STRING; visitor.getStaticContext().issueWarning("Comparison of " + t0.toString(namePool) + (opt0 ? "?" : "") + " to " + t1.toString(namePool) + (opt1 ? "?" : "") + " will fail unless " + which + " empty", this); XPathException err = new XPathException("Cannot compare " + t0.toString(namePool) + " to " + t1.toString(namePool)); err.setIsTypeError(true); err.setErrorCode("XPTY0004"); XPathException err = new XPathException("Type " + t0.toString(env.getNamePool()) + " is not an ordered type"); err.setErrorCode("XPTY0004"); err.setIsTypeError(true); XPathException err = new XPathException("Type " + t1.toString(env.getNamePool()) + " is not an ordered type"); err.setErrorCode("XPTY0004"); err.setIsTypeError(true);
private QName qnameFor (AtomicType type) { if (type.isBuiltInType()) { return qnameFor (((BuiltInAtomicType)type).getQualifiedName()); } return qnameForNameCode(type.getNameCode()); }
private AbstractExpression castExprFor (AbstractExpression ae, AtomicType type) { if (type.isAbstract()) { return ae; } return new FunCall (qnameFor(type), valueTypeForItemType(type), ae); }
if (((AtomicType)t0).isExternalType() || ((AtomicType)t1).isExternalType()) { XPathException err = new XPathException("Cannot perform comparisons involving external objects"); err.setIsTypeError(true);