BUG-7568: Use YangTextSchemaSource to emit schema files
[yangtools.git] / yang / yang-maven-plugin / src / main / java / org / opendaylight / yangtools / yang2sources / plugin / ContextHolder.java
1 /*
2  * Copyright (c) 2013 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.yang2sources.plugin;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Optional;
13 import java.util.Set;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
18
19 final class ContextHolder implements Immutable {
20     private final SchemaContext context;
21     private final Set<Module> modules;
22     private final Set<SourceIdentifier> sources;
23
24     ContextHolder(final SchemaContext context, final Set<Module> modules, final Set<SourceIdentifier> sources) {
25         this.context = Preconditions.checkNotNull(context);
26         this.modules = ImmutableSet.copyOf(modules);
27         this.sources = ImmutableSet.copyOf(sources);
28     }
29
30     SchemaContext getContext() {
31         return context;
32     }
33
34     Set<Module> getYangModules() {
35         return modules;
36     }
37
38     Optional<String> moduleToResourcePath(final Module mod) {
39         final SourceIdentifier id = Util.moduleToIdentifier(mod);
40         return sources.contains(id)
41                 ? Optional.of("/" + YangToSourcesProcessor.META_INF_YANG_STRING_JAR + "/" + id.toYangFilename())
42                         : Optional.empty();
43     }
44 }