Beispiel #1
0
        private ValueDefinition ParseValue(XmlElement element)
        {
            var definition = new ValueDefinition();

            if (element.HasAttribute(TYPE_ATTR))
            {
                definition.Type = element.GetAttribute(TYPE_ATTR);
                if (string.IsNullOrWhiteSpace(definition.Type))
                {
                    throw new ConfigurationException("Attribute 'type' is required.", element.OuterXml);
                }
            }

            definition.Value = element.InnerText;
            definition.Validate();
            return(definition);
        }
Beispiel #2
0
        private void ParseEntry(XmlElement element, out DefinitionBase keyDefinition, out DefinitionBase valueDefinition)
        {
            if (element.HasAttribute(KEY_ATTR) && element.HasAttribute(KEY_REF_ATTR))
            {
                throw new ConfigurationException("Attribute 'key' and 'key-ref' cannot be assigned at the same time.", element.OuterXml);
            }

            if (element.HasAttribute(VALUE_ATTR) && element.HasAttribute(VALUE_REF_ATTR))
            {
                throw new ConfigurationException("Attribute 'value' and 'value-ref' cannot be assigned at the same time.", element.OuterXml);
            }

            if (element.HasAttribute(VALUE_ATTR) && element.HasChildNodes)
            {
                throw new ConfigurationException("Attribute 'value' and child node cannot be assigned at the same time.", element.OuterXml);
            }

            if (element.HasAttribute(VALUE_REF_ATTR) && element.HasChildNodes)
            {
                throw new ConfigurationException("Attribute 'value-ref' and child node cannot be assigned at the same time.", element.OuterXml);
            }

            if (element.HasChildNodes && element.ChildNodes.Count > 1)
            {
                throw new ConfigurationException("Only one child node is allowed.", element.OuterXml);
            }


            if (element.HasAttribute(KEY_ATTR))
            {
                keyDefinition = new ValueDefinition()
                {
                    Value = element.GetAttribute(KEY_ATTR)
                };
                keyDefinition.Validate();
            }
            else if (element.HasAttribute(KEY_REF_ATTR))
            {
                var objectId = element.GetAttribute(KEY_REF_ATTR);
                if (string.IsNullOrWhiteSpace(objectId))
                {
                    throw new ConfigurationException("Attribute 'key-ref' is required.", element.OuterXml);
                }

                keyDefinition = FindReferenceObject(objectId);
            }
            else
            {
                throw new ConfigurationException("Attribute 'key' and 'key-ref' cannot be empty at the same time.", element.OuterXml);
            }

            if (element.HasAttribute(VALUE_ATTR))
            {
                valueDefinition = new ValueDefinition()
                {
                    Value = element.GetAttribute(VALUE_ATTR)
                };
                valueDefinition.Validate();
            }
            else if (element.HasAttribute(VALUE_REF_ATTR))
            {
                var objectId = element.GetAttribute(VALUE_REF_ATTR);
                if (string.IsNullOrWhiteSpace(objectId))
                {
                    throw new ConfigurationException("Attribute 'value-ref' is required.", element.OuterXml);
                }

                valueDefinition = FindReferenceObject(objectId);
            }
            else if (element.HasChildNodes)
            {
                valueDefinition = ParseChildNode((XmlElement)element.FirstChild);
            }
            else
            {
                valueDefinition = ValueDefinition.NULL;
            }
        }