import java.util.ArrayList;
import java.util.List;

import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
import org.apache.myfaces.trinidad.model.RowKeySet;
import org.apache.myfaces.trinidad.model.RowKeySetTreeImpl;
import org.apache.myfaces.trinidad.model.TreeModel;


/**
 * @author abhishek
 */
public class Test {
    private static TreeModel treeModel;

    public static void main(String args[]) {
		Person john = new Person("John Smith");
		Person kim = new Person("Kim Smith");
		Person tom = new Person("Tom Smith");
		Person ira = new Person("Ira Wickrememsinghe");
		Person mallika = new Person("Mallika Wickremesinghe");

		john.getList().add(kim);
		john.getList().add(tom);
		ira.getList().add(mallika);

		// create the list of root nodes:
		List<Person> people = new ArrayList<Person>();
		people.add(john);
		people.add(ira);
		
		//create tree model and override isContainer and getChildData
		treeModel = new ChildPropertyTreeModel(people, "list") {
		    public boolean isContainer() {		
				return !((Person) getRowData()).getList().isEmpty();
		    }	   
		    
		    public Object getChildData(Object parent){
				Person p = (Person) parent;
				if(p.getList().isEmpty()){
				    return null;
				}else{
				    return p.getList();
				}
			    
		    }
		};
		
		treeModel.setRowKey(null);
		RowKeySet ks = new RowKeySetTreeImpl();	
		ks.setCollectionModel(treeModel);
		ks.addAll();	

		for (Object k : ks) {
		    treeModel.setRowKey(k);
		    Person person = (Person) treeModel.getRowData();
		    System.out.println("person name is: " + person.getName());
		}

    }

}

class Person {
    private String name;
    private List<Person> list = new ArrayList<Person>();
    
    public Person(String name) {
	this.name = name;
    }

    public String getName() {
	return name;
    }  

    public List<Person> getList() {
        return list;
    }
    
}