Ejemplo n.º 1
0
void CIMPropertyRep::setValue(const CIMValue& value)
{
    // CIMType of value is immutable:

    if (!value.typeCompatible(_value))
	throw TypeMismatchException();

    if (_arraySize && _arraySize != value.getArraySize())
	throw TypeMismatchException();

    _value = value;
}
Ejemplo n.º 2
0
CIMPropertyRep::CIMPropertyRep(
    const CIMName& name,
    const CIMValue& value,
    Uint32 arraySize,
    const CIMName& referenceClassName,
    const CIMName& classOrigin,
    Boolean propagated)
    :
    _name(name), _value(value), _arraySize(arraySize),
    _referenceClassName(referenceClassName), _classOrigin(classOrigin),
    _propagated(propagated), _refCounter(1), _ownerCount(0)
{
    // ensure name is not null
    if (name.isNull())
    {
        throw UninitializedObjectException();
    }

    // Set the CIM name tag.
    _nameTag = generateCIMNameTag(_name);

    if ((arraySize != 0) &&
        (!value.isArray() || value.getArraySize() != arraySize))
    {
        throw TypeMismatchException();
    }

    // A CIM Property may not be of reference array type
    if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE))
    {
        throw TypeMismatchException();
    }

    // if referenceClassName exists, must be CIMType REFERENCE.
    if (!referenceClassName.isNull())
    {
        if (_value.getType() != CIMTYPE_REFERENCE)
        {
            throw TypeMismatchException();
        }
    }

    // Can a property be of reference type with a null referenceClassName?
    // The DMTF says yes if it is a property of an instance; no if it is a
    // property of a class.  We'll allow it here, but check in the CIMClass
    // addProperty() method.
}
Ejemplo n.º 3
0
void CIMPropertyRep::setValue(const CIMValue& value)
{
    // CIMType of value is immutable:

    if (!value.typeCompatible(_value))
        throw TypeMismatchException();

    if (_arraySize && _arraySize != value.getArraySize())
        throw TypeMismatchException();

    // A CIM Property may not be of reference array type
    if (value.isArray() && (value.getType() == CIMTYPE_REFERENCE))
    {
        throw TypeMismatchException();
    }

    _value = value;
}
Ejemplo n.º 4
0
String IndicationFormatter::_getArrayValues(
    const CIMValue & propertyValue,
    const String & arrayIndexStr,
    const ContentLanguages & contentLangs)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
	"IndicationFormatter::_getArrayValues");

    CIMType type = propertyValue.getType();
    String arrayValues;
    char propertyValueBuffer[2048];
    Uint32 arraySize = propertyValue.getArraySize();

    char arrayIndexBuffer[16];
    Sint32 arrayIndex = 0;
    Uint32 sizeOfArrayIndexStr = arrayIndexStr.size();

    // there is an index value enclosed in brackets (e.g. [2])
    if (sizeOfArrayIndexStr != 0)
    {
        sprintf(arrayIndexBuffer, "%s", (const char *)
	    arrayIndexStr.getCString());

	try
	{
	    _isValidIndex(arrayIndexBuffer);
            arrayIndex = atoi(arrayIndexBuffer);
	}
	catch (CIMException & c)
	{
	    arrayIndex = -1;

	    PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,c.getMessage());
	}
    }

    // Array index is out of range
    if (sizeOfArrayIndexStr != 0 &&
	((arrayIndex < 0) || ((Uint32)arrayIndex >= arraySize)))
    {
	arrayValues = "UNKNOWN";

        PEG_METHOD_EXIT();
        return (arrayValues);
    }

    switch (type)
    {
	case CIMTYPE_UINT8:
	{
	    Array<Uint8> propertyValueUint8;
	    propertyValue.get(propertyValueUint8);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%u",
			propertyValueUint8[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%u",
		    propertyValueUint8[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_UINT16:
	{
	    Array<Uint16> propertyValueUint16;
	    propertyValue.get(propertyValueUint16);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%u",
			propertyValueUint16[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%u",
		    propertyValueUint16[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_UINT32:
	{
	    Array<Uint32> propertyValueUint32;
	    propertyValue.get(propertyValueUint32);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%u",
			propertyValueUint32[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%u",
		    propertyValueUint32[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_UINT64:
	{
	    Array<Uint64> propertyValueUint64;
	    propertyValue.get(propertyValueUint64);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer,
			    "%" PEGASUS_64BIT_CONVERSION_WIDTH "u",
			    propertyValueUint64[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer,
			"%" PEGASUS_64BIT_CONVERSION_WIDTH "u",
		        propertyValueUint64[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT8:
	{
	    Array<Sint8> propertyValueSint8;
	    propertyValue.get(propertyValueSint8);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%i",
			propertyValueSint8[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%i",
		    propertyValueSint8[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT16:
	{
	    Array<Sint16> propertyValueSint16;
	    propertyValue.get(propertyValueSint16);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%i",
			propertyValueSint16[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%i",
		    propertyValueSint16[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT32:
	{
	    Array<Sint32> propertyValueSint32;
	    propertyValue.get(propertyValueSint32);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%i",
			propertyValueSint32[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%i",
		    propertyValueSint32[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_SINT64:
	{
	    Array<Sint64> propertyValueSint64;
	    propertyValue.get(propertyValueSint64);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer,
                            "%" PEGASUS_64BIT_CONVERSION_WIDTH "d",
                            propertyValueSint64[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer,
			"%" PEGASUS_64BIT_CONVERSION_WIDTH "d",
                        propertyValueSint64[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_REAL32:
	{
	    Array<Real32> propertyValueReal32;
	    propertyValue.get(propertyValueReal32);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%f",
			propertyValueReal32[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%f",
		    propertyValueReal32[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_REAL64:
	{
	    Array<Real64> propertyValueReal64;
	    propertyValue.get(propertyValueReal64);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    sprintf(propertyValueBuffer, "%f",
			propertyValueReal64[i]);
		    arrayValues.append(propertyValueBuffer);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        sprintf(propertyValueBuffer, "%f",
		    propertyValueReal64[arrayIndex]);
	        arrayValues = propertyValueBuffer;
	    }

            break;
	}

	case CIMTYPE_BOOLEAN:
	{
	    Array<Boolean> booleanValue;
	    propertyValue.get(booleanValue);

	    Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
	    Locale locale;
	    canLocalize = _canLocalize(contentLangs, locale);
#endif

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		    if (canLocalize)
		    {
			arrayValues.append(_localizeBooleanStr(
			    booleanValue[i], locale));
		    }
		    else
		    {
			arrayValues.append(_getBooleanStr(booleanValue[i]));
		    }
#else
		    arrayValues.append(_getBooleanStr(booleanValue[i]));

#endif
		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
                if (canLocalize)
		{
		    arrayValues = _localizeBooleanStr(
			booleanValue[arrayIndex], locale);
		}
		else
		{
		    arrayValues = _getBooleanStr(booleanValue[arrayIndex]);
		}
#else
		arrayValues = _getBooleanStr(booleanValue[arrayIndex]);
#endif
	    }

            break;
	}

	case CIMTYPE_CHAR16:
	{
	    Array<Char16> propertyValueChar16;
	    propertyValue.get(propertyValueChar16);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    arrayValues.append(propertyValueChar16[i]);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        arrayValues.append(propertyValueChar16[arrayIndex]);
	    }

            break;
	}

	case CIMTYPE_STRING:
	{
	    Array<String> propertyValueString;
	    propertyValue.get(propertyValueString);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    arrayValues.append(propertyValueString[i]);

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        arrayValues.append(propertyValueString[arrayIndex]);
	    }

            break;
	}

	case CIMTYPE_DATETIME:
	{
	    Array<CIMDateTime> propertyValueDateTime;
	    propertyValue.get(propertyValueDateTime);

            Boolean canLocalize = false;

#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
	    Locale locale;
	    canLocalize = _canLocalize(contentLangs, locale);
#endif

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
                    if (canLocalize)
		    {
			arrayValues.append(_localizeDateTime(
			    propertyValueDateTime[i], locale));
		    }
		    else
		    {
		        arrayValues.append(propertyValueDateTime[i].toString());
		    }
#else
		    arrayValues.append(propertyValueDateTime[i].toString());
#endif

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
		if (canLocalize)
		{
		    arrayValues.append(_localizeDateTime(
			propertyValueDateTime[arrayIndex], locale));
		}
		else
		{
		    arrayValues.append(propertyValueDateTime
			[arrayIndex].toString());
		}
#else
	        arrayValues.append(propertyValueDateTime
		    [arrayIndex].toString());
#endif
	    }

            break;
	}

	case CIMTYPE_REFERENCE:
	{
	    Array<CIMObjectPath> propertyValueRef;
	    propertyValue.get(propertyValueRef);

	    // Empty brackets (e.g. []), gets all values of the array
	    if (sizeOfArrayIndexStr == 0)
	    {
                arrayValues.append("[");
		for (Uint32 i=0; i<arraySize; i++)
		{
		    arrayValues.append(propertyValueRef[i].toString());

		    if ( i < arraySize-1)
		    {
			arrayValues.append(",");
		    }
		}

		arrayValues.append("]");
	    }
	    else
	    {
	        arrayValues.append(propertyValueRef
		    [arrayIndex].toString());
	    }

            break;
	}

	default:
	{
	    arrayValues.append("UNKNOWN");

            PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,
		"Unknown CIMType: " + type);

            break;
	}
    }

    PEG_METHOD_EXIT();
    return (arrayValues);
}
Ejemplo n.º 5
0
void
CIMtoXML(CIMQualifier const& cq, ostream& ostr)
{
	CIMFlavor fv;
	
	if (cq.getName().empty())
	{
		OW_THROWCIMMSG(CIMException::FAILED, "qualifier must have a name");
	}
	CIMValue dv = cq.getDefaults().getDefaultValue();
	CIMDataType dt = cq.getDefaults().getDataType();
	CIMValue cv = cq.getValue();
	if (!cv)
	{
		cv = dv;
	}
	if (cv)
	{
		if (cv.isArray())
		{
			dt = CIMDataType(cv.getType(),cv.getArraySize());
		}
		else
		{
			dt = CIMDataType(cv.getType());
		}
	}
	OW_ASSERT(dt);
	ostr
		<< "<QUALIFIER NAME=\""
		<< cq.getName()
		<< "\" TYPE=\"";
	CIMtoXML(dt,ostr);
	ostr << "\" ";
	if (cq.getPropagated())
	{
		ostr << "PROPAGATED=\"true\" ";
	}
	//
	// Create flavors
	//
	fv = CIMFlavor(CIMFlavor::ENABLEOVERRIDE);
	if (cq.hasFlavor(fv))
	{
		//
		// Not needed, because OVERRIDABLE defaults to true!
	}
	else
	{
		fv = CIMFlavor(CIMFlavor::DISABLEOVERRIDE);
		if (cq.hasFlavor(fv))
		{
			CIMtoXML(fv, ostr);
			ostr <<  "=\"false\" ";
		}
	}
	fv = CIMFlavor(CIMFlavor::TOSUBCLASS);
	if (cq.hasFlavor(fv))
	{
		//
		// Not needed, because TOSUBCLASS defaults to true!
	}
	else
	{
		fv = CIMFlavor(CIMFlavor::RESTRICTED);
		if (cq.hasFlavor(fv))
		{
			CIMtoXML(fv, ostr);
			ostr <<  "=\"false\" ";
		}
	}
	// This is a bug in the spec, but we still support it for backward compatibility.
	//fv = CIMFlavor(CIMFlavor::TOINSTANCE);
	//if (cq.hasFlavor(fv))
	//{
	//	CIMtoXML(fv, ostr);
	//	ostr << "=\"true\" ";
	//}
	//else
	//{
		//
		// Not needed, because TOINSTANCE defaults to false!
	//}
	fv = CIMFlavor(CIMFlavor::TRANSLATE);
	if (cq.hasFlavor(fv))
	{
		CIMtoXML(fv, ostr);
		ostr << "=\"true\" ";
	}
	else
	{
		//
		// Not needed, because TRANSLATABLE defaults to false!
	}

	String lang = cq.getLanguage();
	if (!lang.empty())
	{
		ostr << " xml:lang=\"";
		ostr << lang;
		ostr << '\"';
	}

	ostr << '>';
	if (cv)
	{
		CIMtoXML(cv, ostr);
	}
	ostr << "</QUALIFIER>";
}