All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.invation.code.toval.misc.soabase.AbstractSOABaseContainer Maven / Gradle / Ivy

Go to download

TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.

The newest version!
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package de.invation.code.toval.misc.soabase;

import de.invation.code.toval.debug.SimpleDebugger;
import de.invation.code.toval.file.FileUtils;
import de.invation.code.toval.misc.wd.AbstractComponentContainer;
import de.invation.code.toval.validate.ParameterException;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author stocker
 * @param 
 */
public abstract class AbstractSOABaseContainer extends AbstractComponentContainer{

    protected AbstractSOABaseContainer(String serializationPath) {
        super(serializationPath);
    }

    protected AbstractSOABaseContainer(String serializationPath, SimpleDebugger debugger) {
        super(serializationPath, debugger);
    }
    
    @Override
    protected void serializeComponent(C component, String serializationPath, String fileName) throws Exception {
        File pathToStore = new File(serializationPath, fileName);
	component.getProperties().store(pathToStore.getAbsolutePath());
    }

    @Override
    protected C loadComponentFromFile(String file) throws Exception {
        P properties = createNewProperties();
        try {
            properties.load(file);
        } catch (IOException e) {
            throw new IOException("Cannot load properties file: " + FileUtils.separateFileNameFromEnding(file) + ".");
        }
        
        Class baseClass = null;
        try{
            baseClass = properties.getBaseClass();
        } catch(Exception e){
            throw new Exception("Cannot extract property class information from properties file", e);
        }
        if(properties.getClass() == baseClass){
            throw new ParameterException(ParameterException.ErrorCode.INCOMPATIBILITY, "Unexpected SOABase type, expected " + properties.getBaseClass().getSimpleName() + " but got " + baseClass.getSimpleName());
        }
        
        C result = createSOABaseFromProperties(properties);
        result.setName(properties.getName());
        Set activities = properties.getActivities();
        if (activities != null && !activities.isEmpty()) {
            result.addActivities(activities);
        }
        Set subjects = properties.getSubjects();
        if (subjects != null && !subjects.isEmpty()) {
            result.addSubjects(subjects);
        }
        Set attributes = properties.getObjects();
        if (attributes != null && !attributes.isEmpty()) {
            result.addObjects(attributes);
        }
        loadCustomContent(result, properties);
        
        return result;
    }
    
    protected abstract P createNewProperties() throws Exception;
    
    protected abstract C createSOABaseFromProperties(P properties) throws Exception;
    
    protected abstract void loadCustomContent(C SOABase, P properties) throws Exception;

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy