001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package gov.nist.secauto.metaschema.cli.processor.command; 007 008import gov.nist.secauto.metaschema.cli.processor.CLIProcessor.CallingContext; 009import gov.nist.secauto.metaschema.core.util.ObjectUtils; 010 011import org.apache.commons.cli.CommandLine; 012 013import edu.umd.cs.findbugs.annotations.NonNull; 014 015public abstract class AbstractCommandExecutor implements ICommandExecutor { 016 @NonNull 017 private final CallingContext callingContext; 018 @NonNull 019 private final CommandLine commandLine; 020 021 public AbstractCommandExecutor( 022 @NonNull CallingContext callingContext, 023 @NonNull CommandLine commandLine) { 024 this.callingContext = callingContext; 025 this.commandLine = commandLine; 026 } 027 028 @NonNull 029 protected CallingContext getCallingContext() { 030 return callingContext; 031 } 032 033 @NonNull 034 protected CommandLine getCommandLine() { 035 return commandLine; 036 } 037 038 @Override 039 public abstract void execute() throws CommandExecutionException; 040 041 @NonNull 042 protected ICommand getCommand() { 043 return ObjectUtils.requireNonNull(getCallingContext().getTargetCommand()); 044 } 045}