Remove yang-test
[controller.git] / opendaylight / config / config-persister-directory-xml-adapter / src / main / java / org / opendaylight / controller / config / persist / storage / directory / xml / XmlDirectoryStorageAdapter.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.persist.storage.directory.xml;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.base.Splitter;
13 import com.google.common.collect.Sets;
14
15 import java.io.File;
16 import java.util.Set;
17
18 import org.opendaylight.controller.config.persist.api.Persister;
19 import org.opendaylight.controller.config.persist.api.PropertiesProvider;
20 import org.opendaylight.controller.config.persist.api.StorageAdapter;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  * StorageAdapter that retrieves initial configuration from a directory. If multiple files are present, snapshot and
26  * required capabilities will be merged together. Writing to this persister is not supported.
27  */
28 public class XmlDirectoryStorageAdapter implements StorageAdapter {
29     private static final Logger LOG = LoggerFactory.getLogger(XmlDirectoryStorageAdapter.class);
30
31     public static final String DIRECTORY_STORAGE_PROP = "directoryStorage";
32     public static final String INCLUDE_EXT_PROP = "includeExtensions";
33     private static final char EXTENSIONS_SEPARATOR = ',';
34
35     @Override
36     public Persister instantiate(final PropertiesProvider propertiesProvider) {
37         String fileStorageProperty = propertiesProvider.getProperty(DIRECTORY_STORAGE_PROP);
38         Preconditions.checkNotNull(fileStorageProperty,
39                 "Unable to find " + propertiesProvider.getFullKeyForReporting(DIRECTORY_STORAGE_PROP));
40         File storage = new File(fileStorageProperty);
41         String fileExtensions = propertiesProvider.getProperty(INCLUDE_EXT_PROP);
42
43         LOG.debug("Using storage: {}", storage);
44
45         if (fileExtensions != null) {
46             LOG.debug("Using extensions: {}", fileExtensions);
47             return new XmlDirectoryPersister(storage, splitExtensions(fileExtensions));
48         } else {
49             return new XmlDirectoryPersister(storage);
50         }
51     }
52
53     private Set<String> splitExtensions(final String fileExtensions) {
54         return Sets.newHashSet(Splitter.on(EXTENSIONS_SEPARATOR).trimResults().omitEmptyStrings()
55                 .split(fileExtensions));
56     }
57 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.