BUG-1469: introduce ReflectiveExceptionMapper
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / repo / api / AcceptingSchemaSourceFilter.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/eplv10.html
7  */
8 package org.opendaylight.yangtools.yang.model.repo.api;
9
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableList.Builder;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14
15 /**
16  * A {@link SchemaSourceFilter} which accepts any schema source it is presented with.
17  */
18 public final class AcceptingSchemaSourceFilter implements SchemaSourceFilter {
19     private static final AcceptingSchemaSourceFilter INSTANCE = new AcceptingSchemaSourceFilter();
20
21     private final Iterable<Class<? extends SchemaSourceRepresentation>> representations;
22
23     private AcceptingSchemaSourceFilter() {
24         final Builder<Class<? extends SchemaSourceRepresentation>> b = ImmutableList.builder();
25         b.add(SchemaSourceRepresentation.class);
26         representations = b.build();
27     }
28
29     /**
30      * Return the singleton instance of this filter.
31      *
32      * @return Singleton shared instance.
33      */
34     public static final AcceptingSchemaSourceFilter getSingletonInstance() {
35         return INSTANCE;
36     }
37
38     @Override
39     public Iterable<Class<? extends SchemaSourceRepresentation>> supportedRepresentations() {
40         return representations;
41     }
42
43     @Override
44     public ListenableFuture<Boolean> apply(final SchemaSourceRepresentation schemaSource) {
45         return Futures.immediateFuture(Boolean.TRUE);
46     }
47 }