/*This code was generated using the UMPLE modeling language! Date of generation: 2008/07/31 09:26:55*/ /*This class drives: Person, Adoption, Person*/ package Geneology.core; import java.util.*; import java.sql.Date; import Geneology.*; import Geneology.json.*; public class Union { //Class datatypes private String placeOfMarriage; private String dateOfMarriage; private String dateOfDivorce; //Class association variables private List parents; private List adoptions; private List childs; //Registry of our system. GeneologyRegistry registry = GeneologyRegistry.getInstance(); //Constructor public Union(String aPlaceOfMarriage, String aDateOfMarriage, String aDateOfDivorce) { placeOfMarriage = aPlaceOfMarriage; dateOfMarriage = aDateOfMarriage; dateOfDivorce = aDateOfDivorce; parents = new ArrayList(); registry.add(parents); adoptions = new ArrayList(); registry.add(adoptions); childs = new ArrayList(); registry.add(childs); } public boolean setPlaceOfMarriage(String aPlaceOfMarriage) { placeOfMarriage = aPlaceOfMarriage; return true; } public boolean setDateOfMarriage(String aDateOfMarriage) { dateOfMarriage = aDateOfMarriage; return true; } public boolean setDateOfDivorce(String aDateOfDivorce) { dateOfDivorce = aDateOfDivorce; return true; } public String getPlaceOfMarriage() { return placeOfMarriage; } public String getDateOfMarriage() { return dateOfMarriage; } public String getDateOfDivorce() { return dateOfDivorce; } public List getParents() { return parents; } public List getAdoptions() { return adoptions; } public List getChilds() { return childs; } public Person addParent(String aName, String aSex, String aPlaceOfBirth, String aDateOfBirth, String aPlaceOfDeath, String aDateOfDeath) throws Exception { if (!(parents.size() == 2)) { Person newPerson; newPerson = new Person(aName, aSex, aPlaceOfBirth, aDateOfBirth, aPlaceOfDeath, aDateOfDeath); if (!parents.contains(newPerson)) { parents.add(newPerson); registry.add(newPerson); } return newPerson; } else throw new Exception("No more space in the set."); } public Person addParent(Person aParent) throws Exception { if (parents.size() < 2) { if (!parents.contains(aParent)) parents.add(aParent); return aParent; } else throw new Exception("No more space in the set."); } public Adoption addAdoption(String aDateOfAdoption) { Adoption newAdoption; newAdoption = new Adoption(aDateOfAdoption); if (!adoptions.contains(newAdoption)) { registry.add(newAdoption); adoptions.add(newAdoption); } return newAdoption; } public Adoption addAdoption(Adoption aAdoption) { if (!adoptions.contains(aAdoption)) adoptions.add(aAdoption); return aAdoption; } public Person addChild(String aName, String aSex, String aPlaceOfBirth, String aDateOfBirth, String aPlaceOfDeath, String aDateOfDeath) throws Exception { Person newPerson; newPerson = new Person(aName, aSex, aPlaceOfBirth, aDateOfBirth, aPlaceOfDeath, aDateOfDeath); if (!childs.contains(newPerson)) { registry.add(newPerson); childs.add(newPerson); } return newPerson; } public Person addChild(Person aChild) { if (!childs.contains(aChild)) childs.add(aChild); return aChild; } public void delete() { //Delete all many ends first. for (Person aPerson : parents) { aPerson.delete(); } parents.clear(); //Delete all many ends first. for (Adoption aAdoption : adoptions) { aAdoption.delete(); } adoptions.clear(); //Delete all many ends first. for (Person aPerson : childs) { aPerson.delete(); } childs.clear(); } public void deleteParent(Person aPerson) { if (parents.contains(aPerson)) { parents.remove(aPerson); //registry.removeObj(registry.getKey(aPerson)); } else //Throw an UmpleException .. to be implemented. { } } public void deleteAdoption(Adoption aAdoption) { if (adoptions.contains(aAdoption)) { adoptions.remove(aAdoption); //registry.removeObj(registry.getKey(aAdoption)); } else //Throw an UmpleException .. to be implemented. { } } public void deleteChild(Person aPerson) { if (childs.contains(aPerson)) { childs.remove(aPerson); //registry.removeObj(registry.getKey(aPerson)); } else //Throw an UmpleException .. to be implemented. { } } public boolean areManyEndsNull() { if (adoptions.size() == 0 && childs.size() == 0) { return true; } else return false; } /*********************************** * Returns the attribute list along with the * class ID in JSON format. ***********************************/ public JSONObject getAttributes() throws JSONException { JSONObject obj = new JSONObject(); obj.put("CLASS_ID", registry.getKey(this)); obj.put("placeOfMarriage", getPlaceOfMarriage()); obj.put("dateOfMarriage", getDateOfMarriage()); obj.put("dateOfDivorce", getDateOfDivorce()); return obj; } }