/// <summary>
        /// Processes a parameter map element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessParameterMapElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = null;

            if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_CLASS))
            {
                config = new MutableConfiguration(
                        element.Name,
                        ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]),
                        element.Attributes[ConfigConstants.ATTRIBUTE_CLASS]);
            }
            else
            {
                config = new MutableConfiguration(
                        element.Name,
                        ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]));
            }
            config.CreateAttributes(element.Attributes);
            config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);

            AddAttribute(config, ConfigConstants.ATTRIBUTE_EXTENDS, true);

            configurationStore.AddParameterMapConfiguration(config);
            element.Configuration = config;
        }
        /// <summary>
        /// Processes the SQL map element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessSqlMapElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_URI))
            {
                string uri = element.Attributes[ConfigConstants.ATTRIBUTE_URI];
                IResource resource = ResourceLoaderRegistry.GetResource(uri);

                Contract.Assert.That(resource, Is.Not.Null).When("process Resource in ConfigurationInterpreter");

                using (resource)
                {
                    IConfiguration setting = configurationStore.Settings[ConfigConstants.ATTRIBUTE_VALIDATE_SQLMAP];
                    if (setting != null)
                    {
                        bool mustValidate = false;
                        Boolean.TryParse(setting.Value, out mustValidate);
                        if (mustValidate)
                        {
                            XmlDocument document = new XmlDocument();
                            document.Load(resource.Stream);
                            SchemaValidator.Validate(document.ChildNodes[1], "SqlMap.xsd");
                        }
                    }

                    resource.Stream.Position = 0; 
                    using (XmlTextReader reader = new XmlTextReader(resource.Stream))
                    {
                        using (XmlMappingProcessor processor = new XmlMappingProcessor())
                        {
                            processor.Process(reader, configurationStore);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Processes the database element in the SqlMap.config file.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessDatabaseElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = new MutableConfiguration(element.Name);
            config.CreateAttributes(element.Attributes);

            configurationStore.AddDatabaseConfiguration(config);
            element.Configuration = config;
        }
示例#4
0
        /// <summary>
        /// Processes the add element in external properties file
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessAddElement(Tag element, IConfigurationStore configurationStore)
        {
            IConfiguration config = new MutableConfiguration(
                element.Name,
                element.Attributes[ConfigConstants.ATTRIBUTE_KEY],
                element.Attributes[ConfigConstants.ATTRIBUTE_VALUE]);

            configurationStore.AddPropertyConfiguration(config);
        }
        /// <summary>
        /// Processes the type alias element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessTypeAliasElement(Tag element, IConfigurationStore configurationStore)
        {
            IConfiguration config = new MutableConfiguration(
                element.Name,
                element.Attributes[ConfigConstants.ATTRIBUTE_ALIAS],
                element.Attributes[ConfigConstants.ATTRIBUTE_TYPE]);

            configurationStore.AddAliasConfiguration(config);
        }
示例#6
0
        /// <summary>
        /// Processes the Sql element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessSqlElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[ConfigConstants.ATTRIBUTE_ID]);
            config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);

            configurationStore.AddStatementConfiguration(config);
            element.Configuration = config;
        }
        /// <summary>
        /// Processes the flush intervall element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessFlushIntervallElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_CACHEMODEL)
            {
                MutableConfiguration config = new MutableConfiguration(element.Name);
                config.CreateAttributes(element.Attributes);

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes the constructor element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessConstructorElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_RESULTMAP)
            {
                IConfiguration config = new MutableConfiguration(element.Name);
                element.Configuration = config;

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes the type handler element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessTypeHandlerElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = new MutableConfiguration(
                element.Name,
                element.Attributes[ConfigConstants.ATTRIBUTE_TYPE]
                );
            config.CreateAttributes(element.Attributes);

            configurationStore.AddTypeHandlerConfiguration(config);
        }
        /// <summary>
        /// Processes the providers element in the SqlMap.config file.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessProvidersElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_URI))
            {
                string uri = element.Attributes[ConfigConstants.ATTRIBUTE_URI];

                using (XmlTextReader reader = Resources.GetUriAsXmlReader(uri))
                {
                    this.Process(reader, configurationStore);
                }
            }
        }
        /// <summary>
        /// Processes the Include element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessIncludeElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = new MutableConfiguration(
                element.Name,
                element.Attributes[ConfigConstants.ATTRIBUTE_REFID]);
            config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);
            config.CreateAttributes(element.Attributes);
            config.Parent = element.Parent.Configuration;

            element.Parent.Configuration.Children.Add(config);
            element.Configuration = config;
        }
        /// <summary>
        /// Processes the argument element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessArgumentElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_CONSTRUCTOR)
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[ConfigConstants.ATTRIBUTE_ARGUMENTNAME]);
                config.CreateAttributes(element.Attributes);

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes the dynamic elements.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessDynamicElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null)
            {
                MutableConfiguration config = new MutableConfiguration(element.Name);
                config.CreateAttributes(element.Attributes);
                config.Parent = element.Parent.Configuration;

                element.Parent.Configuration.Children.Add(config);
                element.Configuration = config;
            }
        }
        /// <summary>
        /// Processes the parameter element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessParameterElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_PARAMETERMAP)
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[ConfigConstants.ATTRIBUTE_PROPERTY]);
                config.CreateAttributes(element.Attributes);

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes a cache model element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessCacheModelElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = new MutableConfiguration(
                element.Name,
                ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]),
                element.Attributes[ConfigConstants.ATTRIBUTE_TYPE]);
            config.CreateAttributes(element.Attributes);
            config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);

            configurationStore.AddCacheConfiguration(config);
            element.Configuration = config;
        }
        /// <summary>
        /// Processes the flush on execute element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessFlushOnExecuteElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_CACHEMODEL)
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[ConfigConstants.ATTRIBUTE_STATEMENT]);
                config.CreateAttributes(element.Attributes);

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes the DataSource element in the SqlMap.config file. 
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessDataSourceElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_DATABASE)
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[DataConstants.ATTRIBUTE_NAME],
                    element.Attributes[DataConstants.ATTRIBUTE_CONNECTIONSTRING]);
                config.CreateAttributes(element.Attributes);

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes the setting element in the SqlMap.config file.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessSettingElement(Tag element, IConfigurationStore configurationStore)
        {
            // <setting hello="world" />

            string settingKey = element.GetAttributeName(0);
            string settingValue = element.GetAttributeValue(0);

            IConfiguration config = new MutableConfiguration(
                element.Name,
                settingKey,
                settingValue);
            configurationStore.AddSettingConfiguration(config);
        }
        /// <summary>
        /// Processes the discriminator element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessDiscriminatorElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_RESULTMAP)
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[ConfigConstants.ATTRIBUTE_COLUMN]);
                config.CreateAttributes(element.Attributes);
                element.Configuration = config;

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes the result map element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessResultMapElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]),
                    element.Attributes[ConfigConstants.ATTRIBUTE_CLASS]);
            config.CreateAttributes(element.Attributes);
            config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);

            AddAttribute(config, ConfigConstants.ATTRIBUTE_EXTENDS, true);

            configurationStore.AddResultMapConfiguration(config);
            element.Configuration = config;
        }
