class WriterRegistrationService {

    public TransformerWriter getWriter(String format, OutputStream output, Map<String, String> parameters) {
        try {
            // Sanity check -> ensures format is actually enabled before using it.
            final ExportFormat formatByName = formatRegistrationService.getByName(format);
            if (formatByName == null || !formatByName.isEnabled()) {
                throw new TDPException(UNABLE_TO_USE_EXPORT, ExceptionContext.build().put("format", format));
            }
            if (parameters.isEmpty()) {
                return (TransformerWriter) context.getBean("writer#" + format, output);
            } else {
                return (TransformerWriter) context.getBean("writer#" + format, output, parameters);
            }
        } catch (BeansException be) {
            throw new TDPException(TransformationErrorCodes.OUTPUT_TYPE_NOT_SUPPORTED, be);
        }
    }

}