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