blob: 728a59625ac631df97bc805b92f493f1fb4638fc [file] [log] [blame]
Ai Hamanobd51cdd2018-10-18 11:30:07 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.odtn.utils.openconfig;
17
18import org.onosproject.yang.gen.v1.openconfigterminaldevice.rev20161222.openconfigterminaldevice.terminaldevicetop.DefaultTerminalDevice;
19
20import org.onosproject.yang.model.ModelObject;
21import org.onosproject.yang.model.ResourceId;
22import org.onosproject.yang.runtime.AnnotatedNodeInfo;
23import java.util.List;
24import java.util.ArrayList;
25import java.util.stream.Collectors;
26import com.google.common.collect.ImmutableList;
27
28import static org.onosproject.odtn.utils.YangToolUtil.toCharSequence;
29import static org.onosproject.odtn.utils.YangToolUtil.toCompositeData;
30import static org.onosproject.odtn.utils.YangToolUtil.toDataNode;
31import static org.onosproject.odtn.utils.YangToolUtil.toResourceData;
32import static org.onosproject.odtn.utils.YangToolUtil.toXmlCompositeStream;
33
34/**
35 * Utility class to deal with OPENCONFIG TerminalDevice ModelObject & Annotation.
36 */
37public final class OpenConfigTerminalDeviceHandler
38 extends OpenConfigObjectHandler<DefaultTerminalDevice> {
39
40 private static final String OPENCONFIG_NAME = "terminal-device";
41 private static final String NAME_SPACE = "http://openconfig.net/yang/terminal-device";
42
43 /**
44 * OpenConfigTerminalDeviceHandler Constructor.
45 */
46 public OpenConfigTerminalDeviceHandler() {
47 modelObject = new DefaultTerminalDevice();
48 setResourceId(OPENCONFIG_NAME, NAME_SPACE, null, null);
49 annotatedNodeInfos = new ArrayList<AnnotatedNodeInfo>();
50 }
51
52 /**
53 * Add LogicalChannels to modelObject of target OPENCONFIG.
54 *
55 * @param logicalChannels OpenConfigLogicalChannelsHandler having LogicalChannels to be set for
56 * modelObject
57 * @return OpenConfigTerminalDeviceHandler of target OPENCONFIG
58 */
59 public OpenConfigTerminalDeviceHandler addLogicalChannels(
60 OpenConfigLogicalChannelsHandler logicalChannels) {
61 modelObject.logicalChannels(logicalChannels.getModelObject());
62 return this;
63 }
64
65 /**
66 * Get List<CharSequence> of target OPENCONFIG.
67 *
68 * @return List<CharSequence> of target OPENCONFIG
69 */
70 public List<CharSequence> getListCharSequence() {
71 return ImmutableList.of(toDataNode((ModelObject) getModelObject())).stream()
72 .map(node -> toCharSequence(toXmlCompositeStream(
73 toCompositeData(toResourceData(
74 ResourceId.builder().build(), node),
75 annotatedNodeInfos))))
76 .collect(Collectors.toList());
77 }
78}