793911262810f826f332f84c75bb642bb1d7fe6e
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / mapping / attributes / fromxml / AbstractAttributeReadingStrategy.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 org.opendaylight.controller.netconf.util.xml.XmlElement;
12
13 import java.util.List;
14
15 public abstract class AbstractAttributeReadingStrategy implements AttributeReadingStrategy {
16
17     private final String nullableDefault;
18
19     public AbstractAttributeReadingStrategy(String nullableDefault) {
20         this.nullableDefault = nullableDefault;
21     }
22
23     public String getNullableDefault() {
24         return nullableDefault;
25     }
26
27     @Override
28     public AttributeConfigElement readElement(List<XmlElement> configNodes) {
29         if (configNodes.size() == 0)
30             return AttributeConfigElement.createNullValue(postprocessNullableDefault(nullableDefault));
31
32         return readElementHook(configNodes);
33     }
34
35     abstract AttributeConfigElement readElementHook(List<XmlElement> configNodes);
36
37     protected Object postprocessNullableDefault(String nullableDefault) {
38         return nullableDefault;
39     }
40 }