1 package org.opendaylight.yangtools.yang.model.util.repo;
3 import com.google.common.base.Optional;
4 import com.google.common.base.Preconditions;
5 import org.opendaylight.yangtools.concepts.Delegator;
9 * Utility Source Provider implementation which uses delegate to retrieve
10 * sources and transformation function to convert sources to different
15 * Representation of schema sources used by delegate
17 * Representation of schema sources exposed by this provider
19 * @deprecated Replaced with {@link org.opendaylight.yangtools.yang.model.repo.util.SchemaSourceTransformer}
22 public final class TransformingSourceProvider<I, O> implements //
23 AdvancedSchemaSourceProvider<O>, Delegator<AdvancedSchemaSourceProvider<I>> {
25 private final AdvancedSchemaSourceProvider<I> delegate;
26 private final SchemaSourceTransformation<I, O> transformation;
29 * Creates instance of transforming schema source provider which uses
30 * supplied delegate to retrieve sources and transformation to change
31 * sources to different representation.
34 * Delegate which provides sources.
35 * @param transformation
36 * Transformation function which converts sources
37 * @return Instance of TransformingSourceProvider
38 * @throws NullPointerException
39 * if any of arguments is null.
41 public static <I, O> TransformingSourceProvider<I, O> create(final AdvancedSchemaSourceProvider<I> delegate,
42 final SchemaSourceTransformation<I, O> transformation) {
43 return new TransformingSourceProvider<>(delegate, transformation);
46 private TransformingSourceProvider(final AdvancedSchemaSourceProvider<I> delegate,
47 final SchemaSourceTransformation<I, O> transformation) {
48 this.delegate = Preconditions.checkNotNull(delegate, "delegate must not be null");
49 this.transformation = Preconditions.checkNotNull(transformation, "transformation must not be null");
53 public AdvancedSchemaSourceProvider<I> getDelegate() {
58 public Optional<O> getSchemaSource(final SourceIdentifier sourceIdentifier) {
59 Optional<I> potentialSource = getDelegate().getSchemaSource(sourceIdentifier);
60 if (potentialSource.isPresent()) {
61 I inputSource = potentialSource.get();
62 return Optional.<O> of(transformation.transform(inputSource));
64 return Optional.absent();
68 public Optional<O> getSchemaSource(final String moduleName, final Optional<String> revision) {
69 return getSchemaSource(SourceIdentifier.create(moduleName, revision));