blob: 254edd925dd9a296b0b0ca48a6ab9fa7807a5124 [file] [log] [blame]
Rama-Huaweib711e5c2016-08-31 07:55:46 +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.yob;
18
19import org.onosproject.yms.app.ydt.YdtExtendedContext;
20import org.onosproject.yms.ydt.YdtType;
21import org.slf4j.Logger;
22import org.slf4j.LoggerFactory;
23
24import java.util.HashMap;
25import java.util.Map;
26
27import static org.onosproject.yms.app.yob.YobConstants.YDT_TYPE_IS_NOT_SUPPORT;
28import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_LEAF_VALUE_NODE;
29import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_NODE;
30import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_LEAF_VALUE_NODE;
31import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_NODE;
32
33/**
34 * Represents an YANG object builder factory to create different types
35 * of YANG data tree node.
36 */
37final class YobHandlerFactory {
38
39 private static final Logger log =
40 LoggerFactory.getLogger(YobSingleInstanceLeafHandler.class);
41
42 /**
43 * Creates single instance node handler.
44 */
45 private static YobSingleInstanceHandler singleInstanceNode =
46 new YobSingleInstanceHandler();
47
48 /**
49 * Creates multi instance node handler.
50 */
51 private static YobMultiInstanceHandler multiInstanceNode =
52 new YobMultiInstanceHandler();
53
54 /**
55 * Creates single instance leaf node handler.
56 */
57 private static YobSingleInstanceLeafHandler singleInstanceLeaf =
58 new YobSingleInstanceLeafHandler();
59
60 /**
61 * Creates multi instance leaf node handler.
62 */
63 private static YobMultiInstanceLeafHandler multiInstanceLeaf =
64 new YobMultiInstanceLeafHandler();
65
66 /**
67 * Map of YANG object builder handler.
68 */
69 private static Map<YdtType, YobHandler> yobHandlerHashMap =
70 new HashMap<>();
71
72 /**
73 * Create instance of YobHandlerFactory.
74 */
75 YobHandlerFactory() {
76 yobHandlerHashMap.put(SINGLE_INSTANCE_NODE, singleInstanceNode);
77 yobHandlerHashMap.put(MULTI_INSTANCE_NODE, multiInstanceNode);
78 yobHandlerHashMap.put(SINGLE_INSTANCE_LEAF_VALUE_NODE,
79 singleInstanceLeaf);
80 yobHandlerHashMap.put(MULTI_INSTANCE_LEAF_VALUE_NODE,
81 multiInstanceLeaf);
82 }
83
84 /**
85 * Returns the corresponding YOB handler for current context.
86 *
87 * @param ydtExtendedContext ydtExtendedContext is used to get application
88 * related information maintained in YDT
89 * @return YANG object builder node
90 */
91 YobHandler getYobHandlerForContext(
92 YdtExtendedContext ydtExtendedContext) {
93 YobHandler yobHandler =
94 yobHandlerHashMap.get(ydtExtendedContext.getYdtType());
95 if (yobHandler == null) {
96 log.error(YDT_TYPE_IS_NOT_SUPPORT);
97 return null;
98 }
99 return yobHandler;
100 }
101}