X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fmapping%2Fattributes%2Ffromxml%2FObjectNameAttributeReadingStrategy.java;h=8720c654c61f993f09d6503305fdc471d4065a94;hb=25a9fb7730311a5ca298d8c6c8b24f0afb0e27be;hp=bdb9391e2b5a26ac7191eac76448c422a2f0ad11;hpb=a92d9d6a21a0f6ca8d2153795721f500eaf29ee9;p=controller.git diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java index bdb9391e2b..8720c654c6 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/attributes/fromxml/ObjectNameAttributeReadingStrategy.java @@ -8,38 +8,58 @@ 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.config.yangjmxgenerator.attribute.DependencyAttribute; + +import java.util.List; +import java.util.Map; + +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.mapping.ObjectNameAttributeMappingStrategy; import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; -import java.util.List; +public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReadingStrategy { -public class ObjectNameAttributeReadingStrategy extends AbstractAttributeReadingStrategy { + private static final Object PREFIX_SEPARATOR = ":"; - public ObjectNameAttributeReadingStrategy(DependencyAttribute attributeIfc) { - super(attributeIfc); + public ObjectNameAttributeReadingStrategy(String nullableDefault) { + super(nullableDefault); } @Override - AttributeConfigElement readElementHook(List configNodes) { + AttributeConfigElement readElementHook(List configNodes) throws NetconfDocumentedException { XmlElement firstChild = configNodes.get(0); Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + firstChild + " but was " + configNodes.size()); Preconditions.checkNotNull(firstChild, "Element %s should be present", firstChild); - return AttributeConfigElement.create(getAttributeIfc(), resolve(firstChild)); + return AttributeConfigElement.create(getNullableDefault(), resolve(firstChild)); } - private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) { + private ObjectNameAttributeMappingStrategy.MappedDependency resolve(XmlElement firstChild) throws NetconfDocumentedException{ XmlElement typeElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.TYPE_KEY); - String serviceName = typeElement.getTextContent(); + Map.Entry prefixNamespace = typeElement.findNamespaceOfTextContent(); + + String serviceName = checkPrefixAndExtractServiceName(typeElement, prefixNamespace); + XmlElement nameElement = firstChild.getOnlyChildElementWithSameNamespace(XmlNetconfConstants.NAME_KEY); String dependencyName = nameElement.getTextContent(); - return new ObjectNameAttributeMappingStrategy.MappedDependency(serviceName, dependencyName); + return new ObjectNameAttributeMappingStrategy.MappedDependency(prefixNamespace.getValue(), serviceName, + dependencyName); + } + + public static String checkPrefixAndExtractServiceName(XmlElement typeElement, Map.Entry prefixNamespace) throws NetconfDocumentedException { + String serviceName = typeElement.getTextContent(); + // FIXME: comparing Entry with String: + Preconditions.checkState(!prefixNamespace.equals(""), "Service %s value not prefixed with namespace", + XmlNetconfConstants.TYPE_KEY); + String prefix = prefixNamespace.getKey() + PREFIX_SEPARATOR; + Preconditions.checkState(serviceName.startsWith(prefix), + "Service %s not correctly prefixed, expected %s, but was %s", XmlNetconfConstants.TYPE_KEY, prefix, + serviceName); + serviceName = serviceName.substring(prefix.length()); + return serviceName; } }