1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-16 18:11:08 +01:00

Remove API parts scheduled to be removed in Smack 4.3

This commit is contained in:
Florian Schmaus 2017-08-16 14:31:46 +02:00
parent 80eaaf2d71
commit ba323b51f9
11 changed files with 39 additions and 158 deletions

View file

@ -205,15 +205,8 @@ public final class AdHocCommandManager extends Manager {
public void registerCommand(String node, String name, final Class<? extends LocalCommand> clazz) {
registerCommand(node, name, new LocalCommandFactory() {
@Override
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException {
try {
return clazz.getConstructor().newInstance();
}
catch (IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e) {
// TODO: Throw those method in Smack 4.3.
throw new IllegalStateException(e);
}
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
return clazz.getConstructor().newInstance();
}
});
}
@ -361,7 +354,15 @@ public final class AdHocCommandManager extends Manager {
try {
// Create a new instance of the command with the
// corresponding sessioid
LocalCommand command = newInstanceOfCmd(commandNode, sessionId);
LocalCommand command;
try {
command = newInstanceOfCmd(commandNode, sessionId);
}
catch (InstantiationException | IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) {
XMPPError.Builder xmppError = XMPPError.getBuilder().setCondition(XMPPError.Condition.internal_server_error).setDescriptiveEnText(e.getMessage());
return respondError(response, xmppError);
}
response.setType(IQ.Type.result);
command.setData(response);
@ -627,26 +628,22 @@ public final class AdHocCommandManager extends Manager {
* @param sessionID the session id of this execution.
* @return the command instance to execute.
* @throws XMPPErrorException if there is problem creating the new instance.
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
*/
@SuppressWarnings("deprecation")
private LocalCommand newInstanceOfCmd(String commandNode, String sessionID) throws XMPPErrorException
{
private LocalCommand newInstanceOfCmd(String commandNode, String sessionID)
throws XMPPErrorException, InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
AdHocCommandInfo commandInfo = commands.get(commandNode);
LocalCommand command;
try {
command = commandInfo.getCommandInstance();
command.setSessionID(sessionID);
command.setName(commandInfo.getName());
command.setNode(commandInfo.getNode());
}
catch (InstantiationException e) {
throw new XMPPErrorException(XMPPError.getBuilder(
XMPPError.Condition.internal_server_error));
}
catch (IllegalAccessException e) {
throw new XMPPErrorException(XMPPError.getBuilder(
XMPPError.Condition.internal_server_error));
}
LocalCommand command = commandInfo.getCommandInstance();
command.setSessionID(sessionID);
command.setName(commandInfo.getName());
command.setNode(commandInfo.getNode());
return command;
}
@ -680,7 +677,7 @@ public final class AdHocCommandManager extends Manager {
}
public LocalCommand getCommandInstance() throws InstantiationException,
IllegalAccessException
IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException
{
return factory.getInstance();
}

View file

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.commands;
import java.lang.reflect.InvocationTargetException;
/**
* A factory for creating local commands. It's useful in cases where instantiation
* of a command is more complicated than just using the default constructor. For example,
@ -34,7 +36,11 @@ public interface LocalCommandFactory {
* @return a LocalCommand instance.
* @throws InstantiationException if creating an instance failed.
* @throws IllegalAccessException if creating an instance is not allowed.
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException;
public LocalCommand getInstance() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException;
}