SourceForge.net Logo

How to set/retrieve reference values?

The way you retrieve the objects of a reference is very similar to the way you retrieve attribute values. refGetValue() returns a collection of all referenced objects. The collection operations add(), remove(), iterator() allow you to process the objects contained in the collection.

The following example shows how to retrieve referenced objects.

Example 6-6. Retrieve group instances of the reference group of a Person instance

// retrieve all group instances
Collection groups = (Collection)person.refGetValue(
  "org:openmdx:example:lab1:Person:group"
);

// in case the reference is stored as attribute and is indexed,
// the group instance at the specified index can be retrieved like this
List groups = (List)person.refGetValue(
  "org:openmdx:example:lab1:Person:group"
);
Group group = groups.get(index);

The following example shows how to add a new object to a given reference.

Example 6-7. Add a group instance to the reference group of a Person instance

// add a specified group instance
Collection groups = (Collection)person.refGetValue(
  "org:openmdx:example:lab1:Person:group"
);
groups.add(group);

// in case the reference is stored as attribute and is indexed,
// a group instance can be added at a specified index
List groups = (List)person.refGetValue(
  "org:openmdx:example:lab1:Person:group"
);
groups.add(index, group);

The following example shows how to remove an existing object.

Example 6-8. Remove a group instance from the reference group of a Person instance

// remove a specified group instance
Collection groups = (Collection)person.refGetValue(
  "org:openmdx:example:lab1:Person:group"
);
groups.remove(group);

// in case the reference is stored as attribute and is indexed,
// a group instance can be remove at a specified index
List groups = (List)person.refGetValue(
  "org:openmdx:example:lab1:Person:group"
);
groups.remove(index);

Since reference names must be unique within the scope of a class, you can also use just the reference name itself (e.g. group) instead of using the fully qualified reference name (e.g. org:openmdx:example:lab1:Person:group).

Since qualifiers are an extension to the MOF specification, openMDX must define the a mapping of qualifiers to JMI interfaces. openMDX provides additional operations which deal with qualifiers. Please note that these operations are extensions and therefore not JMI compliant.

The openMDX RefObject_1_0 interface extends the JMI RefObject interface which defines the additional operations:

  • public void refGetValue(String featureName, Object qualifier)

  • public void refAddValue(String featureName, Object qualifier, Object value)

  • public void refRemoveValue(String featureName, Object qualifier)