X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fapi%2FValidationException.java;fp=opendaylight%2Fconfig%2Fconfig-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fapi%2FValidationException.java;h=0000000000000000000000000000000000000000;hp=9daacd16dcffcbf1b2de9fdbbf4146124d9832ca;hb=ac6f2699cd0c1e340cc32e8f0d0ca94c8e9c0cc0;hpb=f43b01b81319959b1907e3e04537f5169e7f33d8 diff --git a/opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/ValidationException.java b/opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/ValidationException.java deleted file mode 100644 index 9daacd16dc..0000000000 --- a/opendaylight/config/config-api/src/main/java/org/opendaylight/controller/config/api/ValidationException.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2013, 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, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.config.api; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * This exception is not intended to be used while implementing modules, it - * aggregates validation exceptions and sends them back to the user. Use - * {@link org.opendaylight.controller.config.api.JmxAttributeValidationException} - * for validating modules instead. - */ -public class ValidationException extends Exception { - private static final long serialVersionUID = -6072893219820274247L; - - private final Map> failedValidations; - - public ValidationException( - final Map> failedValidations) { - super(failedValidations.toString()); - this.failedValidations = Collections.unmodifiableMap(failedValidations); - } - - public static ValidationException createFromCollectedValidationExceptions( - final List collectedExceptions) { - Map> failedValidations = new HashMap<>(); - for (ValidationException ve : collectedExceptions) { - for (Entry> outerEntry : ve.getFailedValidations() - .entrySet()) { - for (Entry innerEntry : outerEntry.getValue().entrySet()) { - String moduleName = outerEntry.getKey(); - String instanceName = innerEntry.getKey(); - ExceptionMessageWithStackTrace ex = innerEntry.getValue(); - Map instanceToExMap = failedValidations - .computeIfAbsent(moduleName, k -> new HashMap<>()); - if (instanceToExMap.containsKey(instanceName)) { - throw new IllegalArgumentException("Cannot merge with same module name " + moduleName - + " and instance name " + instanceName); - } - instanceToExMap.put(instanceName, ex); - } - } - } - return new ValidationException(failedValidations); - } - - public static ValidationException createForSingleException(final ModuleIdentifier moduleIdentifier, - final Exception exception) { - Map> failedValidations = new HashMap<>(); - Map innerMap = new HashMap<>(); - - failedValidations.put(moduleIdentifier.getFactoryName(), innerMap); - innerMap.put(moduleIdentifier.getInstanceName(), new ExceptionMessageWithStackTrace(exception)); - return new ValidationException(failedValidations); - } - - public Map> getFailedValidations() { - return failedValidations; - } - - public static class ExceptionMessageWithStackTrace { - private String message; - private String stackTrace; - - public ExceptionMessageWithStackTrace() { - } - - public ExceptionMessageWithStackTrace(final String message, final String stackTrace) { - this.message = message; - this.stackTrace = stackTrace; - } - - public ExceptionMessageWithStackTrace(final Exception exception) { - this(exception.getMessage(), Arrays.toString(exception.getStackTrace())); - } - - public String getMessage() { - return message; - } - - public String getTrace() { - return stackTrace; - } - - public void setMessage(final String message) { - this.message = message; - } - - public void setStackTrace(final String trace) { - this.stackTrace = trace; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (message == null ? 0 : message.hashCode()); - result = prime * result + (stackTrace == null ? 0 : stackTrace.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - ExceptionMessageWithStackTrace other = (ExceptionMessageWithStackTrace) obj; - if (message == null) { - if (other.message != null) { - return false; - } - } else if (!message.equals(other.message)) { - return false; - } - if (stackTrace == null) { - if (other.stackTrace != null) { - return false; - } - } else if (!stackTrace.equals(other.stackTrace)) { - return false; - } - return true; - } - - @Override - public String toString() { - return message; - } - } -}