@Override public ConversionResult convert(/*@NotNull*/ AtomicValue input) { if (input instanceof UntypedAtomicValue) { return untypedConverter.convert(input); } else { return input; } } }
@Override public ConversionResult convert(/*@NotNull*/ AtomicValue input) { if (input instanceof UntypedAtomicValue) { return untypedConverter.convert(input); } else { return input; } } }
public ConversionResult convert(AtomicValue input) { ConversionResult temp = phaseOne.convert(input); if (temp instanceof ValidationFailure) { return temp; } AtomicValue aTemp = (AtomicValue)temp; if (phaseTwo instanceof DownCastingConverter) { return ((DownCastingConverter) phaseTwo).convert(aTemp, aTemp.getCanonicalLexicalRepresentation()); } else { return phaseTwo.convert(aTemp); } }
public ConversionResult convert(AtomicValue input) { ConversionResult temp = phaseOne.convert(input); if (temp instanceof ValidationFailure) { return temp; } AtomicValue aTemp = (AtomicValue)temp; if (phaseTwo instanceof DownCastingConverter) { return ((DownCastingConverter) phaseTwo).convert(aTemp, aTemp.getCanonicalLexicalRepresentation()); } else { return phaseTwo.convert(aTemp); } }
public AtomicValue mapItem(AtomicValue item) throws XPathException { ConversionResult result = converter.convert(item); if (errorCode != null && result instanceof ValidationFailure) { ((ValidationFailure)result).setErrorCode(errorCode); } return result.asAtomic(); } }
public AtomicValue mapItem(AtomicValue item) throws XPathException { ConversionResult result = converter.convert(item); if (errorCode != null && result instanceof ValidationFailure) { ((ValidationFailure)result).setErrorCode(errorCode); } return result.asAtomic(); } }
public ConversionResult convert(/*@NotNull*/ AtomicValue input) { Converter converter = rules.getConverter(input.getPrimitiveType(), (AtomicType) requiredItemType); if (converter == null) { return new ValidationFailure("Cannot convert value from " + input.getPrimitiveType() + " to " + requiredItemType); } else { return converter.convert(input); } } };
public ConversionResult convert(/*@NotNull*/ AtomicValue input) { Converter converter = rules.getConverter(input.getPrimitiveType(), (AtomicType) requiredItemType); if (converter == null) { return new ValidationFailure("Cannot convert value from " + input.getPrimitiveType() + " to " + requiredItemType); } else { return converter.convert(input); } } };
public Stream<? extends XdmAtomicValue> apply(XdmItem xdmItem) { try { AtomicValue source = ((XdmAtomicValue)xdmItem).getUnderlyingValue(); Converter converter = rules.getConverter(source.getItemType(), (AtomicType)tType); AtomicValue result = converter.convert(source).asAtomic(); return Stream.of((XdmAtomicValue) XdmValue.wrap(result)); } catch (ValidationException e) { throw new SaxonApiUncheckedException(new SaxonApiException(e)); } } });
public Stream<? extends XdmAtomicValue> apply(XdmItem xdmItem) { try { AtomicValue source = ((XdmAtomicValue)xdmItem).getUnderlyingValue(); Converter converter = rules.getConverter(source.getItemType(), (AtomicType)tType); AtomicValue result = converter.convert(source).asAtomic(); return Stream.of((XdmAtomicValue) XdmValue.wrap(result)); } catch (ValidationException e) { throw new SaxonApiUncheckedException(new SaxonApiException(e)); } } });
/** * Evaluate as an Item. This should only be called if the AtomicSequenceConverter has cardinality zero-or-one */ public AtomicValue evaluateItem(XPathContext context) throws XPathException { Converter conv = getConverterDynamically(context); AtomicValue item = (AtomicValue) getBaseExpression().evaluateItem(context); if (item == null) { return null; } ConversionResult result = conv.convert(item); if (roleDiagnostic != null && result instanceof ValidationFailure) { // TODO: use more of the information in the roleDiagnostic to form the error message ((ValidationFailure)result).setErrorCode(roleDiagnostic.getErrorCode()); } return result.asAtomic(); }
/** * Evaluate as an Item. This should only be called if the AtomicSequenceConverter has cardinality zero-or-one */ public AtomicValue evaluateItem(XPathContext context) throws XPathException { Converter conv = getConverterDynamically(context); AtomicValue item = (AtomicValue) getBaseExpression().evaluateItem(context); if (item == null) { return null; } ConversionResult result = conv.convert(item); if (roleDiagnostic != null && result instanceof ValidationFailure) { // TODO: use more of the information in the roleDiagnostic to form the error message ((ValidationFailure)result).setErrorCode(roleDiagnostic.getErrorCode()); } return result.asAtomic(); }
/** * Convenience method to convert a given value to a given type. Note: it is more efficient * to obtain a converter in advance and to reuse it for multiple conversions * * @param value the value to be converted * @param targetType the type to which the value is to be converted * @param rules the conversion rules for the configuration * @return the converted value * @throws ValidationException if conversion fails */ public static AtomicValue convert(AtomicValue value, AtomicType targetType, ConversionRules rules) throws ValidationException { Converter converter = rules.getConverter(value.getPrimitiveType(), targetType); if (converter == null) { ValidationFailure ve = new ValidationFailure("Cannot convert value from " + value.getPrimitiveType() + " to " + targetType); ve.setErrorCode("FORG0001"); throw ve.makeException(); } return converter.convert(value).asAtomic(); }
/** * Convenience method to convert a given value to a given type. Note: it is more efficient * to obtain a converter in advance and to reuse it for multiple conversions * * @param value the value to be converted * @param targetType the type to which the value is to be converted * @param rules the conversion rules for the configuration * @return the converted value * @throws ValidationException if conversion fails */ public static AtomicValue convert(AtomicValue value, AtomicType targetType, ConversionRules rules) throws ValidationException { Converter converter = rules.getConverter(value.getPrimitiveType(), targetType); if (converter == null) { ValidationFailure ve = new ValidationFailure("Cannot convert value from " + value.getPrimitiveType() + " to " + targetType); ve.setErrorCode("FORG0001"); throw ve.makeException(); } return converter.convert(value).asAtomic(); }
protected Expression preEvaluate() throws XPathException { GroundedValue literalOperand = ((Literal) getBaseExpression()).getValue(); if (literalOperand instanceof AtomicValue && converter != null) { ConversionResult result = converter.convert((AtomicValue) literalOperand); return Literal.makeLiteral(BooleanValue.get(!(result instanceof ValidationFailure)), this); } final int length = literalOperand.getLength(); if (length == 0) { return Literal.makeLiteral(BooleanValue.get(allowsEmpty()), this); } if (length > 1) { return Literal.makeLiteral(BooleanValue.FALSE, this); } return this; }
protected Expression preEvaluate() throws XPathException { GroundedValue literalOperand = ((Literal) getBaseExpression()).getValue(); if (literalOperand instanceof AtomicValue && converter != null) { ConversionResult result = converter.convert((AtomicValue) literalOperand); return Literal.makeLiteral(BooleanValue.get(!(result instanceof ValidationFailure)), this); } final int length = literalOperand.getLength(); if (length == 0) { return Literal.makeLiteral(BooleanValue.get(allowsEmpty()), this); } if (length > 1) { return Literal.makeLiteral(BooleanValue.FALSE, this); } return this; }
private static Expression makePromoter(Expression exp, Converter converter, BuiltInAtomicType type) { ConversionRules rules = exp.getConfiguration().getConversionRules(); converter.setConversionRules(rules); if (exp instanceof Literal && ((Literal) exp).getValue() instanceof AtomicValue) { ConversionResult result = converter.convert((AtomicValue) ((Literal) exp).getValue()); if (result instanceof AtomicValue) { Literal converted = Literal.makeLiteral((AtomicValue) result, exp); ExpressionTool.copyLocationInfo(exp, converted); return converted; } } AtomicSequenceConverter asc = new AtomicSequenceConverter(exp, type); asc.setConverter(converter); ExpressionTool.copyLocationInfo(exp, asc); return asc; }
private static Expression makePromoter(Expression exp, Converter converter, BuiltInAtomicType type) { ConversionRules rules = exp.getConfiguration().getConversionRules(); converter.setConversionRules(rules); if (exp instanceof Literal && ((Literal) exp).getValue() instanceof AtomicValue) { ConversionResult result = converter.convert((AtomicValue) ((Literal) exp).getValue()); if (result instanceof AtomicValue) { Literal converted = Literal.makeLiteral((AtomicValue) result, exp); ExpressionTool.copyLocationInfo(exp, converted); return converted; } } AtomicSequenceConverter asc = new AtomicSequenceConverter(exp, type); asc.setConverter(converter); ExpressionTool.copyLocationInfo(exp, asc); return asc; }
/** * Determine whether a value is castable to a given type * * @param value the value to be tested * @param targetType the type to be tested against * @param context XPath dynamic context * @return true if the value is castable to the required type */ private boolean isCastable(AtomicValue value, AtomicType targetType, XPathContext context) { Converter converter = this.converter; if (converter == null) { converter = context.getConfiguration().getConversionRules().getConverter(value.getPrimitiveType(), targetType); if (converter == null) { return false; } if (converter.isAlwaysSuccessful()) { return true; } if (getTargetType().isNamespaceSensitive()) { converter = converter.setNamespaceResolver(getRetainedStaticContext()); } } return !(converter.convert(value) instanceof ValidationFailure); }
/** * Determine whether a value is castable to a given type * * @param value the value to be tested * @param targetType the type to be tested against * @param context XPath dynamic context * @return true if the value is castable to the required type */ private boolean isCastable(AtomicValue value, AtomicType targetType, XPathContext context) { Converter converter = this.converter; if (converter == null) { converter = context.getConfiguration().getConversionRules().getConverter(value.getPrimitiveType(), targetType); if (converter == null) { return false; } if (converter.isAlwaysSuccessful()) { return true; } if (getTargetType().isNamespaceSensitive()) { converter = converter.setNamespaceResolver(getRetainedStaticContext()); } } return !(converter.convert(value) instanceof ValidationFailure); }