public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
 {
     if (_configurationHandler != null)
     {
         _configurationHandler(factory);
     }
 }
 public void SetUp()
 {
     IObjectFactory grandparent = new XmlObjectFactory(new ReadOnlyXmlTestResource("root.xml", GetType()));
     IObjectFactory parent = new XmlObjectFactory(new ReadOnlyXmlTestResource("middle.xml", GetType()), grandparent);
     IConfigurableListableObjectFactory child = new XmlObjectFactory(new ReadOnlyXmlTestResource("leaf.xml", GetType()), parent);
     _factory = child;
 }
        public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
        {
            IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames();

            if (Logger.IsInfoEnabled)
                Logger.Info("Iniciando proceso para establecer el alcance de los services y controllers");

            foreach (string objectDefinitionName in objectDefinitionNames)
            {
                IObjectDefinition objectDefinition = factory.GetObjectDefinition(objectDefinitionName);
                if (objectDefinition is ScannedGenericObjectDefinition)
                {
                    var componentAttribute =
                        Attribute.GetCustomAttribute(objectDefinition.ObjectType, typeof (ComponentAttribute), true) as
                            ComponentAttribute;

                    if ( (componentAttribute is ControllerAttribute) || (WcfServices && componentAttribute is ServiceAttribute) )
                    {
                        if (Logger.IsInfoEnabled)
                            Logger.InfoFormat("Estableciendo alcance para la definición {0}", objectDefinitionName);
                        objectDefinition.Scope = "prototype";
                    }
                }
            }
        }
 private static bool IsLazyInit(IConfigurableListableObjectFactory configurableObjectFactory, string name)
 {
     if (configurableObjectFactory == null)
      {
     return false;
      }
      return configurableObjectFactory.GetObjectDefinition(name).IsLazyInit;
 }
Beispiel #5
0
 /// <summary>
 /// Registers any type aliases.  The supplied
 /// <paramref name="factory"/> is not used since type aliases
 /// are registered with a global <see cref="TypeRegistry"/>
 /// </summary>
 /// <param name="factory">
 /// The object factory.
 /// </param>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In case of errors.
 /// </exception>
 public override void PostProcessObjectFactory(
     IConfigurableListableObjectFactory factory)
 {
     if (types != null)
     {
         foreach (DictionaryEntry entry in types)
         {
             string alias = entry.Key.ToString();
             Type   type  = ResolveRequiredType(entry.Value, "value", "custom type alias");
             TypeRegistry.RegisterType(alias, type);
         }
     }
 }
Beispiel #6
0
        public void MalformedOverrideKey()
        {
            IConfigurableListableObjectFactory objectFactory = A.Fake <IConfigurableListableObjectFactory>();
            IConfigurableListableObjectFactory fac           = objectFactory;

            PropertyOverrideConfigurer cfg = new PropertyOverrideConfigurer();
            NameValueCollection        defaultProperties = new NameValueCollection();

            defaultProperties.Add("malformedKey", "Rick Evans");
            cfg.Properties = defaultProperties;

            Assert.Throws <FatalObjectException>(() => cfg.PostProcessObjectFactory(fac));
        }
Beispiel #7
0
 /// <summary>
 /// Registers custom IResource implementations.  The supplied
 /// <paramref name="factory"/> is not used since IResourse implementations
 /// are registered with a global <see cref="Spring.Core.IO.ResourceHandlerRegistry"/>
 /// </summary>
 /// <param name="factory">
 /// The object factory.
 /// </param>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In case of errors.
 /// </exception>
 public override void PostProcessObjectFactory(
     IConfigurableListableObjectFactory factory)
 {
     if (resourceHandlers != null)
     {
         foreach (DictionaryEntry entry in resourceHandlers)
         {
             string protocolName = entry.Key.ToString();
             Type   type         = ResolveRequiredType(entry.Value, "value", "custom IResource implementation");
             ResourceHandlerRegistry.RegisterResourceHandler(protocolName, type);
         }
     }
 }
Beispiel #8
0
        protected override void InitializeServiceLocator()
        {
            IConfigurableApplicationContext context = new StaticApplicationContext();

            objectFactory = context.ObjectFactory;
            var sl = new SpringServiceLocatorAdapter(objectFactory);

            objectFactory.RegisterInstance <IServiceLocator>(sl);
            ServiceLocator.SetLocatorProvider(() => sl);

            objectFactory.Register <IInvoiceTotalCalculator, SumAndTaxTotalCalculator>();
            objectFactory.RegisterPrototype <IInvoice, Invoice>();
        }
Beispiel #9
0
 /// <summary>
 /// Registers any custom converters with the supplied
 /// <paramref name="factory"/>.
 /// </summary>
 /// <param name="factory">
 /// The object factory to register the converters with.
 /// </param>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In case of errors.
 /// </exception>
 public override void PostProcessObjectFactory(
     IConfigurableListableObjectFactory factory)
 {
     if (_customConverters != null)
     {
         foreach (DictionaryEntry entry in _customConverters)
         {
             Type          requiredType = ResolveRequiredType(entry.Key, "key", "custom type converter");
             TypeConverter converter    = ResolveConverter(entry.Value);
             factory.RegisterCustomConverter(requiredType, converter);
         }
     }
 }
        public void DoesNotChokeOnBadResourceLocationIfIgnoreBadResourcesFlagSetToTrue()
        {
            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();

            cfg.IgnoreResourceNotFound = true;
            IResource mockResource = A.Fake <IResource>();

            A.CallTo(() => mockResource.Exists).Returns(false);
            cfg.Location       = mockResource;
            cfg.ConfigSections = new string[] { "" };
            IConfigurableListableObjectFactory mockFactory = A.Fake <IConfigurableListableObjectFactory>();

            A.CallTo(() => mockFactory.GetObjectDefinitionNames(false)).Returns(new string[] {});

            cfg.PostProcessObjectFactory(mockFactory);
        }
