2 * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.config.facade.xml.mapping.attributes.toxml;
11 import com.google.common.base.Preconditions;
12 import java.util.List;
14 import org.opendaylight.controller.config.facade.xml.util.Util;
15 import org.w3c.dom.Document;
17 public class SimpleUnionAttributeWritingStrategy extends SimpleAttributeWritingStrategy {
19 public SimpleUnionAttributeWritingStrategy(final Document document, final String key) {
24 protected Object preprocess(final Object value) {
25 Util.checkType(value, Map.class);
26 Preconditions.checkArgument(((Map<?, ?>) value).size() == 1, "Unexpected number of values in %s, expected 1",
28 Object listOfStrings = ((Map<?, ?>) value).values().iterator().next();
29 Util.checkType(listOfStrings, List.class);
31 StringBuilder builder = new StringBuilder();
32 for (Object character : (List<?>) listOfStrings) {
33 Util.checkType(character, String.class);
34 builder.append(character);
36 return builder.toString();