public void SunnyDayPath()
        {
            IObjectFactory objectFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
            IConfigurableObjectDefinition configurableObjectDefinition =
                (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition));

            object       expectedLookup   = new object();
            const string LookupObjectName = "foo";

            Expect.Call(objectFactory.GetObject(LookupObjectName)).Return(expectedLookup);

            LookupMethodOverride ovr       = new LookupMethodOverride("SunnyDayPath", LookupObjectName);
            MethodOverrides      overrides = new MethodOverrides();

            overrides.Add(ovr);
            Expect.Call(configurableObjectDefinition.MethodOverrides).Return(overrides);

            LookupMethodReplacer replacer = new LookupMethodReplacer(configurableObjectDefinition, objectFactory);

            mocks.ReplayAll();
            MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod();

            object lookup = replacer.Implement(this, method, new object[] {});

            Assert.AreSame(expectedLookup, lookup);

            mocks.VerifyAll();
        }
        protected override ObjectDefinitionHolder CreateObjectDefinitionHolder(
            XmlElement element,
            IConfigurableObjectDefinition definition,
            string objectName,
            IReadOnlyList <string> aliasesArray)
        {
            if (definition is IWebObjectDefinition webDefinition)
            {
                if (definition.IsSingleton &&
                    element.HasAttribute(ObjectDefinitionConstants.ScopeAttribute))
                {
                    webDefinition.Scope = GetScope(element.GetAttribute(ObjectDefinitionConstants.ScopeAttribute));
                }

                // force request and session scoped objects to be lazily initialized...
                if (webDefinition.Scope == ObjectScope.Request ||
                    webDefinition.Scope == ObjectScope.Session)
                {
                    definition.IsLazyInit = true;
                }

//                string typeName = element.GetAttribute(ObjectDefinitionConstants.TypeAttribute);
                string typeName = definition.ObjectTypeName;
                if (typeName != null &&
                    (typeName.EndsWith(".ascx") || typeName.EndsWith(".master")))
                {
                    definition.IsAbstract = true;
                }
            }

            ObjectDefinitionHolder holder = base.CreateObjectDefinitionHolder(element, definition, objectName, aliasesArray);

            return(holder);
        }
Esempio n. 3
0
        private IObjectDefinition ParseExceptionAction(XmlElement element, ParserContext parserContext)
        {
            string typeName        = "Spring.Validation.Actions.ExceptionAction, Spring.Core";
            string throwExpression = GetAttributeValue(element, ValidatorDefinitionConstants.ThrowAttribute);


            ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues();

            ctorArgs.AddGenericArgumentValue(throwExpression);

            string when = GetAttributeValue(element, ValidatorDefinitionConstants.WhenAttribute);
            MutablePropertyValues properties = new MutablePropertyValues();

            if (StringUtils.HasText(when))
            {
                properties.Add("When", when);
            }

            IConfigurableObjectDefinition action =
                parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain);

            action.ConstructorArgumentValues = ctorArgs;
            action.PropertyValues            = properties;

            return(action);
        }
Esempio n. 4
0
        /// <summary>
        /// Parses the RemotingConfigurer definition.
        /// </summary>
        /// <param name="element">The element to parse.</param>
        /// <param name="name">The name of the object definition.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <returns>RemotingConfigurer object definition.</returns>
        private IConfigurableObjectDefinition ParseRemotingConfigurer(
            XmlElement element, string name, ParserContext parserContext)
        {
            string typeName       = GetTypeName(element);
            string filename       = element.GetAttribute(RemotingConfigurerConstants.FilenameAttribute);
            string useConfigFile  = element.GetAttribute(RemotingConfigurerConstants.UseConfigFileAttribute);
            string ensureSecurity = element.GetAttribute(RemotingConfigurerConstants.EnsureSecurityAttribute);

            MutablePropertyValues properties = new MutablePropertyValues();

            if (StringUtils.HasText(filename))
            {
                properties.Add("Filename", filename);
            }
            if (StringUtils.HasText(useConfigFile))
            {
                properties.Add("UseConfigFile", useConfigFile);
            }
            if (StringUtils.HasText(ensureSecurity))
            {
                properties.Add("EnsureSecurity", ensureSecurity);
            }

            IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(
                typeName, null, parserContext.ReaderContext.Reader.Domain);

            cod.PropertyValues = properties;
            return(cod);
        }
Esempio n. 5
0
        public void SunnyDayPath()
        {
            IObjectFactory mockFactory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory));
            IConfigurableObjectDefinition mockDefinition = (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition));
            IMethodReplacer mockReplacer = (IMethodReplacer)mocks.CreateMock(typeof(IMethodReplacer));


            const string ReplacerObjectName = "replacer";

            Expect.Call(mockFactory.GetObject(ReplacerObjectName)).Return(mockReplacer);

            ReplacedMethodOverride ovr       = new ReplacedMethodOverride("SunnyDayPath", ReplacerObjectName);
            MethodOverrides        overrides = new MethodOverrides();

            overrides.Add(ovr);
            Expect.Call(mockDefinition.MethodOverrides).Return(overrides);

            Expect.Call(mockReplacer.Implement(null, null, null)).IgnoreArguments().Return(null);
            mocks.ReplayAll();

            DelegatingMethodReplacer replacer = new DelegatingMethodReplacer(mockDefinition, mockFactory);
            MethodInfo method = (MethodInfo)MethodBase.GetCurrentMethod();

            replacer.Implement(this, method, new object[] {});

            mocks.VerifyAll();
        }
        /// <summary>
        /// Creates an error message action based on the specified message element.
        /// </summary>
        /// <param name="message">The message element.</param>
        /// <param name="parserContext">The parser helper.</param>
        /// <returns>The error message action definition.</returns>
        private static IObjectDefinition ParseErrorMessageAction(XmlElement message, ParserContext parserContext)
        {
            string messageId = GetAttributeValue(message, MessageConstants.IdAttribute);
            string[] providers = GetAttributeValue(message, MessageConstants.ProvidersAttribute).Split(',');
            ArrayList parameters = new ArrayList();

            foreach (XmlElement param in message.ChildNodes)
            {
                IExpression paramExpression = Expression.Parse(GetAttributeValue(param, MessageConstants.ParameterValueAttribute));
                parameters.Add(paramExpression);
            }

            string typeName = "Spring.Validation.Actions.ErrorMessageAction, Spring.Core";
            ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues();
            ctorArgs.AddGenericArgumentValue(messageId);
            ctorArgs.AddGenericArgumentValue(providers);

            string when = GetAttributeValue(message, ValidatorDefinitionConstants.WhenAttribute);
            MutablePropertyValues properties = new MutablePropertyValues();
            if (StringUtils.HasText(when))
            {
                properties.Add("When", when);
            }
            if (parameters.Count > 0)
            {
                properties.Add("Parameters", parameters.ToArray(typeof(IExpression)));
            }

            IConfigurableObjectDefinition action =
                parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain);
            action.ConstructorArgumentValues = ctorArgs;
            action.PropertyValues = properties;

            return action;
        }
Esempio n. 7
0
        /// <summary>The parse inner object definition.</summary>
        /// <param name="element">The element.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <returns>The Spring.Objects.Factory.Config.IObjectDefinition.</returns>
        public static IObjectDefinition ParseInnerObjectDefinition(XmlElement element, ParserContext parserContext)
        {
            // parses out inner object definition for concrete implementation if defined
            var childElements = element.GetElementsByTagName("object");
            IObjectDefinition             innerComponentDefinition = null;
            IConfigurableObjectDefinition inDef = null;

            if (childElements != null && childElements.Count == 1)
            {
                var objectElement = childElements[0] as XmlElement;

                // var odDelegate = parserContext.GetDelegate();
                var odHolder = parserContext.ParserHelper.ParseObjectDefinitionElement(objectElement);

                // odHolder = odDelegate.DecorateObjectDefinitionIfRequired(objectElement, odHolder);
                inDef = odHolder.ObjectDefinition as IConfigurableObjectDefinition;
                var objectName = ObjectDefinitionReaderUtils.GenerateObjectName(inDef, parserContext.Registry);

                // innerComponentDefinition = new ObjectComponentDefinition(inDef, objectName);
                parserContext.Registry.RegisterObjectDefinition(objectName, inDef);
            }

            var aRef = element.GetAttribute(REF_ATTRIBUTE);

            AssertUtils.IsTrue(
                !(!string.IsNullOrWhiteSpace(aRef) && inDef != null),
                "Ambiguous definition. Inner object " + (inDef == null ? string.Empty : inDef.ObjectTypeName) + " declaration and \"ref\" " + aRef + " are not allowed together."
                );

            return(inDef);
        }
Esempio n. 8
0
        /// <summary>
        /// Creates object definition for the validator reference.
        /// </summary>
        /// <param name="element">The action definition element.</param>
        /// <param name="parserContext">The parser helper.</param>
        /// <returns>Generic validation action definition.</returns>
        private IObjectDefinition ParseValidatorReference(XmlElement element, ParserContext parserContext)
        {
            string typeName = "Spring.Validation.ValidatorReference, Spring.Core";
            string name     = GetAttributeValue(element, ValidatorDefinitionConstants.ReferenceNameAttribute);
            string context  = GetAttributeValue(element, ValidatorDefinitionConstants.ReferenceContextAttribute);
            string when     = GetAttributeValue(element, ValidatorDefinitionConstants.WhenAttribute);

            MutablePropertyValues properties = new MutablePropertyValues();

            properties.Add("Name", name);
            if (StringUtils.HasText(context))
            {
                properties.Add("Context", context);
            }
            if (StringUtils.HasText(when))
            {
                properties.Add("When", when);
            }

            IConfigurableObjectDefinition reference =
                parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain);

            reference.PropertyValues = properties;
            return(reference);
        }
Esempio n. 9
0
        public void InstantiationWithNullFactory()
        {
            IConfigurableObjectDefinition mock = (IConfigurableObjectDefinition)
                                                 mocks.CreateMock(typeof(IConfigurableObjectDefinition));

            new DelegatingMethodReplacer(mock, null);
        }
        protected override ObjectDefinitionHolder CreateObjectDefinitionHolder(XmlElement element, IConfigurableObjectDefinition definition, string objectName, string[] aliasesArray)
        {
            IWebObjectDefinition webDefinition = definition as IWebObjectDefinition;

            if (webDefinition != null)
            {
                if (definition.IsSingleton
                    && element.HasAttribute(ObjectDefinitionConstants.ScopeAttribute))
                {
                    webDefinition.Scope = GetScope(element.GetAttribute(ObjectDefinitionConstants.ScopeAttribute));
                }

                // force request and session scoped objects to be lazily initialized...
                if (webDefinition.Scope == ObjectScope.Request
                    || webDefinition.Scope == ObjectScope.Session)
                {
                    definition.IsLazyInit = true;
                }

            //                string typeName = element.GetAttribute(ObjectDefinitionConstants.TypeAttribute);
                string typeName = definition.ObjectTypeName;
                if (typeName != null
                    && (typeName.EndsWith(".ascx") || typeName.EndsWith(".master")))
                {
                    definition.IsAbstract = true;
                }
            }

            ObjectDefinitionHolder holder = base.CreateObjectDefinitionHolder(element, definition, objectName, aliasesArray);
            return holder;
        }
        /// <summary>
        /// Allows for custom modification of an application context's object definitions.
        /// </summary>
        /// <remarks>
        /// <p>
        /// If the object name matches, replaces the type by a AOP proxied type based on inheritance.
        /// </p>
        /// </remarks>
        public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
        {
            IList <string> objectDefinitionNames = factory.GetObjectDefinitionNames();

            for (int i = 0; i < objectDefinitionNames.Count; ++i)
            {
                string name = objectDefinitionNames[i];
                if (IsObjectNameMatch(name))
                {
                    IConfigurableObjectDefinition definition =
                        factory.GetObjectDefinition(name) as IConfigurableObjectDefinition;

                    if (definition == null || IsInfrastructureType(definition.ObjectType, name))
                    {
                        continue;
                    }

                    ProxyFactory pf = CreateProxyFactory(definition.ObjectType, name);

                    InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(pf);
                    iaptb.ProxyDeclaredMembersOnly = this.ProxyDeclaredMembersOnly;
                    Type type = iaptb.BuildProxyType();

                    definition.ObjectType = type;
                    definition.ConstructorArgumentValues.AddIndexedArgumentValue(definition.ConstructorArgumentValues.ArgumentCount, pf);
                }
            }
        }
Esempio n. 12
0
        public IObjectDefinition GetObjectDefinition(IObjectDefinitionService objectDefinitionService)
        {
            // parse the expression tree to create spring object definition.
            IConfigurableObjectDefinition objectDefinition = CreateObjectDefinition(objectDefinitionService);

            switch (_objectCreation.Body.NodeType)
            {
            case ExpressionType.MemberInit:
                MemberInit((MemberInitExpression)_objectCreation.Body, objectDefinition);
                break;

            case ExpressionType.Call:
                break;

            case ExpressionType.New:
                New((NewExpression)_objectCreation.Body, objectDefinition);
                break;

            case ExpressionType.Lambda:
                break;

            case ExpressionType.NewArrayInit:
                break;

            case ExpressionType.ListInit:
                break;

            // straight compilation of expression is required.
            default:
                break;
            }

            return(objectDefinition);
        }
