public void ThrowsTypeLoadExceptionIfProxyInterfacesValueIsSpecifiedInsteadOfListElement()
        {
            using (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:r='http://www.springframework.net/remoting'>  
    
    <r:saoExporter id='ISimpleCounterExporter' targetName='ISimpleCounterProxy' serviceName='RemotedSaoCounterProxy' />
    
    <object id='ISimpleCounter' type='Spring.Remoting.SimpleCounter, Spring.Services.Tests' />

    <object id='ISimpleCounterProxy' type='Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop'>
        <property name='proxyInterfaces' value='Spring.Remoting.ISimpleCounter, Spring.Services.Tests' />
        <property name='target' ref='ISimpleCounter'/>
    </object>
</objects>
"));
                try
                {
                    SaoExporter saoExporter = (SaoExporter)of.GetObject("ISimpleCounterExporter");
                    Assert.Fail();
                }
                catch (ObjectCreationException oce)
                {
                    TypeLoadException tle = (TypeLoadException)oce.GetBaseException();
                    Assert.AreEqual("Could not load type from string value ' Spring.Services.Tests'.", tle.Message);
                }
            }
        }
        private void ConfigureObjectFactory(IObjectDefinitionRegistry factory)
        {
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);

            reader.LoadObjectDefinitions(new StringResource(@"<?xml version='1.0' encoding='UTF-8' ?>
                <objects xmlns='http://www.springframework.net'
                          xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
                          xsi:schemaLocation='http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd'>

                      <object id='Parent' type='Oragon.Spring.Objects.Factory.SPRNET_1334+ParentClass, Oragon.Spring.Core.Tests'>
                        <property name='Name' value='Foo!'/>
			                <property name='InnerObject'>
				                <object type='Oragon.Spring.Objects.Factory.SPRNET_1334+DisposableClass, Oragon.Spring.Core.Tests'/>
			                </property>
                      </object>
<!--
                      <object id='Parent' type='Oragon.Spring.Objects.Factory.SPRNET_1334+ParentClass, Oragon.Spring.Core.Tests'>
                        <property name='Name' value='Foo!'/>
			                <property name='InnerObject' ref='Inner'/>
                      </object>

                      <object id='Inner' type='Oragon.Spring.Objects.Factory.SPRNET_1334+DisposableClass, Oragon.Spring.Core.Tests'/>
-->			          
                      
                </objects>
            "));
        }
Beispiel #3
0
 /// <summary>
 /// Load the object definitions with the given
 /// <see cref="Spring.Objects.Factory.Xml.XmlObjectDefinitionReader"/>.
 /// </summary>
 /// <remarks>
 /// <p>
 /// The lifecycle of the object factory is handled by
 /// <see cref="Spring.Context.Support.AbstractXmlApplicationContext.RefreshObjectFactory"/>;
 /// therefore this method is just supposed to load and / or register
 /// object definitions.
 /// </p>
 /// </remarks>
 /// <param name="objectDefinitionReader">
 /// The reader containing object definitions.</param>
 /// <exception cref="ObjectsException">
 /// In case of object registration errors.
 /// </exception>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In the case of errors encountered reading any of the resources
 /// yielded by the <see cref="ConfigurationLocations"/> method.
 /// </exception>
 protected virtual void LoadObjectDefinitions(
     XmlObjectDefinitionReader objectDefinitionReader)
 {
     string[] locations = ConfigurationLocations;
     if (locations != null)
     {
         objectDefinitionReader.LoadObjectDefinitions(ConfigurationLocations);
     }
 }
        public void SimpleReader()
        {
            GenericApplicationContext applicationContext = new GenericApplicationContext();


            IObjectDefinitionReader objectDefinitionReader = new XmlObjectDefinitionReader(applicationContext);

            objectDefinitionReader.LoadObjectDefinitions("assembly://foo");

            applicationContext.Refresh();
        }
Beispiel #5
0
        /// <summary>
        /// Loads the object definitions into the given object factory, typically through
        /// delegating to one or more object definition readers.
        /// </summary>
        /// <param name="objectFactory">The object factory to lead object definitions into</param>
        /// <see cref="XmlObjectDefinitionReader"/>
        /// <see cref="PropertiesObjectDefinitionReader"/>
        protected virtual void LoadObjectDefinitions(DefaultListableObjectFactory objectFactory)
        {
            //Create a new XmlObjectDefinitionReader for the given ObjectFactory
            XmlObjectDefinitionReader objectDefinitionReader = CreateXmlObjectDefinitionReader(objectFactory);

            // Configure the bean definition reader with this context's
            // resource loading environment.
            objectDefinitionReader.ResourceLoader = this;

            // Allow a subclass to provide custom initialization of the reader,
            // then proceed with actually loading the object definitions.
            InitObjectDefinitionReader(objectDefinitionReader);
            LoadObjectDefinitions(objectDefinitionReader);
        }
Beispiel #6
0
        public void GenericApplicationContextWithXmlObjectDefinitions()
        {
            GenericApplicationContext ctx    = new GenericApplicationContext();
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(ctx);

            reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextB.xml");
            reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextC.xml");
            reader.LoadObjectDefinitions("assembly://Spring.Core.Tests/Spring.Context.Support/contextA.xml");
            ctx.Refresh();

            Assert.IsTrue(ctx.ContainsObject("service"));
            Assert.IsTrue(ctx.ContainsObject("logicOne"));
            Assert.IsTrue(ctx.ContainsObject("logicTwo"));
            ctx.Dispose();
        }
        /// <summary>
        /// Load the object definitions with the given
        /// <see cref="Oragon.Spring.Objects.Factory.Xml.XmlObjectDefinitionReader"/>.
        /// </summary>
        /// <remarks>
        /// <p>
        /// The lifecycle of the object factory is handled by
        /// <see cref="Oragon.Spring.Context.Support.AbstractXmlApplicationContext.RefreshObjectFactory"/>;
        /// therefore this method is just supposed to load and / or register
        /// object definitions.
        /// </p>
        /// </remarks>
        /// <param name="objectDefinitionReader">
        /// The reader containing object definitions.</param>
        /// <exception cref="ObjectsException">
        /// In case of object registration errors.
        /// </exception>
        /// <exception cref="Oragon.Spring.Objects.ObjectsException">
        /// In the case of errors encountered reading any of the resources
        /// yielded by either the <see cref="ConfigurationLocations"/> or
        /// the <see cref="ConfigurationResources"/> methods.
        /// </exception>
        protected virtual void LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader)
        {
            IEnumerable <string> locations = ConfigurationLocations;

            if (locations != null)
            {
                objectDefinitionReader.LoadObjectDefinitions(locations.ToArray());
            }

            IResource[] resources = ConfigurationResources;
            if (resources != null)
            {
                objectDefinitionReader.LoadObjectDefinitions(resources);
            }
        }