Beispiel #11
0
        public void PostProcessObjectFactory(IConfigurableListableObjectFactory objectFactory)
        {
            IObjectDefinitionRegistry registry = objectFactory as IObjectDefinitionRegistry;

            if (registry != null)
            {
                RegisterNullChannel(registry);
                RegisterErrorChannelIfNecessary(registry);
                RegisterTaskSchedulerIfNecessary(registry);
            }
            else if (logger.IsWarnEnabled)
            {
                logger.Warn("ObjectFactory is not a ObjectDefinitionRegistry. The default '"
                            + IntegrationContextUtils.ErrorChannelObjectName + "' and '"
                            + IntegrationContextUtils.TaskSchedulerObjectName + "' cannot be configured.");
            }
        }
        /// <summary>
        /// Postprocesses the object factory.
        /// </summary>
        /// <param name="objectFactory">The object factory.</param>
        public void PostProcessObjectFactory(IConfigurableListableObjectFactory objectFactory)
        {
            if (_postProcessObjectFactoryCalled)
            {
                throw new InvalidOperationException(
                          "PostProcessObjectFactory already called for this post-processor");
            }
            _postProcessObjectFactoryCalled = true;
            if (!_postProcessObjectDefinitionRegistryCalled)
            {
                // ObjectDefinitionRegistryPostProcessor hook apparently not supported...
                // Simply call processConfigObjectDefinitions lazily at this point then.
                ProcessConfigObjectDefinitions((IObjectDefinitionRegistry)objectFactory);
            }

            EnhanceConfigurationClasses(objectFactory);
        }
Beispiel #13
0
 /// <summary>
 /// Inject dependencies into 'this' instance (that is, this test instance).
 /// </summary>
 /// <remarks>
 /// <p>The default implementation populates protected variables if the
 /// <see cref="PopulateProtectedVariables"/> property is set, else
 /// uses autowiring if autowiring is switched on (which it is by default).</p>
 /// <p>You can certainly override this method if you want to totally control
 /// how dependencies are injected into 'this' instance.</p>
 /// </remarks>
 protected virtual void InjectDependencies()
 {
     if (PopulateProtectedVariables)
     {
         if (managedVariableNames == null)
         {
             InitManagedVariableNames();
         }
         InjectProtectedVariables();
     }
     else if (AutowireMode != AutoWiringMode.No)
     {
         IConfigurableListableObjectFactory factory = applicationContext.ObjectFactory;
         ((AbstractObjectFactory)factory).IgnoreDependencyType(typeof(AutoWiringMode));
         factory.AutowireObjectProperties(this, AutowireMode, DependencyCheck);
     }
 }
        public void ObjectNamesIncludingAncestorsPreserveOrderOfRegistration()
        {
            MockRepository mocks = new MockRepository();
            IConfigurableListableObjectFactory of       = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));
            IConfigurableListableObjectFactory ofParent = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));

            Expect.Call(of.GetObjectNamesForType(typeof(object))).Return(new string[] { "objA", "objB", "objC" });
            Expect.Call(((IHierarchicalObjectFactory)of).ParentObjectFactory).Return(ofParent);
            Expect.Call(ofParent.GetObjectNamesForType(typeof(object))).Return(new string[] { "obj2A", "objB", "obj2C" });

            mocks.ReplayAll();

            string[] names = ObjectFactoryUtils.ObjectNamesIncludingAncestors(of);
            Assert.AreEqual(5, names.Length);
            Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);

            mocks.VerifyAll();
        }
Beispiel #15
0
        public void MissingObjectDefinitionDoesntRaiseFatalException()
        {
            const string valueTo_NOT_BeOveridden = "Jenny Lewis";
            TestObject   foo = new TestObject(valueTo_NOT_BeOveridden, 30);
            IConfigurableListableObjectFactory objectFactory = A.Fake <IConfigurableListableObjectFactory>();

            A.CallTo(() => objectFactory.GetObjectDefinition("rubbish")).Returns(null);
            IConfigurableListableObjectFactory fac = objectFactory;

            PropertyOverrideConfigurer cfg = new PropertyOverrideConfigurer();
            NameValueCollection        defaultProperties = new NameValueCollection();

            defaultProperties.Add("rubbish.Name", "Rick Evans");
            cfg.Properties = defaultProperties;

            cfg.PostProcessObjectFactory(fac);
            Assert.AreEqual(valueTo_NOT_BeOveridden, foo.Name, "Property value was overridden, but a rubbish objectName root was supplied.");
        }
        private void AutodetectBeans(Func <Type, string, bool> shouldExportCallback)
        {
            IConfigurableListableObjectFactory configurableObjectFactory = _objectFactory as IConfigurableListableObjectFactory;

            foreach (string name in _objectFactory.GetObjectNamesForType(typeof(object), false, false))
            {
                Type beanType = _objectFactory.GetType(name);
                if (shouldExportCallback(beanType, name))
                {
                    bool   lazyInit = IsLazyInit(configurableObjectFactory, name);
                    object instance = !lazyInit ? _objectFactory[name] : null;
                    if (!_beans.Contains(name) &&
                        (instance == null || !BeansContainsInstance(instance)))
                    {
                        _beans[name] = !lazyInit ? instance : name;
                    }
                }
            }
        }
Beispiel #17
0
        public void DoesNotChokeOnBadResourceLocationIfIgnoreBadResourcesFlagSetToTrue()
        {
            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();

            cfg.IgnoreResourceNotFound = true;
            IResource mockResource = (IResource)mocks.CreateMock(typeof(IResource));

            Expect.Call(mockResource.Exists).Return(false);
            cfg.Location       = mockResource;
            cfg.ConfigSections = new string[] { "" };
            IConfigurableListableObjectFactory mockFactory = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));

            Expect.Call(mockFactory.GetObjectDefinitionNames()).Return(new string[] {});
            mocks.ReplayAll();

            cfg.PostProcessObjectFactory(mockFactory);

            mocks.VerifyAll();
        }
