I have an interface and a class:
public interface FileProcessingService {
String NAME = "fileProcessingService";
void processFile(FileDescriptor fileDescriptor);
}
public class FileDescriptor(){
protected File file;
protected String type;
}
And what I want to do is have it process different filetypes based on the content in the filedescriptor.
Is is possible to have a different service bean for each filetype.
e.g. say i have the following filetypes:
Customer.txt
Supplier.txt
Have a different service bean for each?
Like follows:
@Service(FileProcessingService.NAME)
public class FileProcessingServiceBean implements FileProcessingService {
@Override
public boolean processFile(FileDescriptorExt fileDescriptor) {
return false;
}
}
public class CustomerFileServiceBean extends FileProcessingServiceBean{
@Override
public boolean processFile(FileDescriptorExt fileDescriptor) {
System.out.println("IN CUSTOMER PROCESSOR");
return false;
}
}
public class SupplierFileServiceBean extends FileProcessingServiceBean{
@Override
public boolean processFile(FileDescriptorExt fileDescriptor) {
System.out.println("IN SUPPLIER PROCESSOR");
return false;
}
}
So I can just call
Filedescriptor fd = new FileDescriptor();
fd.setType("Customer");
fd.setFile(Customer.txt);
fileProcessingService.processFile(fd);
And have it automatically process the file with the CustomerFileServiceBean. And if the file is not a customer file, have it process throught the super FileProcessingServiceBean...
Or is this not the right way to go about this? Like how do I get it to choose the appropriate bean e.g. with an annotation or such...? I guess it is downclassing a service - is that possible?