StateTransitionResult.java

  1. /**
  2.  *
  3.  * Copyright 2018-2021 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack.fsm;

  18. import org.jivesoftware.smack.c2s.XmppClientToServerTransport;

  19. public abstract class StateTransitionResult {

  20.     private final String message;

  21.     protected StateTransitionResult(String message) {
  22.         this.message = message;
  23.     }

  24.     @Override
  25.     public String toString() {
  26.         return message;
  27.     }

  28.     public abstract static class AttemptResult extends StateTransitionResult {
  29.         protected AttemptResult(String message) {
  30.             super(message);
  31.         }
  32.     }

  33.     public static class Success extends AttemptResult {

  34.         public static final Success EMPTY_INSTANCE = new Success();

  35.         private Success() {
  36.             super("");
  37.         }

  38.         public Success(String successMessage) {
  39.             super(successMessage);
  40.         }
  41.     }

  42.     public static class Failure extends AttemptResult {
  43.         public Failure(String failureMessage) {
  44.             super(failureMessage);
  45.         }
  46.     }

  47.     public static final class FailureCausedByException<E extends Exception> extends Failure {
  48.         private final E exception;

  49.         public FailureCausedByException(E exception) {
  50.             super(exception.getMessage());
  51.             this.exception = exception;
  52.         }

  53.         public E getException() {
  54.             return exception;
  55.         }
  56.     }

  57.     public static final class FailureCausedByTimeout extends Failure {

  58.         public FailureCausedByTimeout(String failureMessage) {
  59.             super(failureMessage);
  60.         }

  61.     }

  62.     public abstract static class TransitionImpossible extends StateTransitionResult {
  63.         protected TransitionImpossible(String message) {
  64.             super(message);
  65.         }
  66.     }

  67.     public static class TransitionImpossibleReason extends TransitionImpossible {
  68.         public TransitionImpossibleReason(String reason) {
  69.             super(reason);
  70.         }
  71.     }

  72.     public static class TransitionImpossibleBecauseNotImplemented extends TransitionImpossibleReason {
  73.         public TransitionImpossibleBecauseNotImplemented(StateDescriptor stateDescriptor) {
  74.             super(stateDescriptor.getFullStateName(false) + " is not implemented (yet)");
  75.         }
  76.     }

  77.     public static class TransitionImpossibleBecauseNoEndpointsDiscovered extends TransitionImpossibleReason {
  78.         public TransitionImpossibleBecauseNoEndpointsDiscovered(XmppClientToServerTransport transport) {
  79.             super("The transport " + transport + " did not discover any endpoints");
  80.         }
  81.     }
  82. }