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
9 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
11 import java.util.Iterator;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
14 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
15 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
20 class SchemaNodeIdentifierBuildNamespace extends
21 DerivedNamespaceBehaviour<SchemaNodeIdentifier, StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>, SchemaNodeIdentifierBuildNamespace, ChildSchemaNodes<?, ?>>
22 implements IdentifierNamespace<SchemaNodeIdentifier, StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>> {
24 @SuppressWarnings({"unchecked", "rawtypes"})
25 protected SchemaNodeIdentifierBuildNamespace() {
26 super(SchemaNodeIdentifierBuildNamespace.class, (Class) ChildSchemaNodes.class);
30 public StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> get(
31 SchemaNodeIdentifier key) {
32 throw new UnsupportedOperationException("Direct access to namespace is not supported");
36 public StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> getFrom(NamespaceStorageNode storage, SchemaNodeIdentifier key) {
38 final NamespaceStorageNode lookupStartStorage;
39 if(key.isAbsolute() || storage.getStorageNodeType() == StorageNodeType.ROOT_STATEMENT_LOCAL) {
40 lookupStartStorage = NamespaceBehaviour.findClosestTowardsRoot(storage, StorageNodeType.GLOBAL);
42 lookupStartStorage = storage;
44 Iterator<QName> iterator = key.getPathFromRoot().iterator();
45 if(!iterator.hasNext()) {
46 if(lookupStartStorage instanceof StmtContext<?, ?, ?>) {
47 return (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage;
52 StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>> current = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) lookupStartStorage.getFromLocalStorage(ChildSchemaNodes.class, iterator.next());
53 while(current != null && iterator.hasNext()) {
54 current = (StmtContext.Mutable<?, ?, EffectiveStatement<?, ?>>) current.getFromNamespace(ChildSchemaNodes.class, iterator.next());