From f336ffef3aaf674ba23133cb5c5201105e5d8637 Mon Sep 17 00:00:00 2001 From: Dana Kutenicsova Date: Wed, 5 Oct 2016 21:41:14 +0200 Subject: [PATCH] Fix sonar warnings in config-util. Mostly renaming enum constants. Change-Id: I24a3afe1281a070550ef3c8424b35ed58d3691f6 Signed-off-by: Dana Kutenicsova --- .../facade/xml/ConfigSubsystemFacade.java | 6 +- .../SimpleAttributeResolvingStrategy.java | 18 ++-- .../xml/mapping/config/InstanceConfig.java | 6 +- .../strategy/DeleteEditConfigStrategy.java | 12 +-- .../facade/xml/strategy/EditStrategyType.java | 6 +- .../xml/strategy/MergeEditConfigStrategy.java | 12 +-- .../MissingInstanceHandlingStrategy.java | 6 +- .../strategy/ReCreateEditConfigStrategy.java | 12 +-- .../strategy/ReplaceEditConfigStrategy.java | 6 +- .../controller/config/util/CloseableUtil.java | 4 +- .../config/util/ConfigRegistryJMXClient.java | 4 +- .../config/util/xml/DocumentedException.java | 84 +++++++++---------- .../config/util/xml/XmlElement.java | 73 ++++++++-------- .../config/util/xml/XmlMappingConstants.java | 6 +- 14 files changed, 126 insertions(+), 129 deletions(-) diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java index 41629ce422..d70376f579 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/ConfigSubsystemFacade.java @@ -210,9 +210,9 @@ public class ConfigSubsystemFacade implements Closeable { } } catch (InstanceNotFoundException e) { throw new DocumentedException(String.format("Unable to edit ref name " + refNameToServiceEntry.getKey() + " for instance " + on, e), - ErrorType.application, - ErrorTag.operation_failed, - ErrorSeverity.error); + ErrorType.APPLICATION, + ErrorTag.OPERATION_FAILED, + ErrorSeverity.ERROR); } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java index 6c53b80872..5412882e33 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/attributes/resolving/SimpleAttributeResolvingStrategy.java @@ -83,9 +83,9 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS return parseObject(type, value); } catch (Exception e) { throw new DocumentedException("Unable to resolve attribute " + attrName + " from " + value, - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } @@ -97,9 +97,9 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOG.trace("Error parsing object ",e); throw new DocumentedException("Error parsing object.", - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } } @@ -144,9 +144,9 @@ final class SimpleAttributeResolvingStrategy extends AbstractAttributeResolvingS } catch (ParseException e) { LOG.trace("Unable parse value {} due to ",value, e); throw new DocumentedException("Unable to parse value "+value+" as date.", - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java index 84fb06418a..a66fd75dbd 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/mapping/config/InstanceConfig.java @@ -215,9 +215,9 @@ public final class InstanceConfig { if (!foundWithoutNamespaceNodes.isEmpty()){ throw new DocumentedException(String.format("Element %s present multiple times with different namespaces: %s, %s", name, foundConfigNodes, foundWithoutNamespaceNodes), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java index 423fac974f..555af1eb86 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/DeleteEditConfigStrategy.java @@ -29,9 +29,9 @@ public class DeleteEditConfigStrategy extends AbstractEditConfigStrategy { String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException { throw new ConfigHandlingException(String.format("Unable to delete %s : %s , ServiceInstance not found", module, instance), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } @Override @@ -43,9 +43,9 @@ public class DeleteEditConfigStrategy extends AbstractEditConfigStrategy { } catch (InstanceNotFoundException e) { throw new ConfigHandlingException( String.format("Unable to delete %s because of exception %s" + on, e.getMessage()), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java index 47f5078967..9954592b0a 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/EditStrategyType.java @@ -48,9 +48,9 @@ public enum EditStrategyType { throw new OperationNotPermittedException(String.format("With " + defaultStrategy + " as default-operation operations on module elements are not permitted since the default option is restrictive"), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java index 1a5714186c..5f0b23b9ff 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MergeEditConfigStrategy.java @@ -40,9 +40,9 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy { String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ", module, instance), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } @Override @@ -72,9 +72,9 @@ public class MergeEditConfigStrategy extends AbstractEditConfigStrategy { on, configAttributeEntry.getKey(), configAttributeEntry.getValue()), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MissingInstanceHandlingStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MissingInstanceHandlingStrategy.java index 00e850495e..591595eaa5 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MissingInstanceHandlingStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/MissingInstanceHandlingStrategy.java @@ -31,9 +31,9 @@ public class MissingInstanceHandlingStrategy extends AbstractEditConfigStrategy LOG.trace("New instance for {} {} created under name {}", module, instance, on); } catch (InstanceAlreadyExistsException e1) { throw new ConfigHandlingException(String.format("Unable to create instance for %s : %s.", module, instance), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java index 5d695ac171..8df51a2a8f 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReCreateEditConfigStrategy.java @@ -28,9 +28,9 @@ public class ReCreateEditConfigStrategy extends AbstractEditConfigStrategy { String module, String instance, ServiceRegistryWrapper services) throws ConfigHandlingException { throw new ConfigHandlingException( String.format("Unable to recreate %s : %s, Existing module instance not found", module, instance), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } @Override @@ -40,9 +40,9 @@ public class ReCreateEditConfigStrategy extends AbstractEditConfigStrategy { ta.reCreateModule(objectName); } catch(InstanceNotFoundException e) { throw new ConfigHandlingException(String.format("Unable to recreate instance for %s", objectName), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } } diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java index 0d18d56105..9821a8b79e 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/strategy/ReplaceEditConfigStrategy.java @@ -32,9 +32,9 @@ public class ReplaceEditConfigStrategy extends AbstractEditConfigStrategy { String.format("Unable to handle missing instance, no missing instances should appear at this point, missing: %s : %s ", module, instance), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } @Override diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/CloseableUtil.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/CloseableUtil.java index 9777861123..b5f5752dce 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/CloseableUtil.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/CloseableUtil.java @@ -10,6 +10,9 @@ package org.opendaylight.controller.config.util; public class CloseableUtil { + private CloseableUtil() { + } + public static void closeAll(Iterable autoCloseables) throws Exception { Exception lastException = null; for (AutoCloseable autoCloseable : autoCloseables) { @@ -26,6 +29,5 @@ public class CloseableUtil { if (lastException != null) { throw lastException; } - } } diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigRegistryJMXClient.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigRegistryJMXClient.java index 74dd2efed8..71adea8a2f 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigRegistryJMXClient.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/ConfigRegistryJMXClient.java @@ -41,7 +41,7 @@ public class ConfigRegistryJMXClient implements ConfigRegistryClient { this.configMBeanServer = configMBeanServer; this.configRegistryON = configRegistryON; Set searchResult = configMBeanServer.queryMBeans(configRegistryON, null); - if (!(searchResult.size() == 1)) { + if (searchResult.size() != 1) { throw new IllegalStateException("Config registry not found"); } configRegistryMXBeanProxy = JMX.newMXBeanProxy(configMBeanServer, configRegistryON, ConfigRegistryMXBean.class, @@ -87,7 +87,7 @@ public class ConfigRegistryJMXClient implements ConfigRegistryClient { static ObjectName translateServiceRefIfPossible(ObjectName on, Class clazz, MBeanServer configMBeanServer) { ObjectName onObj = on; - if (ObjectNameUtil.isServiceReference(onObj) && clazz.equals(ServiceReferenceMXBean.class) == false) { + if (ObjectNameUtil.isServiceReference(onObj) && !clazz.equals(ServiceReferenceMXBean.class)) { ServiceReferenceMXBean proxy = JMX.newMXBeanProxy(configMBeanServer, onObj, ServiceReferenceMXBean.class); onObj = proxy.getCurrentImplementation(); } diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java index 854255d9f6..09b82f1a96 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/DocumentedException.java @@ -10,7 +10,6 @@ package org.opendaylight.controller.config.util.xml; import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.RPC_REPLY_KEY; import static org.opendaylight.controller.config.util.xml.XmlMappingConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0; - import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -42,7 +41,7 @@ public class DocumentedException extends Exception { private static final long serialVersionUID = 1L; - private final static Logger LOG = LoggerFactory.getLogger( DocumentedException.class ); + private static final Logger LOG = LoggerFactory.getLogger(DocumentedException.class); private static final DocumentBuilderFactory BUILDER_FACTORY; @@ -64,7 +63,7 @@ public class DocumentedException extends Exception { } public enum ErrorType { - transport, rpc, protocol, application; + TRANSPORT, RPC, PROTOCOL, APPLICATION; public String getTagValue() { return name(); @@ -75,31 +74,31 @@ public class DocumentedException extends Exception { return valueOf( text ); } catch( Exception e ) { - return application; + return APPLICATION; } } } public enum ErrorTag { - access_denied("access-denied"), - bad_attribute("bad-attribute"), - bad_element("bad-element"), - data_exists("data-exists"), - data_missing("data-missing"), - in_use("in-use"), - invalid_value("invalid-value"), - lock_denied("lock-denied"), - malformed_message("malformed-message"), - missing_attribute("missing-attribute"), - missing_element("missing-element"), - operation_failed("operation-failed"), - operation_not_supported("operation-not-supported"), - resource_denied("resource-denied"), - rollback_failed("rollback-failed"), - too_big("too-big"), - unknown_attribute("unknown-attribute"), - unknown_element("unknown-element"), - unknown_namespace("unknown-namespace"); + ACCESS_DENIED("access-denied"), + BAD_ATTRIBUTE("bad-attribute"), + BAD_ELEMENT("bad-element"), + DATA_EXISTS("data-exists"), + DATA_MISSING("data-missing"), + IN_USE("in-use"), + INVALID_VALUE("invalid-value"), + LOCK_DENIED("lock-denied"), + MALFORMED_MESSAGE("malformed-message"), + MISSING_ATTRIBUTE("missing-attribute"), + MISSING_ELEMENT("missing-element"), + OPERATION_FAILED("operation-failed"), + OPERATION_NOT_SUPPORTED("operation-not-supported"), + RESOURCE_DENIED("resource-denied"), + ROLLBCK_FAILED("rollback-failed"), + TOO_BIG("too-big"), + UNKNOWN_ATTRIBUTE("unknown-attribute"), + UNKNOWN_ELEMENT("unknown-element"), + UNKNOWN_NAMESPACE("unknown-namespace"); private final String tagValue; @@ -119,12 +118,12 @@ public class DocumentedException extends Exception { } } - return operation_failed; + return OPERATION_FAILED; } } public enum ErrorSeverity { - error, warning; + ERROR, WARNING; public String getTagValue() { return name(); @@ -135,7 +134,7 @@ public class DocumentedException extends Exception { return valueOf( text ); } catch( Exception e ) { - return error; + return ERROR; } } } @@ -147,9 +146,9 @@ public class DocumentedException extends Exception { public DocumentedException(String message) { this(message, - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR ); } @@ -183,29 +182,29 @@ public class DocumentedException extends Exception { public static DocumentedException wrap(E exception) throws DocumentedException { final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.operation_failed.name(), "Exception thrown"); - throw new DocumentedException(exception.getMessage(), exception, ErrorType.application, ErrorTag.operation_failed, - ErrorSeverity.error, errorInfo); + errorInfo.put(ErrorTag.OPERATION_FAILED.name(), "Exception thrown"); + throw new DocumentedException(exception.getMessage(), exception, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, + ErrorSeverity.ERROR, errorInfo); } public static DocumentedException wrap(ValidationException e) throws DocumentedException { final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.operation_failed.name(), "Validation failed"); - throw new DocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed, - ErrorSeverity.error, errorInfo); + errorInfo.put(ErrorTag.OPERATION_FAILED.name(), "Validation failed"); + throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, + ErrorSeverity.ERROR, errorInfo); } public static DocumentedException wrap(ConflictingVersionException e) throws DocumentedException { final Map errorInfo = new HashMap<>(); - errorInfo.put(ErrorTag.operation_failed.name(), "Optimistic lock failed"); - throw new DocumentedException(e.getMessage(), e, ErrorType.application, ErrorTag.operation_failed, - ErrorSeverity.error, errorInfo); + errorInfo.put(ErrorTag.OPERATION_FAILED.name(), "Optimistic lock failed"); + throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, + ErrorSeverity.ERROR, errorInfo); } public static DocumentedException fromXMLDocument( Document fromDoc ) { - ErrorType errorType = ErrorType.application; - ErrorTag errorTag = ErrorTag.operation_failed; - ErrorSeverity errorSeverity = ErrorSeverity.error; + ErrorType errorType = ErrorType.APPLICATION; + ErrorTag errorTag = ErrorTag.OPERATION_FAILED; + ErrorSeverity errorSeverity = ErrorSeverity.ERROR; Map errorInfo = null; String errorMessage = ""; @@ -310,7 +309,8 @@ public class DocumentedException extends Exception { } } catch( ParserConfigurationException e ) { - LOG.error( "Error outputting to XML document", e ); // this shouldn't happen + // this shouldn't happen + LOG.error("Error outputting to XML document", e); } return doc; diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java index 795c6b62db..d58acf128e 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlElement.java @@ -83,9 +83,9 @@ public final class XmlElement { } else { if (!attribKey.startsWith(XmlUtil.XMLNS_ATTRIBUTE_KEY + ":")){ throw new DocumentedException("Attribute doesn't start with :", - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR); } prefix = attribKey.substring(XmlUtil.XMLNS_ATTRIBUTE_KEY.length() + 1); } @@ -108,9 +108,9 @@ public final class XmlElement { if (!getName().equals(expectedName)){ throw new UnexpectedElementException(String.format("Expected %s xml element but was %s", expectedName, getName()), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } @@ -120,9 +120,9 @@ public final class XmlElement { throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s", getNamespaceAttribute(), expectedNamespace), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } @@ -132,9 +132,9 @@ public final class XmlElement { throw new UnexpectedNamespaceException(String.format("Unexpected namespace %s should be %s", getNamespace(), expectedNamespace), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } } @@ -250,9 +250,9 @@ public final class XmlElement { List nameElements = getChildElements(childName); if (nameElements.size() != 1){ throw new DocumentedException("One element " + childName + " expected in " + toString(), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR); } return nameElements.get(0); } @@ -329,9 +329,9 @@ public final class XmlElement { if (children.size() != 1){ throw new DocumentedException(String.format("One element %s:%s expected in %s but was %s", namespace, childName, toString(), children.size()), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR); } return children.get(0); @@ -342,9 +342,9 @@ public final class XmlElement { if (children.size() != 1){ throw new DocumentedException(String.format( "One element expected in %s but was %s", toString(), children.size()), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR); } return children.get(0); } @@ -370,9 +370,9 @@ public final class XmlElement { } } throw new DocumentedException(getName() + " should contain text.", - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR ); } @@ -392,9 +392,9 @@ public final class XmlElement { if (attribute == null || attribute.equals(DEFAULT_NAMESPACE_PREFIX)){ throw new MissingNameSpaceException(String.format("Element %s must specify namespace", toString()), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } return attribute; } @@ -420,9 +420,9 @@ public final class XmlElement { Optional namespaceURI = getNamespaceOptionally(); if (!namespaceURI.isPresent()){ throw new MissingNameSpaceException(String.format("No namespace defined for %s", this), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.operation_failed, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.OPERATION_FAILED, + DocumentedException.ErrorSeverity.ERROR); } return namespaceURI.get(); } @@ -491,9 +491,9 @@ public final class XmlElement { } if (!childElements.isEmpty()){ throw new DocumentedException(String.format("Unrecognised elements %s in %s", childElements, this), - DocumentedException.ErrorType.application, - DocumentedException.ErrorTag.invalid_value, - DocumentedException.ErrorSeverity.error); + DocumentedException.ErrorType.APPLICATION, + DocumentedException.ErrorTag.INVALID_VALUE, + DocumentedException.ErrorSeverity.ERROR); } } @@ -522,12 +522,7 @@ public final class XmlElement { } public boolean hasNamespace() { - if (!getNamespaceAttributeOptionally().isPresent()) { - if (!getNamespaceOptionally().isPresent()) { - return false; - } - } - return true; + return getNamespaceAttributeOptionally().isPresent() || getNamespaceOptionally().isPresent(); } private interface ElementFilteringStrategy { diff --git a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlMappingConstants.java b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlMappingConstants.java index 3065ef0193..e896772b1d 100644 --- a/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlMappingConstants.java +++ b/opendaylight/config/config-util/src/main/java/org/opendaylight/controller/config/util/xml/XmlMappingConstants.java @@ -9,9 +9,6 @@ package org.opendaylight.controller.config.util.xml; public final class XmlMappingConstants { - - private XmlMappingConstants() {} - public static final String RPC_REPLY_KEY = "rpc-reply"; public static final String TYPE_KEY = "type"; public static final String MODULE_KEY = "module"; @@ -27,4 +24,7 @@ public final class XmlMappingConstants { public static final String URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0 = "urn:ietf:params:xml:ns:netconf:base:1.0"; public static final String URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG = "urn:opendaylight:params:xml:ns:yang:controller:config"; + + private XmlMappingConstants() { + } } -- 2.36.6