blob: 8b7baddce7606151c313bf0056453468da42baa0 [file] [log] [blame]
Shankara-Huaweid5823ab2016-11-22 10:14:52 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Shankara-Huaweid5823ab2016-11-22 10:14:52 +05303 *
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.ych.defaultcodecs;
18
19import org.onosproject.yms.app.ych.defaultcodecs.xml.DefaultXmlCodec;
20import org.onosproject.yms.ych.YangDataTreeCodec;
21import org.onosproject.yms.ych.YangProtocolEncodingFormat;
22
23import java.util.Collections;
24import java.util.HashMap;
25import java.util.Map;
26
27import static org.onosproject.yms.ych.YangProtocolEncodingFormat.XML;
28
29/**
30 * Default implementation of YANG codec registry.
31 */
32public final class YangCodecRegistry {
33
34 // no instantiation
35 private YangCodecRegistry() {
36 }
37
38 /**
39 * Default codec map.
40 */
41 private static final Map<YangProtocolEncodingFormat, YangDataTreeCodec>
42 DEFAULT_CODECS = new HashMap<>();
43
44 /**
45 * Initialise the default codec map.
46 */
47 public static void initializeDefaultCodec() {
48 DEFAULT_CODECS.put(XML, new DefaultXmlCodec());
49 }
50
51 /**
52 * Returns the default codec map.
53 *
54 * @return the default codec map
55 */
56 public static Map<YangProtocolEncodingFormat, YangDataTreeCodec> getDefaultCodecs() {
57 return Collections.unmodifiableMap(DEFAULT_CODECS);
58 }
59
60 /**
61 * Registers a default codec for the specified data format.
62 *
63 * @param defaultCodec registered data tree codec
64 * @param dataFormat protocol encoding data format
65 */
66 public static void registerDefaultCodec(
67 YangDataTreeCodec defaultCodec,
68 YangProtocolEncodingFormat dataFormat) {
69 DEFAULT_CODECS.put(dataFormat, defaultCodec);
70 }
71}