View Javadoc
1   /*
2    * Copyright 2012-2019 CodeLibs Project and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.codelibs.fess.ds;
17  
18  import java.util.ArrayList;
19  import java.util.Collections;
20  import java.util.LinkedHashMap;
21  import java.util.List;
22  import java.util.Map;
23  import java.util.Set;
24  
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  public class DataStoreFactory {
29      private static final Logger logger = LoggerFactory.getLogger(DataStoreFactory.class);
30  
31      protected Map<String, DataStore> dataStoreMap = new LinkedHashMap<>();
32  
33      public void add(final String name, final DataStore dataStore) {
34          if (name == null || dataStore == null) {
35              throw new IllegalArgumentException("name or dataStore is null.");
36          }
37          if (logger.isDebugEnabled()) {
38              logger.debug("Loaded " + name);
39          }
40          dataStoreMap.put(name, dataStore);
41      }
42  
43      public DataStore getDataStore(final String name) {
44          return dataStoreMap.get(name);
45      }
46  
47      public List<String> getDataStoreNameList() {
48          final Set<String> nameSet = dataStoreMap.keySet();
49          final List<String> nameList = new ArrayList<>();
50          nameList.addAll(nameSet);
51          Collections.sort(nameList);
52          return nameList;
53      }
54  
55  }