(file) Return to CIMQualifierList.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

File: [Pegasus] / pegasus / src / Pegasus / Common / CIMQualifierList.cpp (download)
Revision: 1.15, Tue Jul 10 21:31:10 2001 UTC (22 years, 11 months ago) by mike
Branch: MAIN
Changes since 1.14: +240 -240 lines
Removed \r\r\n from all files.

//%/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to 
// deal in the Software without restriction, including without limitation the 
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// THE 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 "CIMQualifierList.h"
#include "DeclContext.h"
#include "CIMQualifierDecl.h"
#include "CIMName.h"
#include "Indentor.h"
#include "XmlWriter.h"

PEGASUS_NAMESPACE_BEGIN

CIMQualifierList::CIMQualifierList()
{

}

CIMQualifierList::~CIMQualifierList()
{

}

CIMQualifierList& CIMQualifierList::add(const CIMQualifier& qualifier)
{
    if (!qualifier)
	throw UnitializedHandle();

    if (find(qualifier.getName()) != PEG_NOT_FOUND)
	throw AlreadyExists();

    _qualifiers.append(qualifier);

    return *this;
}
//ATTN: Why do we not do the outofbounds check here. KS 18 May 2k
CIMQualifier& CIMQualifierList::getQualifier(Uint32 pos)
{
    return _qualifiers[pos];
}

//ATTN: added ks 18 may 2001. Should we have outofbounds?
void CIMQualifierList::removeQualifier(Uint32 pos)
{
    _qualifiers.remove(pos);
}

Uint32 CIMQualifierList::find(const String& name) const
{
    for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
    {
	if (CIMName::equal(_qualifiers[i].getName(), name))
	    return i;
    }

    return PEG_NOT_FOUND;
}

Uint32 CIMQualifierList::findReverse(const String& name) const
{
    for (Uint32 i = _qualifiers.size(); i; --i)
    {
	if (CIMName::equal(_qualifiers[i - 1].getName(), name))
	    return i - 1;
    }

    return PEG_NOT_FOUND;
}

void CIMQualifierList::resolve(
    DeclContext* declContext,
    const String& nameSpace,
    Uint32 scope,
    Boolean isInstancePart,
    CIMQualifierList& inheritedQualifiers)
{
    // 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 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.
	//----------------------------------------------------------------------

	CIMConstQualifierDecl qd = declContext->lookupQualifierDecl(
	    nameSpace, q.getName());

	if (!qd)
	    throw UndeclaredQualifier(q.getName());

	//----------------------------------------------------------------------
	// 2. Check the type:
	//----------------------------------------------------------------------

	if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))
	    throw BadQualifierType(q.getName());

	//----------------------------------------------------------------------
	// 3. Check the scope:
	//----------------------------------------------------------------------
#if 0
        // ATTN:  These lines throw a bogus exception if the qualifier has
        // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS
        // grb 1/16/01
	if (!(qd.getScope() & scope))
	    throw BadQualifierScope(qd.getName(), ScopeToString(scope));
#endif
	//----------------------------------------------------------------------
	// See if this qualifier is contained in the inheritedQualifiers. If
	// so then we must handle the OVERRIDABLE flavor.
	//----------------------------------------------------------------------

	// ATTN: there seems to be a problem with the CIM schema that marks the
	// abstract qualifier as non-overridable but then they override it.
	// For now it is just disabled. This problem exists in both XML and
	// CIM schema.

#if 0
	Uint32 pos = inheritedQualifiers.find(q.getName());

	if (pos != PEG_NOT_FOUND)
	{
	    CIMConstQualifier iq = inheritedQualifiers.getQualifier(pos);

	    if (!(iq.getFlavor() & CIMFlavor::OVERRIDABLE))
		throw BadQualifierOverride(q.getName());
	}
#endif
    }

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

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

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

	// If the qualifiers list does not already contain this qualifier,
	// then propagate it (and set the propagated flag to true).

	if (find(iq.getName()) != PEG_NOT_FOUND)
	    continue;

	CIMQualifier q = iq.clone();
	q.setPropagated(true);
	_qualifiers.prepend(q);
    }
}

void CIMQualifierList::toXml(Array<Sint8>& out) const
{
    for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
	_qualifiers[i].toXml(out);
}

void CIMQualifierList::print(PEGASUS_STD(ostream) &os) const
{
    Array<Sint8> tmp;
    toXml(tmp);
    tmp.append('\0');
    os << tmp.getData() << PEGASUS_STD(endl);
}

Boolean CIMQualifierList::identical(const CIMQualifierList& x) const
{
    Uint32 count = getCount();

    if (count != x.getCount())
	return false;

    for (Uint32 i = 0; i < count; i++)
	return _qualifiers[i].identical(x._qualifiers[i]);

    return true;
}

void CIMQualifierList::cloneTo(CIMQualifierList& x) const
{
    x._qualifiers.clear();
    x._qualifiers.reserve(_qualifiers.size());

    for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
	x._qualifiers.append(_qualifiers[i].clone());
}

PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2