Inheritance: ArrayList, IManagedCollection, IMergable
 public void MergeWithNonCompatibleParentType()
 {
     ManagedList child = new ManagedList();
     child.Add("one");
     child.MergeEnabled = true;
     Assert.Throws<InvalidOperationException>(() => child.Merge("hello"));
 }
 public void MergeWithNullParent()
 {
     ManagedList child = new ManagedList();
     child.Add("one");
     child.MergeEnabled = true;
     Assert.AreSame(child, child.Merge(null));
 }
        public ManagedList ParseInterceptors(XmlElement element, ParserContext parserContext)
        {
            ManagedList interceptors = new ManagedList();
            foreach(XmlNode child in element.ChildNodes) {

            /* TODO:
             * check full elementname (incl. NamespaceUri)
            */
            if (child.NodeType == XmlNodeType.Element) {
                XmlElement childElement = (XmlElement) child;
                string localName = child.LocalName;
                if ("object".Equals(localName)) {
                    ObjectDefinitionHolder holder = parserContext.ParserHelper.ParseObjectDefinitionElement(childElement);
                    interceptors.Add(holder);
                }
                else if ("ref".Equals(localName)) {
                    string reference = childElement.GetAttribute("object");
                    interceptors.Add(new RuntimeObjectReference(reference));
                }
                else {
                    if (!parsers.ContainsKey(localName)) {
                        parserContext.ReaderContext.ReportException(childElement, localName, "unsupported interceptor element");
                    }
                    IObjectDefinitionRegisteringParser parser = parsers[localName];
                    string interceptorObjectName = parser.Parse(childElement, parserContext);
                    interceptors.Add(new RuntimeObjectReference(interceptorObjectName));
                }
            }
            }
            return interceptors;
        }
        /// <summary>
        /// Merges the current value set with that of the supplied object.
        /// </summary>
        /// <remarks>The supplied object is considered the parent, and values in the
        /// callee's value set must override those of the supplied object.
        /// </remarks>
        /// <param name="parent">The parent object to merge with</param>
        /// <returns>The result of the merge operation</returns>
        /// <exception cref="ArgumentNullException">If the supplied parent is <code>null</code></exception>
        /// <exception cref="InvalidOperationException">If merging is not enabled for this instance,
        /// (i.e. <code>MergeEnabled</code> equals <code>false</code>.</exception>
        public object Merge(object parent)
        {
            if (!this.mergeEnabled)
            {
                throw new InvalidOperationException(
                          "Not allowed to merge when the 'MergeEnabled' property is set to 'false'");
            }
            if (parent == null)
            {
                return(this);
            }
            IList plist = parent as IList;

            if (plist == null)
            {
                throw new InvalidOperationException("Cannot merge with object of type [" + parent.GetType() + "]");
            }
            IList merged = new ManagedList();

            foreach (object element in plist)
            {
                merged.Add(element);
            }
            foreach (object o in this)
            {
                merged.Add(o);
            }
            return(merged);
        }
        protected override void DoParse(XmlElement element, ObjectDefinitionBuilder builder)
        {
            base.DoParse(element, builder);
            ParseSimpleProperties(element, builder);

            XmlNodeList subElements = element.ChildNodes;
            ManagedList locators = new ManagedList(subElements.Count);
            ManagedList servers = new ManagedList(subElements.Count);
            for (int i = 0; i < subElements.Count; i++) {
                XmlNode subElement = subElements.Item(i);
                if (subElement != null && subElement.NodeType == XmlNodeType.Element)
                {
                    if ("locator".Equals(subElement.LocalName))
                    {
                        locators.Add(ParseLocator((XmlElement)subElement));
                    }
                    if ("server".Equals(subElement.LocalName))
                    {
                        servers.Add(ParseServer((XmlElement)subElement));
                    }
                }
            }

            if (locators.Count > 0)
            {
                builder.AddPropertyValue("Locators", locators);
            }
            if (servers.Count > 0)
            {
                builder.AddPropertyValue("Servers", servers);
            }
        }
        protected override AbstractObjectDefinition ParseInternal(XmlElement element, ParserContext parserContext)
        {
            ObjectDefinitionBuilder builder = BuildObjectDefinition(element, parserContext);
            ManagedList interceptors = null;
            XmlElement interceptorsElement = DomUtils.GetChildElementByTagName(element, "interceptors");

            if(interceptorsElement != null) {
                ChannelInterceptorParser interceptorParser = new ChannelInterceptorParser();
                interceptors = interceptorParser.ParseInterceptors(interceptorsElement, new ParserContext(parserContext.ParserHelper, builder.RawObjectDefinition));
            }
            if(interceptors == null) {
                interceptors = new ManagedList();
            }

            string datatypeAttr = element.GetAttribute("datatype");
            if(StringUtils.HasText(datatypeAttr)) {
                string[] datatypes = StringUtils.CommaDelimitedListToStringArray(datatypeAttr);
                RootObjectDefinition selectorDef = new RootObjectDefinition();
                selectorDef.ObjectTypeName = IntegrationNamespaceUtils.SELECTOR_PACKAGE + ".PayloadTypeSelector";
                selectorDef.ConstructorArgumentValues.AddGenericArgumentValue(datatypes);
                string selectorObjectName = parserContext.ReaderContext.RegisterWithGeneratedName(selectorDef);

                RootObjectDefinition interceptorDef = new RootObjectDefinition();
                interceptorDef.ObjectTypeName = IntegrationNamespaceUtils.CHANNEL_INTERCEPTOR_PACKAGE + ".MessageSelectingInterceptor";
                interceptorDef.ConstructorArgumentValues.AddGenericArgumentValue(new RuntimeObjectReference(selectorObjectName));
                string interceptorObjectName = parserContext.ReaderContext.RegisterWithGeneratedName(interceptorDef);

                interceptors.Add(new RuntimeObjectReference(interceptorObjectName));
            }

            builder.AddPropertyValue("interceptors", interceptors);
            return builder.ObjectDefinition;
        }
 public void MergeWithNonCompatibleParentType()
 {
     ManagedList child = new ManagedList();
     child.Add("one");
     child.MergeEnabled = true;
     child.Merge("hello");
 }
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            base.DoParse(element, builder);

            //TODO investigate setting of scope on client cache
            //builder.AddPropertyValue("Scope", "some value");

            //TODO check if .NET client has any 'data policy' settings.

            ParsingUtils.SetPropertyValue(element, builder, "name", "name");
            ParsingUtils.SetPropertyValue(element, builder, "pool-name", "poolName");

            String cacheRef = element.GetAttribute("cache-ref");
            // add cache reference (fallback to default if nothing is specified)
            builder.AddPropertyReference("cache", (StringUtils.HasText(cacheRef) ? cacheRef : "gemfire-cache"));

            // client region attributes
            String regionAttributesRef = element.GetAttribute("attributes-ref");
            if (StringUtils.HasText(regionAttributesRef))
            {
                ObjectDefinitionBuilder attrBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof(RegionAttributesFactoryObject));
                builder.AddPropertyReference("attributes", regionAttributesRef);
            }

            ManagedList interests = new ManagedList();
            XmlNodeList subElements = element.ChildNodes;
            for (int i = 0; i < subElements.Count; i++)
            {
                XmlNode subElement = subElements.Item(i);
                if (subElement.NodeType == XmlNodeType.Element)
                {
                    string name = subElement.LocalName;
                    if ("cache-listener".Equals(name))
                    {
                        builder.AddPropertyValue("cacheListeners", ParseCacheListener(parserContext, (XmlElement)subElement, builder));
                    }
                    else if ("regex-interest".Equals(name))
                    {
                        interests.Add(ParseRegexInterest(parserContext, (XmlElement)subElement));
                    }
                    else if ("key-interest".Equals(name))
                    {
                        interests.Add(ParseKeyInterest(parserContext, (XmlElement)subElement));
                    }
                    else if ("all-keys-interest".Equals(name))
                    {
                        interests.Add(ParseAllKeysInterest(parserContext, (XmlElement) subElement));
                    }

                }
            }

            if (subElements.Count > 0)
            {
                builder.AddPropertyValue("interests", interests);
            }
        }
 public void MergeEmptyChild()
 {
     ManagedList parent = new ManagedList();
     parent.Add("one");
     parent.Add("two");
     ManagedList child = new ManagedList();
     child.MergeEnabled = true;
     IList mergedList = (IList) child.Merge(parent);
     Assert.AreEqual(2, mergedList.Count);
 }
 public void MergeChildValueOverrideTheParents()
 {
     //doesn't make much sense in the context of a list...
     ManagedList parent = new ManagedList();
     parent.Add("one");
     parent.Add("two");
     ManagedList child = new ManagedList();
     child.Add("one");
     child.MergeEnabled = true;
     IList mergedList = (IList) child.Merge(parent);
     Assert.AreEqual(3, mergedList.Count);
 }
 protected override void VisitEnumerableParameterValue(ContainerResolvedEnumerableParameter parameterValue)
 {
    string typeName = parameterValue.ElementType.Name;
    ManagedList listVal = new ManagedList();
    listVal.ElementTypeName = parameterValue.ElementType.AssemblyQualifiedName;
    foreach (string name in parameterValue.Names)
    {
       listVal.Add(new RuntimeObjectReference(String.Concat(name,".",typeName)));
    }
    InjectionParameter = listVal;
    
 }
 protected override ObjectDefinitionBuilder ParseHandler(XmlElement element, ParserContext parserContext)
 {
     ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.GenericObjectDefinition(IntegrationNamespaceUtils.HANDLER_PACKAGE + ".MessageHandlerChain");
     ManagedList handlerList = new ManagedList();
     handlerList.ElementTypeName = typeof (IMessageHandler).FullName;
     XmlNodeList children = element.ChildNodes;
     for(int i = 0; i < children.Count; i++) {
         XmlNode child = children.Item(i);
         if(child.NodeType == XmlNodeType.Element && !"poller".Equals(child.LocalName)) {
             string childBeanName = ParseChild((XmlElement)child, parserContext, builder.ObjectDefinition);
             handlerList.Add(new RuntimeObjectReference(childBeanName));
         }
     }
     builder.AddPropertyValue("handlers", handlerList);
     return builder;
 }
