From 6959c91c07a68790aaee27484dd896034209f274 Mon Sep 17 00:00:00 2001 From: Irina Muntean <muntean@fortiss.org> Date: Wed, 1 Dec 2021 13:12:44 +0100 Subject: [PATCH] New exception type containing multiple ChainTransformation exceptions Issue-Ref: 4168 Issue-Url: https://git.fortiss.org/af3/af3/-/issues/4168 Signed-off-by: Irina Muntean <muntean@fortiss.org> --- ...llChainTransformationsFailedException.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/exception/AllChainTransformationsFailedException.java diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/exception/AllChainTransformationsFailedException.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/exception/AllChainTransformationsFailedException.java new file mode 100644 index 000000000..81c8b626f --- /dev/null +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/extension/exception/AllChainTransformationsFailedException.java @@ -0,0 +1,79 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2021 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.kernel.extension.exception; + +import java.util.List; + +/** + * + * @author muntean + */ +public class AllChainTransformationsFailedException extends ChainTransformationFailedException { + + /** Stores a reference to the transformation provider chain. */ + private final List<ChainTransformationFailedException> exceptionList; + + /** Constructor. */ + public AllChainTransformationsFailedException( + List<ChainTransformationFailedException> exceptionList) { + super(null, null, null, null); + this.exceptionList = exceptionList; + } + + /** {@inheritDoc} */ + @Override + public String getMessage() { + return getMessage(0); + } + + /** + * @param i + * @return + */ + private String getMessage(int counter) { + String msg = ""; + for(TransformationFailedException ctfe : this.exceptionList) { + String tabs = addTabs(counter); + msg += tabs + "Failed Provider:\n"; + msg += tabs + ctfe.getFailedProvider().getClass().getSimpleName() + "\n"; + + TransformationFailedException cause = (TransformationFailedException)ctfe.getCause(); + if(cause != null) { + msg += tabs + "Cause:\n"; + if(cause instanceof AllChainTransformationsFailedException) + msg += tabs + ((AllChainTransformationsFailedException)cause) + .getMessage(counter + 1) + "\n"; + else + msg += tabs + cause.getMessage() + "\n"; + } + } + return msg; + } + + /** Returns @counter tabs in a string. */ + private String addTabs(int counter) { + String msg = ""; + for(int i = 0; i < counter; i++) { + msg += "\t"; + } + return msg; + } + + /** Returns exceptionList. */ + public List<ChainTransformationFailedException> getExceptionList() { + return exceptionList; + } +} -- GitLab