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

oms3.dsl.OutputDescriptor Maven / Gradle / Ivy

Go to download

Object Modeling System (OMS) is a pure Java object-oriented framework. OMS v3.+ is a highly interoperable and lightweight modeling framework for component-based model and simulation development on multiple platforms.

There is a newer version: 3.5.12
Show newest version
/*
 * $Id: OutputDescriptor.java 610927885082 2015-05-29 [email protected] $
 * 
 * This file is part of the Object Modeling System (OMS),
 * 2007-2012, Olaf David and others, Colorado State University.
 *
 * OMS 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, version 2.1.
 *
 * OMS 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 OMS.  If not, see .
 */
package oms3.dsl;

import oms3.ComponentException;
import java.io.File;
import ngmf.util.DateDirectoryOutput;
import ngmf.util.FlatDirectoryOutput;
import ngmf.util.NumDirectoryOutput;
import ngmf.util.OutputStragegy;
import ngmf.util.SimpleDirectoryOutput;

import static oms3.SimBuilder.*;

/**
 *
 * @author od
 */
public class OutputDescriptor extends AbstractBuildableLeaf {

    int scheme = SIMPLE;
    File dir;

    public OutputDescriptor() {
        dir = new File(System.getProperty("user.dir"), "output");
        if (!dir.exists()) {
            dir = new File(System.getProperty("user.dir"));
        }
    }

    public void setDir(String d) {
        dir = new File(d);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        if (!dir.isDirectory()) {
            throw new IllegalArgumentException("Not a directory " + dir);
        }
    }

    File getDir() {
        return dir;
    }

    public void setScheme(int scheme) {
        if ((scheme == SIMPLE) || (scheme == NUMBERED) || (scheme == TIME)) {
            this.scheme = scheme;
        } else {
            throw new IllegalArgumentException("Invalid output strategy scheme.");
        }
    }

    public OutputStragegy getOutputStrategy(String simName) {
        if (Boolean.getBoolean("oms.csip.server")) {
            return new FlatDirectoryOutput(dir);
        }
        if (scheme == SIMPLE) {
            return  new SimpleDirectoryOutput(getDir(), simName);
        } else if (scheme == NUMBERED) {
            return new NumDirectoryOutput(getDir(), simName);
        } else if (scheme == TIME) {
            return new DateDirectoryOutput(getDir());
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy