StateMachineException.java

  1. /**
  2.  *
  3.  * Copyright 2018-2020 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 java.util.Collections;
  19. import java.util.List;
  20. import java.util.Map;

  21. import org.jivesoftware.smack.SmackException;
  22. import org.jivesoftware.smack.c2s.internal.WalkStateGraphContext;
  23. import org.jivesoftware.smack.fsm.StateDescriptorGraph.GraphVertex;

  24. public abstract class StateMachineException extends SmackException {

  25.     private static final long serialVersionUID = 1L;

  26.     protected StateMachineException(String message) {
  27.         super(message);
  28.     }

  29.     protected StateMachineException() {
  30.         super();
  31.     }

  32.     public static class SmackMandatoryStateFailedException extends StateMachineException {

  33.         private static final long serialVersionUID = 1L;

  34.         public SmackMandatoryStateFailedException(State state, StateTransitionResult failureReason) {
  35.         }
  36.     }

  37.     public static final class SmackStateGraphDeadEndException extends StateMachineException {

  38.         private final List<State> walkedStateGraphPath;

  39.         private final Map<State, StateTransitionResult> failedStates;

  40.         private final StateDescriptor deadEndState;

  41.         private static final long serialVersionUID = 1L;

  42.         private SmackStateGraphDeadEndException(String message, WalkStateGraphContext walkStateGraphContext, GraphVertex<State> stateVertex) {
  43.             super(message);
  44.             this.walkedStateGraphPath = Collections.unmodifiableList(walkStateGraphContext.getWalk());
  45.             this.failedStates = Collections.unmodifiableMap(walkStateGraphContext.getFailedStates());

  46.             deadEndState = stateVertex.getElement().getStateDescriptor();
  47.         }

  48.         public List<State> getWalkedStateGraph() {
  49.             return walkedStateGraphPath;
  50.         }

  51.         public Map<State, StateTransitionResult> getFailedStates() {
  52.             return failedStates;
  53.         }

  54.         public StateDescriptor getDeadEndState() {
  55.             return deadEndState;
  56.         }

  57.         public static SmackStateGraphDeadEndException from(WalkStateGraphContext walkStateGraphContext, GraphVertex<State> stateVertex) {
  58.             String message = stateVertex + " has no successor vertexes";

  59.             return new SmackStateGraphDeadEndException(message, walkStateGraphContext, stateVertex);
  60.         }
  61.     }
  62. }