Added headers
[tpot/pegasus/.git] / src / Pegasus / Common / CIMInstanceRep.cpp
index f4d9738f1974a624466fd1c8c7f5e15f7d7afa8f..aa822c8f897cbd63d8668e0d213081dc3c3f0fe2 100644 (file)
-//%/////////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the "Software"),
-// to deal in the Software without restriction, including without limitation
-// the rights to use, copy, modify, merge, publish, distribute, sublicense,
-// and/or sell copies of the Software, and to permit persons to whom the
-// Software is furnished to do so, subject to the following conditions:
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-// DEALINGS IN THE SOFTWARE.
-//
-//==============================================================================
-//
-// Author: Mike Brasher (mbrasher@bmc.com)
-//
-// Modified By:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#include "CIMInstance.h"
-#include "DeclContext.h"
-#include "Indentor.h"
-#include "CIMName.h"
-#include "XmlWriter.h"
-
-PEGASUS_NAMESPACE_BEGIN
-
-CIMInstanceRep::CIMInstanceRep(const String& className)
-    : _className(className), _resolved(false)
-{
-    if (!CIMName::legal(className))
-       throw IllegalName();
-}
-
-CIMInstanceRep::~CIMInstanceRep()
-{
-
-}
-
-void CIMInstanceRep::addProperty(const CIMProperty& x)
-{
-    if (!x)
-       throw UnitializedHandle();
-
-    // Reject duplicate property names:
-
-    if (findProperty(x.getName()) != PEG_NOT_FOUND)
-       throw AlreadyExists();
-
-    // Note: class origin is resolved later:
-
-    // Append property:
-
-    _properties.append(x);
-}
-
-Uint32 CIMInstanceRep::findProperty(const String& name)
-{
-    for (Uint32 i = 0, n = _properties.size(); i < n; i++)
-    {
-       if (CIMName::equal(_properties[i].getName(), name))
-           return i;
-    }
-
-    return PEG_NOT_FOUND;
-}
-
-Boolean CIMInstanceRep::existsProperty(const String& name)
-{
-    return (findProperty(name) != PEG_NOT_FOUND) ?
-                   true : false;
-}
-
-CIMProperty CIMInstanceRep::getProperty(Uint32 pos)
-{
-    if (pos >= _properties.size())
-       throw OutOfBounds();
-
-    return _properties[pos];
-}
-
-void CIMInstanceRep::removeProperty(Uint32 pos)
-    {
-       if (pos >= _properties.size())
-           throw OutOfBounds();
-
-       _properties.remove(pos);
-    }
-
-
-Uint32 CIMInstanceRep::getPropertyCount() const
-{
-    return _properties.size();
-}
-
-
-void CIMInstanceRep::resolve(
-    DeclContext* context,
-    const String& nameSpace,
-    CIMConstClass& cimClassOut)
-{
-    // ATTN: Verify that references are initialized.
-
-#if 0
-    if (_resolved)
-       throw InstanceAlreadyResolved();
-#endif
-
-    if (!context)
-       throw NullPointer();
-
-    //----------------------------------------------------------------------
-    // First obtain the class:
-    //----------------------------------------------------------------------
-
-    CIMConstClass cimClass =
-       context->lookupClass(nameSpace, _className);
-
-    if (!cimClass)
-       throw PEGASUS_CIM_EXCEPTION(INVALID_CLASS, _className);
-
-    cimClassOut = cimClass;
-
-#if 0
-    if (!cimClass._rep->_resolved)
-       throw ClassNotResolved(_className);
-#endif
-
-    //----------------------------------------------------------------------
-    // Disallow instantiation of abstract classes.
-    //----------------------------------------------------------------------
-
-    if (cimClass.isAbstract())
-       throw InstantiatedAbstractClass();
-
-    //----------------------------------------------------------------------
-    // Validate the qualifiers of this class:
-    //----------------------------------------------------------------------
-
-    _qualifiers.resolve(
-       context,
-       nameSpace,
-       CIMScope::CLASS,
-       false,
-       cimClass._rep->_qualifiers);
-
-    //----------------------------------------------------------------------
-    // First iterate the properties of this instance and verify that
-    // each one is defined in the class and then resolve each one.
-    // Also set the class origin.
-    //----------------------------------------------------------------------
-
-    String classOrigin = cimClass.getClassName();
-
-    for (Uint32 i = 0, n = _properties.size(); i < n; i++)
-    {
-       CIMProperty& property = _properties[i];
-
-       Uint32 pos = cimClass.findProperty(property.getName());
-
-       if (pos == PEG_NOT_FOUND)
-           throw NoSuchProperty(property.getName());
-
-       property.resolve(context, nameSpace, true, cimClass.getProperty(pos));
-        property.setClassOrigin(classOrigin);
-    }
-
-    //----------------------------------------------------------------------
-    // Inject all properties from the class that are not included in the
-    // instance. Copy over the class-origin and set the propagated flag
-    // to true.
-    //----------------------------------------------------------------------
-
-    for (Uint32 i = 0, m = 0, n = cimClass.getPropertyCount(); i < n; i++)
-    {
-       CIMConstProperty property = cimClass.getProperty(i);
-       const String& name = property.getName();
-
-       // See if this instance already contains a property with this name:
-
-       Boolean found = false;
-
-       for (Uint32 j = m, n = _properties.size(); j < n; j++)
-       {
-           if (CIMName::equal(_properties[j].getName(), name))
-           {
-               found = true;
-               break;
-           }
-       }
-
-       if (!found)
-       {
-           CIMProperty p = property.clone();
-           p.setPropagated(true);
-           _properties.insert(m++, p);
-       }
-    }
-
-#if 0
-    _resolved = true;
-#endif
-}
-
-CIMInstanceRep::CIMInstanceRep()
-{
-
-}
-
-CIMInstanceRep::CIMInstanceRep(const CIMInstanceRep& x) :
-    Sharable(),
-    _className(x._className),
-    _resolved(x._resolved)
-{
-    x._qualifiers.cloneTo(_qualifiers);
-
-    _properties.reserve(x._properties.size());
-
-    for (Uint32 i = 0, n = x._properties.size(); i < n; i++)
-       _properties.append(x._properties[i].clone());
-}
-
-CIMInstanceRep& CIMInstanceRep::operator=(const CIMInstanceRep& x)
-{
-    return *this;
-}
-
-Boolean CIMInstanceRep::identical(const CIMInstanceRep* x) const
-{
-    if (_className != x->_className)
-       return false;
-
-    if (!_qualifiers.identical(x->_qualifiers))
-       return false;
-
-    // Compare properties:
-
-    {
-       const Array<CIMProperty>& tmp1 = _properties;
-       const Array<CIMProperty>& tmp2 = x->_properties;
-
-       if (tmp1.size() != tmp2.size())
-           return false;
-
-       for (Uint32 i = 0, n = tmp1.size(); i < n; i++)
-       {
-           if (!tmp1[i].identical(tmp2[i]))
-               return false;
-       }
-    }
-
-    if (_resolved != x->_resolved)
-       return false;
-
-    return true;
-}
-
-void CIMInstanceRep::toXml(Array<Sint8>& out) const
-{
-    // Class opening element:
-
-    out << "<INSTANCE ";
-    out << " CLASSNAME=\"" << _className << "\" ";
-    out << ">\n";
-
-    // Qualifiers:
-
-    _qualifiers.toXml(out);
-
-    // Parameters:
-
-    for (Uint32 i = 0, n = _properties.size(); i < n; i++)
-       _properties[i].toXml(out);
-
-    // Class closing element:
-
-    out << "</INSTANCE>\n";
-}
-
-void CIMInstanceRep::print(PEGASUS_STD(ostream) &os) const
-{
-    Array<Sint8> tmp;
-    toXml(tmp);
-    tmp.append('\0');
-    os << tmp.getData() << PEGASUS_STD(endl);
-}
-
-CIMReference CIMInstanceRep::getInstanceName(
-    const CIMConstClass& cimClass) const
-{
-    //--------------------------------------------------------------------------
-    // Get class name:
-    //--------------------------------------------------------------------------
-
-    String className = getClassName();
-
-    //--------------------------------------------------------------------------
-    // Get key names:
-    //--------------------------------------------------------------------------
-
-    Array<String> keyNames;
-    cimClass.getKeyNames(keyNames);
-
-    if (keyNames.size() == 0)
-       return CIMReference();
-
-    //--------------------------------------------------------------------------
-    // Get type and value for each key (building up key bindings):
-    //--------------------------------------------------------------------------
-
-    KeyBindingArray keyBindings;
-
-    for (Uint32 i = 0, n = keyNames.size(); i < n; i++)
-    {
-       const String& keyName = keyNames[i];
-
-       Uint32 pos = findProperty(keyName);
-       PEGASUS_ASSERT(pos != PEG_NOT_FOUND);
-
-       CIMConstProperty tmp = getProperty(pos);
-
-       if (CIMName::equal(tmp.getName(), keyName))
-       {
-           const CIMValue& value = tmp.getValue();
-
-           // ATTN-A: for now just assert:
-           if (value.isArray())
-               PEGASUS_ASSERT(false);
-
-           CIMType type = value.getType();
-           String valueStr;
-
-           KeyBinding::Type kbType = KeyBinding::STRING;
-
-           switch (type)
-           {
-               case CIMType::BOOLEAN:
-                   kbType = KeyBinding::BOOLEAN;
-                   valueStr = value.toString();
-                   break;
-
-               case CIMType::UINT8:
-               case CIMType::SINT8:
-               case CIMType::UINT16:
-               case CIMType::SINT16:
-               case CIMType::UINT32:
-               case CIMType::SINT32:
-               case CIMType::UINT64:
-               case CIMType::SINT64:
-               case CIMType::CHAR16:
-                   kbType = KeyBinding::NUMERIC;
-                   valueStr = value.toString();
-                   break;
-
-               case CIMType::STRING:
-               case CIMType::DATETIME:
-                   kbType = KeyBinding::STRING;
-                   valueStr = value.toString();
-                   break;
-
-               case CIMType::REFERENCE:
-               {
-                   kbType = KeyBinding::STRING;
-
-                   CIMReference tmpRef = value.toString();
-                   valueStr = tmpRef.toStringCanonical();
-                   break;
-               }
-
-               case CIMType::REAL32:
-               case CIMType::REAL64:
-                   PEGASUS_ASSERT(false);
-           }
-
-           keyBindings.append(KeyBinding(keyName, valueStr, kbType));
-       }
-    }
-
-    return CIMReference(String(), String(), className, keyBindings);
-}
-
-PEGASUS_NAMESPACE_END
+//%/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining a copy\r
+// of this software and associated documentation files (the "Software"), to \r
+// deal in the Software without restriction, including without limitation the \r
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or \r
+// sell copies of the Software, and to permit persons to whom the Software is\r
+// furnished to do so, subject to the following conditions:\r
+// \r
+// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN \r
+// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED\r
+// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT\r
+// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR \r
+// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN \r
+// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+//==============================================================================\r
+//\r
+// Author: Mike Brasher (mbrasher@bmc.com)\r
+//\r
+// Modified By:\r
+//\r
+//%/////////////////////////////////////////////////////////////////////////////\r
+\r
+#include "CIMInstance.h"\r
+#include "DeclContext.h"\r
+#include "Indentor.h"\r
+#include "CIMName.h"\r
+#include "XmlWriter.h"\r
+\r
+PEGASUS_NAMESPACE_BEGIN\r
+\r
+CIMInstanceRep::CIMInstanceRep(const String& className)\r
+    : _className(className), _resolved(false)\r
+{\r
+    if (!CIMName::legal(className))\r
+       throw IllegalName();\r
+}\r
+\r
+CIMInstanceRep::~CIMInstanceRep()\r
+{\r
+\r
+}\r
+\r
+void CIMInstanceRep::addProperty(const CIMProperty& x)\r
+{\r
+    if (!x)\r
+       throw UnitializedHandle();\r
+\r
+    // Reject duplicate property names:\r
+\r
+    if (findProperty(x.getName()) != PEG_NOT_FOUND)\r
+       throw AlreadyExists();\r
+\r
+    // Note: class origin is resolved later:\r
+\r
+    // Append property:\r
+\r
+    _properties.append(x);\r
+}\r
+\r
+Uint32 CIMInstanceRep::findProperty(const String& name)\r
+{\r
+    for (Uint32 i = 0, n = _properties.size(); i < n; i++)\r
+    {\r
+       if (CIMName::equal(_properties[i].getName(), name))\r
+           return i;\r
+    }\r
+\r
+    return PEG_NOT_FOUND;\r
+}\r
+\r
+Boolean CIMInstanceRep::existsProperty(const String& name)\r
+{\r
+    return (findProperty(name) != PEG_NOT_FOUND) ?\r
+                   true : false;\r
+}\r
+\r
+CIMProperty CIMInstanceRep::getProperty(Uint32 pos)\r
+{\r
+    if (pos >= _properties.size())\r
+       throw OutOfBounds();\r
+\r
+    return _properties[pos];\r
+}\r
+\r
+void CIMInstanceRep::removeProperty(Uint32 pos)\r
+    {\r
+       if (pos >= _properties.size())\r
+           throw OutOfBounds();\r
+\r
+       _properties.remove(pos);\r
+    }\r
+\r
+\r
+Uint32 CIMInstanceRep::getPropertyCount() const\r
+{\r
+    return _properties.size();\r
+}\r
+\r
+\r
+void CIMInstanceRep::resolve(\r
+    DeclContext* context,\r
+    const String& nameSpace,\r
+    CIMConstClass& cimClassOut)\r
+{\r
+    // ATTN: Verify that references are initialized.\r
+\r
+#if 0\r
+    if (_resolved)\r
+       throw InstanceAlreadyResolved();\r
+#endif\r
+\r
+    if (!context)\r
+       throw NullPointer();\r
+\r
+    //----------------------------------------------------------------------\r
+    // First obtain the class:\r
+    //----------------------------------------------------------------------\r
+\r
+    CIMConstClass cimClass =\r
+       context->lookupClass(nameSpace, _className);\r
+\r
+    if (!cimClass)\r
+       throw PEGASUS_CIM_EXCEPTION(INVALID_CLASS, _className);\r
+\r
+    cimClassOut = cimClass;\r
+\r
+#if 0\r
+    if (!cimClass._rep->_resolved)\r
+       throw ClassNotResolved(_className);\r
+#endif\r
+\r
+    //----------------------------------------------------------------------\r
+    // Disallow instantiation of abstract classes.\r
+    //----------------------------------------------------------------------\r
+\r
+    if (cimClass.isAbstract())\r
+       throw InstantiatedAbstractClass();\r
+\r
+    //----------------------------------------------------------------------\r
+    // Validate the qualifiers of this class:\r
+    //----------------------------------------------------------------------\r
+\r
+    _qualifiers.resolve(\r
+       context,\r
+       nameSpace,\r
+       CIMScope::CLASS,\r
+       false,\r
+       cimClass._rep->_qualifiers);\r
+\r
+    //----------------------------------------------------------------------\r
+    // First iterate the properties of this instance and verify that\r
+    // each one is defined in the class and then resolve each one.\r
+    // Also set the class origin.\r
+    //----------------------------------------------------------------------\r
+\r
+    String classOrigin = cimClass.getClassName();\r
+\r
+    for (Uint32 i = 0, n = _properties.size(); i < n; i++)\r
+    {\r
+       CIMProperty& property = _properties[i];\r
+\r
+       Uint32 pos = cimClass.findProperty(property.getName());\r
+\r
+       if (pos == PEG_NOT_FOUND)\r
+           throw NoSuchProperty(property.getName());\r
+\r
+       property.resolve(context, nameSpace, true, cimClass.getProperty(pos));\r
+        property.setClassOrigin(classOrigin);\r
+    }\r
+\r
+    //----------------------------------------------------------------------\r
+    // Inject all properties from the class that are not included in the\r
+    // instance. Copy over the class-origin and set the propagated flag\r
+    // to true.\r
+    //----------------------------------------------------------------------\r
+\r
+    for (Uint32 i = 0, m = 0, n = cimClass.getPropertyCount(); i < n; i++)\r
+    {\r
+       CIMConstProperty property = cimClass.getProperty(i);\r
+       const String& name = property.getName();\r
+\r
+       // See if this instance already contains a property with this name:\r
+\r
+       Boolean found = false;\r
+\r
+       for (Uint32 j = m, n = _properties.size(); j < n; j++)\r
+       {\r
+           if (CIMName::equal(_properties[j].getName(), name))\r
+           {\r
+               found = true;\r
+               break;\r
+           }\r
+       }\r
+\r
+       if (!found)\r
+       {\r
+           CIMProperty p = property.clone();\r
+           p.setPropagated(true);\r
+           _properties.insert(m++, p);\r
+       }\r
+    }\r
+\r
+#if 0\r
+    _resolved = true;\r
+#endif\r
+}\r
+\r
+CIMInstanceRep::CIMInstanceRep()\r
+{\r
+\r
+}\r
+\r
+CIMInstanceRep::CIMInstanceRep(const CIMInstanceRep& x) :\r
+    Sharable(),\r
+    _className(x._className),\r
+    _resolved(x._resolved)\r
+{\r
+    x._qualifiers.cloneTo(_qualifiers);\r
+\r
+    _properties.reserve(x._properties.size());\r
+\r
+    for (Uint32 i = 0, n = x._properties.size(); i < n; i++)\r
+       _properties.append(x._properties[i].clone());\r
+}\r
+\r
+CIMInstanceRep& CIMInstanceRep::operator=(const CIMInstanceRep& x)\r
+{\r
+    return *this;\r
+}\r
+\r
+Boolean CIMInstanceRep::identical(const CIMInstanceRep* x) const\r
+{\r
+    if (_className != x->_className)\r
+       return false;\r
+\r
+    if (!_qualifiers.identical(x->_qualifiers))\r
+       return false;\r
+\r
+    // Compare properties:\r
+\r
+    {\r
+       const Array<CIMProperty>& tmp1 = _properties;\r
+       const Array<CIMProperty>& tmp2 = x->_properties;\r
+\r
+       if (tmp1.size() != tmp2.size())\r
+           return false;\r
+\r
+       for (Uint32 i = 0, n = tmp1.size(); i < n; i++)\r
+       {\r
+           if (!tmp1[i].identical(tmp2[i]))\r
+               return false;\r
+       }\r
+    }\r
+\r
+    if (_resolved != x->_resolved)\r
+       return false;\r
+\r
+    return true;\r
+}\r
+\r
+void CIMInstanceRep::toXml(Array<Sint8>& out) const\r
+{\r
+    // Class opening element:\r
+\r
+    out << "<INSTANCE ";\r
+    out << " CLASSNAME=\"" << _className << "\" ";\r
+    out << ">\n";\r
+\r
+    // Qualifiers:\r
+\r
+    _qualifiers.toXml(out);\r
+\r
+    // Parameters:\r
+\r
+    for (Uint32 i = 0, n = _properties.size(); i < n; i++)\r
+       _properties[i].toXml(out);\r
+\r
+    // Class closing element:\r
+\r
+    out << "</INSTANCE>\n";\r
+}\r
+\r
+void CIMInstanceRep::print(PEGASUS_STD(ostream) &os) const\r
+{\r
+    Array<Sint8> tmp;\r
+    toXml(tmp);\r
+    tmp.append('\0');\r
+    os << tmp.getData() << PEGASUS_STD(endl);\r
+}\r
+\r
+CIMReference CIMInstanceRep::getInstanceName(\r
+    const CIMConstClass& cimClass) const\r
+{\r
+    //--------------------------------------------------------------------------\r
+    // Get class name:\r
+    //--------------------------------------------------------------------------\r
+\r
+    String className = getClassName();\r
+\r
+    //--------------------------------------------------------------------------\r
+    // Get key names:\r
+    //--------------------------------------------------------------------------\r
+\r
+    Array<String> keyNames;\r
+    cimClass.getKeyNames(keyNames);\r
+\r
+    if (keyNames.size() == 0)\r
+       return CIMReference();\r
+\r
+    //--------------------------------------------------------------------------\r
+    // Get type and value for each key (building up key bindings):\r
+    //--------------------------------------------------------------------------\r
+\r
+    KeyBindingArray keyBindings;\r
+\r
+    for (Uint32 i = 0, n = keyNames.size(); i < n; i++)\r
+    {\r
+       const String& keyName = keyNames[i];\r
+\r
+       Uint32 pos = findProperty(keyName);\r
+       PEGASUS_ASSERT(pos != PEG_NOT_FOUND);\r
+\r
+       CIMConstProperty tmp = getProperty(pos);\r
+\r
+       if (CIMName::equal(tmp.getName(), keyName))\r
+       {\r
+           const CIMValue& value = tmp.getValue();\r
+\r
+           // ATTN-A: for now just assert:\r
+           if (value.isArray())\r
+               PEGASUS_ASSERT(false);\r
+\r
+           CIMType type = value.getType();\r
+           String valueStr;\r
+\r
+           KeyBinding::Type kbType = KeyBinding::STRING;\r
+\r
+           switch (type)\r
+           {\r
+               case CIMType::BOOLEAN:\r
+                   kbType = KeyBinding::BOOLEAN;\r
+                   valueStr = value.toString();\r
+                   break;\r
+\r
+               case CIMType::UINT8:\r
+               case CIMType::SINT8:\r
+               case CIMType::UINT16:\r
+               case CIMType::SINT16:\r
+               case CIMType::UINT32:\r
+               case CIMType::SINT32:\r
+               case CIMType::UINT64:\r
+               case CIMType::SINT64:\r
+               case CIMType::CHAR16:\r
+                   kbType = KeyBinding::NUMERIC;\r
+                   valueStr = value.toString();\r
+                   break;\r
+\r
+               case CIMType::STRING:\r
+               case CIMType::DATETIME:\r
+                   kbType = KeyBinding::STRING;\r
+                   valueStr = value.toString();\r
+                   break;\r
+\r
+               case CIMType::REFERENCE:\r
+               {\r
+                   kbType = KeyBinding::STRING;\r
+\r
+                   CIMReference tmpRef = value.toString();\r
+                   valueStr = tmpRef.toStringCanonical();\r
+                   break;\r
+               }\r
+\r
+               case CIMType::REAL32:\r
+               case CIMType::REAL64:\r
+                   PEGASUS_ASSERT(false);\r
+           }\r
+\r
+           keyBindings.append(KeyBinding(keyName, valueStr, kbType));\r
+       }\r
+    }\r
+\r
+    return CIMReference(String(), String(), className, keyBindings);\r
+}\r
+\r
+PEGASUS_NAMESPACE_END\r