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  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.JSONObject;
30  
31  import org.apache.hadoop.chukwa.util.ExceptionUtil;
32  
33  @XmlRootElement
34  @XmlType(propOrder={"key", "value"})
35  public class ConfigBean {
36    private String key = null;
37    private String value = null;
38    private static Log log = LogFactory.getLog(ViewBean.class);
39    
40    public ConfigBean() {
41    }
42    
43    public ConfigBean(JSONObject json) throws ParseException {
44      try {
45        key = (String) json.get("key");
46        value = (String) json.get("value");
47      } catch (Exception e) {
48        log.error(ExceptionUtil.getStackTrace(e));
49        throw new ParseException("Error parsing user object.",0);
50      }
51    }
52    
53    @XmlElement
54    public String getKey() {
55      return key;
56    }
57    
58    @XmlElement
59    public String getValue() {
60      return value;
61    }
62    
63    public void setKey(String key) {
64      this.key = key;
65    }
66    
67    public void setValue(String value) {
68      this.value = value;
69    }
70  }