import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
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.model.api.stmt.SchemaTreeAwareEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.SchemaTreeNamespace;
/**
* @param <V> Value type
* @param <N> Namespace Type
*/
-public abstract class NamespaceBehaviour<K, V, N extends IdentifierNamespace<K, V>>
+public abstract class NamespaceBehaviour<K, V, N extends ParserNamespace<K, V>>
extends AbstractSimpleIdentifiable<Class<N>> {
public enum StorageNodeType {
* @return Namespace behaviour
* @throws NamespaceNotAvailableException when the namespace is not available
*/
- <K, V, N extends IdentifierNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(Class<N> type);
+ <K, V, N extends ParserNamespace<K, V>> NamespaceBehaviour<K, V, N> getNamespaceBehaviour(Class<N> type);
}
public interface NamespaceStorageNode {
@Nullable NamespaceStorageNode getParentNamespaceStorage();
- <K, V, N extends IdentifierNamespace<K, V>> @Nullable V getFromLocalStorage(Class<N> type, K key);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable V getFromLocalStorage(Class<N> type, K key);
- <K, V, N extends IdentifierNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(Class<N> type);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable Map<K, V> getAllFromLocalStorage(Class<N> type);
/**
* Populate specified namespace with a key/value pair, overwriting previous contents. Similar to
* @param value Value
* @return Previously-stored value, or null if the key was not present
*/
- <K, V, N extends IdentifierNamespace<K, V>> @Nullable V putToLocalStorage(Class<N> type, K key, V value);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorage(Class<N> type, K key, V value);
/**
* Populate specified namespace with a key/value pair unless the key is already associated with a value. Similar
* @param value Value
* @return Preexisting value or null if there was no previous mapping
*/
- <K, V, N extends IdentifierNamespace<K, V>> @Nullable V putToLocalStorageIfAbsent(Class<N> type, K key,
- V value);
+ <K, V, N extends ParserNamespace<K, V>> @Nullable V putToLocalStorageIfAbsent(Class<N> type, K key, V value);
}
/**
public interface OnDemandSchemaTreeStorageNode extends NamespaceStorageNode {
/**
* Request that a new member of this node's schema tree statement be added. Implementations are required to
- * perform lookup in their internal structure and create a child if tracktable. Resulting node is expected to
+ * perform lookup in their internal structure and create a child if tractable. Resulting node is expected to
* have been registered with local storage, so that it is accessible through
* {@link #getFromLocalStorage(Class, Object)}.
*
* @return Requested child, if it is present.
* @throws NullPointerException in {@code qname} is null
*/
- <D extends DeclaredStatement<QName>, E extends EffectiveStatement<QName, D>>
+ <D extends DeclaredStatement<QName>, E extends SchemaTreeEffectiveStatement<D>>
@Nullable StmtContext<QName, D, E> requestSchemaTreeChild(QName qname);
}
* @param <N> type parameter
* @return global namespace behaviour for supplied namespace type.
*/
- public static <K, V, N extends IdentifierNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> global(
+ public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> global(
final Class<N> identifier) {
return new StorageSpecific<>(identifier, StorageNodeType.GLOBAL);
}
* @param <N> type parameter
* @return source-local namespace behaviour for supplied namespace type.
*/
- public static <K, V, N extends IdentifierNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> sourceLocal(
+ public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> sourceLocal(
final Class<N> identifier) {
return new StorageSpecific<>(identifier, StorageNodeType.SOURCE_LOCAL_SPECIAL);
}
- public static <K, V, N extends IdentifierNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> statementLocal(
+ public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> statementLocal(
final Class<N> identifier) {
- return new StorageSpecific<>(identifier, StorageNodeType.STATEMENT_LOCAL);
+ return new StatementLocal<>(identifier);
}
/**
* @param <N> type parameter
* @return root-statement-local namespace behaviour for supplied namespace type.
*/
- public static <K, V, N extends IdentifierNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> rootStatementLocal(
+ public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> rootStatementLocal(
final Class<N> identifier) {
return new StorageSpecific<>(identifier, StorageNodeType.ROOT_STATEMENT_LOCAL);
}
* @param <N> type parameter
* @return tree-scoped namespace behaviour for supplied namespace type.
*/
- public static <K, V, N extends IdentifierNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> treeScoped(
+ public static <K, V, N extends ParserNamespace<K, V>> @NonNull NamespaceBehaviour<K, V, N> treeScoped(
final Class<N> identifier) {
return new TreeScoped<>(identifier);
}
storage.putToLocalStorage(getIdentifier(), key, value);
}
- static final class StorageSpecific<K, V, N extends IdentifierNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
- private final StorageNodeType storageType;
-
- StorageSpecific(final Class<N> identifier, final StorageNodeType type) {
+ abstract static class AbstractSpecific<K, V, N extends ParserNamespace<K, V>>
+ extends NamespaceBehaviour<K, V, N> {
+ AbstractSpecific(final Class<N> identifier) {
super(identifier);
- storageType = requireNonNull(type);
}
@Override
- public V getFrom(final NamespaceStorageNode storage, final K key) {
- NamespaceStorageNode current = findClosestTowardsRoot(storage, storageType);
- return getFromLocalStorage(current, key);
+ public final V getFrom(final NamespaceStorageNode storage, final K key) {
+ return getFromLocalStorage(findStorageNode(storage), key);
}
@Override
- public Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
- NamespaceStorageNode current = storage;
- while (current.getStorageNodeType() != storageType) {
- current = current.getParentNamespaceStorage();
- }
+ public final Map<K, V> getAllFrom(final NamespaceStorageNode storage) {
+ return getAllFromLocalStorage(findStorageNode(storage));
+ }
+
+ @Override
+ public final void addTo(final NamespaceStorageNode storage, final K key, final V value) {
+ addToStorage(findStorageNode(storage), key, value);
+ }
+
+ abstract NamespaceStorageNode findStorageNode(NamespaceStorageNode storage);
+ }
+
+ static final class StatementLocal<K, V, N extends ParserNamespace<K, V>> extends AbstractSpecific<K, V, N> {
+ StatementLocal(final Class<N> identifier) {
+ super(identifier);
+ }
+
+ @Override
+ NamespaceStorageNode findStorageNode(final NamespaceStorageNode storage) {
+ return storage;
+ }
+ }
+
+ static final class StorageSpecific<K, V, N extends ParserNamespace<K, V>> extends AbstractSpecific<K, V, N> {
+ private final StorageNodeType storageType;
- return getAllFromLocalStorage(current);
+ StorageSpecific(final Class<N> identifier, final StorageNodeType type) {
+ super(identifier);
+ storageType = requireNonNull(type);
}
@Override
- public void addTo(final NamespaceBehaviour.NamespaceStorageNode storage, final K key, final V value) {
- NamespaceStorageNode current = findClosestTowardsRoot(storage, storageType);
- addToStorage(current, key, value);
+ NamespaceStorageNode findStorageNode(final NamespaceStorageNode storage) {
+ return findClosestTowardsRoot(storage, storageType);
}
@Override
}
}
- static final class TreeScoped<K, V, N extends IdentifierNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
-
+ static final class TreeScoped<K, V, N extends ParserNamespace<K, V>> extends NamespaceBehaviour<K, V, N> {
TreeScoped(final Class<N> identifier) {
super(identifier);
}