![]() |
Hubiquitus Android
0.3
Android client for hubiquitus protocol
|
00001 /* 00002 * Copyright (c) Novedia Group 2012. 00003 * 00004 * This file is part of Hubiquitus. 00005 * 00006 * Hubiquitus is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * Hubiquitus is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with Hubiquitus. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 package org.hubiquitus.hapi.util; 00021 00022 import java.util.Calendar; 00023 00024 import org.hubiquitus.hapi.hStructures.HJsonObj; 00025 import org.json.JSONArray; 00026 import org.json.JSONObject; 00027 00032 public class HJsonDictionnary implements HJsonObj{ 00033 00034 private JSONObject jsonObj; 00035 00036 public HJsonDictionnary() { 00037 jsonObj = new JSONObject(); 00038 } 00039 00040 public HJsonDictionnary(JSONObject jsonObj) { 00041 this.fromJSON(jsonObj); 00042 } 00043 00044 public Object get(String key) { 00045 Object value; 00046 try { 00047 value = jsonObj.get(key); 00048 } catch (Exception e) { 00049 value = null; 00050 } 00051 return value; 00052 } 00053 00060 public void put(String key, Object value) { 00061 try { 00062 if (value instanceof HJsonObj) { 00063 jsonObj.put(key, ((HJsonObj)value).toJSON()); 00064 } else if ((value instanceof JSONObject) || (value instanceof JSONArray) || 00065 (value instanceof Boolean) || (value instanceof Integer) || 00066 (value instanceof Double) || (value instanceof String )) { 00067 jsonObj.put(key, value); 00068 } else if (value instanceof Calendar) { 00069 jsonObj.put(key, DateISO8601.fromCalendar((Calendar)value)); 00070 } 00071 } catch (Exception e) { 00072 System.out.println("erreur :" + this.getClass()); 00073 } 00074 } 00075 00076 @Override 00077 public JSONObject toJSON() { 00078 return jsonObj; 00079 } 00080 00081 @Override 00082 public void fromJSON(JSONObject jsonObj) { 00083 this.jsonObj = jsonObj; 00084 } 00085 00086 @Override 00087 public String getHType() { 00088 return "hjsondictionnary"; 00089 } 00090 00091 @Override 00092 public String toString() { 00093 return "HJsonDictionnary [jsonObj=" + jsonObj.toString() + "]"; 00094 } 00095 00096 @Override 00097 public boolean equals(Object obj) { 00098 return jsonObj.equals(obj); 00099 } 00100 00101 @Override 00102 public int hashCode() { 00103 return jsonObj.hashCode(); 00104 } 00105 }