4.1

Table Of Contents
Prerequisites
n
Set up the factory implementation class.
n
Create a public constructor that implements the IPluginFactory interface.
Procedure
1 Declare the IPluginFactory.find() method to find objects of the type java.lang.Object.
public Object find(String type, String id) {
}
2 Write in the logs the type and identifier of the objects that the plug-in factory finds.
public Object find(String type, String id) {
log.debug("find: " + type + ", " + id);
}
3 Call the appropriate methods from the plugged-in technology to obtain the identifiers of objects of each
different type.
The SolarSystemFactory class uses an if-else statement to call the SolarSystemRepository.getStar(),
getPlanetById(), and getMoonById() methods.
public Object find(String type, String id) {
log.debug("find: " + type + ", " + id);
if (type.equals("Star")) {
return SolarSystemRepository.getUniqueInstance().getStar();
}
else if (type.equals("Planet")) {
return SolarSystemRepository.getUniqueInstance().getPlanetById(id);
}
else if (type.equals("Moon")) {
return SolarSystemRepository.getUniqueInstance().getMoonById(id);
}
else if (type.equals("Galaxy")) {
return null; // No object for galaxy defined yet
}
else {
throw new IndexOutOfBoundsException("Type " + type + "
+ unknown for plugin SolarSystem");
}
}
You implemented the IPluginFactory.find() method to find objects by identifier in the plugged-in
technology.
What to do next
Define methods in the plug-in factory to find all objects of a certain type.
Find Objects in the Plugged-In Technology By a Query
You can find objects in the plugged-in technology by defining a query in the IPluginFactory.findAll()
method.
The findAll() method takes the object type and a query as parameters. You can define the syntax of the query
in the IPluginFactory implementation to narrow the search. If you do not define query syntax, findAll()
returns all objects of the specified type. You can ignore the query and find objects by type, ignore the type and
find objects by query, or find objects by both query and type.
Chapter 7 Developing Plug-Ins
VMware, Inc. 159