Esempio n. 1
0
/** toMof - returns the MOF for the CIM Property Object in the parameter.
    The BNF for the property MOF is:
    <pre>
    propertyDeclaration     = 	[ qualifierList ] dataType propertyName
				[ array ] [ defaultValue ] ";"

    array 		    = 	"[" [positiveDecimalValue] "]"

    defaultValue 	    = 	"=" initializer
    </pre>
    Format with qualifiers on one line and declaration on another. Start
    with newline but none at the end.
*/
void CIMPropertyRep::toMof(Array<char>& out) const  //ATTNKS:
{
    //Output the qualifier list
    if (_qualifiers.getCount())
	out << "\n";
    _qualifiers.toMof(out);

    // Output the Type and name on a new line
    out << "\n" << cimTypeToString (_value.getType ()) << " " << _name;

    // If array put the Array indicator "[]" and possible size after name.
    if (_value.isArray())
    {
	if (_arraySize)
	{
	    char buffer[32];
	    sprintf(buffer, "[%d]", _arraySize);
	    out << buffer;
	}
	else
	    out << "[]";
    }

    // If the property value is not Null, add value after "="
    if (!_value.isNull())
    {
	out << " = ";
	if (_value.isArray())
	{
	    // Insert any property values
	    MofWriter::appendValueElement(out, _value);
	}
	else if (_value.getType() == CIMTYPE_REFERENCE)
	{
	    MofWriter::appendValueElement(out, _value);
	}
	else
	{
	    MofWriter::appendValueElement(out, _value);
	}
    }
    // Close the property MOF
    out << ";";

}
Esempio n. 2
0
/** toMof - puts the Mof representation of teh Parameter object to
    the output parameter array
    The BNF for this conversion is:
    parameterList    = 	parameter *( "," parameter )

	parameter    = 	[ qualifierList ] (dataType|objectRef) parameterName
				[ array ]

	parameterName= 	IDENTIFIER

	array 	     = 	"[" [positiveDecimalValue] "]"

    Format on a single line.
    */
