Naked Objects
Appendix A: Getting startedThe Complete Code | |
The resultant three classes are as follows, and should be saved in the project directory: Project.java import java.util.Enumeration; import org.nakedobjects.object.collection.InternalCollection; import org.nakedobjects.object.AbstractNakedObject; import org.nakedobjects.object.Title; import org.nakedobjects.object.control.About; import org.nakedobjects.object.control.ActionAbout; import org.nakedobjects.object.value.Case; import org.nakedobjects.object.value.TextString; public class Project extends AbstractNakedObject { private final TextString name = new TextString(); private final InternalCollection roles = new InternalCollection(Role.class, this); public TextString getName() { return name; } public InternalCollection getRoles() { return roles; } public Role actionAddProjectLeader() { Role projectLeader = (Role)createInstance(Role.class); projectLeader.getName().setValue("Project Leader"); roles.add(projectLeader); return projectLeader; } public About aboutActionAddProjectLeader(){ Enumeration e = getRoles().elements(); while(e.hasMoreElements()){ Role role = (Role)e.nextElement(); if(role.getName().contains("project leader", Case.INSENSITIVE)){ return ActionAbout.DISABLE; } } return ActionAbout.ENABLE; } public Title title() { return name.title(); } } Role.java import org.nakedobjects.object.AbstractNakedObject; import org.nakedobjects.object.Title; import org.nakedobjects.object.value.TextString; public class Role extends AbstractNakedObject { private final TextString name = new TextString(); private Employee employee; public TextString getName() { return name; } public Employee getEmployee() { resolve(employee); return employee; } public void setEmployee(Employee employee) { this.employee = employee; objectChanged(); } public Title title() { return name.title(); } } Employee.java import org.nakedobjects.object.AbstractNakedObject; import org.nakedobjects.object.Title; import org.nakedobjects.object.value.TextString; public class Employee extends AbstractNakedObject { private final TextString name = new TextString(); public TextString getName() { return name; } public Title title() { return name.title(); } }
|
|
Copyright (c) 2002 nakedobjects.org You may print this document for your own personal use, or you may copy it in electronic form for access within your organisation, provided this notice is preserved. |