X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-spi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fspi%2Fmeta%2FNamespaceBehaviour.java;h=20782e2b8ac1cd167e8ed2bf1dbd8a7f005af060;hb=a20c66b18adc7fbbf07c84f09623f77eaa48cfca;hp=9fcba740e922ea0920e52723921756d0a3841471;hpb=ee2a8704ba51ccff4f8411689f4e55371aba71a0;p=yangtools.git diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java index 9fcba740e9..20782e2b8a 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/NamespaceBehaviour.java @@ -9,14 +9,21 @@ package org.opendaylight.yangtools.yang.parser.spi.meta; import static java.util.Objects.requireNonNull; +import com.google.common.annotations.Beta; +import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.base.Verify; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.opendaylight.yangtools.concepts.Identifiable; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.opendaylight.yangtools.concepts.AbstractIdentifiable; +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.parser.spi.SchemaTreeNamespace; /** * Definition / implementation of specific Identifier Namespace behaviour. A namespace behaviour is built on top @@ -27,20 +34,44 @@ import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; * For common behaviour models please use static factories {@link #global(Class)}, {@link #sourceLocal(Class)} and * {@link #treeScoped(Class)}. * - * @param - * Key type - * @param - * Value type - * @param - * Namespace Type + * @param Key type + * @param Value type + * @param Namespace Type */ -public abstract class NamespaceBehaviour> implements Identifiable> { +public abstract class NamespaceBehaviour> + extends AbstractIdentifiable> { public enum StorageNodeType { - GLOBAL, SOURCE_LOCAL_SPECIAL, STATEMENT_LOCAL, ROOT_STATEMENT_LOCAL + /** + * Global storage, visible from all sources. + */ + GLOBAL, + /** + * Storage of the root statement of a particular source and any sources it is importing. + */ + // FIXME: 7.0.0: this is a misnomer and should be renamed + SOURCE_LOCAL_SPECIAL, + /** + * Storage of a single statement. + */ + STATEMENT_LOCAL, + /** + * Storage of the root statement of a particular source. + */ + ROOT_STATEMENT_LOCAL } public interface Registry { + /** + * Get a namespace behavior. + * + * @param type Namespace type class + * @param key type + * @param value type + * @param namespace type + * @return Namespace behaviour + * @throws NamespaceNotAvailableException when the namespace is not available + */ > NamespaceBehaviour getNamespaceBehaviour(Class type); } @@ -52,14 +83,11 @@ public abstract class NamespaceBehaviour> V getFromLocalStorage(Class type, K key); + > @Nullable V getFromLocalStorage(Class type, K key); - @Nullable - > Map getAllFromLocalStorage(Class type); + > @Nullable Map getAllFromLocalStorage(Class type); /** * Populate specified namespace with a key/value pair, overwriting previous contents. Similar to @@ -70,8 +98,7 @@ public abstract class NamespaceBehaviour> V putToLocalStorage(Class type, K key, V value); + > @Nullable V putToLocalStorage(Class type, K key, V value); /** * Populate specified namespace with a key/value pair unless the key is already associated with a value. Similar @@ -82,28 +109,55 @@ public abstract class NamespaceBehaviour> V putToLocalStorageIfAbsent(Class type, K key, V value); + > @Nullable V putToLocalStorageIfAbsent(Class type, K key, + V value); } - private final Class identifier; + /** + * Interface implemented by {@link NamespaceStorageNode}s which support dynamic addition of child elements as they + * are requested. This means that such a node can, defer creation of child namespace storage nodes, in effect lazily + * expanding this namespace on an if-needed basis. + */ + @Beta + 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 tractable. Resulting node is expected to + * have been registered with local storage, so that it is accessible through + * {@link #getFromLocalStorage(Class, Object)}. + * + *

+ * This method must not change its mind about a child's presence -- once it returns non-present, it has to be + * always returning non-present. + * + *

+ * The results produced by this method are expected to be consistent with + * {@link SchemaTreeAwareEffectiveStatement#findSchemaTreeNode(QName)} and + * {@link SchemaTreeNamespace#getFrom(NamespaceStorageNode, QName)}. + * + * @param qname node identifier of the child being requested + * @return Requested child, if it is present. + * @throws NullPointerException in {@code qname} is null + */ + , E extends EffectiveStatement> + @Nullable StmtContext requestSchemaTreeChild(QName qname); + } protected NamespaceBehaviour(final Class identifier) { - this.identifier = requireNonNull(identifier); + super(identifier); } /** * Creates a global namespace behaviour for supplied namespace type. Global behaviour stores and loads all values * from root {@link NamespaceStorageNode} with type of {@link StorageNodeType#GLOBAL}. * - * @param identifier - * Namespace identifier. + * @param identifier Namespace identifier. * @param type parameter * @param type parameter * @param type parameter * @return global namespace behaviour for supplied namespace type. */ - public static @Nonnull > NamespaceBehaviour global( + public static > @NonNull NamespaceBehaviour global( final Class identifier) { return new StorageSpecific<>(identifier, StorageNodeType.GLOBAL); } @@ -113,23 +167,38 @@ public abstract class NamespaceBehaviour type parameter * @param type parameter * @param type parameter * @return source-local namespace behaviour for supplied namespace type. */ - public static > NamespaceBehaviour sourceLocal( + public static > @NonNull NamespaceBehaviour sourceLocal( final Class identifier) { return new StorageSpecific<>(identifier, StorageNodeType.SOURCE_LOCAL_SPECIAL); } - public static > NamespaceBehaviour statementLocal( + public static > @NonNull NamespaceBehaviour statementLocal( final Class identifier) { return new StorageSpecific<>(identifier, StorageNodeType.STATEMENT_LOCAL); } + /** + * Creates a root-statement-local namespace behaviour for supplied namespace type. Root-statement-local namespace + * behaviour stores and loads all values from closest {@link NamespaceStorageNode} ancestor with type + * of {@link StorageNodeType#ROOT_STATEMENT_LOCAL}. + * + * @param identifier Namespace identifier. + * @param type parameter + * @param type parameter + * @param type parameter + * @return root-statement-local namespace behaviour for supplied namespace type. + */ + public static > @NonNull NamespaceBehaviour rootStatementLocal( + final Class identifier) { + return new StorageSpecific<>(identifier, StorageNodeType.ROOT_STATEMENT_LOCAL); + } + /** * Creates tree-scoped namespace behaviour for supplied namespace type. Tree-scoped namespace behaviour searches * for value in all storage nodes up to the root and stores values in supplied node. @@ -141,7 +210,7 @@ public abstract class NamespaceBehaviour type parameter * @return tree-scoped namespace behaviour for supplied namespace type. */ - public static > NamespaceBehaviour treeScoped( + public static > @NonNull NamespaceBehaviour treeScoped( final Class identifier) { return new TreeScoped<>(identifier); } @@ -207,11 +276,6 @@ public abstract class NamespaceBehaviour getIdentifier() { - return identifier; - } - protected final V getFromLocalStorage(final NamespaceStorageNode storage, final K key) { return storage.getFromLocalStorage(getIdentifier(), key); } @@ -225,7 +289,7 @@ public abstract class NamespaceBehaviour> extends NamespaceBehaviour { - StorageNodeType storageType; + private final StorageNodeType storageType; StorageSpecific(final Class identifier, final StorageNodeType type) { super(identifier); @@ -253,6 +317,11 @@ public abstract class NamespaceBehaviour> extends NamespaceBehaviour { @@ -302,4 +371,9 @@ public abstract class NamespaceBehaviour