*/
package org.opendaylight.mdsal.dom.api;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-public interface DOMSchemaService extends DOMService {
-
+public interface DOMSchemaService extends DOMExtensibleService<DOMSchemaService, DOMSchemaServiceExtension> {
/**
* Returns session specific YANG schema context
* @return
* @return Listener registration handle
*/
ListenerRegistration<SchemaContextListener> registerSchemaContextListener(SchemaContextListener listener);
+
+ @Override
+ default Map<Class<? extends DOMSchemaServiceExtension>, DOMSchemaServiceExtension> getSupportedExtensions() {
+ return ImmutableMap.of();
+ }
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.dom.api;
+
+import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+
+/**
+ * A DOMSchemaServiceExtension exposing access to {@link YangTextSchemaSource}. Instances of this method should be
+ * acquired from {@link DOMSchemaService}.
+ */
+@Beta
+public interface DOMYangTextSourceProvider extends DOMSchemaServiceExtension,
+ SchemaSourceProvider<YangTextSchemaSource> {
+
+}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
+import com.google.common.util.concurrent.CheckedFuture;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
+import javax.annotation.Nonnull;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaServiceExtension;
+import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.util.ListenerRegistry;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.LoggerFactory;
public class OsgiBundleScanningSchemaService implements SchemaContextProvider, DOMSchemaService,
- ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, AutoCloseable {
+ ServiceTrackerCustomizer<SchemaContextListener, SchemaContextListener>, DOMYangTextSourceProvider,
+ AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(OsgiBundleScanningSchemaService.class);
private static final AtomicReference<OsgiBundleScanningSchemaService> GLOBAL_INSTANCE = new AtomicReference<>();
this.context = Preconditions.checkNotNull(context);
}
- public static OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
+ public static @Nonnull OsgiBundleScanningSchemaService createInstance(final BundleContext ctx) {
OsgiBundleScanningSchemaService instance = new OsgiBundleScanningSchemaService(ctx);
Preconditions.checkState(GLOBAL_INSTANCE.compareAndSet(null, instance));
instance.start();
final SchemaContextListener service) {
context.ungetService(reference);
}
+
+ @Override
+ public Map<Class<? extends DOMSchemaServiceExtension>, DOMSchemaServiceExtension> getSupportedExtensions() {
+ return ImmutableMap.of(DOMYangTextSourceProvider.class, this);
+ }
+
+ @Override
+ public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(
+ final SourceIdentifier sourceIdentifier) {
+ return contextResolver.getSource(sourceIdentifier);
+ }
}
import org.osgi.framework.ServiceRegistration;
public class SchemaServiceActivator implements BundleActivator {
-
-
private ServiceRegistration<DOMSchemaService> schemaServiceReg;
private OsgiBundleScanningSchemaService schemaService;
public void start(final BundleContext context) {
schemaService = OsgiBundleScanningSchemaService.createInstance(context);
schemaServiceReg = context.registerService(DOMSchemaService.class,
- schemaService, new Hashtable<String,String>());
+ schemaService, new Hashtable<>());
}
@Override
- public void stop(final BundleContext context) throws Exception {
+ public void stop(final BundleContext context) {
schemaServiceReg.unregister();
schemaService.close();
}