Esempio n. 13
0
        /// <summary>
        /// Parses the CaoFactoryObject definition.
        /// </summary>
        /// <param name="element">The element to parse.</param>
        /// <param name="name">The name of the object definition.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <returns>CaoFactoryObject object definition.</returns>
        private IConfigurableObjectDefinition ParseCaoFactoryObject(
            XmlElement element, string name, ParserContext parserContext)
        {
            string typeName         = GetTypeName(element);
            string remoteTargetName = element.GetAttribute(CaoFactoryObjectConstants.RemoteTargetNameAttribute);
            string serviceUrl       = element.GetAttribute(CaoFactoryObjectConstants.ServiceUrlAttribute);

            MutablePropertyValues properties = new MutablePropertyValues();

            if (StringUtils.HasText(remoteTargetName))
            {
                properties.Add("RemoteTargetName", remoteTargetName);
            }
            if (StringUtils.HasText(serviceUrl))
            {
                properties.Add("ServiceUrl", serviceUrl);
            }

            foreach (XmlElement child in element.ChildNodes)
            {
                switch (child.LocalName)
                {
                case CaoFactoryObjectConstants.ConstructorArgumentsElement:
                    properties.Add("ConstructorArguments", base.ParseListElement(child, name, parserContext));
                    break;
                }
            }

            IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(
                typeName, null, parserContext.ReaderContext.Reader.Domain);

            cod.PropertyValues = properties;

            return(cod);
        }
 public void ApplyConvention(string identifierName, IConfigurableObjectDefinition objectDefinition)
 {
     foreach (PropertyInfo propertyInfo in objectDefinition.ObjectType.GetProperties().Where(p => _typeInjections.ContainsKey(p.PropertyType)))
     {
         objectDefinition.PropertyValues.Add(new PropertyValue(propertyInfo.Name, _typeInjections[propertyInfo.PropertyType]));
     }
 }
        public void InstantiationWithNullFactory()
        {
            IConfigurableObjectDefinition configurableObjectDefinition =
                (IConfigurableObjectDefinition)mocks.CreateMock(typeof(IConfigurableObjectDefinition));

            new LookupMethodReplacer(configurableObjectDefinition, null);
        }
Esempio n. 16
0
 /// <summary>
 /// Creates a new instance of the
 /// <see cref="ArgumentNullException"/>
 /// class.
 /// </summary>
 /// <remarks>
 /// <p>
 /// This is an <see lang="abstract"/> class, and as such has no
 /// publicly visible constructors.
 /// </p>
 /// </remarks>
 /// <param name="objectDefinition">
 /// The object definition that is the target of the method replacement.
 /// </param>
 /// <param name="objectFactory">
 /// The enclosing IoC container with which the above
 /// <paramref name="objectDefinition"/> is associated.
 /// </param>
 /// <exception cref="AbstractMethodReplacer">
 /// If either of the supplied arguments is <see langword="null"/>.
 /// </exception>
 protected AbstractMethodReplacer(
     IConfigurableObjectDefinition objectDefinition, IObjectFactory objectFactory)
 {
     AssertUtils.ArgumentNotNull(objectDefinition, "objectDefinition");
     AssertUtils.ArgumentNotNull(objectFactory, "objectFactory");
     this.objectDefinition = objectDefinition;
     this.objectFactory    = objectFactory;
 }
		/// <summary>
		/// Creates a new instance of the
		/// <see cref="ArgumentNullException"/>
		/// class.
		/// </summary>
		/// <remarks>
		/// <p>
		/// This is an <see lang="abstract"/> class, and as such has no
		/// publicly visible constructors.
		/// </p>
		/// </remarks>
		/// <param name="objectDefinition">
		/// The object definition that is the target of the method replacement.
		/// </param>
		/// <param name="objectFactory">
		/// The enclosing IoC container with which the above
		/// <paramref name="objectDefinition"/> is associated.
		/// </param>
		/// <exception cref="AbstractMethodReplacer">
		/// If either of the supplied arguments is <see langword="null"/>.
		/// </exception>
		protected AbstractMethodReplacer(
            IConfigurableObjectDefinition objectDefinition, IObjectFactory objectFactory)
		{
			AssertUtils.ArgumentNotNull(objectDefinition, "objectDefinition");
			AssertUtils.ArgumentNotNull(objectFactory, "objectFactory");
			this.objectDefinition = objectDefinition;
			this.objectFactory = objectFactory;
		}
 /// <summary>
 /// Create an <see cref="ObjectDefinitionHolder"/> instance from the given <paramref name="definition"/> and <paramref name="objectName"/>.
 /// </summary>
 /// <remarks>
 /// This method may be used as a last resort to post-process an object definition before it gets added to the registry.
 /// </remarks>
 protected virtual ObjectDefinitionHolder CreateObjectDefinitionHolder(
     XmlElement element,
     IConfigurableObjectDefinition definition,
     string objectName,
     IReadOnlyList <string> aliases)
 {
     return(new ObjectDefinitionHolder(definition, objectName, aliases));
 }
        /// <summary>
        /// Generates an object name for the given object definition.
        /// </summary>
        /// <param name="definition">The object definition to generate a name for.</param>
        /// <param name="registry">The object definitions registry that the given definition is
        /// supposed to be registerd with</param>
        /// <returns>the generated object name</returns>
        public string GenerateObjectName(IObjectDefinition definition, IObjectDefinitionRegistry registry)
        {
            IConfigurableObjectDefinition objectDef = definition as IConfigurableObjectDefinition;

            if (objectDef == null)
            {
                throw new ArgumentException(
                          "DefaultObjectNameGenerator is only able to handle IConfigurableObjectDefinition subclasses: " +
                          definition);
            }
            return(ObjectDefinitionReaderUtils.GenerateObjectName(objectDef, registry));
        }
Esempio n. 20
0
        /// <see cref="INamespaceParser"/>
        public override IObjectDefinition ParseElement(XmlElement element, ParserContext parserContext)
        {
            string name = element.GetAttribute(ObjectDefinitionConstants.IdAttribute);
            IConfigurableObjectDefinition templateDefinition = ParseTemplateDefinition(element, parserContext);

            if (!StringUtils.HasText(name))
            {
                name = ObjectDefinitionReaderUtils.GenerateObjectName(templateDefinition, parserContext.Registry);
            }
            parserContext.Registry.RegisterObjectDefinition(name, templateDefinition);
            return(null);
        }
Esempio n. 21
0
        public void DoesNotResolveTypeNameToFullTypeInstanceIfAppDomainIsNull()
        {
            DefaultObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory();
            IConfigurableObjectDefinition  definition
                = factory.CreateObjectDefinition(
                      typeof(TestObject).FullName, null, null);

            Assert.IsNotNull(definition, "CreateObjectDefinition with no parent is returning null (it must never do so).");
            Assert.AreEqual(typeof(TestObject).FullName, definition.ObjectTypeName);
            Assert.AreEqual(0, definition.PropertyValues.PropertyValues.Count,
                            "Must not have any property values as none were passed in.");
            Assert.AreEqual(0, definition.ConstructorArgumentValues.ArgumentCount,
                            "Must not have any ctor args as none were passed in.");
        }
