001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *        http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 */
019
020package org.apache.isis.core.commons.config;
021
022import java.awt.Color;
023import java.awt.Font;
024import java.util.Iterator;
025import java.util.Map;
026
027import org.apache.isis.core.commons.components.Injectable;
028import org.apache.isis.core.commons.debug.DebuggableWithTitle;
029import org.apache.isis.core.commons.resource.ResourceStreamSource;
030
031/**
032 * Immutable set of properties representing the configuration of the running
033 * system.
034 * 
035 * <p>
036 * The {@link IsisConfiguration} is one part of a mutable/immutable pair pattern
037 * (cf {@link String} and {@link StringBuilder}). What this means is, as
038 * components are loaded they can discover their own configuration resources.
039 * These are added to {@link IsisConfigurationBuilder}.
040 * 
041 * <p>
042 * Thus the {@link IsisConfiguration} held by different components may vary, but
043 * with each being a possible superset of the previous.
044 */
045public interface IsisConfiguration extends DebuggableWithTitle, Injectable, Iterable<String> {
046
047    /**
048     * Creates a new IsisConfiguration containing the properties starting with
049     * the specified prefix. The names of the new properties will have the
050     * prefixed stripped. This is similar to the {@link #getProperties(String)}
051     * method, except the property names have their prefixes removed.
052     * 
053     * @see #getProperties(String)
054     */
055    IsisConfiguration createSubset(String prefix);
056
057    /**
058     * Gets the boolean value for the specified name where no value or 'on' will
059     * result in true being returned; anything gives false. If no boolean
060     * property is specified with this name then false is returned.
061     * 
062     * @param name
063     *            the property name
064     */
065    boolean getBoolean(String name);
066
067    /**
068     * Gets the boolean value for the specified name. If no property is
069     * specified with this name then the specified default boolean value is
070     * returned.
071     * 
072     * @param name
073     *            the property name
074     * @param defaultValue
075     *            the value to use as a default
076     */
077    boolean getBoolean(String name, boolean defaultValue);
078
079    /**
080     * Gets the color for the specified name. If no color property is specified
081     * with this name then null is returned.
082     * 
083     * @param name
084     *            the property name
085     */
086    Color getColor(String name);
087
088    /**
089     * Gets the color for the specified name. If no color property is specified
090     * with this name then the specified default color is returned.
091     * 
092     * @param name
093     *            the property name
094     * @param defaultValue
095     *            the value to use as a default
096     */
097    Color getColor(String name, Color defaultValue);
098
099    /**
100     * Gets the font for the specified name. If no font property is specified
101     * with this name then null is returned.
102     * 
103     * @param name
104     *            the property name
105     */
106    Font getFont(String name);
107
108    /**
109     * Gets the font for the specified name. If no font property is specified
110     * with this name then the specified default font is returned.
111     * 
112     * @param name
113     *            the property name
114     * @param defaultValue
115     *            the color to use as a default
116     */
117    Font getFont(String name, Font defaultValue);
118
119    /**
120     * Returns a list of entries for the single configuration property with the
121     * specified name.
122     * 
123     * <p>
124     * If there is no matching property then returns an empty array.
125     */
126    String[] getList(String name);
127
128    /**
129     * Gets the number value for the specified name. If no property is specified
130     * with this name then 0 is returned.
131     * 
132     * @param name
133     *            the property name
134     */
135    int getInteger(String name);
136
137    /**
138     * Gets the number value for the specified name. If no property is specified
139     * with this name then the specified default number value is returned.
140     * 
141     * @param name
142     *            the property name
143     * @param defaultValue
144     *            the value to use as a default
145     */
146    int getInteger(String name, int defaultValue);
147
148    /**
149     * Creates a new IsisConfiguration containing the properties starting with
150     * the specified prefix. The names of the properties in the copy are the
151     * same as in the original, ie the prefix is not removed. This is similar to
152     * the {@link #createSubset(String)} method except the names of the
153     * properties are not altered when copied.
154     * 
155     * @see #createSubset(String)
156     */
157    IsisConfiguration getProperties(String withPrefix);
158
159    /**
160     * Returns the configuration property with the specified name. If there is
161     * no matching property then null is returned.
162     */
163    String getString(String name);
164
165    String getString(String name, String defaultValue);
166
167    boolean hasProperty(String name);
168
169    boolean isEmpty();
170
171    /**
172     * Iterates over the property names of this configuration.
173     */
174    @Override
175    Iterator<String> iterator();
176
177    int size();
178
179    /**
180     * The {@link ResourceStreamSource} that was used to build this
181     * configuration.
182     * 
183     * @see IsisConfigurationBuilder#getResourceStreamSource()
184     */
185    ResourceStreamSource getResourceStreamSource();
186
187    /**
188     * A mutable copy of the current set of properties (name/values) held in this configuration.
189     */
190    Map<String, String> asMap();
191
192}