06ae43adce10e9ef5cb88bf33dcecdcd16a1889d
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / CrossSourceStatementReactor.java
1 /*
2  * Copyright (c) 2015 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.yang.parser.stmt.reactor;
9
10 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
11
12 import com.google.common.collect.ImmutableMap;
13 import java.util.EnumMap;
14 import java.util.Map;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle;
18 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
19 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
20
21 public class CrossSourceStatementReactor {
22
23     private final Map<ModelProcessingPhase,StatementSupportBundle> supportedTerminology;
24
25     CrossSourceStatementReactor(Map<ModelProcessingPhase, StatementSupportBundle> supportedTerminology) {
26         this.supportedTerminology = ImmutableMap.copyOf(supportedTerminology);
27     }
28
29     public static final Builder builder() {
30         return new Builder();
31     }
32
33     public final BuildAction newBuild() {
34         return new BuildAction();
35     }
36
37     public static class Builder implements org.opendaylight.yangtools.concepts.Builder<CrossSourceStatementReactor>{
38
39         final Map<ModelProcessingPhase,StatementSupportBundle> bundles = new EnumMap<>(ModelProcessingPhase.class);
40
41         public Builder setBundle(ModelProcessingPhase phase,StatementSupportBundle bundle) {
42             bundles.put(phase, bundle);
43             return this;
44         }
45
46         @Override
47         public CrossSourceStatementReactor build() {
48             return new CrossSourceStatementReactor(bundles);
49         }
50
51     }
52
53     public class BuildAction {
54
55         private final BuildGlobalContext context;
56
57         public BuildAction() {
58             this.context = new BuildGlobalContext(supportedTerminology);
59         }
60
61         public void addSource(StatementStreamSource source) {
62             context.addSource(source);
63         }
64
65         public EffectiveModelContext build() throws SourceException, ReactorException {
66             return context.build();
67         }
68
69         public EffectiveSchemaContext buildEffective() throws SourceException, ReactorException {
70             return context.buildEffective();
71         }
72
73     }
74
75
76 }