Beispiel #18
0
        public static void RegisterDefaultConversationAop(this IConfigurableListableObjectFactory confObjFactory)
        {
            var metaInfoStore = new ReflectionConversationalMetaInfoSource();

            confObjFactory.RegisterInstance(metaInfoStore);
            // register advisor definition
            var pc =
                ObjectDefinitionBuilder.RootObjectDefinition(ObjectDefinitionFactory,
                                                             typeof(ConversationInterceptor))
                .SetAutowireMode(AutoWiringMode.AutoDetect)
                .SetSingleton(false);

            confObjFactory.RegisterObjectDefinition("PersistentConversationalInterceptor", pc.ObjectDefinition);
            var postProcessor = new ConversationalAttributeAutoProxyCreator(metaInfoStore)
            {
                ObjectFactory    = confObjFactory,
                InterceptorNames = new[] { "PersistentConversationalInterceptor" }
            };

            confObjFactory.AddObjectPostProcessor(postProcessor);
        }
        /// <summary>
        /// Apply the given properties to the supplied
        /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
        /// </summary>
        /// <param name="factory">
        /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
        /// used by the application context.
        /// </param>
        /// <param name="props">The properties to apply.</param>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// If an error occured.
        /// </exception>
        protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props)
        {
            PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props);
            ObjectDefinitionVisitor          visitor        = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(resolveAdapter.ParseAndResolveVariables));

            string[] objectDefinitionNames = factory.GetObjectDefinitionNames();
            for (int i = 0; i < objectDefinitionNames.Length; ++i)
            {
                string            name       = objectDefinitionNames[i];
                IObjectDefinition definition = factory.GetObjectDefinition(name);
                try
                {
                    visitor.VisitObjectDefinition(definition);
                }
                catch (ObjectDefinitionStoreException ex)
                {
                    throw new ObjectDefinitionStoreException(
                              definition.ResourceDescription, name, ex.Message);
                }
            }
        }
Beispiel #20
0
        public void MalformedOverrideKey()
        {
            IConfigurableListableObjectFactory objectFactory = mocks.StrictMock <IConfigurableListableObjectFactory>();
            IConfigurableListableObjectFactory fac           = objectFactory;

            PropertyOverrideConfigurer cfg = new PropertyOverrideConfigurer();
            NameValueCollection        defaultProperties = new NameValueCollection();

            defaultProperties.Add("malformedKey", "Rick Evans");
            cfg.Properties = defaultProperties;
            mocks.ReplayAll();
            try
            {
                cfg.PostProcessObjectFactory(fac);
                Assert.Fail("Should have had a FatalObjectException at this point because of a malformed key.");
            }
            catch (FatalObjectException)
            {
            }
            mocks.VerifyAll();
        }
Beispiel #21
0
        public void ObjectNamesForTypeIncludingAncestorsPrototypesAndFactoryObjectsPreserveOrderOfRegistration()
        {
            MockRepository mocks = new MockRepository();
            IConfigurableListableObjectFactory of       = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));
            IConfigurableListableObjectFactory ofParent = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory));
            Type EXPECTEDTYPE = typeof(ITestObject);

            Expect.Call(of.GetObjectNamesForType(EXPECTEDTYPE, false, false)).Return(new string[] { "objA", "objB", "objC" });
            Expect.Call(((IHierarchicalObjectFactory)of).ParentObjectFactory).Return(ofParent);
            Expect.Call(ofParent.GetObjectNamesForType(EXPECTEDTYPE, false, false)).Return(new string[] { "obj2A", "objB", "obj2C" });

            mocks.ReplayAll();

            IList <string> names = ObjectFactoryUtils.ObjectNamesForTypeIncludingAncestors(of, EXPECTEDTYPE, false, false);

            Assert.AreEqual(5, names.Count);
            Assert.AreEqual(new string[] { "objA", "objB", "objC", "obj2A", "obj2C" }, names);


            mocks.VerifyAll();
        }
        public void MissingObjectDefinitionDoesntRaiseFatalException()
        {
            const string valueTo_NOT_BeOveridden = "Jenny Lewis";
            TestObject   foo = new TestObject(valueTo_NOT_BeOveridden, 30);
            IConfigurableListableObjectFactory objectFactory =
                (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory));

            Expect.Call(objectFactory.GetObjectDefinition("rubbish")).Return(null);
            IConfigurableListableObjectFactory fac = (IConfigurableListableObjectFactory)objectFactory;

            PropertyOverrideConfigurer cfg = new PropertyOverrideConfigurer();
            NameValueCollection        defaultProperties = new NameValueCollection();

            defaultProperties.Add("rubbish.Name", "Rick Evans");
            cfg.Properties = defaultProperties;
            mocks.ReplayAll();
            cfg.PostProcessObjectFactory(fac);
            Assert.AreEqual(valueTo_NOT_BeOveridden, foo.Name,
                            "Property value was overridden, but a rubbish objectName root was supplied.");

            mocks.VerifyAll();
        }
        private static void RegisterObject(string objectName, object obj, IObjectFactory objectFactory)
        {
            AssertUtils.ArgumentNotNull(objectName, "object name must not be null");
            IConfigurableListableObjectFactory configurableListableObjectFactory = null;

            if (objectFactory is IConfigurableListableObjectFactory)
            {
                configurableListableObjectFactory = (IConfigurableListableObjectFactory)objectFactory;
            }
            else if (objectFactory is GenericApplicationContext)
            {
                configurableListableObjectFactory = ((GenericApplicationContext)objectFactory).ObjectFactory;
            }
            if (obj is IObjectNameAware)
            {
                ((IObjectNameAware)obj).ObjectName = objectName;
            }
            if (obj is IObjectFactoryAware)
            {
                ((IObjectFactoryAware)obj).ObjectFactory = objectFactory;
            }
            if (obj is IInitializingObject)
            {
                try
                {
                    ((IInitializingObject)obj).AfterPropertiesSet();
                }
                catch (Exception ex)
                {
                    throw new FatalObjectException("failed to register bean with test context", ex);
                }
            }
            if (configurableListableObjectFactory == null)
            {
                throw new ArgumentException("configurableListableObjectFactory must not be null");
            }

            configurableListableObjectFactory.RegisterSingleton(objectName, obj);
        }
