📄 genericpropertiescreator.java
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//* * GenericPropertiesCreator.java * Copyright (C) 2005 University of Waikato, Hamilton, New Zealand * */package weka.gui;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;import java.util.StringTokenizer;import java.util.Vector;import weka.core.ClassDiscovery;import weka.core.Utils;/** * This class can generate the properties object that is normally loaded from * the <code>GenericObjectEditor.props</code> file (= PROPERTY_FILE). It takes * the <code>GenericPropertiesCreator.props</code> file as a template to * determine all the derived classes by checking the classes in the given * packages (a file with the same name in your home directory overrides the * the one in the weka/gui directory/package). <br> * E.g. if we want to have all the subclasses of the <code>Classifier</code> * class then we specify the superclass ("weka.classifiers.Classifier") and the * packages where to look for ("weka.classifiers.bayes" etc.): * * <pre> * * weka.classifiers.Classifier=\ * weka.classifiers.bayes,\ * weka.classifiers.functions,\ * weka.classifiers.lazy,\ * weka.classifiers.meta,\ * weka.classifiers.trees,\ * weka.classifiers.rules * * </pre> * * This creates the same list as stored in the * <code>GenericObjectEditor.props</code> file, but it will also add * additional classes, that are not listed in the static list (e.g. a newly * developed Classifier), but still in the classpath. <br> * <br> * For discovering the subclasses the whole classpath is inspected, which means * that you can have several parallel directories with the same package * structure (e.g. a release directory and a developer directory with additional * classes). <br> * <br> * * @see #CREATOR_FILE * @see #PROPERTY_FILE * @see GenericObjectEditor * @see weka.core.ClassDiscovery * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.9 $ */public class GenericPropertiesCreator { /** whether to output some debug information */ public final static boolean VERBOSE = false; /** The name of the properties file to use as a template. Contains the * packages in which to look for derived classes. It has the same structure * as the <code>PROPERTY_FILE</code> * @see #PROPERTY_FILE */ protected static String CREATOR_FILE = "weka/gui/GenericPropertiesCreator.props"; /** The name of the properties file that lists classes/interfaces/superclasses * to exclude from being shown in the GUI. See the file for more information. */ protected static String EXCLUDE_FILE = "weka/gui/GenericPropertiesCreator.excludes"; /** the prefix for an interface exclusion */ protected static String EXCLUDE_INTERFACE = "I"; /** the prefix for an (exact) class exclusion */ protected static String EXCLUDE_CLASS = "C"; /** the prefix for a superclass exclusion */ protected static String EXCLUDE_SUPERCLASS = "S"; /** The name of the properties file for the static GenericObjectEditor * (<code>USE_DYNAMIC</code> = <code>false</code>) * @see GenericObjectEditor * @see GenericObjectEditor#USE_DYNAMIC */ protected static String PROPERTY_FILE = "weka/gui/GenericObjectEditor.props"; /** the input file with the packages */ protected String m_InputFilename; /** the output props file for the GenericObjectEditor */ protected String m_OutputFilename; /** the "template" properties file with the layout and the packages */ protected Properties m_InputProperties; /** the output properties file with the filled in classes */ protected Properties m_OutputProperties; /** whether an explicit input file was given - if false, the Utils class * is used to locate the props-file */ protected boolean m_ExplicitPropsFile; /** the hashtable that stores the excludes: * key -> Hashtable(prefix -> Vector of classnames) */ protected Hashtable m_Excludes; /** * initializes the creator, locates the props file with the Utils class. * * @throws Exception if loading of CREATOR_FILE fails * @see #CREATOR_FILE * @see Utils#readProperties(String) * @see #loadInputProperties() */ public GenericPropertiesCreator() throws Exception { this(CREATOR_FILE); m_ExplicitPropsFile = false; } /** * initializes the creator, the given file overrides the props-file search * of the Utils class * * @param filename the file containing the packages to create a props file from * @throws Exception if loading of the file fails * @see #CREATOR_FILE * @see Utils#readProperties(String) * @see #loadInputProperties() */ public GenericPropertiesCreator(String filename) throws Exception { super(); m_InputFilename = filename; m_OutputFilename = PROPERTY_FILE; m_InputProperties = null; m_OutputProperties = null; m_ExplicitPropsFile = true; m_Excludes = new Hashtable(); } /** * if FALSE, the locating of a props-file of the Utils-class is used, * otherwise it's tried to load the specified file * * @param value if true the specified file will be loaded not via the * Utils-class * @see Utils#readProperties(String) * @see #loadInputProperties() */ public void setExplicitPropsFile(boolean value) { m_ExplicitPropsFile = value; } /** * returns TRUE, if a file is loaded and not the Utils class used for * locating the props file. * * @return true if the specified file is used and not the one found by * the Utils class * @see Utils#readProperties(String) * @see #loadInputProperties() */ public boolean getExplicitPropsFile() { return m_ExplicitPropsFile; } /** * returns the name of the output file * * @return the name of the output file */ public String getOutputFilename() { return m_OutputFilename; } /** * sets the file to output the properties for the GEO to * * @param filename the filename for the output */ public void setOutputFilename(String filename) { m_OutputFilename = filename; } /** * returns the name of the input file * * @return the name of the input file */ public String getInputFilename() { return m_InputFilename; } /** * sets the file to get the information about the packages from. * automatically sets explicitPropsFile to TRUE. * * @param filename the filename for the input * @see #setExplicitPropsFile(boolean) */ public void setInputFilename(String filename) { m_InputFilename = filename; setExplicitPropsFile(true); } /** * returns the input properties object (template containing the packages) * * @return the input properties (the template) */ public Properties getInputProperties() { return m_InputProperties; } /** * returns the output properties object (structure like the template, but * filled with classes instead of packages) * * @return the output properties (filled with classes) */ public Properties getOutputProperties() { return m_OutputProperties; } /** * loads the property file containing the layout and the packages of * the output-property-file. The exlcude property file is also read here. * * @see #m_InputProperties * @see #m_InputFilename */ protected void loadInputProperties() { if (VERBOSE) System.out.println("Loading '" + getInputFilename() + "'..."); m_InputProperties = new Properties(); try { File f = new File(getInputFilename()); if (getExplicitPropsFile() && f.exists()) m_InputProperties.load(new FileInputStream(getInputFilename())); else m_InputProperties = Utils.readProperties(getInputFilename()); // excludes m_Excludes.clear(); Properties p = Utils.readProperties(EXCLUDE_FILE); Enumeration enm = p.propertyNames(); while (enm.hasMoreElements()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -