This project has retired. For details please refer to its
Attic page.
CatalogBean 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.util.ArrayList;
22 import java.util.List;
23
24 import javax.xml.bind.annotation.XmlElement;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import javax.xml.bind.annotation.XmlType;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 @XmlRootElement
32 @XmlType(propOrder={"type", "id", "label", "children"})
33 public class CatalogBean {
34 private static final Log log = LogFactory.getLog(CatalogBean.class);
35 private List<CatalogBean> children = new ArrayList<CatalogBean>();
36 private String type = "text";
37 private String label = null;
38 private String id = null;
39
40 public CatalogBean() {
41 }
42
43 @XmlElement
44 public String getType() {
45 return type;
46 }
47
48 @XmlElement
49 public String getId() {
50 return id;
51 }
52
53 @XmlElement
54 public String getLabel() {
55 return label;
56 }
57
58 @XmlElement
59 public List<CatalogBean> getChildren() {
60 return children;
61 }
62
63 public void setType(String type) {
64 this.type = type;
65 }
66
67 public void setId(String id) {
68 this.id = id;
69 }
70
71 public void setLabel(String label) {
72 this.label = label;
73 }
74
75 public void setChildren(List<CatalogBean> children) {
76 this.children = children;
77 }
78
79 public void addCatalog(WidgetBean widget) {
80 String[] path = widget.getCategories().split(",");
81 List<CatalogBean> tracker = this.children;
82 if(tracker==null) {
83 tracker = new ArrayList<CatalogBean>();
84 }
85 for(int i=0;i<path.length;i++) {
86 boolean duplicate = false;
87 for(int j=0;j<tracker.size();j++) {
88 if(tracker.get(j).getLabel().intern()==path[i].intern()) {
89 duplicate = true;
90 tracker = tracker.get(j).getChildren();
91 continue;
92 }
93 }
94 if(!duplicate) {
95 tracker = addCategory(tracker, widget.getId(), path[i]);
96 }
97 }
98 tracker = addCategory(tracker, widget.getId(), widget.getTitle());
99 }
100
101 public List<CatalogBean> addCategory(List<CatalogBean> tracker, String id, String label) {
102 CatalogBean c = new CatalogBean();
103 c.setId(id);
104 c.setLabel(label);
105 tracker.add(c);
106 return c.getChildren();
107 }
108
109 }