Beispiel #24
0
 /// <summary>
 /// Modify the application context's internal object factory after its
 /// standard initialization.
 /// </summary>
 /// <param name="factory">
 /// The object factory used by the application context.
 /// </param>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In case of errors.
 /// </exception>
 /// <seealso cref="Spring.Objects.Factory.Config.IObjectFactoryPostProcessor.PostProcessObjectFactory(IConfigurableListableObjectFactory)"/>
 public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
 {
     try
     {
         NameValueCollection properties = new NameValueCollection();
         InitializeWithDefaultProperties(properties);
         LoadProperties(properties);
         ProcessProperties(factory, properties);
     }
     catch (Exception ex)
     {
         if (typeof(ObjectsException).IsInstanceOfType(ex))
         {
             throw;
         }
         else
         {
             throw new ObjectsException(
                       "Errored while postprocessing an object factory.", ex);
         }
     }
 }
        /// <summary>
        /// Apply the property replacement using the specified <see cref="IVariableSource"/>s for all
        /// object in the supplied
        /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
        /// </summary>
        /// <param name="factory">
        /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
        /// used by the application context.
        /// </param>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// If an error occured.
        /// </exception>
        protected virtual void ProcessProperties(IConfigurableListableObjectFactory factory)
        {
            CompositeVariableSource compositeVariableSource = new CompositeVariableSource(variableSourceList);
            TextProcessor           tp      = new TextProcessor(this, compositeVariableSource);
            ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(tp.ParseAndResolveVariables));

            string[] objectDefinitionNames = factory.GetObjectDefinitionNames();
            for (int i = 0; i < objectDefinitionNames.Length; ++i)
            {
                string            name       = objectDefinitionNames[i];
                IObjectDefinition definition = factory.GetObjectDefinition(name);
                try
                {
                    visitor.VisitObjectDefinition(definition);
                }
                catch (ObjectDefinitionStoreException ex)
                {
                    throw new ObjectDefinitionStoreException(
                              definition.ResourceDescription, name, ex.Message);
                }
            }
        }
        public void WithIgnoreUnresolvablePlaceholder()
        {
            const string          defName     = "foo";
            const string          placeholder = "${name}";
            TestObject            foo         = new TestObject(placeholder, 30);
            MutablePropertyValues pvs         = new MutablePropertyValues();

            pvs.Add("name", placeholder);
            RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs);

            IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>();

            A.CallTo(() => mock.GetObjectDefinitionNames(false)).Returns(new string [] { defName });
            A.CallTo(() => mock.GetObjectDefinition(defName, false)).Returns(def);

            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();

            cfg.IgnoreUnresolvablePlaceholders = true;
            cfg.PostProcessObjectFactory(mock);
            Assert.AreEqual(placeholder, foo.Name);

            A.CallTo(() => mock.AddEmbeddedValueResolver(null)).WithAnyArguments().MustHaveHappened();
        }
Beispiel #27
0
        public void WithIgnoreUnresolvablePlaceholder()
        {
            const string          defName     = "foo";
            const string          placeholder = "${name}";
            TestObject            foo         = new TestObject(placeholder, 30);
            MutablePropertyValues pvs         = new MutablePropertyValues();

            pvs.Add("name", placeholder);
            RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs);

            IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory));

            Expect.Call(mock.GetObjectDefinitionNames()).Return(new string [] { defName });
            Expect.Call(mock.GetObjectDefinition(defName)).Return(def);
            mocks.ReplayAll();

            PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer();

            cfg.IgnoreUnresolvablePlaceholders = true;
            cfg.PostProcessObjectFactory(mock);
            Assert.AreEqual(placeholder, foo.Name);

            mocks.VerifyAll();
        }
        /// <summary>
        /// Modify the application context's internal object factory after its
        /// standard initialization.
        /// </summary>
        /// <param name="factory">The object factory used by the application context.</param>
        /// <remarks>
        /// <p>
        /// All object definitions will have been loaded, but no objects will have
        /// been instantiated yet. This allows for overriding or adding properties
        /// even to eager-initializing objects.
        /// </p>
        /// </remarks>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// In case of errors.
        /// </exception>
        public void PostProcessObjectFactory( IConfigurableListableObjectFactory factory )
        {
            if (CollectionUtils.IsEmpty(variableSourceList))
            {
                throw new ArgumentException("No VariableSources configured");
            }

            ICollection filtered = CollectionUtils.FindValuesOfType(this.variableSourceList, typeof (IVariableSource));
            if (filtered.Count != this.variableSourceList.Count)
            {
                throw new ArgumentException("'VariableSources' must contain IVariableSource elements only", "VariableSources");
            }

            try
            {
                ProcessProperties( factory );
            }
            catch (Exception ex)
            {
                if (typeof( ObjectsException ).IsInstanceOfType( ex ))
                {
                    throw;
                }
                else
                {
                    throw new ObjectsException(
                        "Errored while postprocessing an object factory.", ex );
                }
            }
        }
        /// <summary>
        /// Registers well-known <see cref="IObjectPostProcessor"/>s and 
        /// preregisters well-known dependencies using <see cref="IConfigurableListableObjectFactory.RegisterResolvableDependency"/>
        /// </summary>
        /// <param name="objectFactory">the raw object factory as returned from <see cref="RefreshObjectFactory"/></param>
        private void PrepareObjectFactory(IConfigurableListableObjectFactory objectFactory)
        {
            EnsureKnownObjectPostProcessors(objectFactory);
            objectFactory.IgnoreDependencyType(typeof(IResourceLoader));
            objectFactory.IgnoreDependencyType(typeof(IApplicationContext));

            objectFactory.RegisterResolvableDependency(typeof(IObjectFactory), objectFactory);
            objectFactory.RegisterResolvableDependency(typeof(IResourceLoader), this);
            objectFactory.RegisterResolvableDependency(typeof(IApplicationEventPublisher), this);
            objectFactory.RegisterResolvableDependency(typeof(IApplicationContext), this);
            objectFactory.RegisterResolvableDependency(typeof(IEventRegistry), this);
        }
 public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
 {
     Called = true;
 }
