44cb1e761574a69e9c01d1757ac6a96bf0101473
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / SimpleUnionAttributeReadingStrategy.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.fromxml;
10
11 import com.google.common.collect.Lists;
12 import com.google.common.collect.Maps;
13
14 import java.util.List;
15 import java.util.Map;
16
17 public class SimpleUnionAttributeReadingStrategy extends SimpleAttributeReadingStrategy {
18
19     private final String key;
20
21     public SimpleUnionAttributeReadingStrategy(String nullableDefault, String key) {
22         super(nullableDefault);
23         this.key = key;
24     }
25
26     @Override
27     protected Object postprocessParsedValue(String textContent) {
28         char[] charArray = textContent.toCharArray();
29         List<String> chars = Lists.newArrayListWithCapacity(charArray.length);
30
31         for (char c : charArray) {
32             chars.add(Character.toString(c));
33         }
34
35         Map<String, Object> map = Maps.newHashMap();
36         map.put(key, chars);
37         return map;
38     }
39
40     @Override
41     protected Object postprocessNullableDefault(String nullableDefault) {
42         return nullableDefault == null ? null : postprocessParsedValue(nullableDefault);
43     }
44 }