/* * JAME 6.2.1 * http://jame.sourceforge.net * * Copyright 2001, 2016 Andrea Medeghini * * This file is part of JAME. * * JAME is an application for creating fractals and other graphics artifacts. * * JAME is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * JAME is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JAME. If not, see <http://www.gnu.org/licenses/>. * */ package net.sf.jame.devtools.extensions.processor; import java.io.File; import java.io.PrintWriter; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import net.sf.jame.devtools.DevToolsException; import net.sf.jame.devtools.ProcessorDescriptor; import net.sf.jame.devtools.ProcessorParameters; import net.sf.jame.devtools.ProcessorTemplateLoader; import net.sf.jame.devtools.processor.extension.ProcessorExtensionRuntime; import freemarker.template.Configuration; import freemarker.template.Template; public class EnumeratorProcessorRuntime extends ProcessorExtensionRuntime { /** * @see net.sf.jame.devtools.processor.extension.ProcessorExtensionRuntime#process(java.io.File, net.sf.jame.devtools.ProcessorDescriptor, java.util.List, java.util.Map) */ @Override public void process(File path, ProcessorParameters parameters, Map<String, String> variables) throws DevToolsException { try { ProcessorDescriptor element = parameters.getElement(); if (element.isExtension() || element.isConfigurableExtension()) { if (variables.containsKey("generateEnumerator")) { File packagePath = new File(path, variables.get("enumeratorPackageName").replace('.', '/')); packagePath.mkdirs(); Configuration config = new Configuration(); config.setTemplateLoader(new ProcessorTemplateLoader()); HashMap<String, Object> map = new HashMap<String, Object>(); Set<String> imports = new HashSet<String>(); prepare(imports, element); map.putAll(variables); prepareEnumerator(imports, element, variables); List<String> sortedImports = new LinkedList<String>(imports); Collections.sort(sortedImports); map.put("imports", sortedImports); map.put("extension", element); Template template = config.getTemplate("templates/EnumeratorRuntime.ftl"); template.process(map, new PrintWriter(new File(packagePath, capitalize(element.getElementName()) + "EnumeratorRuntime.java"))); } } else if (element.isComplexElement() || element.isSimpleElement()) { } } catch (Exception e) { throw new DevToolsException(e); } } /** * @see net.sf.jame.devtools.processor.extension.ProcessorExtensionRuntime#getName() */ @Override public String getName() { return "EnumeratorRuntime"; } private void prepare(Set<String> imports, ProcessorDescriptor descriptor) { } private void prepareEnumerator(Set<String> imports, ProcessorDescriptor descriptor, Map<String, String> variables) { imports.add("java.util.LinkedList"); imports.add("java.util.List"); imports.add("net.sf.jame.core.extension.Extension"); imports.add("net.sf.jame.core.extension.ExtensionNotFoundException"); imports.add("net.sf.jame.core.scripting.JSException"); imports.add("net.sf.jame.core.scripting.JSExtension"); imports.add("net.sf.jame.core.scripting.extension.EnumeratorExtensionRuntime"); imports.add(descriptor.getRegistryPackageName() + "." + descriptor.getRegistryClassName()); imports.add(descriptor.getExtensionRuntimePackageName() + "." + descriptor.getExtensionRuntimeClassName()); } private static String capitalize(String word) { word = word.substring(0, 1).toUpperCase() + word.substring(1); return word; } }