2 * Copyright (c) 2013 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.netconf.confignetconfconnector.mapping.attributes.fromxml;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.netconf.util.xml.XmlElement;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
16 import java.util.List;
18 public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
19 private static final Logger logger = LoggerFactory.getLogger(SimpleAttributeReadingStrategy.class);
22 public SimpleAttributeReadingStrategy(String nullableDefault) {
23 super(nullableDefault);
27 AttributeConfigElement readElementHook(List<XmlElement> configNodes) {
28 XmlElement xmlElement = configNodes.get(0);
29 Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement
30 + " but was " + configNodes.size());
32 String textContent = "";
34 textContent = xmlElement.getTextContent();
35 }catch(IllegalStateException | NullPointerException e) {
36 // yuma sends <attribute /> for empty value instead of <attribute></attribute>
37 logger.warn("Ignoring exception caused by failure to read text element", e);
40 Preconditions.checkNotNull(textContent, "This element should contain text %s", xmlElement);
41 return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()),
42 postprocessParsedValue(textContent));
46 protected Object postprocessNullableDefault(String nullableDefault) {
47 return nullableDefault;
50 protected Object postprocessParsedValue(String textContent) {