View Javadoc

1   /*
2    * Copyright 2008-2010 Digital Enterprise Research Institute (DERI)
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *          http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.deri.any23.configuration;
18  
19  /**
20   * Defines the main <i>Any23</code> configuration.
21   */
22  public interface Configuration {
23    /**
24       * Returns all the defined configuration properties.
25       *
26       * @return list of defined properties.
27       */
28      String[] getProperties();
29  
30      /**
31       * Checks whether a property is defined or not in configuration.
32       *
33       * @param propertyName name of property to check.
34       * @return <code>true</code> if defined, </code>false</code> otherwise.
35       */
36      boolean defineProperty(String propertyName);
37  
38      /**
39       * Returns the value of a specified property, of the default value if property is not defined.
40       *
41       * @param propertyName name of property
42       * @param defaultValue default value if not found.
43       * @return the value associated to <i>propertyName</i>.
44       */
45      String getProperty(String propertyName, String defaultValue);
46  
47      /**
48       * Returns the value of the specified <code>propertyName</code> or raises an exception
49       * if <code>propertyName</code> is not defined.
50       *
51       * @param propertyName name of property to be returned.
52       * @return property value.
53       * @throws IllegalArgumentException if the property name is not defined
54       *                                  or the found property value is blank or empty.
55       */
56      String getPropertyOrFail(String propertyName);
57  
58      /**
59       * Returns the {@link Integer} value of the specified <code>propertyName</code> or raises an exception
60       * if <code>propertyName</code> is not defined.
61       *
62       * @param propertyName name of property to be returned.
63       * @return property value.
64       * @throws NullPointerException if the property name is not defined.
65       * @throws IllegalArgumentException if the found property value is blank or empty.
66       * @throws NumberFormatException if the found property value is not a valid {@link Integer}.
67       */
68      int getPropertyIntOrFail(String propertyName);
69  
70      /**
71       * Returns the value of a <i> flag property</i>. Such properties can assume only two values:
72       * <ul>
73       *     <li><code>on</code>  if flag is active   (<code>true</code> is returned).
74       *     <li><code>off</code> if flag is inactive (<code>false</code> is returned).
75       * </ul>
76       *
77       * @param propertyName name of property flag.
78       * @return <code>true</code> for <code>on</code>, <code>false</code> for <code>off</code>.
79       * @throws IllegalArgumentException if the <code>propertyName</code> is not declared.
80       */
81      boolean getFlagProperty(final String propertyName);
82  
83      /**
84       * Returns a human readable string containing the configuration dump.
85       *
86       * @return a string describing the configuration options.
87       */
88      String getConfigurationDump();
89  
90  }