/** * 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(); } } }