2 * Copyright (c) 2014 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
8 package org.opendaylight.controller.config.yang.md.sal.connector.netconf;
12 import org.opendaylight.controller.config.api.DependencyResolver;
13 import org.opendaylight.controller.config.api.DynamicMBeanWithInstance;
14 import org.opendaylight.controller.config.spi.Module;
15 import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
16 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
17 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
18 import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
19 import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
20 import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer;
21 import org.osgi.framework.BundleContext;
26 public class NetconfConnectorModuleFactory extends
27 org.opendaylight.controller.config.yang.md.sal.connector.netconf.AbstractNetconfConnectorModuleFactory {
29 // TODO this should be injected
30 // Netconf devices have separated schema registry + factory from controller
31 private final SharedSchemaRepository repository = new SharedSchemaRepository(NAME);
32 private final SchemaContextFactory schemaContextFactory
33 = repository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
35 public NetconfConnectorModuleFactory() {
36 // Start cache and Text to AST transformer
37 final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(repository, YangTextSchemaSource.class, new File("cache/schema"));
38 repository.registerSchemaSourceListener(cache);
39 repository.registerSchemaSourceListener(TextToASTTransformer.create(repository, repository));
43 public Module createModule(final String instanceName, final DependencyResolver dependencyResolver,
44 final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception {
45 final NetconfConnectorModule module = (NetconfConnectorModule) super.createModule(instanceName, dependencyResolver,
48 module.setSchemaRegistry(repository);
49 module.setSchemaContextFactory(schemaContextFactory);
54 public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, final BundleContext bundleContext) {
55 final NetconfConnectorModule module = (NetconfConnectorModule) super.createModule(instanceName, dependencyResolver,
57 module.setSchemaRegistry(repository);
58 module.setSchemaContextFactory(schemaContextFactory);