91 lines
3.1 KiB
C#
91 lines
3.1 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2008 - 2010 All Rights Reserved.
|
|
//
|
|
// File: CimObjectData.cs
|
|
//
|
|
// Contents: CimObjectData is a part of the CimFramework project.
|
|
// It contains an abstract class that keeps its internal data sorted alphabetically.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
using System;
|
|
using System.Collections;
|
|
using System.Xml;
|
|
using Intel.Manageability.Exceptions;
|
|
|
|
namespace Intel.Manageability.Cim.Untyped
|
|
{
|
|
/// <summary>
|
|
/// An abstract class that maintains its data sorted alphabetically.
|
|
/// This class is the base class for the untyped CIM class (CimObject).
|
|
/// </summary>
|
|
public abstract class CimObjectData : CimData
|
|
{
|
|
/// <summary>
|
|
/// Constructor that recieves the class name and namespace and constructs the object accordingly.
|
|
/// </summary>
|
|
/// <param name="className">The name of the class</param>
|
|
/// <param name="nameSpace">The namespace of the class</param>
|
|
protected CimObjectData(string className, string nameSpace)
|
|
: base(className, nameSpace)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copy constructor
|
|
/// </summary>
|
|
/// <param name="other">Object to be copied</param>
|
|
protected CimObjectData(CimObjectData other)
|
|
: base(other)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a new CIM Field
|
|
/// </summary>
|
|
/// <param name="name">Field name</param>
|
|
/// <param name="values">Array of field values</param>
|
|
public override void AddField(string name, string[] values)
|
|
{
|
|
//Arguments sanity check
|
|
if (values == null || containNullValue(values))
|
|
throw new ArgumentNullException("values");
|
|
|
|
if (ContainsField(name))
|
|
throw (new CimException(string.Format("AddField: Field \"{0}\" already exists", name)));
|
|
|
|
|
|
XmlElement root = XmlMembers.DocumentElement;
|
|
//Insert element sorted
|
|
foreach (string val in values)
|
|
{
|
|
//Create a new node
|
|
XmlElement elem = XmlMembers.CreateElement(root.Prefix, name, _xmlNamespace);
|
|
elem.InnerXml = val;
|
|
|
|
//Insert the element in a sorted way
|
|
IEnumerator ienum = XmlMembers.DocumentElement.GetEnumerator();
|
|
XmlNode currentNode = null;
|
|
bool found = false;
|
|
while (ienum.MoveNext())
|
|
{
|
|
currentNode = (XmlNode)ienum.Current;
|
|
if (String.Compare(currentNode.LocalName, name, false) > 0)
|
|
{
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
if (found)
|
|
{
|
|
root.InsertBefore(elem, currentNode);
|
|
}
|
|
else
|
|
{
|
|
root.AppendChild(elem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|