Пример #1
0
void CIMPropertyRep::resolve(
    DeclContext* declContext,
    const CIMNamespaceName& nameSpace,
    Boolean isInstancePart,
    Boolean propagateQualifiers)
{
    CIMQualifierList dummy;

    CIMScope scope = CIMScope::PROPERTY;

    if (_value.getType() == CIMTYPE_REFERENCE)
    {
        scope = CIMScope::REFERENCE;

        // Validate that the reference class exists.

        CIMName referenceClassName;
        if (_referenceClassName.isNull())
        {
            CIMObjectPath reference;
            _value.get(reference);
            referenceClassName = reference.getClassName();
        }
        else
        {
            referenceClassName = _referenceClassName;
        }

        CIMClass referenceClass = declContext->lookupClass(
            nameSpace, referenceClassName);
        if (referenceClass.isUninitialized())
        {
            throw PEGASUS_CIM_EXCEPTION(
                CIM_ERR_INVALID_PARAMETER, referenceClassName.getString());
        }
    }

    _qualifiers.resolve(
        declContext,
        nameSpace,
        scope,
        isInstancePart,
        dummy,
        propagateQualifiers);
}
Пример #2
0
SCMOClass CIMServer::_scmoClassCache_GetClass(
    const CIMNamespaceName& nameSpace,
    const CIMName& className)
{
    CIMClass cc;

    PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::_scmoClassCache_GetClass()");
    try
    {
        cc = _cimserver->_repository->getClass(
            nameSpace,
            className,
            false, // localOnly
            true, // includeQualifiers
            true, // includeClassOrigin
            CIMPropertyList());
    }
    catch (Exception& e)
    {
        PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,
                   "The class '%s' in the name space '%s' was not found. "
                       "The repository throws the following exception: %s",
                   (const char*)className.getString().getCString(),
                   (const char*)nameSpace.getString().getCString(),
                   (const char*)e.getMessage().getCString()));
        // Return a empty class.
        PEG_METHOD_EXIT();
        return SCMOClass("","");
    }

    if (cc.isUninitialized())
    {
        // The requested class was not found !
        // Return a empty class.
        PEG_METHOD_EXIT();
        return SCMOClass("","");
    }
    PEG_METHOD_EXIT();
    return SCMOClass(cc,(const char*)nameSpace.getString().getCString());

}
Пример #3
0
void CIMQualifierList::resolve(
    DeclContext* declContext,
    const CIMNamespaceName & nameSpace,
    CIMScope scope, // Scope of the entity being resolved.
    Boolean isInstancePart,
    CIMQualifierList& inheritedQualifiers,
    Boolean propagateQualifiers)
{
    _keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN;

    PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMQualifierList::resolve()");
    // For each qualifier in the qualifiers array, the following
    // is checked:
    //
    //     1. Whether it is declared (can be obtained from the declContext).
    //
    //     2. Whether it has the same type as the declaration.
    //
    //     3. Whether the qualifier is valid for the given scope.
    //
    //     4. Whether the qualifier can be overriden (the flavor is
    //        ENABLEOVERRIDE on the corresponding reference qualifier).
    //
    //     5. Whether the qualifier should be propagated to the subclass.
    //
    // If the qualifier should be overriden, then it is injected into the
    // qualifiers array (from the inheritedQualifiers array).

    for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
    {
        CIMQualifier q = _qualifiers[i];
        //----------------------------------------------------------------------
        // 1. Check to see if it's declared.
        //----------------------------------------------------------------------
        // set this back to  CIMConstQualifierDecl
        CIMQualifierDecl qd = declContext->lookupQualifierDecl(
            nameSpace, q.getName());

        if (qd.isUninitialized())
        {
            PEG_METHOD_EXIT();
            throw UndeclaredQualifier(q.getName().getString ());
        }

        //----------------------------------------------------------------------
        // 2. Check the type and isArray.  Must be the same:
        //----------------------------------------------------------------------

        if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))
        {
            PEG_METHOD_EXIT();
            throw BadQualifierType(q.getName().getString ());
        }

        //----------------------------------------------------------------------
        // 3. If the qualifier is the EmbeddedInstance qualifier, then check
        // that the class specified by the qualifier exists in the namespace.
        //----------------------------------------------------------------------
        if (q.getName().equal(PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE))
        {
            String className;
            q.getValue().get(className);
            CIMClass classDef = declContext->lookupClass(nameSpace,
                    CIMName(className));
            if (classDef.isUninitialized())
            {
                String embeddedInstType("EmbeddedInstance(\"");
                embeddedInstType = embeddedInstType + className + "\")";
                PEG_METHOD_EXIT();
                throw BadQualifierType(embeddedInstType);
            }
        }

        //----------------------------------------------------------------------
        // 4. Check the scope: Must be legal for this qualifier
        //----------------------------------------------------------------------
        // ATTN:  These lines throw a bogus exception if the qualifier has
        // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS
        // ks Mar 2002. Reinstalled 23 March 2002 to test.

        if (!(qd.getScope().hasScope (scope)))
        {
            PEG_METHOD_EXIT();
            throw BadQualifierScope
                (qd.getName().getString (), scope.toString ());
        }

        //----------------------------------------------------------------------
        // Resolve the qualifierflavor. Since Flavors are a combination of
        // inheritance and input characteristics, resolve the inherited
        // characteristics against those provided with the creation.  If
        // there is a superclass the flavor is resolved against that
        // superclass.  If not, it is resolved against the declaration. If
        // the flavor is disableoverride and tosubclass the resolved
        // qualifier value must be identical to the original
        //----------------------------------------------------------------------
        // Test for Qualifier found in SuperClass. If found and qualifier
        // is not overridable.
        // Abstract (not Overridable and restricted) can be found in subclasses
        // Can have nonabstracts below abstracts. That is function of
        // nottosubclass Association (notOverridable and tosubclass) can be
        // found in subclasses but cannot be changed. No non-associatons below
        // associations. In other words once a class becomes an association,
        // no subclass can override that definition apparently
        // Throw exception if DisableOverride and tosubclass and different
        // value.  Gets the source from superclass if qualifier exists or from
        // declaraction.
        // If we do not throw the exception, resolve the flavor from the
        // inheritance point and resolve against current input.
        // Diableoverride is defined in the CIM Spec to mean that the value
        // cannot change.
        // The other characteristics including the flavor can change
        // apparently. Thus, we need only confirm that the value is the same
        // (2.2 pp 33).  Strange since we would think that override implies
        // that you cannot override any of the characteristics (value, type,
        // flavor, etc.) This also leaves the question of NULL or no values.
        // The implication is that we must move the value from the superclass
        // or declaration.

        Uint32 index = inheritedQualifiers.find(q.getName());

        if (index == PEG_NOT_FOUND)
        {   // Qualifier does not exist in superclass
            /* If from declaration, we can override the default value.
              However, we need some way to get the value if we have a Null.
            if (!qd.getFlavor().hasFlavor(CIMFlavor::OVERRIDABLE) &&
                qd.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS))
            {
                //throw BadQualifierOverride(q.getName());
            }
            */
            // Do not allow change from disable override to enable override.
            if ((!qd.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                  && (q.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)))
            {
                PEG_METHOD_EXIT();
                throw BadQualifierOverride(q.getName().getString ());
            }

            Resolver::resolveQualifierFlavor(
                q, CIMFlavor (qd.getFlavor ()), false);
        }
        else  // qualifier exists in superclass
        {   ////// Make Const again
            CIMQualifier iq = inheritedQualifiers.getQualifier(index);
            // don't allow change override to notoverride.
            if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                  && q.getFlavor ().hasFlavor (CIMFlavor::OVERRIDABLE))
            {
                PEG_METHOD_EXIT();
                throw BadQualifierOverride(q.getName().getString ());
            }

            if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                  && iq.getFlavor ().hasFlavor(CIMFlavor::TOSUBCLASS))
            {
                // test if values the same.
                CIMValue qv = q.getValue();
                CIMValue iqv = iq.getValue();
                if (!(qv == iqv))
                {
                    PEG_METHOD_EXIT();
                    throw BadQualifierOverride(q.getName().getString());
                }
            }

            Resolver::resolveQualifierFlavor(
                q, CIMFlavor(iq.getFlavor()), true);
        }
    }   // end of this objects qualifier loop

    //--------------------------------------------------------------------------
    // Propagate qualifiers to subclass or to instance that do not have
    // already have those qualifiers:
    //--------------------------------------------------------------------------

    if (propagateQualifiers)
    {
        for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++)
        {
            CIMQualifier iq = inheritedQualifiers.getQualifier(i);

            if (isInstancePart)
            {
                if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOINSTANCE)))
                    continue;
            }
            else
            {
                if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS)))
                    continue;
            }

            // If the qualifiers list does not already contain this qualifier,
            // then propagate it (and set the propagated flag to true).  Else
            // we keep current value. Note we have already eliminated any
            // possibility that a nonoverridable qualifier can be in the list.
            if (find(iq.getName()) != PEG_NOT_FOUND)
                continue;

            CIMQualifier q = iq.clone();
            q.setPropagated(true);
            _qualifiers.insert(0, q);
        }
    }
    PEG_METHOD_EXIT();
}
Пример #4
0
void CIMPropertyRep::resolve(
    DeclContext* declContext,
    const CIMNamespaceName& nameSpace,
    Boolean isInstancePart,
    const CIMConstProperty& inheritedProperty,
    Boolean propagateQualifiers)
{
    PEGASUS_ASSERT(!inheritedProperty.isUninitialized());

    // Check the type:

    if (!inheritedProperty.getValue().typeCompatible(_value))
    {
        if (!(
            (inheritedProperty.getValue().getType() == CIMTYPE_OBJECT) &&
            (_value.getType() == CIMTYPE_STRING) &&
            (_qualifiers.find(PEGASUS_QUALIFIERNAME_EMBEDDEDOBJECT)
                 != PEG_NOT_FOUND) &&
            (inheritedProperty.getValue().isArray() == _value.isArray())
            ) &&
            !(
            (inheritedProperty.getValue().getType() == CIMTYPE_INSTANCE) &&
            (_value.getType() == CIMTYPE_STRING) &&
            (_qualifiers.find(PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE)
                 != PEG_NOT_FOUND) &&
            (inheritedProperty.getValue().isArray() == _value.isArray())
            ))
        {
            throw TypeMismatchException();
        }
    }

    // Validate the qualifiers of the property (according to
    // superClass's property with the same name). This method
    // will throw an exception if the validation fails.

    CIMScope scope = CIMScope::PROPERTY;

    if (_value.getType() == CIMTYPE_REFERENCE)
        scope = CIMScope::REFERENCE;

    // Test the reference class name against the inherited property
    if (_value.getType() == CIMTYPE_REFERENCE ||
        _value.getType() == CIMTYPE_INSTANCE)
    {
        CIMName inheritedClassName;
        Array<CIMName> classNames;

        if (_value.getType() == CIMTYPE_INSTANCE)
        {
            Uint32 pos = inheritedProperty.findQualifier(
                             PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE);
            if (pos != PEG_NOT_FOUND)
            {
                String qualStr;
                inheritedProperty.getQualifier(pos).getValue().get(qualStr);
                inheritedClassName = qualStr;
            }

            if (_value.isArray())
            {
                Array<CIMInstance> embeddedInstances;
                _value.get(embeddedInstances);
                for (Uint32 i = 0, n = embeddedInstances.size(); i < n; ++i)
                {
                    classNames.append(embeddedInstances[i].getClassName());
                }
            }
            else
            {
                CIMInstance embeddedInst;
                _value.get(embeddedInst);
                classNames.append(embeddedInst.getClassName());
            }
        }
        else
        {
            CIMName referenceClass;
            if (_referenceClassName.isNull())
            {
                CIMObjectPath reference;
                _value.get(reference);
                referenceClass = reference.getClassName();
            }
            else
            {
                referenceClass = _referenceClassName;
            }

            inheritedClassName = inheritedProperty.getReferenceClassName();
            classNames.append(referenceClass);
        }

        // This algorithm is friendly to arrays of embedded instances. It
        // remembers the class names that are found to be subclasses of the
        // inherited class name retrieved from the inherited property. This
        // ensures that any branch in the inheritance hierarchy will only be
        // traversed once. This provides significant optimization given that
        // most elements of an array of embedded instances will probably be of
        // very closely related types.
        Array<CIMName> successTree;
        successTree.append(inheritedClassName);
        for (Uint32 i = 0, n = classNames.size(); i < n; ++i)
        {
            Array<CIMName> traversalHistory;
            CIMName currentName = classNames[i];
            Boolean found = false;
            while (!found && !currentName.isNull())
            {
                for (Uint32 j = 0, m = successTree.size(); j < m; ++j)
                {
                    if (currentName == successTree[j])
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    traversalHistory.append(currentName);
                    CIMClass currentClass = declContext->lookupClass(
                            nameSpace, currentName);
                    if (currentClass.isUninitialized())
                    {
                        throw PEGASUS_CIM_EXCEPTION(
                            CIM_ERR_INVALID_PARAMETER, currentName.getString());
                    }
                    currentName = currentClass.getSuperClassName();
                }
            }

            if (!found)
            {
                throw TypeMismatchException();
            }

            successTree.appendArray(traversalHistory);
        }
    }

    _qualifiers.resolve(
        declContext, nameSpace, scope, isInstancePart,
        inheritedProperty._rep->_qualifiers, propagateQualifiers);

    _classOrigin = inheritedProperty.getClassOrigin();
}
//
// Initialize the namespaces so that all namespaces with the
// CIM_ElementConformsToProfile class also have the
// PG_ElementConformsToProfile class. Needed in order to implement
// the cross-namespace ElementConformsToProfile association in both
// directions.
//
void InteropProvider::initializeNamespaces()
{
    Array<CIMNamespaceName> namespaceNames =  repository->enumerateNameSpaces();
    // get the PG_ElementConformstoProfile class without the qualifiers
    // and then add just the required ASSOCIATION qualifier, so that
    // resolveclass doesn't fail for the test/EmbeddedInstance/Dynamic
    // namespace, which uses the CIM25 schema that doesn't include any
    // of the new qualifiers added to this class in later versions of
    // the CIMSchema.
    CIMClass conformsClass = repository->getClass(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE,
        true,
        false);
    conformsClass.addQualifier(
        CIMQualifier(CIMName("ASSOCIATION"), CIMValue(true)));
    CIMClass profileClass = repository->getClass(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE,
        true,
        false);
    for(Uint32 i = 0, n = namespaceNames.size(); i < n; ++i)
    {
        // Check if the PG_ElementConformsToProfile class is present
        CIMNamespaceName & currentNamespace = namespaceNames[i];
        CIMClass tmpCimClass;
        CIMClass tmpPgClass;
        CIMClass tmpPgProfileClass;
        try
        {
            // Look for these classes in the same try-block since the
            // second depends on the first
            tmpCimClass = repository->getClass(
                currentNamespace,
                PEGASUS_CLASSNAME_CIM_ELEMENTCONFORMSTOPROFILE);
            tmpPgClass = repository->getClass(
                currentNamespace,
                PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE);
        }
        catch(const Exception &)
        {
        }
        try
        {
            tmpPgProfileClass = repository->getClass(
                currentNamespace,
                PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE);
        }
        catch(const Exception &)
        {
            // Note: if any of the above three classes aren't found,
            // an exception will be thrown, which we can ignore since it's
            // an expected case
            // TBD: Log trace message?
        }

        // If the CIM_ElementConformsToProfile class is present, but
        // the PG_ElementConformsToProfile or PG_RegisteredProfile
        // class is not, then add it to that namespace.
        //
        // Note that we don't have to check for the
        // CIM_RegisteredProfile class because if the
        // CIM_ElementConformsToProfile class is present, the
        // CIM_RegisteredProfile class must also be present.
        if(!tmpCimClass.isUninitialized())
        {
            if(tmpPgClass.isUninitialized())
            {
                CIMClass newclass = conformsClass.clone();
                CIMObjectPath newPath = conformsClass.getPath();
                newPath.setNameSpace(currentNamespace);
                newclass.setPath(newPath);
                repository->createClass(
                    currentNamespace,
                    newclass);
            }
            if(tmpPgProfileClass.isUninitialized())
            {
                CIMClass newclass = profileClass.clone();
                CIMObjectPath newPath = profileClass.getPath();
                newPath.setNameSpace(currentNamespace);
                newclass.setPath(newPath);
                repository->createClass(
                    currentNamespace,
                    newclass);
            }
        }
    }
}
Пример #6
0
void CIMPropertyRep::resolve(
    DeclContext* declContext,
    const CIMNamespaceName& nameSpace,
    Boolean isInstancePart,
    const CIMConstProperty& inheritedProperty,
    Boolean propagateQualifiers)
{
    PEGASUS_ASSERT(!inheritedProperty.isUninitialized());

    // Check the type:

    if (!inheritedProperty.getValue().typeCompatible(_value))
    {
        if (!(
            (inheritedProperty.getValue().getType() == CIMTYPE_OBJECT) &&
            (_value.getType() == CIMTYPE_STRING) &&
            (_qualifiers.find(CIMName("EmbeddedObject")) != PEG_NOT_FOUND) &&
            (inheritedProperty.getValue().isArray() == _value.isArray())
            ))
        {
            throw TypeMismatchException();
        }
    }

    // Validate the qualifiers of the property (according to
    // superClass's property with the same name). This method
    // will throw an exception if the validation fails.

    CIMScope scope = CIMScope::PROPERTY;

    if (_value.getType() == CIMTYPE_REFERENCE)
	scope = CIMScope::REFERENCE;

    // Test the reference class name against the inherited property
    if (_value.getType() == CIMTYPE_REFERENCE)
    {
        CIMName inheritedReferenceClassName = inheritedProperty.getReferenceClassName();
        CIMName referenceClassName;
        if(!_referenceClassName.isNull() && !_value.isNull())
        {
            CIMObjectPath valuePath;
            _value.get(valuePath);
            referenceClassName = valuePath.getClassName();
            bool found = _referenceClassName.equal(referenceClassName);
            while(!found)
            {
                CIMClass referenceClass = declContext->lookupClass(nameSpace, referenceClassName);
                if(referenceClass.isUninitialized())
                {
                    throw PEGASUS_CIM_EXCEPTION(
                      CIM_ERR_NOT_FOUND, referenceClassName.getString());
                }
                referenceClassName = referenceClass.getSuperClassName();
                if(referenceClassName.isNull())
                    throw TypeMismatchException();

                found = inheritedReferenceClassName.equal(referenceClassName);
            }
        }
        else if(!_referenceClassName.isNull())
        {
            referenceClassName = _referenceClassName;
        }
        else if(!_value.isNull())
        {
            CIMObjectPath valuePath;
            _value.get(valuePath);
            referenceClassName = valuePath.getClassName();
        }

        if(!referenceClassName.isNull())
        {
            bool found = inheritedReferenceClassName.equal(referenceClassName);
            while(!found)
            {
                CIMClass referenceClass = declContext->lookupClass(nameSpace, referenceClassName);
                if(referenceClass.isUninitialized())
                {
                    throw PEGASUS_CIM_EXCEPTION(
                        CIM_ERR_NOT_FOUND, referenceClassName.getString());
                }
                referenceClassName = referenceClass.getSuperClassName();
                if(referenceClassName.isNull())
                    throw TypeMismatchException();

                found = inheritedReferenceClassName.equal(referenceClassName);
            }
        }
    }

    _qualifiers.resolve(
	declContext,
	nameSpace,
	scope,
	isInstancePart,
	inheritedProperty._rep->_qualifiers,
	propagateQualifiers);

    _classOrigin = inheritedProperty.getClassOrigin();
}