Fix non-generic references to NormalizedNode
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / toxml / SimpleUnionAttributeWritingStrategy.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.toxml;
10
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.netconf.confignetconfconnector.util.Util;
13 import org.w3c.dom.Document;
14
15 import java.util.List;
16 import java.util.Map;
17
18 public class SimpleUnionAttributeWritingStrategy extends SimpleAttributeWritingStrategy {
19
20     /**
21      * @param document
22      * @param key
23      */
24     public SimpleUnionAttributeWritingStrategy(Document document, String key) {
25         super(document, key);
26     }
27
28     protected Object preprocess(Object value) {
29         Util.checkType(value, Map.class);
30         Preconditions.checkArgument(((Map<?, ?>)value).size() == 1, "Unexpected number of values in %s, expected 1", value);
31         Object listOfStrings = ((Map<?, ?>) value).values().iterator().next();
32         Util.checkType(listOfStrings, List.class);
33
34         StringBuilder b = new StringBuilder();
35         for (Object character: (List)listOfStrings) {
36             Util.checkType(character, String.class);
37             b.append(character);
38         }
39
40         return b.toString();
41     }
42
43 }