X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fconfignetconfconnector%2Fmapping%2Fconfig%2FServices.java;h=bdb4c1b067ff19947a01484165ba25563ba53e0a;hp=9767b3f0560cdeae5f51927a1275dec0e7f8f29f;hb=b3e553ce5b3d3e972cbe19465ab7af2fcb39934c;hpb=3ab0ebe1df3e7606cce0a61572f79bf12deb17c0 diff --git a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java index 9767b3f056..bdb4c1b067 100644 --- a/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java +++ b/opendaylight/netconf/config-netconf-connector/src/main/java/org/opendaylight/controller/netconf/confignetconfconnector/mapping/config/Services.java @@ -8,31 +8,28 @@ package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.management.ObjectName; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectNameAttributeReadingStrategy; import org.opendaylight.controller.netconf.util.xml.XmlElement; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.Maps; +import javax.management.ObjectName; -public final class Services { +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.regex.Matcher; +import java.util.regex.Pattern; - private static final Logger logger = LoggerFactory.getLogger(Services.class); +public final class Services { private static final String PROVIDER_KEY = "provider"; private static final String NAME_KEY = "name"; @@ -86,7 +83,7 @@ public final class Services { // TODO support edit strategies on services - public static Services fromXml(XmlElement xml) { + public static Services fromXml(XmlElement xml) throws NetconfDocumentedException { Map>> retVal = Maps.newHashMap(); List services = xml.getChildElements(SERVICE_KEY); @@ -97,7 +94,7 @@ public final class Services { XmlElement typeElement = service.getOnlyChildElement(TYPE_KEY); Entry prefixNamespace = typeElement.findNamespaceOfTextContent(); - Preconditions.checkState(prefixNamespace.getKey()!=null && prefixNamespace.getKey().equals("") == false, "Type attribute was not prefixed"); + Preconditions.checkState(prefixNamespace.getKey()!=null && !prefixNamespace.getKey().equals(""), "Type attribute was not prefixed"); Map> namespaceToServices = retVal.get(prefixNamespace.getValue()); if(namespaceToServices == null) { @@ -107,8 +104,11 @@ public final class Services { String serviceName = ObjectNameAttributeReadingStrategy.checkPrefixAndExtractServiceName(typeElement, prefixNamespace); - Map innerMap = Maps.newHashMap(); - namespaceToServices.put(serviceName, innerMap); + Map innerMap = namespaceToServices.get(serviceName); + if (innerMap == null) { + innerMap = Maps.newHashMap(); + namespaceToServices.put(serviceName, innerMap); + } List instances = service.getChildElements(XmlNetconfConstants.INSTANCE_KEY); service.checkUnrecognisedElements(instances, typeElement); @@ -133,14 +133,18 @@ public final class Services { Element root = XmlUtil.createElement(document, XmlNetconfConstants.SERVICES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG)); Map>> mappedServices = serviceRegistryWrapper.getMappedServices(); - for (String namespace : mappedServices.keySet()) { + for (Entry>> namespaceToRefEntry : mappedServices.entrySet()) { - for (Entry> serviceEntry : mappedServices.get(namespace).entrySet()) { + for (Entry> serviceEntry : namespaceToRefEntry.getValue().entrySet()) { + // service belongs to config.yang namespace Element serviceElement = XmlUtil.createElement(document, SERVICE_KEY, Optional.absent()); root.appendChild(serviceElement); - Element typeElement = XmlUtil.createPrefixedTextElement(document, XmlUtil.createPrefixedValue(XmlNetconfConstants.PREFIX, TYPE_KEY), XmlNetconfConstants.PREFIX, - serviceEntry.getKey(), Optional.of(namespace)); + // type belongs to config.yang namespace + String serviceType = serviceEntry.getKey(); + Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlNetconfConstants.TYPE_KEY, + XmlNetconfConstants.PREFIX, namespaceToRefEntry.getKey(), serviceType); + serviceElement.appendChild(typeElement); for (Entry instanceEntry : serviceEntry.getValue().entrySet()) { @@ -168,7 +172,7 @@ public final class Services { public static ServiceInstance fromString(String instanceId) { instanceId = instanceId.trim(); Matcher matcher = p.matcher(instanceId); - if(matcher.matches() == false) { + if(!matcher.matches()) { matcher = pDeprecated.matcher(instanceId); } @@ -236,23 +240,30 @@ public final class Services { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj){ return true; - if (obj == null) + } + if (obj == null){ return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()){ return false; + } ServiceInstance other = (ServiceInstance) obj; if (instanceName == null) { - if (other.instanceName != null) + if (other.instanceName != null){ return false; - } else if (!instanceName.equals(other.instanceName)) + } + } else if (!instanceName.equals(other.instanceName)){ return false; + } if (moduleName == null) { - if (other.moduleName != null) + if (other.moduleName != null){ return false; - } else if (!moduleName.equals(other.moduleName)) + } + } else if (!moduleName.equals(other.moduleName)){ return false; + } return true; }