Decouple config and netconf subsystems.
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / fromxml / SimpleUnionAttributeReadingStrategy.java
1 /*
2  * Copyright (c) 2015 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.config.facade.xml.mapping.attributes.fromxml;
10
11 import com.google.common.collect.Lists;
12 import com.google.common.collect.Maps;
13 import java.util.List;
14 import java.util.Map;
15
16 public class SimpleUnionAttributeReadingStrategy extends SimpleAttributeReadingStrategy {
17
18     private final String key;
19
20     public SimpleUnionAttributeReadingStrategy(String nullableDefault, String key) {
21         super(nullableDefault);
22         this.key = key;
23     }
24
25     @Override
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 }