Exemple #13
0
        public void VisitManagedList()
        {
            IObjectDefinition od = new RootObjectDefinition();
            ManagedList       ml = new ManagedList();

            ml.ElementTypeName = "$Property";
            ml.Add("$Property");
            od.PropertyValues.Add("PropertyName", ml);

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));

            odv.VisitObjectDefinition(od);

            ManagedList list = od.PropertyValues.GetPropertyValue("PropertyName").Value as ManagedList;

            Assert.IsNotNull(list, "Property value is not of type ManagedList.  Type = [" +
                             od.PropertyValues.GetPropertyValue("PropertyName").Value.GetType() + "]");
            Assert.AreEqual("Value", list.ElementTypeName);
            Assert.AreEqual("Value", list[0]);
        }
        /// <summary>
        /// Visits the ManagedList property ElementTypeName and
        /// calls <see cref="ResolveValue"/> for list element.
        /// </summary>
        protected virtual void VisitManagedList(ManagedList listVal)
        {
            string elementTypeName = listVal.ElementTypeName;

            if (elementTypeName != null)
            {
                string resolvedName = ResolveStringValue(elementTypeName);
                if (!elementTypeName.Equals(resolvedName))
                {
                    listVal.ElementTypeName = resolvedName;
                }
            }

            for (int i = 0; i < listVal.Count; ++i)
            {
                object oldValue = listVal[i];
                object newValue = ResolveValue(oldValue);
                if (!ObjectUtils.NullSafeEquals(newValue, oldValue))
                {
                    listVal[i] = newValue;
                }
            }
        }
 private void ParseSelectorChain(ObjectDefinitionBuilder builder, XmlElement element, ParserContext parserContext)
 {
     IntegrationNamespaceUtils.SetValueIfAttributeDefined(builder, element, "voting-strategy");
     ManagedList selectors = new ManagedList();
     selectors.ElementTypeName = typeof (IMessageSelector).FullName;
     XmlNodeList childNodes = element.ChildNodes;
     for(int i = 0; i < childNodes.Count; i++) {
         XmlNode child = childNodes.Item(i);
         if(child.NodeType == XmlNodeType.Element) {
             string nodeName = child.LocalName;
             if("selector".Equals(nodeName)) {
                 string refatr = ((XmlElement)child).GetAttribute("ref");
                 selectors.Add(new RuntimeObjectReference(refatr));
             }
             else if("selector-chain".Equals(nodeName)) {
                 ObjectDefinitionBuilder nestedBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(GetObjectTypeName(null));
                 ParseSelectorChain(nestedBuilder, (XmlElement)child, parserContext);
                 string nestedBeanName = parserContext.ReaderContext.RegisterWithGeneratedName(nestedBuilder.ObjectDefinition);
                 selectors.Add(new RuntimeObjectReference(nestedBeanName));
             }
         }
     }
     builder.AddPropertyValue("selectors", selectors);
 }
        public void VisitManagedList()
        {
            IObjectDefinition od = new RootObjectDefinition();
            ManagedList ml = new ManagedList();
            ml.ElementTypeName = "$Property";
            ml.Add("$Property");
            od.PropertyValues.Add("PropertyName", ml);

            ObjectDefinitionVisitor odv = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(ParseAndResolveVariables));
            odv.VisitObjectDefinition(od);

            ManagedList list = od.PropertyValues.GetPropertyValue("PropertyName").Value as ManagedList;

            Assert.IsNotNull(list, "Property value is not of type ManagedList.  Type = [" +
                od.PropertyValues.GetPropertyValue("PropertyName").Value.GetType() + "]");
            Assert.AreEqual("Value", list.ElementTypeName);
            Assert.AreEqual("Value", list[0]);
        }
Exemple #17
0
 /// <summary>
 /// Merges the current value set with that of the supplied object.
 /// </summary>
 /// <remarks>The supplied object is considered the parent, and values in the 
 /// callee's value set must override those of the supplied object.
 /// </remarks>
 /// <param name="parent">The parent object to merge with</param>
 /// <returns>The result of the merge operation</returns>
 /// <exception cref="ArgumentNullException">If the supplied parent is <code>null</code></exception>
 /// <exception cref="InvalidOperationException">If merging is not enabled for this instance,
 /// (i.e. <code>MergeEnabled</code> equals <code>false</code>.</exception>
 public object Merge(object parent)
 {
     if (!this.mergeEnabled)
     {
         throw new InvalidOperationException(
             "Not allowed to merge when the 'MergeEnabled' property is set to 'false'");
     }
     if (parent == null)
     {
         return this;
     }
     IList plist = parent as IList;
     if (plist == null)
     {
         throw new InvalidOperationException("Cannot merge with object of type [" + parent.GetType() + "]");
     }
     IList merged = new ManagedList();
     foreach (object element in plist)
     {
         merged.Add(element);
     }
     foreach (object o in this)
     {
         merged.Add(o);
     }
     return merged;
 }
        public static object ParseRefOrNestedObjectDeclaration(ParserContext parserContext, XmlElement element,
            ObjectDefinitionBuilder builder, string refAttrName)
        {
            String attr = element.GetAttribute(refAttrName);
            bool hasRef = StringUtils.HasText(attr);

            XmlNodeList childNodes = element.ChildNodes;
            if (hasRef)
            {
                if (childNodes.Count > 0)
                {
                    //"either use the '" + refAttrName + "' attribute or a nested object declaration for '"
                    //+ element.getLocalName() + "' element, but not both", element);
                    parserContext.ReaderContext.ReportException(element, element.LocalName,
                                                                "either use the '" + refAttrName +
                                                                "' attribute or a nested object declaration for '"
                                                                + element.LocalName + "' element, but not both");
                }
                return new RuntimeObjectReference(attr);
            }

            if (childNodes.Count == 0)
            {
                parserContext.ReaderContext.ReportException(element, element.LocalName,
                                                            "specify either '" + refAttrName +
                                                            "' attribute or a nested object declaration for '"
                                                            + element.LocalName + "' element");
            }
            // nested parse nested object definition
            if (childNodes.Count == 1)
            {
                if (childNodes[0].NodeType == XmlNodeType.Element)
                {
                    XmlElement childElement = (XmlElement) childNodes[0];
                    return ParsePropertySubElement(childElement, builder.RawObjectDefinition, parserContext);
                }
            }

            ManagedList list = new ManagedList();

            for (int i = 0; i < childNodes.Count; i++)
            {
                XmlNode childNode = childNodes.Item(i);
                if (childNode != null && childNode.NodeType == XmlNodeType.Element)
                {
                    list.Add(ParsePropertySubElement((XmlElement) childNode, builder.RawObjectDefinition, parserContext));
                }
            }

            return list;
        }
        private void ParseListener(XmlElement listenerEle, XmlElement containerEle, ParserContext parserContext)
        {
            var listenerDef = new RootObjectDefinition();

            // listenerDef.setSource(parserContext.extractSource(listenerEle));
            var aRef = listenerEle.GetAttribute(REF_ATTRIBUTE);
            if (string.IsNullOrWhiteSpace(aRef))
            {
                parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'ref' attribute contains empty value.");
            }
            else
            {
                listenerDef.PropertyValues.Add("HandlerObject", new RuntimeObjectReference(aRef));
            }

            string method = null;
            if (listenerEle.HasAttribute(METHOD_ATTRIBUTE))
            {
                method = listenerEle.GetAttribute(METHOD_ATTRIBUTE);
                if (string.IsNullOrWhiteSpace(method))
                {
                    parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'method' attribute contains empty value.");
                }
            }

            listenerDef.PropertyValues.Add("DefaultListenerMethod", method);

            if (containerEle.HasAttribute(MESSAGE_CONVERTER_ATTRIBUTE))
            {
                var messageConverter = containerEle.GetAttribute(MESSAGE_CONVERTER_ATTRIBUTE);
                if (string.IsNullOrWhiteSpace(messageConverter))
                {
                    parserContext.ReaderContext.ReportFatalException(containerEle, "Listener container 'message-converter' attribute contains empty value.");
                }
                else
                {
                    listenerDef.PropertyValues.Add("MessageConverter", new RuntimeObjectReference(messageConverter));
                }
            }

            var containerDef = RabbitNamespaceUtils.ParseContainer(containerEle, parserContext);

            if (listenerEle.HasAttribute(RESPONSE_EXCHANGE_ATTRIBUTE))
            {
                var responseExchange = listenerEle.GetAttribute(RESPONSE_EXCHANGE_ATTRIBUTE);
                listenerDef.PropertyValues.Add("ResponseExchange", responseExchange);
            }

            if (listenerEle.HasAttribute(RESPONSE_ROUTING_KEY_ATTRIBUTE))
            {
                var responseRoutingKey = listenerEle.GetAttribute(RESPONSE_ROUTING_KEY_ATTRIBUTE);
                listenerDef.PropertyValues.Add("ResponseRoutingKey", responseRoutingKey);
            }

            listenerDef.ObjectTypeName = "Spring.Messaging.Amqp.Rabbit.Listener.Adapter.MessageListenerAdapter";
            containerDef.PropertyValues.Add("MessageListener", listenerDef);

            var containerObjectName = containerEle.GetAttribute(ID_ATTRIBUTE);

            // If no object id is given auto generate one using the ReaderContext's ObjectNameGenerator
            if (string.IsNullOrWhiteSpace(containerObjectName))
            {
                containerObjectName = parserContext.ReaderContext.GenerateObjectName(containerDef);
            }

            if (!NamespaceUtils.IsAttributeDefined(listenerEle, QUEUE_NAMES_ATTRIBUTE) && !NamespaceUtils.IsAttributeDefined(listenerEle, QUEUES_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'queue-names' or 'queues' attribute must be provided.");
            }

            if (NamespaceUtils.IsAttributeDefined(listenerEle, QUEUE_NAMES_ATTRIBUTE) && NamespaceUtils.IsAttributeDefined(listenerEle, QUEUES_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(listenerEle, "Listener 'queue-names' or 'queues' attribute must be provided but not both.");
            }

            var queueNames = listenerEle.GetAttribute(QUEUE_NAMES_ATTRIBUTE);
            if (!string.IsNullOrWhiteSpace(queueNames))
            {
                var names = StringUtils.CommaDelimitedListToStringArray(queueNames);
                var values = new ManagedList();
                foreach (var name in names)
                {
                    values.Add(new TypedStringValue(name.Trim()));
                }

                containerDef.PropertyValues.Add("QueueNames", values);
            }

            var queues = listenerEle.GetAttribute(QUEUES_ATTRIBUTE);
            if (!string.IsNullOrWhiteSpace(queues))
            {
                var names = StringUtils.CommaDelimitedListToStringArray(queues);
                var values = new ManagedList();
                foreach (var name in names)
                {
                    values.Add(new RuntimeObjectReference(name.Trim()));
                }

                containerDef.PropertyValues.Add("Queues", values);
            }

            // Register the listener and fire event
            parserContext.Registry.RegisterObjectDefinition(containerObjectName, containerDef);
        }
        /// <summary>
        /// Parses the validator definition.
        /// </summary>
        /// <param name="id">Validator's identifier.</param>
        /// <param name="element">The element to parse.</param>
        /// <param name="parserContext">The parser helper.</param>
        /// <returns>Validator object definition.</returns>
        private IObjectDefinition ParseValidator(string id, XmlElement element, ParserContext parserContext)
        {
            string typeName = GetTypeName(element);
            string parent = GetAttributeValue(element, ObjectDefinitionConstants.ParentAttribute);

            string name = "validator: " + (StringUtils.HasText(id) ? id : this.definitionCount.ToString());

            MutablePropertyValues properties = new MutablePropertyValues();
            IConfigurableObjectDefinition od
                = parserContext.ReaderContext.ObjectDefinitionFactory.CreateObjectDefinition(
                    typeName, parent, parserContext.ReaderContext.Reader.Domain);

            od.PropertyValues = properties;
            od.IsSingleton = true;
            od.IsLazyInit = true;

            ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.TestAttribute, properties, "Test");
            ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.WhenAttribute, properties, "When");
            ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.GroupFastValidateAttribute, properties, "FastValidate");
            ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.RegexExpressionAttribute, properties, "Expression");
            ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.CollectionValidateAllAttribute, properties, "ValidateAll");
            ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.CollectionContextAttribute, properties, "Context");
            ParseAttributeIntoProperty(element, ValidatorDefinitionConstants.CollectionIncludeElementsErrors, properties, "IncludeElementErrors");

