6da4ee301263ffbcb72c5200fdea0b54ee87c3da
[yangtools.git] / yang / yang-model-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.util.concurrent.Futures;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.Collections;
14
15 /**
16  * A filter of schema sources. This is used to restrict which sources representation
17  * instances are allowed to participate in construction of a schema context. This
18  * allows, for example, to create an non-shared island, or require the sources to
19  * be certified before use.
20  */
21 @Beta
22 public interface SchemaSourceFilter {
23     /**
24      * A {@link SchemaSourceFilter} which accepts any schema source it is presented with.
25      */
26     public static final SchemaSourceFilter ALWAYS_ACCEPT = new SchemaSourceFilter() {
27         private final Iterable<Class<? extends SchemaSourceRepresentation>> REPRESENTATIONS =
28                 Collections.<Class<? extends SchemaSourceRepresentation>>singletonList(SchemaSourceRepresentation.class);
29
30         @Override
31         public Iterable<Class<? extends SchemaSourceRepresentation>> supportedRepresentations() {
32             return REPRESENTATIONS;
33         }
34
35         @Override
36         public ListenableFuture<Boolean> apply(final SchemaSourceRepresentation schemaSource) {
37             return Futures.immediateFuture(Boolean.TRUE);
38         }
39     };
40
41     /**
42      * Get the representations this filter supports. A schema source is translated
43      * into one of these representations before it is presented for filtering.
44      *
45      * @return Set of supported representations.
46      */
47     Iterable<Class<? extends SchemaSourceRepresentation>> supportedRepresentations();
48
49     /**
50      * Check if a particular schema source is acceptable to the filter. The process
51      * of checking may be asynchronous, but at some point it needs to produce an
52      * affirmative or negative answer before the schema context construction can
53      * proceed.
54      *
55      * @param schemaSource Schema source to be filtered
56      * @return Promise of a filtering decision. The result should be {@link Boolean#TRUE}
57      *         if the source is acceptable.
58      */
59     ListenableFuture<Boolean> apply(SchemaSourceRepresentation schemaSource);
60 }