* @return The Mapping Model.
* @throws IOException Error reading resource configuration data (the mapping model).
* @throws SAXException Error parsing mapping model.
*/
private EdifactModel getMappingModel() throws IOException, SAXException {
EdifactModel edifactModel;
Hashtable mappings = getMappingTable(applicationContext);
synchronized (configuration) {
edifactModel = (EdifactModel) mappings.get(configuration);
if(edifactModel == null) {
try {
ContainerResourceLocator resourceLocator = applicationContext.getResourceLocator();
if(modelConfigData.startsWith("urn:") || modelConfigData.endsWith(".jar") || modelConfigData.endsWith(".zip")) {
throw new IOException("Unsupported mapping model config URI for basic EDI Parser '" + modelConfigData + "'. Check that you are using the correct EDI parser. You may need to configure an Interchange Parser, such as the UN/EDIFACT parser.");
}
if(resourceLocator instanceof URIResourceLocator) {
// This will resolve config paths relative to the containing smooks config file....
edifactModel = EDIParser.parseMappingModel(modelConfigData, (resourceLocator).getBaseURI());
} else {
edifactModel = EDIParser.parseMappingModel(modelConfigData, URIResourceLocator.getSystemBaseURI());
}
if(edifactModel == null) {
logger.error("Invalid " + MODEL_CONFIG_KEY + " config value '" + modelConfigData + "'. Failed to locate EDI Mapping Model resource!");
}
} catch (IOException e) {
IOException newE = new IOException("Error parsing EDI mapping model [" + configuration.getStringParameter(MODEL_CONFIG_KEY) + "]. Target Profile(s) " + getTargetProfiles() + ".");
newE.initCause(e);
throw newE;
} catch (SAXException e) {
throw new SAXException("Error parsing EDI mapping model [" + configuration.getStringParameter(MODEL_CONFIG_KEY) + "]. Target Profile(s) " + getTargetProfiles() + ".", e);
} catch (EDIConfigurationException e) {
throw new SAXException("Error parsing EDI mapping model [" + configuration.getStringParameter(MODEL_CONFIG_KEY) + "]. Target Profile(s) " + getTargetProfiles() + ".", e);
}
mappings.put(configuration, edifactModel);
logger.debug("Parsed, validated and cached EDI mapping model [" + edifactModel.getEdimap().getDescription().getName() + ", Version " + edifactModel.getEdimap().getDescription().getVersion() + "]. Target Profile(s) " + getTargetProfiles() + ".");
} else if(logger.isInfoEnabled()) {
logger.debug("Found EDI mapping model [" + edifactModel.getEdimap().getDescription().getName() + ", Version " + edifactModel.getEdimap().getDescription().getVersion() + "] in the model cache. Target Profile(s) " + getTargetProfiles() + ".");
}
}
return edifactModel;
}