Esempio n. 22
0
        public void CreateChildDefinition()
        {
            DefaultObjectDefinitionFactory factory = new DefaultObjectDefinitionFactory();
            IConfigurableObjectDefinition  definition
                = factory.CreateObjectDefinition(
                      typeof(TestObject).FullName, "Aimee Mann", AppDomain.CurrentDomain);

            Assert.IsNotNull(definition, "CreateObjectDefinition with no parent is returning null (it must never do so).");
            Assert.AreEqual(typeof(TestObject), definition.ObjectType);
            Assert.AreEqual(0, definition.PropertyValues.PropertyValues.Count,
                            "Must not have any property values as none were passed in.");
            Assert.AreEqual(0, definition.ConstructorArgumentValues.ArgumentCount,
                            "Must not have any ctor args as none were passed in.");
        }
        /// <summary>
        /// Generates an object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/>.
        /// </summary>
        /// <param name="objectDefinition">The <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/>
        /// that requires a generated name.</param>
        /// <param name="registry">The
        /// <see cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry"/>
        /// that the supplied <paramref name="objectDefinition"/> is to be
        /// registered with (needed so that the uniqueness of any generated
        /// name can be guaranteed).</param>
        /// <param name="isInnerObject">if set to <c>true</c> if the given object
        /// definition will be registed as an inner object or as a top level objener objects
        /// verses top level objects.</param>
        /// <returns>
        /// An object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/> and
        /// never <cref lang="null"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If either of the <paramref name="objectDefinition"/> or
        /// <paramref name="registry"/> arguments is <see langword="null"/>.
        /// </exception>
        /// <exception cref="Spring.Objects.Factory.ObjectDefinitionStoreException">
        /// If a unique name cannot be generated.
        /// </exception>
        public static string GenerateObjectName(
            IConfigurableObjectDefinition objectDefinition, IObjectDefinitionRegistry registry, bool isInnerObject)
        {
            AssertUtils.ArgumentNotNull(objectDefinition, "objectDefinition");
            AssertUtils.ArgumentNotNull(registry, "registry");

            string generatedObjectName = objectDefinition.ObjectTypeName;

            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (objectDefinition is ChildObjectDefinition)
                {
                    generatedObjectName = ((ChildObjectDefinition)objectDefinition).ParentName + "$child";
                }
                else if (objectDefinition.FactoryObjectName != null)
                {
                    generatedObjectName = objectDefinition.FactoryObjectName + "$created";
                }
            }
            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (!isInnerObject)
                {
                    throw new ObjectDefinitionStoreException(
                              objectDefinition.ResourceDescription, String.Empty,
                              "Unnamed object definition specifies neither 'Type' nor 'Parent' " +
                              "nor 'FactoryObject' property values so a unique name cannot be generated.");
                }
                generatedObjectName = "$nested";
            }

            String id = generatedObjectName;

            if (isInnerObject)
            {
                id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + ObjectUtils.GetIdentityHexString(objectDefinition);
            }
            else
            {
                int counter = -1;
                while (counter == -1 || registry.ContainsObjectDefinition(id))
                {
                    counter++;
                    id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + counter;
                }
            }

            return(id);
        }
Esempio n. 24
0
        /// <summary>
        /// Parses the SaoExporter definition.
        /// </summary>
        /// <param name="element">The element to parse.</param>
        /// <param name="name">The name of the object definition.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <returns>SaoExporter object definition.</returns>
        private IConfigurableObjectDefinition ParseSaoExporter(
            XmlElement element, string name, ParserContext parserContext)
        {
            string typeName        = GetTypeName(element);
            string targetName      = element.GetAttribute(SaoExporterConstants.TargetNameAttribute);
            string applicationName = element.GetAttribute(SaoExporterConstants.ApplicationNameAttribute);
            string serviceName     = element.GetAttribute(SaoExporterConstants.ServiceNameAttribute);
            string infinite        = element.GetAttribute(SaoExporterConstants.InfiniteAttribute);

            MutablePropertyValues properties = new MutablePropertyValues();

            if (StringUtils.HasText(targetName))
            {
                properties.Add("TargetName", targetName);
            }
            if (StringUtils.HasText(applicationName))
            {
                properties.Add("ApplicationName", applicationName);
            }
            if (StringUtils.HasText(serviceName))
            {
                properties.Add("ServiceName", serviceName);
            }
            if (StringUtils.HasText(infinite))
            {
                properties.Add("Infinite", infinite);
            }

            foreach (XmlElement child in element.ChildNodes)
            {
                switch (child.LocalName)
                {
                case LifeTimeConstants.LifeTimeElement:
                    ParseLifeTime(properties, child, parserContext);
                    break;

                case InterfacesConstants.InterfacesElement:
                    properties.Add("Interfaces", base.ParseListElement(child, name, parserContext));
                    break;
                }
            }

            IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(
                typeName, null, parserContext.ReaderContext.Reader.Domain);

            cod.PropertyValues = properties;
            return(cod);
        }
        /// <summary>
        /// Creates a generic action based on the specified element.
        /// </summary>
        /// <param name="element">The action definition element.</param>
        /// <param name="parserContext">The parser helper.</param>
        /// <returns>Generic validation action definition.</returns>
        private IObjectDefinition ParseGenericAction(XmlElement element, ParserContext parserContext)
        {
            string typeName = GetAttributeValue(element, ObjectDefinitionConstants.TypeAttribute);
            string when = GetAttributeValue(element, ValidatorDefinitionConstants.WhenAttribute);
            MutablePropertyValues properties = base.ParsePropertyElements("validator:action", element, parserContext);
            if (StringUtils.HasText(when))
            {
                properties.Add("When", when);
            }

            IConfigurableObjectDefinition action =
                parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(typeName, null, parserContext.ReaderContext.Reader.Domain);
            action.PropertyValues = properties;

            return action;
        }
        private IConfigurableObjectDefinition ParseDbProviderConfigurer(XmlElement element, string name, ParserContext parserContext)
        {
            string typeName = GetTypeName(element);
            string resource = GetAttributeValue(element, DbProviderConfigurerConstants.ResourceAttribute);

            MutablePropertyValues propertyValues = new MutablePropertyValues();

            if (StringUtils.HasText(resource))
            {
                propertyValues.Add("ProviderResource", resource);
            }
            IConfigurableObjectDefinition cod = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(
                typeName, null, parserContext.ReaderContext.Reader.Domain);

            cod.PropertyValues = propertyValues;
            return(cod);
        }
