AddConstructorArg() 공개 메소드

Adds an index constructor arg value. The current index is tracked internally and all addtions are at the present point
public AddConstructorArg ( object value ) : ObjectDefinitionBuilder
value object The constructor arg value.
리턴 ObjectDefinitionBuilder
        /// <summary>
        /// Parse the supplied XmlElement and populate the supplied ObjectDefinitionBuilder as required.
        /// </summary>
        /// <param name="xml">The obejct representation in XML.</param>
        /// <param name="builder">The builder used to build the object definition in Spring.</param>
        protected override void DoParse(XmlElement xml, ObjectDefinitionBuilder builder)
        {
            // all behaviours with config being parsed have @respondsTo
            string respondsTo = xml.GetAttribute("responds-to");
            builder.AddConstructorArg(respondsTo);

            // all view behaviours have @content-type
            string contentType = xml.GetAttribute("content-type");
            builder.AddConstructorArg(contentType);
        }
 private static void ParseQueueCapacity(ObjectDefinitionBuilder builder, XmlElement queueElement)
 {
     string capacity = queueElement.GetAttribute("capacity");
     if (StringUtils.HasText(capacity)) {
         builder.AddConstructorArg(Convert.ToUInt32(capacity));
     }
 }
        /// <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 exchangeName = element.GetAttribute("name");
            builder.AddConstructorArg(new TypedStringValue(exchangeName));
            this.ParseBindings(element, parserContext, builder, exchangeName);

            NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, true);
            NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE, false);

            var argumentsElement = element.SelectChildElementByTagName(ARGUMENTS_ELEMENT);

            if (argumentsElement != null)
            {
                var parser = new ObjectDefinitionParserHelper(parserContext);
                var map = parser.ParseMapElementToTypedDictionary(argumentsElement, builder.RawObjectDefinition);

                builder.AddConstructorArg(map);
            }
        }
예제 #4
0
        /// <summary>Adds the constructor arg 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>
        /// <returns><c>true</c> if [is attribute defined] [the specified element]; otherwise, <c>false</c>.</returns>
        public static bool AddConstructorArgValueIfAttributeDefined(ObjectDefinitionBuilder builder, XmlElement element, string attributeName)
        {
            var value = element.GetAttribute(attributeName);
            if (!string.IsNullOrWhiteSpace(value))
            {
                builder.AddConstructorArg(new TypedStringValue(value));
                return true;
            }

            return false;
        }
        /// <summary>
        /// Parse the supplied XmlElement and populate the supplied ObjectDefinitionBuilder as required.
        /// </summary>
        /// <param name="xml">The object representation in XML.</param>
        /// <param name="builder">The builder used to build the object definition in Spring.</param>
        protected override void DoParse(XmlElement xml, ObjectDefinitionBuilder builder)
        {
            if (xml == null) throw new ArgumentNullException("xml", "The object description provided is null.");
            if (xml.OwnerDocument == null)  throw new ArgumentException("The xml provided to parse must have an owning document to obtain namespace information from.");

            // all behaviours with config being parsed have @respondsTo
            string respondsTo = xml.GetAttribute("responds-to");
            builder.AddConstructorArg(respondsTo);

            // now we're going to read any config defined within our behaviour identified
            // by its namespace "Inversion.Process.Behaviour"
            HashSet<IConfigurationElement> elements = new HashSet<IConfigurationElement>();
            XmlNamespaceManager ns = new XmlNamespaceManager(xml.OwnerDocument.NameTable);
            ns.AddNamespace("inv", "Inversion.Process.Behaviour");
            XmlNodeList frames = xml.SelectNodes("inv:*", ns);

            // do we have any config then?
            if (frames != null && frames.Count > 0) {
                int ordinal = 0;

                // we're going to read the config into tuples
                // of frame, slot, name, value
                foreach (XmlElement frameElement in frames) {
                    string frame = frameElement.Name;

                    // process any frame attributes as <frame slot="name" />
                    foreach (XmlAttribute pair in frameElement.Attributes) {
                        string slot = pair.Name;
                        string name = pair.Value;
                        IConfigurationElement element = new Configuration.Element(ordinal, frame, slot, name, String.Empty);
                        elements.Add(element);
                        ordinal++;
                    }

                    foreach (XmlElement slotElement in frameElement.ChildNodes) {
                        string slot = slotElement.Name;

                        int start = elements.Count;
                        // read children of slot as <name>value</name>
                        foreach (XmlElement pair in slotElement.ChildNodes) {
                            string name = pair.Name;
                            string value = pair.InnerText;
                            IConfigurationElement element = new Configuration.Element(ordinal, frame, slot, name, value);
                            elements.Add(element);
                            ordinal++;
                        }
                        // read attributes of slot as name="value"
                        foreach (XmlAttribute pair in slotElement.Attributes) {
                            string name = pair.Name;
                            string value = pair.Value;
                            IConfigurationElement element = new Configuration.Element(ordinal, frame, slot, name, value);
                            elements.Add(element);
                            ordinal++;
                        }

                        if (elements.Count == start) { // the slot had no name/value pairs
                            IConfigurationElement element = new Configuration.Element(ordinal, frame, slot, String.Empty, String.Empty);
                            elements.Add(element);
                            ordinal++;
                        }
                    }
                }
                builder.AddConstructorArg(elements);
            }
        }
        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));
        }
