예제 #1
0
 /// <summary>
 /// Merges this object identifier value with another one. One of
 /// the two objects will be discarded and the other will be used
 /// as the merge destination and returned. Note that this
 /// operation modifies both this value and the specified value.
 /// The merge can only be made under certain conditions, for
 /// example that no child OID:s have name conflicts. It is also
 /// assumed that the two OID:s have the same numerical value.
 /// </summary>
 /// <param name="log">The MIB loader log</param>
 /// <param name="location">The file location on error</param>
 /// <param name="value">The OID value to merge with</param>
 /// <returns>The merged object identifier value</returns>
 /// <exception cref="MibException">
 /// If the merge couldn't be performed due to a conflict or
 /// invalid state.
 /// </exception>
 private ObjectIdentifierValue Merge(
     MibLoaderLog log,
     FileLocation location,
     ObjectIdentifierValue value)
 {
     if (this.symbol != null || (value.symbol == null && this.children.Count > 0))
     {
         this.AddChildren(log, location, value);
         return(this);
     }
     else
     {
         value.AddChildren(log, location, this);
         return(value);
     }
 }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ObjectIdentifierValue"/> class.
        /// </summary>
        /// <param name="location">The declaration file location</param>
        /// <param name="parent">The component parent</param>
        /// <param name="name">The component name</param>
        /// <param name="value">The component value</param>
        /// <exception cref="MibException">
        /// If the object identifier parent already has a child with
        /// the specified value
        /// </exception>
        public ObjectIdentifierValue(
            FileLocation location,
            ObjectIdentifierValue parent,
            string name,
            int value)
            : base("OBJECT IDENTIFIER")
        {
            this.parent = parent;
            this.name   = name;
            this.value  = value;
            if (parent.GetChildByValue(value) != null)
            {
                throw new MibException(
                          location,
                          "cannot add duplicate OID children with value " + value);
            }

            parent.AddChild(null, location, this);
        }
예제 #3
0
        /// <summary>
        /// Adds all the children from another object identifier value.
        /// The children are not copied, but actually transferred from the
        /// other value. If this value lacks a name component, it will be
        /// set from other value. This operation thus corresponds to a
        /// merge and thus can only be made under certain conditions. For
        /// example, no child OID:s may have name conflicts. It is assumed
        /// that the other OID has the same numerical value as this one.
        /// </summary>
        /// <param name="log">The MIB loader log</param>
        /// <param name="location">The file location on error</param>
        /// <param name="parent">The OID parent value for the children</param>
        /// <exception cref="MibException">If an irrecoverable conflict
        /// between two children occurred</exception>
        private void AddChildren(
            MibLoaderLog log,
            FileLocation location,
            ObjectIdentifierValue parent)
        {
            ObjectIdentifierValue child;
            string msg;

            if (this.name == null)
            {
                this.name = parent.name;
            }
            else if (parent.name != null && !parent.name.Equals(this.name))
            {
                msg = "OID component '" + parent.name + "' was previously " +
                      "defined as '" + this.name + "'";
                if (log == null)
                {
                    throw new MibException(location, msg);
                }
                else
                {
                    log.AddWarning(location, msg);
                }
            }

            if (parent.symbol != null)
            {
                throw new MibException(
                          location,
                          "INTERNAL ERROR: OID merge with symbol reference already set");
            }

            for (int i = 0; i < parent.children.Count; i++)
            {
                child        = parent.children[i];
                child.parent = this;
                this.AddChild(log, location, child);
            }

            parent.children = null;
        }