Remove yang-test
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / attributes / fromxml / SimpleAttributeReadingStrategy.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.base.Preconditions;
12 import java.util.List;
13 import org.opendaylight.controller.config.util.xml.DocumentedException;
14 import org.opendaylight.controller.config.util.xml.XmlElement;
15
16 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
17     public SimpleAttributeReadingStrategy(final String nullableDefault) {
18         super(nullableDefault);
19     }
20
21     @Override
22     AttributeConfigElement readElementHook(final List<XmlElement> configNodes) throws DocumentedException {
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(final XmlElement xmlElement) throws DocumentedException {
33         return xmlElement.getTextContent();
34     }
35
36     @Override
37     protected Object postprocessNullableDefault(final String nullableDefault) {
38         return nullableDefault;
39     }
40
41     protected Object postprocessParsedValue(final String textContent) {
42         return textContent;
43     }
44
45 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.