示例#21
0
        /// <summary>
        /// Processes the discriminator/case element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessCaseElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_DISCRIMINATOR)
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[ConfigConstants.ATTRIBUTE_VALUE]);
                config.CreateAttributes(element.Attributes);

                AddAttribute(config, ConfigConstants.ATTRIBUTE_RESULTMAP, true);

                element.Parent.Configuration.Children.Add(config);
            }
        }
示例#22
0
        /// <summary>
        /// Processes the text element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        protected override void ProcessTextElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null)
            {
                string text = element.Value.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim(); 

                MutableConfiguration config = new MutableConfiguration(
                                    element.Name,
                                    string.Empty,
                                    element.Value); // text);

                element.Parent.Configuration.Children.Add(config);
                element.Configuration = config;
            }
        }
        /// <summary>
        /// Processes the discriminator/default element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessDefaultElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_DISCRIMINATOR)
            {
                MutableConfiguration config = new MutableConfiguration(
                    ConfigConstants.ELEMENT_CASE,
                    Discriminator.DEFAULT_KEY);
                config.CreateAttributes(element.Attributes);
                config.CreateAttribute(ConfigConstants.ATTRIBUTE_VALUE, Discriminator.DEFAULT_KEY);

                AddAttribute(config, ConfigConstants.ATTRIBUTE_RESULTMAP, true);

                element.Parent.Configuration.Children.Add(config);
            }
        }
        /// <summary>
        /// Processes the statement element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessStatementElement(Tag element, IConfigurationStore configurationStore)
        {
            MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[ConfigConstants.ATTRIBUTE_ID]);
            config.CreateAttributes(element.Attributes);
            config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);

            AddAttribute(config, ConfigConstants.ATTRIBUTE_CACHEMODEL, true);
            AddAttribute(config, ConfigConstants.ELEMENT_PARAMETERMAP, true);
            AddAttribute(config, ConfigConstants.ELEMENT_RESULTMAP, true);
            AddAttribute(config, ConfigConstants.ELEMENT_PRESERVEWHITESPACE, false);

            configurationStore.AddStatementConfiguration(config);
            element.Configuration = config;
        }
        /// <summary>
        /// Processes the provider element in the providers.config file.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessProviderElement(Tag element, IConfigurationStore configurationStore)
        {
            // provider child tag of Database tag
            if (element.Parent != null && element.Parent.Name == "database")
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[DataConstants.ATTRIBUTE_NAME],
                    element.Attributes[DataConstants.ATTRIBUTE_NAME]);
                config.CreateAttributes(element.Attributes);
                element.Parent.Configuration.Children.Add(config);
            }
            else
            {
                MutableConfiguration config = new MutableConfiguration(
                    element.Name,
                    element.Attributes[DataConstants.ATTRIBUTE_NAME]);
                config.CreateAttributes(element.Attributes);

                configurationStore.AddProviderConfiguration(config);
            }
        }
        /// <summary>
        /// Processes the property element in the SqlMap.config file.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="configurationStore">The configuration store.</param>
        private void ProcessPropertyElement(Tag element, IConfigurationStore configurationStore)
        {
            if (element.Parent.Name != ConfigConstants.ELEMENT_CACHEMODEL)
            {
                if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_URI))
                {
                    string uri = element.Attributes[ConfigConstants.ATTRIBUTE_URI];

                    using (XmlTextReader reader = Resources.GetUriAsXmlReader(uri))
                    {
                        this.Process(reader, configurationStore);
                    }
                }
                else
                {
                    IConfiguration config = new MutableConfiguration(
                        element.Name,
                        element.Attributes[ConfigConstants.ATTRIBUTE_KEY],
                        element.Attributes[ConfigConstants.ATTRIBUTE_VALUE]);
                    configurationStore.AddPropertyConfiguration(config);
                }
            }
        }
 /// <summary>
 /// Processes the SQL map element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="configurationStore">The configuration store.</param>
 private void ProcessSqlMapElement(Tag element, IConfigurationStore configurationStore)
 {
     nameSpace = element.Attributes[ConfigConstants.ATTRIBUTE_NAMESPACE];
 }
