package org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml;
import com.google.common.base.Preconditions;
-import org.opendaylight.controller.config.yangjmxgenerator.attribute.AttributeIfc;
import org.opendaylight.controller.netconf.util.xml.XmlElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import javax.management.openmbean.OpenType;
import java.util.List;
-public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy<AttributeIfc> {
+public class SimpleAttributeReadingStrategy extends AbstractAttributeReadingStrategy {
+ private static final Logger logger = LoggerFactory.getLogger(SimpleAttributeReadingStrategy.class);
- public SimpleAttributeReadingStrategy(AttributeIfc attributeIfc) {
- super(attributeIfc);
- }
- /**
- * @param elementOpenType
- */
- public SimpleAttributeReadingStrategy(OpenType<?> elementOpenType) {
- super(new AttributeIfcWrapper(elementOpenType));
+ public SimpleAttributeReadingStrategy(String nullableDefault) {
+ super(nullableDefault);
}
@Override
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 = xmlElement.getTextContent();
+ }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(getAttributeIfc(), textContent);
+ return AttributeConfigElement.create(postprocessNullableDefault(getNullableDefault()),
+ postprocessParsedValue(textContent));
}
- /**
- * Wrapper for JavaAttribute inner element attributes (in case JavaAttribute
- * is array)
- */
- static class AttributeIfcWrapper implements AttributeIfc {
-
- private final OpenType<?> elementOpenType;
-
- public AttributeIfcWrapper(OpenType<?> elementOpenType) {
- this.elementOpenType = elementOpenType;
- }
-
- @Override
- public String getAttributeYangName() {
- return null;
- }
-
- @Override
- public String getNullableDescription() {
- return null;
- }
-
- @Override
- public String getNullableDefault() {
- return null;
- }
-
- @Override
- public String getUpperCaseCammelCase() {
- return null;
- }
-
- @Override
- public String getLowerCaseCammelCase() {
- return null;
- }
-
- @Override
- public OpenType<?> getOpenType() {
- return elementOpenType;
- }
+ @Override
+ protected Object postprocessNullableDefault(String nullableDefault) {
+ return nullableDefault;
+ }
+ protected Object postprocessParsedValue(String textContent) {
+ return textContent;
}
+
}