version 1.1.2.6, 2007/11/08 15:56:25
|
version 1.1.2.7, 2007/11/08 23:20:50
|
|
|
#include "RepositoryDeclContext.h" | #include "RepositoryDeclContext.h" |
#include "Filtering.h" | #include "Filtering.h" |
#include "Serialization.h" | #include "Serialization.h" |
#include "MetaTypes.h" |
#include "SchemaTypes.h" |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
typedef const MetaClass* ConstMetaClassPtr; |
typedef const SchemaClass* ConstSchemaClassPtr; |
#define PEGASUS_ARRAY_T ConstMetaClassPtr |
#define PEGASUS_ARRAY_T ConstSchemaClassPtr |
# include <Pegasus/Common/ArrayInter.h> | # include <Pegasus/Common/ArrayInter.h> |
# include <Pegasus/Common/ArrayImpl.h> | # include <Pegasus/Common/ArrayImpl.h> |
#undef PEGASUS_ARRAY_T | #undef PEGASUS_ARRAY_T |
|
|
//============================================================================== | //============================================================================== |
| |
static size_t const _MAX_NAMESPACE_TABLE_SIZE = 64; | static size_t const _MAX_NAMESPACE_TABLE_SIZE = 64; |
static const MetaNameSpace* _nameSpaceTable[_MAX_NAMESPACE_TABLE_SIZE]; |
static const SchemaNameSpace* _nameSpaceTable[_MAX_NAMESPACE_TABLE_SIZE]; |
static size_t _nameSpaceTableSize = 0; | static size_t _nameSpaceTableSize = 0; |
| |
static const size_t _MAX_FEATURES = 128; | static const size_t _MAX_FEATURES = 128; |
|
|
} | } |
| |
static void _applyModifiedInstance( | static void _applyModifiedInstance( |
const MetaClass* mc, |
const SchemaClass* mc, |
const CIMInstance& modifiedInstance_, | const CIMInstance& modifiedInstance_, |
const CIMPropertyList& propertyList, | const CIMPropertyList& propertyList, |
CIMInstance& resultInstance) | CIMInstance& resultInstance) |
|
|
{ | { |
// Reject attempts to add properties not in class: | // Reject attempts to add properties not in class: |
| |
const MetaFeature* mf = FindFeature( |
const SchemaFeature* mf = FindFeature(mc, |
mc, *Str(cp.getName()), META_FLAG_PROPERTY|META_FLAG_REFERENCE); |
*Str(cp.getName()), SCHEMA_FLAG_PROPERTY|SCHEMA_FLAG_REFERENCE); |
| |
if (!mf) | if (!mf) |
{ | { |
|
|
| |
// Reject attempts to modify key properties: | // Reject attempts to modify key properties: |
| |
if (mf->flags & META_FLAG_KEY) |
if (mf->flags & SCHEMA_FLAG_KEY) |
{ | { |
Throw((CIM_ERR_FAILED, | Throw((CIM_ERR_FAILED, |
"modifyInstance() failed to modify key property: %s", | "modifyInstance() failed to modify key property: %s", |
|
|
return System::strcasecmp(s1, s2) == 0; | return System::strcasecmp(s1, s2) == 0; |
} | } |
| |
static const MetaNameSpace* _findNameSpace(const char* name) |
static const SchemaNameSpace* _findNameSpace(const char* name) |
{ | { |
for (size_t i = 0; i < _nameSpaceTableSize; i++) | for (size_t i = 0; i < _nameSpaceTableSize; i++) |
{ | { |
const MetaNameSpace* ns = _nameSpaceTable[i]; |
const SchemaNameSpace* ns = _nameSpaceTable[i]; |
| |
if (_eqi(ns->name, name)) | if (_eqi(ns->name, name)) |
return ns; | return ns; |
|
|
return 0; | return 0; |
} | } |
| |
static bool _isSubClass(const MetaClass* super, const MetaClass* sub) |
static bool _isSubClass(const SchemaClass* super, const SchemaClass* sub) |
{ | { |
if (!super) | if (!super) |
return true; | return true; |
| |
for (MetaClass* p = sub->super; p; p = p->super) |
for (SchemaClass* p = sub->super; p; p = p->super) |
{ | { |
if (p == super) | if (p == super) |
return true; | return true; |
|
|
} | } |
| |
static inline bool _isDirectSubClass( | static inline bool _isDirectSubClass( |
const MetaClass* super, |
const SchemaClass* super, |
const MetaClass* sub) |
const SchemaClass* sub) |
{ | { |
return sub->super == super; | return sub->super == super; |
} | } |
|
|
printf("pl[%s]\n", pl[i]); | printf("pl[%s]\n", pl[i]); |
} | } |
| |
static bool _contains(const Array<const MetaClass*>& x, const MetaClass* mc) |
static bool _contains(const Array<const SchemaClass*>& x, const SchemaClass* mc) |
{ | { |
Uint32 n = x.size(); | Uint32 n = x.size(); |
const MetaClass* const* p = x.getData(); |
const SchemaClass* const* p = x.getData(); |
| |
while (n--) | while (n--) |
{ | { |
|
|
} | } |
| |
static void _associators( | static void _associators( |
const MetaNameSpace* ns, |
const SchemaNameSpace* ns, |
const CIMName& className, | const CIMName& className, |
const CIMName& assocClass, | const CIMName& assocClass, |
const CIMName& resultClass, | const CIMName& resultClass, |
const String& role, | const String& role, |
const String& resultRole, | const String& resultRole, |
Array<const MetaClass*>& result) |
Array<const SchemaClass*>& result) |
{ | { |
// Lookup source class: | // Lookup source class: |
| |
const MetaClass* mc = FindClass(ns, *Str(className)); |
const SchemaClass* mc = FindClass(ns, *Str(className)); |
| |
if (!mc) | if (!mc) |
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); | Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
|
|
| |
// Lookup result class (if any). | // Lookup result class (if any). |
| |
const MetaClass* rmc = 0; |
const SchemaClass* rmc = 0; |
| |
if (!resultClass.isNull()) | if (!resultClass.isNull()) |
{ | { |
|
|
| |
for (size_t i = 0; ns->classes[i]; i++) | for (size_t i = 0; ns->classes[i]; i++) |
{ | { |
MetaClass* amc = ns->classes[i]; |
SchemaClass* amc = ns->classes[i]; |
| |
// Skip non-association classes: | // Skip non-association classes: |
| |
if (!(amc->flags & META_FLAG_ASSOCIATION)) |
if (!(amc->flags & SCHEMA_FLAG_ASSOCIATION)) |
continue; | continue; |
| |
// Filter by assocClass parameter: | // Filter by assocClass parameter: |
|
|
| |
// Process reference properties: | // Process reference properties: |
| |
MetaFeatureInfo features[META_MAX_FEATURES]; |
SchemaFeatureInfo features[SCHEMA_MAX_FEATURES]; |
size_t size = 0; | size_t size = 0; |
MergeFeatures(amc, false, META_FLAG_REFERENCE, features, size); |
MergeFeatures(amc, false, SCHEMA_FLAG_REFERENCE, features, size); |
| |
for (size_t j = 0; j < size; j++) | for (size_t j = 0; j < size; j++) |
{ | { |
const MetaFeature* mf = features[j].mf; |
const SchemaFeature* mf = features[j].mf; |
| |
// Skip non references: | // Skip non references: |
| |
if (!(mf->flags & META_FLAG_REFERENCE)) |
if (!(mf->flags & SCHEMA_FLAG_REFERENCE)) |
continue; | continue; |
| |
const MetaReference* mr = (const MetaReference*)mf; |
const SchemaReference* mr = (const SchemaReference*)mf; |
| |
// Filter by role parameter. | // Filter by role parameter. |
| |
|
|
| |
for (size_t k = 0; k < size; k++) | for (size_t k = 0; k < size; k++) |
{ | { |
const MetaFeature* rmf = features[k].mf; |
const SchemaFeature* rmf = features[k].mf; |
| |
// Skip the feature under consideration: | // Skip the feature under consideration: |
| |
|
|
| |
// Skip non references: | // Skip non references: |
| |
if (!(rmf->flags & META_FLAG_REFERENCE)) |
if (!(rmf->flags & SCHEMA_FLAG_REFERENCE)) |
continue; | continue; |
| |
const MetaReference* rmr = (const MetaReference*)rmf; |
const SchemaReference* rmr = (const SchemaReference*)rmf; |
| |
// Filter by resultRole parameter. | // Filter by resultRole parameter. |
| |
|
|
} | } |
| |
static void _references( | static void _references( |
const MetaNameSpace* ns, |
const SchemaNameSpace* ns, |
const CIMName& className, | const CIMName& className, |
const CIMName& resultClass, | const CIMName& resultClass, |
const String& role, | const String& role, |
Array<const MetaClass*>& result) |
Array<const SchemaClass*>& result) |
{ | { |
// Lookup source class: | // Lookup source class: |
| |
const MetaClass* mc = FindClass(ns, *Str(className)); |
const SchemaClass* mc = FindClass(ns, *Str(className)); |
| |
if (!mc) | if (!mc) |
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); | Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
| |
// Lookup result class (if any). | // Lookup result class (if any). |
| |
const MetaClass* rmc = 0; |
const SchemaClass* rmc = 0; |
| |
if (!resultClass.isNull()) | if (!resultClass.isNull()) |
{ | { |
|
|
| |
for (size_t i = 0; ns->classes[i]; i++) | for (size_t i = 0; ns->classes[i]; i++) |
{ | { |
MetaClass* amc = ns->classes[i]; |
SchemaClass* amc = ns->classes[i]; |
| |
// Skip non-association classes: | // Skip non-association classes: |
| |
if (!(amc->flags & META_FLAG_ASSOCIATION)) |
if (!(amc->flags & SCHEMA_FLAG_ASSOCIATION)) |
continue; | continue; |
| |
// Filter by result class: | // Filter by result class: |
|
|
| |
// Process reference properties: | // Process reference properties: |
| |
MetaFeatureInfo features[META_MAX_FEATURES]; |
SchemaFeatureInfo features[SCHEMA_MAX_FEATURES]; |
size_t size = 0; | size_t size = 0; |
MergeFeatures(amc, false, META_FLAG_REFERENCE, features, size); |
MergeFeatures(amc, false, SCHEMA_FLAG_REFERENCE, features, size); |
| |
for (size_t j = 0; j < size; j++) | for (size_t j = 0; j < size; j++) |
{ | { |
const MetaFeature* mf = features[j].mf; |
const SchemaFeature* mf = features[j].mf; |
| |
// Skip non references: | // Skip non references: |
| |
if (!(mf->flags & META_FLAG_REFERENCE)) |
if (!(mf->flags & SCHEMA_FLAG_REFERENCE)) |
continue; | continue; |
| |
const MetaReference* mr = (const MetaReference*)mf; |
const SchemaReference* mr = (const SchemaReference*)mf; |
| |
// Filter by role parameter. | // Filter by role parameter. |
| |
|
|
// Add this one to the output: | // Add this one to the output: |
| |
if (!_contains(result, amc)) | if (!_contains(result, amc)) |
result.append((MetaClass*)amc); |
result.append((SchemaClass*)amc); |
} | } |
} | } |
} | } |
| |
static const MetaClass* _findMetaClass( |
static const SchemaClass* _findSchemaClass( |
const char* nameSpace, | const char* nameSpace, |
const char* className) | const char* className) |
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(nameSpace); |
const SchemaNameSpace* ns = _findNameSpace(nameSpace); |
| |
if (!ns) | if (!ns) |
return 0; | return 0; |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Lookup class: | // Lookup class: |
| |
const MetaClass* super = 0; |
const SchemaClass* super = 0; |
| |
if (!className.isNull()) | if (!className.isNull()) |
{ | { |
|
|
| |
for (size_t i = 0; ns->classes[i]; i++) | for (size_t i = 0; ns->classes[i]; i++) |
{ | { |
MetaClass* mc = ns->classes[i]; |
SchemaClass* mc = ns->classes[i]; |
| |
if (deepInheritance) | if (deepInheritance) |
{ | { |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Get associator meta-classes: |
// Get associator schema-classes: |
| |
Array<const MetaClass*> mcs; |
Array<const SchemaClass*> mcs; |
_associators(ns, className, assocClass, resultClass, role, resultRole, mcs); | _associators(ns, className, assocClass, resultClass, role, resultRole, mcs); |
| |
// Convert meta-classes to classes. |
// Convert schema-classes to classes. |
| |
Array<CIMObject> result; | Array<CIMObject> result; |
| |
|
|
| |
for (Uint32 i = 0; i < mcs.size(); i++) | for (Uint32 i = 0; i < mcs.size(); i++) |
{ | { |
const MetaClass* mc = mcs[i]; |
const SchemaClass* mc = mcs[i]; |
CIMClass cc; | CIMClass cc; |
| |
if (MakeClass(_getHostName(), ns, mc, false, includeQualifiers, | if (MakeClass(_getHostName(), ns, mc, false, includeQualifiers, |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Get associator meta-classes: |
// Get associator schema-classes: |
| |
Array<const MetaClass*> mcs; |
Array<const SchemaClass*> mcs; |
_associators(ns, className, assocClass, resultClass, role, resultRole, mcs); | _associators(ns, className, assocClass, resultClass, role, resultRole, mcs); |
| |
// Convert meta-classes to object names: |
// Convert schema-classes to object names: |
| |
Array<CIMObjectPath> result; | Array<CIMObjectPath> result; |
| |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Get reference meta-classes: |
// Get reference schema-classes: |
| |
Array<const MetaClass*> mcs; |
Array<const SchemaClass*> mcs; |
_references(ns, className, resultClass, role, mcs); | _references(ns, className, resultClass, role, mcs); |
| |
// Convert meta-classes to classes. |
// Convert schema-classes to classes. |
| |
Array<CIMObject> result; | Array<CIMObject> result; |
| |
|
|
| |
for (Uint32 i = 0; i < mcs.size(); i++) | for (Uint32 i = 0; i < mcs.size(); i++) |
{ | { |
const MetaClass* mc = mcs[i]; |
const SchemaClass* mc = mcs[i]; |
CIMClass cc; | CIMClass cc; |
| |
if (MakeClass(_getHostName(), ns, mc, false, includeQualifiers, | if (MakeClass(_getHostName(), ns, mc, false, includeQualifiers, |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Get reference meta-classes: |
// Get reference schema-classes: |
| |
Array<const MetaClass*> mcs; |
Array<const SchemaClass*> mcs; |
_references(ns, className, resultClass, role, mcs); | _references(ns, className, resultClass, role, mcs); |
| |
// Convert meta-classes to object paths. |
// Convert schema-classes to object paths. |
| |
Array<CIMObjectPath> result; | Array<CIMObjectPath> result; |
| |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Lookup qualifier: | // Lookup qualifier: |
| |
const MetaQualifierDecl* mqd = FindQualifierDecl(ns, *Str(qualifierName)); |
const SchemaQualifierDecl* mqd = FindQualifierDecl(ns, *Str(qualifierName)); |
| |
if (!mqd) | if (!mqd) |
Throw((CIM_ERR_NOT_FOUND, | Throw((CIM_ERR_NOT_FOUND, |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
|
|
| |
for (size_t i = 0; ns->qualifiers[i]; i++) | for (size_t i = 0; ns->qualifiers[i]; i++) |
{ | { |
const MetaQualifierDecl* mqd = ns->qualifiers[i]; |
const SchemaQualifierDecl* mqd = ns->qualifiers[i]; |
CIMQualifierDecl cqd; | CIMQualifierDecl cqd; |
| |
if (MakeQualifierDecl(ns, mqd, cqd) != 0) | if (MakeQualifierDecl(ns, mqd, cqd) != 0) |
|
|
| |
for (size_t i = 0; i < _nameSpaceTableSize; i++) | for (size_t i = 0; i < _nameSpaceTableSize; i++) |
{ | { |
const MetaNameSpace* ns = _nameSpaceTable[i]; |
const SchemaNameSpace* ns = _nameSpaceTable[i]; |
result.append(ns->name); | result.append(ns->name); |
} | } |
| |
|
|
| |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Lookup class: | // Lookup class: |
| |
const MetaClass* mc = FindClass(ns, *Str(className)); |
const SchemaClass* mc = FindClass(ns, *Str(className)); |
| |
if (!mc) | if (!mc) |
Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); | Throw((CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className))); |
| |
// Append superclass names: | // Append superclass names: |
| |
for (const MetaClass* p = mc->super; p; p = p->super) |
for (const SchemaClass* p = mc->super; p; p = p->super) |
superClassNames.append(p->name); | superClassNames.append(p->name); |
} | } |
| |
|
|
static void (*_loadCallback)(Buffer& buffer, void* data); | static void (*_loadCallback)(Buffer& buffer, void* data); |
static void* _loadData; | static void* _loadData; |
| |
MemoryResidentRepository::MemoryResidentRepository( |
MemoryResidentRepository::MemoryResidentRepository() |
const String& repositoryRoot, |
|
Uint32 repositoryMode) |
|
: |
|
Repository(repositoryRoot, repositoryMode) |
|
{ | { |
// Load users data if any: | // Load users data if any: |
_processLoadHandler(); | _processLoadHandler(); |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Lookup class: | // Lookup class: |
| |
const MetaClass* mc = FindClass(ns, *Str(className)); |
const SchemaClass* mc = FindClass(ns, *Str(className)); |
| |
if (!mc) | if (!mc) |
{ | { |
|
|
const CIMObjectPath& cop = modifiedInstance.getPath(); | const CIMObjectPath& cop = modifiedInstance.getPath(); |
CIMName className = cop.getClassName(); | CIMName className = cop.getClassName(); |
| |
// Get the meta class for this instance. |
// Get the schema-class for this instance. |
| |
const MetaClass* mc = _findMetaClass(*Str(nameSpace), *Str(className)); |
const SchemaClass* mc = _findSchemaClass(*Str(nameSpace), *Str(className)); |
| |
if (!mc) | if (!mc) |
{ | { |
|
|
{ | { |
// Lookup namespace: | // Lookup namespace: |
| |
const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
const SchemaNameSpace* ns = _findNameSpace(*Str(nameSpace)); |
| |
if (!ns) | if (!ns) |
Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); | Throw((CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace))); |
| |
// Lookup class: | // Lookup class: |
| |
const MetaClass* super = 0; |
const SchemaClass* super = 0; |
| |
if (!className.isNull()) | if (!className.isNull()) |
{ | { |
|
|
| |
for (size_t i = 0; ns->classes[i]; i++) | for (size_t i = 0; ns->classes[i]; i++) |
{ | { |
MetaClass* mc = ns->classes[i]; |
SchemaClass* mc = ns->classes[i]; |
| |
bool flag = false; | bool flag = false; |
| |
|
|
} | } |
} | } |
| |
Boolean MemoryResidentRepository::addNameSpace(const MetaNameSpace* nameSpace) |
Boolean MemoryResidentRepository::addNameSpace(const SchemaNameSpace* nameSpace) |
{ | { |
if (!nameSpace) | if (!nameSpace) |
return false; | return false; |