001 package de.kiezatlas;
002
003 import de.deepamehta.core.JSONEnabled;
004 import de.deepamehta.core.Topic;
005
006 import org.codehaus.jettison.json.JSONArray;
007 import org.codehaus.jettison.json.JSONObject;
008
009
010
011 /**
012 * A collection of Geo Objects as returned by the Kiezatlas service (a data transfer object).
013 */
014 public class GeoObjects implements JSONEnabled {
015
016 // ---------------------------------------------------------------------------------------------- Instance Variables
017
018 private JSONObject json = new JSONObject();
019 private JSONArray items = new JSONArray();
020
021 // ---------------------------------------------------------------------------------------------------- Constructors
022
023 GeoObjects(long clock) {
024 try {
025 json.put("items", items);
026 json.put("clock", clock);
027 } catch (Exception e) {
028 throw new RuntimeException("Constructing GeoObjects failed", e);
029 }
030 }
031
032 // -------------------------------------------------------------------------------------------------- Public Methods
033
034 void add(Topic geoObject) {
035 try {
036 items.put(geoObject.toJSON());
037 } catch (Exception e) {
038 throw new RuntimeException("Adding geo object to GeoObjects failed", e);
039 }
040 }
041
042 @Override
043 public JSONObject toJSON() {
044 return json;
045 }
046 }