예제 #1
0
void _Check(const String& name, CIMConstProperty& p, T* tag)
{
    if (p.getName() == name)
    {
        if (IsArray(tag) != p.isArray() || GetType(tag) != p.getType())
            throw CIMException(CIM_ERR_TYPE_MISMATCH, name);
    }
}
PEGASUS_NAMESPACE_BEGIN

#ifdef FQL_DOTRACE
#define ENABLE_LOCAL_DIAGNOSTICS
#endif

Boolean FQLInstancePropertySource::isArrayProperty(
    const CIMName& propertyName) const
{
    unsigned int pos=ci.findProperty(propertyName);
    PEGASUS_ASSERT(pos != PEG_NOT_FOUND);
    CIMConstProperty p = ci.getProperty(pos);
    return p.isArray();
}
예제 #3
0
CIMProperty ObjectNormalizer::processProperty(
    CIMConstProperty& referenceProperty,
    CIMConstProperty& instProperty,
    Boolean includeQualifiers,
    Boolean includeClassOrigin,
    NormalizerContext* context,
    const CIMNamespaceName& nameSpace)
{
    // check name
    if (!referenceProperty.getName().equal(instProperty.getName()))
    {
        MessageLoaderParms message(
            "Common.ObjectNormalizer.INVALID_PROPERTY_NAME",
            "Invalid property name: $0",
            instProperty.getName().getString());

        throw CIMException(CIM_ERR_FAILED, message);
    }

    // check type
    CIMType referencePropType = referenceProperty.getType();
    CIMType instPropType = instProperty.getType();
    if (referencePropType != instPropType)
    {
        MessageLoaderParms message(
            "Common.ObjectNormalizer.INVALID_PROPERTY_TYPE",
            "Invalid property type: $0",
            instProperty.getName().getString());

        throw CIMException(CIM_ERR_FAILED, message);
    }

    // TODO: check array size?

    CIMProperty normalizedProperty(
        referenceProperty.getName(),
        referenceProperty.getValue(),   // default value
        referenceProperty.getArraySize(),
        referenceProperty.getReferenceClassName(),
        CIMName(),
        false);

    // TODO: check override (especially for references)?

    // update value
    if (!instProperty.getValue().isNull())
    {
        normalizedProperty.setValue(instProperty.getValue());
    }

    // update class origin
    if (includeClassOrigin)
    {
        normalizedProperty.setClassOrigin(referenceProperty.getClassOrigin());
    }

    // add qualifiers
    if (includeQualifiers)
    {
        // propagate class property qualifiers
        for (Uint32 i=0, n = referenceProperty.getQualifierCount(); i < n; i++)
        {
            CIMConstQualifier referenceQualifier =
                referenceProperty.getQualifier(i);

            Uint32 pos =
                instProperty.findQualifier(referenceQualifier.getName());

            // update value if qualifier is present in the specified property
            if (pos != PEG_NOT_FOUND)
            {
                CIMConstQualifier cimQualifier = instProperty.getQualifier(pos);

                CIMQualifier normalizedQualifier =
                    _processQualifier(
                        referenceQualifier,
                        cimQualifier);

                normalizedProperty.addQualifier(normalizedQualifier);
            }
            else
            {
                normalizedProperty.addQualifier(referenceQualifier.clone());
            }
        }
    }
#ifdef PEGASUS_SNIA_INTEROP_COMPATIBILITY
    else if (referenceProperty.getType() == CIMTYPE_INSTANCE)
    {
        Uin32 refPos = referenceProperty.findQualifier(
                           PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE);
        Uin32 cimPos = instProperty.findQualifier(
                           PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE);
        if (refPos != PEG_NOT_FOUND && cimPos == PEG_NOT_FOUND)
        {
            instProperty.addQualifier(refProperty.getQualifier(pos));
        }
    }
#endif

    // Check the type of the embedded instance against the class specified by
    // the EmbeddedInstance qualifier. We can only do this if the context
    // is non-zero.
    if (context != 0)
    {
        if (referenceProperty.getType() == CIMTYPE_INSTANCE)
        {
            Uint32 pos = referenceProperty.findQualifier(
                             PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE);

            PEGASUS_ASSERT(pos != PEG_NOT_FOUND);

            String qualClassStr;
            referenceProperty.getQualifier(pos).getValue().get(
                qualClassStr);
            CIMName embedInstClassName(qualClassStr);
            Array<CIMName> embeddedInstSubclasses =
                context->enumerateClassNames(nameSpace, embedInstClassName,
                    true);
            embeddedInstSubclasses.append(embedInstClassName);

            Array<CIMInstance> embeddedInstances;
            if (referenceProperty.isArray())
            {
                instProperty.getValue().get(embeddedInstances);
            }
            else
            {
                CIMInstance embeddedInst;
                instProperty.getValue().get(embeddedInst);
                embeddedInstances.append(embeddedInst);
            }

            Array<CIMClass> embeddedClassDefs;
            for (Uint32 i = 0, n = embeddedInstances.size(); i < n; ++i)
            {
                CIMInstance& currentInstance = embeddedInstances[i];
                CIMName currentClassName = currentInstance.getClassName();
                if (Contains(embeddedInstSubclasses, currentClassName))
                {
                    CIMClass embeddedClassDef;
                    bool found = false;
                    for (Uint32 j = 0, m = embeddedClassDefs.size(); j < m;
                        ++j)
                    {
                        CIMClass& tmpClassDef = embeddedClassDefs[j];
                        if (tmpClassDef.getClassName() == currentClassName)
                        {
                            embeddedClassDef = tmpClassDef;
                            found = true;
                        }
                    }

                    if (!found)
                    {
                        embeddedClassDef = context->getClass(nameSpace,
                            currentClassName);
                        embeddedClassDefs.append(embeddedClassDef);
                    }

                    SharedPtr<NormalizerContext> tmpContext(context->clone());
                    ObjectNormalizer tmpNormalizer(embeddedClassDef,
                        includeQualifiers, includeClassOrigin, nameSpace,
                        tmpContext);
                    if (currentInstance.getPath().getKeyBindings().size()==0)
                    {
                        currentInstance.setPath(
                            currentInstance.buildPath(embeddedClassDef));
                    }
                    embeddedInstances[i] =
                        tmpNormalizer.processInstance(currentInstance);
                }
                else
                {
                    MessageLoaderParms message(
                        "Common.ObjectNormalizer."
                            "INVALID_EMBEDDED_INSTANCE_TYPE",
                        "Found embedded instance of type $0: was expecting "
                            "$1 for property $2",
                        currentClassName.getString(),
                        qualClassStr,
                        instProperty.getName().getString());

                    throw CIMException(CIM_ERR_FAILED, message);
                }
            }

            if (referenceProperty.isArray())
            {
              normalizedProperty.setValue(CIMValue(embeddedInstances));
            }
            else
            {
              normalizedProperty.setValue(CIMValue(embeddedInstances[0]));
            }
        }
    }
    return normalizedProperty;
}