Merge branch 'master' of ../controller
[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 static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ImmutableSet;
13 import java.util.Optional;
14 import java.util.Set;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
19
20 final class ContextHolder implements Immutable {
21     private final EffectiveModelContext context;
22     private final Set<Module> modules;
23     private final Set<SourceIdentifier> sources;
24
25     ContextHolder(final EffectiveModelContext context, final Set<Module> modules, final Set<SourceIdentifier> sources) {
26         this.context = requireNonNull(context);
27         this.modules = ImmutableSet.copyOf(modules);
28         this.sources = ImmutableSet.copyOf(sources);
29     }
30
31     EffectiveModelContext getContext() {
32         return context;
33     }
34
35     Set<Module> getYangModules() {
36         return modules;
37     }
38
39     Optional<String> moduleToResourcePath(final Module mod) {
40         final SourceIdentifier id = Util.moduleToIdentifier(mod);
41         return sources.contains(id)
42                 ? Optional.of("/" + YangToSourcesProcessor.META_INF_YANG_STRING_JAR + "/" + id.toYangFilename())
43                         : Optional.empty();
44     }
45 }