001/*****************************************************************************
002 * Copyright by The HDF Group.                                               *
003 * Copyright by the Board of Trustees of the University of Illinois.         *
004 * All rights reserved.                                                      *
005 *                                                                           *
006 * This file is part of the HDF Java Products distribution.                  *
007 * The full copyright notice, including terms governing use, modification,   *
008 * and redistribution, is contained in the COPYING file, which can be found  *
009 * at the root of the source code distribution tree,                         *
010 * or in https://www.hdfgroup.org/licenses.                                  *
011 * If you do not have access to either file, you may request a copy from     *
012 * help@hdfgroup.org.                                                        *
013 ****************************************************************************/
014
015package hdf.object.h5;
016
017import java.util.ArrayList;
018import java.util.List;
019
020import hdf.hdf5lib.H5;
021import hdf.hdf5lib.HDF5Constants;
022import hdf.hdf5lib.exceptions.HDF5Exception;
023
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026
027/** HDF5 plugin utility class */
028public final class H5Plugins {
029
030    private static final Logger log = LoggerFactory.getLogger(H5Plugins.class);
031
032    private static long totalPaths;
033
034    /**
035     * Creates a list of plugin paths for HDFView.
036     *
037     */
038    public H5Plugins()
039    {
040        totalPaths = H5.H5PLsize(); // initial number of paths
041    }
042
043    /**
044     * Get the total number of paths for the HDF5 library.
045     *
046     * @return total number of plugin paths
047     *
048     * @throws HDF5Exception If there is an error at the HDF5 library level.
049     */
050    public static final long getTotalPluginPaths() throws HDF5Exception
051    {
052        totalPaths = H5.H5PLsize();
053
054        log.trace("getTotalPluginPaths(): total plugin paths {}", totalPaths);
055
056        return totalPaths;
057    }
058
059    /**
060     * Get the list of paths for the HDF5 library.
061     *
062     * @return list of plugin paths
063     *
064     * @throws HDF5Exception If there is an error at the HDF5 library level.
065     */
066    public static final ArrayList<String> getPluginPaths() throws HDF5Exception
067    {
068        ArrayList<String> pathList = new ArrayList<>(5);
069        totalPaths                 = H5.H5PLsize();
070        log.trace("getPluginPaths(): total plugin paths {}", totalPaths);
071        for (int indx = 0; indx < totalPaths; indx++)
072            pathList.add(H5.H5PLget(indx));
073
074        return pathList;
075    }
076
077    /**
078     * Replaces the plugin path.
079     *
080     * @param pluginPath The plugin path.
081     * @param pathIndex  The index to replace the plugin path.
082     */
083    public static void replacePluginPath(String pluginPath, int pathIndex) throws HDF5Exception
084    {
085        H5.H5PLreplace(pluginPath, pathIndex);
086    }
087
088    /**
089     * Inserts the plugin path.
090     *
091     * @param pluginPath The plugin path.
092     * @param pathIndex  The index to insert the plugin path.
093     */
094    public static void insertPluginPath(String pluginPath, int pathIndex) throws HDF5Exception
095    {
096        H5.H5PLinsert(pluginPath, pathIndex);
097    }
098
099    /**
100     * Removes the plugin path.
101     *
102     * @param pathIndex  The index to remove the plugin path.
103     */
104    public static void deletePluginPath(int pathIndex) throws HDF5Exception { H5.H5PLremove(pathIndex); }
105
106    /**
107     * Prepend the plugin path.
108     *
109     * @param pluginPath The plugin path.
110     */
111    public static void prependPluginPath(String pluginPath) throws HDF5Exception
112    {
113        H5.H5PLprepend(pluginPath);
114    }
115
116    /**
117     * Append the plugin path.
118     *
119     * @param pluginPath The plugin path.
120     */
121    public static void appendPluginPath(String pluginPath) throws HDF5Exception { H5.H5PLappend(pluginPath); }
122}