Example usage for javax.imageio.spi ServiceRegistry lookupProviders

List of usage examples for javax.imageio.spi ServiceRegistry lookupProviders

Introduction

In this page you can find the example usage for javax.imageio.spi ServiceRegistry lookupProviders.

Prototype

public static <T> Iterator<T> lookupProviders(Class<T> providerClass) 

Source Link

Document

Locates and incrementally instantiates the available providers of a given service using the context class loader.

Usage

From source file:com.diversityarrays.dal.server.DalServer.java

public static void giveHelpThenExit(int code) {
    for (String line : CMD_HELP_LINES) {
        System.out.println(line);
    }//from   w  ww . ja  v a  2  s. c o m
    System.out.println("Available databaseServiceNames are:");
    for (Iterator<DalDbProviderService> iter = ServiceRegistry.lookupProviders(DalDbProviderService.class); iter
            .hasNext();) {
        DalDbProviderService provider = iter.next();
        System.out.println("\t" + provider.getProviderName());
    }
    System.exit(code);
}

From source file:com.diversityarrays.dal.server.DalServer.java

/**
 * /*from   w  w w  .ja  v  a2s. com*/
 * @param databaseFolder
 * @param databaseServer
 * @param databasePort
 * @param wwwRoot
 * @param host
 * @param serviceName
 * @param prefs
 * @param errors
 * @throws IllegalArgumentException if no provider or unable to create
 * @return
 * @throws NoServiceException 
 */
private static DalDatabase createDalDatabase(String dalDbServiceName, DalServerPreferences prefs)
        throws NoServiceException {
    DalDbProviderService provider = null;
    for (Iterator<DalDbProviderService> iter = ServiceRegistry.lookupProviders(DalDbProviderService.class); iter
            .hasNext();) {
        provider = iter.next();
        if (dalDbServiceName.equals(provider.getProviderName())) {
            break;
        }
    }

    if (provider == null) {
        throw new NoServiceException("No provider for " + dalDbServiceName);
    }

    Set<Parameter<?>> required = provider.getParametersRequired();
    Map<Parameter<?>, Throwable> errors = new LinkedHashMap<Parameter<?>, Throwable>();
    Map<Parameter<?>, ParameterValue<?>> savedSettings = prefs.loadSavedSettings(provider, required, errors);

    if (!errors.isEmpty()) {
        StringBuilder sb = new StringBuilder("Parameter errors:");
        for (Parameter<?> p : errors.keySet()) {
            sb.append("\n  ").append(p.name).append(errors.get(p).getMessage());
        }
        throw new NoServiceException(sb.toString());
    }

    Set<ParameterValue<?>> parameterValues = new LinkedHashSet<ParameterValue<?>>();
    for (Parameter<?> p : required) {
        ParameterValue<?> v = savedSettings.get(p);
        if (v != null) {
            parameterValues.add(v);
        }
    }

    try {
        Closure<String> progress = new Closure<String>() {
            @Override
            public void execute(String msg) {
                System.out.println(msg);
            }
        };
        return provider.createDatabase(parameterValues, progress, false);

    } catch (DalDbException e) {
        throw new NoServiceException("provider " + provider.getProviderName() + " couldn't create DalDatabase",
                e);
    }
}

From source file:datascript.instance.DataScriptInstanceTool.java

private void printServices() {
    Iterator<Extension> it = ServiceRegistry.lookupProviders(Extension.class);
    while (it.hasNext()) {
        Extension ext = it.next();
        System.out.println(ext.getClass().getName());
    }//from   ww  w.  j  a v  a 2 s.  co  m
}

From source file:com.diversityarrays.dal.server.AskServerParams.java

public AskServerParams(Image serverIconImage, final Window owner, String title, File www,
        DalServerPreferences prefs) {/*from   w  ww. jav  a  2  s. c  o  m*/
    super(owner, title, ModalityType.APPLICATION_MODAL);

    this.wwwRoot = www;
    this.preferences = prefs;

    if (serverIconImage != null) {
        setIconImage(serverIconImage);
    }

    Iterator<DalDbProviderService> iter = ServiceRegistry.lookupProviders(DalDbProviderService.class);
    while (iter.hasNext()) {
        DalDbProviderService s = iter.next();
        factoryTabbedPane.addTab(s.getProviderName(), new ProviderPanel(s));
    }

    List<String> hostnames = DalServerUtil.collectHostnamesForChoice(true);
    hostnameChoice = new JComboBox<String>(hostnames.toArray(new String[hostnames.size()]));

    wwwRootPath.setText(wwwRoot.getPath());

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(okButton);
    buttons.add(Box.createHorizontalGlue());
    buttons.add(cancelButton);
    buttons.add(Box.createHorizontalStrut(10));

    getContentPane().add(BorderLayout.NORTH, initGui());
    getContentPane().add(BorderLayout.SOUTH, buttons);
    pack();

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            removeWindowListener(this);
            if (owner != null) {
                GuiUtil.centreOnOwner(AskServerParams.this);
            } else {
                GuiUtil.centreOnScreen(AskServerParams.this);
            }
            okButton.requestFocus(); // unless it is disabled !
        }
    });
}

