06ec2f5a8742f7ccb6ddfcdd16e3ca1318935011
[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 package org.onap.nbi.commons;
15
16 import org.apache.commons.beanutils.PropertyUtilsBean;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  *
22  */
23 public class BeanUtils {
24
25     private static final Logger LOGGER = LoggerFactory.getLogger(BeanUtils.class);
26
27     private static final PropertyUtilsBean PUB = new PropertyUtilsBean();
28
29     private BeanUtils() {
30     }
31
32     /**
33      *
34      * @param bean
35      * @param name
36      * @return
37      */
38     public static Object getNestedProperty(Object bean, String name) {
39         try {
40             return BeanUtils.PUB.getNestedProperty(bean, name);
41         } catch (Exception e) {
42             LOGGER.warn("Enable to retrieve nested property name=" + name, e);
43             return null;
44         }
45     }
46
47     /**
48      *
49      * @param bean
50      * @param name
51      * @param value
52      */
53     public static void setNestedProperty(Object bean, String name, Object value) {
54         try {
55             BeanUtils.PUB.setNestedProperty(bean, name, value);
56         } catch (Exception ex) {
57             LOGGER.warn("Enable to set nested property name=" + name + " value=" + value, ex);
58         }
59     }
60
61 }