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

oms3.dsl.Resource 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: Resource.java fce87655d038 2015-01-05 [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 java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import ngmf.util.WildcardFileFilter;
import oms3.ComponentException;

/**
 *
 * @author od
 */
public class Resource {

    List l = new ArrayList();

    @SuppressWarnings("unchecked")
    public void addResource(Object arg) {
        if (arg == null) {
            throw new ComponentException("No resource string  provided.");
        }
        if (arg.getClass() == String.class) {
            l.add((String) arg);
        } else if (arg instanceof Collection) {
            l.addAll((Collection) arg);
        } else {
            l.add(arg.toString());
        }
    }

    public List getRecources() {
        List f = new ArrayList();
        for (String s : l) {
            File sf = new File(s);
            File parent = sf.getParentFile();
            if (!parent.exists()) {
                throw new IllegalArgumentException("Not found: " + parent);
            }
            File[] fi = parent.listFiles(new WildcardFileFilter(sf.getName()));
            for (File file : fi) {
               f.add(file.toString());
            }
        }
        return f;
    }

    public List filterFiles(String ext) {
        List f = new ArrayList<>();
        for (String s : l) {
            File sf = new File(s);
            File parent = sf.getParentFile();
            if (!parent.exists()) {
                throw new IllegalArgumentException("Not found: " + parent);
            }
            for (File file : parent.listFiles(new WildcardFileFilter(sf.getName()))) {
                //TODO put config logger here.
                if (file.getName().endsWith(ext)) {
                    f.add(file);
                }
            }
        }
        return f;
    }

    public List filterDirectories() {
        List f = new ArrayList<>();
        for (String s : l) {
            File sf = new File(s);
            if (sf.isDirectory() && sf.exists()) {
               f.add(sf);
            }
        }
        return f;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy