AddPropertyValue() public method

Adds the property value under the given name.
public AddPropertyValue ( string name, object value ) : ObjectDefinitionBuilder
name string The name.
value object The value.
return ObjectDefinitionBuilder
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            builder.AddPropertyReference(TxNamespaceUtils.TRANSACTION_MANAGER_PROPERTY,
                GetAttributeValue(element, TxNamespaceUtils.TRANSACTION_MANAGER_ATTRIBUTE));
            XmlNodeList txAttributes = element.SelectNodes("*[local-name()='attributes' and namespace-uri()='" + element.NamespaceURI + "']");
            if (txAttributes.Count > 1 )
            {
                parserContext.ReaderContext.ReportException(element, "tx advice", "Element <attributes> is allowed at most once inside element <advice>");
            }
            else if (txAttributes.Count == 1)
            {
                //using xml defined source
                XmlElement attributeSourceElement = txAttributes[0] as XmlElement;
                AbstractObjectDefinition attributeSourceDefinition =
                    ParseAttributeSource(attributeSourceElement, parserContext);
                builder.AddPropertyValue(TxNamespaceUtils.TRANSACTION_ATTRIBUTE_SOURCE, attributeSourceDefinition);
            }
            else
            {
                //Assume attibutes source
                ObjectDefinitionBuilder txAttributeSourceBuilder =
                    parserContext.ParserHelper.CreateRootObjectDefinitionBuilder(typeof (AttributesTransactionAttributeSource));

                builder.AddPropertyValue(TxNamespaceUtils.TRANSACTION_ATTRIBUTE_SOURCE,
                                         txAttributeSourceBuilder.ObjectDefinition);

            }
        }
        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);
            }
        }
        public void Simple()
        {
            GenericApplicationContext ctx = new GenericApplicationContext();
            IObjectDefinitionFactory  objectDefinitionFactory = new DefaultObjectDefinitionFactory();

            ObjectDefinitionBuilder builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory,
                                                                                           typeof(TestObject));

            builder.AddPropertyValue("Age", 22)
            .AddPropertyValue("Name", "Joe")
            .AddPropertyReference("Spouse", "Spouse")
            .SetSingleton(false);

            ctx.RegisterObjectDefinition("TestObject", builder.ObjectDefinition);

            builder = ObjectDefinitionBuilder.RootObjectDefinition(objectDefinitionFactory, typeof(TestObject));

            IList friends = new ArrayList();

            friends.Add(new TestObject("Dan", 34));
            friends.Add(new TestObject("Mary", 33));
            builder.AddPropertyValue("Friends", friends)
            .AddConstructorArg("Susan")
            .AddConstructorArg(23)
            .SetSingleton(false);

            ctx.RegisterObjectDefinition("Spouse", builder.ObjectDefinition);



            TestObject to = ctx.GetObject("TestObject") as TestObject;

            Assert.IsNotNull(to);

            Assert.AreEqual("Joe", to.Name);
            Assert.AreEqual(22, to.Age);
            Assert.AreEqual(2, to.Spouse.Friends.Count);
            Assert.AreEqual(23, to.Spouse.Age);

            /*
             * AbstractApplicationContext ctx = ContextRegistry.GetContext() as AbstractApplicationContext;
             *
             *
             *
             * //XmlObjectFactory objectFactory = ctx.ObjectFactory as XmlObjectFactory;
             *
             * IObjectFactory objectFactory = ctx.ObjectFactory;
             *
             * //DefaultListableObjectFactory
             * if (objectFactory != null)
             * {
             *  Console.WriteLine("hi");
             * }
             * //objectFactory.RegisterObjectDefinition("TestObject", builder.ObjectDefinition);
             */
        }
        protected void DoParseInternal(XmlElement element, ObjectDefinitionBuilder builder)
        {
            builder.SetSingleton(false);
            string leftMenu = element.GetAttribute("menu");
            if(!string.IsNullOrEmpty(leftMenu)) builder.AddPropertyReference("Menu", leftMenu);
            string rightScreen = element.GetAttribute("screen");
            if(!string.IsNullOrEmpty(rightScreen)) builder.AddPropertyReference("MainScreen", rightScreen);
            foreach (XmlNode node in element.ChildNodes)
            {
                if (node is XmlComment) continue;

                switch (node.LocalName.ToLower())
                {
                    case "steps":
                        XmlNodeList steps = node.ChildNodes;
                        if (steps.Count > 0) // if flow is configured with a list of steps
                        {
                            IDictionary stepsDic = new System.Collections.Hashtable();
                            int count = 0;
                            foreach (XmlNode step in steps)
                            {
                                if(step is XmlComment) continue;
                                if (!step.LocalName.ToLower().Equals("step"))
                                {
                                    throw new Exception("Do not support node with name " + node.Name + " in config file.");
                                }
                                string key = "Step" + (++count).ToString();
                                stepsDic[key] = step.InnerText;
                            }

                            builder.AddPropertyValue("FlowSteps", stepsDic);
                        }
                        break;
                    case "session":
                        string sessionRefBeanName = node.InnerText;
                        if(!string.IsNullOrEmpty(sessionRefBeanName))
                        {
                            builder.AddDependsOn(sessionRefBeanName);
                            builder.AddPropertyReference("Session", sessionRefBeanName);
                        }

                        break;
                    case "menu":
                        string menuClassName = node.InnerText;
                        builder.AddPropertyValue("MenuClass", Type.GetType(menuClassName));
                        break;
                    case "screen":
                        string screenClassName = node.InnerText;
                        builder.AddPropertyValue("MainScreenClass", Type.GetType(screenClassName));
                        break;
                    default:
                        throw new Exception("Do not support node with name " + node.Name + " in config file.");
                        break;
                }
            }
        }
 /*override*/
 protected static void PostProcess(ObjectDefinitionBuilder builder, XmlElement element)
 {
     string policyName = element.GetAttribute(REJECTION_POLICY_ATTRIBUTE);
     builder.AddPropertyValue("rejectedExecutionHandler", CreateRejectedExecutionHandler(policyName));
     builder.AddPropertyValue("corePoolSize", element.GetAttribute(CORE_SIZE_ATTRIBUTE));
     string maxSize = element.GetAttribute(MAX_SIZE_ATTRIBUTE);
     if(StringUtils.HasText(maxSize)) {
         builder.AddPropertyValue("maxPoolSize", maxSize);
     }
 }
 protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
 {
     String taskExecutorRef = element.GetAttribute("task-executor");
     if(StringUtils.HasText(taskExecutorRef)) {
         builder.AddPropertyReference("taskExecutor", taskExecutorRef);
     }
     else {
         IExecutor taskExecutor = IntegrationContextUtils.CreateThreadPoolTaskExecutor(1, 10, 0, "event-multicaster-");
         builder.AddPropertyValue("taskExecutor", taskExecutor);
     }
     // TODO CopyOnWriteArraySet
     builder.AddPropertyValue("collectionClass", typeof (Set)); //CopyOnWriteArraySet));
 }
Exemplo n.º 7
0
 public void Configure(ObjectDefinitionBuilder builder)
 {
     foreach (string key in _properties.Keys)
     {
         builder.AddPropertyValue(key, _properties[key]);
     }
 }
        /// <summary>The do parse.</summary>
        /// <param name="element">The element.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <param name="builder">The builder.</param>
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            var parser = new ObjectDefinitionParserHelper(parserContext);
            var map = parser.ParseMapElement(element, builder.RawObjectDefinition);

            builder.AddPropertyValue("SourceDictionary", map);
        }
        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);
            }
        }
Exemplo n.º 10
0
        /// <summary>Sets the value if attribute defined.</summary>
        /// <param name="builder">The builder.</param>
        /// <param name="element">The element.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>True if successful, else false.</returns>
        public static bool SetValueIfAttributeDefined(ObjectDefinitionBuilder builder, XmlElement element, string attributeName, string propertyName)
        {
            var attributeValue = element.GetAttribute(attributeName);
            if (!string.IsNullOrWhiteSpace(attributeValue))
            {
                builder.AddPropertyValue(propertyName, new TypedStringValue(attributeValue));
                return true;
            }

            return false;
        }
 protected override void DoParse(XmlElement element, ObjectDefinitionBuilder builder)
 {
     foreach(XmlAttribute attribute in element.Attributes) {
         if(IsEligibleAttribute(attribute.Name)) {
             string propertyName = Conventions.AttributeNameToPropertyName(attribute.LocalName);
             AssertUtils.State(StringUtils.HasText(propertyName), "Illegal property name returned from 'extractPropertyName(String)': cannot be null or empty.");
             builder.AddPropertyValue(propertyName, attribute.Value);
         }
     }
     PostProcess(builder, element);
 }
 private void SetConvention(XmlElement element, ObjectDefinitionBuilder builder, string attribute, string property)
 {
     string value = string.Empty;
     try
     {
         value = element.GetAttribute(attribute);
         if (StringUtils.HasText(value))
         {
             Type type = TypeResolutionUtils.ResolveType(value);
             object instance = Activator.CreateInstance(type);
             builder.AddPropertyValue(property, instance);
         }
     }
     catch (TypeLoadException e)
     {
         throw new ObjectCreationException(string.Format("Convention of type '{0}' could not be loaded: {1}", attribute, value));
     }
 }