void CIMParameterRep::toMof(Array<char>& out) const
{
    // Output the qualifiers for the parameter
    _qualifiers.toMof(out);

    if (_qualifiers.getCount())
	out << " ";

    // Output the data type and name
    out << cimTypeToString (_type) << " " <<  _name;

    if (_isArray)
    {
	//Output the array indicator "[ [arraysize] ]"
	if (_arraySize)
	{
	    char buffer[32];
	    sprintf(buffer, "[%d]", _arraySize);
	    out << buffer;
	}
	else
	    out << "[]";
    }
}
Esempio n. 3
0
int _getClass(const int argc, const char **argv)
{
  CIMClass cldef;
  try
  {
    cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] );
  }
  catch (Exception& e)
  {
    cerr << /* "getClass: " << */ e.getMessage() << endl;
    return 1;
  }

  // Display the class definition
  // without qualifiers, for the moment

  // First the class name and superclass
  cout << "class " << cldef.getClassName().getString() << " : "
    << cldef.getSuperClassName().getString() << endl;
  cout << "{" << endl;
  
  // Now the properties
  // No qualifiers except [key], but specify type, array
  for (int i=0; i<cldef.getPropertyCount(); i++)
  {
    CIMProperty p = cldef.getProperty(i);
    cout << "  ";
    // output key, if required
    if (_isKey(p)) cout << "[ Key ] ";
    // prepare to output type, but
    // first, if type is "reference", find target class
    if (p.getType() == CIMTYPE_REFERENCE)
      cout << p.getReferenceClassName().getString() << " REF ";
    // output type
    else cout << cimTypeToString(p.getType()) << " ";
    // output name
    cout << p.getName().getString();
    // output array, if required
    if (p.isArray()) cout << "[]";
    // final eol
    cout << ";" << endl;
  }
  
  // need to do methods
  for (int i=0; i<cldef.getMethodCount(); i++)
  {
    CIMMethod m = cldef.getMethod(i);
    // output type
    cout << "  " << cimTypeToString(m.getType()) << " ";
    // output name
    cout << m.getName().getString() << "(";
    // output parameters
    // new line if there are any parameters
    for (int j=0; j<m.getParameterCount(); j++)
    {
      CIMParameter p = m.getParameter(j);
      // output IN/OUT qualifiers on a fresh line
      cout << endl << "    [ ";
      // loop through qualifiers looking for IN, OUT
      for (int k=0; k<p.getQualifierCount(); k++)
      {
        // when one found, output its value
        CIMQualifier q = p.getQualifier(k);
        if (q.getName().equal("in") ||
            q.getName().equal("out"))
        {
          cout << q.getName().getString() << " ";
        }
      }
      // Now the type
      cout << "] " << cimTypeToString(p.getType()) << " ";
      // finally the name
      cout << p.getName().getString();
      // array brackets
      if (p.isArray()) cout << "[]";
      // closing , on parameter if not last
      if (j != m.getParameterCount()-1) cout << ",";
    }
    // after last param, indent before closing paren

    // close paren
    cout << ")";
    // if (m.isArray()) cout << "[]";
    // finish output
    cout << ";" << endl;
  }
  
  // final brace and done
  cout << "};" << endl;

  return 0; 
}
Esempio n. 4
0
// Tests PROPERTY as an embedded object.
static void testGetInstanceElement(const char* testDataFile)
{
    //--------------------------------------------------------------------------
    // Read in instance
    //--------------------------------------------------------------------------

    CIMInstance cimInstance;
    Buffer text;
    FileSystem::loadFileToMemory(text, testDataFile);

    XmlParser parser((char*)text.getData());

    XmlReader::getInstanceElement(parser, cimInstance);
    PEGASUS_TEST_ASSERT(
        cimInstance.getClassName() == CIMName("CIM_InstCreation"));

    Uint32 idx;
    CIMProperty cimProperty;
    CIMValue cimValue;
    CIMType cimType;
    PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3);

    idx = cimInstance.findProperty(CIMName("IndicationIdentifier"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0);
    String myString;
    cimValue.get(myString);
    PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "0") == 0);

    idx = cimInstance.findProperty(CIMName("IndicationTime"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "datetime") == 0);
    CIMDateTime myDateTime;
    cimValue.get(myDateTime);
    PEGASUS_TEST_ASSERT(myDateTime.equal(
        CIMDateTime("20050227225624.524000-300")));

    idx = cimInstance.findProperty(CIMName("SourceInstance"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "object") == 0);
    CIMObject cimObject;
    cimValue.get(cimObject);
    PEGASUS_TEST_ASSERT(
        cimObject.getClassName() == 
            CIMName("Sample_LifecycleIndicationProviderClass"));
    PEGASUS_TEST_ASSERT(cimObject.getPropertyCount() == 2);

    idx = cimObject.findProperty(CIMName("uniqueId"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimObject.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "uint32") == 0);
    Uint32 myUint32;
    cimValue.get(myUint32);
    PEGASUS_TEST_ASSERT(myUint32 == 1);

    idx = cimObject.findProperty(CIMName("lastOp"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimObject.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0);
    cimValue.get(myString);
    PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "createInstance") == 0);
}
Esempio n. 5
0
// Tests PROPERTY.ARRAY as an embedded object with array type.
static void testGetInstanceElement2(const char* testDataFile)
{
    CIMInstance cimInstance;
    Buffer text;
    FileSystem::loadFileToMemory(text, testDataFile);

    XmlParser parser((char*)text.getData());

    XmlReader::getInstanceElement(parser, cimInstance);
    PEGASUS_TEST_ASSERT(cimInstance.getClassName() == 
                        CIMName("CIM_InstCreation"));

    Uint32 idx;
    CIMProperty cimProperty;
    CIMValue cimValue;
    CIMType cimType;
    PEGASUS_TEST_ASSERT(cimInstance.getPropertyCount() == 3);

    idx = cimInstance.findProperty(CIMName("IndicationIdentifier"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "string") == 0);
    String myString;
    cimValue.get(myString);
    PEGASUS_TEST_ASSERT(strcmp(myString.getCString(), "0") == 0);

    idx = cimInstance.findProperty(CIMName("IndicationTime"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "datetime") == 0);
    CIMDateTime myDateTime;
    cimValue.get(myDateTime);
    PEGASUS_TEST_ASSERT(myDateTime.equal(
        CIMDateTime("20050227225624.524000-300")));

    idx = cimInstance.findProperty(CIMName("SourceInstance"));
    PEGASUS_TEST_ASSERT(idx != PEG_NOT_FOUND);
    cimProperty = cimInstance.getProperty(idx);
    cimValue = cimProperty.getValue();
    cimType = cimProperty.getType();
    PEGASUS_TEST_ASSERT(strcmp(cimTypeToString(cimType), "object") == 0);
    Array<CIMObject> cimObject;
    cimValue.get(cimObject);
    PEGASUS_TEST_ASSERT(cimObject.size() == 2);
    for (idx = 0; idx < cimObject.size(); idx++)
    {
        CIMInstance cimInstanceElement(cimObject[idx]);
        PEGASUS_TEST_ASSERT(cimInstanceElement.getPropertyCount() == 2);
        Uint32 propIdx = cimInstanceElement.findProperty(CIMName("uniqueId"));
        if (propIdx != PEG_NOT_FOUND)
        {
            CIMProperty nestedProperty = 
                cimInstanceElement.getProperty(propIdx);
            cimValue = nestedProperty.getValue();
            Uint32 uniqueId;
            cimValue.get(uniqueId);
            propIdx = cimInstanceElement.findProperty(CIMName("lastOp"));
            nestedProperty = cimInstanceElement.getProperty(propIdx);
            cimValue = nestedProperty.getValue();
            String checkStringValue;
            cimValue.get(checkStringValue);
            if (uniqueId == 1)
            {
                PEGASUS_TEST_ASSERT(strcmp(
                    checkStringValue.getCString(), "createInstance") == 0);
            }
            else if (uniqueId == 2)
            {
                PEGASUS_TEST_ASSERT(strcmp(
                    checkStringValue.getCString(), "deleteInstance") == 0);
            }
            else
            {
                PEGASUS_TEST_ASSERT(false);
            }
        }
    }
}
Esempio n. 6
0
void CIMParameterRep::toXml(Array<char>& out) const
{
    if (_isArray)
    {
        if (_type == CIMTYPE_REFERENCE)
        {
            out << "<PARAMETER.REFARRAY";
            out << " NAME=\"" << _name << "\"";

            if (!_referenceClassName.isNull())
            {
                out << " REFERENCECLASS=\"" << _referenceClassName.getString()
                    << "\"";
            }

			if (_arraySize)
            {
                char buffer[32];
                sprintf(buffer, "%d", _arraySize);
                out << " ARRAYSIZE=\"" << buffer << "\"";
            }

            out << ">\n";

            _qualifiers.toXml(out);

            out << "</PARAMETER.REFARRAY>\n";
        }
        else
        {
            out << "<PARAMETER.ARRAY";
            out << " NAME=\"" << _name << "\" ";
            out << " TYPE=\"" << cimTypeToString (_type) << "\"";

            if (_arraySize)
            {
                char buffer[32];
                sprintf(buffer, "%d", _arraySize);
                out << " ARRAYSIZE=\"" << buffer << "\"";
            }

            out << ">\n";

            _qualifiers.toXml(out);

            out << "</PARAMETER.ARRAY>\n";
        }
    }
    else if (_type == CIMTYPE_REFERENCE)
    {
	out << "<PARAMETER.REFERENCE";
	out << " NAME=\"" << _name << "\"";
        if (!_referenceClassName.isNull())
        {
	    out << " REFERENCECLASS=\"" << _referenceClassName.getString() <<
                   "\"";
        }
	out << ">\n";

	_qualifiers.toXml(out);

	out << "</PARAMETER.REFERENCE>\n";
    }
    else
    {
	out << "<PARAMETER";
	out << " NAME=\"" << _name << "\" ";
	out << " TYPE=\"" << cimTypeToString (_type) << "\"";
	out << ">\n";

	_qualifiers.toXml(out);

	out << "</PARAMETER>\n";
    }
}
Esempio n. 7
0
void RUEpProvider::_createAssociationInstances(
    Array<CIMInstance> nhrInst,
    Array<CIMInstance> ipifInst)
{
    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,
        "RUEpProvider::_createAssociationInstances()");

    Uint16 nhrInstSize = nhrInst.size();
    Uint16 ipifInstSize = ipifInst.size();

    for (Uint16 i = 0; i < nhrInstSize; i++)  // Routes loop.
    {
        CIMInstance _nhrInstRet, _ipifInstRet;
        CIMInstance _nhrInst = nhrInst[i];

        CIMProperty _ipifAddress;
        CIMProperty _ipifSubnetMask_PrefixLength;
        CIMProperty _ipifProtocolIFType;
        CIMProperty _nhrInstanceID = _nhrInst.getProperty(
            _nhrInst.findProperty(PROPERTY_INSTANCE_ID));
        CIMProperty _nhrAddrType;
        CIMProperty _nhrDestMask_PrefixLength;


        for (Uint16 j = 0; j<ipifInstSize; j++)  // Interfaces loop.
        {
            CIMInstance _ipifInst = ipifInst[j];

            _ipifProtocolIFType = _ipifInst.getProperty(
                _ipifInst.findProperty(PROPERTY_PROTOCOL_IF_TYPE));

            Uint16 _pift;
            CIMValue _piftCIMValue = _ipifProtocolIFType.getValue();
            if ((_piftCIMValue.getType() == CIMTYPE_UINT16) &&
                (!_piftCIMValue.isNull ()))
            {
                _piftCIMValue.get(_pift);
            }
            else
            {
                throw CIMOperationFailedException(
                    "Can't determine CIMValue::TYPE of ProtocolIFType:" +
                    String(cimTypeToString(_piftCIMValue.getType())));
            }

            if (_pift == 4096)  // IPv4 address.
            {
                _ipifAddress = _ipifInst.getProperty(
                    _ipifInst.findProperty(
                        PROPERTY_IPV4ADDRESS));
                _ipifSubnetMask_PrefixLength = _ipifInst.getProperty(
                    _ipifInst.findProperty(
                    PROPERTY_SUBNET_MASK));
            }
            else
            {
                if (_pift == 4097)  // IPv6 address.
                {
                    _ipifAddress = _ipifInst.getProperty(
                        _ipifInst.findProperty(
                            PROPERTY_IPV6ADDRESS));
                    _ipifSubnetMask_PrefixLength = _ipifInst.getProperty(
                        _ipifInst.findProperty(
                            PROPERTY_IPV6ADDRESS));
                }
                else
                {
                    char buffer[22];
                    Uint32 sz;
                    String _piftStr = Uint16ToString(buffer, _pift, sz);
                    throw CIMOperationFailedException(
                        "ProtocolIFType == " +  _piftStr );
                }
            }

            // In this implementation, we choose InstanceID to be
            // equal DestinationAddress. So, if Address of interface
            // and InstanceID of route doesn't match, check if SubnetMask
            // of interface and DestinationMask route does.
            if (!_nhrInstanceID.getValue().equal(_ipifAddress.getValue()))
            {
                _nhrAddrType = _nhrInst.getProperty(
                    _nhrInst.findProperty(
                        PROPERTY_ADDRESS_TYPE));
                Uint16 _addrt;
                CIMValue _nhratCIMValue = _nhrAddrType.getValue();
                if ((_nhratCIMValue.getType() == CIMTYPE_UINT16) &&
                    (!_nhratCIMValue.isNull()))
                {
                    _nhratCIMValue.get(_addrt);
                }
                else
                {
                    throw CIMOperationFailedException(
                        "Can't determine CIMValue::TYPE of AddressType: " +
                        String(cimTypeToString(_piftCIMValue.getType())));
                }

                if (_addrt == 1)  // IPv4 address.
                {
                    _nhrDestMask_PrefixLength = _nhrInst.getProperty(
                       _nhrInst.findProperty(
                           PROPERTY_DESTINATION_MASK));
                }
                else
                {
                    if (_addrt == 2)  // IPv6 address.
                    {
                         _nhrDestMask_PrefixLength = _nhrInst.getProperty(
                             _nhrInst.findProperty(
                                 PROPERTY_PREFIX_LENGTH));
                    }
                    else
                    {
                        char buffer[22];
                        Uint32 sz;
                        String _addrtStr = Uint16ToString(buffer, _addrt, sz);
                        throw CIMOperationFailedException(
                            "Unknown AddressType = " + _addrtStr);
                    }
                }

                // If SubnetMask of interface and DestinationMask route
                // doesn't match, these instances are unrelated. So,
                // proceed to the next pair.
                if (!_nhrDestMask_PrefixLength.getValue().equal(
                    _ipifSubnetMask_PrefixLength.getValue()))
                {
                    continue;
                }
            }

            // Build the CIMObjectPath from the instances matching
            CIMObjectPath _ipifObj = _ipifInst.getPath();
            CIMObjectPath _nhrObj = _nhrInst.getPath();

            CIMInstance assocInst(CLASS_PG_ROUTE_USES_ENDPOINT);
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Antecedent"),
                    _ipifObj,
                    0,
                    CLASS_CIM_PROTOCOL_ENDPOINT));
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Dependent"),
                    _nhrObj,
                    0,
                    CLASS_CIM_NEXT_HOP_ROUTE));

            // Build CIMObjectPath from keybindings
            Array<CIMKeyBinding> keyBindings;
            CIMKeyBinding _ipifBinding(
                CIMName("Antecedent"),
                _ipifObj.toString(),
                CIMKeyBinding::REFERENCE);
            CIMKeyBinding _nhrBinding(
                CIMName("Dependent"),
                _nhrObj.toString(),
                CIMKeyBinding::REFERENCE);
            keyBindings.append (_ipifBinding);
            keyBindings.append (_nhrBinding);

            CIMObjectPath path(
                String::EMPTY,
                CIMNamespaceName(),
                CLASS_PG_ROUTE_USES_ENDPOINT,
                keyBindings);

            assocInst.setPath(path);
            _AssociationInstances.append(assocInst);
            break;
        }  // Interfaces loop end.

    }  // Routes loop end.

    PEG_METHOD_EXIT();
}
void IndicationFormatter::_validatePropertyType (
    const CIMClass & indicationClass,
    const String & propertyParam,
    const String & typeStr,
    const Boolean & isArray)
{
    PEG_METHOD_ENTER (TRC_IND_FORMATTER,
	"IndicationFormatter::_validatePropertyType");

    String exceptionStr;
    char propertyTypeBuffer[32];
    char * providedPropertyType;
    Array <String> validPropertyTypes;

    String propertyTypeStr = typeStr;

    validPropertyTypes.append ( "boolean");
    validPropertyTypes.append ( "uint8");
    validPropertyTypes.append ( "sint8");
    validPropertyTypes.append ( "uint16");
    validPropertyTypes.append ( "sint16");
    validPropertyTypes.append ( "uint32");
    validPropertyTypes.append ( "sint32");
    validPropertyTypes.append ( "uint64");
    validPropertyTypes.append ( "sint64");
    validPropertyTypes.append ( "real32");
    validPropertyTypes.append ( "real64");
    validPropertyTypes.append ( "char16");
    validPropertyTypes.append ( "string");
    validPropertyTypes.append ( "datetime");
    validPropertyTypes.append ( "reference");

    propertyTypeStr.toLower();
    sprintf(propertyTypeBuffer, "%s",
        (const char *)propertyTypeStr.getCString());

    // skip white space
    providedPropertyType = propertyTypeBuffer;
    while (*providedPropertyType && isspace(*providedPropertyType))
    {
        providedPropertyType++;
    }

    String providedTypeStr = providedPropertyType;

    Uint32 space = providedTypeStr.find(" ");

    if (space != PEG_NOT_FOUND)
    {
	// skip the appended space from the providedTypeStr
	// e.g {1, string  }
	String restTypeStr = providedTypeStr.subString(space, PEG_NOT_FOUND);

        Uint32 i = 0;
        while (restTypeStr[i] == ' ')
        {
            i++;
        }

        restTypeStr = restTypeStr.subString(i, PEG_NOT_FOUND);
	if (strlen(restTypeStr.getCString()) == 0)
	{
	    providedTypeStr = providedTypeStr.subString(0, space);
	}
        else
        {
            // the provided property type is not a valid type
            // e.g. {1, string  xxx}
            MessageLoaderParms parms(
                "IndicationFormatter.IndicationFormatter._MSG_INVALID_TYPE_OF_FOR_PROPERTY",
            "Invalid property type of $0 in property $1",
            providedPropertyType,
            _PROPERTY_TEXTFORMAT.getString());
        } 
    }

    //
    // Checks if the provided property type is a valid type
    //
    if (!(Contains (validPropertyTypes, providedTypeStr)))
    {
	// the provided property type is not valid type
	MessageLoaderParms parms(
	"IndicationFormatter.IndicationFormatter._MSG_INVALID_TYPE_OF_FOR_PROPERTY",
	"Invalid property type of $0 in property $1",
	providedPropertyType,
	_PROPERTY_TEXTFORMAT.getString());

	exceptionStr.append(MessageLoader::getMessage(parms));

	PEG_METHOD_EXIT();
	throw PEGASUS_CIM_EXCEPTION (
	    CIM_ERR_INVALID_PARAMETER, exceptionStr);
    }

    for (Uint32 i = 0; i < indicationClass.getPropertyCount (); i++)
    {
	CIMName propertyName = indicationClass.getProperty (i).getName ();

        if (String::equalNoCase(propertyParam, (propertyName.getString())))
        {
	    // get the property type;
	    CIMType propertyType =
	                indicationClass.getProperty (i).getType();

	    // Check if the property is an array type
	    if ((isArray && !(indicationClass.getProperty(i).isArray())) ||
		(!isArray && indicationClass.getProperty(i).isArray()))
	    {
		MessageLoaderParms parms(
		"IndicationFormatter.IndicationFormatter._MSG_PROPERTY_IS_NOT_AN_ARRAY_TYPE",
		"The property $0 is not an array type",
                propertyName.getString());

	        exceptionStr.append(MessageLoader::getMessage(parms));

	        PEG_METHOD_EXIT();
	        throw PEGASUS_CIM_EXCEPTION (
	            CIM_ERR_INVALID_PARAMETER, exceptionStr);
	    }

	    // property type matchs
            if (String::equalNoCase(providedTypeStr,
	        cimTypeToString(propertyType)))
            {
	        break;
	    }
	    else
	    {
	        MessageLoaderParms parms(
	        "IndicationFormatter.IndicationFormatter._MSG_MISS_MATCHED_TYPE_OF_FOR_PROPERTY",
	        "The provided property type of $0 in $1 does not match the property type $2",
	         providedPropertyType,
		cimTypeToString(propertyType),
	        _PROPERTY_TEXTFORMAT.getString());

	        exceptionStr.append(MessageLoader::getMessage(parms));

	        PEG_METHOD_EXIT();
	        throw PEGASUS_CIM_EXCEPTION (
	            CIM_ERR_INVALID_PARAMETER, exceptionStr);
            }

        }
    }

    PEG_METHOD_EXIT();
}
Esempio n. 9
0
void CIMPropertyRep::toXml(Array<char>& out) const
{
    if (_value.isArray())
    {
	out << "<PROPERTY.ARRAY";

	out << " NAME=\"" << _name << "\" ";

    // If the property array type is CIMObject, then
    //   encode the property in CIM-XML as a string array with the EMBEDDEDOBJECT attribute
    //   (there is not currently a CIM-XML "object" datatype)
    // else
    //   output the real type
    if (_value.getType() == CIMTYPE_OBJECT)
    {
        Array<CIMObject> a;
        _value.get(a);
        out << " TYPE=\"string\"";
        // If the Embedded Object is an instance, always add the EMBEDDEDOBJECT attribute.
        if (a.size() > 0 && a[0].isInstance())
            out << " EMBEDDEDOBJECT=\"object\"";
        // Else the Embedded Object is a class, always add the EmbeddedObject qualifier.
        // Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined, then
        // the EmbeddedObject qualifier will always be added, whether it's a class or
        // an instance.
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
        else
        {
#endif
            if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND)
            {
                // Note that _qualifiers is not defined as const, and neither is add(),
                // but this method toXml() *is* const. However, in this case we really
                // do want to add the EmbeddedObject qualifier, so we cast away the
                // implied const-ness of _qualifiers.
                ((CIMQualifierList)_qualifiers).add(CIMQualifier(CIMName("EmbeddedObject"), true));
            }
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
        }
#endif
    }
    else
    {
        out << " TYPE=\"" << cimTypeToString (_value.getType ()) << "\"";
    }

    if (_arraySize)
	{
	    char buffer[32];
	    sprintf(buffer, "%d", _arraySize);
	    out << " ARRAYSIZE=\"" << buffer << "\"";
	}

	if (!_classOrigin.isNull())
	    out << " CLASSORIGIN=\"" << _classOrigin << "\"";

	if (_propagated != false)
	    out << " PROPAGATED=\"" << _toString(_propagated) << "\"";

	out << ">\n";

	_qualifiers.toXml(out);

	XmlWriter::appendValueElement(out, _value);

	out << "</PROPERTY.ARRAY>\n";
    }
    else if (_value.getType() == CIMTYPE_REFERENCE)
    {
	out << "<PROPERTY.REFERENCE";

	out << " NAME=\"" << _name << "\" ";

        if (!_referenceClassName.isNull())
        {
            out << " REFERENCECLASS=\"" << _referenceClassName << "\"";
        }

	if (!_classOrigin.isNull())
	    out << " CLASSORIGIN=\"" << _classOrigin << "\"";

	if (_propagated != false)
	    out << " PROPAGATED=\"" << _toString(_propagated) << "\"";

	out << ">\n";

	_qualifiers.toXml(out);

	XmlWriter::appendValueElement(out, _value);

	out << "</PROPERTY.REFERENCE>\n";
    }
    else
    {
	out << "<PROPERTY";
	out << " NAME=\"" << _name << "\" ";

	if (!_classOrigin.isNull())
	    out << " CLASSORIGIN=\"" << _classOrigin << "\"";

	if (_propagated != false)
	    out << " PROPAGATED=\"" << _toString(_propagated) << "\"";

    // If the property type is CIMObject, then
    //   encode the property in CIM-XML as a string with the EMBEDDEDOBJECT attribute
    //   (there is not currently a CIM-XML "object" datatype)
    // else
    //   output the real type
    if (_value.getType() == CIMTYPE_OBJECT)
    {
        CIMObject a;
        _value.get(a);
        out << " TYPE=\"string\"";
        // If the Embedded Object is an instance, always add the EMBEDDEDOBJECT attribute.
        if (a.isInstance())
            out << " EMBEDDEDOBJECT=\"object\"";
        // Else the Embedded Object is a class, always add the EmbeddedObject qualifier.
        // Note that if the macro PEGASUS_SNIA_INTEROP_COMPATIBILITY is defined, then
        // the EmbeddedObject qualifier will always be added, whether it's a class or
        // an instance.
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
        else
        {
#endif
            if (_qualifiers.find(CIMName("EmbeddedObject")) == PEG_NOT_FOUND)
            {
                // Note that _qualifiers is not defined as const, and neither is add(),
                // but this method toXml() *is* const. However, in this case we really
                // do want to add the EmbeddedObject qualifier, so we cast away the
                // implied const-ness of _qualifiers.
                ((CIMQualifierList)_qualifiers).add(CIMQualifier(CIMName("EmbeddedObject"), true));
            }
#ifndef PEGASUS_SNIA_INTEROP_COMPATIBILITY
        }
#endif
    }
    else
    {
        out << " TYPE=\"" << cimTypeToString (_value.getType ()) << "\"";
    }

	out << ">\n";

	_qualifiers.toXml(out);

	XmlWriter::appendValueElement(out, _value);

	out << "</PROPERTY>\n";
    }
}
Esempio n. 10
0
int _getProperty(const int argc, const char **argv)
{
  if (argc < 2)
  {
    _gpUsage();
    return 1;
  }
  
  // need to get class definition to find keys
  // first arg is name of class
  CIMClass cldef;
  try
  {
    cldef = _c.getClass( _nameSpace, argv[0] );
  }
  catch(Exception& e)
  {
    cerr << /* "getProperty: " << */ e.getMessage() << endl;
    return 1;
  }

  CIMObjectPath ref;
  CIMInstance inst;

  // If next arg is "ask", prompt user for keys
  if (String::equalNoCase("ask",argv[1])) ref = CIMObjectPath(String::EMPTY,
                                                   _nameSpace,
                                                   argv[0],
                                                   _inputInstanceKeys(cldef) );

  // else if the next arg and is "list", enumInstNames and print
  // a list from which user will select  
  else if (String::equalNoCase("list",argv[1]))
  {
    ref = _selectInstance( argv[0] );
    if (ref.identical(CIMObjectPath())) return 0;
  }

  // else there's another arg but it's invalid
  else
  {
    _gpUsage();
    return 1;
  }

  CIMProperty pDef;
  // if no more args, display property names and ask which
  if (argc < 3)
  {
    int n;
    for (n=0; n<cldef.getPropertyCount(); n++)
    {
      pDef=cldef.getProperty(n);
      cout << n+1 << ": ";
      cout << cimTypeToString(pDef.getType()) << " ";
      cout << pDef.getName().getString();
      if (pDef.isArray()) cout << "[]";
      cout << endl;
    }
    cout << "Property (1.." << cldef.getPropertyCount() << ")? " << flush;
    cin >> n;
    pDef = cldef.getProperty(n-1);
  }