001/** 002 * 003 * Copyright 2019-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.bind2; 018 019import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.AuthenticatedAndResourceBoundStateDescriptor; 020import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.ConnectedButUnauthenticatedStateDescriptor; 021import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnection.SaslAuthenticationStateDescriptor; 022import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionModule; 023import org.jivesoftware.smack.c2s.internal.ModularXmppClientToServerConnectionInternal; 024import org.jivesoftware.smack.c2s.internal.WalkStateGraphContext; 025import org.jivesoftware.smack.fsm.State; 026import org.jivesoftware.smack.fsm.StateDescriptor; 027import org.jivesoftware.smack.fsm.StateTransitionResult; 028 029public class Bind2Module extends ModularXmppClientToServerConnectionModule<Bind2ModuleDescriptor> { 030 031 protected Bind2Module(Bind2ModuleDescriptor moduleDescriptor, 032 ModularXmppClientToServerConnectionInternal connectionInternal) { 033 super(moduleDescriptor, connectionInternal); 034 } 035 036 public static final class Bind2StateDescriptor extends StateDescriptor { 037 private Bind2StateDescriptor() { 038 super(Bind2State.class, 386, StateDescriptor.Property.notImplemented); 039 040 addPredeccessor(ConnectedButUnauthenticatedStateDescriptor.class); 041 addSuccessor(AuthenticatedAndResourceBoundStateDescriptor.class); 042 declarePrecedenceOver(SaslAuthenticationStateDescriptor.class); 043 } 044 045 @Override 046 protected Bind2Module.Bind2State constructState(ModularXmppClientToServerConnectionInternal connectionInternal) { 047 // 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. 048 Bind2Module bind2Module = connectionInternal.connection.getConnectionModuleFor(Bind2ModuleDescriptor.class); 049 return bind2Module.constructBind2State(this, connectionInternal); 050 } 051 } 052 053 private static final class Bind2State extends State { 054 055 private Bind2State(Bind2StateDescriptor bind2StateDescriptor, 056 ModularXmppClientToServerConnectionInternal connectionInternal) { 057 super(bind2StateDescriptor, connectionInternal); 058 } 059 060 @Override 061 public StateTransitionResult.TransitionImpossible isTransitionToPossible(WalkStateGraphContext walkStateGraphContext) { 062 return new StateTransitionResult.TransitionImpossibleBecauseNotImplemented(stateDescriptor); 063 } 064 065 @Override 066 public StateTransitionResult.AttemptResult transitionInto(WalkStateGraphContext walkStateGraphContext) { 067 throw new IllegalStateException("Bind2 not implemented"); 068 } 069 070 } 071 072 public Bind2State constructBind2State(Bind2StateDescriptor bind2StateDescriptor, 073 ModularXmppClientToServerConnectionInternal connectionInternal) { 074 return new Bind2State(bind2StateDescriptor, connectionInternal); 075 } 076 077}