2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml;
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;
16 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
17 public SimpleAttributeReadingStrategy(final String nullableDefault) {
18 super(nullableDefault);
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());
27 String textContent = readElementContent(xmlElement);
28 return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()),
29 postprocessParsedValue(textContent));
32 protected String readElementContent(final XmlElement xmlElement) throws DocumentedException {
33 return xmlElement.getTextContent();
37 protected Object postprocessNullableDefault(final String nullableDefault) {
38 return nullableDefault;
41 protected Object postprocessParsedValue(final String textContent) {