YANG Model update for A1 Adapter
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / config / BaseSubConfig.java
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.config;
19
20 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile;
21 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile.ConversionException;
22 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.IniConfigurationFile.Section;
23
24 public class BaseSubConfig {
25
26     private final Section subconfig;
27     private final ISubConfigHandler configHandler;
28     private final IniConfigurationFile config;
29
30     protected Section getSubConfig() {
31         return this.subconfig;
32     }
33     protected ISubConfigHandler getConfigHandler() {
34         return this.configHandler;
35     }
36     protected IniConfigurationFile getConfig() {
37         return this.config;
38     }
39     public BaseSubConfig()
40     {
41         this.config=null;
42         this.subconfig=null;
43         this.configHandler=null;
44     }
45     public BaseSubConfig(IniConfigurationFile config, ISubConfigHandler configHandler,String section) {
46         this.config = config;
47         this.subconfig = config.subset(section);
48         this.configHandler = configHandler;
49     }
50     protected boolean hasKey(String key)
51     {
52         if(this.subconfig==null) {
53             return false;
54         }
55         return this.subconfig.hasKey(key);
56     }
57     protected String getString(String key,String def)
58     {
59         if(this.subconfig==null) {
60             return def;
61         }
62         String s;
63         //try
64         {
65             s=this.subconfig.getString(key, def);
66             if(s.isEmpty()) {
67                 s=def;
68             }
69         }
70         /*catch(ConversionException e)
71         {
72             s=def;
73         }
74         */
75         return s;
76     }
77     protected boolean getBoolean(String key, boolean def) {
78         if(this.subconfig==null) {
79             return def;
80         }
81         boolean s;
82         try {
83             s=this.subconfig.getBoolean(key, def);
84         }
85         catch(ConversionException e)
86         {
87             s=def;
88         }
89         return s;
90     }
91     protected int getInt(String key, int def) {
92         if(this.subconfig==null) {
93             return def;
94         }
95         int s;
96         try {
97             s=this.subconfig.getInt(key, def);
98         }
99         catch(ConversionException e)
100         {
101             s=def;
102         }
103         return s;
104     }
105     protected long getLong(String key, long def) {
106         if(this.subconfig==null) {
107             return def;
108         }
109         long s;
110         try {
111             s=this.subconfig.getLong(key, def);
112         }
113         catch(ConversionException e)
114         {
115             s=def;
116         }
117         return s;
118     }
119     protected void save()
120     {
121         if(this.configHandler!=null) {
122             this.configHandler.save();
123         }
124     }
125
126
127 }