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.fits;
016
017import java.util.List;
018
019import hdf.object.FileFormat;
020import hdf.object.Group;
021
022/**
023 * An H5Group represents HDF5 group, inheriting from Group.
024 * Every HDF5 object has at least one name. An HDF5 group is used to store
025 * a set of the names together in one place, i.e. a group. The general
026 * structure of a group is similar to that of the UNIX file system in
027 * that the group may contain references to other groups or data objects
028 * just as the UNIX directory may contain subdirectories or files.
029 *
030 * @version 1.1 9/4/2007
031 * @author Peter X. Cao
032 */
033public class FitsGroup extends Group {
034    private static final long serialVersionUID = 4993155577664991838L;
035
036    /**
037     * The list of attributes of this data object. Members of the list are
038     * instance of AttributeDatset.
039     */
040    private List attributeList;
041
042    /** The default object ID for HDF5 objects */
043    private static final long[] DEFAULT_OID = {0};
044
045    /**
046     * Constructs an HDF5 group with specific name, path, and parent.
047     *
048     * @param fileFormat the file which containing the group.
049     * @param name the name of this group.
050     * @param path the full path of this group.
051     * @param parent the parent of this group.
052     * @param theID the unique identifier of this data object.
053     */
054    public FitsGroup(FileFormat fileFormat, String name, String path, Group parent, long[] theID)
055    {
056        super(fileFormat, name, path, parent, ((theID == null) ? DEFAULT_OID : theID));
057    }
058
059    /*
060     * (non-Javadoc)
061     * @see hdf.object.DataFormat#hasAttribute()
062     */
063    public boolean hasAttribute() { return false; }
064
065    // Implementing DataFormat
066    /**
067     * Retrieves the object's metadata, such as attributes, from the file.
068     *
069     * Metadata, such as attributes, is stored in a List.
070     *
071     * @return the list of metadata objects.
072     *
073     * @throws Exception
074     *             if the metadata can not be retrieved
075     */
076    public List getMetadata() throws Exception
077    {
078        if (!isRoot())
079            return null; // there is only one group in the file: the root
080
081        if (attributeList != null)
082            return attributeList;
083
084        return attributeList;
085    }
086
087    /**
088     * Writes a specific piece of metadata (such as an attribute) into the file.
089     *
090     * If an HDF(4&5) attribute exists in the file, this method updates its
091     * value. If the attribute does not exist in the file, it creates the
092     * attribute in the file and attaches it to the object. It will fail to
093     * write a new attribute to the object where an attribute with the same name
094     * already exists. To update the value of an existing attribute in the file,
095     * one needs to get the instance of the attribute by getMetadata(), change
096     * its values, then use writeMetadata() to write the value.
097     *
098     * @param info
099     *            the metadata to write.
100     *
101     * @throws Exception
102     *             if the metadata can not be written
103     */
104    public void writeMetadata(Object info) throws Exception
105    {
106        // not supported
107        throw new UnsupportedOperationException("Unsupported operation for FITS.");
108    }
109
110    /**
111     * Deletes an existing piece of metadata from this object.
112     *
113     * @param info
114     *            the metadata to delete.
115     *
116     * @throws Exception
117     *             if the metadata can not be removed
118     */
119    public void removeMetadata(Object info) throws Exception
120    {
121        // not supported
122        throw new UnsupportedOperationException("Unsupported operation for FITS.");
123    }
124
125    /**
126     * Updates an existing piece of metadata attached to this object.
127     *
128     * @param info
129     *            the metadata to update.
130     *
131     * @throws Exception
132     *             if the metadata can not be updated
133     */
134    public void updateMetadata(Object info) throws Exception
135    {
136        // not supported
137        throw new UnsupportedOperationException("Unsupported operation for FITS.");
138    }
139
140    // Implementing DataFormat
141    @Override
142    public long open()
143    {
144        // not supported
145        throw new UnsupportedOperationException("Unsupported operation for FITS.");
146    }
147
148    /**
149     *  close group access
150     *
151     * @param gid
152     *        the group identifier
153     */
154    @Override
155    public void close(long gid)
156    {
157        // not supported
158        throw new UnsupportedOperationException("Unsupported operation for FITS.");
159    }
160
161    /**
162     * Creates a new group.
163     *
164     * @param name
165     *        the name of the group to create.
166     * @param pgroup
167     *        the parent group of the new group.
168     *
169     * @return the new group if successful. Otherwise returns null.
170     *
171     * @throws Exception
172     *            if there is an error
173     */
174    public static FitsGroup create(String name, Group pgroup) throws Exception
175    {
176        // not supported
177        throw new UnsupportedOperationException("Unsupported operation for FITS.");
178    }
179
180    // Implementing DataFormat
181    /**
182     * Retrieves the object's metadata, such as attributes, from the file.
183     *
184     * Metadata, such as attributes, is stored in a List.
185     *
186     * @param attrPropList
187     *             the list of properties to get
188     *
189     * @return the list of metadata objects.
190     *
191     * @throws Exception
192     *             if the metadata can not be retrieved
193     */
194    public List getMetadata(int... attrPropList) throws Exception
195    {
196        throw new UnsupportedOperationException("getMetadata(int... attrPropList) is not supported");
197    }
198}