if (templateElement != null && templateElement.getLocalName().equals(
XMLConfigConstants.TEMPLATE_ELT.getLocalPart())) {
String templateName = templateElement.getAttributeValue(new QName("name"));
SynapseConfiguration config = getSynapseConfiguration();
log.debug("Saving template : " + templateName);
TemplateMediator preSeq = config.getSequenceTemplates().get(templateName);
if (preSeq == null) {
handleException("Unable to save template " + templateName + ". Does not exist");
} else {
// we should first try to build the new sequence. if exception we return
Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(
templateElement, getSynapseConfiguration().getProperties());
boolean statisticsEnable = preSeq.isStatisticsEnable();
// if everything went successfully we remove the sequence
config.removeSequenceTemplate(templateName);
if (mediator instanceof TemplateMediator) {
if (statisticsEnable) {
((TemplateMediator) mediator).enableStatistics();
}
((TemplateMediator) mediator).setFileName(preSeq.getFileName());
config.addSequenceTemplate(templateName, (TemplateMediator) mediator);
}
log.debug("Saved template : " + templateName + " to the configuration");
TemplateMediator templ = config.getSequenceTemplates().get(templateName);
if (templ != null) {
templ.init(getSynapseEnvironment());
persistTemplate(templ);
}
}
} else {
handleException("Unable to save template. Invalid definition");