001/** 002 * 003 * Copyright 2018-2021 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 019import org.jivesoftware.smack.c2s.XmppClientToServerTransport; 020 021public abstract class StateTransitionResult { 022 023 private final String message; 024 025 protected StateTransitionResult(String message) { 026 this.message = message; 027 } 028 029 @Override 030 public String toString() { 031 return message; 032 } 033 034 public abstract static class AttemptResult extends StateTransitionResult { 035 protected AttemptResult(String message) { 036 super(message); 037 } 038 } 039 040 public static class Success extends AttemptResult { 041 042 public static final Success EMPTY_INSTANCE = new Success(); 043 044 private Success() { 045 super(""); 046 } 047 048 public Success(String successMessage) { 049 super(successMessage); 050 } 051 } 052 053 public static class Failure extends AttemptResult { 054 public Failure(String failureMessage) { 055 super(failureMessage); 056 } 057 } 058 059 public static final class FailureCausedByException<E extends Exception> extends Failure { 060 private final E exception; 061 062 public FailureCausedByException(E exception) { 063 super(exception.getMessage()); 064 this.exception = exception; 065 } 066 067 public E getException() { 068 return exception; 069 } 070 } 071 072 public static final class FailureCausedByTimeout extends Failure { 073 074 public FailureCausedByTimeout(String failureMessage) { 075 super(failureMessage); 076 } 077 078 } 079 080 public abstract static class TransitionImpossible extends StateTransitionResult { 081 protected TransitionImpossible(String message) { 082 super(message); 083 } 084 } 085 086 public static class TransitionImpossibleReason extends TransitionImpossible { 087 public TransitionImpossibleReason(String reason) { 088 super(reason); 089 } 090 } 091 092 public static class TransitionImpossibleBecauseNotImplemented extends TransitionImpossibleReason { 093 public TransitionImpossibleBecauseNotImplemented(StateDescriptor stateDescriptor) { 094 super(stateDescriptor.getFullStateName(false) + " is not implemented (yet)"); 095 } 096 } 097 098 public static class TransitionImpossibleBecauseNoEndpointsDiscovered extends TransitionImpossibleReason { 099 public TransitionImpossibleBecauseNoEndpointsDiscovered(XmppClientToServerTransport transport) { 100 super("The transport " + transport + " did not discover any endpoints"); 101 } 102 } 103}