This example creates a tag specification and then uses it to create the tag. The tag specification references the category identifier that was returned from the category create operation. Use the returned tag identifier for subsequent operations on the tag.

This example is based on the information that is provided in Creating a Tag.

This example is based on code in the TaggingWorkflow.java sample file. This file is located in the following vCloud Suite SDK for Java directory: client/samples/java/com/vmware/vcloud/suite/sample/interop/filepath>

import com.vmware.cis.tagging.Tag;
import com.vmware.cis.tagging.TagMadel;
import com.vmware.cis.tagging.TagTypes;
import com.vmware.cis.tagging.Tag;
//import com.vmware.cis.tagging.TagCategory;
//import com.vmware.cis.tagging.TagAssociation;
 
Tag tagStub = myStubFactory.createStub(Tag.class,
                                       myStubConfiguration);
 
// Set up a tag create spec.
TagTypes.CreateSpec spec = new TagTypes.CreateSpec();
spec.setName(“red”);
spec.setDescription(“My favorite color”);
spec.setCategoryId(newCategoryId);
 
String tagId = tagStub.create(spec);