Beispiel #31
0
 public void SetUp()
 {
     mocks   = new MockRepository();
     factory = mocks.StrictMock <IConfigurableListableObjectFactory>();
 }
 public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
 {
     SPRNET1231FactoryObject testFactory = (SPRNET1231FactoryObject)factory.GetObject("testFactory");
     Assert.AreEqual(0, testFactory.count);
 }
 /// <summary>
 /// An new <see cref="IConfigurableListableObjectFactory"/> was set. Initialize this creator instance
 /// according to the specified object factory.
 /// </summary>
 /// <param name="objectFactory"></param>
 protected virtual void InitObjectFactory(IConfigurableListableObjectFactory objectFactory)
 {
     _advisorRetrievalHelper = CreateAdvisorRetrievalHelper(objectFactory);
 }
        private void EnhanceConfigurationClasses(IConfigurableListableObjectFactory objectFactory)
        {
            ConfigurationClassEnhancer enhancer = new ConfigurationClassEnhancer(objectFactory);

            IList<string> objectNames = objectFactory.GetObjectDefinitionNames();

            foreach (string name in objectNames)
            {
                IObjectDefinition objDef = objectFactory.GetObjectDefinition(name);

                if (((AbstractObjectDefinition)objDef).HasObjectType)
                {
                    if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null)
                    {
                        //TODO check type of object isn't infrastructure type.

                        Type configClass = objDef.ObjectType;
                        Type enhancedClass = enhancer.Enhance(configClass);

                        Logger.Debug(m => m("Replacing object definition '{0}' existing class '{1}' with enhanced class", name, configClass.FullName));

                        ((IConfigurableObjectDefinition)objDef).ObjectType = enhancedClass;
                    }
                }
            }
        }
        /// <summary>
        /// DO NOT USE - this is subject to change!
        /// </summary>
        /// <param name="appRelativeVirtualPath"></param>
        /// <param name="objectFactory"></param>
        /// <returns>
        /// This method requires registrars to follow the convention of registering web object definitions using their
        /// application relative urls (~/mypath/mypage.aspx). 
        /// </returns>
        /// <remarks>
        /// Resolve an object definition by url.
        /// </remarks>
        protected internal static NamedObjectDefinition FindWebObjectDefinition(string appRelativeVirtualPath, IConfigurableListableObjectFactory objectFactory)
        {
            ILog Log = LogManager.GetLogger(typeof(AbstractHandlerFactory));
            bool isDebug = Log.IsDebugEnabled;

            // lookup definition using app-relative url
            if (isDebug)
                Log.Debug(string.Format("GetHandler():looking up definition for app-relative url '{0}'", appRelativeVirtualPath));
            string objectDefinitionName = appRelativeVirtualPath;
            IObjectDefinition pageDefinition = objectFactory.GetObjectDefinition(appRelativeVirtualPath, true);

            if (pageDefinition == null)
            {
                // try using pagename+extension and pagename only
                string pageExtension = Path.GetExtension(appRelativeVirtualPath);
                string pageName = WebUtils.GetPageName(appRelativeVirtualPath);
                // only looks in the specified object factory -- it will *not* search parent contexts
                pageDefinition = objectFactory.GetObjectDefinition(pageName + pageExtension, false);
                if (pageDefinition == null)
                {
                    pageDefinition = objectFactory.GetObjectDefinition(pageName, false);
                    if (pageDefinition != null)
                        objectDefinitionName = pageName;
                }
                else
                {
                    objectDefinitionName = pageName + pageExtension;
                }

                if (pageDefinition != null)
                {
                    if (isDebug)
                        Log.Debug(string.Format("GetHandler():found definition for page-name '{0}'", objectDefinitionName));
                }
                else
                {
                    if (isDebug)
                        Log.Debug(string.Format("GetHandler():no definition found for page-name '{0}'", pageName));
                }
            }
            else
            {
                if (isDebug)
                    Log.Debug(string.Format("GetHandler():found definition for page-url '{0}'", appRelativeVirtualPath));
            }

            return (pageDefinition == null) ? (NamedObjectDefinition)null : new NamedObjectDefinition(objectDefinitionName, pageDefinition);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SpringObjectMethodInterceptor"/> class.
 /// </summary>
 /// <param name="configurableListableObjectFactory">The configurable listable object factory.</param>
 public SpringObjectMethodInterceptor(IConfigurableListableObjectFactory configurableListableObjectFactory)
 {
     _configurableListableObjectFactory = configurableListableObjectFactory;
 }
 /// <summary>
 /// An new <see cref="IConfigurableListableObjectFactory"/> was set. Initialize this creator instance
 /// according to the specified object factory.
 /// </summary>
 /// <param name="objectFactory"></param>
 protected virtual void InitObjectFactory(IConfigurableListableObjectFactory objectFactory)
 {
     _advisorRetrievalHelper = CreateAdvisorRetrievalHelper(objectFactory);
 }
        private Type GenerateProxyType(string objectName, IConfigurableListableObjectFactory objectFactory)
        {
            ProxyFactory proxyFactory = new ProxyFactory();
            proxyFactory.ProxyTargetAttributes = true;
            proxyFactory.Interfaces = Type.EmptyTypes;
            proxyFactory.TargetSource = new ObjectFactoryTargetSource(objectName, objectFactory);
            SpringObjectMethodInterceptor methodInterceptor = new SpringObjectMethodInterceptor(objectFactory);
            proxyFactory.AddAdvice(methodInterceptor);

            //TODO check type of object isn't infrastructure type.

            InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(proxyFactory);
            //iaptb.ProxyDeclaredMembersOnly = true; // make configurable.
            return iaptb.BuildProxyType();
        }
        /// <summary>
        /// Instantiate and invoke all registered
        /// <see cref="Spring.Objects.Factory.Config.IObjectFactoryPostProcessor"/>
        /// objects, respecting any explicit ordering.
        /// </summary>
        /// <remarks>
        /// <note type="caution">
        /// <b>Must</b> be called before singleton instantiation.
        /// </note>
        /// </remarks>
        /// <exception cref="ObjectsException">In the case of errors.</exception>
        private void InvokeObjectFactoryPostProcessors(IConfigurableListableObjectFactory objectFactory)
        {
            // Invoke BeanDefinitionRegistryPostProcessors first, if any.
            ArrayList processedObjects = new ArrayList();

            if (objectFactory is IObjectDefinitionRegistry)
            {
                IObjectDefinitionRegistry registry = (IObjectDefinitionRegistry)objectFactory;
                ArrayList regularPostProcessors = new ArrayList();
                ArrayList registryPostProcessors = new ArrayList();

                foreach (IObjectFactoryPostProcessor factoryProcessor in ObjectFactoryPostProcessors)
                {
                    if (factoryProcessor is IObjectDefinitionRegistryPostProcessor)
                    {
                        ((IObjectDefinitionRegistryPostProcessor)factoryProcessor).PostProcessObjectDefinitionRegistry(registry);
                        registryPostProcessors.Add(factoryProcessor);
                    }
                    else
                    {
                        regularPostProcessors.Add(factoryProcessor);
                    }
                }

                IDictionary objectMap = objectFactory.GetObjectsOfType(typeof(IObjectDefinitionRegistryPostProcessor), true, false);

                ArrayList registryPostProcessorObjects = new ArrayList(objectMap.Values);
                registryPostProcessorObjects.Sort(new OrderComparator());

                foreach (System.Object processor in registryPostProcessorObjects)
                {
                    ((IObjectDefinitionRegistryPostProcessor)processor).PostProcessObjectDefinitionRegistry(registry);
                }

                InvokeObjectFactoryPostProcessors(registryPostProcessors, objectFactory);
                InvokeObjectFactoryPostProcessors(registryPostProcessorObjects, objectFactory);
                InvokeObjectFactoryPostProcessors(regularPostProcessors, objectFactory);

               // processedObjects.Add(objectMap.Keys);
                 
                foreach (DictionaryEntry entry in objectMap)
                {
                    processedObjects.Add(entry.Key);
                }

            }
            else
            {
                foreach (IObjectFactoryPostProcessor factoryProcessor in ObjectFactoryPostProcessors)
                {
                    // Invoke factory processors registered with the context instance.
                    factoryProcessor.PostProcessObjectFactory(objectFactory);
                }
            }

            // Do not initialize FactoryBeans here: We need to leave all regular beans
            // uninitialized to let the bean factory post-processors apply to them!
            ArrayList factoryProcessorNames = new ArrayList();
            string[] names = GetObjectNamesForType(typeof(IObjectFactoryPostProcessor), true, false);
            foreach (string name in names)
            {
                factoryProcessorNames.Add(name);
            }

            // Separate between ObjectFactoryPostProcessors that implement PriorityOrdered,
            // Ordered, and the rest.
            ArrayList priorityOrderedFactoryProcessors = new ArrayList();
            ArrayList orderedFactoryProcessorsNames = new ArrayList();
            ArrayList nonOrderedFactoryProcessorNames = new ArrayList();

            for (int i = 0; i < factoryProcessorNames.Count; ++i)
            {
                string processorName = (string)factoryProcessorNames[i];
                if (processedObjects.Contains(processorName))
                {
                    //skip  -- already processed in first phase above
                    Debug.WriteLine("");
                }
                else if (IsTypeMatch(processorName, typeof(IPriorityOrdered)))
                {
                    priorityOrderedFactoryProcessors.Add(ObjectFactory.GetObject(processorName, typeof(IObjectFactoryPostProcessor)));
                }
                else if (IsTypeMatch(processorName, typeof(IOrdered)))
                {
                    orderedFactoryProcessorsNames.Add(processorName);
                }
                else
                {
                    nonOrderedFactoryProcessorNames.Add(processorName);
                }
            }
            // First, invoke the IObjectFactoryPostProcessors that implement IPriorityOrdered.
            InvokePriorityOrderedObjectFactoryPostProcessors(factoryProcessorNames, priorityOrderedFactoryProcessors);

            // Second, invoke those IObjectFactoryPostProcessors that implement IOrdered...
            ArrayList orderedFactoryProcessors = new ArrayList();
            foreach (string orderedFactoryProcessorsName in orderedFactoryProcessorsNames)
            {
                orderedFactoryProcessors.Add(ObjectFactory.GetObject(orderedFactoryProcessorsName,
                                                                     typeof(IObjectFactoryPostProcessor)));
            }
            orderedFactoryProcessors.Sort(new OrderComparator());
            InvokeObjectFactoryPostProcessors(orderedFactoryProcessors, ObjectFactory);

            // and then the unordered ones...
            ArrayList nonOrderedPostProcessors = new ArrayList();
            foreach (string nonOrderedFactoryProcessorName in nonOrderedFactoryProcessorNames)
            {
                nonOrderedPostProcessors.Add(ObjectFactory.GetObject(nonOrderedFactoryProcessorName,
                                                                     typeof(IObjectFactoryPostProcessor)));
            }
            InvokeObjectFactoryPostProcessors(nonOrderedPostProcessors, ObjectFactory);

            #region Instrumentation

            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format(
                              CultureInfo.InvariantCulture,
                              "processed {0} IFactoryObjectPostProcessors defined in application context [{1}].",
                              factoryProcessorNames.Count,
                              Name));
            }

            #endregion
        }
 /// <summary>
 /// Modify the application context's internal object factory after its
 /// standard initialization.
 /// </summary>
 /// <param name="factory">The object factory used by the application context.</param>
 /// <remarks>
 /// 	<p>
 /// All object definitions will have been loaded, but no objects will have
 /// been instantiated yet. This allows for overriding or adding properties
 /// even to eager-initializing objects.
 /// </p>
 /// </remarks>
 /// <exception cref="Spring.Objects.ObjectsException">
 /// In case of errors.
 /// </exception>
 public abstract void PostProcessObjectFactory(
     IConfigurableListableObjectFactory factory);
