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