/*This code was generated using the UMPLE modeling language!
 Date of generation: 2008/07/30 10:46:15*/
/*This class drives: Hotel*/

package hotel.core;

import java.util.*;
import hotel.*;
import hotel.json.*;

public class HotelCompany {
  //Class datatypes
  private String name;

  //Class association variables
  private List<Hotel> ownss;

  //Registry of our system.
  HotelRegistry registry = HotelRegistry.getInstance();

  //Constructor
  public HotelCompany(String aName) {
    name = aName;
    ownss = new ArrayList<Hotel>();
    registry.add(ownss);

  }

  public boolean setName(String aName) {
    name = aName;
    return true;
  }

  public String getName() {
    return name;
  }

  public List<Hotel> getOwnss() {
    return ownss;
  }

  public Hotel addOwns(String aName, String aAddress, HotelCompany aHotelCompany) {
    Hotel newHotel;
    newHotel = new Hotel(aName, aAddress, this);
    if (!ownss.contains(newHotel)) {
      registry.add(newHotel);
      ownss.add(newHotel);
    }
    return newHotel;
  }

  public Hotel addOwns(Hotel aOwns) {
    if (!ownss.contains(aOwns))
      ownss.add(aOwns);
    return aOwns;
  }

  public void delete() {
    //Delete all many ends first.
    for (Hotel aHotel : ownss) {
      aHotel.delete();
    }
    ownss.clear();

  }

  public void deleteOwns(Hotel aHotel) {

    if (ownss.contains(aHotel)) {
      ownss.remove(aHotel);

      //registry.removeObj(registry.getKey(aHotel));
    } else
    //Throw an UmpleException .. to be implemented.
    {
    }
  }

  public boolean areManyEndsNull() {
    if (ownss.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("name", getName());
    return obj;
  }

}