1 /* 2 * This file is part of Waarp Project (named also Waarp or GG). 3 * 4 * Copyright (c) 2019, Waarp SAS, and individual contributors by the @author 5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of 6 * individual contributors. 7 * 8 * All Waarp Project is free software: you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or (at your 11 * option) any later version. 12 * 13 * Waarp is distributed in the hope that it will be useful, but WITHOUT ANY 14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * Waarp . If not, see <http://www.gnu.org/licenses/>. 19 */ 20 package org.waarp.common.command; 21 22 import org.waarp.common.command.exception.CommandAbstractException; 23 import org.waarp.common.exception.InvalidArgumentException; 24 import org.waarp.common.file.SessionInterface; 25 26 /** 27 * Interface for Command 28 */ 29 public interface CommandInterface { 30 /** 31 * Set the Command from the args 32 * 33 * @param session 34 * @param command 35 * @param arg 36 * @param code 37 */ 38 void setArgs(SessionInterface session, String command, String arg, 39 @SuppressWarnings("rawtypes") Enum code); 40 41 /** 42 * Execute the command. This execution must set the replyCode in the session 43 * to a correct value before 44 * returning. 45 * 46 * @throws CommandAbstractException in case of an FTP Error occurs 47 */ 48 void exec() throws CommandAbstractException; 49 50 /** 51 * This function is intend to allow to force USER->PASS->ACCT->CDW for 52 * instance 53 * 54 * @param extraNextCommand the extraNextCommand to set 55 */ 56 void setExtraNextCommand(@SuppressWarnings("rawtypes") Enum extraNextCommand); 57 58 /** 59 * This function is called when a new command is received to check if this 60 * new 61 * command is positive according 62 * to the previous command and status. 63 * 64 * @param newCommand 65 * 66 * @return True if this new command is OK, else False 67 */ 68 boolean isNextCommandValid(CommandInterface newCommand); 69 70 /** 71 * @return the object 72 */ 73 Object getObject(); 74 75 /** 76 * @param object the object to set 77 */ 78 void setObject(Object object); 79 80 /** 81 * @return the arg 82 */ 83 String getArg(); 84 85 /** 86 * @return the list of arguments 87 */ 88 String[] getArgs(); 89 90 /** 91 * Get an integer value from argument 92 * 93 * @param argx 94 * 95 * @return the integer 96 * 97 * @throws InvalidArgumentException if the argument is not an 98 * integer 99 */ 100 int getValue(String argx) throws InvalidArgumentException; 101 102 /** 103 * @return the command 104 */ 105 String getCommand(); 106 107 /** 108 * Does this command has an argument 109 * 110 * @return True if it has an argument 111 */ 112 boolean hasArg(); 113 114 /** 115 * @return the current SessionInterface 116 */ 117 SessionInterface getSession(); 118 119 // some helpful functions 120 121 /** 122 * Set the previous command as the new current command (used after a 123 * incorrect 124 * sequence of commands or unknown 125 * command). Also clear the Restart object. 126 */ 127 void invalidCurrentCommand(); 128 129 /** 130 * @return The GgCommandCode associated with this command 131 */ 132 Enum getCode(); 133 }