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

File: [Pegasus] / pegasus / src / Pegasus / Common / Attic / InstanceDeclRep.cpp (download)
Revision: 1.6, Fri Feb 16 02:06:06 2001 UTC (23 years, 4 months ago) by mike
Branch: MAIN
CVS Tags: TASK-PEP362_RestfulService-merged_out_from_trunk, TASK-PEP348_SCMO-merged_out_from_trunk, TASK-PEP317_pullop-merged_out_from_trunk, TASK-PEP317_pullop-merged_in_to_trunk, TASK-PEP311_WSMan-root, TASK-PEP311_WSMan-branch, RELEASE_2_5_0-RC1, HPUX_TEST, HEAD
Changes since 1.5: +3 -0 lines
FILE REMOVED
Renamed many classes and headers.

//BEGIN_LICENSE
//
// Copyright (c) 2000 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 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.
//
//END_LICENSE
//BEGIN_HISTORY
//
// Author:
//
// $Log: InstanceDeclRep.cpp,v $
// Revision 1.6  2001/02/16 02:06:06  mike
// Renamed many classes and headers.
//
// Revision 1.5  2001/01/25 02:12:05  mike
// Added meta-qualifiers to LoadRepository program.
//
// Revision 1.4  2001/01/23 01:25:35  mike
// Reworked resolve scheme.
//
// Revision 1.3  2001/01/22 00:45:47  mike
// more work on resolve scheme
//
// Revision 1.2  2001/01/15 04:31:44  mike
// worked on resolve scheme
//
// Revision 1.1.1.1  2001/01/14 19:52:39  mike
// Pegasus import
//
//
//END_HISTORY

#include "InstanceDecl.h"
#include "DeclContext.h"
#include "Indentor.h"
#include "Name.h"
#include "XmlWriter.h"

PEGASUS_NAMESPACE_BEGIN

InstanceDeclRep::InstanceDeclRep(const String& className)
    : _className(className), _resolved(false)
{
    if (!Name::legal(className))
	throw IllegalName();
}

InstanceDeclRep::~InstanceDeclRep()
{

}

void InstanceDeclRep::addProperty(const Property& x)
{
    if (!x)
	throw UnitializedHandle();

    // Reject duplicate property names:

    if (findProperty(x.getName()) != Uint32(-1))
	throw AlreadyExists();

    // Note: class origin is resolved later:

    // Append property:

    _properties.append(x);
}

Uint32 InstanceDeclRep::findProperty(const String& name)
{
    for (Uint32 i = 0, n = _properties.getSize(); i < n; i++)
    {
	if (Name::equal(_properties[i].getName(), name))
	    return i;
    }

    return Uint32(-1);
}

Property InstanceDeclRep::getProperty(Uint32 pos)
{
    if (pos >= _properties.getSize())
	throw OutOfBounds();

    return _properties[pos];
}

Uint32 InstanceDeclRep::getPropertyCount() const
{
    return _properties.getSize();
}

void InstanceDeclRep::resolve(
    DeclContext* context, 
    const String& nameSpace)
{
#if 0
    if (_resolved)
	throw InstanceAlreadyResolved();
#endif

    if (!context)
	throw NullPointer();

    //----------------------------------------------------------------------
    // First obtain the class:
    //----------------------------------------------------------------------

    ConstClassDecl classDecl = 
	context->lookupClassDecl(nameSpace, _className);

    if (!classDecl)
	throw NoSuchClass(_className);

#if 0
    if (!classDecl._rep->_resolved)
	throw ClassNotResolved(_className);
#endif

    //----------------------------------------------------------------------
    // Disallow instantiation of abstract classes.
    //----------------------------------------------------------------------

    if (classDecl.isAbstract())
	throw InstantiatedAbstractClass();

    //----------------------------------------------------------------------
    // Validate the qualifiers of this class:
    //----------------------------------------------------------------------

    _qualifiers.resolve(
	context,
	nameSpace,
	Scope::CLASS,
	false,
	classDecl._rep->_qualifiers);

    //----------------------------------------------------------------------
    // First iterate the properties of this instance and verify that
    // each one is defined in the class and then resolve each one.
    // Also set the class origin.
    //----------------------------------------------------------------------

    String classOrigin = classDecl.getClassName();

    for (Uint32 i = 0, n = _properties.getSize(); i < n; i++)
    {
	Property& property = _properties[i];

	Uint32 pos = classDecl.findProperty(property.getName());

	if (pos == Uint32(-1))
	    throw NoSuchProperty(property.getName());

	property.resolve(context, nameSpace, true, classDecl.getProperty(pos));
        property.setClassOrigin(classOrigin);
    }

    //----------------------------------------------------------------------
    // Inject all properties from the class that are not included in the
    // instance. Copy over the class-origin and set the propagated flag
    // to true.
    //----------------------------------------------------------------------

    for (Uint32 i = 0, m = 0, n = classDecl.getPropertyCount(); i < n; i++)
    {
	ConstProperty property = classDecl.getProperty(i);
	const String& name = property.getName();

	// See if this instance already contains a property with this name:

	Boolean found = false;

	for (Uint32 j = m, n = _properties.getSize(); j < n; j++)
	{
	    if (_properties[j].getName() == name)
	    {
		found = true;
		break;
	    }
	}

	if (!found)
	{
	    Property p = property.clone();
	    p.setPropagated(true);
	    _properties.insert(m++, p);
	}
    }

#if 0
    _resolved = true;
#endif
}

InstanceDeclRep::InstanceDeclRep()
{

}

InstanceDeclRep::InstanceDeclRep(const InstanceDeclRep& x) : 
    Sharable(),
    _className(x._className),
    _resolved(x._resolved)
{
    x._qualifiers.cloneTo(_qualifiers);

    _properties.reserve(x._properties.getSize());

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

InstanceDeclRep& InstanceDeclRep::operator=(const InstanceDeclRep& x) 
{ 
    return *this; 
}

Boolean InstanceDeclRep::identical(const InstanceDeclRep* x) const
{
    if (_className != x->_className)
	return false;

    if (!_qualifiers.identical(x->_qualifiers))
	return false;

    // Compare properties:

    {
	const Array<Property>& tmp1 = _properties;
	const Array<Property>& tmp2 = x->_properties;

	if (tmp1.getSize() != tmp2.getSize())
	    return false;

	for (Uint32 i = 0, n = tmp1.getSize(); i < n; i++)
	{
	    if (!tmp1[i].identical(tmp2[i]))
		return false;
	}
    }

    if (_resolved != x->_resolved)
	return false;

    return true;
}

void InstanceDeclRep::toXml(Array<Sint8>& out) const
{
    // Class opening element:

    out << "<INSTANCE ";
    out << " CLASSNAME=\"" << _className << "\" ";
    out << ">\n";

    // Qualifiers:

    _qualifiers.toXml(out);

    // Parameters:

    for (Uint32 i = 0, n = _properties.getSize(); i < n; i++)
	_properties[i].toXml(out);

    // Class closing element:

    out << "</INSTANCE>\n";
}

void InstanceDeclRep::print() const
{
    Array<Sint8> tmp;
    toXml(tmp);
    tmp.append('\0');
    std::cout << tmp.getData() << std::endl;
}

PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2