Esempio n. 27
0
 private void MethodCall(MethodCallExpression expression, IConfigurableObjectDefinition objectDefinition, int indexer)
 {
     if (expression.Method.DeclaringType.Equals(typeof(IObjectRegistry)))
     {
         if (expression.Arguments.Count == 1)
         {
             objectDefinition.ConstructorArgumentValues.AddIndexedArgumentValue(indexer, new RuntimeObjectReference((string)((ConstantExpression)expression.Arguments[0]).Value));
         }
         else
         {
             objectDefinition.ConstructorArgumentValues.AddIndexedArgumentValue(indexer, new RuntimeObjectReference(expression.Method.ReturnType.FullName));
         }
     }
     else
     {
     }
 }
        /// <summary>
        /// Creates and initialise the object definition that will be registered in your context.
        /// </summary>
        /// <param name="objectDefinitionService">The object definition service.</param>
        /// <returns></returns>
        public IObjectDefinition GetObjectDefinition(IObjectDefinitionService objectDefinitionService)
        {
            IConfigurableObjectDefinition objectDefinition = CreateObjectDefinition(objectDefinitionService);

            foreach (var convention in _conventions)
            {
                if (convention is TypeNameConvention)
                {
                    if (Identifier.Equals(DomainObjectType.FullName))
                    {
                        _identifier = ((TypeNameConvention)convention).GetIdentifierForType(DomainObjectType);
                    }
                }
                else
                {
                    convention.ApplyConvention(_identifier, objectDefinition);
                }
            }

            if (objectDefinition is RootWebObjectDefinition || objectDefinition is ChildWebObjectDefinition)
            {
                ((IWebObjectDefinition)objectDefinition).Scope = _objectScope;
            }
            else
            {
                // not sure if that should really be used here.
                objectDefinition.Scope = _objectScope.ToString();
            }

            foreach (var definitionAction in _objectDefinitionActions)
            {
                definitionAction(objectDefinition, objectDefinitionService);
            }

            // set the defaults or the one specified.
            objectDefinition.DependencyCheck = _dependencyCheckMode;
            objectDefinition.AutowireMode    = _autoWiringMode;

            if (_objectDependencies.Count > 0)
            {
                objectDefinition.DependsOn = _objectDependencies.ToArray();
            }

            return(objectDefinition);
        }
        public IObjectDefinition GetObjectDefinition(IObjectDefinitionService objectDefinitionService)
        {
            if (!objectDefinitionService.Registry.ContainsObjectDefinition(_constructorFactoryIdentifier))
            {
                IConfigurableObjectDefinition constructorDefinition = objectDefinitionService.Factory.CreateObjectDefinition(typeof(ConstructorFactory).FullName, null, AppDomain.CurrentDomain);
                objectDefinitionService.Registry.RegisterObjectDefinition(_constructorFactoryIdentifier, constructorDefinition);
            }

            IConfigurableObjectDefinition objectDefinition = objectDefinitionService.Factory.CreateObjectDefinition(typeof(MethodInvokingFactoryObject).AssemblyQualifiedName, null, AppDomain.CurrentDomain);

            objectDefinition.PropertyValues.Add(new PropertyValue("TargetObject", new RuntimeObjectReference(_constructorFactoryIdentifier)));
            objectDefinition.PropertyValues.Add(new PropertyValue("TargetMethod", string.Format("CreateInstance<{0}>", typeof(T))));
            objectDefinition.PropertyValues.Add(new PropertyValue("Arguments", new ArrayList {
                _objectCreation
            }));
            objectDefinition.PropertyValues.Add(new PropertyValue("IsSingleton", _isSingleton));

            return(objectDefinition);
        }
        /// <summary>
        /// Creates and initialise the object definition that will be registered in your context.
        /// </summary>
        /// <param name="objectDefinitionService">The object definition service.</param>
        /// <returns></returns>
        public IObjectDefinition GetObjectDefinition(IObjectDefinitionService objectDefinitionService)
        {
            if (_interfaceType == null || String.IsNullOrEmpty(_interfaceType.FullName))
            {
                throw new ConfigurationErrorsException(string.Format("You are trying to bind a type to a null interface!"));
            }

            IConfigurableObjectDefinition objectDefinition;
            var conditionalList = new ManagedList();

            if (!objectDefinitionService.Registry.ContainsObjectDefinition(_interfaceType.FullName))
            {
                objectDefinition            = objectDefinitionService.Factory.CreateObjectDefinition(typeof(ConstrainableDuringLoadFactoryObject).AssemblyQualifiedName, null, AppDomain.CurrentDomain);
                objectDefinition.ObjectType = typeof(ConstrainableDuringLoadFactoryObject);
                objectDefinition.PropertyValues.Add("IsSingleton", _isStatic);
                objectDefinition.PropertyValues.Add("ConditionObjectDefinitions", conditionalList);
            }
            else
            {
                objectDefinition = (IConfigurableObjectDefinition)objectDefinitionService.Registry.GetObjectDefinition(_interfaceType.FullName);
                conditionalList  = (ManagedList)objectDefinition.PropertyValues.GetPropertyValue("ConditionObjectDefinitions").Value;
            }

            if (_constraintRegistry.ContainsKey(_interfaceType.FullName))
            {
                foreach (ConditionalObjectDefinition conditionalDefinition in _constraintRegistry[_interfaceType.FullName])
                {
                    IConfigurableObjectDefinition definition = objectDefinitionService.Factory.CreateObjectDefinition(typeof(ConditionalObjectDefinition).AssemblyQualifiedName, null, AppDomain.CurrentDomain);
                    definition.ConstructorArgumentValues.AddIndexedArgumentValue(0, conditionalDefinition.Condition);
                    definition.ConstructorArgumentValues.AddIndexedArgumentValue(1, conditionalDefinition.TypeName);
                    definition.ConstructorArgumentValues.AddIndexedArgumentValue(2, conditionalDefinition.IsDefault);

                    var ro = new RuntimeObjectReference(conditionalDefinition.TypeName);
                    definition.PropertyValues.Add("Instance", ro);

                    conditionalList.Add(definition);
                }
            }

            return(objectDefinition);
        }
Esempio n. 31
0
        private void New(NewExpression body, IConfigurableObjectDefinition objectDefinition)
        {
            int indexer = 0;

            foreach (Expression expression in body.Arguments)
            {
                switch (expression.NodeType)
                {
                case ExpressionType.Call:
                    MethodCall((MethodCallExpression)expression, objectDefinition, indexer);
                    break;

                case ExpressionType.Constant:
                    objectDefinition.ConstructorArgumentValues.AddIndexedArgumentValue(indexer, ((ConstantExpression)expression).Value);
                    break;

                default:
                    break;
                }
                indexer++;
            }
        }
Esempio n. 32
0
        private void MemberInit(MemberInitExpression body, IConfigurableObjectDefinition objectDefinition)
        {
            int indexer = 0;

            foreach (Expression expression in body.NewExpression.Arguments)
            {
                switch (expression.NodeType)
                {
                case ExpressionType.Call:
                    MethodCall((MethodCallExpression)expression, objectDefinition, indexer);
                    break;

                case ExpressionType.Constant:
                    objectDefinition.ConstructorArgumentValues.AddIndexedArgumentValue(indexer, ((ConstantExpression)expression).Value);
                    break;

                default:
                    break;
                }
                indexer++;
            }

            foreach (MemberBinding memberBinding in body.Bindings)
            {
                switch (memberBinding.BindingType)
                {
                case MemberBindingType.Assignment:
                    MemberAssignment(memberBinding.Member.Name, (MemberAssignment)memberBinding, objectDefinition);
                    break;

                case MemberBindingType.ListBinding:
                    break;

                case MemberBindingType.MemberBinding:
                    break;
                }
            }
        }
 /// <summary>
 /// Create an <see cref="ObjectDefinitionHolder"/> instance from the given <paramref name="definition"/> and <paramref name="objectName"/>.
 /// </summary>
 /// <remarks>
 /// This method may be used as a last resort to post-process an object definition before it gets added to the registry.
 /// </remarks>
 protected virtual ObjectDefinitionHolder CreateObjectDefinitionHolder(XmlElement element, IConfigurableObjectDefinition definition, string objectName, IList<string> aliases)
 {
     return new ObjectDefinitionHolder(definition, objectName, aliases);
 }
		/// <summary>
		/// Creates a new instance of the
		/// <see cref="ArgumentNullException"/>
		/// class.
		/// </summary>
		/// <param name="objectDefinition">
		/// The object definition that is the target of the method replacement.
		/// </param>
		/// <param name="objectFactory">
		/// The enclosing IoC container with which the above
		/// <paramref name="objectDefinition"/> is associated.
		/// </param>
		/// <exception cref="DelegatingMethodReplacer">
		/// If either of the supplied arguments is <see langword="null"/>.
		/// </exception>
		public DelegatingMethodReplacer(IConfigurableObjectDefinition objectDefinition, IObjectFactory objectFactory)
			: base(objectDefinition, objectFactory)
		{
		}
 public void ApplyConvention(string identifierName, IConfigurableObjectDefinition objectDefinition)
 {
     throw new NotImplementedException();
 }