Beispiel #41
0
 public void SetUp()
 {
     factoryMock = new DynamicMock(typeof(IConfigurableListableObjectFactory));
     factory     = (IConfigurableListableObjectFactory)factoryMock.Object;
     host        = NewApplicationHost(AppDomain.CurrentDomain, factory);
 }
        private void RegisterObjectPostProcessors(IConfigurableListableObjectFactory objectFactory)
        {
            RefreshObjectPostProcessorChecker(objectFactory);
            IDictionary dict = GetObjectsOfType(typeof(IObjectPostProcessor), true, false);
            ArrayList objectProcessors = new ArrayList(dict.Values);
            //            objectProcessors.Sort(new OrderComparator());
            foreach (IObjectPostProcessor objectPostProcessor in objectProcessors)
            {
                ObjectFactory.AddObjectPostProcessor(objectPostProcessor);
            }

            if (log.IsDebugEnabled)
            {
                log.Debug(string.Format(
                              CultureInfo.InvariantCulture,
                              "processed {0} IObjectPostProcessors defined in application context [{1}].",
                              objectProcessors.Count,
                              Name));
            }
        }
Beispiel #43
0
 public void SetUp()
 {
     factory = A.Fake <IConfigurableListableObjectFactory>();
 }
 public void Reset(IConfigurableListableObjectFactory objectFactory, int objectPostProcessorTargetCount)
 {
     _objectFactory = objectFactory;
     _objectPostProcessorTargetCount = objectPostProcessorTargetCount;
 }
 public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
 {
     Called = true;
 }
 public void SetUp()
 {
     mocks   = new MockRepository();
     factory = (IConfigurableListableObjectFactory)
               mocks.CreateMock(typeof(IConfigurableListableObjectFactory));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ObjectFactoryTargetSource"/> class.
 /// </summary>
 /// <param name="objectName">Name of the object.</param>
 /// <param name="objectFactory">The object factory.</param>
 public ObjectFactoryTargetSource(string objectName, IConfigurableListableObjectFactory objectFactory)
 {
     _objectName = objectName;
     _objectFactory = objectFactory;
 }
        /// <summary>
        /// Apply the property replacement using the specified <see cref="IVariableSource"/>s for all
        /// object in the supplied
        /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
        /// </summary>
        /// <param name="factory">
        /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
        /// used by the application context.
        /// </param>
        /// <exception cref="Spring.Objects.ObjectsException">
        /// If an error occured.
        /// </exception>
        protected virtual void ProcessProperties( IConfigurableListableObjectFactory factory )
        {
            CompositeVariableSource compositeVariableSource = new CompositeVariableSource(variableSourceList);
            TextProcessor tp = new TextProcessor(this, compositeVariableSource);
            ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(tp.ParseAndResolveVariables));

            IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors);
            for (int i = 0; i < objectDefinitionNames.Count; ++i)
            {
                string name = objectDefinitionNames[i];
                IObjectDefinition definition = factory.GetObjectDefinition( name, includeAncestors );
                
                if (definition == null)
                    continue;

                try
                {
                    visitor.VisitObjectDefinition( definition );
                }
                catch (ObjectDefinitionStoreException ex)
                {
                    throw new ObjectDefinitionStoreException(
                        definition.ResourceDescription, name, ex.Message );
                }
            }
        }
 /// <summary>
 /// Ensures, that predefined ObjectPostProcessors are registered with this ObjectFactory
 /// </summary>
 /// <param name="objectFactory"></param>
 protected void EnsureKnownObjectPostProcessors(IConfigurableListableObjectFactory objectFactory)
 {
     // index 0 contains the ObjectPostProcessorChecker that is handled separately!
     for (int i = 1; i < _defaultObjectPostProcessors.Count; i++)
     {
         objectFactory.AddObjectPostProcessor((IObjectPostProcessor)this._defaultObjectPostProcessors[i]);
     }
 }
 public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
 {
     Assert.AreEqual(ObjectProcessingState.PostProcessObjectFactory, CurrentState);
     CurrentState++;
 }
 /// <summary>
 /// Modify the application context's internal object factory after its standard
 /// initialization.
 /// </summary>
 /// <remarks>
 /// <p>
 /// All object definitions will have been loaded, but no objects
 /// will have been instantiated yet. This allows for the registration
 /// of special
 /// <see cref="Spring.Objects.Factory.Config.IObjectPostProcessor"/>s
 /// in certain
 /// <see cref="Spring.Context.IApplicationContext"/> implementations.
 /// </p>
 /// </remarks>
 /// <param name="objectFactory">
 /// The object factory used by the application context.
 /// </param>
 /// <exception cref="ObjectsException">
 /// In the case of errors.
 /// </exception>.
 protected virtual void PostProcessObjectFactory(
     IConfigurableListableObjectFactory objectFactory)
 {
 }
