2 * Copyright (c) 2015 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.yang.yanglib.impl;
12 import org.opendaylight.controller.config.api.JmxAttributeValidationException;
13 import org.opendaylight.yanglib.impl.YangLibProvider;
14 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
15 import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
16 import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 public class YanglibModule extends org.opendaylight.controller.config.yang.yanglib.impl.AbstractYanglibModule {
21 private static final Logger LOG = LoggerFactory.getLogger(YanglibModule.class);
23 public YanglibModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
24 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
25 super(identifier, dependencyResolver);
28 public YanglibModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
29 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
30 org.opendaylight.controller.config.yang.yanglib.impl.YanglibModule oldModule,
31 java.lang.AutoCloseable oldInstance) {
32 super(identifier, dependencyResolver, oldModule, oldInstance);
36 public void customValidation() {
37 JmxAttributeValidationException.checkNotNull(getCacheFolder(), cacheFolderJmxAttribute);
38 final File file = new File(getCacheFolder());
39 JmxAttributeValidationException
40 .checkCondition(file.exists(), "Non existing cache file", cacheFolderJmxAttribute);
41 JmxAttributeValidationException
42 .checkCondition(file.isDirectory(), "Non directory cache file", cacheFolderJmxAttribute);
46 public java.lang.AutoCloseable createInstance() {
47 // Start cache and Text to AST transformer
48 final SharedSchemaRepository repository = new SharedSchemaRepository("yang-library");
49 YangLibProvider provider = new YangLibProvider(repository, getBindingAddr(), getBindingPort());
51 final FilesystemSchemaSourceCache<YangTextSchemaSource> cache =
52 new FilesystemSchemaSourceCache<>(repository, YangTextSchemaSource.class, new File(getCacheFolder()));
53 repository.registerSchemaSourceListener(cache);
54 LOG.info("Starting yang library with sources from {}", getCacheFolder());
55 getBrokerDependency().registerProvider(provider);