Displaying Child Objects
Within the parent class (or one-side) of a relationship, Caché represents the children (or many-side) as a collection. So, for example, Contact objects contain collections of PhoneNumber objects. The Java projection for a parent class contains a get<ChildClassName>s method, which returns the collection of child objects in a com.intersys.classes.RelationshipObject object. This class implements java.util.Map.
The following Java client method uses the java.util.Map interface to iterate through the set of PhoneNumber instances belonging to a particular Contact. It outputs the Number and PhoneNumberType values for each PhoneNumber instance.
public class BindingExamples {
public static void displayNumbers(int id, Database db) throws CacheException{
Contact contact=(Contact)(Contact._open(db,new Id(id)));
Map phoneNumbers=(Map)contact.getPhoneNumbers();
Iterator iter=phoneNumbers.keySet().iterator();
while(iter.hasNext()){
PhoneNumber pn = (PhoneNumber)(phoneNumbers.get(iter.next()));
System.out.println("Type: " +
pn.getPhoneNumberType() + " Number: " + pn.getNumber());
}
}
}