Revert "Updated SchemaNodeIdentifier namespace handling." 50/27850/1
authorTony Tkacik <ttkacik@cisco.com>
Fri, 2 Oct 2015 22:33:46 +0000 (22:33 +0000)
committerTony Tkacik <ttkacik@cisco.com>
Fri, 2 Oct 2015 22:33:46 +0000 (22:33 +0000)
This reverts commit b6e9bb9ff439eb0e905d8ccf61e15a5a3b2bf444.

Change-Id: I927dc1a9973ab36e7bc54c823e93fd00b240d123
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
24 files changed:
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java [deleted file]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/ModelActionBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModifierImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/NamespaceBehaviourWithListeners.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SimpleNamespaceContext.java [deleted file]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/StatementContextBase.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/VirtualNamespaceContext.java [deleted file]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/AugmentUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ChildSchemaNodes.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SchemaNodeIdentifierBuildNamespace.java [deleted file]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UsesStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/Utils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/test/AugmentProcessTest.java
yang/yang-parser-impl/src/test/resources/model-new/foo.yang
yang/yang-parser-impl/src/test/resources/model-new/subfoo.yang
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-imported.yang
yang/yang-parser-impl/src/test/resources/stmt-test/augments/multiple-augment-root.yang

diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/DerivedNamespaceBehaviour.java
deleted file mode 100644 (file)
index 03dbfa8..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.spi.meta;
-
-import com.google.common.base.Preconditions;
-import java.util.Map;
-import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
-
-public abstract class DerivedNamespaceBehaviour<K, V, N extends IdentifierNamespace<K, V>, T extends IdentifierNamespace<?, ?>>
-        extends NamespaceBehaviour<K, V, N> {
-
-    private Class<T> derivedFrom;
-
-    protected DerivedNamespaceBehaviour(Class<N> identifier, Class<T> derivedFrom) {
-        super(identifier);
-        this.derivedFrom = Preconditions.checkNotNull(derivedFrom);
-    }
-
-    public Class<T> getDerivedFrom() {
-        return derivedFrom;
-    }
-
-    @Override
-    public Map<K, V> getAllFrom(NamespaceStorageNode storage) {
-        throw new UnsupportedOperationException("Virtual namespaces does not support provision of all items.");
-    }
-
-    @Override
-    public abstract V getFrom(NamespaceBehaviour.NamespaceStorageNode storage, K key);
-
-    @Override
-    public void addTo(NamespaceStorageNode storage, K key, V value) {
-        // Intentional noop
-    }
-}
index 54605dbc67961e55fc9d78b7f38adf8d1a32571e..41d22500e432eb3acb41ae7f7f58d1c05c92d39f 100644 (file)
@@ -151,7 +151,7 @@ public interface ModelActionBuilder {
 
     @Nonnull <T extends Mutable<?,?,?>> Prerequisite<T> mutatesEffectiveCtx(T stmt);
 
-    @Nonnull  <K,E extends EffectiveStatement<?,?>, N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>> Prerequisite<Mutable<?,?,E>> mutatesEffectiveCtx(StmtContext<?,?,?> context,Class<N> namespace, K key);
+    @Nonnull  <K,E extends EffectiveStatement<?,?>,N extends StatementNamespace<K, ?, ? extends E>> Prerequisite<Mutable<?,?,E>> mutatesEffectiveCtx(StmtContext<?,?,?> context,Class<N> namespace, K key);
 
     void apply(InferenceAction action) throws InferenceException;
 
index 53c12ccd5712e14940d51c60c8f87e34e29625c7..6d156b1c837f2eb75f1001bf1439848309030b59 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
 public abstract class NamespaceBehaviour<K, V, N extends IdentifierNamespace<K, V>> implements Identifiable<Class<N>> {
 
     public enum StorageNodeType {
-        GLOBAL, SOURCE_LOCAL_SPECIAL, STATEMENT_LOCAL, ROOT_STATEMENT_LOCAL
+        GLOBAL, SOURCE_LOCAL_SPECIAL, STATEMENT_LOCAL,
     }
 
     public interface Registry {
@@ -184,7 +184,10 @@ public abstract class NamespaceBehaviour<K, V, N extends IdentifierNamespace<K,
 
         @Override
         public V getFrom(final NamespaceStorageNode storage, final K key) {
-            NamespaceStorageNode current = findClosestTowardsRoot(storage, storageType);
+            NamespaceStorageNode current = storage;
+            while (current.getStorageNodeType() != storageType) {
+                current = current.getParentNamespaceStorage();
+            }
             return getFromLocalStorage(current, key);
         }
 
@@ -200,7 +203,10 @@ public abstract class NamespaceBehaviour<K, V, N extends IdentifierNamespace<K,
 
         @Override
         public void addTo(NamespaceBehaviour.NamespaceStorageNode storage, K key, V value) {
-            NamespaceStorageNode current = findClosestTowardsRoot(storage, storageType);
+            NamespaceStorageNode current = storage;
+            while (current.getStorageNodeType() != storageType) {
+                current = current.getParentNamespaceStorage();
+            }
             addToStorage(current, key, value);
         }
 
@@ -244,12 +250,4 @@ public abstract class NamespaceBehaviour<K, V, N extends IdentifierNamespace<K,
         }
 
     }
-
-    protected static NamespaceStorageNode findClosestTowardsRoot(NamespaceStorageNode storage, StorageNodeType type) {
-        NamespaceStorageNode current = storage;
-        while(current != null && current.getStorageNodeType() != type) {
-            current = current.getParentNamespaceStorage();
-        }
-        return current;
-    }
 }
index f6d935e6145ab46b7ceaaf241d874db77ee7e927..a7041f2f14040c117557dc1f7bd75c0e7696e564 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
-import com.google.common.base.Verify;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import java.util.ArrayList;
@@ -27,7 +26,6 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
@@ -107,33 +105,20 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh
         if (potential == null) {
             NamespaceBehaviour<K, V, N> potentialRaw = supports.get(currentPhase).getNamespaceBehaviour(type);
             if(potentialRaw != null) {
-                potential = createNamespaceContext(potentialRaw);
+                potential = new NamespaceBehaviourWithListeners<>(potentialRaw);
                 supportedNamespaces.put(type, potential);
-            } else {
-                throw new NamespaceNotAvailableException(
-                        "Namespace " + type + " is not available in phase " + currentPhase);
             }
         }
+        if (potential != null) {
+            Preconditions.checkState(type.equals(potential.getIdentifier()));
 
-        Verify.verify(type.equals(potential.getIdentifier()));
             /*
-         * Safe cast, previous checkState checks equivalence of key from which type argument are
-         * derived
-         */
-        return (NamespaceBehaviourWithListeners<K, V, N>) potential;
-    }
-
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    private <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviourWithListeners<K, V, N> createNamespaceContext(
-            NamespaceBehaviour<K, V, N> potentialRaw) {
-        if (potentialRaw instanceof DerivedNamespaceBehaviour) {
-            VirtualNamespaceContext derivedContext =
-                    new VirtualNamespaceContext<>(potentialRaw);
-            getNamespaceBehaviour(((DerivedNamespaceBehaviour) potentialRaw).getDerivedFrom())
-                    .addDerivedNamespace(derivedContext);
-            return derivedContext;
+             * Safe cast, previous checkState checks equivalence of key from
+             * which type argument are derived
+             */
+            return (NamespaceBehaviourWithListeners<K, V, N>) potential;
         }
-        return new SimpleNamespaceContext<>(potentialRaw);
+        throw new NamespaceNotAvailableException("Namespace " + type + " is not available in phase " + currentPhase);
     }
 
     public StatementDefinitionContext<?, ?, ?> getStatementDefinition(final QName name) {
index 254b65c76b741cc591469ab7614da9ef6402952b..1c719722373d92a319cfdab345b6161e057176e1 100644 (file)
@@ -9,7 +9,6 @@ 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;
@@ -63,6 +62,16 @@ 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;
@@ -93,8 +102,14 @@ class ModifierImpl implements ModelActionBuilder {
     }
 
     private void applyAction() throws InferenceException {
-        Preconditions.checkState(!actionApplied);
-        action.apply();
+
+        try {
+            action.apply();
+        } catch (InferenceException e) {
+            actionApplied = false;
+            return;
+        }
+        // Â Mark all mutations as performed, so context node could move to next.
         actionApplied = true;
     }
 
@@ -124,11 +139,10 @@ class ModifierImpl implements ModelActionBuilder {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    private <K, C extends StmtContext.Mutable<?, ?, ?> , N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>> AbstractPrerequisite<C> mutatesCtxImpl(
+    private <K, C extends StmtContext.Mutable<?, ?, ?> , N extends StatementNamespace<K, ?, ? >> 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;
@@ -137,19 +151,9 @@ class ModifierImpl implements ModelActionBuilder {
             }
         }
 
-    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;
+    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);
     }
 
     @Override