示例#28
0
文件: Tag.cs 项目: reckcn/CSharp
        /// <summary>
        /// Initializes a new instance of the <see cref="Tag"/> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <param name="tagParent">The tag parent. I</param>
        /// <param name="configurationStore">The configuration store.</param>
        public Tag(XmlTextReader reader, Tag tagParent, IConfigurationStore configurationStore)
		{
            if (reader.Name.Length == 0)
            {
                // Case of txt node
                name = reader.NodeType.ToString();//当前节点的类型
                /*
                       * None:     None This is returned by the XmlReader if a Read method has not been called.  
                       * Element :   An element (for example, <item> ). 
                       * Attribute  :   An attribute (for example, id='123' ). 
                       * Text  :    The text content of a node.
                       * CDATA  :      A CDATA section (for example, <![CDATA[my escaped text]]> ). 
                       * EntityReference  :        A reference to an entity (for example, &num; ). 
                       * Entity         :       An entity declaration (for example, <!ENTITY...> ). 
                       * ProcessingInstruction :A processing instruction (for example, <?pi test?> ). 
                       * Comment :A comment (for example, <!-- my comment --> ). 
                      * Document:A document object that, as the root of the document tree, provides access to the entire XML document.
                      * DocumentType :The document type declaration, indicated by the following tag (for example, <!DOCTYPE...> ). 
                      *DocumentFragment  : A document fragment.
                     * Notation : A notation in the document type declaration (for example, <!NOTATION...> ). 
                     * Whitespace :  White space between markup.
                     * SignificantWhitespace : White space between markup in a mixed content model or white space within the xml:space="preserve" scope. 
                     * EndElement : An end element tag (for example, </item> ). 
                     * EndEntity : Returned when XmlReader gets to the end of the entity replacement as a result of a call to ResolveEntity. 
                 * XmlDeclaration : The XML declaration (for example, <?xml version='1.0'?> ). 
                    */
            }
            else
            {
                name = reader.Name;//当前节点的名字
            }
            parent = tagParent;//当前节点的父节点
            value = Tag.ParsePropertyTokens(reader.Value, configurationStore);//处理${}之间的属性值
            LoadAttributes(reader, configurationStore);
		}
