2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
10 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
12 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
13 import java.io.InputStream;
14 import java.util.List;
15 import java.util.Collection;
16 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
17 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
18 import com.google.common.collect.ImmutableMap;
19 import java.util.EnumMap;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
22 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
23 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
24 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
25 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
27 public class CrossSourceStatementReactor {
29 private final Map<ModelProcessingPhase,StatementSupportBundle> supportedTerminology;
30 private final Map<ValidationBundleType,Collection<?>> supportedValidation;
32 CrossSourceStatementReactor(Map<ModelProcessingPhase, StatementSupportBundle> supportedTerminology) {
33 this.supportedTerminology = ImmutableMap.copyOf(supportedTerminology);
34 this.supportedValidation = ImmutableMap.of();
37 CrossSourceStatementReactor(Map<ModelProcessingPhase, StatementSupportBundle> supportedTerminology, Map<ValidationBundleType,Collection<?>> supportedValidation) {
38 this.supportedTerminology = ImmutableMap.copyOf(supportedTerminology);
39 this.supportedValidation = ImmutableMap.copyOf(supportedValidation);
42 public static final Builder builder() {
46 public final BuildAction newBuild() {
47 return new BuildAction();
50 public static class Builder implements org.opendaylight.yangtools.concepts.Builder<CrossSourceStatementReactor>{
52 final Map<ModelProcessingPhase,StatementSupportBundle> bundles = new EnumMap<>(ModelProcessingPhase.class);
53 final Map<ValidationBundleType,Collection<?>> validationBundles = new EnumMap<>(ValidationBundleType.class);
55 public Builder setBundle(ModelProcessingPhase phase,StatementSupportBundle bundle) {
56 bundles.put(phase, bundle);
61 public Builder setValidationBundle(
62 ValidationBundleType type,
63 Collection<?> validationBundle) {
64 validationBundles.put(type,validationBundle);
69 public CrossSourceStatementReactor build() {
70 return new CrossSourceStatementReactor(bundles, validationBundles);
75 public class BuildAction {
77 private final BuildGlobalContext context;
79 public BuildAction() {
80 this.context = new BuildGlobalContext(supportedTerminology, supportedValidation);
83 public void addSource(StatementStreamSource source) {
84 context.addSource(source);
87 public void addSources(StatementStreamSource... sources) {
88 for (StatementStreamSource source : sources) {
89 context.addSource(source);
93 public EffectiveModelContext build() throws SourceException, ReactorException {
94 return context.build();
97 public EffectiveSchemaContext buildEffective() throws SourceException, ReactorException {
98 return context.buildEffective();
101 public SchemaContext buildEffective(List<InputStream> yangInputStreams) throws SourceException, ReactorException {
103 for(InputStream yangInputStream : yangInputStreams) {
104 addSource(new YangStatementSourceImpl(yangInputStream));
107 return buildEffective();