Esempio n. 36
0
		/// <summary>
		/// Creates a new instance of the <see cref="LookupMethodReplacer"/>
		/// class.
		/// </summary>
		/// <param name="objectDefinition">
		/// The object definition that is the target of the method replacement.
		/// </param>
		/// <param name="objectFactory">
		/// The enclosing IoC container with which the above
		/// <paramref name="objectDefinition"/> is associated.
		/// </param>
		/// <exception cref="System.ArgumentNullException">
		/// If either of the supplied arguments is <see langword="null"/>.
		/// </exception>
		public LookupMethodReplacer(IConfigurableObjectDefinition objectDefinition, IObjectFactory objectFactory)
			: base(objectDefinition, objectFactory)
		{
		}
 /// <summary>
 /// Wires up any exposed events in the object instance in the given
 /// <see cref="Spring.Objects.IObjectWrapper"/> with any event handler
 /// values from the <paramref name="definition"/>.
 /// </summary>
 /// <param name="name">
 /// The name of the object.
 /// </param>
 /// <param name="definition">
 /// The definition of the named object.
 /// </param>
 /// <param name="wrapper">
 /// The <see cref="Spring.Objects.IObjectWrapper"/> wrapping the target object.
 /// </param>
 protected void WireEvents(string name, IConfigurableObjectDefinition definition, IObjectWrapper wrapper)
 {
     foreach (string eventName in definition.EventHandlerValues.Events)
     {
         foreach (IEventHandlerValue handlerValue
                 in definition.EventHandlerValues[eventName])
         {
             object handler = null;
             if (handlerValue.Source is RuntimeObjectReference)
             {
                 RuntimeObjectReference roref = (RuntimeObjectReference)handlerValue.Source;
                 handler = ResolveReference(definition, name, eventName, roref);
             }
             else if (handlerValue.Source is Type)
             {
                 // a static Type event is being wired up; simply pass on the Type
                 handler = handlerValue.Source;
             }
             else if (handlerValue.Source is string)
             {
                 // a static Type event is being wired up; we need to resolve the Type
                 handler = TypeResolutionUtils.ResolveType(handlerValue.Source as string);
             }
             else
             {
                 throw new FatalObjectException("Currently, only references to other objects and Types are " + "supported as event sources.");
             }
             handlerValue.Wire(handler, wrapper.WrappedInstance);
         }
     }
 }
        ///// <summary>
        ///// Given a property value, return a value, resolving any references to other
        ///// objects in the factory if necessary.
        ///// </summary>
        ///// <remarks>
        ///// <p>
        ///// The value could be :
        ///// <list type="bullet">
        ///// <item>
        ///// <p>
        ///// An <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/>,
        ///// which leads to the creation of a corresponding new object instance.
        ///// Singleton flags and names of such "inner objects" are always ignored: inner objects
        ///// are anonymous prototypes.
        ///// </p>
        ///// </item>
        ///// <item>
        ///// <p>
        ///// A <see cref="Spring.Objects.Factory.Config.RuntimeObjectReference"/>, which must
        ///// be resolved.
        ///// </p>
        ///// </item>
        ///// <item>
        ///// <p>
        ///// An <see cref="Spring.Objects.Factory.Support.IManagedCollection"/>. This is a
        ///// special placeholder collection that may contain
        ///// <see cref="Spring.Objects.Factory.Config.RuntimeObjectReference"/>s or
        ///// collections that will need to be resolved.
        ///// </p>
        ///// </item>
        ///// <item>
        ///// <p>
        ///// An ordinary object or <see langword="null"/>, in which case it's left alone.
        ///// </p>
        ///// </item>
        ///// </list>
        ///// </p>
        ///// </remarks>
        ///// <param name="name">
        ///// The name of the object that is having the value of one of its properties resolved.
        ///// </param>
        ///// <param name="definition">
        ///// The definition of the named object.
        ///// </param>
        ///// <param name="argumentName">
        ///// The name of the property the value of which is being resolved.
        ///// </param>
        ///// <param name="argumentValue">
        ///// The value of the property that is being resolved.
        ///// </param>
//        protected object ResolveValueIfNecessary(string name, RootObjectDefinition definition, string argumentName, object argumentValue)
//        {
//            object resolvedValue = null;
//
//            AssertUtils.ArgumentNotNull(resolvedValue, "test");
//
//            // we must check the argument value to see whether it requires a runtime
//            // reference to another object to be resolved.
//            // if it does, we'll attempt to instantiate the object and set the reference.
//            if (RemotingServices.IsTransparentProxy(argumentValue))
//            {
//                resolvedValue = argumentValue;
//            }
//            else if (argumentValue is ObjectDefinitionHolder)
//            {
//                // contains an IObjectDefinition with name and aliases...
//                ObjectDefinitionHolder holder = (ObjectDefinitionHolder)argumentValue;
//                resolvedValue = ResolveInnerObjectDefinition(name, holder.ObjectName, argumentName, holder.ObjectDefinition, definition.IsSingleton);
//            }
//            else if (argumentValue is IObjectDefinition)
//            {
//                // resolve plain IObjectDefinition, without contained name: use dummy name... 
//                IObjectDefinition def = (IObjectDefinition)argumentValue;
//                resolvedValue = ResolveInnerObjectDefinition(name, "(inner object)", argumentName, def, definition.IsSingleton);
//
//            }
//            else if (argumentValue is RuntimeObjectReference)
//            {
//                RuntimeObjectReference roref = (RuntimeObjectReference)argumentValue;
//                resolvedValue = ResolveReference(definition, name, argumentName, roref);
//            }
//            else if (argumentValue is ExpressionHolder)
//            {
//                ExpressionHolder expHolder = (ExpressionHolder)argumentValue;
//                object context = null;
//                IDictionary variables = null;
//
//                if (expHolder.Properties != null)
//                {
//                    PropertyValue contextProperty = expHolder.Properties.GetPropertyValue("Context");
//                    context = contextProperty == null
//                                         ? null
//                                         : ResolveValueIfNecessary2(name, definition, "Context",
//                                                                   contextProperty.Value);
//                    PropertyValue variablesProperty = expHolder.Properties.GetPropertyValue("Variables");
//                    object vars = (variablesProperty == null
//                                                   ? null
//                                                   : ResolveValueIfNecessary2(name, definition, "Variables",
//                                                                             variablesProperty.Value));
//                    if (vars is IDictionary)
//                    {
//                        variables = (IDictionary)vars;
//                    }
//                    else
//                    {
//                        if (vars != null) throw new ArgumentException("'Variables' must resolve to an IDictionary");
//                    }
//                }
//
//                if (variables == null) variables = CollectionsUtil.CreateCaseInsensitiveHashtable();
//                // add 'this' objectfactory reference to variables
//                variables.Add(Expression.ReservedVariableNames.CurrentObjectFactory, this);
//
//                resolvedValue = expHolder.Expression.GetValue(context, variables);
//            }
//            else if (argumentValue is IManagedCollection)
//            {
//                resolvedValue =
//                        ((IManagedCollection)argumentValue).Resolve(name, definition, argumentName,
//                                                                     new ManagedCollectionElementResolver(ResolveValueIfNecessary2));
//            }
//            else if (argumentValue is TypedStringValue)
//            {
//                TypedStringValue tsv = (TypedStringValue)argumentValue;
//                try
//                {
//                    Type resolvedTargetType = ResolveTargetType(tsv);
//                    if (resolvedTargetType != null)
//                    {
//                        resolvedValue = TypeConversionUtils.ConvertValueIfNecessary(tsv.TargetType, tsv.Value, null);
//                    }
//                    else
//                    {
//                        resolvedValue = tsv.Value;
//                    }
//                }
//                catch (Exception ex)
//                {
//                    throw new ObjectCreationException(definition.ResourceDescription, name,
//                                                      "Error converted typed String value for " + argumentName, ex);
//                }
//
//            }
//            else
//            {
//                // no need to resolve value...
//                resolvedValue = argumentValue;
//            }
//            return resolvedValue;
//        }

        ///// <summary>
        ///// Resolve the target type of the passed <see cref="TypedStringValue"/>.
        ///// </summary>
        ///// <param name="value">The <see cref="TypedStringValue"/> who's target type is to be resolved</param>
        ///// <returns>The resolved target type, if any. <see lang="null" /> otherwise.</returns>