示例#29
0
        /// <summary>
        /// Processes the specified reader.
        /// </summary>
        /// <param name="reader">The reader. 指向具体的一个配置XML文件</param>
        /// <param name="configurationStore">The configuration store.用于访问XML文件的工具类</param>
        public virtual void Process(XmlTextReader reader, IConfigurationStore configurationStore)
        {
            bool lastElementEmpty = false;

            while (reader.Read())
            {
                //判断是元素的开始或结束情况
                if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)
                {
                    if (!reader.IsStartElement())//判断是不是开始元素标签
                    {
                        //pop off because we reached a closing tag
                        elementStack.Pop();
                        continue;
                    }
                    else if (lastElementEmpty)//上一个元素是否为空
                    {
                        //pop off because this is not a sub-element of last
                        elementStack.Pop();
                    }
                    Tag parent = elementStack.Count == 0 ? null : elementStack.Peek();

                    Tag tag = new Tag(reader, parent, configurationStore);
                    elementStack.Push(tag);//压入栈中的永远是Element开始或结束类型

                    XmlTagHandler handler = null;
                    if (handlers.TryGetValue(tag.Name, out handler))
                    {
                        handler(tag, configurationStore);//configurationStore会被多次递归传递
                    }

                    lastElementEmpty = reader.IsEmptyElement;
                }
                    //判断是文本内容的情况
                else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.CDATA)
                {
                    Tag parent = elementStack.Count == 0 ? null : elementStack.Peek();

                    if (parent.Name == ConfigConstants.ELEMENT_INCLUDE)//"include"情况
                    {
                        parent = parent.Parent;
                    }
                    Tag tag = new Tag(reader, parent, configurationStore);

                    XmlTagHandler handler = null;
                    if (handlers.TryGetValue(ConfigConstants.ELEMENT_TEXT, out handler))
                    {
                        handler(tag, configurationStore);
                    }
                }
            }
        }
示例#30
0
 /// <summary>
 /// Processes the text element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="configurationStore">The configuration store.</param>
 protected virtual void ProcessTextElement(Tag element, IConfigurationStore configurationStore)
 {}
示例#31
0
 /// <summary>
 /// Processes the SQL map element.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="configurationStore">The configuration store.</param>
 private void ProcessSqlMapElement(Tag element, IConfigurationStore configurationStore)
 {
     nameSpace = element.Attributes[ConfigConstants.ATTRIBUTE_NAMESPACE];
 }