Format Java code with respect to ONAP Code Style
[externalapi/nbi.git] / src / main / java / org / onap / nbi / commons / BeanUtils.java
1 /**
2  * Copyright (c) 2018 Orange
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14
15 package org.onap.nbi.commons;
16
17 import org.apache.commons.beanutils.PropertyUtilsBean;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  *
23  */
24 public class BeanUtils {
25
26     private static final Logger LOGGER = LoggerFactory.getLogger(BeanUtils.class);
27
28     private static final PropertyUtilsBean PUB = new PropertyUtilsBean();
29
30     private BeanUtils() {
31     }
32
33     /**
34      *
35      * @param bean
36      * @param name
37      * @return
38      */
39     public static Object getNestedProperty(Object bean, String name) {
40         try {
41             return BeanUtils.PUB.getNestedProperty(bean, name);
42         } catch (Exception e) {
43             LOGGER.warn("Enable to retrieve nested property name=" + name, e);
44             return null;
45         }
46     }
47
48     /**
49      *
50      * @param bean
51      * @param name
52      * @param value
53      */
54     public static void setNestedProperty(Object bean, String name, Object value) {
55         try {
56             BeanUtils.PUB.setNestedProperty(bean, name, value);
57         } catch (Exception ex) {
58             LOGGER.warn("Enable to set nested property name=" + name + " value=" + value, ex);
59         }
60     }
61
62 }