/**
  * Construct an atomic value given its lexical representation and the name of the required
  * built-in atomic type.
  *
  * <p>This method cannot be used to construct values that are namespace-sensitive (QNames and
  * Notations)
  *
  * @param lexicalForm the value in the lexical space of the target data type. More strictly, the
  *     input value before the actions of the whitespace facet for the target data type are
  *     applied.
  * @param type the required atomic type. This must either be one of the built-in atomic types
  *     defined in XML Schema, or a user-defined type whose definition appears in a schema that is
  *     known to the Processor. It must not be an abstract type.
  * @throws SaxonApiException if the type is unknown, or is not atomic, or is namespace-sensitive;
  *     or if the value supplied in <tt>lexicalForm</tt> is not in the lexical space of the
  *     specified atomic type.
  */
 public XdmAtomicValue(String lexicalForm, ItemType type) throws SaxonApiException {
   net.sf.saxon.type.ItemType it = type.getUnderlyingItemType();
   if (!it.isAtomicType()) {
     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");
   }
   if (((AtomicType) it).isBuiltInType()) {
     ConversionResult cv =
         StringValue.convertStringToBuiltInType(
             lexicalForm, (BuiltInAtomicType) it, new Name11Checker());
     try {
       setValue(cv.asAtomic());
     } catch (ValidationException e) {
       throw new SaxonApiException(e);
     }
   } else {
     Configuration config =
         ((ConstructedItemType) type).getProcessor().getUnderlyingConfiguration();
     ConversionResult result =
         new StringValue(lexicalForm)
             .convert((AtomicType) it, true, config.getConversionContext());
     try {
       setValue(result.asAtomic());
     } catch (ValidationException e) {
       throw new SaxonApiException(e);
     }
   }
 }
Exemplo n.º 2
0
 public static Object getValue(
     Class<?> type, Item colItem, Configuration config, CommandContext context)
     throws XPathException, ValidationException, TransformationException {
   Object value = colItem;
   if (value instanceof AtomicValue) {
     value = getValue((AtomicValue) colItem, context);
   } else if (value instanceof Item) {
     Item i = (Item) value;
     if (XMLSystemFunctions.isNull(i)) {
       return null;
     }
     BuiltInAtomicType bat = typeMapping.get(type);
     if (bat != null) {
       AtomicValue av = new StringValue(i.getStringValueCS());
       ConversionResult cr = Converter.convert(av, bat, config.getConversionRules());
       value = cr.asAtomic();
       value = getValue((AtomicValue) value, context);
       if (value instanceof Item) {
         value = ((Item) value).getStringValue();
       }
     } else {
       value = i.getStringValue();
     }
   }
   return FunctionDescriptor.importValue(value, type);
 }