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.data.impl.leafref;
10 import com.google.common.collect.ImmutableMap;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.Module;
14 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
17 public final class LeafRefContext {
19 private final QName currentNodeQName;
20 private final SchemaPath currentNodePath;
21 private final SchemaContext schemaContext;
22 private final Module module;
24 private final LeafRefPath leafRefTargetPath;
25 private final LeafRefPath absoluteLeafRefTargetPath ;
26 private final String leafRefTargetPathString;
28 private final boolean isReferencedBy;
29 private final boolean isReferencing;
31 private final Map<QName, LeafRefContext> referencingChilds;
32 private final Map<QName, LeafRefContext> referencedByChilds;
33 private final Map<QName, LeafRefContext> referencedByLeafRefCtx;
35 LeafRefContext(final LeafRefContextBuilder leafRefContextBuilder) {
36 this.currentNodeQName = leafRefContextBuilder.getCurrentNodeQName();
37 this.currentNodePath = leafRefContextBuilder.getCurrentNodePath();
38 this.schemaContext = leafRefContextBuilder.getSchemaContext();
39 this.leafRefTargetPath = leafRefContextBuilder.getLeafRefTargetPath();
40 this.absoluteLeafRefTargetPath = leafRefContextBuilder.getAbsoluteLeafRefTargetPath();
41 this.leafRefTargetPathString = leafRefContextBuilder.getLeafRefTargetPathString();
42 this.isReferencedBy = leafRefContextBuilder.isReferencedBy();
43 this.isReferencing = leafRefContextBuilder.isReferencing();
44 this.referencingChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencingChilds());
45 this.referencedByChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencedByChilds());
46 this.referencedByLeafRefCtx = ImmutableMap.copyOf(leafRefContextBuilder.getAllReferencedByLeafRefCtxs());
47 this.module = leafRefContextBuilder.getLeafRefContextModule();
50 public static LeafRefContext create(final SchemaContext ctx) {
52 return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
53 } catch (LeafRefYangSyntaxErrorException e) {
54 throw new IllegalArgumentException(e);
58 public boolean hasLeafRefContextChild() {
59 return hasReferencedChild() || hasReferencingChild();
62 public boolean hasReferencedChild() {
63 return !referencedByChilds.isEmpty();
66 public boolean hasReferencingChild() {
67 return !referencingChilds.isEmpty();
70 public boolean isReferenced() {
71 return isReferencedBy;
74 public boolean isReferencing() {
78 public LeafRefContext getReferencingChildByName(final QName name) {
79 return referencingChilds.get(name);
82 public Map<QName, LeafRefContext> getReferencingChilds() {
83 return referencingChilds;
86 public LeafRefContext getReferencedChildByName(final QName name) {
87 return referencedByChilds.get(name);
90 public Map<QName, LeafRefContext> getReferencedByChilds() {
91 return referencedByChilds;
94 public SchemaPath getCurrentNodePath() {
95 return currentNodePath;
98 public LeafRefPath getLeafRefTargetPath() {
99 return leafRefTargetPath;
102 public String getLeafRefTargetPathString() {
103 return leafRefTargetPathString;
106 public QName getNodeName() {
107 return currentNodeQName;
110 SchemaContext getSchemaContext() {
111 return schemaContext;
114 public LeafRefPath getAbsoluteLeafRefTargetPath() {
115 return absoluteLeafRefTargetPath;
118 public Module getLeafRefContextModule() {
122 public LeafRefContext getReferencedByLeafRefCtxByName(final QName qname) {
123 return referencedByLeafRefCtx.get(qname);
126 public Map<QName, LeafRefContext> getAllReferencedByLeafRefCtxs() {
127 return referencedByLeafRefCtx;