/*This code was generated using the UMPLE modeling language!*/

package Elevator;

import java.sql.Time;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Iterator;
import Elevator.json.*;
import Elevator.core.*;
import Elevator.core.Buttons.*;

public class ElevatorFacade {
  // Singleton instance.
  private static ElevatorFacade theInstance;

  //System registry.
  ElevatorRegistry registry = ElevatorRegistry.getInstance();

  /**
   * Dummy constructor
   */
  private ElevatorFacade() {
  }

  /**
   * Returns the only instance of the Facade.
   * 
   * @return
   */
  public static ElevatorFacade getInstance() {
    if (theInstance == null)
      theInstance = new ElevatorFacade();
    return theInstance;
  }

  public int constructCloseDoorButton(Boolean aLightOn, int aElevator) {
    return registry.add(new CloseDoorButton(aLightOn, (Elevator) registry
      .getValue(aElevator)));
  }

  public JSONObject constructCloseDoorButtonJSON(Boolean aLightOn, int aElevator)
    throws JSONException {
    CloseDoorButton contextObj =
      new CloseDoorButton(aLightOn, (Elevator) registry.getValue(aElevator));
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public int getElevatorFromCloseDoorButton(int context) {
    return registry.getKey(((CloseDoorButton) registry.getValue(context))
      .getElevator());
  }

  public JSONObject getElevatorFromCloseDoorButtonJSON(int context)
    throws JSONException {
    return ((CloseDoorButton) registry.getValue(context)).getElevator()
      .getAttributes();
  }

  public void setElevatorInCloseDoorButton(int context, int aElevator)
    throws Exception {
    ((CloseDoorButton) registry.getValue(context))
      .setElevator((Elevator) registry.getValue(aElevator));
  }

  public void deleteCloseDoorButton(int context) {
    ((CloseDoorButton) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public JSONObject getAttributesOfCloseDoorButton(int context)
    throws JSONException {
    return ((CloseDoorButton) registry.getValue(context)).getAttributes();
  }

  public int constructButton(Boolean aLightOn) {
    return registry.add(new Button(aLightOn));
  }

  public JSONObject constructButtonJSON(Boolean aLightOn) throws JSONException {
    Button contextObj = new Button(aLightOn);
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public boolean setLightOnInButton(int context, Boolean aLightOn) {
    return ((Button) registry.getValue(context)).setLightOn(aLightOn);
  }

  public Boolean getLightOnFromButton(int context) {
    return ((Button) registry.getValue(context)).getLightOn();
  }

  public void deleteButton(int context) {
    ((Button) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public JSONObject getAttributesOfButton(int context) throws JSONException {
    return ((Button) registry.getValue(context)).getAttributes();
  }

  public int constructFloorNumberDisplay(int aFloor) {
    return registry.add(new FloorNumberDisplay((Floor) registry
      .getValue(aFloor)));
  }

  public JSONObject constructFloorNumberDisplayJSON(int aFloor)
    throws JSONException {
    FloorNumberDisplay contextObj =
      new FloorNumberDisplay((Floor) registry.getValue(aFloor));
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public int getFloorFromFloorNumberDisplay(int context) {
    return registry.getKey(((FloorNumberDisplay) registry.getValue(context))
      .getFloor());
  }

  public JSONObject getFloorFromFloorNumberDisplayJSON(int context)
    throws JSONException {
    return ((FloorNumberDisplay) registry.getValue(context)).getFloor()
      .getAttributes();
  }

  public void setFloorInFloorNumberDisplay(int context, int aFloor)
    throws Exception {
    ((FloorNumberDisplay) registry.getValue(context)).setFloor((Floor) registry
      .getValue(aFloor));
  }

  public void deleteFloorNumberDisplay(int context) {
    ((FloorNumberDisplay) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public JSONObject getAttributesOfFloorNumberDisplay(int context)
    throws JSONException {
    return ((FloorNumberDisplay) registry.getValue(context)).getAttributes();
  }

  public int constructFullSystem() {
    return registry.add(new FullSystem());
  }

  public JSONObject constructFullSystemJSON() throws JSONException {
    FullSystem contextObj = new FullSystem();
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getElevatorsFromFullSystem(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Elevator obj : ((FullSystem) registry.getValue(context))
      .getElevators()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  public int addElevatorToFullSystem(int context, String aIdentifier,
    String aState, String aDirectionOfMovement, int aFullSystem,
    int aCloseDoorButton, int aOpenDoorButton) throws Exception {
    return registry.getKey(((FullSystem) registry.getValue(context))
      .addElevator(aIdentifier, aState, aDirectionOfMovement,
        (FullSystem) registry.getValue(aFullSystem), (CloseDoorButton) registry
          .getValue(aCloseDoorButton), (OpenDoorButton) registry
          .getValue(aOpenDoorButton)));
  }

  public JSONObject addElevatorToFullSystemJSON(int context,
    String aIdentifier, String aState, String aDirectionOfMovement,
    int aFullSystem, int aCloseDoorButton, int aOpenDoorButton)
    throws JSONException, Exception {
    return ((FullSystem) registry.getValue(context)).addElevator(aIdentifier,
      aState, aDirectionOfMovement,
      (FullSystem) registry.getValue(aFullSystem),
      (CloseDoorButton) registry.getValue(aCloseDoorButton),
      (OpenDoorButton) registry.getValue(aOpenDoorButton)).getAttributes();
  }

  public int addElevatorToFullSystemOnly(int context, int aElevator)
    throws Exception {
    return registry.getKey(((FullSystem) registry.getValue(context))
      .addElevator((Elevator) registry.getValue(aElevator)));
  }

  public JSONObject addElevatorToFullSystemOnlyJSON(int context, int aElevator)
    throws JSONException, Exception {
    return ((FullSystem) registry.getValue(context)).addElevator(
      (Elevator) registry.getValue(aElevator)).getAttributes();
  }

  public void deleteFullSystem(int context) {
    ((FullSystem) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteElevatorFromFullSystem(int context, int aElevator) {
    ((FullSystem) registry.getValue(context))
      .deleteElevator((Elevator) registry.getValue(aElevator));
  }

  public JSONObject getAttributesOfFullSystem(int context) throws JSONException {
    return ((FullSystem) registry.getValue(context)).getAttributes();
  }

  public int constructDownCallButton(Boolean aLightOn,
    ArrayList<Elevator> elevators) {
    return registry.add(new DownCallButton(aLightOn, elevators));
  }

  public JSONObject constructDownCallButtonJSON(Boolean aLightOn,
    ArrayList<Elevator> elevators) throws JSONException {
    DownCallButton contextObj = new DownCallButton(aLightOn, elevators);
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getElevatorsFromDownCallButton(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Elevator obj : ((DownCallButton) registry.getValue(context))
      .getElevators()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  public int addElevatorToDownCallButton(int context, String aIdentifier,
    String aState, String aDirectionOfMovement, int aFullSystem,
    int aCloseDoorButton, int aOpenDoorButton) throws Exception {
    return registry.getKey(((DownCallButton) registry.getValue(context))
      .addElevator(aIdentifier, aState, aDirectionOfMovement,
        (FullSystem) registry.getValue(aFullSystem), (CloseDoorButton) registry
          .getValue(aCloseDoorButton), (OpenDoorButton) registry
          .getValue(aOpenDoorButton)));
  }

  public JSONObject addElevatorToDownCallButtonJSON(int context,
    String aIdentifier, String aState, String aDirectionOfMovement,
    int aFullSystem, int aCloseDoorButton, int aOpenDoorButton)
    throws JSONException, Exception {
    return ((DownCallButton) registry.getValue(context)).addElevator(
      aIdentifier, aState, aDirectionOfMovement,
      (FullSystem) registry.getValue(aFullSystem),
      (CloseDoorButton) registry.getValue(aCloseDoorButton),
      (OpenDoorButton) registry.getValue(aOpenDoorButton)).getAttributes();
  }

  public int addElevatorToDownCallButtonOnly(int context, int aElevator)
    throws Exception {
    return registry.getKey(((DownCallButton) registry.getValue(context))
      .addElevator((Elevator) registry.getValue(aElevator)));
  }

  public JSONObject addElevatorToDownCallButtonOnlyJSON(int context,
    int aElevator) throws JSONException, Exception {
    return ((DownCallButton) registry.getValue(context)).addElevator(
      (Elevator) registry.getValue(aElevator)).getAttributes();
  }

  public void deleteDownCallButton(int context) {
    ((DownCallButton) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteElevatorFromDownCallButton(int context, int aElevator) {
    ((DownCallButton) registry.getValue(context))
      .deleteElevator((Elevator) registry.getValue(aElevator));
  }

  public JSONObject getAttributesOfDownCallButton(int context)
    throws JSONException {
    return ((DownCallButton) registry.getValue(context)).getAttributes();
  }

  public int constructUpCallButton(Boolean aLightOn,
    ArrayList<Elevator> elevators) {
    return registry.add(new UpCallButton(aLightOn, elevators));
  }

  public JSONObject constructUpCallButtonJSON(Boolean aLightOn,
    ArrayList<Elevator> elevators) throws JSONException {
    UpCallButton contextObj = new UpCallButton(aLightOn, elevators);
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getElevatorsFromUpCallButton(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Elevator obj : ((UpCallButton) registry.getValue(context))
      .getElevators()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  public int addElevatorToUpCallButton(int context, String aIdentifier,
    String aState, String aDirectionOfMovement, int aFullSystem,
    int aCloseDoorButton, int aOpenDoorButton) throws Exception {
    return registry.getKey(((UpCallButton) registry.getValue(context))
      .addElevator(aIdentifier, aState, aDirectionOfMovement,
        (FullSystem) registry.getValue(aFullSystem), (CloseDoorButton) registry
          .getValue(aCloseDoorButton), (OpenDoorButton) registry
          .getValue(aOpenDoorButton)));
  }

  public JSONObject addElevatorToUpCallButtonJSON(int context,
    String aIdentifier, String aState, String aDirectionOfMovement,
    int aFullSystem, int aCloseDoorButton, int aOpenDoorButton)
    throws JSONException, Exception {
    return ((UpCallButton) registry.getValue(context)).addElevator(aIdentifier,
      aState, aDirectionOfMovement,
      (FullSystem) registry.getValue(aFullSystem),
      (CloseDoorButton) registry.getValue(aCloseDoorButton),
      (OpenDoorButton) registry.getValue(aOpenDoorButton)).getAttributes();
  }

  public int addElevatorToUpCallButtonOnly(int context, int aElevator)
    throws Exception {
    return registry.getKey(((UpCallButton) registry.getValue(context))
      .addElevator((Elevator) registry.getValue(aElevator)));
  }

  public JSONObject addElevatorToUpCallButtonOnlyJSON(int context, int aElevator)
    throws JSONException, Exception {
    return ((UpCallButton) registry.getValue(context)).addElevator(
      (Elevator) registry.getValue(aElevator)).getAttributes();
  }

  public void deleteUpCallButton(int context) {
    ((UpCallButton) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteElevatorFromUpCallButton(int context, int aElevator) {
    ((UpCallButton) registry.getValue(context))
      .deleteElevator((Elevator) registry.getValue(aElevator));
  }

  public JSONObject getAttributesOfUpCallButton(int context)
    throws JSONException {
    return ((UpCallButton) registry.getValue(context)).getAttributes();
  }

  public int constructOpenDoorButton(Boolean aLightOn, int aElevator) {
    return registry.add(new OpenDoorButton(aLightOn, (Elevator) registry
      .getValue(aElevator)));
  }

  public JSONObject constructOpenDoorButtonJSON(Boolean aLightOn, int aElevator)
    throws JSONException {
    OpenDoorButton contextObj =
      new OpenDoorButton(aLightOn, (Elevator) registry.getValue(aElevator));
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public int getElevatorFromOpenDoorButton(int context) {
    return registry.getKey(((OpenDoorButton) registry.getValue(context))
      .getElevator());
  }

  public JSONObject getElevatorFromOpenDoorButtonJSON(int context)
    throws JSONException {
    return ((OpenDoorButton) registry.getValue(context)).getElevator()
      .getAttributes();
  }

  public void setElevatorInOpenDoorButton(int context, int aElevator)
    throws Exception {
    ((OpenDoorButton) registry.getValue(context))
      .setElevator((Elevator) registry.getValue(aElevator));
  }

  public void deleteOpenDoorButton(int context) {
    ((OpenDoorButton) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public JSONObject getAttributesOfOpenDoorButton(int context)
    throws JSONException {
    return ((OpenDoorButton) registry.getValue(context)).getAttributes();
  }

  public int constructElevator(String aIdentifier, String aState,
    String aDirectionOfMovement, int aFullSystem, int aCloseDoorButton,
    int aOpenDoorButton) {
    return registry.add(new Elevator(aIdentifier, aState, aDirectionOfMovement,
      (FullSystem) registry.getValue(aFullSystem), (CloseDoorButton) registry
        .getValue(aCloseDoorButton), (OpenDoorButton) registry
        .getValue(aOpenDoorButton)));
  }

  public JSONObject constructElevatorJSON(String aIdentifier, String aState,
    String aDirectionOfMovement, int aFullSystem, int aCloseDoorButton,
    int aOpenDoorButton) throws JSONException {
    Elevator contextObj =
      new Elevator(aIdentifier, aState, aDirectionOfMovement,
        (FullSystem) registry.getValue(aFullSystem), (CloseDoorButton) registry
          .getValue(aCloseDoorButton), (OpenDoorButton) registry
          .getValue(aOpenDoorButton));
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public boolean setIdentifierInElevator(int context, String aIdentifier) {
    return ((Elevator) registry.getValue(context)).setIdentifier(aIdentifier);
  }

  public boolean setStateInElevator(int context, String aState) {
    return ((Elevator) registry.getValue(context)).setState(aState);
  }

  public boolean setDirectionOfMovementInElevator(int context,
    String aDirectionOfMovement) {
    return ((Elevator) registry.getValue(context))
      .setDirectionOfMovement(aDirectionOfMovement);
  }

  public String getIdentifierFromElevator(int context) {
    return ((Elevator) registry.getValue(context)).getIdentifier();
  }

  public String getStateFromElevator(int context) {
    return ((Elevator) registry.getValue(context)).getState();
  }

  public String getDirectionOfMovementFromElevator(int context) {
    return ((Elevator) registry.getValue(context)).getDirectionOfMovement();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getConsoleCallButtonsFromElevator(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (ConsoleCallButton obj : ((Elevator) registry.getValue(context))
      .getConsoleCallButtons()) {
      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 getDownCallButtonsFromElevator(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (DownCallButton obj : ((Elevator) registry.getValue(context))
      .getDownCallButtons()) {
      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 getUpCallButtonsFromElevator(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (UpCallButton obj : ((Elevator) registry.getValue(context))
      .getUpCallButtons()) {
      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 getFloorsFromElevator(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Floor obj : ((Elevator) registry.getValue(context)).getFloors()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  public int getFullSystemFromElevator(int context) {
    return registry.getKey(((Elevator) registry.getValue(context))
      .getFullSystem());
  }

  public JSONObject getFullSystemFromElevatorJSON(int context)
    throws JSONException {
    return ((Elevator) registry.getValue(context)).getFullSystem()
      .getAttributes();
  }

  public int getCloseDoorButtonFromElevator(int context) {
    return registry.getKey(((Elevator) registry.getValue(context))
      .getCloseDoorButton());
  }

  public JSONObject getCloseDoorButtonFromElevatorJSON(int context)
    throws JSONException {
    return ((Elevator) registry.getValue(context)).getCloseDoorButton()
      .getAttributes();
  }

  public int getOpenDoorButtonFromElevator(int context) {
    return registry.getKey(((Elevator) registry.getValue(context))
      .getOpenDoorButton());
  }

  public JSONObject getOpenDoorButtonFromElevatorJSON(int context)
    throws JSONException {
    return ((Elevator) registry.getValue(context)).getOpenDoorButton()
      .getAttributes();
  }

  public int addConsoleCallButtonToElevator(int context, Boolean aLightOn,
    int aElevator, int aFloor) throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context))
      .addConsoleCallButton(aLightOn, (Elevator) registry.getValue(aElevator),
        (Floor) registry.getValue(aFloor)));
  }

  public JSONObject addConsoleCallButtonToElevatorJSON(int context,
    Boolean aLightOn, int aElevator, int aFloor) throws JSONException,
    Exception {
    return ((Elevator) registry.getValue(context)).addConsoleCallButton(
      aLightOn, (Elevator) registry.getValue(aElevator),
      (Floor) registry.getValue(aFloor)).getAttributes();
  }

  public int addConsoleCallButtonToElevatorOnly(int context,
    int aConsoleCallButton) throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context))
      .addConsoleCallButton((ConsoleCallButton) registry
        .getValue(aConsoleCallButton)));
  }

  public JSONObject addConsoleCallButtonToElevatorOnlyJSON(int context,
    int aConsoleCallButton) throws JSONException, Exception {
    return ((Elevator) registry.getValue(context)).addConsoleCallButton(
      (ConsoleCallButton) registry.getValue(aConsoleCallButton))
      .getAttributes();
  }

  public int addDownCallButtonToElevator(int context, Boolean aLightOn,
    ArrayList<Elevator> elevators) throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context))
      .addDownCallButton(aLightOn, elevators));
  }

  public JSONObject addDownCallButtonToElevatorJSON(int context,
    Boolean aLightOn, ArrayList<Elevator> elevators) throws JSONException,
    Exception {
    return ((Elevator) registry.getValue(context)).addDownCallButton(aLightOn,
      elevators).getAttributes();
  }

  public int addDownCallButtonToElevatorOnly(int context, int aDownCallButton)
    throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context))
      .addDownCallButton((DownCallButton) registry.getValue(aDownCallButton)));
  }

  public JSONObject addDownCallButtonToElevatorOnlyJSON(int context,
    int aDownCallButton) throws JSONException, Exception {
    return ((Elevator) registry.getValue(context)).addDownCallButton(
      (DownCallButton) registry.getValue(aDownCallButton)).getAttributes();
  }

  public int addUpCallButtonToElevator(int context, Boolean aLightOn,
    ArrayList<Elevator> elevators) throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context))
      .addUpCallButton(aLightOn, elevators));
  }

  public JSONObject addUpCallButtonToElevatorJSON(int context,
    Boolean aLightOn, ArrayList<Elevator> elevators) throws JSONException,
    Exception {
    return ((Elevator) registry.getValue(context)).addUpCallButton(aLightOn,
      elevators).getAttributes();
  }

  public int addUpCallButtonToElevatorOnly(int context, int aUpCallButton)
    throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context))
      .addUpCallButton((UpCallButton) registry.getValue(aUpCallButton)));
  }

  public JSONObject addUpCallButtonToElevatorOnlyJSON(int context,
    int aUpCallButton) throws JSONException, Exception {
    return ((Elevator) registry.getValue(context)).addUpCallButton(
      (UpCallButton) registry.getValue(aUpCallButton)).getAttributes();
  }

  public int addFloorToElevator(int context) throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context)).addFloor());
  }

  public JSONObject addFloorToElevatorJSON(int context) throws JSONException,
    Exception {
    return ((Elevator) registry.getValue(context)).addFloor().getAttributes();
  }

  public int addFloorToElevatorOnly(int context, int aFloor) throws Exception {
    return registry.getKey(((Elevator) registry.getValue(context))
      .addFloor((Floor) registry.getValue(aFloor)));
  }

  public JSONObject addFloorToElevatorOnlyJSON(int context, int aFloor)
    throws JSONException, Exception {
    return ((Elevator) registry.getValue(context)).addFloor(
      (Floor) registry.getValue(aFloor)).getAttributes();
  }

  public void setFullSystemInElevator(int context, int aFullSystem)
    throws Exception {
    ((Elevator) registry.getValue(context)).setFullSystem((FullSystem) registry
      .getValue(aFullSystem));
  }

  public void setCloseDoorButtonInElevator(int context, int aCloseDoorButton)
    throws Exception {
    ((Elevator) registry.getValue(context))
      .setCloseDoorButton((CloseDoorButton) registry.getValue(aCloseDoorButton));
  }

  public void setOpenDoorButtonInElevator(int context, int aOpenDoorButton)
    throws Exception {
    ((Elevator) registry.getValue(context))
      .setOpenDoorButton((OpenDoorButton) registry.getValue(aOpenDoorButton));
  }

  public void deleteElevator(int context) {
    ((Elevator) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteConsoleCallButtonFromElevator(int context,
    int aConsoleCallButton) {
    ((Elevator) registry.getValue(context))
      .deleteConsoleCallButton((ConsoleCallButton) registry
        .getValue(aConsoleCallButton));
  }

  public void deleteDownCallButtonFromElevator(int context, int aDownCallButton) {
    ((Elevator) registry.getValue(context))
      .deleteDownCallButton((DownCallButton) registry.getValue(aDownCallButton));
  }

  public void deleteUpCallButtonFromElevator(int context, int aUpCallButton) {
    ((Elevator) registry.getValue(context))
      .deleteUpCallButton((UpCallButton) registry.getValue(aUpCallButton));
  }

  public void deleteFloorFromElevator(int context, int aFloor) {
    ((Elevator) registry.getValue(context)).deleteFloor((Floor) registry
      .getValue(aFloor));
  }

  public JSONObject getAttributesOfElevator(int context) throws JSONException {
    return ((Elevator) registry.getValue(context)).getAttributes();
  }

  public int constructConsoleCallButton(Boolean aLightOn, int aElevator,
    int aFloor) {
    return registry.add(new ConsoleCallButton(aLightOn, (Elevator) registry
      .getValue(aElevator), (Floor) registry.getValue(aFloor)));
  }

  public JSONObject constructConsoleCallButtonJSON(Boolean aLightOn,
    int aElevator, int aFloor) throws JSONException {
    ConsoleCallButton contextObj =
      new ConsoleCallButton(aLightOn, (Elevator) registry.getValue(aElevator),
        (Floor) registry.getValue(aFloor));
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public int getElevatorFromConsoleCallButton(int context) {
    return registry.getKey(((ConsoleCallButton) registry.getValue(context))
      .getElevator());
  }

  public JSONObject getElevatorFromConsoleCallButtonJSON(int context)
    throws JSONException {
    return ((ConsoleCallButton) registry.getValue(context)).getElevator()
      .getAttributes();
  }

  public int getFloorFromConsoleCallButton(int context) {
    return registry.getKey(((ConsoleCallButton) registry.getValue(context))
      .getFloor());
  }

  public JSONObject getFloorFromConsoleCallButtonJSON(int context)
    throws JSONException {
    return ((ConsoleCallButton) registry.getValue(context)).getFloor()
      .getAttributes();
  }

  public void setElevatorInConsoleCallButton(int context, int aElevator)
    throws Exception {
    ((ConsoleCallButton) registry.getValue(context))
      .setElevator((Elevator) registry.getValue(aElevator));
  }

  public void setFloorInConsoleCallButton(int context, int aFloor)
    throws Exception {
    ((ConsoleCallButton) registry.getValue(context)).setFloor((Floor) registry
      .getValue(aFloor));
  }

  public void deleteConsoleCallButton(int context) {
    ((ConsoleCallButton) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public JSONObject getAttributesOfConsoleCallButton(int context)
    throws JSONException {
    return ((ConsoleCallButton) registry.getValue(context)).getAttributes();
  }

  public int constructStopCallbutton(Boolean aLightOn) {
    return registry.add(new StopCallbutton(aLightOn));
  }

  public JSONObject constructStopCallbuttonJSON(Boolean aLightOn)
    throws JSONException {
    StopCallbutton contextObj = new StopCallbutton(aLightOn);
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  public void deleteStopCallbutton(int context) {
    ((StopCallbutton) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public JSONObject getAttributesOfStopCallbutton(int context)
    throws JSONException {
    return ((StopCallbutton) registry.getValue(context)).getAttributes();
  }

  public int constructFloor() {
    return registry.add(new Floor());
  }

  public JSONObject constructFloorJSON() throws JSONException {
    Floor contextObj = new Floor();
    registry.add(contextObj);
    return contextObj.getAttributes();
  }

  /************
   * Method returns an iterator to the list of id's of the elements involved in this list.
   ***************/
  public Iterator getConsoleCallButtonsFromFloor(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (ConsoleCallButton obj : ((Floor) registry.getValue(context))
      .getConsoleCallButtons()) {
      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 getElevatorsFromFloor(int context) {
    ArrayList listOfIDs = new ArrayList();
    for (Elevator obj : ((Floor) registry.getValue(context)).getElevators()) {
      listOfIDs.add(registry.getKey(obj));
    }
    return listOfIDs.iterator();
  }

  public int getFloorNumberDisplayFromFloor(int context) {
    return registry.getKey(((Floor) registry.getValue(context))
      .getFloorNumberDisplay());
  }

  public JSONObject getFloorNumberDisplayFromFloorJSON(int context)
    throws JSONException {
    return ((Floor) registry.getValue(context)).getFloorNumberDisplay()
      .getAttributes();
  }

  public int addConsoleCallButtonToFloor(int context, Boolean aLightOn,
    int aElevator, int aFloor) throws Exception {
    return registry.getKey(((Floor) registry.getValue(context))
      .addConsoleCallButton(aLightOn, (Elevator) registry.getValue(aElevator),
        (Floor) registry.getValue(aFloor)));
  }

  public JSONObject addConsoleCallButtonToFloorJSON(int context,
    Boolean aLightOn, int aElevator, int aFloor) throws JSONException,
    Exception {
    return ((Floor) registry.getValue(context)).addConsoleCallButton(aLightOn,
      (Elevator) registry.getValue(aElevator),
      (Floor) registry.getValue(aFloor)).getAttributes();
  }

  public int addConsoleCallButtonToFloorOnly(int context, int aConsoleCallButton)
    throws Exception {
    return registry.getKey(((Floor) registry.getValue(context))
      .addConsoleCallButton((ConsoleCallButton) registry
        .getValue(aConsoleCallButton)));
  }

  public JSONObject addConsoleCallButtonToFloorOnlyJSON(int context,
    int aConsoleCallButton) throws JSONException, Exception {
    return ((Floor) registry.getValue(context)).addConsoleCallButton(
      (ConsoleCallButton) registry.getValue(aConsoleCallButton))
      .getAttributes();
  }

  public int addElevatorToFloor(int context, String aIdentifier, String aState,
    String aDirectionOfMovement, int aFullSystem, int aCloseDoorButton,
    int aOpenDoorButton) throws Exception {
    return registry.getKey(((Floor) registry.getValue(context)).addElevator(
      aIdentifier, aState, aDirectionOfMovement, (FullSystem) registry
        .getValue(aFullSystem), (CloseDoorButton) registry
        .getValue(aCloseDoorButton), (OpenDoorButton) registry
        .getValue(aOpenDoorButton)));
  }

  public JSONObject addElevatorToFloorJSON(int context, String aIdentifier,
    String aState, String aDirectionOfMovement, int aFullSystem,
    int aCloseDoorButton, int aOpenDoorButton) throws JSONException, Exception {
    return ((Floor) registry.getValue(context)).addElevator(aIdentifier,
      aState, aDirectionOfMovement,
      (FullSystem) registry.getValue(aFullSystem),
      (CloseDoorButton) registry.getValue(aCloseDoorButton),
      (OpenDoorButton) registry.getValue(aOpenDoorButton)).getAttributes();
  }

  public int addElevatorToFloorOnly(int context, int aElevator)
    throws Exception {
    return registry.getKey(((Floor) registry.getValue(context))
      .addElevator((Elevator) registry.getValue(aElevator)));
  }

  public JSONObject addElevatorToFloorOnlyJSON(int context, int aElevator)
    throws JSONException, Exception {
    return ((Floor) registry.getValue(context)).addElevator(
      (Elevator) registry.getValue(aElevator)).getAttributes();
  }

  public void setFloorNumberDisplayInFloor(int context, int aFloorNumberDisplay)
    throws Exception {
    ((Floor) registry.getValue(context))
      .setFloorNumberDisplay((FloorNumberDisplay) registry
        .getValue(aFloorNumberDisplay));
  }

  public void deleteFloor(int context) {
    ((Floor) registry.getValue(context)).delete();
    registry.removeObj(context);
  }

  public void deleteConsoleCallButtonFromFloor(int context,
    int aConsoleCallButton) {
    ((Floor) registry.getValue(context))
      .deleteConsoleCallButton((ConsoleCallButton) registry
        .getValue(aConsoleCallButton));
  }

  public void deleteElevatorFromFloor(int context, int aElevator) {
    ((Floor) registry.getValue(context)).deleteElevator((Elevator) registry
      .getValue(aElevator));
  }

  public void deleteFloorNumberDisplayFromFloor(int context,
    int aFloorNumberDisplay) {
    ((Floor) registry.getValue(context))
      .deleteFloorNumberDisplay((FloorNumberDisplay) registry
        .getValue(aFloorNumberDisplay));
  }

  public JSONObject getAttributesOfFloor(int context) throws JSONException {
    return ((Floor) registry.getValue(context)).getAttributes();
  }
}