Exemple #1
0
        /// <summary>
        /// Construct an atomic value of a given built-in or user-defined type
        /// </summary>
        /// <example>
        ///   <code>AtomicValue("abcd", QName.XDT_UNTYPED_ATOMIC)</code>
        ///   <para>creates an untyped atomic value containing the string "abcd"</para>
        /// </example>
        /// <param name="lexicalForm">The string representation of the value (any value that is acceptable
        /// in the lexical space, as defined by XML Schema Part 2). Whitespace normalization as defined by
        /// the target type will be applied to the value.</param>
        /// <param name="type">The QName giving the name of the target type. This must be an atomic
        /// type, and it must not be a type that is namespace-sensitive (QName, NOTATION, or types derived
        /// from these). If the type is a user-defined type then its definition must be present
        /// in the schema cache maintained by the <c>SchemaManager</c>.</param>
        /// <param name="processor">The <c>Processor</c> object. This is needed for looking up user-defined
        /// types, and also because some conversions are context-sensitive, for example they depend on the
        /// implicit timezone or the choice of XML 1.0 versus XML 1.1 for validating names.</param>
        /// <exception name="ArgumentException">Thrown if the type is unknown or unsuitable, or if the supplied string is not
        /// a valid lexical representation of a value of the given type.</exception>

        public XdmAtomicValue(String lexicalForm, QName type, Processor processor)
        {
            JConfiguration jconfig = processor.config;
            int            fp      = jconfig.getNamePool().getFingerprint(type.Uri, type.LocalName);

            if (fp == -1)
            {
                throw new ArgumentException("Unknown name " + type);
            }
            JSchemaType st = jconfig.getSchemaType(fp);

            if (st == null)
            {
                throw new ArgumentException("Unknown type " + type);
            }
            if (!(st is JAtomicType))
            {
                throw new ArgumentException("Specified type " + type + " is not atomic");
            }
            if (((JAtomicType)st).isNamespaceSensitive())
            {
                throw new ArgumentException("Specified type " + type + " is namespace-sensitive");
            }
            JAtomicValue result = new StringValue(lexicalForm).convert(
                (JAtomicType)st,
                jconfig.getConversionContext(),
                true);

            if (result is ValidationErrorValue)
            {
                throw new ArgumentException(((ValidationErrorValue)result).getException().getMessage());
            }
            this.value = result;
        }
Exemple #2
0
        /// <summary>
        /// Get the internal Saxon fingerprint of this name
        /// </summary>
        /// <param name="config">The Saxon configuration (the fingerprint for a QName is different in different configurations)</param>
        /// <returns>
        /// The integer fingerprint of the name
        /// </returns>

        internal int GetFingerprint(JConfiguration config)
        {
            JNamePool namePool = config.getNamePool();
            if (fingerprint != -1 && pool == namePool)
            {
                return fingerprint;
            }
            return namePool.allocate(prefix, uri, local) & 0xfffff;
        }