Refine search
@Override public void process(final Module module) { if (uiService == null) return; // no UI service available final UserInterface ui = uiService.getDefaultUI(); if (ui == null) return; // no default UI for (final ModuleItem<?> input : module.getInfo().inputs()) { if (!input.isAutoFill()) continue; // cannot auto-fill this input final Class<?> type = input.getType(); if (type.isAssignableFrom(ui.getClass())) { // input is a compatible UI final String name = input.getName(); module.setInput(name, ui); module.resolveInput(name); } } }
@Override public void process(final Module module) { if (logService == null || moduleService == null) return; final ModuleItem<?> loggerInput = moduleService.getSingleInput(module, Logger.class); if (loggerInput == null || !loggerInput.isAutoFill()) return; String loggerName = loggerInput.getLabel(); if(loggerName == null || loggerName.isEmpty()) loggerName = module.getDelegateObject().getClass().getSimpleName(); Logger logger = logService.subLogger(loggerName); final String name = loggerInput.getName(); module.setInput(name, logger); module.resolveInput(name); }
import iaik.pkcs.pkcs11.Module; import iaik.pkcs.pkcs11.Info; import iaik.pkcs.pkcs11.Slot; public class PKCS11Test { public static void main(String[] args) throws Exception { Module pkcs11Module = Module.getInstance(args[0]); pkcs11Module.initialize(null); pkcs11Module.finalize(null); } }
/** * @deprecated Use {@link #resolveInput(String)} and * {@link #unresolveInput(String)} instead. */ @Deprecated default void setResolved(final String name, final boolean resolved) { if (resolved) resolveInput(name); else unresolveInput(name); }
/** Does any needed processing, after input values have been harvested. */ @SuppressWarnings("unused") default void processResults(final InputPanel<P, W> inputPanel, final Module module) throws ModuleException { final Iterable<ModuleItem<?>> inputs = module.getInfo().inputs(); for (final ModuleItem<?> item : inputs) { final String name = item.getName(); module.resolveInput(name); } } }
/** * Gets the single unresolved {@link File} input parameter. If there is not * exactly one unresolved {@link File} input parameter, or if there are other * types of unresolved parameters, this method returns null. */ private ModuleItem<File> getFileInput(final Module module) { ModuleItem<File> result = null; for (final ModuleItem<?> input : module.getInfo().inputs()) { if (module.isInputResolved(input.getName())) continue; final Class<?> type = input.getType(); if (!File.class.isAssignableFrom(type)) { // not a File parameter; abort return null; } if (result != null) { // second File parameter; abort return null; } @SuppressWarnings("unchecked") final ModuleItem<File> fileInput = (ModuleItem<File>) input; result = fileInput; } return result; }
private <T> void assignDefaultValue(final Module module, final ModuleItem<T> item) { if (module.isInputResolved(item.getName())) return; final T nullValue = Types.nullValue(item.getType()); if (!Objects.equals(item.getValue(module), nullValue)) return; final T defaultValue = moduleService.getDefaultValue(item); if (defaultValue == null) return; item.setValue(module, defaultValue); }
@Override public void process(final Module module) { if (displayService == null || moduleService == null) return; final ModuleItem<?> displayInput = moduleService.getSingleInput(module, Display.class); if (displayInput == null || !displayInput.isAutoFill()) return; @SuppressWarnings("unchecked") final Class<? extends Display<?>> displayType = (Class<? extends Display<?>>) displayInput.getType(); final Display<?> activeDisplay = displayService.getActiveDisplay(displayType); if (activeDisplay == null) return; final String name = displayInput.getName(); module.setInput(name, activeDisplay); module.resolveInput(name); }
module.getInfo().outputs().forEach(output -> { final String name = output.getName(); if (module.isOutputResolved(name)) return; if (module.getOutput(name) == null) return; if (!isSimple(module, output)) return; outputs.add(output); if (outputs.size() == 1 && Types.isText(outputs.get(0).getType())) { final String name = output.getName(); names.addValue(name); values.addValue(module.getOutput(name)); module.resolveOutput(name); final String title = module.getInfo().getTitle(); ui.show(title, outputTable);
@Override public void process(final Module module) { for (final ModuleItem<?> input : module.getInfo().inputs()) { if (input.isRequired() && input.getValue(module) == null) { cancel("'" + input.getName() + "' is required but unset."); } } }
@SuppressWarnings("unchecked") private <T> void assignNamespace(final Module module, final ModuleItem<T> item) { if (module.isInputResolved(item.getName())) return; // if possible, extract the OpEnvironment from the delegate object final Object delegate = module.getDelegateObject(); final OpEnvironment env = delegate instanceof Environmental ? // ((Environmental) delegate).ops() : ops; if (env == null) return; T defaultValue = null; if (Namespace.class.isAssignableFrom(item.getType())) { defaultValue = (T) nsService.create(// (Class<? extends Namespace>) item.getType(), env); } if (defaultValue == null) return; item.setValue(module, defaultValue); module.resolveInput(item.getName()); } }
@Override public void process(final Module module) { if (displayService == null) return; for (final ModuleItem<?> outputItem : module.getInfo().outputs()) { if (module.isOutputResolved(outputItem.getName())) continue; final Object value = outputItem.getValue(module); final String name = defaultName(outputItem); final boolean resolved = handleOutput(name, value); if (resolved) module.resolveOutput(name); } }
@Override public void process(final Module module) { if (uiService == null) return; final ModuleItem<File> fileInput = getFileInput(module); if (fileInput == null) return; final File file = fileInput.getValue(module); final String style = fileInput.getWidgetStyle(); // show file chooser dialog box final File result = uiService.chooseFile(file, style); if (result == null) { cancel(""); return; } fileInput.setValue(module, result); module.resolveInput(fileInput.getName()); }
private <S extends Service> void setServiceValue(final Context context, final Module module, final ModuleItem<S> input) { final S service = context.getService(input.getType()); input.setValue(module, service); module.resolveInput(input.getName()); }
/** Sets the given module's input values to those in the given map. */ private void assignInputs(final Module module, final Map<String, Object> inputMap) { if (inputMap == null) return; // no inputs to assign for (final String name : inputMap.keySet()) { final ModuleItem<?> input = module.getInfo().getInput(name); final Object value = inputMap.get(name); final Object converted; if (input == null) { // inputs whose name starts with a dot are implicitly known by convention if (!name.startsWith(".")) { log.warn("Unmatched input: " + name); } converted = value; } else { final Class<?> type = input.getType(); converted = convertService.convert(value, type); if (value != null && converted == null) { log.error("For input " + name + ": incompatible object " + value.getClass().getName() + " for type " + type.getName()); continue; } } module.setInput(name, converted); module.resolveInput(name); } }
private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel, final Module module, final ModuleItem<T> item) throws ModuleException { final String name = item.getName(); final boolean resolved = module.isInputResolved(name); if (resolved) return null; // skip resolved inputs final Class<T> type = item.getType(); final WidgetModel model = widgetService.createModel(inputPanel, module, item, getObjects(type)); final Class<W> widgetType = inputPanel.getWidgetComponentType(); final InputWidget<?, ?> widget = widgetService.create(model); if (widget == null) { log.debug("No widget found for input: " + model.getItem().getName()); } if (widget != null && widget.getComponentType() == widgetType) { @SuppressWarnings("unchecked") final InputWidget<?, W> typedWidget = (InputWidget<?, W>) widget; inputPanel.addWidget(typedWidget); return model; } if (item.isRequired()) { throw new ModuleException("A " + type.getSimpleName() + " is required but none exist."); } // item is not required; we can skip it return null; }
@Override public void process(final Module module) { for (final ModuleItem<?> input : module.getInfo().inputs()) { if (!input.isAutoFill()) continue; // cannot auto-fill this input final Class<?> type = input.getType(); if (Gateway.class.isAssignableFrom(type)) { // input is a gateway @SuppressWarnings("unchecked") final ModuleItem<? extends Gateway> gatewayInput = (ModuleItem<? extends Gateway>) input; setGatewayValue(getContext(), module, gatewayInput); } } }
private ModuleItem<?> getSingleItem(final Module module, final Collection<Class<?>> types, final Iterable<ModuleItem<?>> items) { ModuleItem<?> result = null; for (final ModuleItem<?> item : items) { final String name = item.getName(); final boolean resolved = module.isInputResolved(name); if (resolved) continue; // skip resolved inputs if (!item.isAutoFill()) continue; // skip unfillable inputs final Class<?> itemType = item.getType(); for (final Class<?> type : types) { if (type.isAssignableFrom(itemType)) { if (result != null) return null; // multiple matching module items result = item; // This module item matches, so no need to check more classes. break; } } } return result; }