001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.config.store;
014
015import static org.apache.juneau.config.store.ConfigFileStore.*;
016
017import java.io.*;
018import java.nio.charset.*;
019
020import org.apache.juneau.*;
021
022/**
023 * Builder for {@link ConfigFileStore} objects.
024 */
025public class ConfigFileStoreBuilder extends ConfigStoreBuilder {
026
027   /**
028    * Constructor, default settings.
029    */
030   public ConfigFileStoreBuilder() {
031      super();
032   }
033
034   /**
035    * Constructor.
036    *
037    * @param ps The initial configuration settings for this builder.
038    */
039   public ConfigFileStoreBuilder(PropertyStore ps) {
040      super(ps);
041   }
042
043
044   //-----------------------------------------------------------------------------------------------------------------
045   // Properties
046   //-----------------------------------------------------------------------------------------------------------------
047
048   /**
049    * Configuration property:  Local file system directory.
050    *
051    * <p>
052    * Identifies the path of the directory containing the configuration files.
053    *
054    * <ul class='seealso'>
055    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_directory}
056    * </ul>
057    *
058    * @param value
059    *    The new value for this property.
060    *    <br>The default is <js>"."</js>.
061    * @return This object (for method chaining).
062    */
063   public ConfigFileStoreBuilder directory(String value) {
064      super.set(FILESTORE_directory, value);
065      return this;
066   }
067
068   /**
069    * Configuration property:  Local file system directory.
070    *
071    * <p>
072    * Identifies the path of the directory containing the configuration files.
073    *
074    * <ul class='seealso'>
075    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_directory}
076    * </ul>
077    *
078    * @param value
079    *    The new value for this property.
080    *    <br>The default is <js>"."</js>.
081    * @return This object (for method chaining).
082    */
083   public ConfigFileStoreBuilder directory(File value) {
084      super.set(FILESTORE_directory, value);
085      return this;
086   }
087
088   /**
089    * Configuration property:  Charset.
090    *
091    * <p>
092    * Identifies the charset of external files.
093    *
094    * <ul class='seealso'>
095    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_charset}
096    * </ul>
097    *
098    * @param value
099    *    The new value for this property.
100    *    <br>The default is <js>"."</js>.
101    * @return This object (for method chaining).
102    */
103   public ConfigFileStoreBuilder charset(String value) {
104      super.set(FILESTORE_charset, value);
105      return this;
106   }
107
108   /**
109    * Configuration property:  Charset.
110    *
111    * <p>
112    * Identifies the charset of external files.
113    *
114    * <ul class='seealso'>
115    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_charset}
116    * </ul>
117    *
118    * @param value
119    *    The new value for this property.
120    *    <br>The default is <js>"."</js>.
121    * @return This object (for method chaining).
122    */
123   public ConfigFileStoreBuilder charset(Charset value) {
124      super.set(FILESTORE_charset, value);
125      return this;
126   }
127
128   /**
129    * Configuration property:  Use watcher.
130    *
131    * <p>
132    * Shortcut for calling <code>useWatcher(<jk>true</jk>)</code>.
133    *
134    * <ul class='seealso'>
135    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_useWatcher}
136    * </ul>
137    *
138    * @return This object (for method chaining).
139    */
140   public ConfigFileStoreBuilder useWatcher() {
141      super.set(FILESTORE_useWatcher, true);
142      return this;
143   }
144
145   /**
146    * Configuration property:  Watcher sensitivity.
147    *
148    * <p>
149    * Determines how frequently the file system is polled for updates.
150    *
151    * <ul class='seealso'>
152    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_watcherSensitivity}
153    * </ul>
154    *
155    * @param value
156    *    The new value for this property.
157    *    <br>The default is {@link WatcherSensitivity#MEDIUM}
158    * @return This object (for method chaining).
159    */
160   public ConfigFileStoreBuilder watcherSensitivity(WatcherSensitivity value) {
161      super.set(FILESTORE_watcherSensitivity, value);
162      return this;
163   }
164
165   /**
166    * Configuration property:  Update-on-write.
167    *
168    * <p>
169    * Shortcut for calling <code>useWatcher(<jk>true</jk>)</code>.
170    *
171    * <ul class='seealso'>
172    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_updateOnWrite}
173    * </ul>
174    *
175    * @return This object (for method chaining).
176    */
177   public ConfigFileStoreBuilder updateOnWrite() {
178      super.set(FILESTORE_updateOnWrite, true);
179      return this;
180   }
181
182   /**
183    * Configuration property:  Watcher sensitivity.
184    *
185    * <p>
186    * Determines how frequently the file system is polled for updates.
187    *
188    * <ul class='seealso'>
189    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_watcherSensitivity}
190    * </ul>
191    *
192    * @param value
193    *    The new value for this property.
194    *    <br>The default is {@link WatcherSensitivity#MEDIUM}
195    * @return This object (for method chaining).
196    */
197   public ConfigFileStoreBuilder watcherSensitivity(String value) {
198      super.set(FILESTORE_watcherSensitivity, value);
199      return this;
200   }
201
202   /**
203    * Configuration property:  File extensions.
204    *
205    * <p>
206    * Defines what file extensions to search for when the config name does not have an extension.
207    *
208    * @param value
209    *    The new value for this property.
210    *    <br>The default is <js>"cfg"</js>.
211    * @return This object (for method chaining).
212    */
213   public ConfigFileStoreBuilder extensions(String value) {
214      super.set(FILESTORE_extensions, value);
215      return this;
216   }
217
218   @Override /* ContextBuilder */
219   public ConfigFileStore build() {
220      return new ConfigFileStore(getPropertyStore());
221   }
222}