001/**
002 *
003 * Copyright 2018-2020 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.fsm;
018
019public abstract class StateTransitionResult {
020
021    private final String message;
022
023    protected StateTransitionResult(String message) {
024        this.message = message;
025    }
026
027    @Override
028    public String toString() {
029        return message;
030    }
031
032    public abstract static class AttemptResult extends StateTransitionResult {
033        protected AttemptResult(String message) {
034            super(message);
035        }
036    }
037
038    public static class Success extends AttemptResult {
039
040        public static final Success EMPTY_INSTANCE = new Success();
041
042        private Success() {
043            super("");
044        }
045
046        public Success(String successMessage) {
047            super(successMessage);
048        }
049    }
050
051    public static class Failure extends AttemptResult {
052        public Failure(String failureMessage) {
053            super(failureMessage);
054        }
055    }
056
057    public static final class FailureCausedByException<E extends Exception> extends Failure {
058        private final E exception;
059
060        public FailureCausedByException(E exception) {
061            super(exception.getMessage());
062            this.exception = exception;
063        }
064
065        public E getException() {
066            return exception;
067        }
068    }
069
070    public static final class FailureCausedByTimeout extends Failure {
071
072        public FailureCausedByTimeout(String failureMessage) {
073            super(failureMessage);
074        }
075
076    }
077
078    public abstract static class TransitionImpossible extends StateTransitionResult {
079        protected TransitionImpossible(String message) {
080            super(message);
081        }
082    }
083
084    public static class TransitionImpossibleReason extends TransitionImpossible {
085        public TransitionImpossibleReason(String reason) {
086            super(reason);
087        }
088    }
089
090    public static class TransitionImpossibleBecauseNotImplemented extends TransitionImpossibleReason {
091        public TransitionImpossibleBecauseNotImplemented(StateDescriptor stateDescriptor) {
092            super(stateDescriptor.getFullStateName(false) + " is not implemented (yet)");
093        }
094    }
095}