Promote SchemaSourceRepresentation
[yangtools.git] / yang / yang-repo-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / SchemaSourceFilter.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.repo.api;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableList;
12 import com.google.common.util.concurrent.FluentFuture;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
16 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
17
18 /**
19  * A filter of schema sources. This is used to restrict which sources representation instances are allowed
20  * to participate in construction of a schema context. This allows, for example, to create an non-shared island,
21  * or require the sources to be certified before use.
22  */
23 @Beta
24 public interface SchemaSourceFilter {
25     /**
26      * A {@link SchemaSourceFilter} which accepts any schema source it is presented with.
27      */
28     @NonNull SchemaSourceFilter ALWAYS_ACCEPT = new SchemaSourceFilter() {
29         private final ImmutableList<Class<? extends SourceRepresentation>> representations =
30                 ImmutableList.of(SourceRepresentation.class);
31
32         @Override
33         public ImmutableList<Class<? extends SourceRepresentation>> supportedRepresentations() {
34             return representations;
35         }
36
37         @Override
38         public FluentFuture<Boolean> apply(final SourceRepresentation schemaSource) {
39             return FluentFutures.immediateTrueFluentFuture();
40         }
41     };
42
43     /**
44      * Get the representations this filter supports. A schema source is translated
45      * into one of these representations before it is presented for filtering.
46      *
47      * @return Set of supported representations.
48      */
49     Iterable<Class<? extends SourceRepresentation>> supportedRepresentations();
50
51     /**
52      * Check if a particular schema source is acceptable to the filter. The process
53      * of checking may be asynchronous, but at some point it needs to produce an
54      * affirmative or negative answer before the schema context construction can
55      * proceed.
56      *
57      * @param schemaSource Schema source to be filtered
58      * @return Promise of a filtering decision. The result should be {@link Boolean#TRUE}
59      *         if the source is acceptable.
60      */
61     ListenableFuture<Boolean> apply(SourceRepresentation schemaSource);
62 }