Managing Resource Extended Attributes
Extending Resource Attributes The ExtendedAttribute property exposed by the Resource class can be used to manage the extended attributes of a resource. This property reads and writes an ArrayList of the ExtendedAttribute objects to deal with a resource’s extended attributes. The ExtendedAttribute object further exposes the relevant properties.
The following example shows how to set a resource’s extended attributes.
1// The path to the documents directory.
2String dataDir = Utils.getDataDir(ExtendedResourceAttributes.class);
3
4Project prj = new Project(dataDir + "project5.mpp");
5
6// Define extended attribute
7ExtendedAttributeDefinition myNumber1 = prj.getExtendedAttributes()
8 .getById((int) ExtendedAttributeTask.Number1);
9if (myNumber1 == null) {
10 myNumber1 = ExtendedAttributeDefinition.createResourceDefinition(ExtendedAttributeResource.Number1, "Age");
11 prj.getExtendedAttributes().add(myNumber1);
12}
13
14// Create extended attribute and set its value
15ExtendedAttribute number1Resource = myNumber1.createExtendedAttribute();
16number1Resource.setNumericValue(BigDecimal.valueOf(30.5345));
17
18// Add a new resource and its extended attribute
19Resource rsc = prj.getResources().add("R1");
20rsc.getExtendedAttributes().add(number1Resource);
21
22prj.save(dataDir + "Project5.xml", SaveFileFormat.XML);
23
24// Display result of conversion.
25System.out.println("Process completed Successfully");