Exemplo n.º 13
0
        /// <summary>The do parse.</summary>
        /// <param name="element">The element.</param>
        /// <param name="parserContext">The parser context.</param>
        /// <param name="builder">The builder.</param>
        protected override void DoParse(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            var connectionFactoryRef = element.GetAttribute(CONNECTION_FACTORY_ATTRIBUTE);

            // At least one of 'templateRef' or 'connectionFactoryRef' attribute must be set.
            if (string.IsNullOrWhiteSpace(connectionFactoryRef))
            {
                parserContext.ReaderContext.ReportFatalException(element, "A '" + CONNECTION_FACTORY_ATTRIBUTE + "' attribute must be set.");
            }

            if (!string.IsNullOrWhiteSpace(connectionFactoryRef))
            {
                // Use constructor with connectionFactory parameter
                builder.AddConstructorArgReference(connectionFactoryRef);
            }

            var attributeValue = element.GetAttribute(AUTO_STARTUP_ATTRIBUTE);
            if (!string.IsNullOrWhiteSpace(attributeValue))
            {
                builder.AddPropertyValue("AutoStartup", attributeValue);
            }
        }
 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 static void SetPropertyValue(XmlElement element, ObjectDefinitionBuilder builder, string attrName,
     string propertyName)
 {
     string attr = element.GetAttribute(attrName);
     if (StringUtils.HasText(attr))
     {
         builder.AddPropertyValue(propertyName, attr);
     }
 }
        private void ParseMongoClientSettings(XmlElement element, ObjectDefinitionBuilder mongoDefBuilder)
        {
            if (!element.HasChildNodes)
                return;

            foreach (XmlElement node in element.ChildNodes)
            {
                if (node.LocalName != ObjectNames.MongoSettings)
                    continue;

                var settingsDefBuilder = ObjectDefinitionBuilder.GenericObjectDefinition(typeof (MongoClientSettingsFactoryObject));

                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeConnectTimeout, MongoClientSettingsFactoryObject.ConnectTimeoutProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeConnectionMode, MongoClientSettingsFactoryObject.ConnectionModeProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeUsername, MongoClientSettingsFactoryObject.UsernameProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributePassword, MongoClientSettingsFactoryObject.PasswordProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeGuidRepresentation, MongoClientSettingsFactoryObject.GuidRepresentationProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeIPv6, MongoClientSettingsFactoryObject.IPv6Property);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeMaxConnectionIdleTime, MongoClientSettingsFactoryObject.MaxConnectionIdleTimePropert);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeMaxConnectionLifeTime, MongoClientSettingsFactoryObject.MaxConnectionLifeTimeProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeMaxConnectionPoolSize, MongoClientSettingsFactoryObject.MaxConnectionPoolSizeProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeMinConnectionPoolSize, MongoClientSettingsFactoryObject.MinConnectionPoolSizeProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeReadPreference, MongoClientSettingsFactoryObject.ReadPreferenceProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeReplicaSetName, MongoClientSettingsFactoryObject.ReplicaSetNameProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeSecondaryAcceptableLatency, MongoClientSettingsFactoryObject.SecondaryAcceptableLatencyProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeServer, MongoClientSettingsFactoryObject.ServerProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeServers, MongoClientSettingsFactoryObject.ServersProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeSocketTimeout, MongoClientSettingsFactoryObject.SocketTimeoutProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeUseSsl, MongoClientSettingsFactoryObject.UseSslProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeVerifySslCertificate, MongoClientSettingsFactoryObject.VerifySslCertificateProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeWaitQueueSize, MongoClientSettingsFactoryObject.WaitQueueSizeProeprty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeWaitQueueTimeout, MongoClientSettingsFactoryObject.WaitQueueTimeoutProperty);
                SetPropertyValue(settingsDefBuilder, node, ObjectNames.MongoSettingsAttributeWriteConcern, MongoClientSettingsFactoryObject.WriteConcernProperty);

                mongoDefBuilder.AddPropertyValue(MongoFactoryObject.MongoClientSettingsProperty, settingsDefBuilder.ObjectDefinition);

                break;
            }
        }
 private void ParseAttribute(XmlElement element, ObjectDefinitionBuilder mongoDefBuilder, string property, string attribute)
 {
     string value = element.GetAttribute(attribute);
     if (StringUtils.HasText(value))
         mongoDefBuilder.AddPropertyValue(property, value);
 }
        private void SetPropertyValue(ObjectDefinitionBuilder builder, XmlElement element, string attrName, string propertyName)
        {
            AssertUtils.ArgumentNotNull(builder, "builder");
            AssertUtils.ArgumentNotNull(element, "element");
            AssertUtils.ArgumentHasText(attrName, "attrName");
            AssertUtils.ArgumentHasText(propertyName, "propertyName");

            string attr = element.GetAttribute(attrName);
            if (StringUtils.HasText(attr))
            {
                builder.AddPropertyValue(propertyName, attr);
            }
        }
        private void ParseTypeFilters(XmlElement element, ObjectDefinitionBuilder builder)
        {
            var includeTypeFilters = new List<ITypeFilter>();
            var excludeTypeFilters = new List<ITypeFilter>();

            foreach (XmlNode node in element.ChildNodes)
            {
                if (node.Name.Contains(ObjectNames.IncludeFilterElement))
                {
                    var typeFilter = CreateTypeFilter(node);
                    if (typeFilter != null)
                        includeTypeFilters.Add(typeFilter);
                }
                else if (node.Name.Contains(ObjectNames.ExcludeFilterElement))
                {
                    var typeFilter = CreateTypeFilter(node);
                    if (typeFilter != null)
                        excludeTypeFilters.Add(typeFilter);
                }
            }

            builder.AddPropertyValue(ConventionProfileFactory.IncludeFiltersProperty, includeTypeFilters);
            builder.AddPropertyValue(ConventionProfileFactory.ExcludeFiltersProperty, excludeTypeFilters);
        }
        private void ParseContainerConfiguration(XmlElement ele, ParserContext parserContext,
                                                 ObjectDefinitionBuilder containerDef)
        {
            string destinationType = ele.GetAttribute(DESTINATION_TYPE_ATTRIBUTE);
            bool pubSubDomain = false;
            bool subscriptionDurable = false;
            if (DESTINATION_TYPE_DURABLE_TOPIC.Equals(destinationType))
            {
                pubSubDomain = true;
                subscriptionDurable = true;
            }
            else if (DESTINATION_TYPE_TOPIC.Equals(destinationType))
            {
                pubSubDomain = true;
            }
            else if ("".Equals(destinationType) || DESTINATION_TYPE_QUEUE.Equals(destinationType))
            {
                // the default: queue
            }
            else
            {
                parserContext.ReaderContext.ReportException(ele, destinationType,
                                                            "Invalid listener container '" + DESTINATION_TYPE_ATTRIBUTE +
                                                            "': only 'queue', 'topic' and 'durableTopic' supported");
            }

            containerDef.AddPropertyValue("PubSubDomain", pubSubDomain);
            containerDef.AddPropertyValue("SubscriptionDurable", subscriptionDurable);

            if (ele.HasAttribute(CLIENT_ID_ATTRIBUTE))
            {
                string clientId = ele.GetAttribute(CLIENT_ID_ATTRIBUTE);
                if (!StringUtils.HasText(clientId))
                {
                    parserContext.ReaderContext.ReportException(ele, clientId,
                                                                "Listener '" + CLIENT_ID_ATTRIBUTE +
                                                                "' attribute contains empty value.");
                }
                containerDef.AddPropertyValue("ClientId", clientId);
            }
        }
        //        private IConfigurableObjectDefinition ParseDatabaseDefinition(XmlElement element, string name, ParserContext parserContext)
        //        {
        //            switch (element.LocalName)
        //            {
        //                case DbProviderFactoryObjectConstants.DbProviderFactoryObjectElement:
        //                    return ParseDatabaseConfigurer(element, name, parserContext);
        //            }
        //            return null;
        //        }
        private void ParseDatabaseConfigurer(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            //            string typeName = GetTypeName(element);
            string providerNameAttribute = GetAttributeValue(element, DbProviderFactoryObjectConstants.ProviderNameAttribute);
            string connectionString = GetAttributeValue(element, DbProviderFactoryObjectConstants.ConnectionStringAttribute);

            //            MutablePropertyValues properties = new MutablePropertyValues();
            if (StringUtils.HasText(providerNameAttribute))
            {
                builder.AddPropertyValue("Provider", providerNameAttribute);
            //                properties.Add("Provider", providerNameAttribute);
            }
            if (StringUtils.HasText(connectionString))
            {
                builder.AddPropertyValue("ConnectionString", connectionString);
            //                properties.Add("ConnectionString", connectionString);
            }

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

            //            return builder.ObjectDefinition;
        }
        protected override void ParseTransformer(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder)
        {
            ManagedDictionary headers = new ManagedDictionary();
            XmlAttributeCollection attributes = element.Attributes;
            for (int i = 0; i < attributes.Count; i++) {
            XmlNode node = attributes.Item(i);
            String name = node.LocalName;
            if (IsEligibleHeaderName(name)) {
                name = Conventions.AttributeNameToPropertyName(name);
                object value;
                if(ReferenceAttributesContains(name))
                    value = new RuntimeObjectReference(node.Value);
                else
                    value = node.Value;

                if (_prefix != null) {
                    name = _prefix + name;
                }
                headers.Add(name, value);
            }
            }
            PostProcessHeaders(element, headers, parserContext);
            builder.AddConstructorArg(headers);
            builder.AddPropertyValue("overwrite", ShouldOverwrite(element));
        }
        private void ParseListenerConfiguration(XmlElement ele, ParserContext parserContext,
                                                ObjectDefinitionBuilder containerDef)
        {
            string destination = ele.GetAttribute(DESTINATION_ATTRIBUTE);
            if (!StringUtils.HasText(destination))
            {
                parserContext.ReaderContext.ReportException(ele, LISTENER_ELEMENT,
                                                            "Listener '" + DESTINATION_ATTRIBUTE +
                                                            "' attribute contains empty value.");
            }
            containerDef.AddPropertyValue("DestinationName", destination);

            if (ele.HasAttribute(SUBSCRIPTION_ATTRIBUTE))
            {
                string subscription = ele.GetAttribute(SUBSCRIPTION_ATTRIBUTE);
                if (!StringUtils.HasText(subscription))
                {
                    parserContext.ReaderContext.ReportException(ele, SUBSCRIPTION_ATTRIBUTE,
                                                                "Listener '" + SUBSCRIPTION_ATTRIBUTE +
                                                                "' attribute contains empty value.");
                }
                containerDef.AddPropertyValue("DurableSubscriptionName", subscription);
            }

            if (ele.HasAttribute(SELECTOR_ATTRIBUTE))
            {
                string selector = ele.GetAttribute(SELECTOR_ATTRIBUTE);
                if (!StringUtils.HasText(selector))
                {
                    parserContext.ReaderContext.ReportException(ele, selector,
                                                                "Listener '" + SELECTOR_ATTRIBUTE +
                                                                "' attribute contains empty value.");
                }
                containerDef.AddPropertyValue("MessageSelector", selector);
            }
        }
 /**
  * Parse a "transactional" element and configure the "transactionManager" and "transactionDefinition"
  * properties for the target builder.
  */
 private static void ConfigureTransactionAttributes(XmlElement txElement, ObjectDefinitionBuilder targetBuilder)
 {
     targetBuilder.AddPropertyReference("transactionManager", txElement.GetAttribute("transaction-manager"));
     DefaultTransactionDefinition txDefinition = new DefaultTransactionDefinition();
     txDefinition.PropagationBehavior = (TransactionPropagation)Enum.Parse(typeof(TransactionPropagation), txElement.GetAttribute("propagation"));
     txDefinition.TransactionIsolationLevel = (IsolationLevel)Enum.Parse(typeof(IsolationLevel), txElement.GetAttribute("isolation"));
     txDefinition.TransactionTimeout = Convert.ToInt32(txElement.GetAttribute("timeout"));
     txDefinition.ReadOnly = txElement.GetAttribute("read-only").Equals("true", StringComparison.OrdinalIgnoreCase);
     targetBuilder.AddPropertyValue("transactionDefinition", txDefinition);
 }
 /// <summary>
 /// Populates the specified object definition property with the value
 /// of the attribute whose name is provided if that attribute is
 /// defined in the given element.
 /// </summary>
 /// <param name="builder">the builder to add the prperty to</param>
 /// <param name="element">the XML element where the attribute should be defined</param>
 /// <param name="attributeName">the name of the attribute whose value will be used to populate the property</param>
 /// <param name="propertyName">the name of the property to be populated</param>
 public static void SetValueIfAttributeDefined(ObjectDefinitionBuilder builder, XmlElement element, string attributeName, string propertyName)
 {
     string attributeValue = element.GetAttribute(attributeName);
     if(StringUtils.HasText(attributeValue)) {
         builder.AddPropertyValue(propertyName, attributeValue);
     }
 }
 /**
  * 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);
 }