// TODO: (EE) - is this a mistake to check 'validateAll' but add 'context' then?
//            if (StringUtils.HasText(validateAll))
//            {
//                properties.Add("Context", context);
//            }

            ManagedList nestedValidators = new ManagedList();
            ManagedList actions = new ManagedList();
            ParserContext childParserContext = new ParserContext(parserContext.ParserHelper, od);
            foreach (XmlNode node in element.ChildNodes)
            {
                XmlElement child = node as XmlElement;
                if (child != null)
                {
                    switch (child.LocalName)
                    {
                        case ValidatorDefinitionConstants.PropertyElement:
                            string propertyName = GetAttributeValue(child, ValidatorDefinitionConstants.PropertyNameAttribute);
                            properties.Add(propertyName, base.ParsePropertyValue(child, name, childParserContext));
                            break;
                        case ValidatorDefinitionConstants.MessageElement:
                            actions.Add(ParseErrorMessageAction(child, childParserContext));
                            break;
                        case ValidatorDefinitionConstants.ActionElement:
                            actions.Add(ParseGenericAction(child, childParserContext));
                            break;
                        case ValidatorDefinitionConstants.ExceptionElement:
                            actions.Add(ParseExceptionAction(child, childParserContext));
                            break;
                        case ValidatorDefinitionConstants.ReferenceElement:
                            nestedValidators.Add(ParseValidatorReference(child, childParserContext));
                            break;
                        default:
                            nestedValidators.Add(ParseAndRegisterValidator(child, childParserContext));
                            break;
                    }
                }
            }
            if (nestedValidators.Count > 0)
            {
                properties.Add("Validators", nestedValidators);
            }
            if (actions.Count > 0)
            {
                properties.Add("Actions", actions);
            }

            return od;
        }
 public void MergeNotAllowedWhenMergeNotEnabled()
 {
     ManagedList child = new ManagedList();
     child.Merge(null);
 }
 public void MergeNotAllowedWhenMergeNotEnabled()
 {
     ManagedList child = new ManagedList();
     Assert.Throws<InvalidOperationException>(() => child.Merge(null), "Not allowed to merge when the 'MergeEnabled' property is set to 'false'");
 }
        public void SunnyDay()
        {
            StaticApplicationContext ac = new StaticApplicationContext();

            MutablePropertyValues pvs = new MutablePropertyValues();
            pvs.Add("age", "${age}");
            RootObjectDefinition def
                = new RootObjectDefinition("${fqn}", new ConstructorArgumentValues(), pvs);
            ac.RegisterObjectDefinition("tb3", def);

            pvs = new MutablePropertyValues();
            pvs.Add("age", "${age}");
            pvs.Add("name", "name${var}${");
            pvs.Add("spouse", new RuntimeObjectReference("${ref}"));
            ac.RegisterSingleton("tb1", typeof (TestObject), pvs);

            ConstructorArgumentValues cas = new ConstructorArgumentValues();
            cas.AddIndexedArgumentValue(1, "${age}");
            cas.AddGenericArgumentValue("${var}name${age}");

            pvs = new MutablePropertyValues();
            ArrayList friends = new ManagedList();
            friends.Add("na${age}me");
            friends.Add(new RuntimeObjectReference("${ref}"));
            pvs.Add("friends", friends);

            ISet someSet = new ManagedSet();
            someSet.Add("na${age}me");
            someSet.Add(new RuntimeObjectReference("${ref}"));
            pvs.Add("someSet", someSet);

            IDictionary someDictionary = new ManagedDictionary();
            someDictionary["key1"] = new RuntimeObjectReference("${ref}");
            someDictionary["key2"] = "${age}name";
            MutablePropertyValues innerPvs = new MutablePropertyValues();
            someDictionary["key3"] = new RootObjectDefinition(typeof (TestObject), innerPvs);
            someDictionary["key4"] = new ChildObjectDefinition("tb1", innerPvs);
            pvs.Add("someMap", someDictionary);

            RootObjectDefinition definition = new RootObjectDefinition(typeof (TestObject), cas, pvs);
            ac.DefaultListableObjectFactory.RegisterObjectDefinition("tb2", definition);

            pvs = new MutablePropertyValues();
            pvs.Add("Properties", "<spring-config><add key=\"age\" value=\"98\"/><add key=\"var\" value=\"${m}var\"/><add key=\"ref\" value=\"tb2\"/><add key=\"m\" value=\"my\"/><add key=\"fqn\" value=\"Spring.Objects.TestObject, Spring.Core.Tests\"/></spring-config>");
            ac.RegisterSingleton("configurer", typeof (PropertyPlaceholderConfigurer), pvs);
            ac.Refresh();

            TestObject tb1 = (TestObject) ac.GetObject("tb1");
            TestObject tb2 = (TestObject) ac.GetObject("tb2");
            TestObject tb3 = (TestObject) ac.GetObject("tb3");
            Assert.AreEqual(98, tb1.Age);
            Assert.AreEqual(98, tb2.Age);
            Assert.AreEqual(98, tb3.Age);
            Assert.AreEqual("namemyvar${", tb1.Name);
            Assert.AreEqual("myvarname98", tb2.Name);
            Assert.AreEqual(tb2, tb1.Spouse);
            Assert.AreEqual(2, tb2.Friends.Count);
            IEnumerator ie = tb2.Friends.GetEnumerator();
            ie.MoveNext();
            Assert.AreEqual("na98me", ie.Current);
            ie.MoveNext();
            Assert.AreEqual(tb2, ie.Current);
            Assert.AreEqual(2, tb2.SomeSet.Count);
            Assert.IsTrue(tb2.SomeSet.Contains("na98me"));
            Assert.IsTrue(tb2.SomeSet.Contains(tb2));
            Assert.AreEqual(4, tb2.SomeMap.Count);
            Assert.AreEqual(tb2, tb2.SomeMap["key1"]);
            Assert.AreEqual("98name", tb2.SomeMap["key2"]);
            TestObject inner1 = (TestObject) tb2.SomeMap["key3"];
            TestObject inner2 = (TestObject) tb2.SomeMap["key4"];
            Assert.AreEqual(0, inner1.Age);
            Assert.AreEqual(null, inner1.Name);
            Assert.AreEqual(98, inner2.Age);
            Assert.AreEqual("namemyvar${", inner2.Name);
        }
        /// <summary>
        /// Gets a list definition.
        /// </summary>
        /// <param name="collectionEle">
        /// The element describing the list definition.
        /// </param>
        /// <param name="name">
        /// The name of the object (definition) associated with the list definition.
        /// </param>
        /// <param name="parserContext">
        /// The namespace-aware parser.
        /// </param>
        /// <returns>The list definition.</returns>
        protected virtual IList ParseListElement(XmlElement collectionEle, string name, ParserContext parserContext)
        {
            string elementTypeName = GetAttributeValue(collectionEle, "element-type");
            XmlNodeList nl = collectionEle.ChildNodes;
            ManagedList target = new ManagedList(nl.Count);

            if (StringUtils.HasText(elementTypeName))
            {
                target.ElementTypeName = elementTypeName;
            }
            target.MergeEnabled = ParseMergeAttribute(collectionEle, parserContext.ParserHelper);

            foreach (XmlNode node in collectionEle.ChildNodes)
            {
                XmlElement ele = node as XmlElement;
                if (ele != null)
                {
                    target.Add(ParsePropertySubElement(ele, name, parserContext));
                }
            }
            return target;
        }
        public void SunnyDay()
        {
            StaticApplicationContext ac = new StaticApplicationContext();


            MutablePropertyValues pvs = new MutablePropertyValues();

            pvs.Add("age", "${age}");
            RootObjectDefinition def
                = new RootObjectDefinition("${fqn}", new ConstructorArgumentValues(), pvs);

            ac.RegisterObjectDefinition("tb3", def);



            pvs = new MutablePropertyValues();
            pvs.Add("age", "${age}");
            pvs.Add("name", "name${var}${");
            pvs.Add("spouse", new RuntimeObjectReference("${ref}"));
            ac.RegisterSingleton("tb1", typeof(TestObject), pvs);

            ConstructorArgumentValues cas = new ConstructorArgumentValues();

            cas.AddIndexedArgumentValue(1, "${age}");
            cas.AddGenericArgumentValue("${var}name${age}");

            pvs = new MutablePropertyValues();
            ArrayList friends = new ManagedList();

            friends.Add("na${age}me");
            friends.Add(new RuntimeObjectReference("${ref}"));
            pvs.Add("friends", friends);

            ISet someSet = new ManagedSet();

            someSet.Add("na${age}me");
            someSet.Add(new RuntimeObjectReference("${ref}"));
            pvs.Add("someSet", someSet);

            IDictionary someDictionary = new ManagedDictionary();

            someDictionary["key1"] = new RuntimeObjectReference("${ref}");
            someDictionary["key2"] = "${age}name";
            MutablePropertyValues innerPvs = new MutablePropertyValues();

            someDictionary["key3"] = new RootObjectDefinition(typeof(TestObject), innerPvs);
            someDictionary["key4"] = new ChildObjectDefinition("tb1", innerPvs);
            pvs.Add("someMap", someDictionary);

            RootObjectDefinition definition = new RootObjectDefinition(typeof(TestObject), cas, pvs);

            ac.DefaultListableObjectFactory.RegisterObjectDefinition("tb2", definition);

            pvs = new MutablePropertyValues();
            pvs.Add("Properties", "<spring-config><add key=\"age\" value=\"98\"/><add key=\"var\" value=\"${m}var\"/><add key=\"ref\" value=\"tb2\"/><add key=\"m\" value=\"my\"/><add key=\"fqn\" value=\"Spring.Objects.TestObject, Spring.Core.Tests\"/></spring-config>");
            ac.RegisterSingleton("configurer", typeof(PropertyPlaceholderConfigurer), pvs);
            ac.Refresh();

            TestObject tb1 = (TestObject)ac.GetObject("tb1");
            TestObject tb2 = (TestObject)ac.GetObject("tb2");
            TestObject tb3 = (TestObject)ac.GetObject("tb3");

            Assert.AreEqual(98, tb1.Age);
            Assert.AreEqual(98, tb2.Age);
            Assert.AreEqual(98, tb3.Age);
            Assert.AreEqual("namemyvar${", tb1.Name);
            Assert.AreEqual("myvarname98", tb2.Name);
            Assert.AreEqual(tb2, tb1.Spouse);
            Assert.AreEqual(2, tb2.Friends.Count);
            IEnumerator ie = tb2.Friends.GetEnumerator();

            ie.MoveNext();
            Assert.AreEqual("na98me", ie.Current);
            ie.MoveNext();
            Assert.AreEqual(tb2, ie.Current);
            Assert.AreEqual(2, tb2.SomeSet.Count);
            Assert.IsTrue(tb2.SomeSet.Contains("na98me"));
            Assert.IsTrue(tb2.SomeSet.Contains(tb2));
            Assert.AreEqual(4, tb2.SomeMap.Count);
            Assert.AreEqual(tb2, tb2.SomeMap["key1"]);
            Assert.AreEqual("98name", tb2.SomeMap["key2"]);
            TestObject inner1 = (TestObject)tb2.SomeMap["key3"];
            TestObject inner2 = (TestObject)tb2.SomeMap["key4"];

            Assert.AreEqual(0, inner1.Age);
            Assert.AreEqual(null, inner1.Name);
            Assert.AreEqual(98, inner2.Age);
            Assert.AreEqual("namemyvar${", inner2.Name);
        }
        /// <summary>
        /// Visits the ManagedList property ElementTypeName and 
        /// calls <see cref="ResolveValue"/> for list element.
        /// </summary>
        protected virtual void VisitManagedList(ManagedList listVal)
        {
            string elementTypeName = listVal.ElementTypeName;
            if (elementTypeName != null)
            {
                string resolvedName = ResolveStringValue(elementTypeName);
                if (!elementTypeName.Equals(resolvedName))
                {
                    listVal.ElementTypeName = resolvedName;
                }
            }

            for (int i = 0; i < listVal.Count; ++i)
            {
                object oldValue = listVal[i];
                object newValue = ResolveValue(oldValue);
                if (!ObjectUtils.NullSafeEquals(newValue, oldValue))
                {
                    listVal[i] = newValue;
                }
            }
        }
 /**
  * Parses the 'advice-chain' element's sub-elements.
  */
 private static void ConfigureAdviceChain(XmlNode adviceChainElement, ObjectDefinitionBuilder targetBuilder, ParserContext parserContext)
 {
     ManagedList adviceChain = new ManagedList();
     adviceChain.ElementTypeName = typeof (IAdvice).FullName;
     XmlNodeList childNodes = adviceChainElement.ChildNodes;
     for(int i = 0; i < childNodes.Count; i++) {
         XmlNode child = childNodes.Item(i);
         if(child.NodeType == XmlNodeType.Element) {
             XmlElement childElement = (XmlElement)child;
             string localName = child.LocalName;
             if("object".Equals(localName)) {
                 //ObjectDefinitionHolder holder = parserContext.ParserHelper.ParseObjectDefinitionElement(childElement, targetBuilder.ObjectDefinition);
                 IObjectDefinition def = parserContext.ParserHelper.ParseCustomElement(childElement, targetBuilder.ObjectDefinition);
                 string name = parserContext.ReaderContext.RegisterWithGeneratedName(def);
                 adviceChain.Add(new RuntimeObjectReference(name));
             }
             else if("ref".Equals(localName)) {
                 String refatr = childElement.GetAttribute("object");
                 adviceChain.Add(new RuntimeObjectReference(refatr));
             }
             else {
                 IObjectDefinition customBeanDefinition = parserContext.ParserHelper.ParseCustomElement(childElement, targetBuilder.ObjectDefinition);
                 if(customBeanDefinition == null) {
                     parserContext.ReaderContext.ReportException(childElement, childElement.Name, "failed to parse custom element '" + localName + "'");
                 }
             }
         }
     }
     targetBuilder.AddPropertyValue("adviceChain", adviceChain);
 }