Bug 2366 - new parser API - implementation of declared statements
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / NamespaceBehaviour.java
index 0f795cc1710c81df39b79c44458d0a0ec8c2b92e..129110d8537491c41716a7db9f59d40bcdcb7042 100644 (file)
@@ -29,15 +29,13 @@ 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,
-        SourceLocalSpecial,
-        StatementLocal
+        GLOBAL,
+        SOURCE_LOCAL_SPECIAL,
+        STATEMENT_LOCAL,
     }
 
     public interface Registry {
-
-        abstract <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(Class<N> type);
-
+        <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(Class<N> type);
     }
 
     public interface NamespaceStorageNode {
@@ -48,13 +46,14 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
 
         @Nullable  <K, V, N extends IdentifierNamespace<K, V>> V getFromLocalStorage(Class<N> type, K key);
 
+        //<K, V, N extends IdentifierNamespace<K, V>> Map<K, V> getAllFromLocalStorage(Class<N> type);
+
         @Nullable  <K, V, N extends IdentifierNamespace<K, V>> void addToLocalStorage(Class<N> type, K key, V value);
 
     }
 
     private final Class<N> identifier;
 
-
     protected NamespaceBehaviour(Class<N> identifier) {
         this.identifier = Preconditions.checkNotNull(identifier);
     }
@@ -64,13 +63,13 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
      * Creates global namespace behaviour for supplied namespace type.
      *
      * Global behaviour stores and loads all values from root {@link NamespaceStorageNode}
-     * with type of {@link StorageNodeType#Global}.
+     * with type of {@link StorageNodeType#GLOBAL}.
      *
      * @param identifier Namespace identifier.
      * @return global namespace behaviour for supplied namespace type.
      */
     public static @Nonnull <K,V, N extends IdentifierNamespace<K, V>>  NamespaceBehaviour<K,V,N> global(Class<N> identifier) {
-        return new StorageSpecific<>(identifier, StorageNodeType.Global);
+        return new StorageSpecific<>(identifier, StorageNodeType.GLOBAL);
     }
 
     /**
@@ -79,13 +78,13 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
      *
      * Source-local namespace behaviour stores and loads all values from closest
      * {@link NamespaceStorageNode} ancestor with type of
-     * {@link StorageNodeType#SourceLocalSpecial}.
+     * {@link StorageNodeType#SOURCE_LOCAL_SPECIAL}.
      *
      * @param identifier Namespace identifier.
      * @return source-local namespace behaviour for supplied namespace type.
      */
     public static <K,V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K,V,N> sourceLocal(Class<N> identifier) {
-        return new StorageSpecific<>(identifier, StorageNodeType.SourceLocalSpecial);
+        return new StorageSpecific<>(identifier, StorageNodeType.SOURCE_LOCAL_SPECIAL);
     }
 
     /**
@@ -103,8 +102,10 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
     }
 
     public abstract V getFrom(NamespaceStorageNode storage, K key);
-    public abstract void addTo(NamespaceStorageNode storage,K key,V value);
 
+    //public abstract Map<K, V> getAllFrom(NamespaceStorageNode storage);
+
+    public abstract void addTo(NamespaceStorageNode storage,K key,V value);
 
     @Override
     public Class<N> getIdentifier() {
@@ -115,6 +116,10 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
         return storage.getFromLocalStorage(getIdentifier(), key);
     }
 
+//    protected final Map<K, V> getAllFromLocalStorage(NamespaceStorageNode storage) {
+//        return storage.getAllFromLocalStorage(getIdentifier());
+//    }
+
     protected final void addToStorage(NamespaceStorageNode storage,K key,V value) {
         storage.addToLocalStorage(getIdentifier(),key,value);
     }
@@ -131,12 +136,21 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
         @Override
         public V getFrom(final NamespaceStorageNode storage, final K key) {
             NamespaceStorageNode current = storage;
-            while(current.getParentNamespaceStorage() != null) {
+            while(current.getStorageNodeType() != storageType) {
                 current = current.getParentNamespaceStorage();
             }
             return getFromLocalStorage(current,key);
         }
 
+//        @Override
+//        public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
+//            NamespaceStorageNode current = storage;
+//            while(current.getStorageNodeType() != storageType) {
+//                current = current.getParentNamespaceStorage();
+//            }
+//            return getAllFromLocalStorage(current);
+//        }
+
         @Override
         public void addTo(NamespaceBehaviour.NamespaceStorageNode storage, K key, V value) {
             NamespaceStorageNode current = storage;
@@ -167,11 +181,23 @@ public abstract class NamespaceBehaviour<K,V, N extends IdentifierNamespace<K, V
             return null;
         }
 
+//        @Override
+//        public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
+//            NamespaceStorageNode current = storage;
+//            while(current != null) {
+//                final Map<K, V> val = getAllFromLocalStorage(current);
+//                if(val != null) {
+//                    return val;
+//                }
+//                current = current.getParentNamespaceStorage();
+//            }
+//            return null;
+//        }
+
         @Override
         public void addTo(NamespaceStorageNode storage,K key, V value) {
             addToStorage(storage, key, value);
         }
 
     }
-
 }