001: /*
002: * $RCSfile: TileCodecDescriptorImpl.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:55 $
010: * $State: Exp $
011: */package javax.media.jai.tilecodec;
012:
013: import javax.media.jai.PropertyGenerator;
014:
015: /**
016: * An abstract class that implements the <code>TileCodecDescriptor</code>
017: * interface and is suitable for subclassing. This class provides default
018: * implementations for some of the methods from
019: * <code>TileCodecDescriptor</code>. Subclasses should override these methods
020: * if they do not wish to retain the default implementation.
021: *
022: * All <code>String</code>s are treated in a case-retentive and
023: * case-insensitive manner.
024: *
025: * @since JAI 1.1
026: */
027: public abstract class TileCodecDescriptorImpl implements
028: TileCodecDescriptor {
029:
030: private String formatName;
031: private boolean includesSMInfo, includesLocationInfo;
032:
033: /**
034: * Creates a <code>TileCodecDescriptorImpl</code> with the given
035: * format name and <code>boolean</code>s to specify whether layout
036: * information is included in the encoded stream.
037: *
038: * @param formatName The name of the format. This is also
039: * the name under which this descriptor
040: * will be registered under in the
041: * <code>OperationRegistry</code>.
042: * @param includesSampleModelInfo Whether the format encodes the tile's
043: * <code>SampleModel</code> or equivalent
044: * information into the encoded stream.
045: * @param includesLocationInfo Whether the format encodes the tile's
046: * upper left corner position or equivalent
047: * information into the encoded stream.
048: * @throws IllegalArgumentException if formatName is null.
049: */
050: public TileCodecDescriptorImpl(String formatName,
051: boolean includesSampleModelInfo,
052: boolean includesLocationInfo) {
053:
054: // Cause IllegalArgumentException if formatName is null
055: if (formatName == null) {
056: throw new IllegalArgumentException(JaiI18N
057: .getString("TileCodecDescriptorImpl0"));
058: }
059:
060: this .formatName = formatName;
061: this .includesSMInfo = includesSampleModelInfo;
062: this .includesLocationInfo = includesLocationInfo;
063: }
064:
065: /**
066: * Returns the name of the format.
067: */
068: public String getName() {
069: return formatName;
070: }
071:
072: /**
073: * Returns the registry modes supported by this descriptor. The
074: * default implementation of this method in this class returns a
075: * <code>String</code> array containing the "tileDecoder" and
076: * "tileEncoder" strings. If the subclass does not support any of
077: * these modes, it should override this method to return the names of
078: * those modes that it supports.
079: *
080: * @see javax.media.jai.RegistryMode
081: */
082: public String[] getSupportedModes() {
083: return new String[] { "tileDecoder", "tileEncoder" };
084: }
085:
086: /**
087: * This method is implemented to return true if the specified
088: * registryModeName is either "tileDecoder" or "tileEncoder". If
089: * the subclass doesn't support any one of these modes, it should
090: * override this method to return true only for the supported mode(s).
091: *
092: * @param registryModeName The name of the registry mode to check
093: * support for.
094: * @throws IllegalArgumentException if registryModeName is null.
095: */
096: public boolean isModeSupported(String registryModeName) {
097:
098: if (registryModeName == null) {
099: throw new IllegalArgumentException(JaiI18N
100: .getString("TileCodecDescriptorImpl1"));
101: }
102:
103: if (registryModeName.equalsIgnoreCase("tileDecoder") == true
104: || registryModeName.equalsIgnoreCase("tileEncoder") == true) {
105: return true;
106: }
107:
108: return false;
109: }
110:
111: /**
112: * Whether this descriptor supports properties.
113: *
114: * @return true, if the implementation of this descriptor supports
115: * properties. false otherwise. Since tile codecs do not support
116: * properties, so this default implementation returns false.
117: *
118: * @see PropertyGenerator
119: */
120: public boolean arePropertiesSupported() {
121: return false;
122: }
123:
124: /**
125: * Returns an array of <code>PropertyGenerator</code>s implementing
126: * the property inheritance for this operation. Since neither
127: * <code>TileEncoder</code> or <code>TileDecoder</code> supports
128: * properties, the default implementation throws an
129: * <code>UnsupportedOperationException</code>. Subclasses should
130: * override this method if they wish to produce inherited properties.
131: *
132: * @throws IllegalArgumentException if <code>modeName</code> is null.
133: * @throws UnsupportedOperationException if
134: * <code>arePropertiesSupported()</code> returns <code>false</code>
135: */
136: public PropertyGenerator[] getPropertyGenerators(String modeName) {
137:
138: if (modeName == null) {
139: throw new IllegalArgumentException(JaiI18N
140: .getString("TileCodecDescriptorImpl1"));
141: }
142:
143: throw new UnsupportedOperationException(JaiI18N
144: .getString("TileCodecDescriptorImpl2"));
145: }
146:
147: /**
148: * Returns true if the format encodes layout information generally
149: * specified via the <code>SampleModel</code> in the encoded data stream.
150: */
151: public boolean includesSampleModelInfo() {
152: return includesSMInfo;
153: }
154:
155: /**
156: * Returns true if the format encodes in the data stream the location of
157: * the <code>Raster</code> with respect to its enclosing image.
158: */
159: public boolean includesLocationInfo() {
160: return includesLocationInfo;
161: }
162: }
|