blob: 4f076ab830e01c5447b94f20179100203b8f40a8 [file] [log] [blame]
Bharat saraswalf53b29a2016-09-27 15:35:15 +05301/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.yms.app.ysr;
18
19import com.google.common.collect.ImmutableMap;
20import org.onosproject.yangutils.datamodel.YangSchemaNode;
21
22import java.util.Map;
23import java.util.Objects;
24import java.util.concurrent.ConcurrentHashMap;
25import java.util.concurrent.ConcurrentMap;
26
27/**
28 * Represents registered application's context for YANG schema registry.
29 */
30public class YsrAppContext {
31
32 /**
33 * Current application's YANG schema node.
34 */
35 private YangSchemaNode curNode;
36
37 /**
38 * Current application's YANG schema node with different revision store.
39 */
40 private final ConcurrentMap<String, YangSchemaNode>
41 multiRevisionSchemaNodeStore;
42
43 /**
44 * Current application's object.
45 */
46 private Object appObject;
47
48 /**
49 * Jar file path.
50 */
51 private String jarPath;
52
53 /**
54 * If for current object notification is registered.
55 */
56 private boolean isNotificationRegistered;
57
58 /**
59 * Creates an instance of YANG schema registry application context.
60 */
61 YsrAppContext() {
62 multiRevisionSchemaNodeStore = new ConcurrentHashMap<>();
63 }
64
65 /**
66 * Returns current application's object.
67 *
68 * @return current application's object
69 */
70 Object appObject() {
71 return appObject;
72 }
73
74 /**
75 * Sets current application's object.
76 *
77 * @param appObject current application's object
78 */
79 void appObject(Object appObject) {
80 this.appObject = appObject;
81 }
82
83 /**
84 * Returns current application's YANG schema node.
85 *
86 * @return current application's YANG schema node
87 */
88 YangSchemaNode curNode() {
89 return curNode;
90 }
91
92 /**
93 * Sets current application's schema node.
94 *
95 * @param node current schema's node
96 */
97 void curNode(YangSchemaNode node) {
98 curNode = node;
99 }
100
101 /**
102 * Returns jar file path.
103 *
104 * @return jar file path
105 */
106 String jarPath() {
107 return jarPath;
108 }
109
110 /**
111 * Sets jar file path.
112 *
113 * @param jarPath jar file path
114 */
115 void jarPath(String jarPath) {
116 this.jarPath = jarPath;
117 }
118
119 @Override
120 public int hashCode() {
121 return Objects.hash(curNode, appObject);
122 }
123
124 @Override
125 public boolean equals(Object obj) {
126 if (this == obj) {
127 return true;
128 }
129 if (obj instanceof YsrAppContext) {
130 YsrAppContext that = (YsrAppContext) obj;
131 return Objects.equals(curNode, that.curNode) &&
132 Objects.equals(appObject, that.appObject);
133 }
134 return false;
135 }
136
137 /**
138 * Returns true if for application object notification is registered.
139 *
140 * @return true if for application object notification is registered
141 */
142 boolean isNotificationRegistered() {
143 return isNotificationRegistered;
144 }
145
146 /**
147 * Sets true if for application object notification is registered.
148 *
149 * @param notificationRegistered true if for application object notification is registered
150 */
151 void setNotificationRegistered(boolean notificationRegistered) {
152 isNotificationRegistered = notificationRegistered;
153 }
154
155 /**
156 * Returns YANG schema node store for specific revision.
157 *
158 * @return YANG schema node store for specific revision
159 */
160 Map<String, YangSchemaNode> getYangSchemaNodeForRevisionStore() {
161 return ImmutableMap.copyOf(multiRevisionSchemaNodeStore);
162 }
163
164 /**
165 * Returns a schema node for specific revision from store.
166 *
167 * @param nodeNameWithRevision schema node name for specific revision
168 * @return schema node for specific revision.
169 */
170 YangSchemaNode getSchemaNodeForRevisionStore(String nodeNameWithRevision) {
171 return multiRevisionSchemaNodeStore.get(nodeNameWithRevision);
172 }
173
174 /**
175 * Removes a schema node of specific revision from store.
176 *
177 * @param nodeNameWithRevision schema node name for specific revision
178 */
179 void removeSchemaNodeForRevisionStore(String nodeNameWithRevision) {
180 multiRevisionSchemaNodeStore.remove(nodeNameWithRevision);
181 }
182
183 /**
184 * Adds schema node with revision from store.
185 *
186 * @param nodeNameWithRevision schema node name for specific revision
187 * @param schemaNode schema node for specific revision
188 */
189 void addSchemaNodeWithRevisionStore(String nodeNameWithRevision, YangSchemaNode schemaNode) {
190 multiRevisionSchemaNodeStore.put(nodeNameWithRevision, schemaNode);
191 }
192}