/*This code was generated using the UMPLE modeling language!*/

package Geneology;

import java.sql.Time;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Iterator;
import Geneology.json.*;
import Geneology.core.*;

public class GeneologyFacade {
  // Singleton instance.
  private static GeneologyFacade theInstance;

  //System registry.
  GeneologyRegistry registry = GeneologyRegistry.getInstance();

  /**
   * Dummy constructor
   */
  private GeneologyFacade() {
  }

  /**
   * Returns the only instance of the Facade.
   * 
   * @return
   */
  public static GeneologyFacade getInstance() {
    if (theInstance == null)
      theInstance = new GeneologyFacade();
    return theInstance;
  }

  public int constructUnion(String aPlaceOfMarriage, String aDateOfMarriage,
    String aDateOfDivorce) {
    return registry.add(new Union(aPlaceOfMarriage, aDateOfMarriage,
      aDateOfDivorce));
  }

  public JSONObject constructUnionJSON(String aPlaceOfMarriage,
    String aDateOfMarriage, String aDateOfDivorce) throws JSONException {
    Union contextObj =
      new Union(aPlaceOfMarriage, aDateOfMarriage, aDateOfDivorce);
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public boolean setPlaceOfMarriageInUnion(int context, String aPlaceOfMarriage) {
    return ((Union) registry.getValue(context))
      .setPlaceOfMarriage(aPlaceOfMarriage);
  }

  public boolean setDateOfMarriageInUnion(int context, String aDateOfMarriage) {
    return ((Union) registry.getValue(context))
      .setDateOfMarriage(aDateOfMarriage);
  }

  public boolean setDateOfDivorceInUnion(int context, String aDateOfDivorce) {
    return ((Union) registry.getValue(context))
      .setDateOfDivorce(aDateOfDivorce);
  }

  public String getPlaceOfMarriageFromUnion(int context) {
    return ((Union) registry.getValue(context)).getPlaceOfMarriage();
  }

  public String getDateOfMarriageFromUnion(int context) {
    return ((Union) registry.getValue(context)).getDateOfMarriage();
  }

  public String getDateOfDivorceFromUnion(int context) {
    return ((Union) registry.getValue(context)).getDateOfDivorce();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getParentsFromUnion(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Person obj : ((Union) registry.getValue(context)).getParents()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getAdoptionsFromUnion(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Adoption obj : ((Union) registry.getValue(context)).getAdoptions()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getChildsFromUnion(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Person obj : ((Union) registry.getValue(context)).getChilds()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  public int addParentToUnion(int context, String aName, String aSex,
    String aPlaceOfBirth, String aDateOfBirth, String aPlaceOfDeath,
    String aDateOfDeath) throws Exception {
    return registry.getKey(((Union) registry.getValue(context)).addParent(
      aName, aSex, aPlaceOfBirth, aDateOfBirth, aPlaceOfDeath, aDateOfDeath));
  }

  public JSONObject addParentToUnionJSON(int context, String aName,
    String aSex, String aPlaceOfBirth, String aDateOfBirth,
    String aPlaceOfDeath, String aDateOfDeath) throws JSONException, Exception {
    return ((Union) registry.getValue(context)).addParent(aName, aSex,
      aPlaceOfBirth, aDateOfBirth, aPlaceOfDeath, aDateOfDeath).getAttributes();
  }

  public int addParentToUnionOnly(int context, int aParent) throws Exception {
    return registry.getKey(((Union) registry.getValue(context))
      .addParent((Person) registry.getValue(aParent)));
  }

  public JSONObject addParentToUnionOnlyJSON(int context, int aParent)
    throws JSONException, Exception {
    return ((Union) registry.getValue(context)).addParent(
      (Person) registry.getValue(aParent)).getAttributes();
  }

  public int addAdoptionToUnion(int context, String aDateOfAdoption)
    throws Exception {
    return registry.getKey(((Union) registry.getValue(context))
      .addAdoption(aDateOfAdoption));
  }

  public JSONObject addAdoptionToUnionJSON(int context, String aDateOfAdoption)
    throws JSONException, Exception {
    return ((Union) registry.getValue(context)).addAdoption(aDateOfAdoption)
      .getAttributes();
  }

  public int addAdoptionToUnionOnly(int context, int aAdoption)
    throws Exception {
    return registry.getKey(((Union) registry.getValue(context))
      .addAdoption((Adoption) registry.getValue(aAdoption)));
  }

  public JSONObject addAdoptionToUnionOnlyJSON(int context, int aAdoption)
    throws JSONException, Exception {
    return ((Union) registry.getValue(context)).addAdoption(
      (Adoption) registry.getValue(aAdoption)).getAttributes();
  }

  public int addChildToUnion(int context, String aName, String aSex,
    String aPlaceOfBirth, String aDateOfBirth, String aPlaceOfDeath,
    String aDateOfDeath) throws Exception {
    return registry.getKey(((Union) registry.getValue(context)).addChild(aName,
      aSex, aPlaceOfBirth, aDateOfBirth, aPlaceOfDeath, aDateOfDeath));
  }

  public JSONObject addChildToUnionJSON(int context, String aName, String aSex,
    String aPlaceOfBirth, String aDateOfBirth, String aPlaceOfDeath,
    String aDateOfDeath) throws JSONException, Exception {
    return ((Union) registry.getValue(context)).addChild(aName, aSex,
      aPlaceOfBirth, aDateOfBirth, aPlaceOfDeath, aDateOfDeath).getAttributes();
  }

  public int addChildToUnionOnly(int context, int aChild) throws Exception {
    return registry.getKey(((Union) registry.getValue(context))
      .addChild((Person) registry.getValue(aChild)));
  }

  public JSONObject addChildToUnionOnlyJSON(int context, int aChild)
    throws JSONException, Exception {
    return ((Union) registry.getValue(context)).addChild(
      (Person) registry.getValue(aChild)).getAttributes();
  }

  public void deleteUnion(int context) {
    ((Union) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteParentFromUnion(int context, int aPerson) {
    ((Union) registry.getValue(context)).deleteParent((Person) registry
      .getValue(aPerson));
  }

  public void deleteAdoptionFromUnion(int context, int aAdoption) {
    ((Union) registry.getValue(context)).deleteAdoption((Adoption) registry
      .getValue(aAdoption));
  }

  public void deleteChildFromUnion(int context, int aPerson) {
    ((Union) registry.getValue(context)).deleteChild((Person) registry
      .getValue(aPerson));
  }

  public JSONObject getAttributesOfUnion(int context) throws JSONException {
    return ((Union) registry.getValue(context)).getAttributes();
  }

  public int constructAdoption(String aDateOfAdoption) {
    return registry.add(new Adoption(aDateOfAdoption));
  }

  public JSONObject constructAdoptionJSON(String aDateOfAdoption)
    throws JSONException {
    Adoption contextObj = new Adoption(aDateOfAdoption);
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public boolean setDateOfAdoptionInAdoption(int context, String aDateOfAdoption) {
    return ((Adoption) registry.getValue(context))
      .setDateOfAdoption(aDateOfAdoption);
  }

  public String getDateOfAdoptionFromAdoption(int context) {
    return ((Adoption) registry.getValue(context)).getDateOfAdoption();
  }

  public int getAdoptiveParentsFromAdoption(int context) {
    return registry.getKey(((Adoption) registry.getValue(context))
      .getAdoptiveParents());
  }

  public JSONObject getAdoptiveParentsFromAdoptionJSON(int context)
    throws JSONException {
    return ((Adoption) registry.getValue(context)).getAdoptiveParents()
      .getAttributes();
  }

  public int getAdoptedChildFromAdoption(int context) {
    return registry.getKey(((Adoption) registry.getValue(context))
      .getAdoptedChild());
  }

  public JSONObject getAdoptedChildFromAdoptionJSON(int context)
    throws JSONException {
    return ((Adoption) registry.getValue(context)).getAdoptedChild()
      .getAttributes();
  }

  public void setAdoptiveParentsInAdoption(int context, int aAdoptiveParents)
    throws Exception {
    ((Adoption) registry.getValue(context)).setAdoptiveParents((Union) registry
      .getValue(aAdoptiveParents));
  }

  public void setAdoptedChildInAdoption(int context, int aAdoptedChild)
    throws Exception {
    ((Adoption) registry.getValue(context)).setAdoptedChild((Person) registry
      .getValue(aAdoptedChild));
  }

  public void deleteAdoption(int context) {
    ((Adoption) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteAdoptiveParentsFromAdoption(int context, int aUnion) {
    ((Adoption) registry.getValue(context))
      .deleteAdoptiveParents((Union) registry.getValue(aUnion));
  }

  public void deleteAdoptedChildFromAdoption(int context, int aPerson) {
    ((Adoption) registry.getValue(context))
      .deleteAdoptedChild((Person) registry.getValue(aPerson));
  }

  public JSONObject getAttributesOfAdoption(int context) throws JSONException {
    return ((Adoption) registry.getValue(context)).getAttributes();
  }

  public int constructPerson(String aName, String aSex, String aPlaceOfBirth,
    String aDateOfBirth, String aPlaceOfDeath, String aDateOfDeath)
    throws Exception {
    return registry.add(new Person(aName, aSex, aPlaceOfBirth, aDateOfBirth,
      aPlaceOfDeath, aDateOfDeath));
  }

  public JSONObject constructPersonJSON(String aName, String aSex,
    String aPlaceOfBirth, String aDateOfBirth, String aPlaceOfDeath,
    String aDateOfDeath) throws JSONException, Exception {
    Person contextObj =
      new Person(aName, aSex, aPlaceOfBirth, aDateOfBirth, aPlaceOfDeath,
        aDateOfDeath);
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public boolean setNameInPerson(int context, String aName) {
    return ((Person) registry.getValue(context)).setName(aName);
  }

  public boolean setSexInPerson(int context, String aSex) {
    return ((Person) registry.getValue(context)).setSex(aSex);
  }

  public boolean setPlaceOfBirthInPerson(int context, String aPlaceOfBirth) {
    return ((Person) registry.getValue(context)).setPlaceOfBirth(aPlaceOfBirth);
  }

  public boolean setDateOfBirthInPerson(int context, String aDateOfBirth) {
    return ((Person) registry.getValue(context)).setDateOfBirth(aDateOfBirth);
  }

  public boolean setPlaceOfDeathInPerson(int context, String aPlaceOfDeath) {
    return ((Person) registry.getValue(context)).setPlaceOfDeath(aPlaceOfDeath);
  }

  public boolean setDateOfDeathInPerson(int context, String aDateOfDeath) {
    return ((Person) registry.getValue(context)).setDateOfDeath(aDateOfDeath);
  }

  public String getNameFromPerson(int context) {
    return ((Person) registry.getValue(context)).getName();
  }

  public String getSexFromPerson(int context) {
    return ((Person) registry.getValue(context)).getSex();
  }

  public String getPlaceOfBirthFromPerson(int context) {
    return ((Person) registry.getValue(context)).getPlaceOfBirth();
  }

  public String getDateOfBirthFromPerson(int context) {
    return ((Person) registry.getValue(context)).getDateOfBirth();
  }

  public String getPlaceOfDeathFromPerson(int context) {
    return ((Person) registry.getValue(context)).getPlaceOfDeath();
  }

  public String getDateOfDeathFromPerson(int context) {
    return ((Person) registry.getValue(context)).getDateOfDeath();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getUnionsFromPerson(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Union obj : ((Person) registry.getValue(context)).getUnions()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getAdoptionsFromPerson(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Adoption obj : ((Person) registry.getValue(context)).getAdoptions()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  public int getParentsFromPerson(int context) {
    return registry.getKey(((Person) registry.getValue(context)).getParents());
  }

  public JSONObject getParentsFromPersonJSON(int context) throws JSONException {
    return ((Person) registry.getValue(context)).getParents().getAttributes();
  }

  public int addUnionToPerson(int context, String aPlaceOfMarriage,
    String aDateOfMarriage, String aDateOfDivorce) throws Exception {
    return registry.getKey(((Person) registry.getValue(context)).addUnion(
      aPlaceOfMarriage, aDateOfMarriage, aDateOfDivorce));
  }

  public JSONObject addUnionToPersonJSON(int context, String aPlaceOfMarriage,
    String aDateOfMarriage, String aDateOfDivorce) throws JSONException,
    Exception {
    return ((Person) registry.getValue(context)).addUnion(aPlaceOfMarriage,
      aDateOfMarriage, aDateOfDivorce).getAttributes();
  }

  public int addUnionToPersonOnly(int context, int aUnion) throws Exception {
    return registry.getKey(((Person) registry.getValue(context))
      .addUnion((Union) registry.getValue(aUnion)));
  }

  public JSONObject addUnionToPersonOnlyJSON(int context, int aUnion)
    throws JSONException, Exception {
    return ((Person) registry.getValue(context)).addUnion(
      (Union) registry.getValue(aUnion)).getAttributes();
  }

  public int addAdoptionToPerson(int context, String aDateOfAdoption)
    throws Exception {
    return registry.getKey(((Person) registry.getValue(context))
      .addAdoption(aDateOfAdoption));
  }

  public JSONObject addAdoptionToPersonJSON(int context, String aDateOfAdoption)
    throws JSONException, Exception {
    return ((Person) registry.getValue(context)).addAdoption(aDateOfAdoption)
      .getAttributes();
  }

  public int addAdoptionToPersonOnly(int context, int aAdoption)
    throws Exception {
    return registry.getKey(((Person) registry.getValue(context))
      .addAdoption((Adoption) registry.getValue(aAdoption)));
  }

  public JSONObject addAdoptionToPersonOnlyJSON(int context, int aAdoption)
    throws JSONException, Exception {
    return ((Person) registry.getValue(context)).addAdoption(
      (Adoption) registry.getValue(aAdoption)).getAttributes();
  }

  public void setParentsInPerson(int context, int aParents) throws Exception {
    ((Person) registry.getValue(context)).setParents((Union) registry
      .getValue(aParents));
  }

  public void deletePerson(int context) {
    ((Person) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteUnionFromPerson(int context, int aUnion) {
    ((Person) registry.getValue(context)).deleteUnion((Union) registry
      .getValue(aUnion));
  }

  public void deleteAdoptionFromPerson(int context, int aAdoption) {
    ((Person) registry.getValue(context)).deleteAdoption((Adoption) registry
      .getValue(aAdoption));
  }

  public void deleteParentsFromPerson(int context, int aUnion) {
    ((Person) registry.getValue(context)).deleteParents((Union) registry
      .getValue(aUnion));
  }

  public JSONObject getAttributesOfPerson(int context) throws JSONException {
    return ((Person) registry.getValue(context)).getAttributes();
  }
}