    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 files COPYING and Copyright.html. *
    009 * COPYING can be found at the root of the source code distribution tree.    *
    010 * Or, see https://support.hdfgroup.org/products/licenses.html               *
    011 * If you do not have access to either file, you may request a copy from     *
    012 * help@hdfgroup.org.                                                        *
    013 ****************************************************************************/
    014
    015package hdf.view.MetaDataView;
    016
    017import org.eclipse.swt.widgets.Composite;
    018
    019import hdf.object.Dataset;
    020import hdf.object.Datatype;
    021import hdf.object.Group;
    022import hdf.object.HObject;
    023import hdf.object.h5.H5Link;
    024import hdf.view.Tools;
    025import hdf.view.ViewProperties;
    026import hdf.view.DataView.DataViewManager;
    027
    028/**
    029 * A simple Factory class which returns concrete instances of the default
    030 * MetaDataView, based on whether the data object is a Group, Dataset, Datatype
    031 * or other form of object.
    032 *
    033 * @author jhenderson
    034 * @version 1.0 4/18/2018
    035 */
    036public class DefaultMetaDataViewFactory extends MetaDataViewFactory {
    037
    038    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DefaultMetaDataViewFactory.class);
    039
    040    @Override
    041    public MetaDataView getMetaDataView(Composite parentObj, DataViewManager viewer, HObject theObj) throws ClassNotFoundException {
    042        String dataViewName = null;
    043        Object[] initargs = { parentObj, viewer, theObj };
    044        MetaDataView theView = null;
    045
    046        if (theObj instanceof Group)
    047            dataViewName = ViewProperties.DEFAULT_GROUP_METADATAVIEW_NAME;
    048        else if (theObj instanceof Dataset)
    049            dataViewName = ViewProperties.DEFAULT_DATASET_METADATAVIEW_NAME;
    050        else if (theObj instanceof Datatype)
    051            dataViewName = ViewProperties.DEFAULT_DATATYPE_METADATAVIEW_NAME;
    052        else if (theObj instanceof H5Link)
    053            dataViewName = ViewProperties.DEFAULT_LINK_METADATAVIEW_NAME;
    054        else
    055            dataViewName = null;
    056
    057        Class<?> theClass = null;
    058        try {
    059            log.trace("getMetaDataView(): Class.forName({})", dataViewName);
    060
    061            /* Attempt to load the class by the given name */
    062            theClass = Class.forName(dataViewName);
    063        }
    064        catch (Exception ex) {
    065            log.debug("getMetaDataView(): unable to load default MetaDataView class by name({})", dataViewName);
    066            theClass = null;
    067        }
    068
    069        if (theClass == null) throw new ClassNotFoundException();
    070
    071        try {
    072            theView = (MetaDataView) Tools.newInstance(theClass, initargs);
    073
    074            log.trace("getMetaDataView(): returning MetaDataView instance {}", theView);
    075        }
    076        catch (Exception ex) {
    077            log.debug("getMetaDataView(): Error instantiating class:", ex);
    078            theView = null;
    079        }
    080
    081        return theView;
    082    }
    083
    084}