Bind2Module.java

  1. /**
  2.  *
  3.  * Copyright 2019-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.bind2;

  18. import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.AuthenticatedAndResourceBoundStateDescriptor;
  19. import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.ConnectedButUnauthenticatedStateDescriptor;
  20. import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.SaslAuthenticationStateDescriptor;
  21. import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionModule;
  22. import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal;
  23. import org.jivesoftware.smack.c2s.internal.WalkStateGraphContext;
  24. import org.jivesoftware.smack.fsm.State;
  25. import org.jivesoftware.smack.fsm.StateDescriptor;
  26. import org.jivesoftware.smack.fsm.StateTransitionResult;

  27. public class Bind2Module extends ModularXmppClientToServerConnectionModule<Bind2ModuleDescriptor> {

  28.     protected Bind2Module(Bind2ModuleDescriptor moduleDescriptor,
  29.                     ModularXmppClientToServerConnectionInternal connectionInternal) {
  30.         super(moduleDescriptor, connectionInternal);
  31.     }

  32.     public static final class Bind2StateDescriptor extends StateDescriptor {
  33.         private Bind2StateDescriptor() {
  34.             super(Bind2State.class, 386, StateDescriptor.Property.notImplemented);

  35.             addPredeccessor(ConnectedButUnauthenticatedStateDescriptor.class);
  36.             addSuccessor(AuthenticatedAndResourceBoundStateDescriptor.class);
  37.             declarePrecedenceOver(SaslAuthenticationStateDescriptor.class);
  38.         }

  39.         @Override
  40.         protected Bind2Module.Bind2State constructState(ModularXmppClientToServerConnectionInternal connectionInternal) {
  41.             // This is the trick: the module is constructed prior the states, so we get the actual state out of the module by fetching the module from the connection.
  42.             Bind2Module bind2Module = connectionInternal.connection.getConnectionModuleFor(Bind2ModuleDescriptor.class);
  43.             return bind2Module.constructBind2State(this, connectionInternal);
  44.         }
  45.     }

  46.     private static final class Bind2State extends State {

  47.         private Bind2State(Bind2StateDescriptor bind2StateDescriptor,
  48.                         ModularXmppClientToServerConnectionInternal connectionInternal) {
  49.             super(bind2StateDescriptor, connectionInternal);
  50.         }

  51.         @Override
  52.         public StateTransitionResult.TransitionImpossible isTransitionToPossible(WalkStateGraphContext walkStateGraphContext) {
  53.             return new StateTransitionResult.TransitionImpossibleBecauseNotImplemented(stateDescriptor);
  54.         }

  55.         @Override
  56.         public StateTransitionResult.AttemptResult transitionInto(WalkStateGraphContext walkStateGraphContext) {
  57.             throw new IllegalStateException("Bind2 not implemented");
  58.         }

  59.     }

  60.     public Bind2State constructBind2State(Bind2StateDescriptor bind2StateDescriptor,
  61.                     ModularXmppClientToServerConnectionInternal connectionInternal) {
  62.         return new Bind2State(bind2StateDescriptor, connectionInternal);
  63.     }

  64. }