Decouple config and netconf subsystems.
[controller.git] / opendaylight / config / config-manager-facade-xml / src / main / java / org / opendaylight / controller / config / facade / xml / mapping / config / Services.java
@@ -1,12 +1,13 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
 
-package org.opendaylight.controller.netconf.confignetconfconnector.mapping.config;
+package org.opendaylight.controller.config.facade.xml.mapping.config;
+
 
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
@@ -18,11 +19,11 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.management.ObjectName;
 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.XmlUtil;
+import org.opendaylight.controller.config.facade.xml.mapping.attributes.fromxml.ObjectNameAttributeReadingStrategy;
+import org.opendaylight.controller.config.util.xml.DocumentedException;
+import org.opendaylight.controller.config.util.xml.XmlElement;
+import org.opendaylight.controller.config.util.xml.XmlMappingConstants;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -84,7 +85,7 @@ public final class Services {
 
     // TODO support edit strategies on services
 
-    public static Services fromXml(XmlElement xml) throws NetconfDocumentedException {
+    public static Services fromXml(XmlElement xml) throws DocumentedException {
         Map<String, Map<String, Map<String, String>>> retVal = Maps.newHashMap();
 
         List<XmlElement> services = xml.getChildElements(SERVICE_KEY);
@@ -103,7 +104,8 @@ public final class Services {
                 retVal.put(prefixNamespace.getValue(), namespaceToServices);
             }
 
-            String serviceName =  ObjectNameAttributeReadingStrategy.checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
+            String serviceName =  ObjectNameAttributeReadingStrategy
+                .checkPrefixAndExtractServiceName(typeElement, prefixNamespace);
 
             Map<String, String> innerMap = namespaceToServices.get(serviceName);
             if (innerMap == null) {
@@ -111,7 +113,7 @@ public final class Services {
                 namespaceToServices.put(serviceName, innerMap);
             }
 
-            List<XmlElement> instances = service.getChildElements(XmlNetconfConstants.INSTANCE_KEY);
+            List<XmlElement> instances = service.getChildElements(XmlMappingConstants.INSTANCE_KEY);
             service.checkUnrecognisedElements(instances, typeElement);
 
             for (XmlElement instance : instances) {
@@ -120,8 +122,8 @@ public final class Services {
 
                 if (!ModifyAction.DELETE.toString().toLowerCase().equals(
                         instance.getAttribute(
-                                XmlNetconfConstants.OPERATION_ATTR_KEY,
-                                XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)))
+                                XmlMappingConstants.OPERATION_ATTR_KEY,
+                                XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0)))
                 {
                     XmlElement providerElement = instance.getOnlyChildElement(PROVIDER_KEY);
                     String providerName = providerElement.getTextContent();
@@ -140,7 +142,7 @@ public final class Services {
     }
 
     public static Element toXml(ServiceRegistryWrapper serviceRegistryWrapper, Document document) {
-        Element root = XmlUtil.createElement(document, XmlNetconfConstants.SERVICES_KEY, Optional.of(XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
+        Element root = XmlUtil.createElement(document, XmlMappingConstants.SERVICES_KEY, Optional.of(XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG));
 
         Map<String, Map<String, Map<String, String>>> mappedServices = serviceRegistryWrapper.getMappedServices();
         for (Entry<String, Map<String, Map<String, String>>> namespaceToRefEntry : mappedServices.entrySet()) {
@@ -152,13 +154,13 @@ public final class Services {
 
                 // type belongs to config.yang namespace
                 String serviceType = serviceEntry.getKey();
-                Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlNetconfConstants.TYPE_KEY,
-                        XmlNetconfConstants.PREFIX, namespaceToRefEntry.getKey(), serviceType);
+                Element typeElement = XmlUtil.createTextElementWithNamespacedContent(document, XmlMappingConstants.TYPE_KEY,
+                        XmlMappingConstants.PREFIX, namespaceToRefEntry.getKey(), serviceType);
 
                 serviceElement.appendChild(typeElement);
 
                 for (Entry<String, String> instanceEntry : serviceEntry.getValue().entrySet()) {
-                    Element instanceElement = XmlUtil.createElement(document, XmlNetconfConstants.INSTANCE_KEY, Optional.<String>absent());
+                    Element instanceElement = XmlUtil.createElement(document, XmlMappingConstants.INSTANCE_KEY, Optional.<String>absent());
                     serviceElement.appendChild(instanceElement);
 
                     Element nameElement = XmlUtil.createTextElement(document, NAME_KEY, instanceEntry.getKey(), Optional.<String>absent());
@@ -216,22 +218,22 @@ public final class Services {
         }
 
         private static final String blueprint = "/"
-                + XmlNetconfConstants.MODULES_KEY + "/" + XmlNetconfConstants.MODULE_KEY + "["
-                + XmlNetconfConstants.TYPE_KEY + "='%s']["
-                + XmlNetconfConstants.NAME_KEY + "='%s']";
+                + XmlMappingConstants.MODULES_KEY + "/" + XmlMappingConstants.MODULE_KEY + "["
+                + XmlMappingConstants.TYPE_KEY + "='%s']["
+                + XmlMappingConstants.NAME_KEY + "='%s']";
 
         // TODO unify with xpath in RuntimeRpc
 
         // Previous version of xpath, needs to be supported for backwards compatibility (persisted configs by config-persister)
-        private static final String blueprintRDeprecated = "/" + XmlNetconfConstants.CONFIG_KEY + "/"
-                + XmlNetconfConstants.MODULES_KEY + "/" + XmlNetconfConstants.MODULE_KEY + "\\["
-                + XmlNetconfConstants.NAME_KEY + "='%s'\\]/" + XmlNetconfConstants.INSTANCE_KEY + "\\["
-                + XmlNetconfConstants.NAME_KEY + "='%s'\\]";
+        private static final String blueprintRDeprecated = "/" + XmlMappingConstants.CONFIG_KEY + "/"
+                + XmlMappingConstants.MODULES_KEY + "/" + XmlMappingConstants.MODULE_KEY + "\\["
+                + XmlMappingConstants.NAME_KEY + "='%s'\\]/" + XmlMappingConstants.INSTANCE_KEY + "\\["
+                + XmlMappingConstants.NAME_KEY + "='%s'\\]";
 
         private static final String blueprintR = "/"
-                + XmlNetconfConstants.MODULES_KEY + "/" + XmlNetconfConstants.MODULE_KEY + "\\["
-                + XmlNetconfConstants.TYPE_KEY + "='%s'\\]\\["
-                + XmlNetconfConstants.NAME_KEY + "='%s'\\]";
+                + XmlMappingConstants.MODULES_KEY + "/" + XmlMappingConstants.MODULE_KEY + "\\["
+                + XmlMappingConstants.TYPE_KEY + "='%s'\\]\\["
+                + XmlMappingConstants.NAME_KEY + "='%s'\\]";
 
         private static final Pattern pDeprecated = Pattern.compile(String.format(blueprintRDeprecated, "(.+)", "(.+)"));
         private static final Pattern p = Pattern.compile(String.format(blueprintR, "(.+)", "(.+)"));