2e8b459b70c77fdfc7073e47dcc6a953470451c5
[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     protected Object postprocessParsedValue(String textContent) {
27         char[] charArray = textContent.toCharArray();
28         List<String> chars = Lists.newArrayListWithCapacity(charArray.length);
29
30         for (char c : charArray) {
31             chars.add(Character.toString(c));
32         }
33
34         Map<String, Object> map = Maps.newHashMap();
35         map.put(key, chars);
36         return map;
37     }
38
39     @Override
40     protected Object postprocessNullableDefault(String nullableDefault) {
41         return nullableDefault == null ? null : postprocessParsedValue(nullableDefault);
42     }
43 }