if(log.isInfoEnabled()) {
log.info("Uploading data from file '" + fileName + "'");
}
if(fileName.endsWith(XML_EXT)) {
if(xmlScript2RepresentationClass == null) {
throw new BusinessLogicException("The xml script requires configured name2class mapping!");
}
int divIdx1 = fileName.indexOf('_');
int divIdx2 = fileName.indexOf('.');
if(divIdx1 == -1 || divIdx2 == -1) {
throw new BusinessLogicException("Illegal file name format: '" + fileName + "'");
}
Class dataRepresentationClass = xmlScript2RepresentationClass.get(fileName.substring(divIdx1 + 1, divIdx2));
if(dataRepresentationClass == null) {
throw new BusinessLogicException("Cannot find data representation mapping for the file '" + fileName + "'");
}
JAXBContext context;
try {
context = JAXBContext.newInstance(dataRepresentationClass);
} catch (JAXBException e) {
throw new BusinessLogicException("Cannot create JAXB context for class '" + dataRepresentationClass.getName() + "'", e);
}
Object dataRepresentation;
try {
dataRepresentation = context.createUnmarshaller().unmarshal(nextScript);
} catch (JAXBException e) {
throw new BusinessLogicException("Cannot marshal script '" + nextScript + "'", e);
}
dataImportersFactory.importData(dataRepresentation);
} else if(fileName.endsWith(SQL_EXT)){
sqlScriptsExecutor.executeScripts(nextScript);
}