本文整理汇总了C++中CIMInstance::clone方法的典型用法代码示例。如果您正苦于以下问题:C++ CIMInstance::clone方法的具体用法?C++ CIMInstance::clone怎么用?C++ CIMInstance::clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIMInstance
的用法示例。
在下文中一共展示了CIMInstance::clone方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createInstance
void InstanceProvider::createInstance(
const OperationContext & context,
const CIMObjectPath & instanceReference,
const CIMInstance & instanceObject,
ObjectPathResponseHandler & handler)
{
// Validate the class name
if (!instanceObject.getClassName().equal("Sample_InstanceProviderClass"))
{
throw CIMNotSupportedException(
instanceObject.getClassName().getString());
}
// Find the key property
Uint32 idIndex = instanceObject.findProperty("Identifier");
if (idIndex == PEG_NOT_FOUND)
{
throw CIMInvalidParameterException("Missing key value");
}
CIMInstance cimInstance = instanceObject.clone();
// Create the new instance name
CIMValue idValue = instanceObject.getProperty(idIndex).getValue();
Array<CIMKeyBinding> keys;
keys.append(CIMKeyBinding("Identifier", idValue));
CIMObjectPath instanceName = CIMObjectPath(
String(),
CIMNamespaceName(),
instanceObject.getClassName(),
keys);
cimInstance.setPath(instanceName);
// Determine whether this instance already exists
for(Uint32 i = 0, n = _instances.size(); i < n; i++)
{
if(instanceName == _instances[i].getPath())
{
throw CIMObjectAlreadyExistsException(instanceName.toString());
}
}
// begin processing the request
handler.processing();
// add the new instance to the array
_instances.append(cimInstance);
// deliver the new instance name
handler.deliver(instanceName);
// complete processing the request
handler.complete();
}
示例2: modifyInstance
void InstanceProvider::modifyInstance(
const OperationContext & context,
const CIMObjectPath & instanceReference,
const CIMInstance & instanceObject,
const Boolean includeQualifiers,
const CIMPropertyList & propertyList,
ResponseHandler & handler)
{
// convert a potential fully qualified reference into a local reference
// (class name and keys only).
CIMObjectPath localReference = CIMObjectPath(
String(),
CIMNamespaceName(),
instanceReference.getClassName(),
instanceReference.getKeyBindings());
// begin processing the request
handler.processing();
// instance index corresponds to reference index
for(Uint32 i = 0, n = _instances.size(); i < n; i++)
{
if(localReference == _instances[i].getPath())
{
CIMInstance cimInstance = instanceObject.clone();
CIMObjectPath instanceName = CIMObjectPath(
String(),
CIMNamespaceName(),
instanceReference.getClassName(),
instanceReference.getKeyBindings());
cimInstance.setPath(instanceName);
// overwrite existing instance
_instances[i] = instanceObject;
break;
}
}
// complete processing the request
handler.complete();
}
示例3: testEmbeddedValueArray
void testEmbeddedValueArray(const CIMInstance & startInstance,
const CIMNamespaceName & NAMESPACE,
SimpleDeclContext * context)
{
CIMInstance instance1(startInstance.clone());
// Test an array of CIMObjects that are CIMInstances
CIMInstance instance2(CIMName ("MyClass"));
instance2.addQualifier(CIMQualifier(CIMName ("classcounter"), true));
instance2.addProperty(CIMProperty(CIMName ("message"), String("Adios")));
Resolver::resolveInstance (instance2, context, NAMESPACE, true);
CIMInstance instance3(CIMName ("MyClass"));
instance3.addQualifier(CIMQualifier(CIMName ("classcounter"), false));
instance3.addProperty(CIMProperty(CIMName ("message"),
String("Au Revoir")));
Resolver::resolveInstance (instance3, context, NAMESPACE, true);
Array<EmbeddedType> arr16;
arr16.append(EmbeddedType(instance1));
arr16.append(EmbeddedType(instance2));
arr16.append(EmbeddedType(instance3));
test02(arr16);
// Specific test to verify the cloning of CIMObjects when set as and
// gotten from a CIMValue.
CIMValue v1array;
// Create CIMValue v1 of type CIMTYPE_OBJECT (ie. CIMObject)
v1array.set(arr16);
// Change the "count" property of arr16[1], and then verify
// that the CIMValue v1array, that was set from arr16, is
// not affected (ie. tests clone() on CIMValue::set() ).
Uint32 propIx = arr16[1].findProperty(CIMName("count"));
PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);
CIMValue v2 = arr16[1].getProperty(propIx).getValue();
Uint32 propCount;
v2.get(propCount);
PEGASUS_TEST_ASSERT(propCount == 55);
arr16[1].removeProperty(propIx);
arr16[1].addProperty(CIMProperty(CIMName ("count"), Uint32(65))
.addQualifier(CIMQualifier(CIMName ("counter"), true))
.addQualifier(CIMQualifier(CIMName ("min"), String("0")))
.addQualifier(CIMQualifier(CIMName ("max"), String("1"))));
Array<EmbeddedType> object2array;
v1array.get(object2array);
CIMInstance instance2a(object2array[1]);
propIx = instance2a.findProperty(CIMName("count"));
PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);
CIMValue v3 = instance2a.getProperty(propIx).getValue();
v3.get(propCount);
PEGASUS_TEST_ASSERT(propCount == 55);
// Now change the "count" property of instance2a, which was obtained
// from a get of CIMValue v1array. Again, the underlying CIMValue should
// not be affected (ie. tests clone() on CIMValue::get() ).
instance2a.removeProperty(propIx);
instance2a.addProperty(CIMProperty(CIMName ("count"), Uint32(65))
.addQualifier(CIMQualifier(CIMName ("counter"), true))
.addQualifier(CIMQualifier(CIMName ("min"), String("0")))
.addQualifier(CIMQualifier(CIMName ("max"), String("1"))));
Array<EmbeddedType> object3array;
v1array.get(object3array);
CIMInstance instance2b(object3array[1]);
propIx = instance2b.findProperty(CIMName("count"));
PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);
CIMValue v4 = instance2b.getProperty(propIx).getValue();
v4.get(propCount);
PEGASUS_TEST_ASSERT(propCount == 55);
// Specific test for setting value as a null CIMObject() (see bug 3373).
// Confirm that CIMValue() with an uninitialized CIMObject in the input
// array will throw exception.
arr16.append(EmbeddedType());
bool caught_exception = false;
try
{
CIMValue y(arr16);
}
catch(UninitializedObjectException&)
{
caught_exception = true;
}
PEGASUS_TEST_ASSERT (caught_exception == true);
// Confirm that set() with an uninitialized CIMObject in the input
// array will throw exception.
caught_exception = false;
try
{
CIMValue y;
y.set(arr16);
}
catch(UninitializedObjectException&)
{
caught_exception = true;
}
PEGASUS_TEST_ASSERT (caught_exception == true);
}
示例4: testEmbeddedValue
void testEmbeddedValue(const CIMInstance & instance)
{
CIMInstance instance1 = instance.clone();
// Specific test to verify the cloning of CIMObjects/CIMInstances when set
// and gotten from a CIMValue.
CIMValue v1;
// Create CIMValue v1 of type CIMTYPE_OBJECT/CIMTYPE_INSTANCE
v1.set(EmbeddedType(instance1));
// Change the "count" property of instance1, and then verify
// that the CIMValue v1, that was set from instance1, is
// not affected (ie. tests clone() on CIMValue::set() ).
Uint32 propIx = instance1.findProperty(CIMName("count"));
PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);
CIMValue v2 = instance1.getProperty(propIx).getValue();
Uint32 propCount;
v2.get(propCount);
PEGASUS_TEST_ASSERT(propCount == 55);
instance1.removeProperty(propIx);
instance1.addProperty(CIMProperty(CIMName ("count"), Uint32(65))
.addQualifier(CIMQualifier(CIMName ("counter"), true))
.addQualifier(CIMQualifier(CIMName ("min"), String("0")))
.addQualifier(CIMQualifier(CIMName ("max"), String("1"))));
EmbeddedType object2;
v1.get(object2);
CIMInstance instance1a(object2);
propIx = instance1a.findProperty(CIMName("count"));
PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);
CIMValue v3 = instance1a.getProperty(propIx).getValue();
v3.get(propCount);
PEGASUS_TEST_ASSERT(propCount == 55);
// Now change the "count" property of instance1a, which was obtained
// from a get of CIMValue v1. Again, the underlying CIMValue should
// not be affected (ie. tests clone() on CIMValue::get() ).
instance1a.removeProperty(propIx);
instance1a.addProperty(CIMProperty(CIMName ("count"), Uint32(65))
.addQualifier(CIMQualifier(CIMName ("counter"), true))
.addQualifier(CIMQualifier(CIMName ("min"), String("0")))
.addQualifier(CIMQualifier(CIMName ("max"), String("1"))));
EmbeddedType object3;
v1.get(object3);
CIMInstance instance1b(object3);
propIx = instance1b.findProperty(CIMName("count"));
PEGASUS_TEST_ASSERT(propIx != PEG_NOT_FOUND);
CIMValue v4 = instance1b.getProperty(propIx).getValue();
v4.get(propCount);
PEGASUS_TEST_ASSERT(propCount == 55);
// Specific test for setting value as a null CIMObject/CIMInstance
// (see bug 3373).
// Confirm that CIMValue() with an uninitialized CIMObject/CIMInstance will
// throw exception.
Boolean caught_exception = false;
try
{
EmbeddedType obj = EmbeddedType();
CIMValue y(obj);
}
catch(UninitializedObjectException&)
{
caught_exception = true;
}
PEGASUS_TEST_ASSERT (caught_exception == true);
// Confirm that set() with an uninitialized CIMObject/CIMInstance will
// throw exception.
caught_exception = false;
try
{
CIMValue y;
y.set(EmbeddedType());
}
catch(UninitializedObjectException&)
{
caught_exception = true;
}
PEGASUS_TEST_ASSERT (caught_exception == true);
}
示例5: modifyInstance
//
// Modify instance based on modifiedInstance.
//
void UserAuthProvider::modifyInstance(
const OperationContext & context,
const CIMObjectPath & instanceReference,
const CIMInstance& modifiedIns,
const Boolean includeQualifiers,
const CIMPropertyList & propertyList,
ResponseHandler & handler)
{
PEG_METHOD_ENTER(TRC_USER_MANAGER,"UserAuthProvider::modifyInstance");
//
// get userName
//
String user;
try
{
IdentityContainer container = context.get(IdentityContainer::NAME);
user= container.getUserName();
}
catch (...)
{
user= String::EMPTY;
}
//
// verify user authorizations
//
if ( user != String::EMPTY || user != "" )
{
_verifyAuthorization(user);
}
//
// check if the class name requested is PG_Authorization
//
if (!instanceReference.getClassName().equal (CLASS_NAME_PG_AUTHORIZATION))
{
PEG_METHOD_EXIT();
throw PEGASUS_CIM_EXCEPTION (
CIM_ERR_NOT_SUPPORTED, instanceReference.getClassName().getString());
}
CIMInstance newInstance = modifiedIns;
// begin processing the request
handler.processing();
try
{
//
// Get the user name from the instance
//
String userNameStr;
String namespaceStr;
String authorizationStr;
Uint32 pos = modifiedIns.findProperty ( PROPERTY_NAME_USERNAME );
CIMProperty prop = (CIMProperty)newInstance.getProperty(pos);
prop.getValue().get(userNameStr);
//
// Get the namespace from the instance
//
pos = modifiedIns.findProperty ( PROPERTY_NAME_NAMESPACE );
prop = (CIMProperty)newInstance.getProperty(pos);
prop.getValue().get(namespaceStr);
//
// Get the authorization from the instance
//
pos = modifiedIns.findProperty ( PROPERTY_NAME_AUTHORIZATION );
prop = (CIMProperty)newInstance.getProperty(pos);
prop.getValue().get(authorizationStr);
//
// ATTN: Note that the following is a hack, because
// modifyInstance() in repository does not like
// the hostname and namespace included in the CIMObjectPath
// passed to it as a parameter.
//
CIMObjectPath ref("", CIMNamespaceName (),
modifiedIns.getClassName(), instanceReference.getKeyBindings());
CIMInstance newModifiedIns = modifiedIns.clone ();
newModifiedIns.setPath (ref);
//
// call modifyInstances of the repository
//
_repository->modifyInstance(
instanceReference.getNameSpace(), newModifiedIns);
//
// set authorization in the UserManager
//
_userManager->setAuthorization(
userNameStr, namespaceStr, authorizationStr );
//.........这里部分代码省略.........
示例6: test04
//.........这里部分代码省略.........
pl1.clear();
pl1Array.append("blob");
pl1Array.append("ratio");
pl1.set(pl1Array);
CIMInstance newInstance = class1.buildInstance(false, true, pl1);
assert(newInstance.getPropertyCount() == 1);
assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
assert(newInstance.findProperty("blob") == PEG_NOT_FOUND);
assert(newInstance.findProperty("message") == PEG_NOT_FOUND);
assert(newInstance.getQualifierCount() == 0);
}
///////////////////////////////////////////////////////////////////////
//
// Instance Filtering function tests
//
///////////////////////////////////////////////////////////////////////
// build instance as starting point for tests.
CIMInstance tstInstance =
class1.buildInstance(true, true, CIMPropertyList());
//
// Test complete copy, no change
//
{
if (verbose)
{
cout << "Test1" << endl;
}
CIMInstance filterInstance = tstInstance.clone();
filterInstance.filter(true, true, CIMPropertyList());
assert(tstInstance.identical(filterInstance));
assert(filterInstance.getPropertyCount() == 3);
assert(filterInstance.getQualifierCount() ==
tstInstance.getQualifierCount());
}
//
// Filter to one property, ratio
//
{
if (verbose)
{
cout << "Test2" << endl;
}
Array<CIMName> pl1Array;
pl1Array.append("ratio");
CIMPropertyList pl1(pl1Array);
CIMInstance filterInstance = tstInstance.clone();
filterInstance.filter(true, true, pl1);
if (verbose)
{
XmlWriter::printInstanceElement(filterInstance);
}
assert(filterInstance.getPropertyCount() == 1);
assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND);
assert(_propertyIdentical("ratio", filterInstance, tstInstance));
示例7: createInstance
void LifecycleIndicationProvider::createInstance(
const OperationContext & context,
const CIMObjectPath & instanceReference,
const CIMInstance & instanceObject,
ObjectPathResponseHandler & handler)
{
// cout << "LifecycleIndicationProvider::createInstance()" << endl;
// Validate the class name
if(!instanceObject.getClassName().equal(
"Sample_LifecycleIndicationProviderClass"))
{
throw CIMNotSupportedException(
instanceObject.getClassName().getString());
}
// Find the key property
Uint32 idIndex = instanceObject.findProperty("uniqueId");
if(idIndex == PEG_NOT_FOUND)
{
throw CIMInvalidParameterException("Missing key value");
}
CIMInstance cimInstance = instanceObject.clone();
// Create the new instance name
CIMValue idValue = instanceObject.getProperty(idIndex).getValue();
Array<CIMKeyBinding> keys;
keys.append(CIMKeyBinding("uniqueId", idValue));
CIMObjectPath instanceName =
CIMObjectPath(
String(),
CIMNamespaceName(),
instanceObject.getClassName(),
keys);
cimInstance.setPath(instanceName);
// Determine whether this instance already exists
for(Uint32 i = 0, n = _instances.size(); i < n; i++)
{
if(instanceName == _instances[i].getPath())
{
throw CIMObjectAlreadyExistsException(instanceName.toString());
}
}
// begin processing the request
handler.processing();
// add the new instance to the array
_instances.append(cimInstance);
// deliver the new instance name
handler.deliver(instanceName);
// complete processing the request
handler.complete();
// If there is at least one subscription active for the lifecycle indication
// InstCreation_for_Sample_LifecycleIndicationProviderClass, then generate
// that indication here, embedding the newly-created instance as
// the SourceInstance property. See LifecycleIndicationProviderR.mof.
if (_lifecycle_indications_enabled)
{
CIMInstance indicationInstance(
CIMName(
"InstCreation_for_Sample_LifecycleIndicationProviderClass"));
CIMObjectPath path;
path.setNameSpace("root/SampleProvider");
path.setClassName(
"InstCreation_for_Sample_LifecycleIndicationProviderClass");
indicationInstance.setPath(path);
char buffer[32];
sprintf(buffer, "%d", _nextUID++);
indicationInstance.addProperty
(CIMProperty ("IndicationIdentifier",String(buffer)));
CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime ();
indicationInstance.addProperty
(CIMProperty ("IndicationTime", currentDateTime));
indicationInstance.addProperty
(CIMProperty ("SourceInstance",CIMObject(cimInstance)));
_indication_handler->deliver (indicationInstance);
// cout << "LifecycleIndicationProvider::createInstance() sent "
// "InstCreation_for_Sample_LifecycleIndicationProviderClass"
// << endl;
}
}
示例8: _getIndPropertyValue
String IndicationFormatter::_getIndPropertyValue(
const String & specifiedPropertyName,
const String & arrayIndexStr,
const CIMInstance & indication,
const ContentLanguages & contentLangs)
{
PEG_METHOD_ENTER (TRC_IND_FORMATTER,
"IndicationFormatter::_getIndPropertyValue");
CIMInstance indicationInstance = indication.clone();
String propertyName;
Boolean canLocalize = false;
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
Locale locale;
canLocalize = _canLocalize(contentLangs, locale);
#endif
for (Uint32 i=0; i < indicationInstance.getPropertyCount(); i++)
{
CIMProperty property = indicationInstance.getProperty(i);
propertyName = property.getName().getString();
// get specified property value
if (String::equalNoCase(propertyName, specifiedPropertyName))
{
CIMValue propertyValue = property.getValue();
Boolean valueIsNull = propertyValue.isNull();
CIMType type = propertyValue.getType();
if (!valueIsNull)
{
Boolean isArray = propertyValue.isArray();
if (isArray)
{
PEG_METHOD_EXIT();
return (_getArrayValues(propertyValue, arrayIndexStr,
contentLangs));
}
else // value is not an array
{
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
if (canLocalize)
{
if (type == CIMTYPE_DATETIME)
{
CIMDateTime dateTimeValue;
propertyValue.get(dateTimeValue);
PEG_METHOD_EXIT();
return(_localizeDateTime(dateTimeValue, locale));
}
else if (type == CIMTYPE_BOOLEAN)
{
Boolean booleanValue;
propertyValue.get(booleanValue);
PEG_METHOD_EXIT();
return(_localizeBooleanStr(booleanValue, locale));
}
else
{
PEG_METHOD_EXIT();
return (propertyValue.toString());
}
}
else
{
if (type == CIMTYPE_BOOLEAN)
{
PEG_METHOD_EXIT();
return (_getBooleanStr(propertyValue));
}
else
{
PEG_METHOD_EXIT();
return (propertyValue.toString());
}
}
#else
if (type == CIMTYPE_BOOLEAN)
{
PEG_METHOD_EXIT();
return (_getBooleanStr(propertyValue));
}
else
{
PEG_METHOD_EXIT();
return (propertyValue.toString());
}
#endif
}
}
else // value is NULL
{
PEG_METHOD_EXIT();
return ("NULL");
}
//.........这里部分代码省略.........
示例9: _formatDefaultIndicationText
String IndicationFormatter::_formatDefaultIndicationText(
const CIMInstance & indication,
const ContentLanguages & contentLangs)
{
PEG_METHOD_ENTER (TRC_IND_FORMATTER,
"IndicationFormatter::_formatDefaultIndicationText");
CIMInstance indicationInstance = indication.clone();
String propertyName;
String indicationStr;
Uint32 propertyCount = indicationInstance.getPropertyCount();
indicationStr.append("Indication (default format):");
Boolean canLocalize = false;
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
Locale locale;
canLocalize = _canLocalize(contentLangs, locale);
#endif
for (Uint32 i=0; i < propertyCount; i++)
{
CIMProperty property = indicationInstance.getProperty(i);
propertyName = property.getName().getString();
CIMValue propertyValue = property.getValue();
Boolean valueIsNull = propertyValue.isNull();
Boolean isArray = propertyValue.isArray();
indicationStr.append(propertyName);
indicationStr.append(" = ");
CIMType type = propertyValue.getType();
if (!valueIsNull)
{
if (isArray)
{
indicationStr.append(_getArrayValues(propertyValue, "",
contentLangs));
}
else // value is not an array
{
#if defined(PEGASUS_HAS_ICU) && defined(PEGASUS_INDFORMATTER_USE_ICU)
if (canLocalize)
{
if (type == CIMTYPE_DATETIME)
{
CIMDateTime dateTimeValue;
propertyValue.get(dateTimeValue);
indicationStr.append(_localizeDateTime(dateTimeValue,
locale));
}
else if (type == CIMTYPE_BOOLEAN)
{
Boolean booleanValue;
propertyValue.get(booleanValue);
indicationStr.append(_localizeBooleanStr(booleanValue,
locale));
}
else
{
indicationStr.append(propertyValue.toString());
}
}
else
{
if (type == CIMTYPE_BOOLEAN)
{
indicationStr.append(_getBooleanStr(propertyValue));
}
else
{
indicationStr.append(propertyValue.toString());
}
}
#else
if (type == CIMTYPE_BOOLEAN)
{
indicationStr.append(_getBooleanStr(propertyValue));
}
else
{
indicationStr.append(propertyValue.toString());
}
#endif
}
}
else
{
indicationStr.append("NULL");
}
if (i < propertyCount -1)
{
indicationStr.append(", ");
}
propertyName.clear();
}
//.........这里部分代码省略.........