Beispiel #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;
        }
Beispiel #2
0
        /// <summary>
        /// Factory method to get an <c>AtomicType</c> object representing the atomic type with a given QName.
        /// </summary>
        /// <remarks>
        /// It is undefined whether two calls on this method supplying the same QName will return the same
        /// <c>XdmAtomicType</c> object instance.
        /// </remarks>
        /// <param name="qname">The QName of the required type</param>
        /// <returns>An <c>AtomicType</c> object representing this type if it is present in this schema (and is an
        /// atomic type); otherwise, null. </returns>

        public XdmAtomicType GetAtomicType(QName qname)
        {
            JSchemaType type = config.getSchemaType(qname.ToStructuredQName());

            if (type is JBuiltInAtomicType)
            {
                return(XdmAtomicType.BuiltInAtomicType(qname));
            }
            else if (type is JAtomicType)
            {
                return(new XdmAtomicType((JAtomicType)type));
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
		/// Factory method to get an <c>AtomicType</c> object representing the atomic type with a given <c>QName</c>.
        /// </summary>
        /// <remarks>
		/// It is undefined whether two calls on this method supplying the same <c>QName</c> will return the same
        /// <c>XdmAtomicType</c> object instance.
        /// </remarks>
		/// <param name="qname">The <c>QName</c> of the required type</param>
        /// <returns>An <c>AtomicType</c> object representing this type if it is present in this schema (and is an
        /// atomic type); otherwise, null. </returns>

        public XdmAtomicType GetAtomicType(QName qname)
        {
			JSchemaType type = config.getSchemaType(qname.ToStructuredQName());
            if (type is JBuiltInAtomicType)
            {
                return XdmAtomicType.BuiltInAtomicType(qname);
            }
            else if (type is JAtomicType)
            {
                JItemTypeFactory factory = new JItemTypeFactory(processor.JProcessor);
                return new XdmAtomicType(factory.getAtomicType(qname.UnderlyingQName()));
            }
            else
            {
                return null;
            }
        }