@Override public boolean accepts(ConfigurationGenerator cg) { return cg.getTemplateList().contains(TEMPLATE_NAME); }
/** * Add template(s) to the {@link #PARAM_TEMPLATES_NAME} list if not already present * * @param templatesToAdd Comma separated templates to add * @since 5.5 */ public void addTemplate(String templatesToAdd) throws ConfigurationException { List<String> templatesList = getTemplateList(); List<String> templatesToAddList = asList(templatesToAdd.split(TEMPLATE_SEPARATOR)); if (templatesList.addAll(templatesToAddList)) { String newTemplatesStr = String.join(TEMPLATE_SEPARATOR, templatesList); HashMap<String, String> parametersToSave = new HashMap<>(); parametersToSave.put(PARAM_TEMPLATES_NAME, newTemplatesStr); saveFilteredConfiguration(parametersToSave); changeTemplates(newTemplatesStr); } }
/** * Remove template(s) from the {@link #PARAM_TEMPLATES_NAME} list * * @param templatesToRm Comma separated templates to remove * @since 5.5 */ public void rmTemplate(String templatesToRm) throws ConfigurationException { List<String> templatesList = getTemplateList(); List<String> templatesToRmList = asList(templatesToRm.split(TEMPLATE_SEPARATOR)); if (templatesList.removeAll(templatesToRmList)) { String newTemplatesStr = String.join(TEMPLATE_SEPARATOR, templatesList); Map<String, String> parametersToSave = new HashMap<>(); parametersToSave.put(PARAM_TEMPLATES_NAME, newTemplatesStr); saveFilteredConfiguration(parametersToSave); changeTemplates(newTemplatesStr); } }
protected Collection<BackingChecker> getCheckers() throws ConfigurationException { if (checkers == null) { checkers = new HashSet<>(); for (String template : configurationGenerator.getTemplateList()) { try { File templateDir = configurationGenerator.getTemplateConf(template).getParentFile(); String classPath = getClasspathForTemplate(template); String checkClass = configurationGenerator.getUserConfig() .getProperty(template + PARAM_CHECK_SUFFIX); Optional<URLClassLoader> ucl = getClassLoaderForTemplate(templateDir, classPath); if (ucl.isPresent()) { Class<?> klass = Class.forName(checkClass, true, ucl.get()); checkers.add((BackingChecker) klass.newInstance()); } } catch (IOException e) { log.warn("Unable to read check configuration for template : " + template, e); } catch (ReflectiveOperationException | ClassCastException e) { throw new ConfigurationException("Unable to check configuration for backing service " + template, e); } } } return checkers; }