2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.rfc7950.namespace;
10 import com.google.common.annotations.Beta;
11 import java.util.Iterator;
12 import java.util.Optional;
13 import javax.annotation.Nonnull;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
17 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
20 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
21 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
24 * Legacy namespace for looking up nodes by their Schema Tree identifier.
26 * @deprecated Use path-based utilities provided around {@link ChildSchemaNodeNamespace} instead.
30 public final class SchemaNodeIdentifierBuildNamespace
31 extends DerivedNamespaceBehaviour<SchemaNodeIdentifier, Mutable<?, ?, EffectiveStatement<?, ?>>, QName,
32 SchemaNodeIdentifierBuildNamespace, ChildSchemaNodeNamespace<?, ?>>
33 implements IdentifierNamespace<SchemaNodeIdentifier, Mutable<?, ?, EffectiveStatement<?, ?>>> {
35 @SuppressWarnings({"unchecked", "rawtypes"})
36 public SchemaNodeIdentifierBuildNamespace() {
37 super(SchemaNodeIdentifierBuildNamespace.class, (Class) ChildSchemaNodeNamespace.class);
41 * Find statement context identified by interpreting specified {@link SchemaNodeIdentifier} starting at specified
42 * {@link StmtContext}.
44 * @param root Search root context
45 * @param identifier {@link SchemaNodeIdentifier} relative to search root
46 * @return Matching statement context, if present.
47 * @throws NullPointerException if any of the arguments is null
48 * @deprecated Use {@link ChildSchemaNodeNamespace#findNode(StmtContext, SchemaNodeIdentifier)} instead.
51 public static Optional<StmtContext<?, ?, ?>> findNode(final StmtContext<?, ?, ?> root,
52 final SchemaNodeIdentifier identifier) {
53 return ChildSchemaNodeNamespace.findNode(root, identifier);
57 public Mutable<?, ?, EffectiveStatement<?, ?>> get(@Nonnull final SchemaNodeIdentifier key) {
58 throw new UnsupportedOperationException("Direct access to namespace is not supported");
61 @SuppressWarnings("unchecked")
63 public Mutable<?, ?, EffectiveStatement<?, ?>> getFrom(final NamespaceStorageNode storage,
64 final SchemaNodeIdentifier key) {
65 final NamespaceStorageNode lookupStartStorage;
66 if (key.isAbsolute() || storage.getStorageNodeType() == StorageNodeType.ROOT_STATEMENT_LOCAL) {
67 lookupStartStorage = NamespaceBehaviour.findClosestTowardsRoot(storage, StorageNodeType.GLOBAL);
69 lookupStartStorage = storage;
71 final Iterator<QName> iterator = key.getPathFromRoot().iterator();
72 if (!iterator.hasNext()) {
73 if (lookupStartStorage instanceof StmtContext<?, ?, ?>) {
74 return (Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage;
78 QName nextPath = iterator.next();
79 Mutable<?, ?, EffectiveStatement<?, ?>> current = lookupStartStorage.getFromLocalStorage(
80 ChildSchemaNodeNamespace.class,nextPath);
81 if (current == null && lookupStartStorage instanceof StmtContext<?, ?, ?>) {
82 return ChildSchemaNodeNamespace.tryToFindUnknownStatement(nextPath.getLocalName(),
83 (Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage);
85 while (current != null && iterator.hasNext()) {
86 nextPath = iterator.next();
87 final Mutable<?, ?, EffectiveStatement<?, ?>> nextNodeCtx = current.getFromNamespace(
88 ChildSchemaNodeNamespace.class,nextPath);
89 if (nextNodeCtx == null) {
90 return ChildSchemaNodeNamespace.tryToFindUnknownStatement(nextPath.getLocalName(), current);
92 current = nextNodeCtx;
98 public QName getSignificantKey(final SchemaNodeIdentifier key) {
99 return key.getLastComponent();