Index: src/main/java/javax/imageio/metadata/IIOMetadata.java =================================================================== --- src/main/java/javax/imageio/metadata/IIOMetadata.java (revision 478555) +++ src/main/java/javax/imageio/metadata/IIOMetadata.java (working copy) @@ -14,18 +14,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * @author Rustem V. Rafikov - * @version $Revision: 1.3 $ - */ package javax.imageio.metadata; -/** - * @author Rustem V. Rafikov - * @version $Revision: 1.3 $ - * - * TODO add all the methods from the spec - */ +import org.w3c.dom.Node; +import org.apache.harmony.x.imageio.metadata.IIOMetadataUtils; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.lang.reflect.Method; +import java.util.ArrayList; + public abstract class IIOMetadata { protected boolean standardFormatSupported; @@ -36,18 +34,179 @@ protected IIOMetadataController defaultController; protected IIOMetadataController controller; - protected IIOMetadata() { - throw new UnsupportedOperationException("Not supported yet"); - } + protected IIOMetadata() {} protected IIOMetadata(boolean standardMetadataFormatSupported, String nativeMetadataFormatName, String nativeMetadataFormatClassName, String[] extraMetadataFormatNames, String[] extraMetadataFormatClassNames) { - // TODO implement for SpecJBB - throw new UnsupportedOperationException("Not supported yet"); + standardFormatSupported = standardMetadataFormatSupported; + this.nativeMetadataFormatName = nativeMetadataFormatName; + this.nativeMetadataFormatClassName = nativeMetadataFormatClassName; + if (extraMetadataFormatNames == null) { + if (extraMetadataFormatClassNames != null) { + throw new IllegalArgumentException( + "extraMetadataFormatNames == null && extraMetadataFormatClassNames != null!" + ); + } + } else { + if (extraMetadataFormatClassNames == null) { + throw new IllegalArgumentException( + "extraMetadataFormatNames != null && extraMetadataFormatClassNames == null!" + ); + } + if (extraMetadataFormatNames.length == 0) { + throw new IllegalArgumentException("extraMetadataFormatNames.length == 0!"); + } + if (extraMetadataFormatClassNames.length != extraMetadataFormatNames.length) { + throw new IllegalArgumentException( + "extraMetadataFormatClassNames.length != extraMetadataFormatNames.length!" + ); + } + this.extraMetadataFormatNames = extraMetadataFormatNames.clone(); + this.extraMetadataFormatClassNames = extraMetadataFormatClassNames.clone(); + } } - //-- TODO add all the methods from the spec + public abstract Node getAsTree(String formatName); + public abstract boolean isReadOnly(); + public abstract void mergeTree(String formatName, Node root) throws IIOInvalidTreeException; + public abstract void reset(); + + public IIOMetadataController getController() { + return controller; + } + + public boolean hasController() { + return getController() != null; + } + + public boolean activateController() { + if (!hasController()) { + throw new IllegalStateException("hasController() == false!"); + } + return getController().activate(this); + } + + public IIOMetadataController getDefaultController() { + return defaultController; + } + + public String[] getExtraMetadataFormatNames() { + return extraMetadataFormatNames == null ? null : extraMetadataFormatNames.clone(); + } + + public IIOMetadataFormat getMetadataFormat(String formatName) { + return IIOMetadataUtils.instantiateMetadataFormat( + formatName, + standardFormatSupported, + nativeMetadataFormatName, nativeMetadataFormatClassName, + extraMetadataFormatNames, extraMetadataFormatClassNames + ); + } + + public String getNativeMetadataFormatName() { + return nativeMetadataFormatName; + } + + public boolean isStandardMetadataFormatSupported() { + return standardFormatSupported; + } + + public String[] getMetadataFormatNames() { + ArrayList res = new ArrayList(); + + String nativeMetadataFormatName = getNativeMetadataFormatName(); + boolean standardFormatSupported = isStandardMetadataFormatSupported(); + String extraMetadataFormatNames[] = getExtraMetadataFormatNames(); + + if (standardFormatSupported) { + res.add(IIOMetadataFormatImpl.standardMetadataFormatName); + } + if (nativeMetadataFormatName != null) { + res.add(nativeMetadataFormatName); + } + if (extraMetadataFormatNames != null) { + for (String extraMetadataFormatName : extraMetadataFormatNames) { + res.add(extraMetadataFormatName); + } + } + + return res.size() > 0 ? res.toArray(new String[0]) : null; + } + + protected IIOMetadataNode getStandardChromaNode() { + return null; + } + + protected IIOMetadataNode getStandardCompressionNode() { + return null; + } + + protected IIOMetadataNode getStandardDataNode() { + return null; + } + + protected IIOMetadataNode getStandardDimensionNode() { + return null; + } + + protected IIOMetadataNode getStandardDocumentNode() { + return null; + } + + protected IIOMetadataNode getStandardTextNode() { + return null; + } + + protected IIOMetadataNode getStandardTileNode() { + return null; + } + + protected IIOMetadataNode getStandardTransparencyNode() { + return null; + } + + protected final IIOMetadataNode getStandardTree() { + // Create root node + IIOMetadataNode root = new IIOMetadataNode(IIOMetadataFormatImpl.standardMetadataFormatName); + + Node node; + if ((node = getStandardChromaNode()) != null) { + root.appendChild(node); + } + if ((node = getStandardCompressionNode()) != null) { + root.appendChild(node); + } + if ((node = getStandardDataNode()) != null) { + root.appendChild(node); + } + if ((node = getStandardDimensionNode()) != null) { + root.appendChild(node); + } + if ((node = getStandardDocumentNode()) != null) { + root.appendChild(node); + } + if ((node = getStandardTextNode()) != null) { + root.appendChild(node); + } + if ((node = getStandardTileNode()) != null) { + root.appendChild(node); + } + if ((node = getStandardTransparencyNode()) != null) { + root.appendChild(node); + } + + return root; + } + + public void setController(IIOMetadataController controller) { + this.controller = controller; + } + + public void setFromTree(String formatName, Node root) throws IIOInvalidTreeException { + reset(); + mergeTree(formatName, root); + } } Index: src/main/java/javax/imageio/spi/ImageReaderWriterSpi.java =================================================================== --- src/main/java/javax/imageio/spi/ImageReaderWriterSpi.java (revision 478555) +++ src/main/java/javax/imageio/spi/ImageReaderWriterSpi.java (working copy) @@ -20,9 +20,10 @@ */ package javax.imageio.spi; -/** - * TODO add all the methods from the spec - */ +import org.apache.harmony.x.imageio.metadata.IIOMetadataUtils; + +import javax.imageio.metadata.IIOMetadataFormat; + public abstract class ImageReaderWriterSpi extends IIOServiceProvider implements RegisterableService { @@ -56,7 +57,7 @@ String[] extraImageMetadataFormatClassNames) { super(vendorName, version); - if (names == null || names.length == 0 || pluginClassName == null) { + if (names == null || names.length == 0) { throw new NullPointerException("format names array cannot be NULL or empty"); } @@ -64,32 +65,93 @@ throw new NullPointerException("Plugin class name cannot be NULL"); } - - this.names = names; - this.suffixes = suffixes; - this.MIMETypes = MIMETypes; + // We clone all the arrays to be consistent with the fact that + // some methods of this class must return clones of the arrays + // as it is stated in the spec. + this.names = names.clone(); + this.suffixes = suffixes == null ? null : suffixes.clone(); + this.MIMETypes = MIMETypes == null ? null : MIMETypes.clone(); this.pluginClassName = pluginClassName; this.supportsStandardStreamMetadataFormat = supportsStandardStreamMetadataFormat; this.nativeStreamMetadataFormatName = nativeStreamMetadataFormatName; this.nativeStreamMetadataFormatClassName = nativeStreamMetadataFormatClassName; - this.extraStreamMetadataFormatNames = extraStreamMetadataFormatNames; - this.extraStreamMetadataFormatClassNames = extraStreamMetadataFormatClassNames; + + this.extraStreamMetadataFormatNames = + extraStreamMetadataFormatNames == null ? + null : extraStreamMetadataFormatNames.clone(); + + this.extraStreamMetadataFormatClassNames = + extraStreamMetadataFormatClassNames == null ? + null : extraStreamMetadataFormatClassNames.clone(); + this.supportsStandardImageMetadataFormat = supportsStandardImageMetadataFormat; this.nativeImageMetadataFormatName = nativeImageMetadataFormatName; this.nativeImageMetadataFormatClassName = nativeImageMetadataFormatClassName; - this.extraImageMetadataFormatNames = extraImageMetadataFormatNames; - this.extraImageMetadataFormatClassNames = extraImageMetadataFormatClassNames; - } - public ImageReaderWriterSpi() { - throw new UnsupportedOperationException("Not implemented yet"); + this.extraImageMetadataFormatNames = + extraImageMetadataFormatNames == null ? + null : extraImageMetadataFormatNames.clone(); + + this.extraImageMetadataFormatClassNames = + extraImageMetadataFormatClassNames == null ? + null : extraImageMetadataFormatClassNames.clone(); } + public ImageReaderWriterSpi() {} + public String[] getFormatNames() { - return names; + return names.clone(); } public String[] getFileSuffixes() { - return suffixes; + return suffixes == null ? null : suffixes.clone(); } + + public String[] getExtraImageMetadataFormatNames() { + return extraImageMetadataFormatNames == null ? null : extraImageMetadataFormatNames.clone(); + } + + public String[] getExtraStreamMetadataFormatNames() { + return extraStreamMetadataFormatNames == null ? null : extraStreamMetadataFormatNames.clone(); + } + + public IIOMetadataFormat getImageMetadataFormat(String formatName) { + return IIOMetadataUtils.instantiateMetadataFormat( + formatName, supportsStandardImageMetadataFormat, + nativeImageMetadataFormatName, nativeImageMetadataFormatClassName, + extraImageMetadataFormatNames, extraImageMetadataFormatClassNames + ); + } + + public IIOMetadataFormat getStreamMetadataFormat(String formatName) { + return IIOMetadataUtils.instantiateMetadataFormat( + formatName, supportsStandardStreamMetadataFormat, + nativeStreamMetadataFormatName, nativeStreamMetadataFormatClassName, + extraStreamMetadataFormatNames, extraStreamMetadataFormatClassNames + ); + } + + public String[] getMIMETypes() { + return MIMETypes == null ? null : MIMETypes.clone(); + } + + public String getNativeImageMetadataFormatName() { + return nativeImageMetadataFormatName; + } + + public String getNativeStreamMetadataFormatName() { + return nativeStreamMetadataFormatName; + } + + public String getPluginClassName() { + return pluginClassName; + } + + public boolean isStandardImageMetadataFormatSupported() { + return supportsStandardImageMetadataFormat; + } + + public boolean isStandardStreamMetadataFormatSupported() { + return supportsStandardStreamMetadataFormat; + } } Index: src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java =================================================================== --- src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java (revision 478555) +++ src/main/java/javax/imageio/stream/MemoryCacheImageInputStream.java (working copy) @@ -27,7 +27,7 @@ private InputStream is; private RandomAccessMemoryCache ramc = new RandomAccessMemoryCache(); - public MemoryCacheImageInputStream(InputStream stream) throws IOException { + public MemoryCacheImageInputStream(InputStream stream) { if (stream == null) { throw new IllegalArgumentException("stream == null!"); }