blob: 1dc568cbb9a01294b5bd47bff57113e3ce226015 [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.openconfigplatform.rev20161222.openconfigplatform.platformcomponenttop.DefaultComponents;
19import org.onosproject.yang.model.ModelObject;
20import org.onosproject.yang.model.ResourceId;
21import org.onosproject.yang.runtime.AnnotatedNodeInfo;
22import java.util.List;
23import java.util.ArrayList;
24import java.util.stream.Collectors;
25import com.google.common.collect.ImmutableList;
26
27import static org.onosproject.odtn.utils.YangToolUtil.toCharSequence;
28import static org.onosproject.odtn.utils.YangToolUtil.toCompositeData;
29import static org.onosproject.odtn.utils.YangToolUtil.toDataNode;
30import static org.onosproject.odtn.utils.YangToolUtil.toResourceData;
31import static org.onosproject.odtn.utils.YangToolUtil.toXmlCompositeStream;
32
33/**
34 * Utility class to deal with OPENCONFIG Componets ModelObject & Annotation.
35 */
36public final class OpenConfigComponentsHandler
37 extends OpenConfigObjectHandler<DefaultComponents> {
38
39 private static final String OPENCONFIG_NAME = "components";
40 private static final String NAME_SPACE = "http://openconfig.net/yang/platform";
41
42 /**
43 * OpenConfigComponentsHandler Constructor.
44 */
45 public OpenConfigComponentsHandler() {
46 modelObject = new DefaultComponents();
47 setResourceId(OPENCONFIG_NAME, NAME_SPACE, null, null);
48 annotatedNodeInfos = new ArrayList<AnnotatedNodeInfo>();
49 }
50
51 /**
52 * Add Component to modelObject of target OPENCONFIG.
53 *
54 * @param component OpenConfigComponentHandler having Component to be set for modelObject
55 * @return OpenConfigComponentsHandler of target OPENCONFIG
56 */
57 public OpenConfigComponentsHandler addComponent(OpenConfigComponentHandler component) {
58 modelObject.addToComponent(component.getModelObject());
59 return this;
60 }
61
62 /**
63 * Get List<CharSequence> of target OPENCONFIG.
64 *
65 * @return List<CharSequence> of target OPENCONFIG
66 */
67 public List<CharSequence> getListCharSequence() {
68 return ImmutableList.of(toDataNode((ModelObject) getModelObject())).stream()
69 .map(node -> toCharSequence(toXmlCompositeStream(
70 toCompositeData(toResourceData(
71 ResourceId.builder().build(), node),
72 annotatedNodeInfos))))
73 .collect(Collectors.toList());
74 }
75}