//============================================================================== // AbstractDocument.java //============================================================================== package tribble.archive; import java.io.IOException; import java.lang.String; import java.lang.System; import java.lang.Throwable; /******************************************************************************* * Generic read-only archive document. * *
* An archive document is composed of content data (such as an image, * text, or other kind of user data) and one or more properties. * *
* Most of the methods in this class do not throw any checked exceptions. * *
* Note: This requires Java 1.5 or later. * * *
* Note that this method can be called multiple times with no ill effects. * *
* Note that this method does not throw any exceptions. * * @since API 2.0, 2008-04-03 */ //@Override public void close() { m_props = CLOSED; } /*************************************************************************** * Retrieve the ID of this archive document. * * @return * A name that identifies the document within the archive. * * @throws IOException * Thrown if an error occurred while accessing the document. * * @since API 2.0, 2008-04-03 */ //@Override public String getID() { return m_id; } /*************************************************************************** * Retrieve the size of the data for this archive document. * * @return * The size (typically in bytes) of the document data, or -1 if the size is * not known. * * @throws IllegalStateException (unchecked) * Thrown if {@link #close} has been called for this object. * * @since API 2.0, 2008-04-03 */ //@Override public long getSize() { checkOpen(); return m_size; } /*************************************************************************** * Retrieve the properties for this archive document. * * @return * The properties defined for this document. * * @throws IllegalStateException (unchecked) * Thrown if {@link #close} has been called for this object. * * @since API 2.0, 2008-04-03 */ //@Override public DocumentProperty[] getProperties() { DocumentProperty[] copy; // Build a copy of the properties checkOpen(); copy = new DocumentProperty[m_props.length]; System.arraycopy(m_props, 0, copy, 0, m_props.length); return copy; } /*************************************************************************** * Retrieve the value of a property in this archive document. * * @param prop * The name of the document property value to retrieve. * * @return * The property value (which may be null). * * @throws IOException * Thrown if the document does not have the specified property. * * @throws IllegalStateException (unchecked) * Thrown if {@link #close} has been called for this object. * * @since API 2.0, 2008-04-03 */ //@Override public Object getProperty(String prop) throws IOException { // Sanity checks checkOpen(); if (m_propVals == null) throw new IOException("Document has no properties"); for (int i = 0; i < m_props.length; i++) { if (m_props[i].getName().equals(prop)) return m_propVals[i]; } throw new IOException("No such document property: " + prop); } } // End AbstractDocument.java