<commit_before>/*
 *    ALMA - Atacama Large Millimiter Array
 *    (c) European Southern Observatory, 2002
 *    Copyright by ESO (in the framework of the ALMA collaboration),
 *    All rights reserved
 *
 *    This library 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 2.1 of the License, or (at your option) any later version.
 *
 *    This library 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 this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *    MA 02111-1307  USA
 */
package alma.tools.entitybuilder;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;

import alma.acs.makesupport.AcsFileFinder;
import alma.acs.testsupport.TestLogger;

/**
 * Finds XML schema files (.xsd) and xsd-bindingclass-config files (.xml) 
 * in the wicked depth of overlayed ACS directories such as INTROOT/idl and ACSROOT/idl.
 *  
 * @author hsommer
 * created Feb 10, 2005 
 */
public class XsdFileFinder extends AcsFileFinder
{
	private List xsdConfigFileNames;
    private boolean verbose;

    /**
	 * @param dirs the directories to search for files in
     * @param xsdConfigFileNames the path-free names of xsd config files to use, such as "systementities.xml" 
	 */
	public XsdFileFinder(File[] dirs, String[] xsdConfigFileNames) {
        // todo-: the base class should be changed to not always call scanDirs(..) in the ctor.
        // then our filename filter could be smarter and only allow the known xsdConfigFileNames 
        // instead of any .xml file. Not a big deal though since we handle this in a second step filtering.
		super(dirs, new XsdConfigFileNameFilter(), TestLogger.getLogger("xmljbind-XsdFileFinder", Level.FINER));
        this.xsdConfigFileNames = Arrays.asList(xsdConfigFileNames);
	}

	public String getClasspath() {
		String cp = "";
		for (Iterator iter = m_fileMap.values().iterator(); iter.hasNext();)
		{
			File jarfile = (File) iter.next();
			cp += jarfile.getAbsolutePath() + File.pathSeparator;
		}
		return cp;
	}

	/**
     * Finds an XML schema file given its file name without path.
     * @return the file, or null if it's not found.
	 */
	public File resolveXsdFile(String xsdFileName) {
        File schema = (File) m_fileMap.get(xsdFileName);
        if (verbose) {
            m_logger.fine("requested=" + xsdFileName + "; resolved=" + schema);
        }
        return schema;
    }

    /**
     * Finds a config file for XML schema binding class generation, given its file name without path.
     * @return the file, or null if it's not found or if it is not one of the registered <code>xsdConfigFileNames</code> from the c'tor.
     */
    public File resolveXsdConfigFile(String xsdConfigFileName) {
        File schemaConfigFile = (File) m_fileMap.get(xsdConfigFileName);
        if (schemaConfigFile != null && !xsdConfigFileNames.contains(xsdConfigFileName)) {
            String msg = XsdFileFinder.class.getName() + "#resolveXsdConfigFile: requested file name matched '" + 
                        schemaConfigFile.getAbsolutePath() + "', however it was not registered as a valid config file in the constructor of this class.";
            m_logger.warning(msg);
            schemaConfigFile = null;
        }
        if (verbose) {
            String msg = "requested=" + xsdConfigFileName + "; resolved=" + schemaConfigFile;
            m_logger.fine(msg);
        }
        return schemaConfigFile;
    }

    
    public File[] getAllXsdConfigFiles() {
        ArrayList files = new ArrayList();
        for (Iterator iter = xsdConfigFileNames.iterator(); iter.hasNext();) {
            String xsdConfigFileName = (String) iter.next();
            File configFile = resolveXsdConfigFile(xsdConfigFileName);
            if (configFile != null) {
                files.add(configFile);
            }
            else {
                m_logger.warning("Binding configuration file '" + xsdConfigFileName + "' not found. Will try to continue without.");
            }
        }
        return (File[]) files.toArray(new File[files.size()]);
    }
    
    
	public static class XsdConfigFileNameFilter implements FilenameFilter {
		public boolean accept(File dir, String name) {
			return ( name.toLowerCase().endsWith("xml") || name.toLowerCase().endsWith("xsd"));
		}
<commit_msg>typed lists instead of arrays<commit_after>/*
 *    ALMA - Atacama Large Millimiter Array
 *    (c) European Southern Observatory, 2002
 *    Copyright by ESO (in the framework of the ALMA collaboration),
 *    All rights reserved
 *
 *    This library 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 2.1 of the License, or (at your option) any later version.
 *
 *    This library 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 this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *    MA 02111-1307  USA
 */
package alma.tools.entitybuilder;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;

import alma.acs.makesupport.AcsFileFinder;
import alma.acs.testsupport.TestLogger;

/**
 * Finds XML schema files (.xsd) and xsd-bindingclass-config files (.xml) 
 * in the wicked depth of overlayed ACS directories such as INTROOT/idl and ACSROOT/idl.
 *  
 * @author hsommer
 * created Feb 10, 2005 
 */
public class XsdFileFinder extends AcsFileFinder
{
	private List<String> xsdConfigFileNames;
    private boolean verbose;

