public void Registered()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            INamespaceParser namespaceParser = NamespaceParserRegistry.GetParser("http://www.springframework.net/wcf");

            Assert.IsNotNull(namespaceParser);
            Assert.IsTrue(namespaceParser is WcfNamespaceParser);
        }
        /// <summary>
        /// Parses an element in a custom namespace.
        /// </summary>
        /// <param name="ele"></param>
        /// <param name="containingDefinition">if a nested element, the containing object definition</param>
        /// <returns>the parsed object definition or null if not supported by the corresponding parser.</returns>
        public IObjectDefinition ParseCustomElement(XmlElement ele, IObjectDefinition containingDefinition)
        {
            String           namespaceUri = ele.NamespaceURI;
            INamespaceParser handler      = NamespaceParserRegistry.GetParser(namespaceUri);

            if (handler == null)
            {
                Error("Unable to locate Spring NamespaceHandler for XML schema namespace [" + namespaceUri + "]", ele);
                return(null);
            }
            return(handler.ParseElement(ele, new ParserContext(this, containingDefinition)));
        }
Ejemplo n.º 3
0
        /// <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>
        /// Returns a parser for the given namespace.
        /// </summary>
        /// <param name="namespaceURI">
        /// The namespace for which to lookup the parser implementation.
        /// </param>
        /// <returns>
        /// A parser for a given <paramref name="namespaceURI"/>, or
        /// <see langword="null"/> if no parser was found.
        /// </returns>
        public static INamespaceParser GetParser(string namespaceURI)
        {
            INamespaceParser parser = (INamespaceParser)parsers[namespaceURI];

            if (parser == null)
            {
                bool ok = RegisterWellknownNamespaceParserType(namespaceURI);
                if (ok)
                {
                    parser = (INamespaceParser)parsers[namespaceURI];
                }
            }
            return(parser);
        }
Ejemplo n.º 5
0
        /// <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="namespaceUri">
        /// The namespace with which to associate instance of the parser.
        /// </param>
        /// <param name="parser">
        /// The parser instance.
        /// </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.ArgumentNullException">
        /// If <paramref name="parser"/> is <see langword="null"/>, or if
        /// <paramref name="namespaceUri"/> is not specified and parser class
        /// does not have default value defined using <see cref="NamespaceParserAttribute"/>.
        /// </exception>
        public static void RegisterParser(INamespaceParser parser, string namespaceUri, string schemaLocation)
        {
            AssertUtils.ArgumentNotNull(parser, "parser");

            // determine and use defaults for the namespace and schema location, if necessary
            if (StringUtils.IsNullOrEmpty(namespaceUri) || StringUtils.IsNullOrEmpty(schemaLocation))
            {
                NamespaceParserAttribute defaults = GetDefaults(parser.GetType());
                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);
                    }
                }
            }

            // initialize the parser
            parser.Init();

            // register parser
            lock (parsers.SyncRoot)
                lock (schemas)
                {
                    parsers[namespaceUri] = parser;
                    if (StringUtils.HasText(schemaLocation) && !schemas.Contains(namespaceUri))
                    {
                        RegisterSchema(namespaceUri, schemaLocation);
                    }
                }
        }
        /// <summary>
        /// Returns a parser for the given namespace.
        /// </summary>
        /// <param name="namespaceURI">
        /// The namespace for which to lookup the parser implementation.
        /// </param>
        /// <returns>
        /// A parser for a given <paramref name="namespaceURI"/>, or
        /// <see langword="null"/> if no parser was found.
        /// </returns>
        public static INamespaceParser GetParser(string namespaceURI)
        {
            INamespaceParser parser = (INamespaceParser)parsers[namespaceURI];

            if (parser == null)
            {
                bool ok = RegisterWellknownNamespaceParserType(namespaceURI);
                if (ok)
                {
                    parser = (INamespaceParser)parsers[namespaceURI];

                    //work-around for SPRNET-1277 where we're inconsistent re: exposing /db or /database as the final namespace element
                    if (parser == null && namespaceURI == "http://www.springframework.net/db")
                    {
                        parser = (INamespaceParser)parsers["http://www.springframework.net/database"];
                    }
                }
            }
            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="namespaceUri">
        /// The namespace with which to associate instance of the parser.
        /// </param>
        /// <param name="parser">
        /// The parser instance.
        /// </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.ArgumentNullException">
        /// If <paramref name="parser"/> is <see langword="null"/>, or if 
        /// <paramref name="namespaceUri"/> is not specified and parser class
        /// does not have default value defined using <see cref="NamespaceParserAttribute"/>.
        /// </exception>
        public static void RegisterParser(INamespaceParser parser, string namespaceUri, string schemaLocation)
        {
            AssertUtils.ArgumentNotNull(parser, "parser");

            // determine and use defaults for the namespace and schema location, if necessary
            if (StringUtils.IsNullOrEmpty(namespaceUri) || StringUtils.IsNullOrEmpty(schemaLocation))
            {
                NamespaceParserAttribute defaults = GetDefaults(parser.GetType());
                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);
                    }
                }
            }

            // initialize the parser
            parser.Init();

            // register parser
            lock (parsers.SyncRoot)
                lock (schemas)
                {
                    parsers[namespaceUri] = parser;
                    if (StringUtils.HasText(schemaLocation) && !schemas.Contains(namespaceUri))
                    {
                        RegisterSchema(namespaceUri, schemaLocation);
                    }
                }
        }
 /// <summary>
 /// Pegisters parser, using default namespace and schema location
 /// as defined by the <see cref="NamespaceParserAttribute"/>.
 /// </summary>
 /// <param name="parser">
 /// The parser instance.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// If <paramref name="parser"/> is <see langword="null"/>.
 /// </exception>
 public static void RegisterParser(INamespaceParser parser)
 {
     RegisterParser(parser, null, null);
 }
 /// <summary>
 /// Pegisters parser, using default namespace and schema location
 /// as defined by the <see cref="NamespaceParserAttribute"/>.
 /// </summary>
 /// <param name="parser">
 /// The parser instance.
 /// </param>
 /// <exception cref="System.ArgumentNullException">
 /// If <paramref name="parser"/> is <see langword="null"/>.
 /// </exception>
 public static void RegisterParser(INamespaceParser parser)
 {
     RegisterParser(parser, null, null);
 }
Ejemplo n.º 10
0
 public IntNamespaceHandlerDelegate(INamespaceParser outer)
 {
     this.outer = outer;
 }
Ejemplo n.º 11
0
        public void Registered()
        {
            INamespaceParser parser = NamespaceParserRegistry.GetParser("http://www.springframework.net/mongo");

            Assert.That(parser, Is.Not.Null);
        }
 public IntNamespaceHandlerDelegate(INamespaceParser outer)
 {
     this.outer = outer;
 }
Ejemplo n.º 13
0
		public CsParser(string pOutDir, INamespaceParser pParser) {
			_parser = pParser;
			_output = pOutDir.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar;
		}
Ejemplo n.º 14
0
		public static void AddParser(INamespaceParser pCsAstVisitor, string pName) {
			_parsers[pName.ToLowerInvariant()] = pCsAstVisitor;
		}