This project has retired. For details please refer to its Attic page.
ColumnBean xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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 ColumnBean {
33    private WidgetBean[] widgets;
34    
35    private static Log log = LogFactory.getLog(ColumnBean.class);
36    
37    public ColumnBean() {
38    }
39    
40    public ColumnBean(JSONArray json) throws ParseException {
41      try {
42        widgets = new WidgetBean[json.size()];
43        for(int i=0;i<json.size();i++) {
44          widgets[i]=new WidgetBean((JSONObject) json.get(i));
45        }
46      } catch (Exception e) {
47        log.error(ExceptionUtil.getStackTrace(e));
48        throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
49      }
50    }
51    
52    @XmlElement
53    public WidgetBean[] getWidgets() {
54      return widgets.clone();
55    }
56    
57    public void setWidgets(WidgetBean[] ws) {
58      widgets=(WidgetBean[]) ws.clone();
59    }
60    
61    public void update() {
62      for(int i=0;i<widgets.length;i++) {
63        widgets[i].update();
64      }
65    }
66    
67    public JSONArray deserialize() {
68      JSONArray ja = new JSONArray();
69      for(int i=0;i<widgets.length;i++) {
70        ja.add(widgets[i].deserialize());
71      }
72      return ja;
73    }
74  }