Beispiel #8
0
        private static AbstractApplicationContext GetAbstractApplicationContext()
        {
            if (!ContextRegistry.IsContextRegistered(_RootContext))
            {
                lock (lock_init)
                {
                    if (!ContextRegistry.IsContextRegistered(_RootContext))
                    {
                        GenericApplicationContext ctx = new GenericApplicationContext();
                        ctx.Name = _RootContext;
                        XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(ctx);
                        reader.LoadObjectDefinitions(new StringResource("<?xml version=\"1.0\" encoding=\"utf-8\" ?><objects></objects>"));
                        ContextRegistry.RegisterContext(ctx);
                    }
                }
            }

            return(ContextRegistry.GetContext(_RootContext) as AbstractApplicationContext);
        }
Beispiel #9
0
        private static IApplicationContext CreateContextMixXmlAndProgrammatic()
        {
            GenericApplicationContext ctx = new GenericApplicationContext();

            IObjectDefinitionReader objectDefinitionReader = new XmlObjectDefinitionReader(ctx);

            objectDefinitionReader.LoadObjectDefinitions("assembly://Spring.IocQuickStart.MovieFinder/Spring.IocQuickStart.MovieFinder/AppContextContribution.xml");

            IObjectDefinitionFactory objectDefinitionFactory = new DefaultObjectDefinitionFactory();
            ObjectDefinitionBuilder  builder =
                ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(ColonDelimitedMovieFinder));

            builder.AddConstructorArg("movies.txt");
            ctx.RegisterObjectDefinition("AnotherMovieFinder", builder.ObjectDefinition);


            ctx.Refresh();

            return(ctx);
        }
        public void ThrowsCannotLoadObjectTypeExceptionOnInvalidTypename()
        {
            try
            {
                MockApplicationContext       myContext     = new MockApplicationContext("myContext");
                DefaultListableObjectFactory objectFactory = (DefaultListableObjectFactory)myContext.ObjectFactory;
                XmlObjectDefinitionReader    reader        = new XmlObjectDefinitionReader(objectFactory);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>  
	<object id='test2' type='DOESNOTEXIST' />
</objects>
"));
                myContext.Refresh();
            }
            catch (Exception e)
            {
//            Console.WriteLine(e);
                Assert.IsInstanceOf(typeof(CannotLoadObjectTypeException), e);
            }
        }
Beispiel #11
0
 /// <summary>
 /// Initialize the object definition reader used for loading the object
 /// definitions of this context.
 /// </summary>
 /// <remarks>
 /// <p>
 /// The default implementation of this method is a no-op; i.e. it does
 /// nothing. Can be overridden in subclasses to provide custom
 /// initialization of the supplied
 /// <paramref name="objectDefinitionReader"/>; for example, a derived
 /// class may want to turn off XML validation.
 /// </p>
 /// </remarks>
 /// <param name="objectDefinitionReader">
 /// The object definition reader used by this context.
 /// </param>
 protected virtual void InitObjectDefinitionReader(
     XmlObjectDefinitionReader objectDefinitionReader)
 {
 }
Beispiel #12
0
 protected override void  LoadObjectDefinitions(XmlObjectDefinitionReader objectDefinitionReader)
 {
     base.LoadObjectDefinitions(objectDefinitionReader);
     objectDefinitionReader.LoadObjectDefinitions(configurationResources);
 }
Beispiel #13
0
 /// <summary>
 /// Initializes object definition reader.
 /// </summary>
 /// <param name="objectDefinitionReader">Reader to initialize.</param>
 protected override void InitObjectDefinitionReader(XmlObjectDefinitionReader objectDefinitionReader)
 {
     //            NamespaceParserRegistry.RegisterParser(typeof(WebObjectsNamespaceParser));
 }