Class AbstractStreamController
- All Implemented Interfaces:
IStreamController
- Direct Known Subclasses:
CsvProcessingController
,JsonProcessingController
,PmdAnalysisController
This class provides common functionality for controllers including:
- Command configuration and creation using CommandFactory
- StreamConverter lifecycle management
- Error handling and logging
- Input/output validation
Subclasses need to implement the command configuration logic by overriding configureCommands()
method. This allows each controller to define its specific processing
pipeline while inheriting common functionality.
Example usage:
public class CsvToJsonController extends AbstractStreamController { @Override protected CommandConfig[] configureCommands() { return new CommandConfig[] { new CommandConfig(CsvNavigateCommand.class, "Extract CSV data"), new CommandConfig(JsonFormatCommand.class, "Format as JSON") }; } @Override public String getInputDataType() { return "CSV"; } @Override public String getOutputDataType() { return "JSON"; } }
- Since:
- 1.0
- Version:
- 1.0
- Author:
- StreamConverter Team
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Default constructor that initializes the controller. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract CommandConfig[]
Configures the command pipeline for this controller.protected final CommandConfig[]
Gets the configured command configurations.Gets a description of the controller's current configuration.protected final StreamConverter
Gets the configured StreamConverter instance.final boolean
Checks if the controller is properly configured.final List
<CommandResult> process
(InputStream inputStream, OutputStream outputStream) Processes data from input stream to output stream using the configured command pipeline.protected void
Allows subclasses to perform additional validation after configuration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.streamconverter.controller.IStreamController
getInputDataType, getOutputDataType
-
Constructor Details
-
AbstractStreamController
protected AbstractStreamController()Default constructor that initializes the controller.The controller will be configured lazily on first use to allow subclasses to complete their initialization.
-
-
Method Details
-
process
public final List<CommandResult> process(InputStream inputStream, OutputStream outputStream) throws IOException Processes data from input stream to output stream using the configured command pipeline.This method ensures the controller is configured before processing and handles all error scenarios appropriately.
- Specified by:
process
in interfaceIStreamController
- Parameters:
inputStream
- the input stream to read data fromoutputStream
- the output stream to write results to- Returns:
- list of command execution results
- Throws:
IOException
- if an I/O error occurs during processingIllegalArgumentException
- if input parameters are nullIllegalStateException
- if the controller cannot be configured
-
isConfigured
Checks if the controller is properly configured.- Specified by:
isConfigured
in interfaceIStreamController
- Returns:
- true if configured, false otherwise
-
getConfigurationDescription
Gets a description of the controller's current configuration.- Specified by:
getConfigurationDescription
in interfaceIStreamController
- Returns:
- configuration description
-
configureCommands
Configures the command pipeline for this controller.Subclasses must implement this method to define their specific processing pipeline. The returned CommandConfig array will be used to create the actual command objects using EnhancedCommandFactory.
Example implementation:
@Override protected CommandConfig[] configureCommands() { return new CommandConfig[] { new CommandConfig(CsvNavigateCommand.class, "data", "Extract data column"), new CommandConfig(CsvValidateCommand.class, "Validate output", requiredColumns) }; }
- Returns:
- array of command configurations defining the processing pipeline
- Throws:
IllegalStateException
- if the configuration is invalid
-
getCommandConfigs
Gets the configured command configurations.This method is protected to allow subclasses access to the configuration for advanced scenarios while keeping it internal to the controller hierarchy.
- Returns:
- array of command configurations, or null if not yet configured
-
getStreamConverter
Gets the configured StreamConverter instance.This method is protected to allow subclasses access to the StreamConverter for advanced scenarios while keeping it internal to the controller hierarchy.
- Returns:
- the StreamConverter instance, or null if not yet configured
-
validateConfiguration
Allows subclasses to perform additional validation after configuration.This method is called after the command pipeline is configured but before the controller is marked as ready. Subclasses can override this to add custom validation logic.
- Throws:
IllegalStateException
- if validation fails
-