X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager-facade-xml%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Ffacade%2Fxml%2Frpc%2FRuntimeRpcElementResolved.java;fp=opendaylight%2Fconfig%2Fconfig-manager-facade-xml%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Ffacade%2Fxml%2Frpc%2FRuntimeRpcElementResolved.java;h=a63114c9adc7ef114d9b80cba310499e77072435;hb=d266f4384d4850af9049d7cddd2bbac8f75ba61e;hp=cd3d72a5c500d75a2e5393c76c2e923e2bd7b83a;hpb=b197d75e803beac663033287d769dce62c108490;p=controller.git diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java index cd3d72a5c5..a63114c9ad 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/rpc/RuntimeRpcElementResolved.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 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, @@ -23,7 +23,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.Module; /** - * Represents parsed xpath to runtime bean instance + * Represents parsed xpath to runtime bean instance. */ public final class RuntimeRpcElementResolved { private final String moduleName; @@ -33,9 +33,9 @@ public final class RuntimeRpcElementResolved { private final Map additionalAttributes; private RuntimeRpcElementResolved(String namespace, String moduleName, String instanceName, String runtimeBeanName, - Map additionalAttributes) { + Map additionalAttributes) { this.moduleName = Preconditions.checkNotNull(moduleName, "Module name"); - this.instanceName = Preconditions.checkNotNull(instanceName, "Instance name"); + this.instanceName = Preconditions.checkNotNull(instanceName, "Instance name"); this.additionalAttributes = additionalAttributes; this.namespace = Preconditions.checkNotNull(namespace, "Namespace"); this.runtimeBeanName = Preconditions.checkNotNull(runtimeBeanName, "Runtime bean name"); @@ -75,52 +75,60 @@ public final class RuntimeRpcElementResolved { } /** - * Pattern for an absolute instance identifier xpath pointing to a runtime bean instance e.g: + * Pattern for an absolute instance identifier xpath pointing to a runtime bean. + * For instance e.g: + * *
      * /modules/module[name=instanceName][type=moduleType]
      * 
+ * + *

* or + * *

      * /a:modules/a:module[a:name=instanceName][a:type=moduleType]
      * 
*/ - private static final String xpathPatternBlueprint = - "/" + getRegExForPrefixedName(Modules.QNAME.getLocalName())+ "/" + getRegExForPrefixedName(Module.QNAME.getLocalName()) + private static final String XPATH_PATTERN_BLUEPRINT = "/" + getRegExForPrefixedName(Modules.QNAME.getLocalName()) + + "/" + getRegExForPrefixedName(Module.QNAME.getLocalName()) - + "\\[" - + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" - + "=('|\")?(?[^'\"\\]]+)('|\")?" - + "( and |\\]\\[)" - + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" - + "=('|\")?(?[^'\"\\]]+)('|\")?" - + "\\]" + + "\\[" + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" + "=('|\")?(?[^'\"\\]]+)('|\")?" + + "( and |\\]\\[)" + "(?" + getRegExForPrefixedName(XmlMappingConstants.TYPE_KEY) + "|" + + getRegExForPrefixedName(XmlMappingConstants.NAME_KEY) + ")" + "=('|\")?(?[^'\"\\]]+)('|\")?" + + "\\]" - + "(?.*)"; + + "(?.*)"; /** - * Return reg ex that matches either the name with or without a prefix + * Return reg ex that matches either the name with or without a prefix. */ private static String getRegExForPrefixedName(final String name) { return "([^:]+:)?" + name; } - private static final Pattern xpathPattern = Pattern.compile(xpathPatternBlueprint); + private static final Pattern XPATH_PATTERN = Pattern.compile(XPATH_PATTERN_BLUEPRINT); /** - * Pattern for additional path elements inside xpath for instance identifier pointing to an inner runtime bean e.g: + * Pattern for additional path elements inside xpath for instance identifier + * pointing to an inner runtime bean. E.g: + * *
      * /modules/module[name=instanceName and type=moduleType]/inner[key=b]
      * 
*/ - private static final String additionalPatternBlueprint = getRegExForPrefixedName("(?.+)") + "\\[(?" + getRegExForPrefixedName("(.+)") + ")=('|\")?(?[^'\"\\]]+)('|\")?\\]"; - private static final Pattern additionalPattern = Pattern.compile(additionalPatternBlueprint); + private static final String ADDITIONAL_PATTERN_BLUEPRINT = getRegExForPrefixedName("(?.+)") + + "\\[(?" + getRegExForPrefixedName("(.+)") + + ")=('|\")?(?[^'\"\\]]+)('|\")?\\]"; + private static final Pattern ADDITIONAL_PATTERN = Pattern.compile(ADDITIONAL_PATTERN_BLUEPRINT); public static RuntimeRpcElementResolved fromXpath(String xpath, String elementName, String namespace) { - Matcher matcher = xpathPattern.matcher(xpath); + Matcher matcher = XPATH_PATTERN.matcher(xpath); Preconditions.checkState(matcher.matches(), "Node %s with value '%s' not in required form on rpc element %s, required format is %s", - //TODO refactor this string, and/or unify with RPR.CONTEXT_INSTANCE from netconf - "context-instance", xpath, elementName, xpathPatternBlueprint); + // TODO refactor this string, and/or unify with RPR.CONTEXT_INSTANCE from + // netconf + "context-instance", xpath, elementName, XPATH_PATTERN_BLUEPRINT); PatternGroupResolver groups = new PatternGroupResolver(matcher.group("key1"), matcher.group("value1"), matcher.group("value2"), matcher.group("additional")); @@ -136,11 +144,13 @@ public final class RuntimeRpcElementResolved { private static final class PatternGroupResolver { - private final String key1, value1, value2; + private final String key1; + private final String value1; + private final String value2; private final String additional; private String runtimeBeanYangName; - PatternGroupResolver(String key1, String value1, String value2, String additional) { + PatternGroupResolver(String key1, String value1, String value2, String additional) { this.key1 = Preconditions.checkNotNull(key1); this.value1 = Preconditions.checkNotNull(value1); this.value2 = Preconditions.checkNotNull(value2); @@ -155,21 +165,19 @@ public final class RuntimeRpcElementResolved { return key1.contains(XmlMappingConstants.NAME_KEY) ? value1 : value2; } - Map getAdditionalKeys(String elementName, String moduleName) { HashMap additionalAttributes = Maps.newHashMap(); runtimeBeanYangName = moduleName; for (String additionalKeyValue : additional.split("/")) { - if (Strings.isNullOrEmpty(additionalKeyValue)){ + if (Strings.isNullOrEmpty(additionalKeyValue)) { continue; } - Matcher matcher = additionalPattern.matcher(additionalKeyValue); - Preconditions - .checkState( - matcher.matches(), - "Attribute %s not in required form on rpc element %s, required format for additional attributes is: %s", - additionalKeyValue, elementName, additionalPatternBlueprint); + Matcher matcher = ADDITIONAL_PATTERN.matcher(additionalKeyValue); + Preconditions.checkState(matcher.matches(), + "Attribute %s not in required form on rpc element %s," + + " required format for additional attributes is: %s", + additionalKeyValue, elementName, ADDITIONAL_PATTERN_BLUEPRINT); String name = matcher.group("additionalKey"); runtimeBeanYangName = name; additionalAttributes.put(name, matcher.group("additionalValue")); @@ -178,7 +186,7 @@ public final class RuntimeRpcElementResolved { } private String getRuntimeBeanYangName() { - Preconditions.checkState(runtimeBeanYangName!=null); + Preconditions.checkState(runtimeBeanYangName != null); return runtimeBeanYangName; } }