private IObjectDefinitionParser FindParserForElement(XmlElement element, ParserContext parserContext)
        {
            IObjectDefinitionParser parser = objectParsers[element.LocalName] as IObjectDefinitionParser;

            if (parser == null)
            {
                parserContext.ReaderContext.ReportException(element, "unknown object name", "Cannot locate IObjectDefinitionParser for element ["
                                                            + element.LocalName + "]");
            }
            return(parser);
        }
        /// <summary>
        /// Associates a parser with a namespace.
        /// </summary>
        /// <remarks>
        /// <note>
        /// Parsers registered with the same <paramref name="namespaceUri"/> as that
        /// of a parser that has previously been registered will overwrite the existing
        /// parser.
        /// </note>
        /// </remarks>
        /// <param name="parserType">
        /// The <see cref="System.Type"/> of the parser that will be activated
        /// when the attendant <paramref name="namespaceUri"/> is
        /// encountered.
        /// </param>
        /// <param name="namespaceUri">
        /// The namespace with which to associate instance of the parser.
        /// </param>
        /// <param name="schemaLocation">
        /// The location of the XML schema that should be used for validation
        /// of the XML elements that belong to the specified namespace
        /// (can be any valid Spring.NET resource URI).
        /// </param>
        /// <exception cref="System.ArgumentException">
        /// If the <paramref name="parserType"/> is not a <see cref="System.Type"/>
        /// that implements the <see cref="INamespaceParser"/>
        /// interface.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="parserType"/> is <see langword="null"/>.
        /// </exception>
        public static void RegisterParser(Type parserType, string namespaceUri, string schemaLocation)
        {
            AssertUtils.ArgumentNotNull(parserType, "parserType");

            INamespaceParser np = null;

            if ((typeof(INamespaceParser)).IsAssignableFrom(parserType))
            {
                np = (INamespaceParser)ObjectUtils.InstantiateType(parserType);
            }
            // TODO (EE): workaround to enable smooth transition between 1.x and 2.0 style namespace handling
            else if (typeof(IObjectDefinitionParser).IsAssignableFrom(parserType))
            {
                // determine and use defaults for the namespace and schema location, if necessary
                if (StringUtils.IsNullOrEmpty(namespaceUri) || StringUtils.IsNullOrEmpty(schemaLocation))
                {
                    NamespaceParserAttribute defaults = GetDefaults(parserType);
                    if (defaults == null)
                    {
                        throw new ArgumentNullException(
                                  "Either default or an explicit namespace value must be specified for a configuration parser.");
                    }

                    if (StringUtils.IsNullOrEmpty(namespaceUri))
                    {
                        namespaceUri = defaults.Namespace;
                    }

                    if (StringUtils.IsNullOrEmpty(schemaLocation))
                    {
                        schemaLocation = defaults.SchemaLocation;
                        if (defaults.SchemaLocationAssemblyHint != null)
                        {
                            schemaLocation =
                                GetAssemblySchemaLocation(defaults.SchemaLocationAssemblyHint, schemaLocation);
                        }
                    }
                }

                IObjectDefinitionParser odParser = (IObjectDefinitionParser)ObjectUtils.InstantiateType(parserType);
                np = new ObjectDefinitionParserNamespaceParser(odParser);
            }
            else
            {
                throw new ArgumentException(
                          string.Format("The [{0}] Type must implement the INamespaceParser interface.", parserType.Name)
                          , "parserType");
            }

            RegisterParser(np, namespaceUri, schemaLocation);
        }
 /// <summary>
 /// Register the specified <see cref="IObjectDefinitionParser"/> for the given <paramref name="elementName"/>
 /// </summary>
 protected virtual void RegisterObjectDefinitionParser(string elementName, IObjectDefinitionParser parser)
 {
     AssertUtils.ArgumentNotNull(elementName, "elementName");
     AssertUtils.ArgumentNotNull(parser, "parser");
     objectParsers[elementName] = parser;
 }
 public ObjectDefinitionParserNamespaceParser(IObjectDefinitionParser odParser)
 {
     this.odParser = odParser;
 }
 public ObjectDefinitionParserNamespaceParser(IObjectDefinitionParser odParser)
 {
     this.odParser = odParser;
 }
Пример #6
0
 /// <summary>
 /// Register the specified <see cref="IObjectDefinitionParser"/> for the given <paramref name="elementName"/>
 /// </summary>
 protected virtual void RegisterObjectDefinitionParser(string elementName, IObjectDefinitionParser parser)
 {
     AssertUtils.ArgumentNotNull(elementName, "elementName");
     AssertUtils.ArgumentNotNull(parser, "parser");
     objectParsers[elementName] = parser;
 }
Пример #7
0
 protected void RegisterObjectDefinitionParser(string elementName, IObjectDefinitionParser parser)
 {
     namespaceHandlerDelegate.DoRegisterObjectDefinitionParser(elementName, parser);
 }
Пример #8
0
 public void DoRegisterObjectDefinitionParser(string elementName, IObjectDefinitionParser parser)
 {
     base.RegisterObjectDefinitionParser(elementName, parser);
 }
 protected void RegisterObjectDefinitionParser(string elementName, IObjectDefinitionParser parser)
 {
     namespaceHandlerDelegate.DoRegisterObjectDefinitionParser(elementName, parser);
 }
 public void DoRegisterObjectDefinitionParser(string elementName, IObjectDefinitionParser parser)
 {
     base.RegisterObjectDefinitionParser(elementName, parser);
 }