2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.config.persist.storage.directory.xml;
11 import com.google.common.base.Preconditions;
12 import com.google.common.base.Splitter;
13 import com.google.common.collect.Sets;
16 import org.opendaylight.controller.config.persist.api.Persister;
17 import org.opendaylight.controller.config.persist.api.PropertiesProvider;
18 import org.opendaylight.controller.config.persist.api.StorageAdapter;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * StorageAdapter that retrieves initial configuration from a directory. If multiple files are present, snapshot and
24 * required capabilities will be merged together. Writing to this persister is not supported.
26 public class XmlDirectoryStorageAdapter implements StorageAdapter {
27 private static final Logger LOG = LoggerFactory.getLogger(XmlDirectoryStorageAdapter.class);
29 public static final String DIRECTORY_STORAGE_PROP = "directoryStorage";
30 public static final String INCLUDE_EXT_PROP = "includeExtensions";
31 private static final char EXTENSIONS_SEPARATOR = ',';
35 public Persister instantiate(final PropertiesProvider propertiesProvider) {
36 String fileStorageProperty = propertiesProvider.getProperty(DIRECTORY_STORAGE_PROP);
37 Preconditions.checkNotNull(fileStorageProperty, "Unable to find " + propertiesProvider.getFullKeyForReporting(DIRECTORY_STORAGE_PROP));
38 File storage = new File(fileStorageProperty);
39 String fileExtensions = propertiesProvider.getProperty(INCLUDE_EXT_PROP);
41 LOG.debug("Using storage: {}", storage);
43 if(fileExtensions != null) {
44 LOG.debug("Using extensions: {}", fileExtensions);
45 return new XmlDirectoryPersister(storage, splitExtensions(fileExtensions));
47 return new XmlDirectoryPersister(storage);
51 private Set<String> splitExtensions(final String fileExtensions) {
52 return Sets.newHashSet(Splitter.on(EXTENSIONS_SEPARATOR).trimResults().omitEmptyStrings()
53 .split(fileExtensions));