//        protected virtual Type ResolveTargetType(TypedStringValue value)
//        {
//            if (value.HasTargetType)
//            {
//                return value.TargetType;
//            }
//            else
//            {
//                return null;
//            }
//        }

        ///// <summary>
        ///// Resolves an inner object definition.
        ///// </summary>
        ///// <param name="name">
        ///// The name of the object that surrounds this inner object definition.
        ///// </param>
        ///// <param name="innerObjectName">
        ///// The name of the inner object definition... note: this is a synthetic
        ///// name assigned by the factory (since it makes no sense for inner object
        ///// definitions to have names).
        ///// </param>
        ///// <param name="argumentName">
        ///// The name of the property the value of which is being resolved.
        ///// </param>
        ///// <param name="definition">
        ///// The definition of the inner object that is to be resolved.
        ///// </param>
        ///// <param name="singletonOwner">
        ///// <see langword="true"/> if the owner of the property is a singleton.
        ///// </param>
        ///// <returns>
        ///// The resolved object as defined by the inner object definition.
        ///// </returns>
//        protected object ResolveInnerObjectDefinition(string name, string innerObjectName, string argumentName, IObjectDefinition definition,
//                                                      bool singletonOwner)
//        {
//            RootObjectDefinition mod = GetMergedObjectDefinition(innerObjectName, definition);
//            mod.IsSingleton = singletonOwner;
//            object instance;
//            object result;
//            try
//            {
//                instance = InstantiateObject(innerObjectName, mod, ObjectUtils.EmptyObjects, false, false);
//                result = GetObjectForInstance(innerObjectName, instance);
//            }
//            catch (ObjectsException ex)
//            {
//                throw ObjectCreationException.GetObjectCreationException(ex, name, argumentName, definition.ResourceDescription, innerObjectName);
//            }
//            if (singletonOwner && instance is IDisposable)
//            {
//                // keep a reference to the inner object instance, to be able to destroy
//                // it on factory shutdown...
//                DisposableInnerObjects.Add(instance);
//            }
//            return result;
//        }

        /// <summary>
        /// Resolve a reference to another object in the factory.
        /// </summary>
        /// <param name="name">
        /// The name of the object that is having the value of one of its properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named object.
        /// </param>
        /// <param name="argumentName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="reference">
        /// The runtime reference containing the value of the property.
        /// </param>
        /// <returns>A reference to another object in the factory.</returns>
        protected object ResolveReference(IConfigurableObjectDefinition definition, string name, string argumentName, RuntimeObjectReference reference)
        {
            #region Instrumentation

            if (log.IsDebugEnabled)
            {
                log.Debug(
                        string.Format(CultureInfo.InvariantCulture, "Resolving reference from property '{0}' in object '{1}' to object '{2}'.",
                                      argumentName, name, reference.ObjectName));
            }

            #endregion

            try
            {
                if (reference.IsToParent)
                {
                    if (null == ParentObjectFactory)
                    {
                        throw new ObjectCreationException(definition.ResourceDescription, name,
                                                          string.Format(
                                                                  "Can't resolve reference to '{0}' in parent factory: " + "no parent factory available.",
                                                                  reference.ObjectName));
                    }
                    return ParentObjectFactory.GetObject(reference.ObjectName);
                }
                return GetObject(reference.ObjectName);
            }
            catch (ObjectsException ex)
            {
                throw ObjectCreationException.GetObjectCreationException(ex, name, argumentName, definition.ResourceDescription, reference.ObjectName);
            }
        }
        /// <summary>
        /// Give an object a chance to react now all its properties are set,
        /// and a chance to know about its owning object factory (this object).
        /// </summary>
        /// <remarks>
        /// <p>
        /// This means checking whether the object implements
        /// <see cref="Spring.Objects.Factory.IInitializingObject"/> and  / or
        /// <see cref="Spring.Objects.Factory.IObjectFactoryAware"/>, and invoking the
        /// necessary callback(s) if it does.
        /// </p>
        /// <p>
        /// Custom init methods are resolved in a <b>case-insensitive</b> manner.
        /// </p>
        /// </remarks>
        /// <param name="target">
        /// The new object instance we may need to initialise.
        /// </param>
        /// <param name="name">
        /// The name the object has in the factory. Used for logging output.
        /// </param>
        /// <param name="definition">
        /// The definition of the target object instance.
        /// </param>
        protected virtual void InvokeInitMethods(object target, string name, IConfigurableObjectDefinition definition)
        {
            if (ObjectUtils.IsAssignableAndNotTransparentProxy(typeof(IInitializingObject), target))
            {
                #region Instrumentation

                if (log.IsDebugEnabled)
                {
                    log.Debug(string.Format(CultureInfo.InvariantCulture, "Calling AfterPropertiesSet() on object with name '{0}'.", name));
                }

                #endregion

                ((IInitializingObject)target).AfterPropertiesSet();
            }
            if (StringUtils.HasText(definition.InitMethodName))
            {
                #region Instrumentation

                if (log.IsDebugEnabled)
                {
                    log.Debug(
                            string.Format(CultureInfo.InvariantCulture, "Calling custom init method '{0} on object with name '{1}'.",
                                          definition.InitMethodName, name));
                }

                #endregion

                try
                {
                    MethodInfo targetMethod = target.GetType().GetMethod(definition.InitMethodName, MethodResolutionFlags, null, Type.EmptyTypes, null);
                    if (targetMethod == null)
                    {
                        throw new ObjectCreationException(definition.ResourceDescription, name,
                                                          "Could not find the named initialization method '" + definition.InitMethodName + "'.");
                    }
                    targetMethod.Invoke(target, ObjectUtils.EmptyObjects);
                }
                catch (TargetInvocationException ex)
                {
                    throw new ObjectCreationException(definition.ResourceDescription, name,
                                                      "Initialization method '" + definition.InitMethodName + "' threw exception", ex.GetBaseException());
                }
                catch (Exception ex)
                {
                    throw new ObjectCreationException(definition.ResourceDescription, name,
                                                      "Invocation of initialization method '" + definition.InitMethodName + "' failed", ex);
                }
            }
        }
        private void CheckDependencies(string name, IConfigurableObjectDefinition definition, PropertyInfo[] filteredPropInfo, IPropertyValues properties)
        {
            DependencyCheckingMode dependencyCheck = definition.DependencyCheck;
            PropertyInfo[] unsatisfiedDependencies = AutowireUtils.GetUnsatisfiedDependencies(filteredPropInfo, properties, dependencyCheck);

            if (unsatisfiedDependencies.Length > 0)
            {
                throw new UnsatisfiedDependencyException(definition.ResourceDescription, name, unsatisfiedDependencies[0].Name,
                    "Set this property value or disable dependency checking for this object.");                
            }
        }
        /// <summary>
        /// Perform a dependency check that all properties exposed have been set, if desired.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Dependency checks can be objects (collaborating objects), simple (primitives
        /// and <see cref="System.String"/>), or all (both).
        /// </p>
        /// </remarks>
        /// <param name="name">
        /// The name of the object.
        /// </param>
        /// <param name="definition">
        /// The definition of the named object.
        /// </param>
        /// <param name="wrapper">
        /// The <see cref="Spring.Objects.IObjectWrapper"/> wrapping the target object.
        /// </param>
        /// <param name="properties">
        /// The property values to be checked.
        /// </param>
        /// <exception cref="Spring.Objects.Factory.UnsatisfiedDependencyException">
        /// If all of the checked dependencies were not satisfied.
        /// </exception>
        protected void DependencyCheck(string name, IConfigurableObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties)
        {
            DependencyCheckingMode dependencyCheck = definition.DependencyCheck;
            if (dependencyCheck == DependencyCheckingMode.None)
            {
                return;
            }

            PropertyInfo[] filteredPropInfo = FilterPropertyInfoForDependencyCheck(wrapper);
            if (HasInstantiationAwareBeanPostProcessors)
            {
                foreach (IObjectPostProcessor processor in ObjectPostProcessors)
                {
                    IInstantiationAwareObjectPostProcessor inProc = processor as IInstantiationAwareObjectPostProcessor;
                    if (inProc != null)
                    {
                        properties =
                            inProc.PostProcessPropertyValues(properties, filteredPropInfo, wrapper.WrappedInstance, name);
                        if (properties == null)
                        {
                            return;
                        }
                    }
                }
            }


            CheckDependencies(name, definition, filteredPropInfo, properties);
        }
        /// <summary>
        /// Generates an object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/>.
        /// </summary>
        /// <param name="objectDefinition">The <see cref="Spring.Objects.Factory.Config.IObjectDefinition"/>
        /// that requires a generated name.</param>
        /// <param name="registry">The
        /// <see cref="Spring.Objects.Factory.Support.IObjectDefinitionRegistry"/>
        /// that the supplied <paramref name="objectDefinition"/> is to be
        /// registered with (needed so that the uniqueness of any generated
        /// name can be guaranteed).</param>
        /// <param name="isInnerObject">if set to <c>true</c> if the given object
        /// definition will be registed as an inner object or as a top level objener objects
        /// verses top level objects.</param>
        /// <returns>
        /// An object definition name for the supplied
        /// <paramref name="objectDefinition"/> that is guaranteed to be unique
        /// within the scope of the supplied <paramref name="registry"/> and
        /// never <cref lang="null"/>.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        /// If either of the <paramref name="objectDefinition"/> or
        /// <paramref name="registry"/> arguments is <see langword="null"/>.
        /// </exception>
        /// <exception cref="Spring.Objects.Factory.ObjectDefinitionStoreException">
        /// If a unique name cannot be generated.
        /// </exception>
        public static string GenerateObjectName(
            IConfigurableObjectDefinition objectDefinition, IObjectDefinitionRegistry registry, bool isInnerObject)
        {
            AssertUtils.ArgumentNotNull(objectDefinition, "objectDefinition");
            AssertUtils.ArgumentNotNull(registry, "registry");

            string generatedObjectName = objectDefinition.ObjectTypeName;
            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (objectDefinition is ChildObjectDefinition)
                {
                    generatedObjectName = ((ChildObjectDefinition)objectDefinition).ParentName + "$child";
                }
                else if (objectDefinition.FactoryObjectName != null)
                {
                    generatedObjectName = objectDefinition.FactoryObjectName + "$created";
                }
            }
            if (StringUtils.IsNullOrEmpty(generatedObjectName))
            {
                if (!isInnerObject)
                {
                    throw new ObjectDefinitionStoreException(
                        objectDefinition.ResourceDescription, String.Empty,
                        "Unnamed object definition specifies neither 'Type' nor 'Parent' " +
                        "nor 'FactoryObject' property values so a unique name cannot be generated.");
                }
                generatedObjectName = "$nested";
            }

            String id = generatedObjectName;
            if (isInnerObject)
            {
                id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + ObjectUtils.GetIdentityHexString(objectDefinition);
            }
            else
            {
                int counter = -1;
                while (counter == -1 || registry.ContainsObjectDefinition(id))
                {
                    counter++;
                    id = generatedObjectName + GENERATED_OBJECT_NAME_SEPARATOR + counter;
                }
            }

            return id;
        }
 /// <summary>
 /// Generates the name of the object for a top-level object definition unique within the given object factory.
 /// </summary>
 /// <param name="definition">The object definition to generate an object name for.</param>
 /// <param name="registry">The registry to check for existing names.</param>
 /// <returns>The generated object name</returns>
 /// <exception cref="ObjectDefinitionStoreException">if no unique name can be generated for the given
 /// object definition</exception>
 public static string GenerateObjectName(IConfigurableObjectDefinition definition, IObjectDefinitionRegistry registry)
 {
     return GenerateObjectName(definition, registry, false);
 }
 private static void RegisterPostProcessor(IObjectDefinitionRegistry registry, IConfigurableObjectDefinition objectDefinition, string objectName)
 {
     objectDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
     registry.RegisterObjectDefinition(objectName, objectDefinition);
 }