+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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 <Pegasus/Common/Config.h>
-#include <fstream>
-#include <Pegasus/Common/InternalException.h>
-#include <Pegasus/Common/FileSystem.h>
-#include <Pegasus/Common/Exception.h>
-#include "AssocClassTable.h"
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-#define ASSOC_CLASS_NAME_INDEX 0
-#define FROM_CLASS_NAME_INDEX 1
-#define FROM_PROPERTY_NAME_INDEX 2
-#define TO_CLASS_NAME_INDEX 3
-#define TO_PROPERTY_NAME_INDEX 4
-#define NUM_FIELDS 5
-
-static inline Boolean _MatchNoCase(const String& x, const String& pattern)
-{
- return pattern.size() == 0 || String::equalNoCase(x, pattern);
-}
-
-static String _Escape(const String& str)
-{
- String result;
-
- for (Uint32 i = 0, n = str.size(); i < n; i++)
- {
- Char16 c = str[i];
-
- switch (c)
- {
- case '\n':
- result += "\\n";
- break;
-
- case '\r':
- result += "\\r";
- break;
-
- case '\t':
- result += "\\t";
- break;
-
- case '\f':
- result += "\\f";
- break;
-
- case '\\':
- result += "\\\\";
- break;
-
- default:
- result += c;
- }
- }
-
- return result;
-}
-
-static String _Unescape(const String& str)
-{
- String result;
-
- for (Uint32 i = 0, n = str.size(); i < n; i++)
- {
- Char16 c = str[i];
-
- if (c == '\\')
- {
- if (i + 1 == n)
- break;
-
- c = str[i + 1];
-
- switch (c)
- {
- case 'n':
- result += "\n";
- break;
-
- case 'r':
- result += "\r";
- break;
-
- case 't':
- result += "\t";
- break;
-
- case 'f':
- result += "\f";
- break;
-
- default:
- result += c;
- }
-
- i++;
- }
- else
- result += c;
- }
-
- return result;
-}
-
-static Boolean _GetRecord(ifstream& is, Array<String>& fields)
-{
- fields.clear();
- String line;
-
- for (Uint32 i = 0; i < NUM_FIELDS; i++)
- {
- if (!GetLine(is, line))
- return false;
-
- fields.append(_Unescape(line));
- }
-
- // Skip the blank line:
-
- if (!GetLine(is, line))
- return false;
-
- return true;
-}
-
-static void _PutRecord(ofstream& os, Array<String>& fields)
-{
- for (Uint32 i = 0, n = fields.size(); i < n; i++)
- os << _Escape(fields[i]) << endl;
- os << endl;
-}
-
-void AssocClassTable::append(
- PEGASUS_STD(ofstream)& os,
- const String& assocClassName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toClassName,
- const String& toPropertyName)
-{
- Array<String> fields;
- fields.reserveCapacity(5);
- fields.append(assocClassName);
- fields.append(fromClassName);
- fields.append(fromPropertyName);
- fields.append(toClassName);
- fields.append(toPropertyName);
-
- _PutRecord(os, fields);
-}
-
-void AssocClassTable::append(
- const String& path,
- const String& assocClassName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toClassName,
- const String& toPropertyName)
-{
- // Open input file:
-
- ofstream os;
-
- if (!OpenAppend(os, path))
- throw CannotOpenFile(path);
-
- // Insert the entry:
-
- Array<String> fields;
- fields.reserveCapacity(5);
- fields.append(assocClassName);
- fields.append(fromClassName);
- fields.append(fromPropertyName);
- fields.append(toClassName);
- fields.append(toPropertyName);
-
- _PutRecord(os, fields);
-}
-
-Boolean AssocClassTable::deleteAssociation(
- const String& path,
- const String& assocClassName)
-{
- // Open input file:
-
- ifstream is;
-
- if (!Open(is, path))
- return false;
-
- // Open output file:
-
- String tmpPath = path + ".tmp";
- ofstream os;
-
- if (!Open(os, tmpPath))
- throw CannotOpenFile(tmpPath);
-
- // Copy over all lines except ones with the given association instance name:
-
- Array<String> fields;
- Boolean found = false;
-
- while (_GetRecord(is, fields))
- {
- if (assocClassName != fields[ASSOC_CLASS_NAME_INDEX])
- {
- _PutRecord(os, fields);
- found = true;
- }
- }
-
- // Close both files:
-
- is.close();
- os.close();
-
- // Remove orginal file:
-
- if (!FileSystem::removeFile(path))
- throw CannotRemoveFile(path);
-
- // Rename back to original name:
-
- if (!FileSystem::renameFile(tmpPath, path))
- throw CannotRenameFile(path);
-
- return found;
-}
-
-Boolean AssocClassTable::getAssociatorNames(
- const String& path,
- const String& className,
- const String& assocClass,
- const String& resultClass,
- const String& role,
- const String& resultRole,
- Array<String>& associatorNames)
-{
- // Open input file:
-
- ifstream is;
-
- if (!Open(is, path))
- return false;
-
- // For each line:
-
- Array<String> fields;
- Boolean found = false;
-
-
- while (_GetRecord(is, fields))
- {
- if (_MatchNoCase(className, fields[FROM_CLASS_NAME_INDEX]) &&
- _MatchNoCase(fields[ASSOC_CLASS_NAME_INDEX], assocClass) &&
- _MatchNoCase(fields[TO_CLASS_NAME_INDEX], resultClass) &&
- _MatchNoCase(fields[FROM_PROPERTY_NAME_INDEX], role) &&
- _MatchNoCase(fields[TO_PROPERTY_NAME_INDEX], resultRole))
- {
- associatorNames.append(fields[TO_CLASS_NAME_INDEX]);
- found = true;
- }
- }
-
- return found;
-}
-
-Boolean AssocClassTable::getReferenceNames(
- const String& path,
- const String& className,
- const String& resultClass,
- const String& role,
- Array<String>& referenceNames)
-{
- // Open input file:
-
- ifstream is;
-
- if (!Open(is, path))
- return false;
-
- // For each line:
-
- Array<String> fields;
- Boolean found = false;
-
- while (_GetRecord(is, fields))
- {
- if (_MatchNoCase(className, fields[FROM_CLASS_NAME_INDEX]) &&
- _MatchNoCase(fields[ASSOC_CLASS_NAME_INDEX], resultClass) &&
- _MatchNoCase(fields[FROM_PROPERTY_NAME_INDEX], role))
- {
- if (!Contains(referenceNames, fields[ASSOC_CLASS_NAME_INDEX]))
- referenceNames.append(fields[ASSOC_CLASS_NAME_INDEX]);
- found = true;
- }
- }
-
- return found;
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#ifndef Pegasus_AssocClassTable_h
-#define Pegasus_AssocClassTable_h
-
-#include <iostream>
-#include <fstream>
-#include <Pegasus/Common/Config.h>
-#include <Pegasus/Common/CIMObjectPath.h>
-#include <Pegasus/Common/String.h>
-#include <Pegasus/Common/ArrayInternal.h>
-
-PEGASUS_NAMESPACE_BEGIN
-
-/** Maintains all associations for a given namesspace.
-*/
-class PEGASUS_REPOSITORY_LINKAGE AssocClassTable
-{
-public:
-
- /** Appends a row into the association class table. There is no checking
- for duplicate entries (the caller ensures this). The case of
- the arguments doesn't matter. They are ignored during comparison.
- */
- static void append(
- PEGASUS_STD(ofstream)& os,
- const String& assocClassName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toClassName,
- const String& toPropertyName);
-
- /** Appends a row into the association class table. There is no checking
- for duplicate entries (the caller ensures this). The case of the
- arguments doesn't matter. Case is ignored during comparison.
- */
- static void append(
- const String& path,
- const String& assocClassName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toClassName,
- const String& toPropertyName);
-
- /** Deletes the given association from the table by removing every entry
- with the given assocClassName.
- @returns true if such an association was found.
- */
- static Boolean deleteAssociation(
- const String& path,
- const String& assocClassName);
-
- /** Finds all associators of the given class. See
- CIMOperations::associators() for a full description.
- */
- static Boolean getAssociatorNames(
- const String& path,
- const String& className,
- const String& assocClass,
- const String& resultClass,
- const String& role,
- const String& resultRole,
- Array<String>& associatorNames);
-
- /** Obtain all references (association instance names) in which the
- given class involved. See CIMOperations::associators() for a
- full description.
- */
- static Boolean getReferenceNames(
- const String& path,
- const String& className,
- const String& resultClass,
- const String& role,
- Array<String>& referenceNames);
-
-private:
-
- AssocClassTable() { /* private */ }
-};
-
-PEGASUS_NAMESPACE_END
-
-#endif /* Pegasus_AssocClassTable_h */
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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 <Pegasus/Common/Config.h>
-#include <fstream>
-#include <Pegasus/Common/InternalException.h>
-#include <Pegasus/Common/FileSystem.h>
-#include <Pegasus/Common/Exception.h>
-#include "AssocInstTable.h"
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-#define ASSOC_INSTANCE_NAME_INDEX 0
-#define ASSOC_CLASS_NAME_INDEX 1
-#define FROM_OBJECT_NAME_INDEX 2
-#define FROM_CLASS_NAME_INDEX 3
-#define FROM_PROPERTY_NAME_INDEX 4
-#define TO_OBJECT_NAME_INDEX 5
-#define TO_CLASS_NAME_INDEX 6
-#define TO_PROPERTY_NAME_INDEX 7
-#define NUM_FIELDS 8
-
-static inline Boolean _MatchNoCase(const String& x, const String& pattern)
-{
- return pattern.size() == 0 || String::equalNoCase(x, pattern);
-}
-
-static String _Escape(const String& str)
-{
- String result;
-
- for (Uint32 i = 0, n = str.size(); i < n; i++)
- {
- Char16 c = str[i];
-
- switch (c)
- {
- case '\n':
- result += "\\n";
- break;
-
- case '\r':
- result += "\\r";
- break;
-
- case '\t':
- result += "\\t";
- break;
-
- case '\f':
- result += "\\f";
- break;
-
- case '\\':
- result += "\\\\";
- break;
-
- default:
- result += c;
- }
- }
-
- return result;
-}
-
-static String _Unescape(const String& str)
-{
- String result;
-
- for (Uint32 i = 0, n = str.size(); i < n; i++)
- {
- Char16 c = str[i];
-
- if (c == '\\')
- {
- if (i + 1 == n)
- break;
-
- c = str[i + 1];
-
- switch (c)
- {
- case 'n':
- result += "\n";
- break;
-
- case 'r':
- result += "\r";
- break;
-
- case 't':
- result += "\t";
- break;
-
- case 'f':
- result += "\f";
- break;
-
- default:
- result += c;
- }
-
- i++;
- }
- else
- result += c;
- }
-
- return result;
-}
-
-static Boolean _GetRecord(ifstream& is, Array<String>& fields)
-{
- fields.clear();
- String line;
-
- for (Uint32 i = 0; i < NUM_FIELDS; i++)
- {
- if (!GetLine(is, line))
- return false;
-
- fields.append(_Unescape(line));
- }
-
- // Skip the blank line:
-
- if (!GetLine(is, line))
- return false;
-
- return true;
-}
-
-static void _PutRecord(ofstream& os, Array<String>& fields)
-{
- for (Uint32 i = 0, n = fields.size(); i < n; i++)
- os << _Escape(fields[i]) << endl;
- os << endl;
-}
-
-void AssocInstTable::append(
- PEGASUS_STD(ofstream)& os,
- const String& assocInstanceName,
- const String& assocClassName,
- const String& fromInstanceName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toInstanceName,
- const String& toClassName,
- const String& toPropertyName)
-{
- Array<String> fields;
- fields.reserveCapacity(8);
- fields.append(assocInstanceName);
- fields.append(assocClassName);
- fields.append(fromInstanceName);
- fields.append(fromClassName);
- fields.append(fromPropertyName);
- fields.append(toInstanceName);
- fields.append(toClassName);
- fields.append(toPropertyName);
-
- _PutRecord(os, fields);
-}
-
-void AssocInstTable::append(
- const String& path,
- const String& assocInstanceName,
- const String& assocClassName,
- const String& fromInstanceName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toInstanceName,
- const String& toClassName,
- const String& toPropertyName)
-{
- // Open input file:
-
- ofstream os;
-
- if (!OpenAppend(os, path))
- throw CannotOpenFile(path);
-
- // Insert the entry:
-
- Array<String> fields;
- fields.reserveCapacity(8);
- fields.append(assocInstanceName);
- fields.append(assocClassName);
- fields.append(fromInstanceName);
- fields.append(fromClassName);
- fields.append(fromPropertyName);
- fields.append(toInstanceName);
- fields.append(toClassName);
- fields.append(toPropertyName);
-
- _PutRecord(os, fields);
-}
-
-Boolean AssocInstTable::deleteAssociation(
- const String& path,
- const CIMObjectPath& assocInstanceName)
-{
- // Open input file:
-
- ifstream is;
-
- if (!Open(is, path))
- return false;
-
- // Open output file:
-
- String tmpPath = path + ".tmp";
- ofstream os;
-
- if (!Open(os, tmpPath))
- throw CannotOpenFile(tmpPath);
-
- // Copy over all lines except ones with the given association instance name:
-
- Array<String> fields;
- Boolean found = false;
-
- while (_GetRecord(is, fields))
- {
- if (assocInstanceName != fields[ASSOC_INSTANCE_NAME_INDEX])
- {
- _PutRecord(os, fields);
- found = true;
- }
- }
-
- // Close both files:
-
- is.close();
- os.close();
-
- // Remove orginal file:
-
- if (!FileSystem::removeFile(path))
- throw CannotRemoveFile(path);
-
- // Rename back to original name:
-
- if (!FileSystem::renameFile(tmpPath, path))
- throw CannotRenameFile(path);
-
- return found;
-}
-
-Boolean AssocInstTable::getAssociatorNames(
- const String& path,
- const CIMObjectPath& instanceName,
- const String& assocClass,
- const String& resultClass,
- const String& role,
- const String& resultRole,
- Array<String>& associatorNames)
-{
- // Open input file:
-
- ifstream is;
-
- if (!Open(is, path))
- return false;
-
- // For each line:
-
- Array<String> fields;
- Boolean found = false;
-
- while (_GetRecord(is, fields))
- {
- if (instanceName == fields[FROM_OBJECT_NAME_INDEX] &&
- _MatchNoCase(fields[ASSOC_CLASS_NAME_INDEX], assocClass) &&
- _MatchNoCase(fields[TO_CLASS_NAME_INDEX], resultClass) &&
- _MatchNoCase(fields[FROM_PROPERTY_NAME_INDEX], role) &&
- _MatchNoCase(fields[TO_PROPERTY_NAME_INDEX], resultRole))
- {
- associatorNames.append(fields[TO_OBJECT_NAME_INDEX]);
- found = true;
- }
- }
-
- return found;
-}
-
-Boolean AssocInstTable::getReferenceNames(
- const String& path,
- const CIMObjectPath& instanceName,
- const String& resultClass,
- const String& role,
- Array<String>& referenceNames)
-{
- // Open input file:
-
- ifstream is;
-
- if (!Open(is, path))
- return false;
-
- // For each line:
-
- Array<String> fields;
- Boolean found = false;
-
- while (_GetRecord(is, fields))
- {
- if (instanceName == fields[FROM_OBJECT_NAME_INDEX] &&
- _MatchNoCase(fields[ASSOC_CLASS_NAME_INDEX], resultClass) &&
- _MatchNoCase(fields[FROM_PROPERTY_NAME_INDEX], role))
- {
- if (!Contains(referenceNames, fields[ASSOC_INSTANCE_NAME_INDEX]))
- referenceNames.append(fields[ASSOC_INSTANCE_NAME_INDEX]);
- found = true;
- }
- }
-
- return found;
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#ifndef Pegasus_AssocInstTable_h
-#define Pegasus_AssocInstTable_h
-
-#include <iostream>
-#include <fstream>
-#include <Pegasus/Common/Config.h>
-#include <Pegasus/Common/CIMObjectPath.h>
-#include <Pegasus/Common/String.h>
-#include <Pegasus/Common/ArrayInternal.h>
-
-PEGASUS_NAMESPACE_BEGIN
-
-/** Maintains all associations for a given namesspace.
-*/
-class PEGASUS_REPOSITORY_LINKAGE AssocInstTable
-{
-public:
-
- /** Appends a row into the association table. There is no checking
- for duplicate entries (the caller ensures this). The case of
- the arguments doesn't matter. They are ignored during comparison.
- */
- static void append(
- PEGASUS_STD(ofstream)& os,
- const String& assocInstanceName,
- const String& assocClassName,
- const String& fromInstanceName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toInstanceName,
- const String& toClassName,
- const String& toPropertyName);
-
- /** Appends a row into the association table. There is no checking
- for duplicate entries (the caller ensures this). The case of the
- arguments doesn't matter. Case is ignored during comparison.
- */
- static void append(
- const String& path,
- const String& assocInstanceName,
- const String& assocClassName,
- const String& fromInstanceName,
- const String& fromClassName,
- const String& fromPropertyName,
- const String& toInstanceName,
- const String& toClassName,
- const String& toPropertyName);
-
- /** Deletes the given association from the table by removing every entry
- with an assocInstanceName equal to the assocInstanceName parameter.
- @returns true if such an association was found.
- */
- static Boolean deleteAssociation(
- const String& path,
- const CIMObjectPath& assocInstanceName);
-
- /** Finds all associators of the given object. See
- CIMOperations::associators() for a full description.
- */
- static Boolean getAssociatorNames(
- const String& path,
- const CIMObjectPath& objectName,
- const String& assocClass,
- const String& resultClass,
- const String& role,
- const String& resultRole,
- Array<String>& associatorNames);
-
- /** Obtain all references (association instance names) in which the
- given object is involved. See CIMOperations::associators() for a
- full description.
- */
- static Boolean getReferenceNames(
- const String& path,
- const CIMObjectPath& objectName,
- const String& resultClass,
- const String& role,
- Array<String>& referenceNames);
-
-private:
-
- AssocInstTable() { /* private */ }
-};
-
-PEGASUS_NAMESPACE_END
-
-#endif /* Pegasus_AssocInstTable_h */
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
-// Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
-// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
-// Karl Schopmeyer (k.schopmeyer@opengroup.org)
-// Carol Ann Krug Graves, Hewlett-Packard Company
-// (carolann_graves@hp.com)
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#include <Pegasus/Common/Config.h>
-#include <cctype>
-#include <cstdio>
-#include <fstream>
-#include <Pegasus/Common/Pair.h>
-#include <Pegasus/Common/Destroyer.h>
-#include <Pegasus/Common/FileSystem.h>
-#include <Pegasus/Common/InternalException.h>
-#include <Pegasus/Common/XmlReader.h>
-#include <Pegasus/Common/XmlWriter.h>
-#include <Pegasus/Common/DeclContext.h>
-#include <Pegasus/Common/Resolver.h>
-#include <Pegasus/Common/System.h>
-#include <Pegasus/Repository/CIMRepository.h>
-#include "RepositoryDeclContext.h"
-#include "InstanceIndexFile.h"
-#include "InstanceFile.h"
-#include "AssocInstTable.h"
-#include "AssocClassTable.h"
-
-#define INDENT_XML_FILES
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// _LoadObject()
-//
-// Loads objects (classes and qualifiers) from disk to
-// memory objects.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-template<class Object>
-void _LoadObject(
- const String& path,
- Object& object)
-{
- // Get the real path of the file:
-
- String realPath;
-
- if (!FileSystem::existsNoCase(path, realPath))
- throw CannotOpenFile(path);
-
- // Load file into memory:
-
- Array<Sint8> data;
- FileSystem::loadFileToMemory(data, realPath);
- data.append('\0');
-
- XmlParser parser((char*)data.getData());
-
- XmlReader::getObject(parser, object);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// _SaveObject()
-//
-// Saves objects (classes and qualifiers) from memory to
-// disk files.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-template<class Object>
-void _SaveObject(const String& path, const Object& object)
-{
- Array<Sint8> out;
- object.toXml(out);
-
- PEGASUS_STD(ofstream) os(path.getCString() PEGASUS_IOS_BINARY);
-
- if (!os)
- throw CannotOpenFile(path);
-
-#ifdef INDENT_XML_FILES
- out.append('\0');
- XmlWriter::indentedPrint(os, out.getData(), 2);
-#else
- os.write((char*)out.getData(), out.size());
-#endif
-}
-
-static String _MakeAssocInstPath(
- const String& nameSpace,
- const String& repositoryRoot)
-{
- String tmp = nameSpace;
- tmp.translate('/', '#');
- return String(Cat(repositoryRoot, "/", tmp, "/instances/associations"));
-}
-
-static String _MakeAssocClassPath(
- const String& nameSpace,
- const String& repositoryRoot)
-{
- String tmp = nameSpace;
- tmp.translate('/', '#');
- return String(Cat(repositoryRoot, "/", tmp, "/classes/associations"));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// CIMRepository
-//
-// The following are not implemented:
-//
-// CIMRepository::execQuery()
-// CIMRepository::referencesNames()
-// CIMRepository::invokeMethod()
-//
-// Note that invokeMethod() will never implemented since it is not
-// meaningful for a repository.
-//
-// ATTN: make operations on files non-case-sensitive.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-CIMRepository::CIMRepository(const String& repositoryRoot)
- : _repositoryRoot(repositoryRoot), _nameSpaceManager(repositoryRoot),
- _lock()
-{
- _context = new RepositoryDeclContext(this);
- _isDefaultInstanceProvider = (ConfigManager::getInstance()->getCurrentValue(
- "repositoryIsDefaultInstanceProvider") == "true");
- _providerName = ConfigManager::getInstance()->getCurrentValue(
- "repositoryProviderName");
-}
-
-CIMRepository::~CIMRepository()
-{
- delete _context;
-}
-
-
-void CIMRepository::read_lock(void) throw(IPCException)
-{
- _lock.wait_read(pegasus_thread_self());
-}
-
-void CIMRepository::read_unlock(void)
-{
- _lock.unlock_read(pegasus_thread_self());
-}
-
-void CIMRepository::write_lock(void) throw(IPCException)
-{
- _lock.wait_write(pegasus_thread_self());
-}
-
-void CIMRepository::write_unlock(void)
-{
- _lock.unlock_write(pegasus_thread_self());
-}
-
-CIMClass CIMRepository::getClass(
- const String& nameSpace,
- const String& className,
- Boolean localOnly,
- Boolean includeQualifiers,
- Boolean includeClassOrigin,
- const CIMPropertyList& propertyList)
-{
- // ATTN: localOnly, includeQualifiers, and includeClassOrigin are ignored
- // for now.
-
- String classFilePath;
- classFilePath = _nameSpaceManager.getClassFilePath(nameSpace, className);
-
- CIMClass cimClass;
-
- try
- {
- _LoadObject(classFilePath, cimClass);
- }
- catch (Exception & e)
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, className);
- }
-
- return cimClass;
-}
-
-//----------------------------------------------------------------------
-//
-// _getInstanceIndex()
-//
-// Returns the index (or byte location) and size of the instance
-// record in the instance file for a given instance. Returns false
-// if the instance cannot be found.
-//
-//----------------------------------------------------------------------
-
-Boolean CIMRepository::_getInstanceIndex(
- const String& nameSpace,
- const CIMObjectPath& instanceName,
- String& className,
- Uint32& size,
- Uint32& index,
- Boolean searchSuperClasses) const
-{
- // -- Get all descendent classes of this class:
-
- className = instanceName.getClassName();
-
- Array<String> classNames;
- _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
- classNames.prepend(className);
-
- // -- Get all superclasses of this one:
-
- if (searchSuperClasses)
- _nameSpaceManager.getSuperClassNames(nameSpace, className, classNames);
-
- // -- Get instance names from each qualifying instance file for the class
-
- for (Uint32 i = 0; i < classNames.size(); i++)
- {
- CIMObjectPath tmpInstanceName = instanceName;
- tmpInstanceName.setClassName(classNames[i]);
-
- // -- Lookup index of instance:
-
- String path = _getIndexFilePath(nameSpace, classNames[i]);
-
- if (InstanceIndexFile::lookup(path, tmpInstanceName, size, index))
- {
- className = classNames[i];
- return true;
- }
- }
-
- return false;
-}
-
-CIMInstance CIMRepository::getInstance(
- const String& nameSpace,
- const CIMObjectPath& instanceName,
- Boolean localOnly,
- Boolean includeQualifiers,
- Boolean includeClassOrigin,
- const CIMPropertyList& propertyList)
-{
- // -- Get the index for this instance:
-
- String className;
- Uint32 index;
- Uint32 size;
-
- if (!_getInstanceIndex(nameSpace, instanceName, className, size, index))
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
- }
-
- // -- Load the instance from file:
-
- String path = _getInstanceFilePath(nameSpace, className);
- CIMInstance cimInstance;
- if (!_loadInstance(path, cimInstance, index, size))
- {
- throw CannotOpenFile(path);
- }
-
- return cimInstance;
-}
-
-void CIMRepository::deleteClass(
- const String& nameSpace,
- const String& className)
-{
- // -- Get the class and check to see if it is an association class:
-
- CIMClass cimClass = getClass(nameSpace, className, false);
- Boolean isAssociation = cimClass.isAssociation();
-
- // -- Disallow deletion if class has instances:
-
- String path = _getIndexFilePath(nameSpace, className);
- String realPath;
-
- if (FileSystem::existsNoCase(path, realPath))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_CLASS_HAS_INSTANCES, className);
-
- // -- Delete the class (disallowed if there are subclasses):
-
- _nameSpaceManager.deleteClass(nameSpace, className);
-
- // -- Remove association:
-
- if (isAssociation)
- {
- String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
-
- if (FileSystem::exists(assocFileName))
- AssocClassTable::deleteAssociation(assocFileName, className);
- }
-}
-
-void CIMRepository::deleteInstance(
- const String& nameSpace,
- const CIMObjectPath& instanceName)
-{
- String errMessage;
-
- // -- Lookup instance from the index file:
-
- String indexFilePath = _getIndexFilePath(
- nameSpace, instanceName.getClassName());
-
- Uint32 index;
- Uint32 size;
-
- if (!InstanceIndexFile::lookup(indexFilePath, instanceName, size, index))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
-
- // -- Remove entry from index file:
-
- if (!InstanceIndexFile::remove(indexFilePath, instanceName))
- {
- errMessage.append("Failed to delete instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- Remove the instance from the instance file:
-
- String instanceFilePath = _getInstanceFilePath(
- nameSpace, instanceName.getClassName());
-
- if (!InstanceFile::removeInstance(instanceFilePath, size, index))
- {
- errMessage.append("Failed to delete instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- Rename the temporary index and instance files back to the original:
-
- if (!_renameTempInstanceAndIndexFiles(indexFilePath, instanceFilePath))
- {
- errMessage.append("Unexpected error occurred while deleting instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- Remove it from the association table (if it is really association).
- // -- We ignore the return value intentionally. If it is an association,
- // -- true is returned. Otherwise, true is returned.
-
- String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
-
- if (FileSystem::exists(assocFileName))
- AssocInstTable::deleteAssociation(assocFileName, instanceName);
-}
-
-void CIMRepository::_createAssocClassEntries(
- const String& nameSpace,
- const CIMConstClass& assocClass)
-{
- // Open input file:
-
- String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
- ofstream os;
-
- if (!OpenAppend(os, assocFileName))
- throw CannotOpenFile(assocFileName);
-
- // Get the association's class name:
-
- String assocClassName = assocClass.getClassName();
-
- // For each property:
-
- Uint32 n = assocClass.getPropertyCount();
-
- for (Uint32 i = 0; i < n; i++)
- {
- CIMConstProperty fromProp = assocClass.getProperty(i);
-
- if (fromProp.getType() == CIMTYPE_REFERENCE)
- {
- for (Uint32 j = 0; j < n; j++)
- {
- CIMConstProperty toProp = assocClass.getProperty(j);
-
- if (toProp.getType() == CIMTYPE_REFERENCE &&
- fromProp.getName() != toProp.getName())
- {
- String fromClassName = fromProp.getReferenceClassName();
- String fromPropertyName = fromProp.getName();
- String toClassName = toProp.getReferenceClassName();
- String toPropertyName = toProp.getName();
-
- AssocClassTable::append(
- os,
- assocClassName,
- fromClassName,
- fromPropertyName,
- toClassName,
- toPropertyName);
- }
- }
- }
- }
-}
-
-void CIMRepository::createClass(
- const String& nameSpace,
- const CIMClass& newClass)
-{
- // -- Resolve the class:
- CIMClass cimClass(newClass);
-
- Resolver::resolveClass (cimClass, _context, nameSpace);
-
- // -- If an association, populate associations file:
-
- if (cimClass.isAssociation())
- _createAssocClassEntries(nameSpace, cimClass);
-
- // -- Create namespace manager entry:
-
- String classFilePath;
-
- _nameSpaceManager.createClass(nameSpace, cimClass.getClassName(),
- cimClass.getSuperClassName(), classFilePath);
-
- // -- Create the class file:
-
- _SaveObject(classFilePath, cimClass);
-}
-
-/*------------------------------------------------------------------------------
-
- This routine does the following:
-
- 1. Creates two entries in the association file for each relationship
- formed by this new assocation instance. A binary association
- (one with two references) ties two instances together. Suppose
- there are two instances: I1 and I2. Then two entries are created:
-
- I2 -> I1
- I1 -> I2
-
- For a ternary relationship, six entries will be created. Suppose
- there are three instances: I1, I2, and I3:
-
- I1 -> I2
- I1 -> I3
- I2 -> I1
- I2 -> I3
- I3 -> I1
- I3 -> I2
-
- So for an N-ary relationship, there will be 2*N entries created.
-
- 2. Verifies that the association instance refers to real objects.
- (note that an association reference may refer to either an instance
- or a class). Throws an exception if one of the references does not
- refer to a valid object.
-
-------------------------------------------------------------------------------*/
-
-void CIMRepository::_createAssocInstEntries(
- const String& nameSpace,
- const CIMConstClass& cimClass,
- const CIMInstance& cimInstance,
- const CIMObjectPath& instanceName)
-{
- // Open input file:
-
- String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
- ofstream os;
-
- if (!OpenAppend(os, assocFileName))
- throw CannotOpenFile(assocFileName);
-
- // Get the association's instance name and class name:
-
- String assocInstanceName = instanceName.toString();
- String assocClassName = instanceName.getClassName();
-
- // For each property:
-
- for (Uint32 i = 0, n = cimInstance.getPropertyCount(); i < n; i++)
- {
- CIMConstProperty fromProp = cimInstance.getProperty(i);
-
- // If a reference property:
-
- if (fromProp.getType() == CIMTYPE_REFERENCE)
- {
- // For each property:
-
- for (Uint32 j = 0, n = cimInstance.getPropertyCount(); j < n; j++)
- {
- CIMConstProperty toProp = cimInstance.getProperty(j);
-
- // If a reference property and not the same property:
-
- if (toProp.getType() == CIMTYPE_REFERENCE &&
- fromProp.getName() != toProp.getName())
- {
- CIMObjectPath fromRef;
- fromProp.getValue().get(fromRef);
-
- CIMObjectPath toRef;
- toProp.getValue().get(toRef);
-
- String fromObjectName = fromRef.toString();
- String fromClassName = fromRef.getClassName();
- String fromPropertyName = fromProp.getName();
- String toObjectName = toRef.toString();
- String toClassName = toRef.getClassName();
- String toPropertyName = toProp.getName();
-
- AssocInstTable::append(
- os,
- assocInstanceName,
- assocClassName,
- fromObjectName,
- fromClassName,
- fromPropertyName,
- toObjectName,
- toClassName,
- toPropertyName);
- }
- }
- }
- }
-}
-
-CIMObjectPath CIMRepository::createInstance(
- const String& nameSpace,
- const CIMInstance& newInstance)
-{
- String errMessage;
-
- // -- Resolve the instance (looks up class):
- CIMInstance cimInstance(newInstance);
-
- CIMConstClass cimClass;
- Resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass);
- CIMObjectPath instanceName = cimInstance.getInstanceName(cimClass);
-
- // -- Make sure the class has keys (otherwise it will be impossible to
- // -- create the instance.
-
- if (!cimClass.hasKeys())
- {
- errMessage = "class has no keys: ";
- errMessage += cimClass.getClassName();
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- Be sure instance does not already exist:
-
- String className;
- Uint32 dummyIndex;
- Uint32 dummySize;
-
- if (_getInstanceIndex(nameSpace, instanceName, className, dummySize,
- dummyIndex, true))
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS,
- instanceName.toString());
- }
-
- // -- Handle if association:
-
- if (cimClass.isAssociation())
- {
- _createAssocInstEntries(nameSpace,
- cimClass, cimInstance, instanceName);
- }
-
- // -- Get instance file path:
-
- String instanceFilePath = _getInstanceFilePath(nameSpace,
- cimInstance.getClassName());
-
- // -- Save instance to file:
-
- Uint32 index;
- Uint32 size;
- if (!_saveInstance(instanceFilePath, cimInstance, index, size))
- {
- errMessage.append("Failed to create instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- Make index file entry:
-
- String indexFilePath = _getIndexFilePath(
- nameSpace, cimInstance.getClassName());
-
- if (!InstanceIndexFile::insert(indexFilePath, instanceName, size, index))
- {
- errMessage.append("Failed to create instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- Rename the temporary index and instance files back to the original
-
- if (!_renameTempInstanceAndIndexFiles(indexFilePath, instanceFilePath))
- {
- errMessage.append("Unexpected error occurred while creating instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
- return (instanceName);
-}
-
-void CIMRepository::modifyClass(
- const String& nameSpace,
- const CIMClass& modifiedClass)
-{
- // -- Resolve the class:
- CIMClass cimClass(modifiedClass);
-
- Resolver::resolveClass (cimClass, _context, nameSpace);
-
- // -- Check to see if it is okay to modify this class:
-
- String classFilePath;
-
- _nameSpaceManager.checkModify(nameSpace, cimClass.getClassName(),
- cimClass.getSuperClassName(), classFilePath);
-
- // -- Delete the old file containing the class:
-
- if (!FileSystem::removeFileNoCase(classFilePath))
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
- "failed to remove file in CIMRepository::modifyClass()");
- }
-
- // -- Create new class file:
-
- _SaveObject(classFilePath, cimClass);
-}
-
-void CIMRepository::modifyInstance(
- const String& nameSpace,
- const CIMNamedInstance& modifiedInstance,
- Boolean includeQualifiers,
- const CIMPropertyList& propertyList)
-{
- String errMessage;
- CIMInstance cimInstance; // The instance that replaces the original
-
- if (propertyList.isNull())
- {
- //
- // Replace all the properties in the instance
- //
- if (includeQualifiers)
- {
- //
- // Replace the entire instance with the given instance
- // (this is the default behavior)
- //
- cimInstance = modifiedInstance.getInstance();
- }
- else
- {
- //
- // Replace all the properties in the instance, but keep the
- // original qualifiers on the instance and on the properties
- //
-
- cimInstance = getInstance(nameSpace,
- modifiedInstance.getInstanceName(), false, true);
- CIMInstance newInstance(
- modifiedInstance.getInstanceName().getClassName());
- CIMInstance givenInstance = modifiedInstance.getInstance();
-
- //
- // Copy over the original instance qualifiers
- //
- for (Uint32 i=0; i<cimInstance.getQualifierCount(); i++)
- {
- newInstance.addQualifier(cimInstance.getQualifier(i));
- }
-
- //
- // Loop through the properties replacing each property in the
- // original with a new value, but keeping the original qualifiers
- //
- for (Uint32 i=0; i<givenInstance.getPropertyCount(); i++)
- {
- // Copy the given property value (not qualifiers)
- CIMProperty givenProperty = givenInstance.getProperty(i);
- CIMProperty newProperty(
- givenProperty.getName(),
- givenProperty.getValue(),
- givenProperty.getArraySize(),
- givenProperty.getReferenceClassName(),
- givenProperty.getClassOrigin(),
- givenProperty.getPropagated());
-
- // Copy the original property qualifiers
- Uint32 origPos =
- cimInstance.findProperty(newProperty.getName());
- if (origPos != PEG_NOT_FOUND)
- {
- CIMProperty origProperty = cimInstance.getProperty(origPos);
- for (Uint32 j=0; j<origProperty.getQualifierCount(); j++)
- {
- newProperty.addQualifier(origProperty.getQualifier(i));
- }
- }
-
- // Add the newly constructed property to the new instance
- newInstance.addProperty(newProperty);
- }
-
- // Use the newly merged instance to replace the original instance
- cimInstance = newInstance;
- }
- }
- else
- {
- //
- // Replace only the properties specified in the given instance
- //
-
- cimInstance = getInstance(nameSpace,
- modifiedInstance.getInstanceName(), false, true);
- CIMInstance givenInstance = modifiedInstance.getInstance();
-
- // NOTE: Instance qualifiers are not changed when a property list
- // is specified. Property qualifiers are replaced with the
- // corresponding property values.
-
- //
- // Loop through the propertyList replacing each property in the original
- //
- for (Uint32 i=0; i<propertyList.size(); i++)
- {
- Uint32 origPropPos =
- cimInstance.findProperty(propertyList[i]);
- if (origPropPos != PEG_NOT_FOUND)
- {
- // Case: Property set in original
- CIMProperty origProperty =
- cimInstance.getProperty(origPropPos);
-
- // Get the given property value
- Uint32 givenPropPos =
- givenInstance.findProperty(propertyList[i]);
- if (givenPropPos != PEG_NOT_FOUND)
- {
- // Case: Property set in original and given
- CIMProperty givenProperty =
- givenInstance.getProperty(givenPropPos);
-
- // Copy over the property from the given to the original
- if (includeQualifiers)
- {
- // Case: Total property replacement
- cimInstance.removeProperty(origPropPos);
- cimInstance.addProperty(givenProperty);
- }
- else
- {
- // Case: Replace only the property value (not quals)
- origProperty.setValue(givenProperty.getValue());
- cimInstance.removeProperty(origPropPos);
- cimInstance.addProperty(origProperty);
- }
- }
- else
- {
- // Case: Property set in original and not in given
- // Just remove the property (set to null)
- cimInstance.removeProperty(origPropPos);
- }
- }
- else
- {
- // Case: Property not set in original
-
- // Get the given property value
- Uint32 givenPropPos =
- givenInstance.findProperty(propertyList[i]);
- if (givenPropPos != PEG_NOT_FOUND)
- {
- // Case: Property set in given and not in original
- CIMProperty givenProperty =
- givenInstance.getProperty(givenPropPos);
-
- // Copy over the property from the given to the original
- if (includeQualifiers)
- {
- // Case: Total property copy
- cimInstance.addProperty(givenProperty);
- }
- else
- {
- // Case: Copy only the property value (not qualifiers)
- CIMProperty newProperty(
- givenProperty.getName(),
- givenProperty.getValue(),
- givenProperty.getArraySize(),
- givenProperty.getReferenceClassName(),
- givenProperty.getClassOrigin(),
- givenProperty.getPropagated());
- cimInstance.addProperty(newProperty);
- }
- }
- else
- {
- // Case: Property not set in original or in given
-
- // Nothing to do; just make sure the property name is valid
- // ATTN: This is not the most efficient solution
- CIMClass cimClass = getClass(
- nameSpace, cimInstance.getClassName(), false);
- if (cimClass.findProperty (propertyList[i])
- == PEG_NOT_FOUND)
- {
- // ATTN: This exception may be returned by setProperty
- throw PEGASUS_CIM_EXCEPTION(
- CIM_ERR_NO_SUCH_PROPERTY, "modifyInstance()");
- }
- }
- }
- }
- }
-
- // -- Resolve the instance (looks up the class):
-
- CIMConstClass cimClass;
- resolver::resolveInstance (cimInstance, _context, nameSpace, cimClass);
-
- CIMObjectPath instanceName = cimInstance.getInstanceName(cimClass);
-
- // -- Disallow if instance name is changed by this operation (attempt
- // -- to modify a key property.
-
- if (instanceName != modifiedInstance.getInstanceName())
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
- "Attempted to modify a key property");
- }
-
- // -- Lookup index of entry from index file:
-
- String indexFilePath = _getIndexFilePath(
- nameSpace, instanceName.getClassName());
-
- Uint32 oldSize;
- Uint32 oldIndex;
- Uint32 newSize;
- Uint32 newIndex;
-
- if (!InstanceIndexFile::lookup(indexFilePath, instanceName, oldSize,
- oldIndex))
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
- }
-
- // -- modify the instance file
-
- String instanceFilePath = _getInstanceFilePath(
- nameSpace, instanceName.getClassName());
-
- if (!_modifyInstance(instanceFilePath, cimInstance, oldIndex, oldSize,
- newIndex, newSize))
- {
- errMessage.append("Failed to modify instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- modify the instance index file
-
- if (!InstanceIndexFile::modify(indexFilePath, instanceName, newSize,
- newIndex))
- {
- errMessage.append("Failed to modify instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-
- // -- Rename the temporary index and instance files back to the original
-
- if (!_renameTempInstanceAndIndexFiles(indexFilePath, instanceFilePath))
- {
- errMessage.append("Unexpected error occurred while modifying instance ");
- errMessage.append(instanceName.toString());
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
-}
-
-Array<CIMClass> CIMRepository::enumerateClasses(
- const String& nameSpace,
- const String& className,
- Boolean deepInheritance,
- Boolean localOnly,
- Boolean includeQualifiers,
- Boolean includeClassOrigin)
-{
- Array<String> classNames;
-
- _nameSpaceManager.getSubClassNames(
- nameSpace, className, deepInheritance, classNames);
-
- Array<CIMClass> result;
-
- for (Uint32 i = 0; i < classNames.size(); i++)
- {
- result.append(getClass(nameSpace, classNames[i], localOnly,
- includeQualifiers, includeClassOrigin));
- }
-
- return result;
-}
-
-Array<String> CIMRepository::enumerateClassNames(
- const String& nameSpace,
- const String& className,
- Boolean deepInheritance)
-{
- Array<String> classNames;
-
- _nameSpaceManager.getSubClassNames(
- nameSpace, className, deepInheritance, classNames);
-
- return classNames;
-}
-
-Array<CIMNamedInstance> CIMRepository::enumerateInstances(
- const String& nameSpace,
- const String& className,
- Boolean deepInheritance,
- Boolean localOnly,
- Boolean includeQualifiers,
- Boolean includeClassOrigin,
- const CIMPropertyList& propertyList)
-{
- // -- Get all descendent classes of this class:
-
- Array<String> classNames;
- _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
- classNames.prepend(className);
-
- // -- Get all instances for this class and all its descendent classes
-
- Array<CIMNamedInstance> namedInstances;
-
- for (Uint32 i = 0; i < classNames.size(); i++)
- {
- if (!_loadAllInstances(nameSpace, classNames[i], namedInstances))
- {
- String errMessage = "Failed to load instances in class ";
- errMessage.append(classNames[i]);
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
- }
-
- return namedInstances;
-}
-
-Array<CIMObjectPath> CIMRepository::enumerateInstanceNames(
- const String& nameSpace,
- const String& className)
-{
- // -- Get all descendent classes of this class:
-
- Array<String> classNames;
- _nameSpaceManager.getSubClassNames(nameSpace, className, true, classNames);
- classNames.prepend(className);
-
- // -- Get instance names from each qualifying instance file for the class:
-
- Array<CIMObjectPath> instanceNames;
- Array<Uint32> indices;
- Array<Uint32> sizes;
-
- for (Uint32 i = 0; i < classNames.size(); i++)
- {
- // -- Form the name of the class index file:
-
- String path = _getIndexFilePath(nameSpace, classNames[i]);
-
- // Get all instances for that class:
-
- if (!InstanceIndexFile::appendInstanceNamesTo(path, instanceNames,
- indices, sizes))
- {
- String errMessage = "Failed to load instance names in class ";
- errMessage.append(classNames[i]);
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, errMessage);
- }
- PEGASUS_ASSERT(instanceNames.size() == indices.size());
- PEGASUS_ASSERT(instanceNames.size() == sizes.size());
- }
-
- return instanceNames;
-}
-
-Array<CIMInstance> CIMRepository::execQuery(
- const String& queryLanguage,
- const String& query)
-{
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "execQuery()");
-
- return Array<CIMInstance>();
-}
-
-Array<CIMObjectWithPath> CIMRepository::associators(
- const String& nameSpace,
- const CIMObjectPath& objectName,
- const String& assocClass,
- const String& resultClass,
- const String& role,
- const String& resultRole,
- Boolean includeQualifiers,
- Boolean includeClassOrigin,
- const CIMPropertyList& propertyList)
-{
- Array<CIMObjectPath> names = associatorNames(
- nameSpace,
- objectName,
- assocClass,
- resultClass,
- role,
- resultRole);
-
- Array<CIMObjectWithPath> result;
-
- for (Uint32 i = 0, n = names.size(); i < n; i++)
- {
- String tmpNameSpace = names[i].getNameSpace();
-
- if (tmpNameSpace.size() == 0)
- tmpNameSpace = nameSpace;
-
- if (names[i].isClassName())
- {
- CIMObjectPath tmpRef = names[i];
- tmpRef.setHost(String());
- tmpRef.setNameSpace(String());
-
- CIMClass cimClass = getClass(
- tmpNameSpace,
- tmpRef.getClassName(),
- false,
- includeQualifiers,
- includeClassOrigin,
- propertyList);
-
- CIMObject cimObject(cimClass);
- result.append(CIMObjectWithPath(names[i], cimObject));
- }
- else
- {
- CIMObjectPath tmpRef = names[i];
- tmpRef.setHost(String());
- tmpRef.setNameSpace(String());
-
- CIMInstance cimInstance = getInstance(
- tmpNameSpace,
- tmpRef,
- false,
- includeQualifiers,
- includeClassOrigin,
- propertyList);
-
- CIMObject cimObject(cimInstance);
- result.append(CIMObjectWithPath(names[i], cimObject));
- }
- }
-
- return result;
-}
-
-Array<CIMObjectPath> CIMRepository::associatorNames(
- const String& nameSpace,
- const CIMObjectPath& objectName,
- const String& assocClass,
- const String& resultClass,
- const String& role,
- const String& resultRole)
-{
- Array<String> associatorNames;
-
- if (objectName.isClassName())
- {
- String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
-
- AssocClassTable::getAssociatorNames(
- assocFileName,
- objectName.toString(),
- assocClass,
- resultClass,
- role,
- resultRole,
- associatorNames);
- }
- else
- {
- String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
-
- AssocInstTable::getAssociatorNames(
- assocFileName,
- objectName,
- assocClass,
- resultClass,
- role,
- resultRole,
- associatorNames);
- }
-
- Array<CIMObjectPath> result;
-
- for (Uint32 i = 0, n = associatorNames.size(); i < n; i++)
- {
- CIMObjectPath r = associatorNames[i];
-
- if (r.getHost().size() == 0)
- r.setHost(System::getHostName());
-
- if (r.getNameSpace().size() == 0)
- r.setNameSpace(nameSpace);
-
- result.append(r);
- }
-
- return result;
-}
-
-Array<CIMObjectWithPath> CIMRepository::references(
- const String& nameSpace,
- const CIMObjectPath& objectName,
- const String& resultClass,
- const String& role,
- Boolean includeQualifiers,
- Boolean includeClassOrigin,
- const CIMPropertyList& propertyList)
-{
- Array<CIMObjectPath> names = referenceNames(
- nameSpace,
- objectName,
- resultClass,
- role);
-
- Array<CIMObjectWithPath> result;
-
- for (Uint32 i = 0, n = names.size(); i < n; i++)
- {
- String tmpNameSpace = names[i].getNameSpace();
-
- if (tmpNameSpace.size() == 0)
- tmpNameSpace = nameSpace;
-
- // ATTN: getInstance() should this be able to handle instance names
- // with host names and namespaces?
-
- CIMObjectPath tmpRef = names[i];
- tmpRef.setHost(String());
- tmpRef.setNameSpace(String());
-
- if (objectName.isClassName())
- {
- CIMClass cimClass = getClass(
- tmpNameSpace,
- tmpRef.getClassName(),
- false,
- includeQualifiers,
- includeClassOrigin,
- propertyList);
-
- result.append(CIMObjectWithPath(names[i], cimClass));
- }
- else
- {
- CIMInstance instance = getInstance(
- tmpNameSpace,
- tmpRef,
- false,
- includeQualifiers,
- includeClassOrigin,
- propertyList);
-
- result.append(CIMObjectWithPath(names[i], instance));
- }
- }
-
- return result;
-}
-
-Array<CIMObjectPath> CIMRepository::referenceNames(
- const String& nameSpace,
- const CIMObjectPath& objectName,
- const String& resultClass,
- const String& role)
-{
- Array<String> tmpReferenceNames;
-
- if (objectName.isClassName())
- {
- String assocFileName = _MakeAssocClassPath(nameSpace, _repositoryRoot);
-
- if (!AssocClassTable::getReferenceNames(
- assocFileName,
- objectName.getClassName(),
- resultClass,
- role,
- tmpReferenceNames))
- {
- // Ignore error! It's okay not to have references.
- }
- }
- else
- {
- String assocFileName = _MakeAssocInstPath(nameSpace, _repositoryRoot);
-
- if (!AssocInstTable::getReferenceNames(
- assocFileName,
- objectName,
- resultClass,
- role,
- tmpReferenceNames))
- {
- // Ignore error! It's okay not to have references.
- }
- }
-
- Array<CIMObjectPath> result;
-
- for (Uint32 i = 0, n = tmpReferenceNames.size(); i < n; i++)
- {
- CIMObjectPath r = tmpReferenceNames[i];
-
- if (r.getHost().size() == 0)
- r.setHost(System::getHostName());
-
- if (r.getNameSpace().size() == 0)
- r.setNameSpace(nameSpace);
-
- result.append(r);
- }
-
- return result;
-}
-
-CIMValue CIMRepository::getProperty(
- const String& nameSpace,
- const CIMObjectPath& instanceName,
- const String& propertyName)
-{
- // -- Get the index for this instance:
-
- String className;
- Uint32 index;
- Uint32 size;
-
- if (!_getInstanceIndex(nameSpace, instanceName, className, size, index))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, instanceName.toString());
-
- // -- Load the instance into memory:
-
- String path = _getInstanceFilePath(nameSpace, className);
- CIMInstance cimInstance;
- if (!_loadInstance(path, cimInstance, index, size))
- {
- throw CannotOpenFile(path);
- }
-
- // -- Grab the property from the instance:
-
- Uint32 pos = cimInstance.findProperty(propertyName);
-
- // ATTN: This breaks if the property is simply null
- if (pos == PEG_NOT_FOUND)
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NO_SUCH_PROPERTY, "getProperty()");
-
- CIMProperty prop = cimInstance.getProperty(pos);
-
- // -- Return the value:
-
- return prop.getValue();
-}
-
-void CIMRepository::setProperty(
- const String& nameSpace,
- const CIMObjectPath& instanceName,
- const String& propertyName,
- const CIMValue& newValue)
-{
- //
- // Create the instance to pass to modifyInstance()
- //
- CIMInstance instance(instanceName.getClassName());
- // ATTN: Is this the correct construction for this property?
- instance.addProperty(CIMProperty(propertyName, newValue));
- CIMNamedInstance namedInstance(instanceName, instance);
-
- //
- // Create the propertyList to pass to modifyInstance()
- //
- Array<String> propertyListArray;
- propertyListArray.append(propertyName);
- CIMPropertyList propertyList(propertyListArray);
-
- //
- // Modify the instance to set the value of the given property
- //
- modifyInstance(nameSpace, namedInstance, false, propertyList);
-}
-
-CIMQualifierDecl CIMRepository::getQualifier(
- const String& nameSpace,
- const String& qualifierName)
-{
- // -- Get path of qualifier file:
-
- String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
- nameSpace, qualifierName);
-
- // -- Load qualifier:
-
- CIMQualifierDecl qualifierDecl;
-
- try
- {
- _LoadObject(qualifierFilePath, qualifierDecl);
- }
- catch (CannotOpenFile&)
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, qualifierName);
- }
-
- return qualifierDecl;
-}
-
-void CIMRepository::setQualifier(
- const String& nameSpace,
- const CIMQualifierDecl& qualifierDecl)
-{
- // -- Get path of qualifier file:
-
- String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
- nameSpace, qualifierDecl.getName());
-
- // -- If qualifier alread exists, throw exception:
-
- if (FileSystem::existsNoCase(qualifierFilePath))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS, qualifierDecl.getName());
-
- // -- Save qualifier:
-
- _SaveObject(qualifierFilePath, qualifierDecl);
-}
-
-void CIMRepository::deleteQualifier(
- const String& nameSpace,
- const String& qualifierName)
-{
- // -- Get path of qualifier file:
-
- String qualifierFilePath = _nameSpaceManager.getQualifierFilePath(
- nameSpace, qualifierName);
-
- // -- Delete qualifier:
-
- if (!FileSystem::removeFileNoCase(qualifierFilePath))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_FOUND, qualifierName);
-}
-
-Array<CIMQualifierDecl> CIMRepository::enumerateQualifiers(
- const String& nameSpace)
-{
- String qualifiersRoot = _nameSpaceManager.getQualifiersRoot(nameSpace);
-
- Array<String> qualifierNames;
-
- if (!FileSystem::getDirectoryContents(qualifiersRoot, qualifierNames))
- {
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
- "enumerateQualifiers(): internal error");
- }
-
- Array<CIMQualifierDecl> qualifiers;
-
- for (Uint32 i = 0; i < qualifierNames.size(); i++)
- {
- CIMQualifierDecl qualifier = getQualifier(nameSpace, qualifierNames[i]);
- qualifiers.append(qualifier);
- }
-
- return qualifiers;
-}
-
-CIMValue CIMRepository::invokeMethod(
- const String& nameSpace,
- const CIMObjectPath& instanceName,
- const String& methodName,
- const Array<CIMValue>& inParameters,
- Array<CIMValue>& outParameters)
-{
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, "invokeMethod()");
- return CIMValue();
-}
-
-void CIMRepository::createNameSpace(const String& nameSpace)
-{
- _nameSpaceManager.createNameSpace(nameSpace);
-}
-
-Array<String> CIMRepository::enumerateNameSpaces() const
-{
- Array<String> nameSpaceNames;
- _nameSpaceManager.getNameSpaceNames(nameSpaceNames);
- return nameSpaceNames;
-}
-
-void CIMRepository::deleteNameSpace(const String& nameSpace)
-{
- _nameSpaceManager.deleteNameSpace(nameSpace);
-}
-
-//----------------------------------------------------------------------
-//
-// _getIndexFilePath()
-//
-// returns the file path of the instance index file.
-//
-//----------------------------------------------------------------------
-
-String CIMRepository::_getIndexFilePath(
- const String& nameSpace,
- const String& className) const
-{
- String tmp = _nameSpaceManager.getInstanceFileBase(nameSpace, className);
- tmp.append(".idx");
- return tmp;
-}
-
-//----------------------------------------------------------------------
-//
-// _getInstanceFilePath()
-//
-// returns the file path of the instance file.
-//
-//----------------------------------------------------------------------
-
-String CIMRepository::_getInstanceFilePath(
- const String& nameSpace,
- const String& className) const
-{
- String tmp = _nameSpaceManager.getInstanceFileBase(nameSpace, className);
- tmp.append(".instances");
- return tmp;
-}
-
-//----------------------------------------------------------------------
-//
-// _loadInstance()
-//
-// Loads an instance object from disk to memory. Returns true on
-// success.
-//
-//----------------------------------------------------------------------
-
-Boolean CIMRepository::_loadInstance(
- const String& path,
- CIMInstance& object,
- Uint32 index,
- Uint32 size)
-{
- // Load instance from instance file into memory:
-
- Array<Sint8> data;
- if (!InstanceFile::loadInstance(path, index, size, data))
- {
- return false;
- }
-
- XmlParser parser((char*)data.getData());
-
- XmlReader::getObject(parser, object);
-
- return true;
-}
-
-//----------------------------------------------------------------------
-//
-// _loadAllInstances()
-//
-// Loads all the instance objects for a given class from disk to memory.
-// Returns true on success.
-//
-//----------------------------------------------------------------------
-
-Boolean CIMRepository::_loadAllInstances(
- const String& nameSpace,
- const String& className,
- Array<CIMNamedInstance>& namedInstances)
-{
- Array<CIMObjectPath> instanceNames;
- Array<Sint8> data;
- Array<Uint32> indices;
- Array<Uint32> sizes;
-
- //
- // Form the name of the instance index file
- //
- String indexFilePath = _getIndexFilePath(nameSpace, className);
-
- //
- // Form the name of the instance file
- //
- String instanceFilePath = _getInstanceFilePath(nameSpace, className);
-
- //
- // Get all instance names and record information from the index file
- //
- if (!InstanceIndexFile::appendInstanceNamesTo(
- indexFilePath, instanceNames, indices, sizes))
- {
- return false;
- }
- PEGASUS_ASSERT(instanceNames.size() == indices.size());
- PEGASUS_ASSERT(instanceNames.size() == sizes.size());
-
- //
- // Load all instance data from the instance file
- //
- if (instanceNames.size() > 0)
- {
- if (!InstanceFile::loadAllInstances(instanceFilePath, data))
- {
- return false;
- }
-
- //
- // for each instance loaded, call XML parser to parse the XML
- // data and create a CIMInstance object.
- //
- CIMInstance tmpInstance;
-
- Uint32 bufferSize = data.size();
- char* buffer = (char*)data.getData();
-
- for (Uint32 i = 0; i < instanceNames.size(); i++)
- {
- XmlParser parser(&(buffer[indices[i]]));
-
- XmlReader::getObject(parser, tmpInstance);
-
- namedInstances.append(CIMNamedInstance(instanceNames[i], tmpInstance));
- }
- }
-
- return true;
-}
-
-//----------------------------------------------------------------------
-//
-// _saveInstance()
-//
-// Saves an instance object from memory to disk file. Returns true
-// on success.
-//
-//----------------------------------------------------------------------
-
-Boolean CIMRepository::_saveInstance(
- const String& path,
- const CIMInstance& object,
- Uint32& index,
- Uint32& size)
-{
- Array<Sint8> out;
- object.toXml(out);
-
- if (!InstanceFile::insertInstance(out, path, index, size))
- {
- return false;
- }
-
- return true;
-}
-
-//----------------------------------------------------------------------
-//
-// _modifyInstance()
-//
-// Modifies an instance object saved in the disk file. Returns true
-// on success.
-//
-//----------------------------------------------------------------------
-
-Boolean CIMRepository::_modifyInstance(
- const String& path,
- const CIMInstance& object,
- Uint32 oldIndex,
- Uint32 oldSize,
- Uint32& newIndex,
- Uint32& newSize)
-{
- Array<Sint8> out;
- object.toXml(out);
-
- if (!InstanceFile::modifyInstance(out, path, oldIndex, oldSize, newIndex,
- newSize))
- {
- return false;
- }
-
- return true;
-}
-
-//------------------------------------------------------------------------------
-//
-// _renameTempInstanceAndIndexFiles()
-//
-// Renames the temporary instance and instance index files back to the
-// original files. The temporary files were created for an insert,
-// remove, or modify operation (to avoid data inconsistency between
-// the two files in case of unexpected system termination or failure).
-// This method is called after a successful insert, remove, or modify
-// operation on BOTH the index file and the instance file. Returns
-// true on success.
-//
-//------------------------------------------------------------------------------
-
-Boolean CIMRepository::_renameTempInstanceAndIndexFiles(
- const String& indexFilePath,
- const String& instanceFilePath)
-{
- //
- // Rename the original files to backup files
- //
- // This is done so that we would not lose the original files if an error
- // occurs in renaming the temporary files back after the original files
- // have been removed.
- //
- String realIndexFilePath;
- if (FileSystem::existsNoCase(indexFilePath, realIndexFilePath))
- {
- if (!FileSystem::renameFile(realIndexFilePath,
- realIndexFilePath + ".orig"))
- return false;
- }
- else
- {
- realIndexFilePath = indexFilePath;
- }
-
- String realInstanceFilePath;
- if (FileSystem::existsNoCase(instanceFilePath, realInstanceFilePath))
- {
- if (!FileSystem::renameFile(realInstanceFilePath,
- realInstanceFilePath + ".orig"))
- return false;
- }
- else
- {
- realInstanceFilePath = instanceFilePath;
- }
-
- //
- // Rename the temporary instance and index files back to be the original
- // files.
- //
- // If the index file is now empty (zero size), delete the temporary
- // files instead.
- //
- Uint32 fileSize;
- String tmpIndexFilePath = realIndexFilePath + ".tmp";
- String tmpInstanceFilePath = realInstanceFilePath + ".tmp";
-
- if (!FileSystem::getFileSizeNoCase(tmpIndexFilePath, fileSize))
- return false;
-
- if (fileSize == 0)
- {
- if (!FileSystem::removeFileNoCase(tmpIndexFilePath))
- return false;
-
- if (!FileSystem::removeFileNoCase(tmpInstanceFilePath))
- return false;
- }
- else
- {
- if (!FileSystem::renameFile(tmpIndexFilePath, realIndexFilePath))
- return false;
-
- if (!FileSystem::renameFile(tmpInstanceFilePath, realInstanceFilePath))
- return false;
- }
-
- //
- // Now remove the backup files
- //
- FileSystem::removeFile(realIndexFilePath + ".orig");
- FileSystem::removeFile(realInstanceFilePath + ".orig");
-
- return true;
-}
-
-void CIMRepository::setDeclContext(RepositoryDeclContext *context)
-{
- _context = context;
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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 <Pegasus/Common/String.h>
-#include <Pegasus/Common/HashTable.h>
-#include <Pegasus/Common/Dir.h>
-#include "InheritanceTree.h"
-
-PEGASUS_NAMESPACE_BEGIN
-
-PEGASUS_USING_STD;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// NoCaseEqualFunc
-//
-////////////////////////////////////////////////////////////////////////////////
-
-struct NoCaseEqualFunc
-{
- static Boolean equal(const String& x, const String& y)
- {
- return String::equalNoCase(x, y);
- }
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// InheritanceTreeNode
-//
-////////////////////////////////////////////////////////////////////////////////
-
-struct InheritanceTreeNode
-{
- InheritanceTreeNode(const String& className);
-
- void addSubClass(InheritanceTreeNode* subClass);
-
- Boolean removeSubClass(InheritanceTreeNode* subClass);
-
- void getSubClassNames(
- Array<String>& subClassNames,
- Boolean deepInheritance);
-
- void getSuperClassNames(Array<String>& superClassNames);
-
- void print(PEGASUS_STD(ostream)& os) const;
-
- Boolean isSubClass(const String& className);
-
- String className;
- InheritanceTreeNode* superClass;
- InheritanceTreeNode* sibling;
- InheritanceTreeNode* subClasses;
- Boolean provisional;
-};
-
-InheritanceTreeNode::InheritanceTreeNode(const String& className)
- : className(className), superClass(0),
- sibling(0), subClasses(0), provisional(true)
-{
-
-}
-
-void InheritanceTreeNode::addSubClass(InheritanceTreeNode* subClass)
-{
- subClass->superClass = this;
- subClass->sibling = subClasses;
- subClasses = subClass;
-}
-
-Boolean InheritanceTreeNode::removeSubClass(InheritanceTreeNode* subClass)
-{
- InheritanceTreeNode* prev = 0;
-
- for (InheritanceTreeNode* p = subClasses; p; p = p->sibling)
- {
- if (p == subClass)
- {
- if (prev)
- prev->sibling = subClass->sibling;
- else
- subClasses = subClass->sibling;
-
- return true;
- }
- prev = p;
- }
-
- return false;
-}
-
-void InheritanceTreeNode::getSubClassNames(
- Array<String>& subClassNames,
- Boolean deepInheritance)
-{
- // For each subClass:
-
- for (InheritanceTreeNode* p = subClasses; p; p = p->sibling)
- {
- subClassNames.append(p->className);
-
- if (deepInheritance)
- {
- p->getSubClassNames(subClassNames, true);
- }
- }
-}
-
-Boolean InheritanceTreeNode::isSubClass(const String& className_)
-{
- if (String::equalNoCase(className, className_))
- return true;
-
- for (InheritanceTreeNode* p = subClasses; p; p = p->sibling)
- {
- if (String::equalNoCase(p->className, className_))
- return true;
- }
-
- return false;
-}
-
-void InheritanceTreeNode::getSuperClassNames(Array<String>& superClassNames)
-{
- // For each superClass:
-
- for (InheritanceTreeNode* p = superClass; p; p = p->superClass)
- {
- superClassNames.append(p->className);
- p->getSuperClassNames(superClassNames);
- }
-}
-
-void InheritanceTreeNode::print(PEGASUS_STD(ostream)& os) const
-{
- os << className << " : " ;
- os << (superClass ? superClass->className : String("<None>"));
-
- os << " { ";
-
- for (InheritanceTreeNode* p = subClasses; p; p = p->sibling)
- os << p->className << ' ';
-
- os << "}" << endl;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// InheritanceTreeRep
-//
-////////////////////////////////////////////////////////////////////////////////
-
-struct InheritanceTreeRep
-{
- typedef HashTable<String, InheritanceTreeNode*,
- NoCaseEqualFunc, HashFunc<String> > Table;
- Table table;
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// InheritanceTree
-//
-////////////////////////////////////////////////////////////////////////////////
-
-InheritanceTree::InheritanceTree()
-{
- _rep = new InheritanceTreeRep;
-}
-
-InheritanceTree::~InheritanceTree()
-{
- delete _rep;
-}
-
-void InheritanceTree::insert(
- const String& className,
- const String& superClassName)
-{
- // ATTN: need found flag!
-
- // -- Insert superclass:
-
- InheritanceTreeNode* superClassNode = 0;
-
- if (superClassName.size() &&
- !_rep->table.lookup(superClassName, superClassNode))
- {
- superClassNode = new InheritanceTreeNode(superClassName);
- _rep->table.insert(superClassName, superClassNode);
- }
-
- // -- Insert class:
-
- InheritanceTreeNode* classNode = 0;
-
- if (!_rep->table.lookup(className, classNode))
- {
- classNode = new InheritanceTreeNode(className);
- _rep->table.insert(className, classNode);
- }
-
- classNode->provisional = false;
-
- // -- Link the class and superclass nodes:
-
- if (superClassNode)
- superClassNode->addSubClass(classNode);
-}
-
-void InheritanceTree::insertFromPath(const String& path)
-{
- for (Dir dir(path); dir.more(); dir.next())
- {
- String fileName = dir.getName();
-
- // Ignore the current and parent directories.
-
- if (fileName == "." || fileName == "..")
- continue;
-
- Uint32 dot = fileName.find('.');
-
- // Ignore files without dots in them:
-
- if (dot == PEG_NOT_FOUND)
- continue;
-
- String className = fileName.subString(0, dot);
- String superClassName = fileName.subString(dot + 1);
-
- if (superClassName == "#")
- superClassName.clear();
-
- insert(className, superClassName);
- }
-}
-
-void InheritanceTree::check() const
-{
- for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++)
- {
- if (i.value()->provisional)
- throw InvalidInheritanceTree(i.value()->className);
- }
-}
-
-Boolean InheritanceTree::getSubClassNames(
- const String& className,
- Boolean deepInheritance,
- Array<String>& subClassNames) const
-{
- // -- Case 1: className is empty: get all class names (if deepInheritance)
- // -- or just root class names (if not deepInheritance).
-
- if (!className.size())
- {
- for (InheritanceTreeRep::Table::Iterator i = _rep->table.start();i;i++)
- {
- if (deepInheritance)
- {
- // Append all classes:
-
- subClassNames.append(i.key());
- }
- else if (!i.value()->superClass)
- {
- // Just append root classes:
-
- subClassNames.append(i.key());
- }
- }
- return true;
- }
-
- // -- Case 2: className non-empty: get names of classes descendent from
- // -- the given class.
-
- for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++)
- {
- if (String::equalNoCase(className, i.key()))
- {
- i.value()->getSubClassNames(subClassNames, deepInheritance);
- return true;
- }
- }
-
- // Not found!
- return false;
-}
-
-Boolean InheritanceTree::isSubClass(const String& class1, const String& class2)
-{
- InheritanceTreeNode* node = 0;
-
- if (!_rep->table.lookup(class1, node))
- return false;
-
- return node->isSubClass(class2);
-}
-
-Boolean InheritanceTree::getSuperClassNames(
- const String& className,
- Array<String>& superClassNames) const
-{
- InheritanceTreeNode* classNode;
-
- if (_rep->table.lookup(className, classNode))
- {
- classNode->getSuperClassNames(superClassNames);
- return true;
- }
-
- return false;
-}
-
-Boolean InheritanceTree::getSuperClass(
- const String& className,
- String& superClassName) const
-{
- InheritanceTreeNode* classNode;
-
- if (_rep->table.lookup(className, classNode))
- {
- if (classNode->superClass)
- {
- superClassName = classNode->superClass->className;
- }
- else
- {
- superClassName.clear();
- }
-
- return true;
- }
-
- return false;
-}
-
-Boolean InheritanceTree::hasSubClasses(
- const String& className,
- Boolean& hasSubClasses) const
-{
- InheritanceTreeNode* node = 0;
-
- if (!_rep->table.lookup(className, node))
- return false;
-
- hasSubClasses = node->subClasses != 0;
- return true;
-}
-
-Boolean InheritanceTree::containsClass(const String& className) const
-{
- return _rep->table.contains(className);
-}
-
-void InheritanceTree::remove(const String& className)
-{
- // -- Lookup the node:
-
- InheritanceTreeNode* node = 0;
-
- if (!_rep->table.lookup(className, node))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS, className);
-
- // -- Disallow if is has any subclasses:
-
- if (node->subClasses)
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_CLASS_HAS_CHILDREN, className);
-
- // -- Remove as child of superclass:
-
- InheritanceTreeNode* superClass = node->superClass;
-
- if (superClass)
- {
- Boolean result = superClass->removeSubClass(node);
- PEGASUS_ASSERT(result);
- }
-
- // -- Remove from the hash table and delete:
-
- Boolean result = _rep->table.remove(className);
- PEGASUS_ASSERT(result);
- delete node;
-}
-
-void InheritanceTree::print(PEGASUS_STD(ostream)& os) const
-{
- for (InheritanceTreeRep::Table::Iterator i = _rep->table.start(); i; i++)
- i.value()->print(os);
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#ifndef Pegasus_InheritanceTree_h
-#define Pegasus_InheritanceTree_h
-
-#include <iostream>
-#include <Pegasus/Common/Config.h>
-#include <Pegasus/Common/String.h>
-#include <Pegasus/Common/InternalException.h>
-
-PEGASUS_NAMESPACE_BEGIN
-
-struct InheritanceTreeRep;
-
-/** The InheritanceTree class tracks inheritance relationships of CIM classes.
-
- This class is a memory resident version of the repository's persistent
- inheritance information (represented using file names). The InheritanceTree
- provides O(1) access (via hashing) to any class in the inheritance tree.
-
- The inheritance tree provides methods for interrogating certain kinds of
- information about a class, including:
-
- <ul>
- <li>the superclass</li>
- <li>the subclasses</li>
- <li>the descendent classes</li>
- </ul>
-
- The insert() method is used to build up an InheritanceTree. The insert()
- method is called for each class-subclass relationship. For example, consider
- the following list of class-subclass pairs:
-
- <pre>
- { "D", "B" }
- { "E", "B" }
- { "B", "A" }
- { "C", "A" }
- { "F", "C" }
- </pre>
-
- These pairs specify the following inheritance tree:
-
- <pre>
- A
- / \
- B C
- / \ \
- D E F
- </pre>
-
- The pairs above may be used to build a class tree as follows:
-
- <pre>
- InheritanceTree it;
- it.insert("D", "B");
- it.insert("E", "B");
- it.insert("B", "A");
- it.insert("C", "A");
- it.insert("F", "C");
- it.insert("A", "");
- it.check();
- </pre>
-
- The check() method determines whether insert() was called for every class
- used as a superclass. In the following example, check() would fail (and
- throw and exception) since the "B" class is passed as a superclass (second
- argument) in two insert() calls but was never passed as the class itself
- (first argument) in any insert() call:
-
- <pre>
- InheritanceTree it;
- it.insert("D", "B");
- it.insert("E", "B");
- it.insert("C", "A");
- it.insert("F", "C");
- it.insert("A", "");
- it.check();
- </pre>
-
- In this case, check() throws an InvalidInheritanceTree exception.
-
- The InheritanceTree may be printed by calling the print() method.
-
- The insertFromPath() method is used to build up an InheritanceTree from
- the file names in a certain directory as used by the CIMRepository. The
- CIMRepository contains a disk file per class and the name has this form:
-
- <pre>
- <ClassName>.<SuperClassName>
- </pre>
-
- For example, a class called "ThisClass" with super class "ThatClass"
- has this name:
-
- <pre>
- ThisClass.ThisClass
- </pre>
-
- The file or course contains the XML encoding of the ThisClass class (which
- is irrelevant for the InheritanceTree). A root class (with no superclass
- has the following form):
-
- <pre>
- <ClassName>.#
- </pre>
-
- Suppose that ThatClass is a root class; then its file name is:
-
- <pre>
- ThatClass.#
- </pre>
-
- It must be obvious by now that the insertFromPath() method just scans
- the file names in a directory and calls insert() for each one (splitting
- the class name from superclass name and translating '#' to an empty string).
-
- The insertFromPath() method does NOT call check(), so it still must be
- called to verify the InheritanceTree.
-*/
-class PEGASUS_REPOSITORY_LINKAGE InheritanceTree
-{
-public:
-
- /** Default constructor. */
- InheritanceTree();
-
- /** Destructor. */
- ~InheritanceTree();
-
- /** Inserts a class-subclass relationship into the inheritance three.
- Note that a class CAN be inserted before its superclass, in which case
- a provisional entry is made for the superclass and flagged as such;
- when the superclass is later inserted, the provisional flag is cleared.
- @param className - name of class being inserted.
- @param superClassName - name of super class of class.
- */
- void insert(const String& className, const String& superClassName);
-
- /** Scan directory for file names of the form <ClassName>.<SuperClass> and
- call insert on insert for each one. Note that root classes (classes with
- no superclass) will use "#" for a SuperClass name.
- @param path - directory that contains files describing inheritance
- infoformation.
- @exception throws CannotOpenDirectory is invalid path specifies an
- invalid directory.
- */
- void insertFromPath(const String& path);
-
- /** Checks that every superClassName passed to insert() was also passed
- as a className argument to insert(). In other words, it checks that
- there are no provisional entries as described in the insert() method.
- @exception InvalidInheritanceTree
- */
- void check() const;
-
- /** Get subclass names of the given class.
- @param className - class whose subclass names will be gotten. If
- className is empty, all classnames are returned.
- @param deepInheritance - if true all descendent classes of class
- are returned. If className is empty, only root classes are returned.
- @param subClassNames - output argument to hold subclass names.
- @return true on success. False if no such class.
- */
- Boolean getSubClassNames(
- const String& className,
- Boolean deepInheritance,
- Array<String>& subClassNames) const;
-
- /** Returns true if class1 is a subclass of class2.
- */
- Boolean isSubClass(const String& class1, const String& class2);
-
- /** Get the names of all superclasses of this class (direct and indirect).
- */
- Boolean getSuperClassNames(
- const String& className,
- Array<String>& subClassNames) const;
-
- /** Get the superclass of the given class.
- @param className name of class.
- @param superClassName name of superclass upon return.
- @return true if class was found; false otherwise.
- */
- Boolean getSuperClass(
- const String& className,
- String& superClassName) const;
-
- /** Returns true if the given class has sub-classes. */
- Boolean hasSubClasses(
- const String& className,
- Boolean& hasSubClasses) const;
-
- /** Returns true if this inhertance tree contains the given class. */
- Boolean containsClass(const String& className) const;
-
- /** Removes the given class from the class graph.
- @exception CIMException(CIM_ERR_CLASS_HAS_CHILDREN)
- @exception CIMException(CIM_ERR_INVALID_CLASS)
- */
- void remove(const String& className);
-
- /** Prints the class */
- void print(PEGASUS_STD(ostream)& os) const;
-
-private:
-
- InheritanceTree(const InheritanceTree&) { }
-
- InheritanceTree& operator=(const InheritanceTree&) { return *this; }
-
- InheritanceTreeRep* _rep;
-};
-
-/** The InvalidInheritanceTree exception is thrown when the
- InheritanceTreeRep::check() method determines that an inheritance tree
- was not fully specified (when any class was passed as a superClassName
- argument to insert() but never as a className argument.
-*/
-class InvalidInheritanceTree : public Exception
-{
-public:
-
- InvalidInheritanceTree(const String& className)
- : Exception("Invalid inheritance tree: unknown class: " + className) { }
-};
-
-PEGASUS_NAMESPACE_END
-
-#endif /* Pegasus_InheritanceTree_h */
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
-//
-// Modified By:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#include <Pegasus/Common/Config.h>
-#include <fstream>
-#include <Pegasus/Common/Destroyer.h>
-#include <Pegasus/Common/FileSystem.h>
-#include <Pegasus/Common/XmlWriter.h>
-#include "InstanceFile.h"
-
-// Note: If the INDENT_XML_FILES option is set, the XmlWriter is called
-// to parse the xml data to add indentations before saving the
-// instance data to the instance file. It somewhat impacts the
-// performance of a create or modify instance operation. In the
-// future, this option should be made a configurable property to
-// allow enabling and disabling without re-compilation.
-
-#define INDENT_XML_FILES
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-/**
- Loads an instance record in the instance file to memory.
- */
-Boolean InstanceFile::loadInstance(
- const String& path,
- Uint32 index,
- Uint32 size,
- Array<Sint8>& data)
-{
- //
- // check for the existence of the instance file, and get the real path
- // of the file
- //
- String realPath;
-
- if (!FileSystem::existsNoCase(path, realPath))
- {
- return false;
- }
-
- //
- // load data from file
- //
- if (!_loadData(realPath, index, size, data))
- {
- return false;
- }
-
- return true;
-}
-
-/**
- Loads all the instance records in the instance file to memory.
- */
-Boolean InstanceFile::loadAllInstances(
- const String& path,
- Array<Sint8>& data)
-{
- //
- // check for the existence of the instance file, and get the real path
- // of the file
- //
- String realPath;
-
- if (!FileSystem::existsNoCase(path, realPath))
- {
- return false;
- }
-
- //
- // get the size of the instance file
- //
- Uint32 fileSize;
- if (!FileSystem::getFileSizeNoCase(realPath, fileSize))
- {
- return false;
- }
-
- //
- // load all the instance data stored in the instance file
- //
- if (!_loadData(realPath, 0, fileSize, data))
- {
- return false;
- }
-
- return true;
-}
-
-/**
- Inserts a new record into the instance file. Sets the byte position
- and the size of the newly added instance record. Returns true on
- success.
-
- This method creates a temporary file, copies the contents of the original
- instance file to the temporary file, and appends the new entry to the
- temporary file. The caller must rename the temporary file back to the
- original file after the insert operation is successful on BOTH the
- instance index file and the instance file.
- */
-Boolean InstanceFile::insertInstance(
- Array<Sint8> out,
- const String& path,
- Uint32& index,
- Uint32& size)
-{
- //
- // Create a temporary instance file
- //
- // First make sure that there is not already a temporary file.
- // If a temporary file already exists, remove it first.
- //
- String tempFilePath;
- if (FileSystem::existsNoCase(path + ".tmp", tempFilePath))
- {
- if (!FileSystem::removeFileNoCase(tempFilePath))
- {
- return false;
- }
- }
-
- ofstream os((path+".tmp").getCString(), ios::app | ios::binary);
-
- if (!os)
- {
- return false;
- }
-
- //
- // Check for the existence of the instance file. If file exists, copy
- // the contents of the file to the temporary file.
- //
- String realPath;
- if (FileSystem::existsNoCase(path, realPath))
- {
- ifstream is(realPath.getCString(), ios::binary);
-
- if (!is)
- {
- return false;
- }
-
- //
- // get the size of the instance file
- //
- Uint32 fileSize;
- if (!FileSystem::getFileSizeNoCase(realPath, fileSize))
- {
- return false;
- }
-
- char* buffer = new char[fileSize];
- is.clear();
- is.seekg(0);
- is.read(buffer, fileSize);
-
- if (is.fail())
- return false;
-
- os.write(buffer, fileSize);
-
- delete [] buffer;
-
- is.close();
- }
-
- //
- // append the new instance to the end of the file
- //
- if (!_insertData(out, os, index, size))
- {
- return false;
- }
-
- os.close();
-
- return true;
-}
-
-/**
- Removes an instance record from the instance file.
-
- This method creates a temporary file, then calls removeData() to remove
- the entry from the temporary file. The caller must rename the temporary
- file back to the original file after the remove operation is successful
- on BOTH the instance index file and the instance file.
- */
-Boolean InstanceFile::removeInstance(
- const String& path,
- Uint32 size,
- Uint32 index)
-{
- //
- // check for the existence of the instance file, and get the real path
- // of the file
- //
- String realPath;
-
- if (!FileSystem::existsNoCase(path, realPath))
- {
- return false;
- }
-
- //
- // Create a temporary instance index file
- //
- // First make sure that there is not already a temporary file.
- // If a temporary file already exists, remove it first.
- //
- String tempFilePath;
- if (FileSystem::existsNoCase(realPath + ".tmp", tempFilePath))
- {
- if (!FileSystem::removeFileNoCase(tempFilePath))
- {
- return false;
- }
- }
-
- ofstream os((realPath+".tmp").getCString(), ios::app | ios::binary);
-
- if (!os)
- {
- return false;
- }
-
- //
- // remove the entry from file
- //
- if (!_removeData(realPath, os, size, index))
- {
- return false;
- }
-
- os.close();
-
- return true;
-}
-
-/**
- Modifies an instance record in the instance file by first removing the
- the old instance record in the instance file, then appends the new
- instance record to the instance file. Returns the byte position and the
- size of the newly added instance record.
-
- This method creates a temporary file. All updates are done to the
- temporary file. The caller must rename the temporary file back to the
- the original file after the modify operation is successful on BOTH the
- instance index file and the instance file.
- */
-Boolean InstanceFile::modifyInstance(
- Array<Sint8> out,
- const String& path,
- Uint32 oldIndex,
- Uint32 oldSize,
- Uint32& newIndex,
- Uint32& newSize)
-{
- //
- // check for the existence of the instance file, and get the real path
- // of the file
- //
- String realPath;
-
- if (!FileSystem::existsNoCase(path, realPath))
- {
- return false;
- }
-
- //
- // Open a temporary instance file
- //
- // First make sure that there is not already a temporary file.
- // If a temporary file already exists, remove it first.
- //
- String tempFilePath;
- if (FileSystem::existsNoCase(realPath + ".tmp", tempFilePath))
- {
- if (!FileSystem::removeFileNoCase(tempFilePath))
- {
- return false;
- }
- }
-
- ofstream os((realPath+".tmp").getCString(), ios::app | ios::binary);
-
- if (!os)
- {
- return false;
- }
-
- //
- // remove the old entry from the temporary file
- //
- if (!_removeData(realPath, os, oldSize, oldIndex))
- {
- return false;
- }
-
- //
- // Append the new instance to the instance file
- //
- if (!_insertData(out, os, newIndex, newSize))
- {
- return false;
- }
-
- os.close();
-
- return true;
-}
-
-/**
- Loads data from the instance file at the given byte positon for the
- given size.
- */
-Boolean InstanceFile::_loadData(
- const String& path,
- Uint32 index,
- Uint32 size,
- Array<Sint8>& data)
-{
- //
- // open the instance file
- //
- ifstream is(path.getCString(), ios::in | ios::binary);
-
- if (!is)
- {
- return false;
- }
-
- //
- // position the file get pointer at the specified location
- //
- is.clear();
- is.seekg(index);
-
- //
- // Load data from file into memory
- //
- char* buffer = new char[size];
- is.read( buffer, size);
-
- if (is.fail())
- return false;
-
- data.clear();
- data.reserveCapacity(size+1);
- data.append(buffer, size);
- data.append('\0');
-
- is.close();
-
- delete [] buffer;
-
- return true;
-}
-
-/**
- Removes a record in the instance file at the given byte position for
- the given size.
- */
-Boolean InstanceFile::_removeData(
- const String& realPath,
- ofstream& os,
- Uint32 size,
- Uint32 index)
-{
- //
- // Open the instance file
- //
- ifstream is(realPath.getCString(), ios::in | ios::binary);
-
- if (!is)
- {
- return false;
- }
-
- //
- // get the size of the instance file
- //
- Uint32 fileSize;
- if (!FileSystem::getFileSizeNoCase(realPath, fileSize))
- {
- return false;
- }
-
- //
- // Copy all the entries in the instance file up to the one to be deleted
- //
- Array<Sint8> data;
- Uint32 copySize;
- Uint32 sizeNeeded;
-
- //
- // determine the number of bytes to copy
- //
- sizeNeeded = fileSize - size;
-
- //
- // if the entry to be deleted is not the only entry in the instance file,
- // copy the remaining entries
- //
- if (sizeNeeded > 0)
- {
- char* buffer = new char[sizeNeeded];
-
- data.clear();
- data.reserveCapacity(sizeNeeded);
-
- is.clear();
-
- //
- // copy from the beginning of the file if the entry to be deleted
- // is not the first entry in the file
- //
- if (index != 0)
- {
- is.seekg(0);
- is.read( buffer, index );
-
- if (is.fail())
- return false;
-
- data.append(buffer, index);
- }
-
- //
- // skip the entry to be deleted and copy the remaining entries
- //
- Uint32 placeToCopy = index + size;
-
- is.seekg(placeToCopy);
- copySize = (fileSize - placeToCopy) - 1;
-
- is.read( buffer, copySize );
-
- if (is.fail())
- return false;
-
- data.append(buffer, copySize);
- data.append('\0');
-
- delete [] buffer;
-
- //
- // write data to the temporary file
- //
- os << (char*)data.getData() << endl;
-
- os.flush();
- }
-
- is.close();
-
- return true;
-}
-
-/**
- Inserts a new record into the instance file.
-
- */
-Boolean InstanceFile::_insertData(
- Array<Sint8> out,
- ofstream& os,
- Uint32& index,
- Uint32& size)
-{
- Uint32 begPos; // file position before insertion
- Uint32 endPos; // file position after insertion
-
- //
- // determine current position of file
- //
- begPos = os.tellp();
- index = begPos;
-
- //
- // write the CIM/XML encoding of the instance to file
- //
-#ifdef INDENT_XML_FILES
- out.append('\0');
- XmlWriter::indentedPrint(os, out.getData(), 2);
-#else
- os.write((char*)out.getData(), out.size());
-#endif
-
- //
- // determine the size of the instance record written to file
- //
- endPos = os.tellp();
- size = endPos - begPos;
-
- os.flush();
-
- return true;
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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: Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
-//
-// Modified By:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#ifndef Pegasus_InstanceFile_h
-#define Pegasus_InstanceFile_h
-
-PEGASUS_NAMESPACE_BEGIN
-
-/** This class manages access to an 'instance file' which stores all the
- instances of a CIM class.
-
- For each instance, The CIM/XML representation is stored in the file.
- The byte location and size of a particular instance record in the file
- is stored in the 'instance index file'. The name of an instance file
- has the following form:
-
- <pre>
- className.instances
- </pre>
-
- Here's an example:
-
- <pre>
- Employee.instances
- </pre>
-
- When an instance is added, it is appended to the end of the
- instance file. After an instance is deleted, the instance file is
- reorganized to reuse the disk space. When an instance is modified,
- the old instance is deleted, and the modified instance is
- appended to the end of the file.
-
- It is very important to keep both the instance and index file in
- a consistent state. In order to minimize the window in which the
- instance and index file can be left in an inconsistent state (after
- an unexpected system termination or failure), all updates to the
- instance and index files are done first to temporary files. After
- an update operation is successful on BOTH the instance and index files,
- the temporary files are renamed back to the original files.
-
- */
-
-class PEGASUS_REPOSITORY_LINKAGE InstanceFile
-{
-public:
-
- /** loads an instance record in the instance file to memory. The caller
- passes the byte position and the size of the instance record to be
- read. Returns true on success.
-
- @param path the file path of the instance file
- @param index the byte positon of the instance record
- @param size the size of the instance record
- @param data the buffer to hold the instance data
-
- @return true if successful
- false if an error occurs in accessing the instance file
- */
- static Boolean loadInstance(
- const String& path,
- Uint32 index,
- Uint32 size,
- Array<Sint8>& data);
-
- /** loads all the instance records in the instance file to memory.
- Returns true on success.
-
- @param path the file path of the instance file
- @param data the buffer to hold the data
-
- @return true if successful
- false if an error occurs in accessing the instance file
- */
- static Boolean loadAllInstances(
- const String& path,
- Array<Sint8>& data);
-
- /** Inserts a new instance record into the instance file. The byte
- position and the size of the newly inserted instance record are
- returned. Returns true on success.
-
- @param out the buffer containing the CIM/XML encoding of the
- instance
- @param path the file path of the instance file
- @param index the byte positon of the instance record
- @param size the size of the instance record
-
- @return true if successful
- false if an error occurs in accessing the instance file
- or adding a new record to the instance file
- */
- static Boolean insertInstance(
- Array<Sint8> out,
- const String& path,
- Uint32& index,
- Uint32& size);
-
- /** Removes an instance record in the instance file at the given byte
- position for the given size. Returns true on success.
-
- @param path the file path of the instance file
- @param size the size of the instance record
- @param index the byte positon of the instance record
-
- @return true if successful
- false if an error occurs in accessing the instance file
- or removing a record from the instance file
- */
- static Boolean removeInstance(
- const String& path,
- Uint32 size,
- Uint32 index);
-
- /** Modifies an instance record in the instance file by first removing
- the old instance record in the instance file at the given byte
- position, then inserts a new instance record into the instance file.
- The byte position and the size of the newly added instance record
- are returned. Returns true on success.
-
- @param out the buffer containing the CIM/XML encoding of the
- modified instance
- @param path the file path of the instance file
- @param oldIndex the byte positon of the old instance record
- @param oldSize the size of the old instance record
- @param newIndex the byte positon of the new instance record
- @param newSize the size of the new instance record
-
- @return true if successful
- false if an error occurs in accessing or modifying the
- instance file
- */
- static Boolean modifyInstance(
- Array<Sint8> out,
- const String& path,
- Uint32 oldIndex,
- Uint32 oldSize,
- Uint32& newIndex,
- Uint32& newSize);
-
-private:
-
- /** Loads data from the instance file.
-
- This method is called to load data from the instance file. It loads
- the given number of bytes starting at the given byte position of the
- file. Returns true on success.
-
- @param path the file path of the instance file
- @param index the starting byte positon
- @param size the number of bytes to load
- @param data the buffer to hold the data
-
- @return true if successful
- false if an error occurs in accessing the instance file
- */
- static Boolean _loadData(
- const String& path,
- Uint32 index,
- Uint32 size,
- Array<Sint8>& data);
-
- /** Removes data in the temporary instance file at the given byte position
- for the given size. Returns true on success.
-
- @param path the file path of the instance file
- @parm os the ofstream of the temporary instance file
- @param size the size of the instance record
- @param index the byte positon of the instance record
-
- @return true if successful
- false if an error occurs in accessing the instance file
- or removing a record from the instance file
- */
- static Boolean _removeData(
- const String& path,
- PEGASUS_STD(ofstream)& os,
- Uint32 size,
- Uint32 index);
-
- /** Appends data to the end of the temporary instance file. Returns true
- on success.
-
- @param out the buffer containing the CIM/XML encoding of the
- instance
- @parm os the ofstream of the temporary instance file
- @param index the byte positon of the instance record
- @param size the size of the instance record
-
- @return true if successful
- false if an error occurs in accessing the instance file
- or removing a record from the instance file
- */
- static Boolean _insertData(
- Array<Sint8> out,
- PEGASUS_STD(ofstream)& os,
- Uint32& index,
- Uint32& size);
-};
-
-PEGASUS_NAMESPACE_END
-
-#endif /* Pegasus_InstanceFile_h */
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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:
-// Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#include <Pegasus/Common/Config.h>
-#include <fstream>
-#include <cctype>
-#include <cstdio>
-#include <cstdlib>
-#include <Pegasus/Common/Destroyer.h>
-#include <Pegasus/Common/FileSystem.h>
-#include "InstanceIndexFile.h"
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-//------------------------------------------------------------------------------
-//
-// _GetLine()
-//
-// Gets the next line of the file:
-//
-//------------------------------------------------------------------------------
-
-static Boolean _GetLine(istream& is, Array<char>& x)
-{
- x.clear();
- x.reserveCapacity(1024);
-
- char c;
-
- while (is.get(c) && c != '\n')
- x.append(c);
-
- x.append('\0');
-
- return is ? true : false;
-}
-
-//------------------------------------------------------------------------------
-//
-// _GetNextRecord()
-//
-// Gets the next record in the index file.
-//
-//------------------------------------------------------------------------------
-
-static Boolean _GetNextRecord(
- istream& is,
- Array<char>& line,
- Uint32& hashCode,
- const char*& objectName,
- Uint32& index,
- Uint32& size,
- Boolean& error)
-{
- error = false;
-
- // -- Get the next line:
-
- if (!_GetLine(is, line))
- return false;
-
- // -- Get the hash-code:
-
- char* end = 0;
- hashCode = strtoul(line.getData(), &end, 16);
-
- if (!end)
- {
- error = true;
- return false;
- }
-
- // -- Skip whitespace:
-
- while (*end && isspace(*end))
- end++;
-
- if (!*end)
- {
- error = true;
- return false;
- }
-
- // -- Get index:
-
- const char* indexString = end;
-
- end = 0;
- index = strtoul(indexString, &end, 10);
-
- if (!end)
- {
- error = true;
- return false;
- }
-
- // -- Skip whitespace:
-
- while (*end && isspace(*end))
- end++;
-
- if (!*end)
- {
- error = true;
- return false;
- }
-
- // -- Get size:
-
- const char* sizeString = end;
-
- end = 0;
- size = strtoul(sizeString, &end, 10);
-
- if (!end)
- {
- error = true;
- return false;
- }
-
- // -- Skip whitespace:
-
- while (*end && isspace(*end))
- end++;
-
- if (!*end)
- {
- error = true;
- return false;
- }
-
- // -- Get instance name:
-
- objectName = end;
-
- return true;
-}
-
-//------------------------------------------------------------------------------
-//
-// InstanceIndexFile::lookup()
-//
-//------------------------------------------------------------------------------
-
-Boolean InstanceIndexFile::lookup(
- const String& path,
- const CIMObjectPath& instanceName,
- Uint32& sizeOut,
- Uint32& indexOut)
-{
- indexOut = PEG_NOT_FOUND;
-
- String realPath;
-
- if (!FileSystem::existsNoCase(path, realPath))
- return false;
-
- ifstream is(realPath.getCString(), ios::binary);
-
- if (is)
- {
- Uint32 targetHashCode = instanceName.makeHashCode();
-
- Array<char> line;
- Uint32 hashCode;
- const char* objectName;
- Uint32 size;
- Uint32 index;
- Boolean error;
-
- while (_GetNextRecord(is, line, hashCode, objectName, index, size,
- error))
- {
- if (hashCode == targetHashCode &&
- CIMObjectPath(objectName) == instanceName)
- {
- indexOut = index;
- sizeOut = size;
- return true;
- }
- }
-
- if (error)
- {
- // ATTN: This should only happen if the index file is corrupted,
- // may want to log an error in the log file.
- }
- }
-
- return false;
-}
-
-//------------------------------------------------------------------------------
-//
-// InstanceIndexFile::insert()
-//
-// This method creates a temporary file, copies the contents of the original
-// instance index file to the temporary file, and appends the new entry to
-// the temporary file. The caller must rename the temporary file back to
-// the original file after the insert operation is successful on BOTH the
-// the instance index file and the instance file.
-//
-//------------------------------------------------------------------------------
-
-Boolean InstanceIndexFile::insert(
- const String& path,
- const CIMObjectPath& instanceName,
- Uint32 sizeIn,
- Uint32 indexIn)
-{
- //
- // Create a temporary instance index file
- //
- // First make sure that there is not already a temporary file exists.
- // If a temporary file already exists, remove it first.
- //
- String tempFilePath;
- if (FileSystem::existsNoCase((path + ".tmp"), tempFilePath))
- {
- if (!FileSystem::removeFileNoCase(tempFilePath))
- return false;
- }
-
- ofstream os((path+".tmp").getCString(), ios::app | ios::binary);
-
- if (!os)
- return false;
-
- //
- // Check for the existence of the original instance index file. If
- // file exists, copy the contents of the file to the temporary file.
- //
- String realPath;
- if (FileSystem::existsNoCase(path, realPath))
- {
- ifstream is(realPath.getCString(), ios::binary);
-
- if (!is)
- return false;
-
- //
- // get the size of the instance file
- //
- Uint32 fileSize;
- if (!FileSystem::getFileSizeNoCase(realPath, fileSize))
- return false;
-
- char* data = new char[fileSize];
- is.clear();
- is.seekg(0);
- is.read(data, fileSize);
-
- if (is.fail())
- return false;
-
- os.write(data, fileSize);
-
- delete [] data;
-
- is.close();
- }
-
- //
- // Append the new instance to the temporary instance index file:
- //
- _appendEntry(os, instanceName, sizeIn, indexIn);
-
- os.flush();
- os.close();
-
- return true;
-}
-
-//------------------------------------------------------------------------------
-//
-// InstanceIndexFile::remove()
-//
-// This method creates a temporary file, copies the contents of the original
-// instance index file to the temporary file, and removes the entry from the
-// the temporary file. The caller must rename the temporary file back to the
-// original file after the remove operation is successful on BOTH the
-// instance index file and the instance file.
-//
-//------------------------------------------------------------------------------
-
-Boolean InstanceIndexFile::remove(
- const String& path_,
- const CIMObjectPath& instanceName)
-{
- //
- // Check for the existence of the instance index file and get the
- // real name of the file.
- //
- String path;
-
- if (!FileSystem::existsNoCase(path_, path))
- return false;
-
- //
- // Create a temporary instance index file
- //
- // First make sure that there is not already a temporary file exists.
- // If a temporary file already exists, remove it first.
- //
- String tempFilePath;
- if (FileSystem::existsNoCase((path + ".tmp"), tempFilePath))
- {
- if (!FileSystem::removeFileNoCase(tempFilePath))
- return false;
- }
-
- ofstream os((path+".tmp").getCString(), ios::binary);
-
- if (!os)
- {
- return false;
- }
-
- //
- // remove the entry from file
- //
- if (!_removeEntry(os, path, instanceName))
- {
- return false;
- }
-
- os.flush();
- os.close();
-
- return true;
-}
-
-//------------------------------------------------------------------------------
-//
-// InstanceIndexFile::modify()
-//
-// This method creates a temporary file and copies the contents of the
-// original instance index file to the temporary file. Modifications
-// are done only to the temporary file. The caller must rename the
-// temporary file back to the original file after the modify operation
-// is successful on BOTH the instance index file and the instance file.
-//
-//------------------------------------------------------------------------------
-
-Boolean InstanceIndexFile::modify(
- const String& path,
- const CIMObjectPath& instanceName,
- Uint32 sizeIn,
- Uint32 indexIn)
-{
- //
- // Check for the existence of the instance index file and get the
- // real name of the file.
- //
- String realPath;
-
- if (!FileSystem::existsNoCase(path, realPath))
- return false;
-
- //
- // Create a temporary instance index file
- //
- // First make sure that there is not already a temporary file exists.
- // If a temporary file already exists, remove it first.
- //
- String tempFilePath;
- if (FileSystem::existsNoCase((path + ".tmp"), tempFilePath))
- {
- if (!FileSystem::removeFileNoCase(tempFilePath))
- {
- return false;
- }
- }
-
- ofstream os((realPath+".tmp").getCString(), ios::binary);
-
- if (!os)
- {
- return false;
- }
-
- //
- // remove the entry from file
- //
- if (!_removeEntry(os, realPath, instanceName))
- {
- return false;
- }
-
- //
- // Append the new instance to the temporary instance index file:
- //
- _appendEntry(os, instanceName, sizeIn, indexIn);
-
- os.flush();
- os.close();
-
- return true;
-}
-
-//------------------------------------------------------------------------------
-//
-// InstanceIndexFile::appendInstanceNamesTo()
-//
-// This method returns a list of all the instance names, as well as a list
-// of the indices (or byte locations) of the instance records, and a list
-// of the sizes of the instance records.
-//
-//------------------------------------------------------------------------------
-
-Boolean InstanceIndexFile::appendInstanceNamesTo(
- const String& path,
- Array<CIMObjectPath>& instanceNames,
- Array<Uint32>& indices,
- Array<Uint32>& sizes)
-{
- // -- Open index file and load the instance names
-
- String realPath;
-
- if (FileSystem::existsNoCase(path, realPath))
- {
- ifstream is(realPath.getCString(), ios::binary);
-
- if (!is)
- return false;
-
- // -- Build instance-names array:
-
- Array<char> line;
- Uint32 hashCode;
- const char* objectName;
- Uint32 index;
- Uint32 size;
- Boolean error;
-
- while (_GetNextRecord(is, line, hashCode, objectName, index, size,
- error))
- {
- instanceNames.append(objectName);
- indices.append(index);
- sizes.append(size);
- }
-
- if (error)
- return false;
- }
-
- return true;
-}
-
-//------------------------------------------------------------------------------
-//
-// InstanceIndexFile::_appendEntry()
-//
-// Appends a new entry to the temporary instance index file.
-//
-//------------------------------------------------------------------------------
-
-void InstanceIndexFile::_appendEntry(
- ofstream& os,
- const CIMObjectPath& instanceName,
- Uint32 sizeIn,
- Uint32 indexIn)
-{
- //
- // Append the new instance to the temporary instance index file:
- //
- Uint32 targetHashCode = instanceName.makeHashCode();
-
- char buffer[32];
- sprintf(buffer, "%08X", targetHashCode);
- os << buffer << ' ' << indexIn << ' ' << sizeIn << ' ';
- os << instanceName << endl;
-}
-
-//------------------------------------------------------------------------------
-//
-// InstanceIndexFile::_removeEntry()
-//
-// Removes an entry from the temporary instance index file.
-//
-//------------------------------------------------------------------------------
-
-Boolean InstanceIndexFile::_removeEntry(
- ofstream& os,
- const String& path,
- const CIMObjectPath& instanceName)
-{
- //
- // Open the index file
- //
- ifstream is(path.getCString(), ios::binary);
-
- if (!is)
- {
- return false;
- }
-
- //
- // Copy all entries except the one specified:
- //
- Uint32 targetHashCode = instanceName.makeHashCode();
-
- Boolean found = false;
- Array<char> line;
- Uint32 hashCode;
- const char* objectName;
- Uint32 size;
- Uint32 index;
- Boolean error;
- Uint32 deletedSize = 0;
-
- while (_GetNextRecord(is, line, hashCode, objectName, index, size, error))
- {
- if (targetHashCode == hashCode &&
- CIMObjectPath(objectName) == instanceName)
- {
- //
- // found the entry of the instance to be deleted, keep track
- // of the size of the deleted record
- //
- found = true;
- deletedSize = size;
- }
- else
- {
- if (found)
- {
- //
- // Adjust the index of the subsequent records by subtracting
- // the size of the deleted record from the index. This
- // requires that the index file entries are in the same order
- // as the instance records in the instance file.
- //
- index = index - deletedSize;
- }
-
- _appendEntry(os, objectName, size, index);
- }
- }
-
- is.close();
-
- if (error)
- {
- return false;
- }
-
- return found;
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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:
-// Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#ifndef Pegasus_InstanceIndexFile_h
-#define Pegasus_InstanceIndexFile_h
-
-#include <Pegasus/Common/Config.h>
-#include <Pegasus/Common/String.h>
-#include <Pegasus/Common/InternalException.h>
-#include <Pegasus/Common/CIMObjectPath.h>
-
-PEGASUS_NAMESPACE_BEGIN
-
-/** This class manages access to an 'instance index file' which maps
- instance names to the index (or location) of the instances in an
- 'instance file'. Lines of this file have the following form:
-
- <pre>
- <hash-code> <index> <size> ClassName.key1=value1,...,keyN=valueN
- </pre>
-
- Where the hash-code is an eight digit hex number, the index is the byte
- location of the instance record in the instance file, the size is the
- record size of the instance record, and instance name is a CIM style
- object name.
-
- Here's an example:
-
- <pre>
- A6B275A9 0 1425 Employee.ssn=444332222
- A6BA08BE 1425 1430 Employee.ssn=555667777
- </pre>
-
- Each instance in Pegasus is represented as a record in the instance
- file for the CIM class. Each instance record contains the CIM/XML
- encoding of the instance. Information about each instance record in
- an instance file is kept in an instance index file. The name of
- an instance index file has the following form:
-
- <pre>
- ClassName.idx
- </pre>
-
- Here's an example:
-
- <pre>
- Employee.idx
- </pre>
-
- An instance can be obtained from an instance name by searching all entries
- in the instance index file with the same hash code (to account for hash
- clashes), comparing the instance names, and obtaining the index and size
- of the instance record in the corresponding instance file.
-
- Methods are provided for managing the instance index file: adding,
- removing, and modifying.
-
- It is very important to keep both the instance and index file in a
- consistent state. In order to minimize the window in which the
- instance and index file can be left in an inconsistent state (after
- an unexpected system termination or failure), all updates to the
- instance and index files are done first to the temporary files. After
- an update operation is successful on BOTH the instance and index files,
- the temporary files are renamed back to the original files.
-
-*/
-
-class PEGASUS_REPOSITORY_LINKAGE InstanceIndexFile
-{
-public:
-
- /** Searches the instance index file for the given instance name. Sets
- the index parameter to the corresponding index, and sets the size
- parameter to the corresponding instance record size. Returns true
- on success.
-
- @param path the file path of the instance index file
- @param instanceName the name of the instance
- @param sizeOut the size of the instance record found
- @param indexOut the index of the instance record found
-
- @return true if the instance is found
- false if the instance cannot be found
- */
- static Boolean lookup(
- const String& path,
- const CIMObjectPath& instanceName,
- Uint32& sizeOut,
- Uint32& indexOut);
-
- /** Inserts a new entry into the instance index file. Saves the index and
- size of the instance record passed in. This method assumes that the
- keys in the instance name are in sorted order. This must be done
- prior to calling the method. Returns true on success.
-
- @param path the file path of the instance index file
- @param instanceName the name of the instance
- @param sizeIn the size of the new instance record
- @param indexIn the index of the new instance record
-
- @return true if successful
- false if an error occurs in inserting the entry
- */
- static Boolean insert(
- const String& path,
- const CIMObjectPath& instanceName,
- Uint32 sizeIn,
- Uint32 indexIn);
-
- /** Removes the entry with the given instance name. Returns true on
- success.
-
- @param path the file path of the instance index file
- @param instanceName the name of the instance
-
- @return true if successful
- false if an error occurs in removing the entry
- */
- static Boolean remove(
- const String& path,
- const CIMObjectPath& instanceName);
-
- /** Modifies an entry by first removing the old entry and then inserting
- a new entry at the end of the file. Returns true on success.
-
- @param path the file path of the instance index file
- @param instanceName the name of the instance
- @param sizeIn the size of the modified instance record
- @param indexIn the index of the modified instance record
-
- @return true if successful
- false if an error occurs in modifying the entry
- */
- static Boolean modify(
- const String& path,
- const CIMObjectPath& instanceName,
- Uint32 sizeIn,
- Uint32 indexIn);
-
- /** Gets the information stored in the index file for all the instances
- of the given class. Appends the instance names, indices and sizes
- to the given arrays (does not clear the arrays first). Returns
- true on success.
-
- @param path the file path of the instance index file
- @param instanceNames an array to hold the instance names
- @param indices an array to hold the indices of the instance
- records
- @param sizes an array to hold the sizes of the instance
- records
-
- @return true if successful
- false if an error occurs in loading information from
- the instance index file
- */
- static Boolean appendInstanceNamesTo(
- const String& path,
- Array<CIMObjectPath>& instanceNames,
- Array<Uint32>& indices,
- Array<Uint32>& sizes);
-
-private:
-
- /** Appends a new entry to the temporary index file. Returns true
- on success.
-
- @param os the ofstream of the temporary index file
- @param instanceName the name of the instance
- @param sizeIn the size of the new instance record
- @param indexIn the index of the new instance record
-
- @return true if successful
- false if an error occurs in appending the entry
- */
- static void _appendEntry(
- PEGASUS_STD(ofstream)& os,
- const CIMObjectPath& instanceName,
- Uint32 sizeIn,
- Uint32 indexIn);
-
- /** Removes an entry from the temporary instance index file. Returns
- true on success.
-
- @param os the ofstream of the temporary index file
- @param path the file path of the original instance index file
- @param instanceName the name of the instance
-
- @return true if successful
- false if an error occurs in removing the entry
- */
- static Boolean _removeEntry(
- PEGASUS_STD(ofstream)& os,
- const String& path,
- const CIMObjectPath& instanceName);
-};
-
-PEGASUS_NAMESPACE_END
-
-#endif /* Pegasus_InstanceIndexFile_h */
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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 <Pegasus/Common/FileSystem.h>
-#include <Pegasus/Common/String.h>
-#include <Pegasus/Common/HashTable.h>
-#include <Pegasus/Common/Dir.h>
-#include "NameSpaceManager.h"
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-static char _CLASSES_DIR[] = "classes";
-static char _INSTANCES_DIR[] = "instances";
-static char _QUALIFIERS_DIR[] = "qualifiers";
-
-static char _CLASSES_SUFFIX[] = "/classes";
-static char _INSTANCES_SUFFIX[] = "/instances";
-static char _QUALIFIERS_SUFFIX[] = "/qualifiers";
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// _MakeClassFilePath()
-//
-////////////////////////////////////////////////////////////////////////////////
-
-static inline String _MakeClassFilePath(
- const String& nameSpacePath,
- const String& className,
- const String& superClassName)
-{
- if (superClassName.size())
- {
- return nameSpacePath + _CLASSES_SUFFIX + "/" + className + "." +
- superClassName;
- }
- else
- return nameSpacePath + _CLASSES_SUFFIX + "/" + className + ".#";
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// _MakeQualifierFilePath()
-//
-////////////////////////////////////////////////////////////////////////////////
-
-static inline String _MakeQualifierFilePath(
- const String& nameSpacePath,
- const String& qualifierName)
-{
- return nameSpacePath + _QUALIFIERS_SUFFIX + "/" + qualifierName;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// _MakeInstanceFileBase()
-//
-////////////////////////////////////////////////////////////////////////////////
-
-static inline String _MakeInstanceFileBase(
- const String& nameSpacePath,
- const String& className)
-{
- return nameSpacePath + _INSTANCES_SUFFIX + "/" + className;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// NameSpace
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class NameSpace
-{
-public:
-
- NameSpace(const String& nameSpacePath, const String& nameSpaceName);
-
- ~NameSpace();
-
- const String& getNameSpacePath() const { return _nameSpacePath; }
-
- const String& getNameSpaceName() const { return _nameSpaceName; }
-
- const String getClassFilePath(const String& className) const;
-
- const String getQualifierFilePath(const String& qualifierName) const;
-
- const String getInstanceFileBase(const String& className) const;
-
- InheritanceTree& getInheritanceTree() { return _inheritanceTree; }
-
- /** Print this namespace. */
- void print(PEGASUS_STD(ostream)& os) const;
-
-private:
-
- InheritanceTree _inheritanceTree;
- String _nameSpacePath;
- String _nameSpaceName;
-};
-
-NameSpace::NameSpace(const String& nameSpacePath, const String& nameSpaceName)
- : _nameSpacePath(nameSpacePath), _nameSpaceName(nameSpaceName)
-{
- _inheritanceTree.insertFromPath(nameSpacePath + "/classes");
-}
-
-NameSpace::~NameSpace()
-{
-
-}
-
-const String NameSpace::getClassFilePath(const String& className) const
-{
- String superClassName;
-
- if (!_inheritanceTree.getSuperClass(className, superClassName))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS, className);
-
- return _MakeClassFilePath(_nameSpacePath, className, superClassName);
-}
-
-const String NameSpace::getQualifierFilePath(const String& qualifierName) const
-{
- return _MakeQualifierFilePath(_nameSpacePath, qualifierName);
-}
-
-const String NameSpace::getInstanceFileBase(const String& className) const
-{
- return _MakeInstanceFileBase(_nameSpacePath, className);
-}
-
-void NameSpace::print(PEGASUS_STD(ostream)& os) const
-{
- os << "=== NameSpace: " << _nameSpaceName << PEGASUS_STD(endl);
- os << "_nameSpacePath: " << _nameSpacePath << PEGASUS_STD(endl);
- _inheritanceTree.print(os);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// NameSpaceManagerRep
-//
-////////////////////////////////////////////////////////////////////////////////
-
-typedef HashTable<String,NameSpace*,EqualFunc<String>,HashFunc<String> > Table;
-
-struct NameSpaceManagerRep
-{
- Table table;
-};
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// NameSpaceManager
-//
-////////////////////////////////////////////////////////////////////////////////
-
-static Boolean _IsNameSpaceDir(const String& nameSpacePath)
-{
- if (!FileSystem::isDirectory(nameSpacePath))
- return false;
-
- if (!FileSystem::isDirectory(nameSpacePath + _CLASSES_SUFFIX))
- return false;
-
- if (!FileSystem::isDirectory(nameSpacePath + _INSTANCES_SUFFIX))
- return false;
-
- if (!FileSystem::isDirectory(nameSpacePath + _QUALIFIERS_SUFFIX))
- return false;
-
- return true;
-}
-
-static void _CreateNameSpaceDirectories(const String& nameSpacePath)
-{
- if (!FileSystem::makeDirectory(nameSpacePath))
- throw CannotCreateDirectory(nameSpacePath);
-
- String classesPath = nameSpacePath + _CLASSES_SUFFIX;
- String instancesPath = nameSpacePath + _INSTANCES_SUFFIX;
- String qualifiersPath = nameSpacePath + _QUALIFIERS_SUFFIX;
-
- if (!FileSystem::makeDirectory(classesPath))
- throw CannotCreateDirectory(classesPath);
-
- if (!FileSystem::makeDirectory(instancesPath))
- throw CannotCreateDirectory(instancesPath);
-
- if (!FileSystem::makeDirectory(qualifiersPath))
- throw CannotCreateDirectory(qualifiersPath);
-}
-
-static Boolean _NameSpaceDirHierIsEmpty(const String& nameSpacePath)
-{
- for (Dir dir(nameSpacePath); dir.more(); dir.next())
- {
- const char* name = dir.getName();
-
- if (strcmp(name, ".") != 0 &&
- strcmp(name, "..") != 0 &&
- CompareNoCase(name, _CLASSES_DIR) != 0 &&
- CompareNoCase(name, _INSTANCES_DIR) != 0 &&
- CompareNoCase(name, _QUALIFIERS_DIR) != 0)
- {
- return true;
- }
- }
-
- String classesPath = nameSpacePath + _CLASSES_SUFFIX;
- String instancesPath = nameSpacePath + _INSTANCES_SUFFIX;
- String qualifiersPath = nameSpacePath + _QUALIFIERS_SUFFIX;
-
- return
- FileSystem::isDirectoryEmpty(classesPath) &&
- FileSystem::isDirectoryEmpty(instancesPath) &&
- FileSystem::isDirectoryEmpty(qualifiersPath);
-}
-
-NameSpaceManager::NameSpaceManager(const String& repositoryRoot)
- : _repositoryRoot(repositoryRoot)
-{
- // Create directory if does not already exist:
-
- if (!FileSystem::isDirectory(_repositoryRoot))
- {
- if (!FileSystem::makeDirectory(_repositoryRoot))
- throw CannotCreateDirectory(_repositoryRoot);
- }
-
- _rep = new NameSpaceManagerRep;
-
- // Create a NameSpace object for each directory under repositoryRoot.
- // This will throw an exception if the directory does not exist:
-
- for (Dir dir(repositoryRoot); dir.more(); dir.next())
- {
- String dirName = dir.getName();
-
- if (dirName == ".." || dirName == ".")
- continue;
-
- String nameSpacePath = repositoryRoot + "/" + dirName;
-
- if (_IsNameSpaceDir(nameSpacePath))
- {
- String nameSpaceName = dirName;
- nameSpaceName.translate('#', '/');
-
- NameSpace* nameSpace = 0;
-
- try
- {
- nameSpace = new NameSpace(nameSpacePath, nameSpaceName);
- }
- catch (Exception& e)
- {
- delete nameSpace;
- throw e;
- }
-
- _rep->table.insert(nameSpaceName, nameSpace);
- }
- }
-}
-
-NameSpaceManager::~NameSpaceManager()
-{
- for (Table::Iterator i = _rep->table.start(); i; i++)
- delete i.value();
-
- delete _rep;
-}
-
-Boolean NameSpaceManager::nameSpaceExists(const String& nameSpaceName) const
-{
- return _rep->table.contains(nameSpaceName);
-}
-
-void NameSpaceManager::createNameSpace(const String& nameSpaceName)
-{
- // Throw exception if namespace already exists:
-
- if (nameSpaceExists(nameSpaceName))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS, nameSpaceName);
-
- // Attempt to create all the namespace diretories:
-
- String nameSpaceDirName = nameSpaceName;
- nameSpaceDirName.translate('/', '#');
- String nameSpacePath = _repositoryRoot + "/" + nameSpaceDirName;
-
- _CreateNameSpaceDirectories(nameSpacePath);
-
- // Create NameSpace object and register it:
-
- NameSpace* nameSpace = 0;
-
- try
- {
- nameSpace = new NameSpace(nameSpacePath, nameSpaceName);
- }
- catch (Exception& e)
- {
- delete nameSpace;
- throw e;
- }
-
- _rep->table.insert(nameSpaceName, nameSpace);
-}
-
-void NameSpaceManager::deleteNameSpace(const String& nameSpaceName)
-{
- // If no such namespace:
-
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- // Form namespace path:
-
- String nameSpaceDirName = nameSpaceName;
- nameSpaceDirName.translate('/', '#');
- String nameSpacePath = _repositoryRoot + "/" + nameSpaceDirName;
-
- // Delete the entire namespace directory hierarchy:
-
- if (!_NameSpaceDirHierIsEmpty(nameSpacePath))
- throw NonEmptyNameSpace(nameSpaceName);
-
- if (!FileSystem::removeDirectoryHier(nameSpacePath))
- throw CannotRemoveDirectory(nameSpacePath);
-
- // Remove and delete the namespace object:
-
- Boolean success = _rep->table.remove(nameSpaceName);
- PEGASUS_ASSERT(success);
- delete nameSpace;
-}
-
-void NameSpaceManager::getNameSpaceNames(Array<String>& nameSpaceNames) const
-{
- nameSpaceNames.clear();
-
- for (Table::Iterator i = _rep->table.start(); i; i++)
- nameSpaceNames.append(i.key());
-}
-
-String NameSpaceManager::getClassFilePath(
- const String& nameSpaceName,
- const String& className) const
-{
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- return nameSpace->getClassFilePath(className);
-}
-
-String NameSpaceManager::getInstanceFileBase(
- const String& nameSpaceName,
- const String& className) const
-{
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- return nameSpace->getInstanceFileBase(className);
-}
-
-String NameSpaceManager::getQualifierFilePath(
- const String& nameSpaceName,
- const String& qualifierName) const
-{
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- return nameSpace->getQualifierFilePath(qualifierName);
-}
-
-void NameSpaceManager::deleteClass(
- const String& nameSpaceName,
- const String& className) const
-{
- // -- Lookup NameSpace object:
-
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- // -- Get path to class file:
-
- String classFilePath = nameSpace->getClassFilePath(className);
-
- // -- Remove the file from the inheritance tree:
-
- nameSpace->getInheritanceTree().remove(className);
-
- // -- Remove the file from disk:
-
- if (!FileSystem::removeFileNoCase(classFilePath))
- throw CannotRemoveFile(classFilePath);
-}
-
-void NameSpaceManager::print(PEGASUS_STD(ostream)& os) const
-{
- for (Table::Iterator i = _rep->table.start(); i; i++)
- {
- NameSpace* nameSpace = i.value();
- nameSpace->print(os);
- }
-
- os << PEGASUS_STD(endl);
-}
-
-void NameSpaceManager::createClass(
- const String& nameSpaceName,
- const String& className,
- const String& superClassName,
- String& classFilePath)
-{
- // -- Lookup namespace:
-
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- InheritanceTree& it = nameSpace->getInheritanceTree();
-
- // -- Be certain class doesn't already exist:
-
- if (it.containsClass(className))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_ALREADY_EXISTS, className);
-
- // -- Be certain superclass exists:
-
- if (superClassName.size() && !it.containsClass(superClassName))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_SUPERCLASS, superClassName);
-
- // -- Insert the entry:
-
- it.insert(className, superClassName);
-
- // -- Build the path to the class:
-
- classFilePath = _MakeClassFilePath(
- nameSpace->getNameSpacePath(), className, superClassName);
-}
-
-void NameSpaceManager::checkModify(
- const String& nameSpaceName,
- const String& className,
- const String& superClassName,
- String& classFilePath)
-{
- // -- Lookup namespace:
-
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- InheritanceTree& it = nameSpace->getInheritanceTree();
-
- // -- Disallow changing of superclass:
-
- String oldSuperClassName;
-
- if (!it.getSuperClass(className, oldSuperClassName))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS, className);
-
- if (superClassName != oldSuperClassName)
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "attempt to change superclass");
-
- // -- Disallow modification of class with subclasses:
-
- Boolean hasSubClasses;
- it.hasSubClasses(className, hasSubClasses);
-
- if (hasSubClasses)
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_CLASS_HAS_CHILDREN, className);
-
- // -- Build the path to the class:
-
- classFilePath = _MakeClassFilePath(
- nameSpace->getNameSpacePath(), className, superClassName);
-}
-
-void NameSpaceManager::getSubClassNames(
- const String& nameSpaceName,
- const String& className,
- Boolean deepInheritance,
- Array<String>& subClassNames) const
-{
- // -- Lookup namespace:
-
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- InheritanceTree& it = nameSpace->getInheritanceTree();
-
- if (!it.getSubClassNames(className, deepInheritance, subClassNames))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS, className);
-}
-
-void NameSpaceManager::getSuperClassNames(
- const String& nameSpaceName,
- const String& className,
- Array<String>& subClassNames) const
-{
- // -- Lookup namespace:
-
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- InheritanceTree& it = nameSpace->getInheritanceTree();
-
- // -- Get names of all superclasses:
-
- if (!it.getSuperClassNames(className, subClassNames))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_CLASS, className);
-}
-
-String NameSpaceManager::getQualifiersRoot(const String& nameSpaceName) const
-{
- // -- Lookup namespace:
-
- NameSpace* nameSpace = 0;
-
- if (!_rep->table.lookup(nameSpaceName, nameSpace))
- throw PEGASUS_CIM_EXCEPTION(CIM_ERR_INVALID_NAMESPACE, nameSpaceName);
-
- return nameSpace->getNameSpacePath() + _QUALIFIERS_SUFFIX;
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#ifndef Pegasus_NameSpaceManager_h
-#define Pegasus_NameSpace_Managerh
-
-#include <Pegasus/Common/Config.h>
-#include <Pegasus/Repository/InheritanceTree.h>
-
-PEGASUS_NAMESPACE_BEGIN
-
-struct NameSpaceManagerRep;
-class NameSpace;
-
-
-/** The NameSpaceManager class manages a collection of NameSpace objects.
-*/
-class PEGASUS_REPOSITORY_LINKAGE NameSpaceManager
-{
-public:
-
- /** Constructor.
- @param repositoryRoot path to directory called "repository".
- @exception NoSuchDirectory if repositoryRoot not a valid directory.
- */
- NameSpaceManager(const String& repositoryRoot);
-
- /** Destructor.
- */
- ~NameSpaceManager();
-
- /** Determines whether the given namespace exists:
- @param nameSpaceName name of namespace.
- @return true if namespace eixsts; false otherwise.
- */
- Boolean nameSpaceExists(const String& nameSpaceName) const;
-
- /** Creates the given namespace.
- @param nameSpaceName name of namespace to be created.
- @exception CIMException(CIM_ERR_ALREADY_EXISTS)
- @exception CannotCreateDirectory
- */
- void createNameSpace(const String& nameSpaceName);
-
- /** Deletes the given namespace.
- @param nameSpaceName name of namespace to be deleted.
- @exception CIMException(CIM_ERR_INVALID_NAMESPACE)
- @exception NonEmptyNameSpace
- @exception FailedToRemoveDirectory
- */
- void deleteNameSpace(const String& nameSpaceName);
-
- /** Gets array of all namespace names.
- @param nameSpaceNames filled with names of all namespaces.
- */
- void getNameSpaceNames(Array<String>& nameSpaceNames) const;
-
- /** Get path to the class file for the given class.
- @param nameSpaceName name of the namespace.
- @param className name of class.
- @exception CIMException(CIM_ERR_INVALID_NAMESPACE)
- @exception CIMException(CIM_ERR_INVALID_CLASS)
- */
- String getClassFilePath(
- const String& nameSpaceName,
- const String& className) const;
-
- /** Get path to the qualifier file for the given class.
- @param nameSpaceName name of the namespace.
- @param qualifierName name of qualifier.
- @exception CIMException(CIM_ERR_INVALID_NAMESPACE)
- @exception CIMException(CIM_ERR_NOT_FOUND)
- */
- String getQualifierFilePath(
- const String& nameSpaceName,
- const String& qualifierName) const;
-
- String getInstanceFileBase(
- const String& nameSpaceName,
- const String& className) const;
-
- /** Get path to the directory containing qualifiers:
- @param nameSpaceName name of the namespace.
- */
- String getQualifiersRoot(const String& nameSpaceName) const;
-
- /** Deletes the class file for the given class.
- @param nameSpaceName name of namespace.
- @param className name of class.
- @exception CIMException(CIM_ERR_INVALID_NAMESPACE)
- @exception CIMException(CIM_ERR_INVALID_CLASS)
- @exception CIMException(CIM_ERR_CLASS_HAS_CHILDREN)
- */
- void deleteClass(
- const String& nameSpaceName,
- const String& className) const;
-
- /** Print out the namespaces. */
- void print(PEGASUS_STD(ostream)& os) const;
-
- /** Creates an entry for a new class.
- @param nameSpaceName namespace to contain class.
- @param className name of class
- @param superClassName name of superClassName
- @param classFilePath path of file to contain class itself.
- */
- void createClass(
- const String& nameSpaceName,
- const String& className,
- const String& superClassName,
- String& classFilePath);
-
- /** Checks if it is okay to modify this class.
- @param nameSpaceName namespace.
- @param className name of class being modified.
- @param superClassName superclass of class being modified.
- @param classFilePath full path to file containing class.
- @exception CIMException(CIM_ERR_INVALID_CLASS)
- @exception CIMException(CIM_ERR_FAILED) if there is an attempt
- to change the superclass of this class.
- @exception CIMException(CIM_ERR_CLASS_HAS_CHILDREN) if class
- has any children.
- */
- void checkModify(
- const String& nameSpaceName,
- const String& className,
- const String& superClassName,
- String& classFilePath);
-
- /** Get subclass names of the given class in the given namespace.
- @param nameSpaceName
- @param className - class whose subclass names will be gotten. If
- className is empty, all classnames are returned.
- @param deepInheritance - if true all descendent classes of class
- are returned. If className is empty, only root classes are returned.
- @param subClassNames - output argument to hold subclass names.
- @exception CIMException(CIM_ERR_INVALID_CLASS)
- */
- void getSubClassNames(
- const String& nameSpaceName,
- const String& className,
- Boolean deepInheritance,
- Array<String>& subClassNames) const;
-
- /** Get the names of all superclasses (direct and indirect) of this
- class.
- */
- void getSuperClassNames(
- const String& nameSpaceName,
- const String& className,
- Array<String>& subClassNames) const;
-
-private:
-
- String _repositoryRoot;
- NameSpaceManagerRep* _rep;
-};
-
-/** This exception is thrown if one attempts to remove a namespace that still
- contains classes, instances, or qualifier.
-*/
-class NonEmptyNameSpace : public Exception
-{
-public:
-
- NonEmptyNameSpace(const String& nameSpaceName) : Exception(
- "Attempt to delete a non-empty namespace: " + nameSpaceName) { }
-};
-
-PEGASUS_NAMESPACE_END
-
-#endif /* Pegasus_NameSpaceManager_h */
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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 "RepositoryDeclContext.h"
-#include <Pegasus/Repository/CIMRepository.h>
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-RepositoryDeclContext::RepositoryDeclContext(CIMRepository* repository)
- : _repository(repository)
-{
-
-}
-
-RepositoryDeclContext::~RepositoryDeclContext()
-{
-
-}
-
-CIMQualifierDecl RepositoryDeclContext::lookupQualifierDecl(
- const String& nameSpace,
- const String& qualifierName) const
-{
- // Ignore the exception since this routine is only supposed report
- // whether it can be found:
-
- try
- {
- return _repository->getQualifier(nameSpace, qualifierName);
- }
- catch (Exception&)
- {
- return CIMQualifierDecl();
- }
-}
-
-CIMClass RepositoryDeclContext::lookupClass(
- const String& nameSpace,
- const String& className) const
-{
- // Ignore the exception since this routine is only supposed report
- // whether it can be found:
-
- try
- {
- return _repository->getClass(nameSpace, className, false, true, true);
- }
- catch (Exception&)
- {
- return CIMClass();
- }
-}
-
-PEGASUS_NAMESPACE_END
+++ /dev/null
-//%2003////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
-// Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
-// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
-// IBM Corp.; EMC Corporation, The Open Group.
-//
-// 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 ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
-// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. 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:
-//
-//%/////////////////////////////////////////////////////////////////////////////
-
-#ifndef PegasusRepository_Repository_Decl_Context_h
-#define PegasusRepository_Repository_Decl_Context_h
-
-#include <Pegasus/Common/DeclContext.h>
-
-PEGASUS_USING_STD;
-
-PEGASUS_NAMESPACE_BEGIN
-
-class CIMRepository; // forward declaration for repository member
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// RepositoryDeclContext
-//
-// This context is used by the resolve() methods to lookup dependent
-// objects during resolution.
-//
-////////////////////////////////////////////////////////////////////////////////
-
-class PEGASUS_REPOSITORY_LINKAGE RepositoryDeclContext : public DeclContext
-{
-public:
-
- RepositoryDeclContext(CIMRepository* repository);
-
- virtual ~RepositoryDeclContext();
-
- virtual CIMQualifierDecl lookupQualifierDecl(
- const String& nameSpace,
- const String& qualifierName) const;
-
- virtual CIMClass lookupClass(
- const String& nameSpace,
- const String& className) const;
-
-protected:
-
- CIMRepository* _repository;
-};
-
-PEGASUS_NAMESPACE_END
-
-#endif
+++ /dev/null
-ROOT = ../../../..
-
-DIR = Pegasus/Repositories/genericfile
-
-include $(ROOT)/mak/config.mak
-
-INCLUDES = -I..
-
-LOCAL_DEFINES = -DPEGASUS_REPOSITORY_INTERNAL
-
-LIBRARIES = pegcommon \
- pegconfig
-
-LIBRARY = pegrepository
-
-SOURCES = \
- AssocClassTable.cpp \
- AssocInstTable.cpp \
- NameSpaceManager.cpp \
- InheritanceTree.cpp \
- InstanceIndexFile.cpp \
- InstanceFile.cpp \
- RepositoryDeclContext.cpp \
- CIMRepository.cpp
-
-include $(ROOT)/mak/library.mak