IBM Content Manager, Version 8.5      Supports:  Oracle, DB2, C++, Java

Setting and retrieving item attribute values

The example demonstrates how to set and retrieve item attribute values.

Example: Java™

Attribute values are stored and retrieved as java.lang.Objects. To set or retrieve attribute values, use the DDO setData and the getData() methods respectively. Set the value by using an object with the type corresponds to the attribute type. Example:
ddo.setData(ddo.dataId(DKConstant.DK_CM_NAMESPACE_ATTR,
     nameOfAttrStr),valueObj);
Object obj = ddo.getData(ddo.dataId(DK_CM_NAMESPACE_ATTR,nameOfAttrStr));
The preceding statement sets the attribute value to the value that is passed in as a java.lang.Object valueObj. The nameOfAttrStr is the string name of the attribute. This attribute was defined and specified in the item type when the item type of this DDO was defined. valueObj is the value you must set and it must be of the correct type for this attribute.

Example: C++

When setting values for individual attributes, use the individual attribute definition name. To access attributes that belong to an attribute group, use this format: <Attribute Group Name>.<Attribute Name>. Example:
//The code snippet below shows the value of the character attribute
//"book_title" for the item represented by the DDO ddoDocument is set to
//the value "Effective C++"
ddoDocument->setData(ddoDocument->dataId(DK_CM_NAMESPACE_ATTR,
                    DKString("book_title")),DKString("Effective C++"));
//The code snippet below shows the value of the integer attribute 
//"book_num_pages" for the item represented
//by the DDO ddoDocument is set to the value "250"
ddoDocument->setData(ddoDocument->dataId(DK_CM_NAMESPACE_ATTR,
                      DKString("book_num_pages")),(long)250);
//This code snippet shows how the value of the "book_title" attribute of the
//item represented by the DDO ddoDocument is retrieved into the "title" 
//string variable.
DKString title =(DKString) ddoDocument->getData(ddoDocument->
   dataId(DK_CM_NAMESPACE_ATTR,DKString("book_title")));


Feedback

Last updated: December 2013
dcmcm073.htm

© Copyright IBM Corporation 2013.