import com.google.common.base.Preconditions;
import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.List;
public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
+ private static final Logger logger = LoggerFactory.getLogger(SimpleAttributeReadingStrategy.class);
+
public SimpleAttributeReadingStrategy(String nullableDefault) {
super(nullableDefault);
Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + xmlElement
+ " but was " + configNodes.size());
- String textContent = xmlElement.getTextContent();
+ String textContent = "";
+ try{
+ textContent = readElementContent(xmlElement);
+ }catch(IllegalStateException | NullPointerException e) {
+ // yuma sends <attribute /> for empty value instead of <attribute></attribute>
+ logger.warn("Ignoring exception caused by failure to read text element", e);
+ }
Preconditions.checkNotNull(textContent, "This element should contain text %s", xmlElement);
- return AttributeConfigElement.create(getNullableDefault(), postprocessParsedValue(textContent));
+ return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()),
+ postprocessParsedValue(textContent));
+ }
+
+ protected String readElementContent(XmlElement xmlElement) {
+ return xmlElement.getTextContent();
+ }
+
+ @Override
+ protected Object postprocessNullableDefault(String nullableDefault) {
+ return nullableDefault;
}
protected Object postprocessParsedValue(String textContent) {