Beispiel #52
0
        /// <summary>
        /// Modify the application context's internal object factory after its
        /// standard initialization.
        /// </summary>
        /// <param name="factory">
        /// The object factory used by the application context.
        /// </param>
        /// <seealso cref="Spring.Objects.Factory.Config.IObjectFactoryPostProcessor.PostProcessObjectFactory(IConfigurableListableObjectFactory)"/>
        public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
        {
            string filename = null;
            if (UseConfigFile)
            {
                filename = (Filename == null) 
                    ? AppDomain.CurrentDomain.SetupInformation.ConfigurationFile 
                    : Filename.File.FullName;
            }
#if NET_2_0
            RemotingConfiguration.Configure(filename, EnsureSecurity);
#else
            RemotingConfiguration.Configure(filename);
#endif
            #region Instrumentation

            if (log.IsDebugEnabled)
            {
                if (filename == null)
                {
                    log.Debug("Default remoting infrastructure loaded.");
                }
                else
                {
                    log.Debug(String.Format("Remoting infrastructure configured using file '{0}'.", filename));
                }
            }

            #endregion
        }
 private void InvokeObjectFactoryPostProcessors(IList objectFactoryPostProcessors, IConfigurableListableObjectFactory objectFactory)
 {
     foreach (IObjectFactoryPostProcessor processor in objectFactoryPostProcessors)
     {
         processor.PostProcessObjectFactory(objectFactory);
     }
 }
		/// <summary>
		/// Apply the given properties to the supplied
		/// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
		/// </summary>
		/// <param name="factory">
		/// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
		/// used by the application context.
		/// </param>
		/// <param name="props">The properties to apply.</param>
		/// <exception cref="Spring.Objects.ObjectsException">
		/// If an error occured.
		/// </exception>
		protected override void ProcessProperties(
			IConfigurableListableObjectFactory factory, NameValueCollection props)
		{
			foreach (string key in props.AllKeys)
			{
				ProcessKey(factory, key, props[key]);
			}
		}
 /// <summary>
 /// Resets the well-known ObjectPostProcessorChecker that logs an info
 /// message when an object is created during IObjectPostProcessor
 /// instantiation, i.e. when an object is not eligible for being
 /// processed by all IObjectPostProcessors.
 /// </summary>
 private void RefreshObjectPostProcessorChecker(IConfigurableListableObjectFactory objectFactory)
 {
     int registeredObjectPostProcessorCount = GetObjectNamesForType(typeof(IObjectPostProcessor), true, false).Length;
     int objectPostProcessorCount = ObjectFactory.ObjectPostProcessorCount + 1
                                    + registeredObjectPostProcessorCount;
     ((ObjectPostProcessorChecker)_defaultObjectPostProcessors[0]).Reset(objectFactory, objectPostProcessorCount);
 }
		/// <summary>
		/// Process the given key as 'name.property' entry.
		/// </summary>
		/// <param name="factory">
		/// The object factory containing the object definitions that are to be
		/// processed.
		/// </param>
		/// <param name="key">The key.</param>
		/// <param name="value">The value.</param>
		/// <exception cref="Spring.Objects.ObjectsException">
		/// If an error occurs.
		/// </exception>
		/// <exception cref="Spring.Objects.FatalObjectException">
		/// If the property was not well formed (i.e. not in the format "name.property").
		/// </exception>
		protected virtual void ProcessKey(
			IConfigurableListableObjectFactory factory, string key, string value)
		{
			int dotIndex = key.IndexOf('.');
			if (dotIndex == -1)
			{
				throw new FatalObjectException(
					string.Format(CultureInfo.InvariantCulture,
					              "Invalid key '{0}': expected 'objectName.property' form.", key));
			}
			string name = key.Substring(0, dotIndex);
			string objectProperty = key.Substring(dotIndex + 1);
			IObjectDefinition definition = factory.GetObjectDefinition(name);
			if(definition != null) 
			{
                PropertyValue pv = definition.PropertyValues.GetPropertyValue(objectProperty);
                if (pv != null && pv.Value is RuntimeObjectReference)
                {
                    definition.PropertyValues.Add(objectProperty, new RuntimeObjectReference(value));
                }
                else if (pv != null && pv.Value is ExpressionHolder)
                {
                    definition.PropertyValues.Add(objectProperty, new ExpressionHolder(value));
                }
                else
                {
                    definition.PropertyValues.Add(objectProperty, value);
                }
			}
			else 
			{
				#region Instrumentation

				if (_logger.IsWarnEnabled)
				{
					_logger.Warn(string.Format(CultureInfo.InvariantCulture,
						"Cannot find object '{0}' when overriding properties; check configuration.", name));
				}

				#endregion
			}

			#region Instrumentation

			if (_logger.IsDebugEnabled)
			{
				_logger.Debug(string.Format(CultureInfo.InvariantCulture,
				                            "Property '{0}' set to '{1}'.", key, value));
			}

			#endregion
		}
        /// <summary>
		/// Apply the given properties to the supplied
		/// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>.
		/// </summary>
		/// <param name="factory">
		/// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>
		/// used by the application context.
		/// </param>
		/// <param name="props">The properties to apply.</param>
		/// <exception cref="Spring.Objects.ObjectsException">
		/// If an error occured.
		/// </exception>
		protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props)
		{
            PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props);
            ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(resolveAdapter.ParseAndResolveVariables);

			IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames();
			for (int i = 0; i < objectDefinitionNames.Count; ++i)
			{
				string name = objectDefinitionNames[i];
				IObjectDefinition definition = factory.GetObjectDefinition(name);
				try
				{
                    visitor.VisitObjectDefinition(definition);
				}
				catch (ObjectDefinitionStoreException ex)
				{
					throw new ObjectDefinitionStoreException(
						definition.ResourceDescription, name, ex.Message);
				}
			}

            factory.AddEmbeddedValueResolver(resolveAdapter);
		}
        /// <summary>
        /// Postprocesses the object factory.
        /// </summary>
        /// <param name="objectFactory">The object factory.</param>
        public void PostProcessObjectFactory(IConfigurableListableObjectFactory objectFactory)
        {
            if (_postProcessObjectFactoryCalled)
            {
                throw new InvalidOperationException(
                        "PostProcessObjectFactory already called for this post-processor");
            }
            _postProcessObjectFactoryCalled = true;
            if (!_postProcessObjectDefinitionRegistryCalled)
            {
                // ObjectDefinitionRegistryPostProcessor hook apparently not supported...
                // Simply call processConfigObjectDefinitions lazily at this point then.
                ProcessConfigObjectDefinitions((IObjectDefinitionRegistry)objectFactory);
            }

            EnhanceConfigurationClasses(objectFactory);
        }
        public void SetUp()
        {
            mocks = new MockRepository();
            factory = mocks.StrictMock<IConfigurableListableObjectFactory>();

        }
        private void EnhanceConfigurationClasses(IConfigurableListableObjectFactory objectFactory)
        {
            string[] objectNames = objectFactory.GetObjectDefinitionNames();

            foreach (string t in objectNames)
            {
                IObjectDefinition objDef = objectFactory.GetObjectDefinition(t);

                if (((AbstractObjectDefinition)objDef).HasObjectType)
                {
                    if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null)
                    {

                        ProxyFactory proxyFactory = new ProxyFactory();
                        proxyFactory.ProxyTargetAttributes = true;
                        proxyFactory.Interfaces = Type.EmptyTypes;
                        proxyFactory.TargetSource = new ObjectFactoryTargetSource(t, objectFactory);
                        SpringObjectMethodInterceptor methodInterceptor = new SpringObjectMethodInterceptor(objectFactory);
                        proxyFactory.AddAdvice(methodInterceptor);

                        //TODO check type of object isn't infrastructure type.

                        InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(proxyFactory);
                        //iaptb.ProxyDeclaredMembersOnly = true; // make configurable.
                        ((IConfigurableObjectDefinition)objDef).ObjectType = iaptb.BuildProxyType();

                        objDef.ConstructorArgumentValues.AddIndexedArgumentValue(objDef.ConstructorArgumentValues.ArgumentCount, proxyFactory);

                    }
                }
            }
        }