8f6a7cd1e4d2e4f19918d97fdfbb8f928060a696
[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 java.util.List;
13 import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
14 import org.opendaylight.controller.netconf.util.xml.XmlElement;
15
16 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
17     public SimpleAttributeReadingStrategy(String nullableDefault) {
18         super(nullableDefault);
19     }
20
21     @Override
22     AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException {
23         XmlElement xmlElement = configNodes.get(0);
24         Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement
25                 + " but was " + configNodes.size());
26
27         String textContent = readElementContent(xmlElement);
28         return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()),
29                 postprocessParsedValue(textContent));
30     }
31
32     protected String readElementContent(XmlElement xmlElement) throws NetconfDocumentedException {
33         return xmlElement.getTextContent();
34     }
35
36     @Override
37     protected Object postprocessNullableDefault(String nullableDefault) {
38         return nullableDefault;
39     }
40
41     protected Object postprocessParsedValue(String textContent) {
42         return textContent;
43     }
44
45 }