This project has retired. For details please refer to its
Attic page.
ViewBean 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.parser.JSONParser;
32
33 import org.apache.hadoop.chukwa.util.ExceptionUtil;
34
35 @XmlRootElement
36 @XmlType
37 public class ViewBean {
38 private PagesBean[] pages;
39 private String description;
40 private String owner;
41
42 private String name;
43 private String permissionType;
44 private static Log log = LogFactory.getLog(ViewBean.class);
45
46 public ViewBean() {
47 }
48
49 public ViewBean(byte[] buffer) throws ParseException {
50 JSONParser parser = new JSONParser();
51 try {
52 JSONObject json = (JSONObject) parser.parse(new String(buffer));
53 if(json.containsKey("description")) {
54 this.description = (String) json.get("description");
55 } else {
56 this.description = "";
57 }
58 this.owner= (String) json.get("owner");
59 this.name= (String) json.get("name");
60 this.permissionType= (String) json.get("permissionType");
61 int size = ((JSONArray) json.get("pages")).size();
62 PagesBean[] pages = new PagesBean[size];
63 JSONArray pagesArray = (JSONArray) json.get("pages");
64 for(int i=0;i<size;i++) {
65 pages[i] = new PagesBean((JSONObject) pagesArray.get(i));
66 }
67 this.pages=pages;
68 } catch (Exception e) {
69 log.error(ExceptionUtil.getStackTrace(e));
70 throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
71 }
72 }
73
74 @XmlElement
75 public PagesBean[] getPages() {
76 return pages.clone();
77 }
78
79 @XmlElement
80 public int getPagesCount() {
81 return pages.length;
82 }
83
84 @XmlElement
85 public String getDescription() {
86 return this.description;
87 }
88
89 @XmlElement
90 public String getOwner() {
91 return this.owner;
92 }
93
94 @XmlElement
95 public String getName() {
96 return this.name;
97 }
98
99 @XmlElement
100 public String getPermissionType() {
101 return this.permissionType;
102 }
103
104 public void setPages(PagesBean[] pages) {
105 this.pages = (PagesBean[]) pages.clone();
106 }
107
108 public void setDescription(String description) {
109 this.description = description;
110 }
111
112 public void setOwner(String owner) {
113 this.owner = owner;
114 }
115
116 public void setName(String name) {
117 this.name = name;
118 }
119
120 public void setPermissionType(String permissionType) {
121 this.permissionType = permissionType;
122 }
123
124 public void update() {
125 if(this.pages!=null) {
126 for(PagesBean page : pages) {
127 page.update();
128 }
129 }
130 }
131
132 @SuppressWarnings("unchecked")
133 public JSONObject deserialize() {
134 update();
135 JSONObject view = new JSONObject();
136 try {
137 view.put("name", this.name);
138 view.put("owner", this.owner);
139 view.put("permissionType", this.permissionType);
140 view.put("description", this.description);
141 JSONArray ja = new JSONArray();
142 for(int i=0;i<this.pages.length;i++) {
143 ja.add(this.pages[i].deserialize());
144 }
145 view.put("pages", (JSONArray) ja);
146 } catch (Exception e){
147 log.error(ExceptionUtil.getStackTrace(e));
148 }
149 return view;
150 }
151 }