@@ -226,7 +230,7 @@ class ModifierImpl implements ModelActionBuilder {
 
 
    @Override
-    public <K, E extends EffectiveStatement<?, ?>, N extends IdentifierNamespace<K, ? extends StmtContext<?, ?, ?>>> AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(
+    public <K, E extends EffectiveStatement<?, ?>, N extends StatementNamespace<K, ?, ? extends E>> AbstractPrerequisite<Mutable<?, ?, E>> mutatesEffectiveCtx(
             final StmtContext<?, ?, ?> context, final Class<N> namespace, final K key) {
         return mutatesCtxImpl(context, namespace, key, EFFECTIVE_MODEL);
     }
@@ -236,6 +240,7 @@ 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> {
@@ -257,6 +262,7 @@ class ModifierImpl implements ModelActionBuilder {
         protected boolean resolvePrereq(final T value) throws InferenceException {
             this.value = value;
             this.done = true;
+            tryToResolve();
             return isApplied();
         }
 
@@ -347,9 +353,8 @@ class ModifierImpl implements ModelActionBuilder {
         @Override
         public void namespaceItemAdded(final StatementContextBase<?, ?, ?> context, final Class<?> namespace, final Object key,
                 final Object value) throws SourceException {
-            StatementContextBase<?, ?, ?> targetCtx = contextImpl(value);
-            targetCtx.addMutation(modPhase,this);
-            resolvePrereq((C) targetCtx);
+            context.addMutation(modPhase,this);
+            resolvePrereq((C) context);
         }
 
         @Override
index 1f10c18a96bcc33a7d1e00d3f5e49836af7b9bb8..c4bbb76f004a6417f456a791a49001063e14948c 100644 (file)
@@ -7,78 +7,76 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
-import java.util.ArrayList;
+import com.google.common.base.Optional;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+import java.util.Collection;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 
-abstract class NamespaceBehaviourWithListeners<K, V, N extends IdentifierNamespace<K, V>>
-        extends NamespaceBehaviour<K, V, N> {
+final class NamespaceBehaviourWithListeners<K,V, N extends IdentifierNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
 
-    abstract static class ValueAddedListener<K> {
+    abstract static class ValueAddedListener {
         private final NamespaceStorageNode ctxNode;
-        private K key;
 
-        public ValueAddedListener(final NamespaceStorageNode contextNode, K key) {
+        public ValueAddedListener(final NamespaceStorageNode contextNode) {
             this.ctxNode = contextNode;
-            this.key = key;
-        }
-
-        public NamespaceStorageNode getCtxNode() {
-            return ctxNode;
-        }
-
-        public K getKey() {
-            return key;
         }
 
         abstract void onValueAdded(Object key, Object value);
     }
 
     private final NamespaceBehaviour<K, V, N> delegate;
-    private final List<VirtualNamespaceContext<?, V, ?>> derivedNamespaces = new ArrayList<>();
-
+    private final Multimap<K, ValueAddedListener> listeners = HashMultimap.create();
 
     protected NamespaceBehaviourWithListeners(final NamespaceBehaviour<K, V, N> delegate) {
         super(delegate.getIdentifier());
         this.delegate = delegate;
     }
 
-    protected abstract void addListener(K key, ValueAddedListener<K> listener);
-
-    protected abstract Iterator<ValueAddedListener<K>> getMutableListeners(K key);
-
-    protected abstract boolean isRequestedValue(ValueAddedListener<K> listener, NamespaceStorageNode storage, V value);
-
     @Override
     public void addTo(final NamespaceStorageNode storage, final K key, final V value) {
         delegate.addTo(storage, key, value);
 
-        Iterator<ValueAddedListener<K>> keyListeners = getMutableListeners(key);
-        List<ValueAddedListener<K>> toNotify = new ArrayList<>();
+        Iterator<ValueAddedListener> keyListeners = listeners.get(key).iterator();
         while (keyListeners.hasNext()) {
-            ValueAddedListener<K> listener = keyListeners.next();
-            if (isRequestedValue(listener, storage, value)) {
+            ValueAddedListener listener = keyListeners.next();
+            if (listener.ctxNode == storage || hasIdentiticalValue(listener.ctxNode,key,value)) {
                 keyListeners.remove();
-                toNotify.add(listener);
+                listener.onValueAdded(key, value);
             }
         }
-        for(ValueAddedListener<K> listener : toNotify) {
-            listener.onValueAdded(key, value);
-        }
-        for (VirtualNamespaceContext<?, V, ?> derived : derivedNamespaces) {
-            derived.addTo(storage, null, value);
+
+        if (key instanceof ModuleIdentifier && !listeners.isEmpty()) {
+            Collection<ValueAddedListener> defaultImportListeners = getDefaultImportListeners((ModuleIdentifier) key);
+            Iterator<ValueAddedListener> defaultImportsIterator = defaultImportListeners.iterator();
+            while (defaultImportsIterator.hasNext()) {
+                ValueAddedListener listener = defaultImportsIterator.next();
+                if(listener.ctxNode == storage || hasIdentiticalValue(listener.ctxNode,key,value)) {
+                    defaultImportsIterator.remove();
+                    listener.onValueAdded(key, value);
+                }
+            }
         }
     }
 
-    final void addValueListener(final ValueAddedListener<K> listener) {
-        addListener(listener.key, listener);
+    private Collection<ValueAddedListener> getDefaultImportListeners(final ModuleIdentifier key) {
+        ModuleIdentifier defaultImportKey = new ModuleIdentifierImpl(key.getName(),
+            Optional.fromNullable(key.getNamespace()), Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP));
+        return listeners.get((K)defaultImportKey);
+    }
+
+    private boolean hasIdentiticalValue(final NamespaceStorageNode ctxNode, final K key, final V value) {
+        return getFrom(ctxNode, key) == value;
     }
 
-    final void addDerivedNamespace(VirtualNamespaceContext<?, V, ?> namespace) {
-        derivedNamespaces.add(namespace);
+    void addValueListener(final K key, final ValueAddedListener listener) {
+        listeners.put(key, listener);
     }
 
     @Override
index b1bf364e0c387792d4b156d333ce25aa1dd387a0..8c883dd26572b680ac0537dc5297d79e1640ffae 100644 (file)
@@ -15,7 +15,6 @@ import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.NamespaceStorageNode;
 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.Registry;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour.StorageNodeType;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 
@@ -101,10 +100,6 @@ public class RootStatementContext<A, D extends DeclaredStatement<A>, E extends E
         return sourceContext;
     }
 
-    @Override
-    public StorageNodeType getStorageNodeType() {
-        return StorageNodeType.ROOT_STATEMENT_LOCAL;
-    }
     /**
      * @return this as its own root
      */
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SimpleNamespaceContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SimpleNamespaceContext.java
deleted file mode 100644 (file)
index 01e499f..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.stmt.reactor;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-final class SimpleNamespaceContext<K, V, N extends IdentifierNamespace<K, V>>
-        extends NamespaceBehaviourWithListeners<K, V, N> {
-
-    // FIXME: Change this to Multimap, once issue with modules
-    // is resolved.
-    private final List<NamespaceBehaviourWithListeners.ValueAddedListener<K>> listeners = new ArrayList<>();
-    public SimpleNamespaceContext(NamespaceBehaviour<K, V, N> delegate) {
-        super(delegate);
-    }
-
-    protected boolean isRequestedValue(NamespaceBehaviourWithListeners.ValueAddedListener<K> listener, NamespaceStorageNode storage, V value) {
-        NamespaceStorageNode listenerCtx = listener.getCtxNode();
-        return value == getFrom(listenerCtx, listener.getKey());
-    }
-
-    @Override
-    protected void addListener(K key, NamespaceBehaviourWithListeners.ValueAddedListener<K> listener) {
-        listeners.add(listener);
-    }
-
-    @Override
-    protected Iterator<NamespaceBehaviourWithListeners.ValueAddedListener<K>> getMutableListeners(K key) {
-        return listeners.iterator();
-    }
-}
\ No newline at end of file
index b11d2a40aa3d732144a08f114e0c0628010ad04b..db760d0792cfd2be2f7901ca98626656d89b1ab0 100644 (file)
@@ -255,11 +255,11 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     PhaseCompletionProgress tryToCompletePhase(final ModelProcessingPhase phase) throws SourceException {
         Collection<ModifierImpl> currentPhaseModifiers = modifiers.get(phase);
 
-        boolean hasProgressed = tryToProgress(currentPhaseModifiers);
+        boolean hasProgressed = hasProgress(currentPhaseModifiers);
 
         boolean phaseCompleted = root.tryToCompletePhase(phase);
 
-        hasProgressed = (tryToProgress(currentPhaseModifiers) | hasProgressed);
+        hasProgressed = (hasProgress(currentPhaseModifiers) | hasProgressed);
 
         if (phaseCompleted && (currentPhaseModifiers.isEmpty())) {
             finishedPhase = phase;
@@ -273,12 +273,12 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh
     }
 
 
-    private static boolean tryToProgress(final Collection<ModifierImpl> currentPhaseModifiers) {
+    private static boolean hasProgress(final Collection<ModifierImpl> currentPhaseModifiers) {
 
         Iterator<ModifierImpl> modifier = currentPhaseModifiers.iterator();
         boolean hasProgressed = false;
         while (modifier.hasNext()) {
-            if (modifier.next().tryApply()) {
+            if (modifier.next().isApplied()) {
                 modifier.remove();
                 hasProgressed = true;
             }
index 5e05a47580d57e1091c628c3ddcb26945f824149..d28dc9a458c472d70c13b7645c7e282779168e6d 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
+import java.util.LinkedList;
+
+import java.util.List;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
 import com.google.common.collect.HashMultimap;
@@ -17,8 +20,6 @@ import java.util.Collections;
 import java.util.EventListener;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
 import java.util.Map;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.concepts.Identifiable;
@@ -485,7 +486,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         NamespaceBehaviour<K, V, N> behaviour = getBehaviourRegistry().getNamespaceBehaviour(type);
         if (behaviour instanceof NamespaceBehaviourWithListeners) {
             NamespaceBehaviourWithListeners<K, V, N> casted = (NamespaceBehaviourWithListeners<K, V, N>) behaviour;
-            casted.addValueListener(new ValueAddedListener<K>(this, key) {
+            casted.addValueListener(key, new ValueAddedListener(this) {
                 @Override
                 void onValueAdded(Object key, Object value) {
                     try {
index 04a01d17fceaebb6b1b913c071519724ea8cb489..4c3be3e9a2e16ad4fb2696d60a8ba9f67d6af180 100644 (file)
@@ -63,6 +63,10 @@ class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Effective
         } else {
             this.argument = original.argument;
         }
+
+        copyDeclaredStmts(original, newQNameModule, typeOfCopy);
+
+        copyEffectiveStmts(original, newQNameModule, typeOfCopy);
     }
 
     private void copyDeclaredStmts(SubstatementContext<A, D, E> original,
@@ -146,9 +150,6 @@ class SubstatementContext<A, D extends DeclaredStatement<A>, E extends Effective
         }
 
         definition().onStatementAdded(copy);
-
-        copy.copyDeclaredStmts(this, newQNameModule, typeOfCopy);
-        copy.copyEffectiveStmts(this, newQNameModule, typeOfCopy);
         return copy;
     }
 
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/VirtualNamespaceContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/VirtualNamespaceContext.java
deleted file mode 100644 (file)
index 75c4b5e..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.stmt.reactor;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-
-final class VirtualNamespaceContext<K, V, N extends IdentifierNamespace<K, V>>
-        extends NamespaceBehaviourWithListeners<K, V, N> {
-
-    private final List<NamespaceBehaviourWithListeners.ValueAddedListener<K>> listeners = new ArrayList<>(20);
-
-    public VirtualNamespaceContext(NamespaceBehaviour<K, V, N> delegate) {
-        super(delegate);
-    }
-
-    protected boolean isRequestedValue(NamespaceBehaviourWithListeners.ValueAddedListener<K> listener, NamespaceStorageNode storage, V value) {
-        return value == getFrom(listener.getCtxNode(), listener.getKey());
-    }
-
-    @Override
-    protected void addListener(K key, NamespaceBehaviourWithListeners.ValueAddedListener<K> listener) {
-        listeners.add(listener);
-    }
-
-    @Override
-    protected Iterator<NamespaceBehaviourWithListeners.ValueAddedListener<K>> getMutableListeners(K key) {
-        return listeners.iterator();
-    }
-}
\ No newline at end of file
index 96e311a357828c0cfb20a54769c0dff201e51763..9e39f9009f4657b1bb91db333d90bc3c7bd15bff 100644 (file)
@@ -22,10 +22,8 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AugmentEffectiveStatementImpl;
@@ -80,21 +78,32 @@ public class AugmentStatementImpl extends
             }
 
             final ModelActionBuilder augmentAction = augmentNode
-                    .newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
+                    .newInferenceAction(ModelProcessingPhase.FULL_DECLARATION);
             final ModelActionBuilder.Prerequisite<StmtContext<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>>> sourceCtxPrereq = augmentAction
-                    .requiresCtx(augmentNode, ModelProcessingPhase.EFFECTIVE_MODEL);
-            final Prerequisite<Mutable<?, ?, EffectiveStatement<?, ?>>> target = augmentAction.mutatesEffectiveCtx(getSearchRoot(augmentNode), SchemaNodeIdentifierBuildNamespace.class, augmentNode.getStatementArgument());
+                    .requiresCtx(augmentNode,
+                            ModelProcessingPhase.FULL_DECLARATION);
+
             augmentAction.apply(new ModelActionBuilder.InferenceAction() {
 
                 @Override
                 public void apply() throws InferenceException {
-                    final StatementContextBase<?, ?, ?> augmentTargetCtx = (StatementContextBase<?, ?, ?>) target.get();
+                    final StatementContextBase<?, ?, ?> augmentTargetCtx = AugmentUtils
+                            .getAugmentTargetCtx(augmentNode);
+
+                    if (augmentTargetCtx == null) {
+                        throw new InferenceException(
+                                "Augment target not found: "
+                                        + augmentNode.getStatementArgument(),
+                                augmentNode.getStatementSourceReference());
+                    }
 
                     if (!AugmentUtils.isSupportedAugmentTarget(augmentTargetCtx) || StmtContextUtils.isInExtensionBody(augmentTargetCtx)) {
                         augmentNode.setIsSupportedToBuildEffective(false);
                         return;
                     }
+
                     final StatementContextBase<?, ?, ?> augmentSourceCtx = (StatementContextBase<?, ?, ?>) augmentNode;
+
                     try {
                         AugmentUtils.copyFromSourceToTarget(augmentSourceCtx,
                                 augmentTargetCtx);
@@ -132,15 +141,6 @@ public class AugmentStatementImpl extends
                 }
             });
         }
-
-        private Mutable<?, ?, ?> getSearchRoot(Mutable<?, ?, ?> augmentContext) {
-            Mutable<?, ?, ?> parent = augmentContext.getParentContext();
-            // Augment is in uses - we need to augment instantiated nodes in parent.
-            if(Rfc6020Mapping.USES.equals(parent.getPublicDefinition())) {
-                return parent.getParentContext();
-            }
-            return parent;
-        }
     }
 
     @Nonnull
index c71ba67c9a6c26e5474c6196d052c716674df8b5..dd14bf87d90860cd2ea415a833ad71e8c254064d 100644 (file)
@@ -10,48 +10,65 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList.Builder;
 import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 import java.util.regex.Pattern;
+import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.AugmentStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.DataDefinitionStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.MandatoryStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.WhenStatement;
+import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.TypeOfCopy;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace;
 import org.opendaylight.yangtools.yang.parser.spi.validation.ValidationBundlesNamespace.ValidationBundleType;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-// FIXME: Move this to the AugmentStatementDefinition#ApplyAction
 public final class AugmentUtils {
 
+    private static final Logger LOG = LoggerFactory.getLogger(AugmentUtils.class);
     private static final Pattern PATH_REL_PATTERN1 = Pattern.compile("\\.\\.?\\s*/(.+)");
     private static final Pattern PATH_REL_PATTERN2 = Pattern.compile("//.*");
 
     private AugmentUtils() {
+        throw new UnsupportedOperationException();
     }
 
     public static Iterable<QName> parseAugmentPath(final StmtContext<?, ?, ?> ctx, final String path) {
         Preconditions.checkArgument(!PATH_REL_PATTERN1.matcher(path).matches()
             && !PATH_REL_PATTERN2.matcher(path).matches(),
-                    "An argument for augment can be only absolute path; or descendant if used in uses");
+            "An argument for augment can be only absolute path; or descendant if used in uses");
+
         return Utils.parseXPath(ctx, path);
     }
 
     public static void copyFromSourceToTarget(final StatementContextBase<?, ?, ?> sourceCtx,
             final StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
+
         copyDeclaredStmts(sourceCtx, targetCtx);
         copyEffectiveStmts(sourceCtx, targetCtx);
     }
 
-    // FIXME: Declared statements should not be copied.
-    private static void copyDeclaredStmts(final StatementContextBase<?, ?, ?> sourceCtx,
+    public static void copyDeclaredStmts(final StatementContextBase<?, ?, ?> sourceCtx,
             final StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
 
         final List<StatementContextBase<?, ?, ?>> subStatements = new Builder<StatementContextBase<?, ?, ?>>()
@@ -74,7 +91,7 @@ public final class AugmentUtils {
         }
     }
 
-    private static void copyEffectiveStmts(final StatementContextBase<?, ?, ?> sourceCtx,
+    public static void copyEffectiveStmts(final StatementContextBase<?, ?, ?> sourceCtx,
             final StatementContextBase<?, ?, ?> targetCtx) throws SourceException {
 
         final List<StatementContextBase<?, ?, ?>> subStatements = new Builder<StatementContextBase<?, ?, ?>>()
@@ -98,41 +115,54 @@ public final class AugmentUtils {
     }
 
     private static void validateNodeCanBeCopiedByAugment(final StatementContextBase<?, ?, ?> sourceCtx,
-            final List<StatementContextBase<?, ?, ?>> targetSubStatements, final boolean sourceAndTargetInSameModule) {
+            final Iterable<StatementContextBase<?, ?, ?>> targetSubStatements,
+            final boolean sourceAndTargetInSameModule) {
 
-        if (sourceCtx.getPublicDefinition().getDeclaredRepresentationClass().equals(WhenStatement.class)) {
+        if (WhenStatement.class.equals(sourceCtx.getPublicDefinition().getDeclaredRepresentationClass())) {
             return;
         }
 
         if (!sourceAndTargetInSameModule) {
-            final List<StatementContextBase<?, ?, ?>> sourceSubStatements = new Builder<StatementContextBase<?, ?, ?>>()
-                    .addAll(sourceCtx.declaredSubstatements()).addAll(sourceCtx.effectiveSubstatements()).build();
-
-            for (final StatementContextBase<?, ?, ?> sourceSubStatement : sourceSubStatements) {
-                if (sourceSubStatement.getPublicDefinition().getDeclaredRepresentationClass()
-                        .equals(MandatoryStatement.class)) {
-                    throw new IllegalArgumentException(
-                            String.format(
-                                    "An augment cannot add node '%s' because it is mandatory and in module different from target",
-                                    sourceCtx.rawStatementArgument()));
-                }
+            for (final StatementContextBase<?, ?, ?> sourceSubStatement :
+                Iterables.concat(sourceCtx.declaredSubstatements(), sourceCtx.effectiveSubstatements())) {
+                Preconditions.checkArgument(!MandatoryStatement.class.equals(
+                    sourceSubStatement.getPublicDefinition().getDeclaredRepresentationClass()),
+                    "An augment cannot add node '%s' because it is mandatory and in module different from target",
+                    sourceCtx.rawStatementArgument());
             }
         }
 
         for (final StatementContextBase<?, ?, ?> subStatement : targetSubStatements) {
 
-            final boolean sourceIsDataNode = DataDefinitionStatement.class.isAssignableFrom(sourceCtx
-                    .getPublicDefinition().getDeclaredRepresentationClass());
-            final boolean targetIsDataNode = DataDefinitionStatement.class.isAssignableFrom(subStatement
-                    .getPublicDefinition().getDeclaredRepresentationClass());
-            boolean qNamesEqual = sourceIsDataNode && targetIsDataNode
-                    && Objects.equals(sourceCtx.getStatementArgument(), subStatement.getStatementArgument());
-
-            if (qNamesEqual) {
-                throw new IllegalStateException(String.format(
-                        "An augment cannot add node named '%s' because this name is already used in target",
-                        sourceCtx.rawStatementArgument()));
+            final boolean sourceIsDataNode = DataDefinitionStatement.class.isAssignableFrom(
+                sourceCtx.getPublicDefinition().getDeclaredRepresentationClass());
+            final boolean targetIsDataNode = DataDefinitionStatement.class.isAssignableFrom(
+                subStatement.getPublicDefinition().getDeclaredRepresentationClass());
+            Preconditions.checkState(!sourceIsDataNode || !targetIsDataNode
+                    || !Objects.equals(sourceCtx.getStatementArgument(), subStatement.getStatementArgument()),
+                "An augment cannot add node named '%s' because this name is already used in target",
+                sourceCtx.rawStatementArgument());
+        }
+    }
+
+    public static QNameModule getNewQNameModule(final StatementContextBase<?, ?, ?> targetCtx,
+            final StatementContextBase<?, ?, ?> sourceCtx) {
+        Object targetStmtArgument = targetCtx.getStatementArgument();
+
+        final StatementContextBase<?, ?, ?> root = sourceCtx.getRoot();
+        final QNameModule sourceQNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root);
+
+        if (targetStmtArgument instanceof QName) {
+            QName targetQName = (QName) targetStmtArgument;
+            QNameModule targetQNameModule = targetQName.getModule();
+
+            if (targetQNameModule.equals(sourceQNameModule)) {
+                return null;
+            } else {
+                return targetQNameModule;
             }
+        } else {
+            return null;
         }
     }
 
@@ -148,7 +178,100 @@ public final class AugmentUtils {
         return REUSED_DEF_SET.contains(stmtContext.getPublicDefinition());
     }
 
-    static boolean isSupportedAugmentTarget(final StatementContextBase<?, ?, ?> substatementCtx) {
+    public static StatementContextBase<?, ?, ?> getAugmentTargetCtx(
+            final Mutable<SchemaNodeIdentifier, AugmentStatement, EffectiveStatement<SchemaNodeIdentifier, AugmentStatement>> augmentNode) {
+
+        final SchemaNodeIdentifier augmentTargetNode = augmentNode.getStatementArgument();
+        Preconditions.checkArgument(augmentTargetNode != null,
+                "Augment argument null, something bad happened in some of previous parsing phases");
+
+        List<StatementContextBase<?, ?, ?>> rootStatementCtxList = new ArrayList<>();
+        if (augmentTargetNode.isAbsolute()) {
+
+            QNameModule module = augmentTargetNode.getPathFromRoot().iterator().next().getModule();
+
+            StatementContextBase<?, ?, ?> rootStatementCtx =
+                    (StatementContextBase<?, ?, ?>) augmentNode.getFromNamespace(NamespaceToModule.class, module);
+            rootStatementCtxList.add(rootStatementCtx);
+
+            final Map<?, ?> subModules = rootStatementCtx.getAllFromNamespace(IncludedModuleContext.class);
+            if (subModules != null) {
+                rootStatementCtxList.addAll((Collection<? extends StatementContextBase<?, ?, ?>>) subModules.values());
+            }
+
+        } else {
+            StatementContextBase<?, ?, ?> parent = (StatementContextBase<?, ?, ?>) augmentNode.getParentContext();
+            if (StmtContextUtils.producesDeclared(parent, UsesStatement.class)) {
+                rootStatementCtxList.add(parent.getParentContext());
+            } else {
+                // error
+            }
+        }
+
+        StatementContextBase<?, ?, ?> augmentTargetCtx = null;
+        for (final StatementContextBase<?, ?, ?> rootStatementCtx : rootStatementCtxList) {
+            augmentTargetCtx = findCtxOfNodeInRoot(rootStatementCtx, augmentTargetNode);
+            if (augmentTargetCtx != null) {
+                break;
+            }
+        }
+
+        return augmentTargetCtx;
+    }
+
+    @Nullable
+    public static StatementContextBase<?, ?, ?> findCtxOfNodeInSubstatements(final StatementContextBase<?, ?, ?> rootStmtCtx,
+            final Iterable<QName> path) {
+
+        StatementContextBase<?, ?, ?> parent = rootStmtCtx;
+
+        Iterator<QName> pathIter = path.iterator();
+        while (pathIter.hasNext()) {
+            QName nextPathQName = pathIter.next();
+            StatementContextBase<?, ?, ?> foundSubstatement = getSubstatementByQName(parent, nextPathQName);
+
+            if (foundSubstatement == null) {
+                return null;
+            }
+            if (!pathIter.hasNext()) {
+                return foundSubstatement;
+            }
+
+            parent = foundSubstatement;
+        }
+
+        return null;
+    }
+
+    public static StatementContextBase<?, ?, ?> getSubstatementByQName(final StatementContextBase<?, ?, ?> parent,
+            final QName nextPathQName) {
+
+        Collection<StatementContextBase<?, ?, ?>> declaredSubstatement = parent.declaredSubstatements();
+        Collection<StatementContextBase<?, ?, ?>> effectiveSubstatement = parent.effectiveSubstatements();
+
+        for (StatementContextBase<?, ?, ?> substatement : Iterables.concat(declaredSubstatement, effectiveSubstatement)) {
+            Object substatementArgument = substatement.getStatementArgument();
+            QName substatementQName;
+            if (substatementArgument instanceof QName) {
+                substatementQName = (QName) substatementArgument;
+
+                if (nextPathQName.getLocalName().equals(
+                        substatementQName.getLocalName())) {
+                    if (isSupportedAugmentTarget(substatement)) {
+                        return substatement;
+                    } else if (Utils.isUnknownNode(substatement)) {
+                        LOG.warn("Module '{}': augment into unknown node '{}'.",
+                                substatement.getRoot().getStatementArgument(), substatementArgument);
+                        return substatement;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static boolean isSupportedAugmentTarget(final StatementContextBase<?, ?, ?> substatementCtx) {
 
         /*
          * :TODO Substatement must be allowed augment target type e.g. Container, etc... and must be not for example
@@ -164,4 +287,10 @@ public final class AugmentUtils {
         return allowedAugmentTargets == null || allowedAugmentTargets.isEmpty()
                 || allowedAugmentTargets.contains(substatementCtx.getPublicDefinition());
     }
+
+    @Nullable
+    public static StatementContextBase<?, ?, ?> findCtxOfNodeInRoot(final StatementContextBase<?, ?, ?> rootStmtCtx,
+            final SchemaNodeIdentifier node) {
+        return findCtxOfNodeInSubstatements(rootStmtCtx, node.getPathFromRoot());
+    }
 }
index 6482c99f510c4dc7ccb39c1f4fbfc9fe066bae72..b9761b1a913edcd5d27ec64751a4c399de42e637 100644 (file)
@@ -7,13 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
 /**
  * Statement local namespace, which holds direct schema node descendants.
@@ -21,42 +18,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
  * @param <D>
  * @param <E>
  */
-public class ChildSchemaNodes<D extends DeclaredStatement<QName>,E extends EffectiveStatement<QName, D>>
-    extends NamespaceBehaviour<QName, StmtContext<?, D, E>, ChildSchemaNodes<D, E>>
-    implements StatementNamespace<QName, D, E>{
+public interface ChildSchemaNodes<D extends DeclaredStatement<QName>,E extends EffectiveStatement<QName, D>> extends StatementNamespace<QName, D, E>{
 
-    protected ChildSchemaNodes() {
-        super((Class<ChildSchemaNodes<D,E>>) (Class) ChildSchemaNodes.class);
-    }
-
-    @Override
-    public StmtContext<?, D, E> get(QName key) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
-    public StmtContext<?, D, E> getFrom(NamespaceStorageNode storage, QName key) {
-        return globalOrStatementSpecific(storage).getFromLocalStorage(getIdentifier(), key);
-    }
-
-    @Override
-    public Map<QName, StmtContext<?, D, E>> getAllFrom(NamespaceStorageNode storage) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public void addTo(NamespaceBehaviour.NamespaceStorageNode storage, QName key, StmtContext<?, D, E> value) {
-        globalOrStatementSpecific(storage).addToLocalStorage(ChildSchemaNodes.class, key, value);
-    }
-
-    private NamespaceStorageNode globalOrStatementSpecific(NamespaceBehaviour.NamespaceStorageNode storage) {
-        NamespaceStorageNode current = storage;
-        while(current.getStorageNodeType() != StorageNodeType.STATEMENT_LOCAL && current.getStorageNodeType() != StorageNodeType.GLOBAL) {
-            current = current.getParentNamespaceStorage();
-        }
-        return current;
-    }
 }
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SchemaNodeIdentifierBuildNamespace.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SchemaNodeIdentifierBuildNamespace.java
deleted file mode 100644 (file)
index bee80c9..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
-
-import java.util.Iterator;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-
-class SchemaNodeIdentifierBuildNamespace extends
-        DerivedNamespaceBehaviour<SchemaNodeIdentifier, StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>, SchemaNodeIdentifierBuildNamespace, ChildSchemaNodes<?, ?>>
-        implements IdentifierNamespace<SchemaNodeIdentifier, StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>> {
-
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    protected SchemaNodeIdentifierBuildNamespace() {
-        super(SchemaNodeIdentifierBuildNamespace.class, (Class) ChildSchemaNodes.class);
-    }
-
-    @Override
-    public StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> get(
-            SchemaNodeIdentifier key) {
-        throw new UnsupportedOperationException("Direct access to namespace is not supported");
-    }
-
-    @Override
-    public StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> getFrom(NamespaceStorageNode storage, SchemaNodeIdentifier key) {
-
-        final NamespaceStorageNode lookupStartStorage;
-        if(key.isAbsolute() || storage.getStorageNodeType() == StorageNodeType.ROOT_STATEMENT_LOCAL) {
-            lookupStartStorage = NamespaceBehaviour.findClosestTowardsRoot(storage, StorageNodeType.GLOBAL);
-        } else {
-            lookupStartStorage = storage;
-        }
-        Iterator<QName> iterator = key.getPathFromRoot().iterator();
-        if(!iterator.hasNext()) {
-            if(lookupStartStorage instanceof StmtContext<?, ?, ?>) {
-                return (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage;
-            } else {
-                return null;
-            }
-        }
-        StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> current = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage.getFromLocalStorage(ChildSchemaNodes.class, iterator.next());
-        while(current != null && iterator.hasNext()) {
-            current = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) current.getFromNamespace(ChildSchemaNodes.class, iterator.next());
-        }
-        return current;
-    }
-
-}
index 57e5bb0368716d86ac6d8db625691e54c74a6416..514b9f04082e2ddd1f0fba75156ff4f1c14b10da 100644 (file)
@@ -30,7 +30,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.StatementContextBase;
@@ -68,13 +67,13 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
                 return;
             }
 
-            ModelActionBuilder usesAction = usesNode.newInferenceAction(ModelProcessingPhase.EFFECTIVE_MODEL);
+            ModelActionBuilder usesAction = usesNode.newInferenceAction(FULL_DECLARATION);
             final QName groupingName = usesNode.getStatementArgument();
 
             final Prerequisite<StmtContext<?, ?, ?>> sourceGroupingPre = usesAction.requiresCtx(usesNode,
-                    GroupingNamespace.class, groupingName, ModelProcessingPhase.EFFECTIVE_MODEL);
-            final Prerequisite<? extends StmtContext.Mutable<?, ?, ?>> targetNodePre = usesAction.mutatesEffectiveCtx(
-                    usesNode.getParentContext());
+                    GroupingNamespace.class, groupingName, FULL_DECLARATION);
+            final Prerequisite<? extends StmtContext.Mutable<?, ?, ?>> targetNodePre = usesAction.mutatesCtx(
+                    usesNode.getParentContext(), FULL_DECLARATION);
 
             usesAction.apply(new InferenceAction() {
 
index e491c5975db17f0ed7aad8f7f2f411273f3ab349..389456e361f7b4a7efd603c63325dc0a65ded59e 100644 (file)
@@ -297,9 +297,14 @@ public final class Utils {
     }
 
     @Nullable
-    public static StatementContextBase<?, ?, ?> findNode(final StmtContext<?, ?, ?> rootStmtCtx,
+    public static StatementContextBase<?, ?, ?> findNode(final StatementContextBase<?, ?, ?> rootStmtCtx,
             final SchemaNodeIdentifier node) {
-        return (StatementContextBase<?, ?, ?>) rootStmtCtx.getFromNamespace(SchemaNodeIdentifierBuildNamespace.class, node);
+        StatementContextBase<?, ?, ?> current = rootStmtCtx;
+        Iterator<QName> arguments = node.getPathFromRoot().iterator();
+        while(current != null && arguments.hasNext()) {
+            current = (StatementContextBase<?, ?, ?>) current.getFromNamespace(ChildSchemaNodes.class, arguments.next());
+        }
+        return current;
     }
 
     public static SchemaPath getSchemaPath(final StmtContext<?, ?, ?> ctx) {
index 6dd2595d3ed8a70e0df8a41c2b3562eab4c5c9b6..9f316ec9491fd5e9a9071c5944fe4a1bed510eb4 100644 (file)
@@ -83,8 +83,7 @@ public final class YangInferencePipeline {
             .addSupport(new YinElementStatementImpl.Definition())
             .addSupport(new ArgumentStatementImpl.Definition())
             .addSupport(new ExtensionStatementImpl.Definition())
-            .addSupport(new ChildSchemaNodes())
-            .addSupport(new SchemaNodeIdentifierBuildNamespace())
+            .addSupport(global(ChildSchemaNodes.class))
             .addSupport(global(ExtensionNamespace.class))
             .addSupport(new TypedefStatementImpl.Definition())
             .addSupport(treeScoped(TypeNamespace.class))
index 890c47b0fc65fa4f49d9d07cc97f84935cf055a5..fdc1802e684dad99614b367e5738a15d6bccaecf 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.meta.ModelStatement;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
@@ -109,7 +108,11 @@ public class AugmentProcessTest {
                 MULTIPLE_AUGMENT_SUBMODULE);
 
         EffectiveSchemaContext result = null;
-        result = reactor.buildEffective();
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
         assertNotNull(result);
     }
 
@@ -120,11 +123,15 @@ public class AugmentProcessTest {
         addSources(reactor, MULTIPLE_AUGMENT);
 
         EffectiveSchemaContext result = null;
-        result = reactor.buildEffective();
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
         assertNotNull(result);
     }
 
-    @Test(expected=SomeModifiersUnresolvedException.class)
+    @Test
     public void multipleAugmentIncorrectPathTest() throws SourceException,
             ReactorException {
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
@@ -132,22 +139,40 @@ public class AugmentProcessTest {
         addSources(reactor, MULTIPLE_AUGMENT_INCORRECT);
 
         EffectiveSchemaContext result = null;
-        result = reactor.buildEffective();
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
+
         assertNull(result);
     }
 
-    @Test(expected=SomeModifiersUnresolvedException.class)
+    @Test
     public void multipleAugmentIncorrectPathAndGrpTest()
             throws SourceException, ReactorException {
         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
                 .newBuild();
         addSources(reactor, MULTIPLE_AUGMENT_INCORRECT2);
+
         EffectiveSchemaContext result = null;
-        result = reactor.buildEffective();
+        try {
+            result = reactor.buildEffective();
+        } catch (Exception e) {
+            log(e, "");
+        }
+
         assertNull(result);
     }
 
+    private void log(final Throwable e, final String indent) {
+        System.out.println(indent + e.getMessage());
 
+        Throwable[] suppressed = e.getSuppressed();
+        for (Throwable throwable : suppressed) {
+            log(throwable, indent + "        ");
+        }
+    }
 
     @Test
     public void readAndParseYangFileTest() throws SourceException,
index 1c361e4b5cd09a672cd327b285dd48529be2fd70..ba12bd6ee75ccdd9f6ed5e9157ae542fb28b030b 100644 (file)
@@ -130,7 +130,7 @@ module foo {
         status obsolete;
     }
 
-    augment "/br:interfaces/br:ifEntry/bz:augment-holder" {
+    augment "/br:interfaces/br:ifEntry/br:augment-holder" {
         when "if:ifType='ds0'";
         leaf ds0ChannelNumber {
             type string;
index 412f9c15a94cee69b1eb00034608dba937de79d1..190053010cc7c4994a7f1496e6fa153b495f0528 100644 (file)
@@ -54,7 +54,7 @@ submodule subfoo {
         status obsolete;
     }
 
-    augment "/br:interfaces/br:ifEntry/bz:augment-holder" {
+    augment "/br:interfaces/br:ifEntry/br:augment-holder" {
         when "if:ifType='ds0'";
         leaf subleaf {
             type string;
index 26ec3c8978eb47fea6c0e5d44f5befdb9f2794af..0d030b23fad18061cd0a621d5163b6c68a367b27 100644 (file)
@@ -3,6 +3,10 @@ module multiple-augment-imported {
     namespace "multiple-augment-imported";
     prefix imp;
 
+    augment /root-container/container-from-grp1/sub-container-from-grp1/container-in-uses-augment/sub-container-from-augment2/sub-container-from-augment3 {
+        container sub-container-from-augment4 {
+        }
+    }
 
     container root-container {
         uses grp1 {
@@ -25,6 +29,11 @@ module multiple-augment-imported {
         }
     }
 
+    augment /root-container/added-container-1 {
+        container added-container-2 {
+        }
+    }
+
     grouping grp2 {
         container container-from-grp2 {
             container sub-container-from-grp2 {
@@ -42,10 +51,10 @@ module multiple-augment-imported {
         container sub-container-from-augment2 {
         }
     }
-
+    
     grouping grp-from-import {
         container container-from-grp-from-import {
-
+            
         }
     }
 }
index 5ec75d342b24b98f1a3f68e5e7f1fbe383b4cb23..88123f77367698d74f60ff45b35bb648f9768002 100644 (file)
@@ -4,7 +4,7 @@ module multiple-augment-root {
     prefix root;
 
     import multiple-augment-imported { prefix imp; revision-date 1970-01-01; }
-
+    
     include multiple-augment-submodule { revision-date 1970-01-01; }
 
     augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-in-uses-augment/imp:sub-container-from-augment2 {
@@ -22,7 +22,7 @@ module multiple-augment-root {
         }
     }
 
-    augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2/sub-container-from-augment5 {
+    augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-from-grp2/imp:sub-container-from-grp2/imp:sub-container-from-augment5 {
         container sub-container-from-augment7 {
         }
     }
@@ -36,7 +36,7 @@ module multiple-augment-root {
         container added-container-1 {
         }
     }
-
+    
     container container-with-multiple-uses {
         uses imp:grp-from-import{
             augment container-from-grp-from-import {