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