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;
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;
}
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;
}
}
@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;
}
}
- 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
@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);
}
@Override
public void apply(final InferenceAction action) throws InferenceException {
this.action = Preconditions.checkNotNull(action);
- tryToResolve();
}
private abstract class AbstractPrerequisite<T> implements Prerequisite<T> {
protected boolean resolvePrereq(final T value) throws InferenceException {
this.value = value;
this.done = true;
- tryToResolve();
return isApplied();
}
@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