Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
Expand All @@ -50,6 +51,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import javax.xml.XMLConstants;

Expand Down Expand Up @@ -220,18 +222,39 @@ private void generateComponentClasses(Task task) throws ParserConfigurationExcep
}
}

private final TransformerFactory transformerFactory = new net.sf.saxon.TransformerFactoryImpl();

private final Map<String, Templates> templatesCache = new ConcurrentHashMap<>();

private Transformer createTransformer(Task task, String xsltFile)
throws TransformerFactoryConfigurationError, TransformerConfigurationException {
StreamSource styleSource;
final String cacheKey;
final StreamSource styleSource;
File xslt = new File(task.getTransformDirectory() + "/" + xsltFile);
if (xslt.exists()) {
cacheKey = xslt.getAbsolutePath();
styleSource = new StreamSource(xslt);
} else {
logInfo("Loading predefined xslt file:" + xsltFile);
cacheKey = "classpath:" + xsltFile;
styleSource = new StreamSource(this.getClass().getResourceAsStream(xsltFile));
}
TransformerFactory transformerFactory = new net.sf.saxon.TransformerFactoryImpl();
return transformerFactory.newTransformer(styleSource);

try {
Templates templates = templatesCache.computeIfAbsent(cacheKey, k -> {
try {
return transformerFactory.newTemplates(styleSource);
} catch (TransformerConfigurationException e) {
throw new CodeGenerationException(e);
}
});
return templates.newTransformer();
} catch (CodeGenerationException e) {
if (e.getCause() instanceof TransformerConfigurationException) {
throw (TransformerConfigurationException) e.getCause();
}
throw e;
}
}

private final Map<String, Document> specificationCache = new HashMap<>();
Expand Down
Loading