/** * generates if necessary a Capabilities object for the given leaf. */ protected void initCapabilities() { String classname; Class<?> cls; Object obj; if (m_Capabilities != null) { return; } if (!isLeaf()) { return; } classname = getClassnameFromPath(new TreePath(getPath())); try { cls = Class.forName(classname); if (!ClassDiscovery.hasInterface(CapabilitiesHandler.class, cls)) { return; } obj = cls.newInstance(); m_Capabilities = ((CapabilitiesHandler) obj).getCapabilities(); } catch (Exception e) { // ignore it } }
/** * retrieves the language names of the availabel stemmers. */ private static void initStemmers() { Vector<String> classnames; int i; if (m_Stemmers != null) { return; } m_Stemmers = new Vector<String>(); if (!m_Present) { return; } classnames = GenericObjectEditor.getClassnames(SNOWBALL_PROGRAM); // try dynamic discovery if not in props file if (classnames.size() == 0) { classnames = ClassDiscovery.find(SNOWBALL_PROGRAM, PACKAGE_EXT); for (i = 0; i < classnames.size(); i++) { m_Stemmers.add(getStemmerName(classnames.get(i).toString())); } } }
/** * generates if necessary a Capabilities object for the given leaf. */ protected void initCapabilities() { String classname; Class cls; Object obj; if (m_Capabilities != null) return; if (!isLeaf()) return; classname = getClassnameFromPath(new TreePath(getPath())); try { cls = Class.forName(classname); if (!ClassDiscovery.hasInterface(CapabilitiesHandler.class, cls)) return; obj = cls.newInstance(); m_Capabilities = ((CapabilitiesHandler) obj).getCapabilities(); } catch (Exception e) { // ignore it } }
/** * retrieves the language names of the availabel stemmers. */ private static void initStemmers() { Vector classnames; int i; if (m_Stemmers != null) return; m_Stemmers = new Vector<String>(); if (!m_Present) return; classnames = GenericObjectEditor.getClassnames(SNOWBALL_PROGRAM); // try dynamic discovery if not in props file if (classnames.size() == 0) { classnames = ClassDiscovery.find(SNOWBALL_PROGRAM, PACKAGE_EXT); for (i = 0; i < classnames.size(); i++) m_Stemmers.add(getStemmerName(classnames.get(i).toString())); } }
/** * determines all the classes derived from the given superclass in the * specified packages * * @param superclass the class to find subclasses for * @param pacakges the packages to search in for subclasses * @return the classes that were found */ protected static Vector getClassnames(String superclass, Vector packages) { Vector result; Vector names; int i; int n; result = new Vector(); for (i = 0; i < packages.size(); i++) { names = ClassDiscovery.find(superclass, (String) packages.get(i)); for (n = 0; n < names.size(); n++) { // skip non-public classes if (isValidClassname((String) names.get(n))) result.add(names.get(n)); } } return result; }
/** * determines all the classes derived from the given superclass in the * specified packages * * @param superclass the class to find subclasses for * @param pacakges the packages to search in for subclasses * @return the classes that were found */ protected static Vector<String> getClassnames(String superclass, Vector<String> packages) { Vector<String> result; Vector<String> names; int i; int n; result = new Vector<String>(); for (i = 0; i < packages.size(); i++) { names = ClassDiscovery.find(superclass, packages.get(i)); for (n = 0; n < names.size(); n++) { // skip non-public classes if (isValidClassname(names.get(n))) { result.add(names.get(n)); } } } return result; }
/** * generates if necessary a Capabilities object for the given leaf. */ protected void initCapabilities() { String classname; Class cls; Object obj; if (m_Capabilities != null) { return; } if (!isLeaf()) { return; } classname = getClassnameFromPath(new TreePath(getPath())); try { cls = Class.forName(classname); if (!ClassDiscovery.hasInterface(CapabilitiesHandler.class, cls)) { return; } obj = cls.newInstance(); m_Capabilities = ((CapabilitiesHandler) obj).getCapabilities(); } catch (Exception e) { // ignore it } }
/** * retrieves the language names of the availabel stemmers. */ private static void initStemmers() { Vector classnames; int i; if (m_Stemmers != null) return; m_Stemmers = new Vector(); if (!m_Present) return; classnames = GenericObjectEditor.getClassnames(SNOWBALL_PROGRAM); // try dynamic discovery if not in props file if (classnames.size() == 0) { classnames = ClassDiscovery.find(SNOWBALL_PROGRAM, PACKAGE_EXT); for (i = 0; i < classnames.size(); i++) m_Stemmers.add(getStemmerName(classnames.get(i).toString())); } }
/** * Returns the available classnames for a certain property in the props file. * * @param property the property to get the classnames for * @return the classnames */ public static Vector<String> getClassnames(String property) { Vector<String> result; Set<String> r = PluginManager.getPluginNamesOfType(property); result = new Vector<String>(); if (r != null) { result.addAll(r); } Collections.sort(result, new ClassDiscovery.StringCompare()); return result; }
/** * default constructor. */ public CommandlineCompletion() { super(); // build incremental list of packages if (m_Packages == null) { // get all packages Vector<String> list = ClassDiscovery.findPackages(); // create incremental list HashSet<String> set = new HashSet<String>(); for (int i = 0; i < list.size(); i++) { String[] parts = list.get(i).split("\\."); for (int n = 1; n < parts.length; n++) { String pkg = ""; for (int m = 0; m <= n; m++) { if (m > 0) { pkg += "."; } pkg += parts[m]; } set.add(pkg); } } // init packages m_Packages = new Vector<String>(); m_Packages.addAll(set); Collections.sort(m_Packages); m_Trie = new Trie(); m_Trie.addAll(m_Packages); } }
/** * default constructor. */ public CommandlineCompletion() { super(); // build incremental list of packages if (m_Packages == null) { // get all packages Vector list = ClassDiscovery.findPackages(); // create incremental list HashSet<String> set = new HashSet<String>(); for (int i = 0; i < list.size(); i++) { String[] parts = ((String) list.get(i)).split("\\."); for (int n = 1; n < parts.length; n++) { String pkg = ""; for (int m = 0; m <= n; m++) { if (m > 0) pkg += "."; pkg += parts[m]; } set.add(pkg); } } // init packages m_Packages = new Vector<String>(); m_Packages.addAll(set); Collections.sort(m_Packages); m_Trie = new Trie(); m_Trie.addAll(m_Packages); } }
/** * Called when the class of object being edited changes. * * @return the hashtable containing the HierarchyPropertyParsers for the root * elements */ protected Hashtable<String, HierarchyPropertyParser> getClassesFromProperties() { Hashtable<String, HierarchyPropertyParser> hpps = new Hashtable<String, HierarchyPropertyParser>(); String className = m_ClassType.getName(); Set<String> cls = PluginManager.getPluginNamesOfType(className); if (cls == null) { return hpps; } List<String> toSort = new ArrayList<String>(cls); Collections.sort(toSort, new ClassDiscovery.StringCompare()); StringBuilder b = new StringBuilder(); for (String s : toSort) { b.append(s).append(","); } String listS = b.substring(0, b.length() - 1); // Hashtable typeOptions = // sortClassesByRoot(EDITOR_PROPERTIES.getProperty(className)); Hashtable<String, String> typeOptions = sortClassesByRoot(listS); if (typeOptions == null) { /* * System.err.println("Warning: No configuration property found in\n" + * PROPERTY_FILE + "\n" + "for " + className); */ } else { try { Enumeration<String> enm = typeOptions.keys(); while (enm.hasMoreElements()) { String root = enm.nextElement(); String typeOption = typeOptions.get(root); HierarchyPropertyParser hpp = new HierarchyPropertyParser(); hpp.build(typeOption, ", "); hpps.put(root, hpp); } } catch (Exception ex) { Logger.log(weka.core.logging.Logger.Level.WARNING, "Invalid property: " + typeOptions); } } return hpps; }
/** * fills in all the classes (based on the packages in the input properties * file) into the output properties file * * @throws Exception if something goes wrong * @see #m_OutputProperties */ protected void generateOutputProperties() throws Exception { Enumeration<?> keys; String key; String value; String pkg; StringTokenizer tok; Vector<String> classes; HashSet<String> names; int i; m_OutputProperties = new Properties(); keys = m_InputProperties.propertyNames(); while (keys.hasMoreElements()) { key = keys.nextElement().toString(); if (key.equals(USE_DYNAMIC)) { continue; } tok = new StringTokenizer(m_InputProperties.getProperty(key), ","); names = new HashSet<String>(); // get classes for all packages while (tok.hasMoreTokens()) { pkg = tok.nextToken().trim(); try { classes = ClassDiscovery.find(Class.forName(key), pkg); } catch (Exception e) { System.out.println("Problem with '" + key + "': " + e); classes = new Vector<String>(); } for (i = 0; i < classes.size(); i++) { // skip non-public classes if (!isValidClassname(classes.get(i).toString())) { continue; } // some classes should not be listed for some keys if (!isValidClassname(key, classes.get(i).toString())) { continue; } names.add(classes.get(i)); } } // generate list value = ""; classes = new Vector<String>(); classes.addAll(names); Collections.sort(classes, new StringCompare()); for (i = 0; i < classes.size(); i++) { if (!value.equals("")) { value += ","; } value += classes.get(i).toString(); } if (VERBOSE) { System.out.println(pkg + " -> " + value); } // set value m_OutputProperties.setProperty(key, value); } }
/** * sorts the table over the given column, either ascending or descending * * @param columnIndex the column to sort over * @param ascending ascending if true, otherwise descending */ public void sort(int columnIndex, boolean ascending) { int columnType; int i; ArrayList<SortContainer> sorted; SortContainer cont; Object value; // can we sort? if ((!isInitialized()) || (getModel().getRowCount() != mIndices.length)) { System.out.println(this.getClass().getName() + ": Table model not initialized!"); return; } // init mSortColumn = columnIndex; mAscending = ascending; initializeIndices(); // determine the column type: 0=string/other, 1=comparable if (ClassDiscovery.hasInterface(Comparable.class, getColumnClass(mSortColumn))) { columnType = 1; } else { columnType = 0; } // create list for sorting sorted = new ArrayList<SortContainer>(); for (i = 0; i < getRowCount(); i++) { value = mModel.getValueAt(mIndices[i], mSortColumn); if (columnType == 0) { cont = new SortContainer((value == null) ? null : value.toString(), mIndices[i]); } else { cont = new SortContainer((Comparable<?>) value, mIndices[i]); } sorted.add(cont); } Collections.sort(sorted); for (i = 0; i < sorted.size(); i++) { if (mAscending) { mIndices[i] = sorted.get(i).getIndex(); } else { mIndices[i] = sorted.get(sorted.size() - 1 - i).getIndex(); } } sorted.clear(); sorted = null; }
/** * returns a hashtable with the association * "file extension <-> converter classname" for the list of converter * classnames. * * @param classnames list of converter classnames * @param intf interfaces the converters have to implement * @return hashtable with ExtensionFileFilters */ protected static Hashtable<String, String> getFileConverters( Vector<String> classnames, String[] intf) { Hashtable<String, String> result; String classname; Class<?> cls; String[] ext; FileSourcedConverter converter; int i; int n; result = new Hashtable<String, String>(); for (i = 0; i < classnames.size(); i++) { classname = classnames.get(i); // all necessary interfaces implemented? for (n = 0; n < intf.length; n++) { if (!ClassDiscovery.hasInterface(intf[n], classname)) { continue; } } // get data from converter try { cls = Class.forName(classname); converter = (FileSourcedConverter) cls.newInstance(); ext = converter.getFileExtensions(); } catch (Exception e) { cls = null; converter = null; ext = new String[0]; } if (converter == null) { continue; } for (n = 0; n < ext.length; n++) { result.put(ext[n], classname); } } return result; }
/** * fills in all the classes (based on the packages in the input properties * file) into the output properties file * * @throws Exception if something goes wrong * @see #m_OutputProperties */ protected void generateOutputProperties() throws Exception { Enumeration keys; String key; String value; String pkg; StringTokenizer tok; Vector classes; HashSet names; int i; m_OutputProperties = new Properties(); keys = m_InputProperties.propertyNames(); while (keys.hasMoreElements()) { key = keys.nextElement().toString(); if (key.equals(USE_DYNAMIC)) continue; tok = new StringTokenizer(m_InputProperties.getProperty(key), ","); names = new HashSet(); // get classes for all packages while (tok.hasMoreTokens()) { pkg = tok.nextToken().trim(); try { classes = ClassDiscovery.find(Class.forName(key), pkg); } catch (Exception e) { System.out.println("Problem with '" + key + "': " + e); classes = new Vector(); } for (i = 0; i < classes.size(); i++) { // skip non-public classes if (!isValidClassname(classes.get(i).toString())) continue; // some classes should not be listed for some keys if (!isValidClassname(key, classes.get(i).toString())) continue; names.add(classes.get(i)); } } // generate list value = ""; classes = new Vector(); classes.addAll(names); Collections.sort(classes, new StringCompare()); for (i = 0; i < classes.size(); i++) { if (!value.equals("")) value += ","; value += classes.get(i).toString(); } if (VERBOSE) System.out.println(pkg + " -> " + value); // set value m_OutputProperties.setProperty(key, value); } }
/** * sorts the table over the given column, either ascending or descending * * @param columnIndex the column to sort over * @param ascending ascending if true, otherwise descending */ public void sort(int columnIndex, boolean ascending) { int columnType; int i; ArrayList<SortContainer> sorted; SortContainer cont; Object value; // can we sort? if ( (!isInitialized()) || (getModel().getRowCount() != mIndices.length) ) { System.out.println( this.getClass().getName() + ": Table model not initialized!"); return; } // init mSortColumn = columnIndex; mAscending = ascending; initializeIndices(); // determine the column type: 0=string/other, 1=comparable if (ClassDiscovery.hasInterface(Comparable.class, getColumnClass(mSortColumn))) columnType = 1; else columnType = 0; // create list for sorting sorted = new ArrayList<SortContainer>(); for (i = 0; i < getRowCount(); i++) { value = mModel.getValueAt(mIndices[i], mSortColumn); if (columnType == 0) cont = new SortContainer((value == null) ? null : value.toString(), mIndices[i]); else cont = new SortContainer((Comparable) value, mIndices[i]); sorted.add(cont); } Collections.sort(sorted); for (i = 0; i < sorted.size(); i++) { if (mAscending) mIndices[i] = sorted.get(i).getIndex(); else mIndices[i] = sorted.get(sorted.size() - 1 - i).getIndex(); } sorted.clear(); sorted = null; }
/** * returns a hashtable with the association * "file extension <-> converter classname" for the list of converter * classnames. * * @param classnames list of converter classnames * @param intf interfaces the converters have to implement * @return hashtable with ExtensionFileFilters */ protected static Hashtable<String,String> getFileConverters(Vector classnames, String[] intf) { Hashtable<String,String> result; String classname; Class cls; String[] ext; FileSourcedConverter converter; int i; int n; result = new Hashtable<String,String>(); for (i = 0; i < classnames.size(); i++) { classname = (String) classnames.get(i); // all necessary interfaces implemented? for (n = 0; n < intf.length; n++) { if (!ClassDiscovery.hasInterface(intf[n], classname)) continue; } // get data from converter try { cls = Class.forName(classname); converter = (FileSourcedConverter) cls.newInstance(); ext = converter.getFileExtensions(); } catch (Exception e) { cls = null; converter = null; ext = new String[0]; } if (converter == null) continue; for (n = 0; n < ext.length; n++) result.put(ext[n], classname); } return result; }
/** * fills in all the classes (based on the packages in the input properties * file) into the output properties file * * @throws Exception if something goes wrong * @see #m_OutputProperties */ protected void generateOutputProperties() throws Exception { Enumeration keys; String key; String value; String pkg; StringTokenizer tok; Vector classes; HashSet names; int i; m_OutputProperties = new Properties(); keys = m_InputProperties.propertyNames(); while (keys.hasMoreElements()) { key = keys.nextElement().toString(); if (key.equals(USE_DYNAMIC)) continue; tok = new StringTokenizer(m_InputProperties.getProperty(key), ","); names = new HashSet(); // get classes for all packages while (tok.hasMoreTokens()) { pkg = tok.nextToken().trim(); try { classes = ClassDiscovery.find(Class.forName(key), pkg); } catch (Exception e) { System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +Messages.getInstance().getString("GenericPropertiesCreator_GenerateOutputProperties_Text_First") + key + Messages.getInstance().getString("GenericPropertiesCreator_GenerateOutputProperties_Text_Second") + e); classes = new Vector(); } for (i = 0; i < classes.size(); i++) { // skip non-public classes if (!isValidClassname(classes.get(i).toString())) continue; // some classes should not be listed for some keys if (!isValidClassname(key, classes.get(i).toString())) continue; names.add(classes.get(i)); } } // generate list value = ""; classes = new Vector(); classes.addAll(names); Collections.sort(classes, new StringCompare()); for (i = 0; i < classes.size(); i++) { if (!value.equals("")) value += ","; value += classes.get(i).toString(); } if (VERBOSE) System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() +pkg + " -> " + value); // set value m_OutputProperties.setProperty(key, value); } }
/** * sorts the table over the given column, either ascending or descending * * @param columnIndex the column to sort over * @param ascending ascending if true, otherwise descending */ public void sort(int columnIndex, boolean ascending) { int columnType; int i; ArrayList<SortContainer> sorted; SortContainer cont; Object value; // can we sort? if ( (!isInitialized()) || (getModel().getRowCount() != mIndices.length) ) { System.out.println(Thread.currentThread().getStackTrace()[1].getClassName() + this.getClass().getName() + Messages.getInstance().getString("SortedTableModel_Sort_Text_Firt")); return; } // init mSortColumn = columnIndex; mAscending = ascending; initializeIndices(); // determine the column type: 0=string/other, 1=comparable if (ClassDiscovery.hasInterface(Comparable.class, getColumnClass(mSortColumn))) columnType = 1; else columnType = 0; // create list for sorting sorted = new ArrayList<SortContainer>(); for (i = 0; i < getRowCount(); i++) { value = mModel.getValueAt(mIndices[i], mSortColumn); if (columnType == 0) cont = new SortContainer((value == null) ? null : value.toString(), mIndices[i]); else cont = new SortContainer((Comparable) value, mIndices[i]); sorted.add(cont); } Collections.sort(sorted); for (i = 0; i < sorted.size(); i++) { if (mAscending) mIndices[i] = sorted.get(i).getIndex(); else mIndices[i] = sorted.get(sorted.size() - 1 - i).getIndex(); } sorted.clear(); sorted = null; }