예제 #7
0
 /// <summary>Adds the constructor arg boolean 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="defaultValue">if set to <c>true</c> [default value].</param>
 public static void AddConstructorArgBooleanValueIfAttributeDefined(ObjectDefinitionBuilder builder, XmlElement element, string attributeName, bool defaultValue)
 {
     var value = element.GetAttribute(attributeName);
     if (!string.IsNullOrWhiteSpace(value))
     {
         builder.AddConstructorArg(new TypedStringValue(value));
     }
     else
     {
         builder.AddConstructorArg(defaultValue);
     }
 }
예제 #8
0
        /// <summary>Adds the constructor arg parent ref if attribute defined.</summary>
        /// <param name="builder">The builder.</param>
        /// <param name="element">The element.</param>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <returns><c>true</c> if [is attribute defined] [the specified element]; otherwise, <c>false</c>.</returns>
        public static bool AddConstructorArgParentRefIfAttributeDefined(ObjectDefinitionBuilder builder, XmlElement element, string attributeName)
        {
            var value = element.GetAttribute(attributeName);
            if (!string.IsNullOrWhiteSpace(value))
            {
                var child = ObjectDefinitionBuilder.GenericObjectDefinition();
                child.RawObjectDefinition.ParentName = value;
                builder.AddConstructorArg(child.ObjectDefinition);
                return true;
            }

            return false;
        }
예제 #9
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)
        {
            if (!NamespaceUtils.IsAttributeDefined(element, "name") && !NamespaceUtils.IsAttributeDefined(element, ID_ATTRIBUTE))
            {
                parserContext.ReaderContext.ReportFatalException(element, "Queue must have either id or name (or both)");
            }

            NamespaceUtils.AddConstructorArgValueIfAttributeDefined(builder, element, "name");

            if (!NamespaceUtils.IsAttributeDefined(element, "name"))
            {
                if (this.AttributeHasIllegalOverride(element, DURABLE_ATTRIBUTE, "false")
                    || this.AttributeHasIllegalOverride(element, EXCLUSIVE_ATTRIBUTE, "true")
                    || this.AttributeHasIllegalOverride(element, AUTO_DELETE_ATTRIBUTE, "true"))
                {
                    parserContext.ReaderContext.ReportFatalException(element, "Anonymous queue cannot specify durable='true', exclusive='false' or auto-delete='false'");
                    return;
                }
            }
            else
            {
                NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, DURABLE_ATTRIBUTE, false);
                NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, EXCLUSIVE_ATTRIBUTE, false);
                NamespaceUtils.AddConstructorArgBooleanValueIfAttributeDefined(builder, element, AUTO_DELETE_ATTRIBUTE, false);
            }

            var queueArguments = element.GetAttribute(ARGUMENTS);
            var argumentsElement = element.SelectChildElementByTagName(ARGUMENTS);

            if (argumentsElement != null)
            {
                var parser = new ObjectDefinitionParserHelper(parserContext);
                if (!string.IsNullOrWhiteSpace(queueArguments))
                {
                    parserContext.ReaderContext.ReportFatalException(element, "Queue may have either a queue-attributes attribute or element, but not both");
                }

                var map = parser.ParseMapElement(argumentsElement, builder.RawObjectDefinition);
                builder.AddConstructorArg(map);
            }

            if (!string.IsNullOrWhiteSpace(queueArguments))
            {
                builder.AddConstructorArgReference(queueArguments);
            }
        }