This project has retired. For details please refer to its
Attic page.
UserBean xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.rest.bean;
20
21 import java.text.ParseException;
22
23 import javax.xml.bind.annotation.XmlElement;
24 import javax.xml.bind.annotation.XmlRootElement;
25 import javax.xml.bind.annotation.XmlType;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.json.simple.JSONArray;
30 import org.json.simple.JSONObject;
31 import org.json.simple.JSONValue;
32
33 import org.apache.hadoop.chukwa.util.ExceptionUtil;
34
35 @XmlRootElement
36 @XmlType(propOrder={"id", "views", "properties"})
37 public class UserBean {
38 private String id;
39 private JSONArray views;
40 private JSONObject properties;
41 private static Log log = LogFactory.getLog(UserBean.class);
42
43 public UserBean() {
44 views = new JSONArray();
45 properties = new JSONObject();
46 }
47
48 public UserBean(JSONObject json) throws ParseException {
49 try {
50 id = (String) json.get("id");
51 views = (JSONArray) json.get("views");
52 if(json.containsKey("properties")) {
53 properties = (JSONObject) json.get("properties");
54 } else {
55 properties = new JSONObject();
56 }
57 } catch (Exception e) {
58 log.error(ExceptionUtil.getStackTrace(e));
59 throw new ParseException("Error parsing user object.",0);
60 }
61 }
62
63 @XmlElement
64 public String getId() {
65 return id;
66 }
67
68 @XmlElement
69 public JSONArray getViews() {
70 return views;
71 }
72
73 @XmlElement
74 public String getProperties() {
75 return properties.toString();
76 }
77
78 public void setProperties(String buffer) {
79 try {
80 this.properties = (JSONObject) JSONValue.parse(buffer);
81 } catch (Exception e) {
82 log.error(ExceptionUtil.getStackTrace(e));
83 }
84 }
85
86 public String getPropertyValue(String key) {
87 return (String) this.properties.get(key);
88 }
89
90 public void setId(String id) {
91 this.id=id;
92 }
93
94 public void setViews(JSONArray ja) {
95 this.views=ja;
96 }
97
98 public void setProperty(String key, String value) throws ParseException {
99 try {
100 this.properties.put(key, value);
101 } catch (Exception e) {
102 log.error(ExceptionUtil.getStackTrace(e));
103 throw new ParseException("Error parsing user object.",0);
104 }
105 }
106
107 public JSONObject deserialize() {
108 JSONObject json = new JSONObject();
109 try {
110 json.put("id", this.id);
111 json.put("views", this.views);
112 json.put("properties", this.properties);
113 } catch (Exception e) {
114 log.error(ExceptionUtil.getStackTrace(e));
115 }
116 return json;
117 }
118 }