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