4.0

Table Of Contents
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);
}
}
if (parentType.equals("Planet")) {
if (relationName.equals("OrbitingMoons")) {
Planet parentPlanet =
SolarSystemRepository.getUniqueInstance().getPlanetById(parentId);
if (parentPlanet != null) {
return parentPlanet.getMoons();
}
return null;
}
else {
throw new IndexOutOfBoundsException("Unknown relation name: "
+ relationName);
}
}
else {
return null;
}
}
You defined methods in the IPluginFactory implementation to find objects in the plugged-in technology that
relate to other objects by a certain relation type.
What to do next
Discover whether an object relates to any child objects by a given type of relation.
Discover Whether an Object has Children of a Given Relation Type
You implement the IPluginFactory.hasChildrenInRelation() method to discover whether an object relates
to any children by a given type of relation.
You can implement an if-else statement in the hasChildrenInRelation() method to check for child objects
that relate to a parent by a certain relation type. For example, you can implement a function that uses the
hasChildrenInRelation() method in the solar system example to check whether a Planet object has any moons.
Chapter 7 Developing Plug-Ins
VMware, Inc. 165