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
8 package org.opendaylight.controller.sal.schema.service.impl;
10 import com.google.common.base.Preconditions;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.Futures;
13 import java.util.HashSet;
15 import javax.annotation.concurrent.GuardedBy;
16 import org.opendaylight.controller.sal.core.api.model.SchemaService;
17 import org.opendaylight.controller.sal.core.api.model.YangTextSourceProvider;
18 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
19 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
20 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
21 import org.opendaylight.yangtools.concepts.ListenerRegistration;
22 import org.opendaylight.yangtools.yang.model.api.Module;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
26 import org.opendaylight.yangtools.yang.model.repo.api.MissingSchemaSourceException;
27 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
28 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
29 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
32 public final class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvider, SchemaService,
33 YangTextSourceProvider, AutoCloseable {
36 private final Set<ListenerRegistration<?>> listeners = new HashSet<>();
37 private final Object lock = new Object();
38 private final DOMSchemaService schemaService;
39 private final DOMYangTextSourceProvider yangProvider;
41 private GlobalBundleScanningSchemaServiceImpl(final DOMSchemaService schemaService) {
42 this.schemaService = Preconditions.checkNotNull(schemaService);
43 this.yangProvider = (DOMYangTextSourceProvider) schemaService.getSupportedExtensions()
44 .get(DOMYangTextSourceProvider.class);
47 public static GlobalBundleScanningSchemaServiceImpl createInstance(final DOMSchemaService schemaService) {
48 return new GlobalBundleScanningSchemaServiceImpl(schemaService);
52 public SchemaContext getSchemaContext() {
53 return schemaService.getGlobalContext();
57 public SchemaContext getGlobalContext() {
58 return schemaService.getGlobalContext();
62 public void addModule(final Module module) {
63 throw new UnsupportedOperationException();
67 public SchemaContext getSessionContext() {
68 throw new UnsupportedOperationException();
72 public void removeModule(final Module module) {
73 throw new UnsupportedOperationException();
77 public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
78 final SchemaContextListener listener) {
80 final ListenerRegistration<SchemaContextListener> reg = schemaService.registerSchemaContextListener(
83 final ListenerRegistration<SchemaContextListener> ret =
84 new AbstractListenerRegistration<SchemaContextListener>(listener) {
86 protected void removeRegistration() {
88 listeners.remove(this);
100 public void close() {
101 synchronized (lock) {
102 for (ListenerRegistration<?> l : listeners) {
109 @SuppressWarnings("unchecked")
111 public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(
112 final SourceIdentifier sourceIdentifier) {
113 if (yangProvider == null) {
114 return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException(
115 "Source provider is not available", sourceIdentifier));
118 return (CheckedFuture<YangTextSchemaSource, SchemaSourceException>) yangProvider.getSource(sourceIdentifier);