1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.config;
\r
25 import java.lang.reflect.Method;
\r
27 import org.onap.aaf.cadi.Access;
\r
28 import org.onap.aaf.cadi.Access.Level;
\r
30 public interface Get {
\r
31 public String get(String name, String def, boolean print);
\r
35 * A class for Getting info out of "JavaBean" format
\r
38 public static class Bean implements Get {
\r
39 private Object bean;
\r
40 private Class<?> bc;
\r
41 private Class<?>[] params;
\r
42 private Object[] args;
\r
44 public Bean(Object bean) {
\r
46 bc = bean.getClass();
\r
47 params = new Class<?>[0]; // note, this will allow to go out of scope after config
\r
48 args = new Object[0];
\r
51 public String get(String name, String def, boolean print) {
\r
53 String gname = "get"+Character.toUpperCase(name.charAt(0))+name.substring(1);
\r
55 Method meth = bc.getMethod(gname, params);
\r
56 Object obj = meth.invoke(bean, args);
\r
57 str = obj==null?null:obj.toString(); // easy string convert...
\r
58 } catch (Exception e) {
\r
61 // Take def if nothing else
\r
64 // don't log defaults
\r
66 str = str.trim(); // this is vital in Property File based values, as spaces can hide easily
\r
68 // Note: Can't log during configuration
\r
73 public static Get NULL = new Get() {
\r
74 public String get(String name, String def, boolean print) {
\r
79 public static class AccessGet implements Get {
\r
80 private Access access;
\r
81 public AccessGet(Access access) {
\r
82 this.access = access;
\r
84 public String get(String name, String def, boolean print) {
\r
85 String gotten = access.getProperty(name, def);
\r
87 if(gotten == null) {
\r
88 access.log(Level.INIT,name, "is not set");
\r
90 access.log(Level.INIT,name, "is set to", gotten);
\r