From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java

private void loadVisualisationTools() {

    List<VisualisationTool> list = new ArrayList<>();

    VisToolParams params = new VisToolParams(selectedValueStore, curationData, colorProviderFactory,
            suppressionHandler);//from   w  w  w.j  ava  2s  .  co  m

    Shared.Log.d(TAG, "Visualisation Plugins: "); //$NON-NLS-1$

    boolean useHardcoded = Boolean.getBoolean("USE_HARDCODED_VISTOOLS"); //$NON-NLS-1$
    if (useHardcoded) {
        // TODO remove hard coded VisualisationTool generation once dynamic
        // loading works

        String[] vtoolClassNames = { "com.diversityarrays.kdxplore.heatmap.HeatMapVisualisationTool", //$NON-NLS-1$
                "com.diversityarrays.kdxplore.boxplot.BoxPlotVisualisationTool", //$NON-NLS-1$
                "com.diversityarrays.kdxplore.scatterplot.ScatterPlotVisualisationTool" //$NON-NLS-1$
        };

        for (String className : vtoolClassNames) {
            try {
                Class<?> clazz = Class.forName(className);
                if (VisualisationTool.class.isAssignableFrom(clazz)) {
                    @SuppressWarnings("unchecked")
                    Class<VisualisationTool> vtoolClass = (Class<VisualisationTool>) clazz;
                    Constructor<VisualisationTool> ctor = vtoolClass.getConstructor(VisToolParams.class);
                    VisualisationTool vtool = ctor.newInstance(params);
                    list.add(vtool);
                    Shared.Log.i(TAG, vtool.toString());
                } else {
                    Shared.Log.e(TAG, "VisualisationTool.class not assignable for instance of " + className);
                }
            } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException
                    | IllegalAccessException | InvocationTargetException e) {
                Shared.Log.e(TAG, "Unable to get VisualisationTool for " + className, e);
            }
        }
    } else {

        Iterator<VisualisationToolService> it = ServiceRegistry.lookupProviders(VisualisationToolService.class);
        while (it.hasNext()) {
            try {
                VisualisationToolService vtoolService = it.next();
                VisualisationTool vtool = vtoolService.createVisualisationTool(params);
                list.add(vtool);
                System.out.println(vtool.toString());
            } catch (java.util.ServiceConfigurationError error) {
                Shared.Log.e(TAG, "VisualisationToolService error", error);
                messages.printErrorLn("VisualisationToolService error: ", error);
            }
        }

    }

    visualisationTools = list.toArray(new VisualisationTool[list.size()]);

    toolController = new VisualisationToolController(selectedValueStore, visualisationTools);
    toolController.addSelectionChangeListener(visToolSelectionChangeListener);

    for (VisualisationTool tool : visualisationTools) {
        visualisationToolById.put(tool.getVisualisationToolId(), tool);
    }
}

From source file:org.dcm4che2.tool.dcm2jpg.Dcm2Jpg.java

private void showFormatNames() {
    System.out.println("List of supported Format Names of registered ImageWriters:");
    Iterator<ImageWriterSpi> writers = ServiceRegistry.lookupProviders(ImageWriterSpi.class);
    HashSet<String> allNames = new HashSet<String>();
    String[] names;/*from   w  w w.j a va2  s  .c  om*/
    for (; writers.hasNext();) {
        names = writers.next().getFormatNames();
        for (int i = 0; i < names.length; i++) {
            allNames.add(names[i].toUpperCase());
        }
    }
    System.out.print("   Found " + allNames.size() + " format names: ");
    for (String n : allNames) {
        System.out.print("'" + n + "', ");
    }
    System.out.println();
}

From source file:org.mule.module.launcher.DefaultAppBloodhound.java

public DefaultAppBloodhound() {
    // defaults first
    parserRegistry.put("properties", new PropertiesDescriptorParser());

    final Iterator<DescriptorParser> it = ServiceRegistry.lookupProviders(DescriptorParser.class);

    MultiMap overrides = new MultiValueMap();
    while (it.hasNext()) {
        final DescriptorParser parser = it.next();
        overrides.put(parser.getSupportedFormat(), parser);
    }//  ww  w.j a va  2  s .c om
    mergeParserOverrides(overrides);
}

From source file:org.openrdf.sail.rdbms.RdbmsStore.java

private RdbmsConnectionFactory newFactory(DatabaseMetaData metaData) throws SQLException {
    String dbn = metaData.getDatabaseProductName();
    String dbv = metaData.getDatabaseProductVersion();
    RdbmsConnectionFactory factory;//from   www.ja  v  a 2 s .co  m
    Iterator<RdbmsProvider> providers;
    providers = ServiceRegistry.lookupProviders(RdbmsProvider.class);
    while (providers.hasNext()) {
        RdbmsProvider provider = providers.next();
        factory = provider.createRdbmsConnectionFactory(dbn, dbv);
        if (factory != null)
            return factory;
    }
    return new RdbmsConnectionFactory();
}