Merge changes Ia268965a,Iefa79f99
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / SimpleAttributeReadingStrategy.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.base.Preconditions;
12 import org.opendaylight.controller.netconf.util.xml.XmlElement;
13
14 import java.util.List;
15
16 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
17
18     public SimpleAttributeReadingStrategy(String nullableDefault) {
19         super(nullableDefault);
20     }
21
22     @Override
23     AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
24         XmlElement xmlElement = configNodes.get(0);
25         Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement
26                 + " but was " + configNodes.size());
27
28         String textContent = xmlElement.getTextContent();
29
30         Preconditions.checkNotNull(textContent, "This element should contain text %s", xmlElement);
31         return AttributeConfigElement.create(getNullableDefault(), postprocessParsedValue(textContent));
32     }
33
34     protected Object postprocessParsedValue(String textContent) {
35         return textContent;
36     }
37
38 }