blob: 53f8230903bfc298022968a5416eb6c299d4dc5e [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.xml;
18
19import org.dom4j.Element;
20import org.onosproject.yms.ydt.YdtContext;
21
22import java.util.Iterator;
23import java.util.Stack;
24
25/**
26 * Represents a multi instance leaf node handler in YCH.
27 */
28public class XmlCodecMultiInstanceLeafHandler extends XmlCodecHandler {
29
30 @Override
31 public void setXmlValue(YdtContext ydtContext,
32 Stack<Element> elementStack) {
33
34 if (ydtContext.getValueSet().isEmpty()) {
35 return;
36 }
37
38 Iterator<String> iterator = ydtContext.getValueSet().iterator();
39 elementStack.peek().setText(iterator.next());
40 Element topOfStack = elementStack.pop();
41 Element parent = elementStack.peek();
42
43 while (iterator.hasNext()) {
44 Element newElement = updateNameAndNamespace(ydtContext, parent);
45 newElement.setText(iterator.next());
46 }
47 elementStack.push(topOfStack);
48 }
49}