Revert "Revert "Updated SchemaNodeIdentifier namespace handling.""
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / ModifierImpl.java
index 1c719722373d92a319cfdab345b6161e057176e1..254b65c76b741cc591469ab7614da9ef6402952b 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
 import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.EFFECTIVE_MODEL;
 import static org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase.FULL_DECLARATION;
+
 import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
 import java.util.HashSet;
@@ -62,16 +63,6 @@ class ModifierImpl implements ModelActionBuilder {
         return new IllegalStateException("Source exception during registering prerequisite. This is probably bug.",e);
     }
 
-    private void tryToResolve() throws InferenceException {
-        if(action == null || isApplied()) {
-            // Action was not yet defined
-            return;
-        }
-        if(removeSatisfied()) {
-            applyAction();
-        }
-    }
-
     private boolean removeSatisfied() {
         Iterator<AbstractPrerequisite<?>> prereq = unsatisfied.iterator();
         boolean allSatisfied = true;
@@ -102,14 +93,8 @@ class ModifierImpl implements ModelActionBuilder {
     }
 
     private void applyAction() throws InferenceException {
-
-        try {
-            action.apply();
-        } catch (InferenceException e) {
-            actionApplied = false;
-            return;
-        }
-        //  Mark all mutations as performed, so context node could move to next.
+        Preconditions.checkState(!actionApplied);
+        action.apply();
         actionApplied = true;
     }
 
@@ -139,10 +124,11 @@ class ModifierImpl implements ModelActionBuilder {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    private <K, C extends StmtContext.Mutable<?, ?, ?> , N extends StatementNamespace<K, ?, ? >> AbstractPrerequisite<C> mutatesCtxImpl(
+    private <K, C extends StmtContext.Mutable<?, ?, ?> , N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>> AbstractPrerequisite<C> mutatesCtxImpl(
                 final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key, final ModelProcessingPhase phase) {
             try {
                 PhaseModificationInNamespace<C> mod = new PhaseModificationInNamespace<C>(phase);
+                addReq(mod);
                 addMutation(mod);
                 contextImpl(context).onNamespaceItemAddedAction((Class) namespace,key,mod);
                 return mod;
@@ -151,9 +137,19 @@ class ModifierImpl implements ModelActionBuilder {
             }
         }
 
-    private static StatementContextBase<?,?,?> contextImpl(final StmtContext<?,?,?> context) {
-        Preconditions.checkArgument(context instanceof StatementContextBase,"Supplied context was not provided by this reactor.");
-        return StatementContextBase.class.cast(context);
+    private static StatementContextBase<?,?,?> contextImpl(final Object value) {
+        Preconditions.checkArgument(value instanceof StatementContextBase,"Supplied context was not provided by this reactor.");
+        return StatementContextBase.class.cast(value);
+    }
+
+    boolean tryApply() {
+        Preconditions.checkState(action != null, "Action was not defined yet.");
+
+        if (removeSatisfied()) {
+            applyAction();
+            return true;
+        }
+        return false;
     }
 
     @Override
@@ -230,7 +226,7 @@ class ModifierImpl implements ModelActionBuilder {
 
 
    @Override
-    public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>> AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(
+    public <K, E extends EffectiveStatement<?, ?>, N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>> AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(
             final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key) {
         return mutatesCtxImpl(context, namespace, key, EFFECTIVE_MODEL);
     }
@@ -240,7 +236,6 @@ class ModifierImpl implements ModelActionBuilder {
     @Override
     public void apply(final InferenceAction action) throws InferenceException {
         this.action = Preconditions.checkNotNull(action);
-        tryToResolve();
     }
 
     private abstract class AbstractPrerequisite<T> implements Prerequisite<T> {
@@ -262,7 +257,6 @@ class ModifierImpl implements ModelActionBuilder {
         protected boolean resolvePrereq(final T value) throws InferenceException {
             this.value = value;
             this.done = true;
-            tryToResolve();
             return isApplied();
         }
 
@@ -353,8 +347,9 @@ class ModifierImpl implements ModelActionBuilder {
         @Override
         public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace, final Object key,
                 final Object value) throws SourceException {
-            context.addMutation(modPhase,this);
-            resolvePrereq((C) context);
+            StatementContextBase<?, ?, ?> targetCtx = contextImpl(value);
+            targetCtx.addMutation(modPhase,this);
+            resolvePrereq((C) targetCtx);
         }
 
         @Override