    /**
	 * @param dirs the directories to search for files in
     * @param xsdConfigFileNames the path-free names of xsd config files to use, such as "systementities.xml" 
	 */
	public XsdFileFinder(List<File> dirs, List<String> xsdConfigFileNames) {
        // todo-: the base class should be changed to not always call scanDirs(..) in the ctor.
        // then our filename filter could be smarter and only allow the known xsdConfigFileNames 
        // instead of any .xml file. Not a big deal though since we handle this in a second step filtering.
		super(dirs.toArray(new File[dirs.size()]), new XsdConfigFileNameFilter(), TestLogger.getLogger("xmljbind-XsdFileFinder", Level.FINER));
        this.xsdConfigFileNames = xsdConfigFileNames;
	}

	public String getClasspath() {
		String cp = "";
		for (Iterator iter = m_fileMap.values().iterator(); iter.hasNext();)
		{
			File jarfile = (File) iter.next();
			cp += jarfile.getAbsolutePath() + File.pathSeparator;
		}
		return cp;
	}

	/**
     * Finds an XML schema file given its file name without path.
     * @return the file, or null if it's not found.
	 */
	public File resolveXsdFile(String xsdFileName) {
        File schema = (File) m_fileMap.get(xsdFileName);
        if (verbose) {
            m_logger.fine("requested=" + xsdFileName + "; resolved=" + schema);
        }
        return schema;
    }

    /**
     * Finds a config file for XML schema binding class generation, given its file name without path.
     * @return the file, or null if it's not found or if it is not one of the registered <code>xsdConfigFileNames</code> from the c'tor.
     */
    public File resolveXsdConfigFile(String xsdConfigFileName) {
        File schemaConfigFile = (File) m_fileMap.get(xsdConfigFileName);
        if (schemaConfigFile != null && !xsdConfigFileNames.contains(xsdConfigFileName)) {
            String msg = XsdFileFinder.class.getName() + "#resolveXsdConfigFile: requested file name matched '" + 
                        schemaConfigFile.getAbsolutePath() + "', however it was not registered as a valid config file in the constructor of this class.";
            m_logger.warning(msg);
            schemaConfigFile = null;
        }
        if (verbose) {
            String msg = "requested=" + xsdConfigFileName + "; resolved=" + schemaConfigFile;
            m_logger.fine(msg);
        }
        return schemaConfigFile;
    }

    
    public File[] getAllXsdConfigFiles() {
        ArrayList<File> files = new ArrayList<File>();
        for (String xsdConfigFileName : xsdConfigFileNames) {
            File configFile = resolveXsdConfigFile(xsdConfigFileName);
            if (configFile != null) {
                files.add(configFile);
            }
            else {
                m_logger.warning("Binding configuration file '" + xsdConfigFileName + "' not found. Will try to continue without.");
            }
        }
        return files.toArray(new File[files.size()]);
    }
    
    
	public static class XsdConfigFileNameFilter implements FilenameFilter {
		public boolean accept(File dir, String name) {
			return ( name.toLowerCase().endsWith("xml") || name.toLowerCase().endsWith("xsd"));
		}

{'fraction_non_alphanumeric': 0.09080636877247046, 'fraction_numerical': 0.005341551104262969, 'mean_word_length': 2.943296881328473, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7592345', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2661, 'n_words': 957}