4.1

Table Of Contents
Find Objects By Relation Type in the Plugged-In Technology
You can find objects by their relationship to other objects in the plugged-in technology by using the
IPluginFactory.findRelation() method. You can also determine whether an object has any dependent child
objects by using the IPluginFactory.hasChildrenInRelation() method.
The IPluginFactory.findRelation() returns all of the dependent child objects that relate to a parent object by
a certain relation type.
The IPluginFactory.hasChildrenInRelation() method returns HasChildrenResult objects to confirm whether
a parent object has any dependent child objects that relate to it by a given relation type. The possible values of
a HasChildrenResult object are yes, no, or unknown. For information about HasChildrenResult objects, see
“HasChildrenResult Enumeration,” on page 222.
You define the relations between the objects in the plugged-in technology in the vso.xml file for the plug-in.
Prerequisites
n
Set up the factory implementation class.
n
Create a public constructor that implements the IPluginFactory interface.
Procedure
1 Declare the IPluginFactory.findRelation() method to return a java.util.List instance that lists all the
child objects that relate to a parent object by a given relation.
public List findRelation(String parentType, String parentId, String relationName) {
}
2 Write in the logs the type and identifier of the parent object and the name of the relationship that the child
objects have to the parent.
public List findRelation(String parentType, String parentId, String relationName) {
log.debug("findRelation: " + parentType + ", " + parentId + ", " + relationName);
}
3 Call the appropriate methods from the plugged-in technology to obtain lists of child objects that relate to
their parent objects by different types of relations.
The SolarSystemFactory class uses an if-else statement to call the
SolarSystemRepository.getAllPlanets() method to return a list of all of the planets that relate to a
particular star by the OrbitingPlanets relation. The if-else statement also calls Planet.getMoons() to
return a list of all of the moons that relate to a particular planet by the OrbitingMoons relation.
public List findRelation(String parentType, String parentId, String relationName) {
log.debug("findRelation: " + parentType + ", " + parentId + ", " + relationName);
if (parentId == null) {
List<Star> list = new Vector<Star>();
list.add(SolarSystemRepository.getUniqueInstance().getStar());
return list;
}
if (parentType.equals("Star")) {
if (relationName.equals("OrbitingPlanets")) {
return SolarSystemRepository.getUniqueInstance().getAllPlanets();
}
else {
throw new IndexOutOfBoundsException("Unknown relation name: "
+ relationName);
}
}
Chapter 7 Developing Plug-Ins
VMware, Inc. 161