a0acf12cc7c04a68f53e5e6c7c9de6b31f5efff2
[appc.git] / appc-common / src / main / java / org / onap / appc / configuration / Configuration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.configuration;
26
27 import java.util.Properties;
28
29 import org.slf4j.Logger;
30
31
32
33 /**
34  * This interface defines the common configuration support that is available to the application.
35  * <p>
36  * Where properties are common to all CDP components (server, coordinator, and EPM), the property symbolic values are
37  * defined as part of this interface. Where they are unique to each component, they must be defined within that
38  * component.
39  * </p>
40  */
41 public interface Configuration {
42
43     String PROPERTY_BOOTSTRAP_FILE_NAME = "org_onap_appc_bootstrap_file"; //
44     String DEFAULT_BOOTSTRAP_FILE_NAME = "appc.properties"; 
45     String PROPERTY_BOOTSTRAP_FILE_PATH = "org_onap_appc_bootstrap_path"; //
46     String DEFAULT_BOOTSTRAP_FILE_PATH = "/opt/openecomp/appc/data/properties,${user.home},etc,../etc";
47     String PROPERTY_RESOURCE_BUNDLES = "org.onap.appc.resources"; 
48     String DEFAULT_RESOURCE_BUNDLES = "org/onap/appc/i18n/MessageResources";
49
50    /**
51      * This method is called to obtain a property expressed as a boolean value (true or false). The standard rules for
52      * {@link Boolean#valueOf(String)} are used.
53      * 
54      * @param key
55      *            The property key
56      * @return The value of the property expressed as a boolean, or false if it does not exist.
57      */
58     boolean getBooleanProperty(String key);
59
60     /**
61      * This method is called to obtain a property expressed as a boolean value (true or false). The standard rules for
62      * {@link Boolean#valueOf(String)} are used.
63      * 
64      * @param key
65      *            The property key
66      * @param defaultValue
67      *            The default value to be returned if the property does not exist
68      * @return The value of the property expressed as a boolean, or false if it does not exist.
69      */
70     boolean getBooleanProperty(String key, boolean defaultValue);
71
72     /**
73      * Returns the indicated property value expressed as a floating point double-precision value (double). The standard
74      * rules for {@link Double#valueOf(String)} are used.
75      * 
76      * @param key
77      *            The property to retrieve
78      * @return The value of the property, or 0.0 if not found or invalid
79      */
80     double getDoubleProperty(String key);
81
82     /**
83      * Returns the indicated property value expressed as a floating point double-precision value (double). The standard
84      * rules for {@link Double#valueOf(String)} are used.
85      * 
86      * @param key
87      *            The property to retrieve
88      * @param defaultValue
89      *            The default value to be returned if the property does not exist
90      * @return The value of the property, or 0.0 if not found or invalid
91      */
92     double getDoubleProperty(String key, double defaultValue);
93
94     /**
95      * Returns the property indicated expressed as an integer. The standard rules for
96      * {@link Integer#parseInt(String, int)} using a radix of 10 are used.
97      * 
98      * @param key
99      *            The property name to retrieve.
100      * @return The value of the property, or 0 if it does not exist or is invalid.
101      */
102     int getIntegerProperty(String key);
103
104     /**
105      * Returns the property indicated expressed as an integer. The standard rules for
106      * {@link Integer#parseInt(String, int)} using a radix of 10 are used.
107      * 
108      * @param key
109      *            The property name to retrieve.
110      * @param defaultValue
111      *            The default value to be returned if the property does not exist
112      * @return The value of the property, or 0 if it does not exist or is invalid.
113      */
114     int getIntegerProperty(String key, int defaultValue);
115
116     /**
117      * Returns the specified property as a long integer value, if it exists, or zero if it does not.
118      * 
119      * @param key
120      *            The key of the property desired.
121      * @return The value of the property expressed as an integer long value, or zero if the property does not exist or
122      *         is not a valid integer long.
123      */
124     long getLongProperty(String key);
125
126     /**
127      * Returns the specified property as a long integer value, if it exists, or the default value if it does not exist
128      * or is invalid.
129      * 
130      * @param key
131      *            The key of the property desired.
132      * @param defaultValue
133      *            the value to be returned if the property is not valid or does not exist.
134      * @return The value of the property expressed as an integer long value, or the default value if the property does
135      *         not exist or is not a valid integer long.
136      */
137     long getLongProperty(String key, long defaultValue);
138
139     /**
140      * This method can be called to retrieve a properties object that is immutable. Any attempt to modify the properties
141      * object returned will result in an exception. This allows a caller to view the current configuration as a set of
142      * properties.
143      * 
144      * @return An unmodifiable properties object.
145      */
146     Properties getProperties();
147
148     /**
149      * This method is called to obtain a property as a string value
150      * 
151      * @param key
152      *            The key of the property
153      * @return The string value, or null if it does not exist.
154      */
155     String getProperty(String key);
156
157     /**
158      * This method is called to obtain a property as a string value
159      * 
160      * @param key
161      *            The key of the property
162      * @param defaultValue
163      *            The default value to be returned if the property does not exist
164      * @return The string value, or null if it does not exist.
165      */
166     String getProperty(String key, String defaultValue);
167
168     /**
169      * Returns true if the named property is defined, false otherwise.
170      * 
171      * @param key
172      *            The key of the property we are interested in
173      * @return True if the property exists.
174      */
175     boolean isPropertyDefined(String key);
176
177     /**
178      * Returns an indication of the validity of the boolean property. A boolean property is considered to be valid only
179      * if it has the value "true" or "false" (ignoring case).
180      * 
181      * @param key
182      *            The property to be checked
183      * @return True if the value is a boolean constant, or false if it does not exist or is not a correct string
184      */
185     boolean isValidBoolean(String key);
186
187     /**
188      * Returns an indication if the indicated property represents a valid double-precision floating point number.
189      * 
190      * @param key
191      *            The property to be examined
192      * @return True if the property is a valid representation of a double, or false if it does not exist or contains
193      *         illegal characters.
194      */
195     boolean isValidDouble(String key);
196
197     /**
198      * Returns an indication if the property is a valid integer value or not.
199      * 
200      * @param key
201      *            The key of the property to check
202      * @return True if the value is a valid integer string, or false if it does not exist or contains illegal
203      *         characters.
204      */
205     boolean isValidInteger(String key);
206
207     /**
208      * Determines is the specified property exists and is a valid representation of an integer long value.
209      * 
210      * @param key
211      *            The property to be checked
212      * @return True if the property is a valid representation of an integer long value, and false if it either does not
213      *         exist or is not valid.
214      */
215     boolean isValidLong(String key);
216
217     /**
218      * This method allows the caller to set all properties from a provided properties object into the configuration
219      * property set.
220      * <p>
221      * The primary difference between this method and the factory method
222      * {@link ConfigurationFactory#getConfiguration(Properties)} is that this method does not clear and reload the
223      * configuration. Rather, this method merges the provided properties object contents into the existing properties,
224      * replacing any same-named keys with the values from this object.
225      * </p>
226      * 
227      * @param properties
228      *            The properties object to copy all properties from
229      */
230     void setProperties(Properties properties);
231
232     /**
233      * This method allows a caller to insert a new property definition into the configuration object. This allows the
234      * application to adjust or add to the current configuration. If the property already exists, it is replaced with
235      * the new value.
236      * 
237      * @param key
238      *            The key of the property to be defined
239      * @param value
240      *            The value of the property to be defined
241      */
242     void setProperty(String key, String value);
243 }