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;
11 import java.io.IOException;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.Module;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
18 public final class LeafRefContext {
20 private final QName currentNodeQName;
21 private final SchemaPath currentNodePath;
22 private final SchemaContext schemaContext;
23 private final Module module;
25 private final LeafRefPath leafRefTargetPath;
26 private final LeafRefPath absoluteLeafRefTargetPath ;
27 private final String leafRefTargetPathString;
29 private final boolean isReferencedBy;
30 private final boolean isReferencing;
32 private final Map<QName, LeafRefContext> referencingChilds;
33 private final Map<QName, LeafRefContext> referencedByChilds;
34 private final Map<QName, LeafRefContext> referencedByLeafRefCtx;
36 LeafRefContext(final LeafRefContextBuilder leafRefContextBuilder) {
37 this.currentNodeQName = leafRefContextBuilder.getCurrentNodeQName();
38 this.currentNodePath = leafRefContextBuilder.getCurrentNodePath();
39 this.schemaContext = leafRefContextBuilder.getSchemaContext();
40 this.leafRefTargetPath = leafRefContextBuilder.getLeafRefTargetPath();
41 this.absoluteLeafRefTargetPath = leafRefContextBuilder.getAbsoluteLeafRefTargetPath();
42 this.leafRefTargetPathString = leafRefContextBuilder.getLeafRefTargetPathString();
43 this.isReferencedBy = leafRefContextBuilder.isReferencedBy();
44 this.isReferencing = leafRefContextBuilder.isReferencing();
45 this.referencingChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencingChilds());
46 this.referencedByChilds = ImmutableMap.copyOf(leafRefContextBuilder.getReferencedByChilds());
47 this.referencedByLeafRefCtx = ImmutableMap.copyOf(leafRefContextBuilder.getAllReferencedByLeafRefCtxs());
48 this.module = leafRefContextBuilder.getLeafRefContextModule();
51 public static LeafRefContext create(final SchemaContext ctx) {
53 return new LeafRefContextTreeBuilder(ctx).buildLeafRefContextTree();
54 } catch (LeafRefYangSyntaxErrorException e) {
55 throw new IllegalArgumentException(e);
56 } catch (IOException e) {
57 throw new IllegalStateException(e);
61 public boolean hasLeafRefContextChild() {
62 return hasReferencedChild() || hasReferencingChild();
65 public boolean hasReferencedChild() {
66 return !referencedByChilds.isEmpty();
69 public boolean hasReferencingChild() {
70 return !referencingChilds.isEmpty();
73 public boolean isReferenced() {
74 return isReferencedBy;
77 public boolean isReferencing() {
81 public LeafRefContext getReferencingChildByName(final QName name) {
82 return referencingChilds.get(name);
85 public Map<QName, LeafRefContext> getReferencingChilds() {
86 return referencingChilds;
89 public LeafRefContext getReferencedChildByName(final QName name) {
90 return referencedByChilds.get(name);
93 public Map<QName, LeafRefContext> getReferencedByChilds() {
94 return referencedByChilds;
97 public SchemaPath getCurrentNodePath() {
98 return currentNodePath;
101 public LeafRefPath getLeafRefTargetPath() {
102 return leafRefTargetPath;
105 public String getLeafRefTargetPathString() {
106 return leafRefTargetPathString;
109 public QName getNodeName() {
110 return currentNodeQName;
113 SchemaContext getSchemaContext() {
114 return schemaContext;
117 public LeafRefPath getAbsoluteLeafRefTargetPath() {
118 return absoluteLeafRefTargetPath;
121 public Module getLeafRefContextModule() {
125 public LeafRefContext getReferencedByLeafRefCtxByName(final QName qname) {
126 return referencedByLeafRefCtx.get(qname);
129 public Map<QName, LeafRefContext> getAllReferencedByLeafRefCtxs() {
130 return referencedByLeafRefCtx;