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    * <h5 class='section'>See Also:</h5>
055    * <ul>
056    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_directory}
057    * </ul>
058    *
059    * @param value
060    *    The new value for this property.
061    *    <br>The default is <js>"."</js>.
062    * @return This object (for method chaining).
063    */
064   public ConfigFileStoreBuilder directory(String value) {
065      super.set(FILESTORE_directory, value);
066      return this;
067   }
068
069   /**
070    * Configuration property:  Local file system directory.
071    *
072    * <p>
073    * Identifies the path of the directory containing the configuration files.
074    *
075    * <h5 class='section'>See Also:</h5>
076    * <ul>
077    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_directory}
078    * </ul>
079    *
080    * @param value
081    *    The new value for this property.
082    *    <br>The default is <js>"."</js>.
083    * @return This object (for method chaining).
084    */
085   public ConfigFileStoreBuilder directory(File value) {
086      super.set(FILESTORE_directory, value);
087      return this;
088   }
089
090   /**
091    * Configuration property:  Charset.
092    *
093    * <p>
094    * Identifies the charset of external files.
095    *
096    * <h5 class='section'>See Also:</h5>
097    * <ul>
098    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_charset}
099    * </ul>
100    *
101    * @param value
102    *    The new value for this property.
103    *    <br>The default is <js>"."</js>.
104    * @return This object (for method chaining).
105    */
106   public ConfigFileStoreBuilder charset(String value) {
107      super.set(FILESTORE_charset, value);
108      return this;
109   }
110
111   /**
112    * Configuration property:  Charset.
113    *
114    * <p>
115    * Identifies the charset of external files.
116    *
117    * <h5 class='section'>See Also:</h5>
118    * <ul>
119    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_charset}
120    * </ul>
121    *
122    * @param value
123    *    The new value for this property.
124    *    <br>The default is <js>"."</js>.
125    * @return This object (for method chaining).
126    */
127   public ConfigFileStoreBuilder charset(Charset value) {
128      super.set(FILESTORE_charset, value);
129      return this;
130   }
131
132   /**
133    * Configuration property:  Use watcher.
134    *
135    * <p>
136    * Shortcut for calling <code>useWatcher(<jk>true</jk>)</code>.
137    *
138    * <h5 class='section'>See Also:</h5>
139    * <ul>
140    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_useWatcher}
141    * </ul>
142    *
143    * @return This object (for method chaining).
144    */
145   public ConfigFileStoreBuilder useWatcher() {
146      super.set(FILESTORE_useWatcher, true);
147      return this;
148   }
149
150   /**
151    * Configuration property:  Watcher sensitivity.
152    *
153    * <p>
154    * Determines how frequently the file system is polled for updates.
155    *
156    * <h5 class='section'>See Also:</h5>
157    * <ul>
158    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_watcherSensitivity}
159    * </ul>
160    *
161    * @param value
162    *    The new value for this property.
163    *    <br>The default is {@link WatcherSensitivity#MEDIUM}
164    * @return This object (for method chaining).
165    */
166   public ConfigFileStoreBuilder watcherSensitivity(WatcherSensitivity value) {
167      super.set(FILESTORE_watcherSensitivity, value);
168      return this;
169   }
170
171   /**
172    * Configuration property:  Update-on-write.
173    *
174    * <p>
175    * Shortcut for calling <code>useWatcher(<jk>true</jk>)</code>.
176    *
177    * <h5 class='section'>See Also:</h5>
178    * <ul>
179    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_updateOnWrite}
180    * </ul>
181    *
182    * @return This object (for method chaining).
183    */
184   public ConfigFileStoreBuilder updateOnWrite() {
185      super.set(FILESTORE_updateOnWrite, true);
186      return this;
187   }
188
189   /**
190    * Configuration property:  Watcher sensitivity.
191    *
192    * <p>
193    * Determines how frequently the file system is polled for updates.
194    *
195    * <h5 class='section'>See Also:</h5>
196    * <ul>
197    *    <li class='jf'>{@link ConfigFileStore#FILESTORE_watcherSensitivity}
198    * </ul>
199    *
200    * @param value
201    *    The new value for this property.
202    *    <br>The default is {@link WatcherSensitivity#MEDIUM}
203    * @return This object (for method chaining).
204    */
205   public ConfigFileStoreBuilder watcherSensitivity(String value) {
206      super.set(FILESTORE_watcherSensitivity, value);
207      return this;
208   }
209
210   @Override /* ContextBuilder */
211   public ConfigFileStore build() {
212      return new ConfigFileStore(getPropertyStore());
213   }
214}