/** * Utility method to get a FlowLoader implementation suitable for loading a flow with the supplied * file extension. * * @param flowFileExtension the file extension to get a FlowLoader for * @param log the log in use * @return a FlowLoader * @throws WekaException if a problem occurs */ public static FlowLoader getFlowLoader(String flowFileExtension, Logger log) throws WekaException { Set<String> availableLoaders = PluginManager.getPluginNamesOfType(FlowLoader.class.getCanonicalName()); FlowLoader result = null; if (availableLoaders != null) { try { for (String l : availableLoaders) { FlowLoader candidate = (FlowLoader) PluginManager.getPluginInstance(FlowLoader.class.getCanonicalName(), l); if (candidate.getFlowFileExtension().equalsIgnoreCase(flowFileExtension)) { result = candidate; break; } } } catch (Exception ex) { throw new WekaException(ex); } } if (result != null) { result.setLog(log); } return result; }
// register default loader for JSON flow files static { PluginManager.addPlugin( FlowLoader.class.getCanonicalName(), JSONFlowLoader.class.getCanonicalName(), JSONFlowLoader.class.getCanonicalName(), true); // TODO temporary (move to a package later) PluginManager.addPlugin( FlowLoader.class.getCanonicalName(), LegacyFlowLoader.class.getCanonicalName(), LegacyFlowLoader.class.getCanonicalName(), true); Set<String> flowLoaders = PluginManager.getPluginNamesOfType(FlowLoader.class.getCanonicalName()); if (flowLoaders != null) { try { for (String f : flowLoaders) { FlowLoader fl = (FlowLoader) PluginManager.getPluginInstance(FlowLoader.class.getCanonicalName(), f); String extension = fl.getFlowFileExtension(); String description = fl.getFlowFileExtensionDescription(); FLOW_FILE_EXTENSIONS.add( new ExtensionFileFilter("." + extension, description + " (*." + extension + ")")); } } catch (Exception ex) { ex.printStackTrace(); } } }
/** * Utility method to load a flow from a file * * @param flowFile the file to load from * @param log the log to use * @return the loaded Flow * @throws WekaException if a problem occurs */ public static Flow loadFlow(File flowFile, Logger log) throws WekaException { String extension = "kf"; if (flowFile.toString().lastIndexOf('.') > 0) { extension = flowFile .toString() .substring(flowFile.toString().lastIndexOf('.') + 1, flowFile.toString().length()); } FlowLoader toUse = getFlowLoader(extension, log); if (toUse == null) { throw new WekaException("Was unable to find a loader for flow file: " + flowFile.toString()); } return toUse.readFlow(flowFile); }
/** * Utility method to load a flow from the supplied reader using the supplied FlowLoader * * @param r the reader to load from * @param loader the FlowLoader to use * @return the loaded flow * @throws WekaException if a problem occurs */ public static Flow loadFlow(Reader r, FlowLoader loader) throws WekaException { return loader.readFlow(r); }
/** * Utility method to load a flow from the supplied input stream using the supplied FlowLoader * * @param is the input stream to load from * @param loader the FlowLoader to use * @return the loaded Flow * @throws WekaException if a problem occurs */ public static Flow loadFlow(InputStream is, FlowLoader loader) throws WekaException { return loader.readFlow(is); }