Пример #1
0
        /// <summary>
        /// Validation callback for a validating XML reader.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">Any data pertinent to the event.</param>
        private void HandleValidation(object sender, ValidationEventArgs args)
        {
            if (args.Severity == XmlSeverityType.Error)
            {
                XmlSchemaException ex        = args.Exception;
                XmlReader          xmlReader = (XmlReader)sender;
                if (!NamespaceParserRegistry.GetSchemas().Contains(xmlReader.NamespaceURI) && ex is XmlSchemaValidationException)
                {
                    // try wellknown parsers
                    bool registered = NamespaceParserRegistry.RegisterWellknownNamespaceParserType(xmlReader.NamespaceURI);
                    if (registered)
                    {
                        throw new RetryParseException();
                    }
                }
                throw ex;
            }
            else
            {
                #region Instrumentation

                if (log.IsWarnEnabled)
                {
                    log.Warn(
                        "Ignored XML validation warning: " + args.Message,
                        args.Exception);
                }

                #endregion
            }
        }
Пример #2
0
        public void ParsesNonDefaultNamespace()
        {
            try
            {
                NamespaceParserRegistry.Reset();

                DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
                XmlObjectDefinitionReader    reader = new XmlObjectDefinitionReader(of);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
<core:objects xmlns:core='http://www.springframework.net'>  
	<core:object id='test2' type='Oragon.Spring.Objects.TestObject, Oragon.Spring.Core.Tests'>
        <core:property name='Sibling'>
            <core:object type='Oragon.Spring.Objects.TestObject, Oragon.Spring.Core.Tests' />
        </core:property>
    </core:object>
</core:objects>
"));
                TestObject test2 = (TestObject)of.GetObject("test2");
                Assert.AreEqual(typeof(TestObject), test2.GetType());
                Assert.IsNotNull(test2.Sibling);
            }
            finally
            {
                NamespaceParserRegistry.Reset();
            }
        }
Пример #3
0
        public void AutoRegistersWellknownNamespaceParser()
        {
            try
            {
                Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (Assembly assembly in loadedAssemblies)
                {
                    if (assembly.GetName(true).Name.StartsWith("Oragon.Spring.Data"))
                    {
                        Assert.Fail("Oragon.Spring.Data is already loaded - this test checks if it gets loaded during xml parsing");
                    }
                }

                NamespaceParserRegistry.Reset();

                DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
                XmlObjectDefinitionReader    reader = new XmlObjectDefinitionReader(of);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
                                                    <objects xmlns='http://www.springframework.net' 
                                                             xmlns:tx='http://www.springframework.net/tx'>  
                                                          <tx:attribute-driven />
                                                    </objects>
                                                    "));
                object apc = of.GetObject(AopNamespaceUtils.AUTO_PROXY_CREATOR_OBJECT_NAME);
                Assert.NotNull(apc);
            }
            finally
            {
                NamespaceParserRegistry.Reset();
            }
        }
Пример #4
0
        public void AutoRegistersAllWellknownNamespaceParsers_3_0()
        {
            string[] namespaces = { "http://www.springframework.net/wcf" };

            foreach (string ns in namespaces)
            {
                Assert.IsNotNull(NamespaceParserRegistry.GetParser(ns),
                                 string.Format("Parser for Namespace {0} could not be auto-registered.", ns));
            }
        }
Пример #5
0
        /// <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)));
        }
        public void CanLoadSchemaImportingOtherSchemaByRelativePath()
        {
            string schemaLocation = TestResourceLoader.GetAssemblyResourceUri(this.GetType(), "NamespaceParserRegistryTests_TestSchema.xsd");

            NamespaceParserRegistry.RegisterParser(new TestNamespaceParser(), "http://www.example.com/brief", schemaLocation);
            XmlReader vr = XmlUtils.CreateValidatingReader(new StringResource(
                                                               @"<?xml version='1.0' encoding='UTF-8' ?>
                            <brief class='foo' />
                            ").InputStream, NamespaceParserRegistry.GetSchemas(), null);
            ConfigXmlDocument newDoc = new ConfigXmlDocument();

            newDoc.Load(vr);
        }
Пример #7
0
        public void ThrowsOnUnknownNamespaceUri()
        {
            NamespaceParserRegistry.Reset();

            DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader    reader = new XmlObjectDefinitionReader(of);

            Assert.Throws <ObjectDefinitionStoreException>(() => reader.LoadObjectDefinitions(new StringResource(
                                                                                                  @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' 
     xmlns:x='http://www.springframework.net/XXXX'>  
  <x:group id='tripValidator' />
</objects>
")));
        }
Пример #8
0
        public void AutoRegistersAllWellknownNamespaceParsers_Common()
        {
            string[] namespaces =
            {
                "http://www.springframework.net/tx",
                "http://www.springframework.net/aop",
                "http://www.springframework.net/db",
                "http://www.springframework.net/database",
                "http://www.springframework.net/remoting",
                "http://www.springframework.net/nms",
                "http://www.springframework.net/validation",
                "http://www.springframework.net/nvelocity"
            };

            foreach (string ns in namespaces)
            {
                Assert.IsNotNull(NamespaceParserRegistry.GetParser(ns),
                                 string.Format("Parser for Namespace {0} could not be auto-registered.", ns));
            }
        }
Пример #9
0
        private XmlReader CreateValidatingReader(MemoryStream stream)
        {
            XmlReader reader;

            if (SystemUtils.MonoRuntime)
            {
                reader = XmlUtils.CreateReader(stream);
            }
            else
            {
                reader = XmlUtils.CreateValidatingReader(stream, Resolver, NamespaceParserRegistry.GetSchemas(), HandleValidation);
            }

            #region Instrumentation

            if (log.IsDebugEnabled)
            {
                log.Debug("Using the following XmlReader implementation : " + reader.GetType());
            }
            return(reader);

            #endregion
        }
Пример #10
0
 public void RegisterParserWithEmptyNamespaceWithoutDefaultValues()
 {
     Assert.Throws <ArgumentNullException>(() => NamespaceParserRegistry.RegisterParser(typeof(NotImplementedXmlObjectDefinitionParser), string.Empty, null));
 }
Пример #11
0
 public void RegisterParserWithBadParserType()
 {
     Assert.Throws <ArgumentException>(() => NamespaceParserRegistry.RegisterParser(GetType()));
 }
Пример #12
0
 public void RegisterParserWithNullType()
 {
     Assert.Throws <ArgumentNullException>(() => NamespaceParserRegistry.RegisterParser((Type)null));
 }
 public void TearDown()
 {
     NamespaceParserRegistry.Reset();
 }
 public void SetUp()
 {
     NamespaceParserRegistry.Reset();
 }