Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 Michael Ruflin, Andr´┐Ż Locher, Claudia von Bastian. This file is part of Tatool. Tatool is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Tatool 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Tatool. If not, see <>. /
 package ch.tatool.core.module.initializer;
 import java.util.Map;
ExecutorConfiguration which loads the elements from a Spring context file.

Michael Ruflin
 public class SpringExecutorInitializer implements ExecutorInitializer {
 	private static final String ROOT_ELEMENT = "moduleHierarchy";
Logger used by the service.
     Logger logger = LoggerFactory.getLogger(SpringExecutorInitializer.class);
     public static final String SPRING_ELEMENT_CONFIGURATION_XML_PROPERTY = "SpringXmlElementConfig";

Configures the executor with the given module.
 	public void initialize(Executor executorModule module) {
 		// load the root execution element
 		Element element = fetchRootElement(module);
 		// instantiate the execution strategy
 	protected void setupExecutionStrategy(Executor executorModule module) {
 		// TODO: make this configurable through a module property

Loads the data contained in the configuration file into the module and binary module properties. This method can be used to get data required for a module creation.
 	public boolean loadModuleConfiguration(File configurationXmlFileMap<StringStringmodulePropertiesMap<Stringbyte[]> binaryModuleProperties,  Map<StringDataExportermoduleExporters) {
 		// load the file into a String
         String configurationXML = null;
         try {
             configurationXML = FileUtils.readFileToString(configurationXmlFile"UTF-8");
             return loadModuleConfiguration(configurationXMLmodulePropertiesbinaryModulePropertiesmoduleExporters);
         } catch (IOException ioe) {
             .error("Unable to load Tatool file."ioe);
             return false;
 	public boolean loadModuleConfiguration(String configurationXMLMap<StringStringmodulePropertiesMap<Stringbyte[]> binaryModulePropertiesMap<StringDataExportermoduleExporters) {
 		// test-wise load configuration to ensure all classes are valid
 		// fetch the module properties
 		Map<StringStringsetupProperties = getModuleSetupProperties(configurationXML);
		// fetch the module exporters
		Map<StringDataExporterexporterList = getModuleExporters(configurationXML);
		// write the configuration file and configuration class into the properties too
		try {
			.error("Unable to load Tatool file."e);
			throw new RuntimeException(e);
		return true;
	protected Map<StringStringgetModuleSetupProperties(String configurationXML) {
        // see whether we have module properties
        if (.containsBean("moduleProperties")) {
            Map<StringStringproperties = (Map<StringString>) .getBean("moduleProperties");
            return properties;
        } else {
            return Collections.emptyMap();
    protected Map<StringDataExportergetModuleExporters(String configurationXML) {
        // see whether we have module exporters
        if ( != null && .containsBean("moduleExporters")) {
        	Map<StringDataExporterexporters = (Map<StringDataExporter>) .getBean("moduleExporters");
            return exporters;
        } else {
            return Collections.emptyMap();

Loads the persisted module configuration
    protected Element fetchRootElement(Module module) {
    	// fetch the configuration
        if (configXML == null) {
            // TODO: inform user that module is broken
            throw new RuntimeException("Unable to load Tatool file. Configuration is missing!");
        // load the configuration
        return loadRootElementFromSpringXML(configXML);
Checks whether a configuration xml is valid or not.
    protected Element loadRootElementFromSpringXML(String configXML) {
        // try loading the configuration
    	 = null;
        try {
        	 = new GenericXmlApplicationContextnew ByteArrayResourceconfigXML.getBytes() ) );
        } catch (BeansException be) {
        	.error("Unable to load Tatool file."be);
            throw new RuntimeException("Unable to load Tatool file.");
        // check whether we have the mandatory beans (rootElement)
        if (! .containsBean()) {
        	.error("Unable to load Tatool file. Root element missing!");
        	throw new CreationException("Unable to load Tatool file. Root element missing!");       
        // fetch the rootElement
        try {
        	Element root = (Element.getBean();
        	return root;
        } catch (RuntimeException e) {
        	String[] errors = e.getMessage().split(";");
        	throw new CreationException(errors[errors.length-1]);
New to GrepCode? Check out our FAQ X