Bug 2366 - new parser API - implementation of declared statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / BuildGlobalContext.java
index 7bfee3471b203a750190448748300b2269dcc31b..cb0dd2c3437cf505d86b9ad120de14603bd7be09 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
+
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableList;
@@ -60,6 +63,10 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh
         this.supports = supports;
     }
 
+    public StatementSupportBundle getSupportsForPhase(ModelProcessingPhase currentPhase) {
+        return supports.get(currentPhase);
+    }
+
     public void addSource(@Nonnull StatementStreamSource source) {
         sources.add(new SourceSpecificContext(this,source));
     }
@@ -135,6 +142,32 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh
         return new EffectiveModelContext(rootStatements);
     }
 
+    public EffectiveSchemaContext buildEffective() throws SourceException, ReactorException {
+        for(ModelProcessingPhase phase : PHASE_EXECUTION_ORDER) {
+            startPhase(phase);
+            loadPhaseStatements();
+            completePhaseActions();
+            endPhase(phase);
+        }
+        return transformEffective();
+    }
+
+    private EffectiveSchemaContext transformEffective() {
+        Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL);
+        List<DeclaredStatement<?>> rootStatements = new ArrayList<>();
+        List<EffectiveStatement<?,?>> rootEffectiveStatements = new ArrayList<>();
+
+        for(SourceSpecificContext source : sources) {
+            DeclaredStatement<?> root = source.getRoot().buildDeclared();
+            rootStatements.add(root);
+
+            EffectiveStatement<?,?> rootEffective = source.getRoot().buildEffective();
+            rootEffectiveStatements.add(rootEffective);
+        }
+
+        return new EffectiveSchemaContext(rootStatements,rootEffectiveStatements);
+    }
+
     private void startPhase(ModelProcessingPhase phase) {
         Preconditions.checkState(Objects.equals(finishedPhase, phase.getPreviousPhase()));
         for(SourceSpecificContext source : sources) {