📄 descriptorengine.java
字号:
} /** * Returns a List containing the instantiated descriptor classes. * * @return A List containing descriptor classes */ public List getDescriptorInstances() { return descriptors; } /** * Set the list of <code>Descriptor</code> objects. * * @param descriptors A List of descriptor objects * @see #getDescriptorInstances() */ public void setDescriptorInstances(List descriptors) { this.descriptors = descriptors; } /** * Get the all the unique dictionary classes that the descriptors belong to. * * @return An array containing the unique dictionary classes. */ public String[] getAvailableDictionaryClasses() { List classList = new ArrayList(); for (Iterator iter = speclist.iterator(); iter.hasNext();) { DescriptorSpecification spec = (DescriptorSpecification) iter.next(); String[] tmp = getDictionaryClass(spec); if (tmp != null) classList.addAll(Arrays.asList(tmp)); } Set uniqueClasses = new HashSet(classList); return (String[]) uniqueClasses.toArray(new String[]{}); } /** * Returns a list containing the classes that implement a specific interface. * <p/> * The interface name specified can be null or an empty string. In this case the interface name * is automatcally set to <i>IDescriptor</i>. Specifying <i>IDescriptor</i> will * return all available descriptor classes. Valid interface names are * <ul> * <li>IMolecularDescriptor * <li>IAtomicDescripto * <li>IBondDescriptor * <li>IDescriptor * </ul> * * @param interfaceName The name of the interface that classes should implement * @param jarFileNames A String[] containing the fully qualified names of the jar files * to examine for descriptor classes. In general this can be set to NULL, in which case * the system classpath is examined for available jar files. This parameter can be set for * situations where the system classpath is not available or is modified such as in an application * container. * @return A list containing the classes implementing the specified interface, null if an invalid interface * is specified */ public static List getDescriptorClassNameByInterface(String interfaceName, String[] jarFileNames) { if (interfaceName == null || interfaceName.equals("")) interfaceName = "IDescriptor"; if (!interfaceName.equals("IDescriptor") && !interfaceName.equals("IMolecularDescriptor") && !interfaceName.equals("IAtomicDescriptor") && !interfaceName.equals("IBondDescriptor")) return null; String[] jars; if (jarFileNames == null) { String classPath = System.getProperty("java.class.path"); jars = classPath.split(File.pathSeparator); } else { jars = jarFileNames; } ArrayList classlist = new ArrayList(); for (int i = 0; i < jars.length; i++) { logger.debug("Looking in " + jars[i]); JarFile jarFile; try { jarFile = new JarFile(jars[i]); Enumeration enumeration = jarFile.entries(); while (enumeration.hasMoreElements()) { JarEntry jarEntry = (JarEntry) enumeration.nextElement(); if (jarEntry.toString().indexOf(".class") != -1) { String className = jarEntry.toString().replace('/', '.').replaceAll(".class", ""); if (className.indexOf('$') != -1) continue; Class klass = null; try { klass = Class.forName(className); } catch (ClassNotFoundException cnfe) { logger.debug(cnfe); } catch (NoClassDefFoundError ncdfe) { logger.debug(ncdfe); } catch (UnsatisfiedLinkError ule) { logger.debug(ule); } if (klass == null) continue; // check that its not abstract or an interface int modifer = klass.getModifiers(); if (Modifier.isAbstract(modifer) || Modifier.isInterface(modifer)) continue; // get the interfaces implemented and see if one matches the one we're looking for Class[] interfaces = klass.getInterfaces(); for (int k = 0; k < interfaces.length; k++) { if (interfaces[k].getName().equals(interfaceName)) { classlist.add(className); break; } } } } } catch (IOException e) { logger.error("Error opening the jar file: " + jars[i]); logger.debug(e); } } return classlist; } /** * Returns a list containing the classes found in the specified descriptor package. * <p/> * The package name specified can be null or an empty string. In this case the package name * is automatcally set to "org.openscience.cdk.qsar.descriptors" and as a result will return * classes corresponding to both atomic and molecular descriptors. * * @param packageName The name of the package containing the required descriptor * @param jarFileNames A String[] containing the fully qualified names of the jar files * to examine for descriptor classes. In general this can be set to NULL, in which case * the system classpath is examined for available jar files. This parameter can be set for * situations where the system classpath is not available or is modified such as in an application * container. * @return A list containing the classes in the specified package */ public static List getDescriptorClassNameByPackage(String packageName, String[] jarFileNames) { if (packageName == null || packageName.equals("")) { packageName = "org.openscience.cdk.qsar.descriptors"; } String[] jars; if (jarFileNames == null) { String classPath = System.getProperty("java.class.path"); jars = classPath.split(File.pathSeparator); } else { jars = jarFileNames; } ArrayList classlist = new ArrayList(); for (int i = 0; i < jars.length; i++) { logger.debug("Looking in " + jars[i]); JarFile jarFile; try { jarFile = new JarFile(jars[i]); Enumeration enumeration = jarFile.entries(); while (enumeration.hasMoreElements()) { JarEntry jarEntry = (JarEntry) enumeration.nextElement(); if (jarEntry.toString().indexOf(".class") != -1) { String tmp = jarEntry.toString().replace('/', '.').replaceAll(".class", ""); if (!(tmp.indexOf(packageName) != -1)) continue; if (tmp.indexOf('$') != -1) continue; classlist.add(tmp); } } } catch (IOException e) { logger.error("Error opening the jar file: " + jars[i]); logger.debug(e); } } return classlist; } public List instantiateDescriptors(List descriptorClassNames) { List descriptors; descriptors = new ArrayList(); for (Iterator iter = descriptorClassNames.iterator(); iter.hasNext();) { String descriptorName = (String) iter.next(); try { IDescriptor descriptor = (IDescriptor) this.getClass().getClassLoader().loadClass(descriptorName).newInstance(); descriptors.add(descriptor); logger.info("Loaded descriptor: ", descriptorName); } catch (ClassNotFoundException exception) { logger.error("Could not find this Descriptor: ", descriptorName); logger.debug(exception); } catch (Exception exception) { logger.error("Could not load this Descriptor: ", descriptorName); logger.debug(exception); } } return descriptors; } public List initializeSpecifications(List descriptors) { List speclist = new ArrayList(); for (int i = 0; i < descriptors.size(); i++) { IDescriptor descriptor = (IDescriptor) descriptors.get(i); speclist.add(descriptor.getSpecification()); } return speclist; } private String getSpecRef(String identifier) { String specRef = null; // see if we got a descriptors java class name for (int i = 0; i < classNames.size(); i++) { String className = (String) classNames.get(i); if (className.equals(identifier)) { IDescriptor descriptor = (IDescriptor) descriptors.get(i); DescriptorSpecification descSpecification = descriptor.getSpecification(); String[] tmp = descSpecification.getSpecificationReference().split("#"); if (tmp.length != 2) { logger.debug("Something fishy with the spec ref: ", descSpecification.getSpecificationReference()); } else { specRef = tmp[1]; } } } // if we are here and specRef==null we have a SpecificationReference if (specRef == null) { String[] tmp = identifier.split("#"); if (tmp.length != 2) { logger.debug("Something fishy with the identifier: ", identifier); } else { specRef = tmp[1]; } } return specRef; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -