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;
31 public final class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvider, SchemaService,
32 YangTextSourceProvider, AutoCloseable {
35 private final Set<ListenerRegistration<?>> listeners = new HashSet<>();
36 private final Object lock = new Object();
37 private final DOMSchemaService schemaService;
38 private final DOMYangTextSourceProvider yangProvider;
40 private GlobalBundleScanningSchemaServiceImpl(final DOMSchemaService schemaService) {
41 this.schemaService = Preconditions.checkNotNull(schemaService);
42 this.yangProvider = (DOMYangTextSourceProvider) schemaService.getSupportedExtensions()
43 .get(DOMYangTextSourceProvider.class);
46 public static GlobalBundleScanningSchemaServiceImpl createInstance(final DOMSchemaService schemaService) {
47 return new GlobalBundleScanningSchemaServiceImpl(schemaService);
51 public SchemaContext getSchemaContext() {
52 return schemaService.getGlobalContext();
56 public SchemaContext getGlobalContext() {
57 return schemaService.getGlobalContext();
61 public void addModule(final Module module) {
62 throw new UnsupportedOperationException();
66 public SchemaContext getSessionContext() {
67 throw new UnsupportedOperationException();
71 public void removeModule(final Module module) {
72 throw new UnsupportedOperationException();
76 public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(
77 final SchemaContextListener listener) {
79 final ListenerRegistration<SchemaContextListener> reg = schemaService.registerSchemaContextListener(
82 final ListenerRegistration<SchemaContextListener> ret =
83 new AbstractListenerRegistration<SchemaContextListener>(listener) {
85 protected void removeRegistration() {
87 listeners.remove(this);
100 synchronized (lock) {
101 for (ListenerRegistration<?> l : listeners) {
108 @SuppressWarnings("unchecked")
110 public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(
111 final SourceIdentifier sourceIdentifier) {
112 if (yangProvider == null) {
113 return Futures.immediateFailedCheckedFuture(new MissingSchemaSourceException(
114 "Source provider is not available", sourceIdentifier));
117 return (CheckedFuture<YangTextSchemaSource, SchemaSourceException>) yangProvider.getSource(sourceIdentifier);