This project has retired. For details please refer to its
Attic page.
PagesBean 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
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.json.simple.JSONArray;
28 import org.json.simple.JSONObject;
29
30 import org.apache.hadoop.chukwa.util.ExceptionUtil;
31
32 public class PagesBean {
33 private static Log log = LogFactory.getLog(PagesBean.class);
34 private String title;
35 private int[] columnSizes;
36 private ColumnBean[] layout;
37 private int columns;
38
39 public PagesBean() {
40 }
41
42
43 public PagesBean(JSONObject json) throws ParseException {
44 try {
45 title = (String) json.get("title");
46 columns = ((Long) json.get("columns")).intValue();
47 JSONArray layout = (JSONArray) json.get("layout");
48 this.layout = new ColumnBean[layout.size()];
49 for(int i=0;i<layout.size();i++) {
50 ColumnBean c = new ColumnBean((JSONArray) layout.get(i));
51 this.layout[i]=c;
52 }
53 if(json.containsKey("colSize")) {
54 JSONArray ja = (JSONArray) json.get("colSize");
55 columnSizes = new int[ja.size()];
56 for(int i=0; i< ja.size(); i++) {
57 columnSizes[i] = ((Long) ja.get(i)).intValue();
58 }
59 }
60 } catch (Exception e) {
61 log.error(ExceptionUtil.getStackTrace(e));
62 throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
63 }
64 }
65
66 @XmlElement
67 public String getTitle() {
68 return title;
69 }
70
71
72
73
74
75
76 @XmlElement(name="layout")
77 public ColumnBean[] getLayout() {
78 return layout.clone();
79 }
80
81 public void update() {
82 for(int i=0;i<layout.length;i++) {
83 layout[i].update();
84 }
85 }
86
87 public void setTitle(String title) {
88 this.title = title;
89 }
90
91 public void setLayout(ColumnBean[] layout) {
92 this.layout = (ColumnBean[]) layout.clone();
93 }
94
95 @XmlElement(name="colSize")
96 public int[] getColSize() {
97 return this.columnSizes.clone();
98 }
99
100 public void setColSize(int[] size) {
101 this.columnSizes = (int[]) size.clone();
102 }
103
104 @XmlElement(name="columns")
105 public int getColumns() {
106 return this.columns;
107 }
108
109 public void setColumns(int columns) {
110 this.columns = columns;
111 }
112
113 public JSONObject deserialize() {
114 JSONObject json = new JSONObject();
115 JSONArray ja = new JSONArray();
116 JSONArray sizes = new JSONArray();
117 try {
118 json.put("title", this.title);
119 for(int i=0;i<layout.length;i++) {
120 ja.add(layout[i].deserialize());
121 }
122 json.put("layout", (JSONArray) ja);
123 json.put("columns", layout.length);
124 if(columnSizes!=null) {
125 for(int colSize : columnSizes) {
126 sizes.add(colSize);
127 }
128 }
129 json.put("colSize", (JSONArray) sizes);
130 } catch (Exception e) {
131 log.error(ExceptionUtil.getStackTrace(e));
132 }
133 return json;
134 }
135
136 }