summaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/imageio/metadata
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libjava/classpath/javax/imageio/metadata
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libjava/classpath/javax/imageio/metadata')
-rw-r--r--libjava/classpath/javax/imageio/metadata/IIOInvalidTreeException.java68
-rw-r--r--libjava/classpath/javax/imageio/metadata/IIOMetadata.java323
-rw-r--r--libjava/classpath/javax/imageio/metadata/IIOMetadataController.java47
-rw-r--r--libjava/classpath/javax/imageio/metadata/IIOMetadataFormat.java124
-rw-r--r--libjava/classpath/javax/imageio/metadata/IIOMetadataFormatImpl.java881
-rw-r--r--libjava/classpath/javax/imageio/metadata/IIOMetadataNode.java709
-rw-r--r--libjava/classpath/javax/imageio/metadata/package.html46
7 files changed, 2198 insertions, 0 deletions
diff --git a/libjava/classpath/javax/imageio/metadata/IIOInvalidTreeException.java b/libjava/classpath/javax/imageio/metadata/IIOInvalidTreeException.java
new file mode 100644
index 000000000..b79b8cf96
--- /dev/null
+++ b/libjava/classpath/javax/imageio/metadata/IIOInvalidTreeException.java
@@ -0,0 +1,68 @@
+/* IIOInvalidTreeException.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.metadata;
+
+import javax.imageio.IIOException;
+
+import org.w3c.dom.Node;
+
+public class IIOInvalidTreeException extends IIOException
+{
+ private static final long serialVersionUID = -1314083172544132777L;
+
+ protected Node offendingNode;
+
+ public IIOInvalidTreeException(String message, Node offendingNode)
+ {
+ super(message);
+ this.offendingNode = offendingNode;
+ }
+
+ public IIOInvalidTreeException(String message, Throwable cause,
+ Node offendingNode)
+ {
+ super(message, cause);
+ this.offendingNode = offendingNode;
+ }
+
+ public Node getOffendingNode()
+ {
+ return offendingNode;
+ }
+}
diff --git a/libjava/classpath/javax/imageio/metadata/IIOMetadata.java b/libjava/classpath/javax/imageio/metadata/IIOMetadata.java
new file mode 100644
index 000000000..b898b9942
--- /dev/null
+++ b/libjava/classpath/javax/imageio/metadata/IIOMetadata.java
@@ -0,0 +1,323 @@
+/* IIOMetadata.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.metadata;
+
+import org.w3c.dom.Node;
+
+/**
+ * Represents metadata that describe an image or an image stream.
+ * Each ImageIO plugin will represent image data using an opaque
+ * object but all such objects should expose their internal
+ * information as a tree of IIOMetadataNodes.
+ *
+ * There are three formats of metadata that a plugin can support:
+ *
+ * <ul>
+ * <li>a "native" format</li>
+ * <li>a custom format</li>
+ * <li>a standard plugin-neutral format</li>
+ * </ul>
+ *
+ * If a plugin supports more than one format of metadata, the other
+ * formats can be retrieved by calling getMetadataFormatNames.
+ *
+ * The native format is used to transfer metadata from one image to
+ * another image of the same type, losslessly.
+ *
+ * The custom format describes the image metadata and exposes a tree
+ * of IIOMetadataNodes but its internal representation is specific to
+ * this plugin.
+ *
+ * The plugin-neutral format uses a generic tree structure as its
+ * internal representation.
+ *
+ * ImageTranscoders may be used to convert metadata understood by one
+ * plugin to metadata understood by another, however the conversion
+ * may be lossy.
+ *
+ * @author Michael Koch (konqueror@gmx.de)
+ * @author Thomas Fitzsimmons (fitzsim@redhat.com)
+ */
+public abstract class IIOMetadata
+{
+ protected IIOMetadataController controller;
+ protected IIOMetadataController defaultController;
+ protected String[] extraMetadataFormatClassNames;
+ protected String[] extraMetadataFormatNames;
+ protected String nativeMetadataFormatClassName;
+ protected String nativeMetadataFormatName;
+ protected boolean standardFormatSupported;
+
+ /**
+ * Construct an IIOMetadata object.
+ */
+ protected IIOMetadata()
+ {
+ // Do nothing here.
+ }
+
+ /**
+ * Construct an IIOMetadata object.
+ *
+ * @param standardMetadataFormatSupported
+ * @param nativeMetadataFormatName
+ * @param nativeMetadataFormatClassName
+ * @param extraMetadataFormatNames
+ * @param extraMetadataFormatClassNames
+ *
+ * @throws IllegalArgumentException if extraMetadataFormatNames has length of
+ * zero or extraMetadataFormatNames and extraMetadataFormatClassNames are
+ * neither both null, not have the same length
+ */
+ protected IIOMetadata(boolean standardMetadataFormatSupported,
+ String nativeMetadataFormatName,
+ String nativeMetadataFormatClassName,
+ String[] extraMetadataFormatNames,
+ String[] extraMetadataFormatClassNames)
+ {
+ if (extraMetadataFormatNames != null
+ && extraMetadataFormatNames.length == 0)
+ throw new IllegalArgumentException
+ ("extraMetadataFormatNames may not be empty");
+
+ if (((extraMetadataFormatNames == null)
+ && (extraMetadataFormatClassNames != null))
+ || ((extraMetadataFormatNames != null)
+ && (extraMetadataFormatClassNames == null))
+ || ((extraMetadataFormatNames != null)
+ && (extraMetadataFormatClassNames != null)
+ && (extraMetadataFormatNames.length !=
+ extraMetadataFormatClassNames.length)))
+ throw new IllegalArgumentException
+ ("extraMetadataFormatNames and extraMetadataFormatClassNames " +
+ "have different lengths");
+
+ this.standardFormatSupported = standardMetadataFormatSupported;
+ this.nativeMetadataFormatName = nativeMetadataFormatName;
+ this.nativeMetadataFormatClassName = nativeMetadataFormatClassName;
+ this.extraMetadataFormatNames = extraMetadataFormatNames;
+ this.extraMetadataFormatClassNames = extraMetadataFormatClassNames;
+ }
+
+ public boolean activateController()
+ {
+ if (! hasController())
+ return false;
+
+ return getDefaultController().activate(this);
+ }
+
+ public IIOMetadataController getController()
+ {
+ return controller;
+ }
+
+ public IIOMetadataController getDefaultController()
+ {
+ return defaultController;
+ }
+
+ public String[] getExtraMetadataFormatNames()
+ {
+ return (String[]) extraMetadataFormatNames.clone();
+ }
+
+ public IIOMetadataFormat getMetadataFormat(String formatName)
+ {
+ if (formatName == null)
+ throw new IllegalArgumentException("formatName may not be null");
+
+ String formatClassName = null;
+
+ if (isStandardMetadataFormatSupported()
+ && formatName.equals(nativeMetadataFormatName))
+ formatClassName = nativeMetadataFormatClassName;
+ else
+ {
+ String[] extraFormatNames = getExtraMetadataFormatNames();
+
+ for (int i = extraFormatNames.length - 1; i >= 0; --i)
+ if (extraFormatNames[i].equals(formatName))
+ {
+ formatClassName = extraFormatNames[i];
+ break;
+ }
+ }
+
+ if (formatClassName == null)
+ throw new IllegalArgumentException("unknown format");
+
+ IIOMetadataFormat format;
+
+ try
+ {
+ format = (IIOMetadataFormat) Class.forName(formatClassName)
+ .newInstance();
+ }
+ catch (Exception e)
+ {
+ IllegalStateException ise = new IllegalStateException();
+ ise.initCause(e);
+ throw ise;
+ }
+
+ return format;
+ }
+
+ public String[] getMetadataFormatNames()
+ {
+ String[] formatNames = getExtraMetadataFormatNames();
+
+ if (isStandardMetadataFormatSupported())
+ {
+ // Combine native metadata format name and extra metadata format names
+ // into one String array.
+ String[] tmp = new String[formatNames.length + 1];
+ tmp[0] = getNativeMetadataFormatName();
+
+ for (int i = 1; i < tmp.length; ++i)
+ tmp[i] = formatNames[i - 1];
+
+ formatNames = tmp;
+ }
+
+ return formatNames;
+ }
+
+ public String getNativeMetadataFormatName()
+ {
+ return nativeMetadataFormatName;
+ }
+
+ public boolean hasController()
+ {
+ return getController() != null;
+ }
+
+ public abstract boolean isReadOnly();
+
+ public boolean isStandardMetadataFormatSupported()
+ {
+ return standardFormatSupported;
+ }
+
+ public abstract void reset();
+
+ public void setController(IIOMetadataController controller)
+ {
+ this.controller = controller;
+ }
+
+ public abstract Node getAsTree (String formatName);
+
+ 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;
+ }
+
+ private void appendChild (IIOMetadataNode node,
+ IIOMetadataNode child)
+ {
+ if (child != null)
+ node.appendChild(child);
+ }
+
+ protected final IIOMetadataNode getStandardTree ()
+ {
+ IIOMetadataNode node = new IIOMetadataNode();
+
+ appendChild (node, getStandardChromaNode());
+ appendChild (node, getStandardCompressionNode());
+ appendChild (node, getStandardDataNode());
+ appendChild (node, getStandardDimensionNode());
+ appendChild (node, getStandardDocumentNode());
+ appendChild (node, getStandardTextNode());
+ appendChild (node, getStandardTileNode());
+ appendChild (node, getStandardTransparencyNode());
+
+ return node;
+ }
+
+ public abstract void mergeTree (String formatName,
+ Node root)
+ throws IIOInvalidTreeException;
+
+ public void setFromTree (String formatName, Node root)
+ throws IIOInvalidTreeException
+ {
+ reset();
+
+ mergeTree (formatName, root);
+ }
+}
diff --git a/libjava/classpath/javax/imageio/metadata/IIOMetadataController.java b/libjava/classpath/javax/imageio/metadata/IIOMetadataController.java
new file mode 100644
index 000000000..86e544386
--- /dev/null
+++ b/libjava/classpath/javax/imageio/metadata/IIOMetadataController.java
@@ -0,0 +1,47 @@
+/* IIOMetadataController.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.metadata;
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ */
+public interface IIOMetadataController
+{
+ boolean activate(IIOMetadata metadata);
+}
diff --git a/libjava/classpath/javax/imageio/metadata/IIOMetadataFormat.java b/libjava/classpath/javax/imageio/metadata/IIOMetadataFormat.java
new file mode 100644
index 000000000..15f2ceb0b
--- /dev/null
+++ b/libjava/classpath/javax/imageio/metadata/IIOMetadataFormat.java
@@ -0,0 +1,124 @@
+/* IIOMetadataFormat.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.metadata;
+
+import java.util.Locale;
+
+import javax.imageio.ImageTypeSpecifier;
+
+/**
+ * @author Michael Koch (konqueror@gmx.de)
+ */
+public interface IIOMetadataFormat
+{
+ int CHILD_POLICY_ALL = 1;
+ int CHILD_POLICY_CHOICE = 3;
+ int CHILD_POLICY_EMPTY = 0;
+ int CHILD_POLICY_MAX = 5;
+ int CHILD_POLICY_REPEAT = 5;
+ int CHILD_POLICY_SEQUENCE = 4;
+ int CHILD_POLICY_SOME = 2;
+ int DATATYPE_BOOLEAN = 1;
+ int DATATYPE_DOUBLE = 4;
+ int DATATYPE_FLOAT = 3;
+ int DATATYPE_INTEGER = 2;
+ int DATATYPE_STRING = 0;
+ int VALUE_ARBITRARY = 1;
+ int VALUE_ENUMERATION = 16;
+ int VALUE_LIST = 32;
+ int VALUE_NONE = 0;
+ int VALUE_RANGE = 2;
+ int VALUE_RANGE_MAX_INCLUSIVE = 10;
+ int VALUE_RANGE_MAX_INCLUSIVE_MASK = 8;
+ int VALUE_RANGE_MIN_INCLUSIVE = 6;
+ int VALUE_RANGE_MIN_INCLUSIVE_MASK = 4;
+ int VALUE_RANGE_MIN_MAX_INCLUSIVE = 14;
+
+ boolean canNodeAppear (String elementName, ImageTypeSpecifier imageType);
+
+ int getAttributeDataType (String elementName, String attrName);
+
+ String getAttributeDefaultValue (String elementName, String attrName);
+
+ String getAttributeDescription (String elementName, String attrName, Locale locale);
+
+ String[] getAttributeEnumerations (String elementName, String attrName);
+
+ int getAttributeListMaxLength (String elementName, String attrName);
+
+ int getAttributeListMinLength (String elementName, String attrName);
+
+ String getAttributeMaxValue (String elementName, String attrName);
+
+ String getAttributeMinValue (String elementName, String attrName);
+
+ String[] getAttributeNames (String elementName);
+
+ int getAttributeValueType (String elementName, String attrName);
+
+ String[] getChildNames (String elementName);
+
+ int getChildPolicy (String elementName);
+
+ String getElementDescription (String elementName, Locale locale);
+
+ int getElementMaxChildren (String elementName);
+
+ int getElementMinChildren (String elementName);
+
+ int getObjectArrayMaxLength (String elementName);
+
+ int getObjectArrayMinLength (String elementName);
+
+ Class<?> getObjectClass (String elementName);
+
+ Object getObjectDefaultValue (String elementName);
+
+ Object[] getObjectEnumerations (String elementName);
+
+ Comparable<?> getObjectMaxValue (String elementName);
+
+ Comparable<?> getObjectMinValue (String elementName);
+
+ int getObjectValueType (String elementName);
+
+ String getRootName();
+
+ boolean isAttributeRequired (String elementName, String attrName);
+}
diff --git a/libjava/classpath/javax/imageio/metadata/IIOMetadataFormatImpl.java b/libjava/classpath/javax/imageio/metadata/IIOMetadataFormatImpl.java
new file mode 100644
index 000000000..efea723f9
--- /dev/null
+++ b/libjava/classpath/javax/imageio/metadata/IIOMetadataFormatImpl.java
@@ -0,0 +1,881 @@
+/* IIOMetadataFormatImpl.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.metadata;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.TypeInfo;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
+import javax.imageio.ImageTypeSpecifier;
+
+public abstract class IIOMetadataFormatImpl implements IIOMetadataFormat
+{
+ /**
+ * The standard metadata format name constant set to
+ * "javax_imageio_1.0".
+ */
+ public static final String standardMetadataFormatName = "javax_imageio_1.0";
+
+ private String rootName;
+
+ // These maps assume that each element name is unique.
+
+ private Map nodes = new HashMap();
+
+ // A mapping from element name to child policy.
+ private Map childPolicies = new HashMap();
+
+ // A mapping from element name to the permissible number of
+ // children. Values in this map are length-two integer arrays; the
+ // first index is the minimum bound, the second index is the maximum
+ // bound.
+ private Map childRanges = new HashMap();
+
+ private String resourceBaseName;
+
+ // Package-private so that it may be used in IIOMetadataNode.
+ static class IIOMetadataNodeAttr extends IIOMetadataNode
+ implements Attr
+ {
+ protected Element owner;
+ protected String name;
+ protected int dataType;
+ protected boolean required;
+ protected String defaultValue;
+
+ public IIOMetadataNodeAttr (Element owner,
+ String name,
+ String defaultValue)
+ {
+ this (owner, name, IIOMetadataFormat.DATATYPE_STRING,
+ true, defaultValue);
+ }
+
+ public IIOMetadataNodeAttr (Element owner,
+ String name,
+ int dataType,
+ boolean required,
+ String defaultValue)
+ {
+ this.owner = owner;
+ this.name = name;
+ this.dataType = dataType;
+ this.required = required;
+ this.defaultValue = defaultValue;
+ }
+
+ public String getName ()
+ {
+ return name;
+ }
+
+ public Element getOwnerElement ()
+ {
+ return owner;
+ }
+
+ public int getDataType ()
+ {
+ return dataType;
+ }
+
+ public TypeInfo getSchemaTypeInfo ()
+ {
+ return null;
+ }
+
+ public boolean getSpecified ()
+ {
+ return false;
+ }
+
+ public String getValue ()
+ {
+ return defaultValue;
+ }
+
+ public boolean isId()
+ {
+ return false;
+ }
+
+ public void setValue (String value)
+ {
+ }
+
+ // new methods
+
+ public boolean isRequired ()
+ {
+ return required;
+ }
+ }
+
+ private class IIOMetadataNodeAttrEnumerated extends IIOMetadataNodeAttr
+ {
+ protected List enumeratedValues;
+
+ public IIOMetadataNodeAttrEnumerated (Element owner,
+ String name,
+ int dataType,
+ boolean required,
+ String defaultValue,
+ List enumeratedValues)
+ {
+ super (owner, name, dataType, required, defaultValue);
+ this.enumeratedValues = new ArrayList (enumeratedValues);
+ }
+
+ public Object[] getEnumerations ()
+ {
+ return enumeratedValues.toArray ();
+ }
+ }
+
+ private class IIOMetadataNodeAttrBounded extends IIOMetadataNodeAttr
+ {
+ protected String minValue;
+ protected String maxValue;
+ protected boolean minInclusive;
+ protected boolean maxInclusive;
+
+ public IIOMetadataNodeAttrBounded (Element owner,
+ String name,
+ int dataType,
+ boolean required,
+ String defaultValue,
+ String minValue,
+ String maxValue,
+ boolean minInclusive,
+ boolean maxInclusive)
+ {
+ super (owner, name, dataType, required, defaultValue);
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ this.minInclusive = minInclusive;
+ this.maxInclusive = maxInclusive;
+ }
+
+ public String getMinValue ()
+ {
+ return minValue;
+ }
+
+ public String getMaxValue ()
+ {
+ return maxValue;
+ }
+ }
+
+ private class IIOMetadataNodeAttrList extends IIOMetadataNodeAttr
+ {
+ protected int listMinLength;
+ protected int listMaxLength;
+
+ public IIOMetadataNodeAttrList (Element owner,
+ String name,
+ int dataType,
+ boolean required,
+ int listMinLength,
+ int listMaxLength)
+ {
+ super (owner, name, dataType, required, null);
+ this.listMinLength = listMinLength;
+ this.listMaxLength = listMaxLength;
+ }
+
+ public int getListMinLength ()
+ {
+ return listMinLength;
+ }
+
+ public int getListMaxLength ()
+ {
+ return listMaxLength;
+ }
+ }
+
+ private class NodeObject
+ {
+ protected Element owner;
+ protected Class classType;
+ protected boolean required;
+ protected Object defaultValue;
+ protected int valueType;
+
+ public NodeObject (Element owner,
+ Class classType,
+ boolean required,
+ Object defaultValue)
+ {
+ this.owner = owner;
+ this.classType = classType;
+ this.required = required;
+ this.defaultValue = defaultValue;
+ valueType = IIOMetadataFormat.VALUE_ARBITRARY;
+ }
+
+ public int getValueType ()
+ {
+ return valueType;
+ }
+
+ public Class getClassType ()
+ {
+ return classType;
+ }
+
+ public Element getOwnerElement ()
+ {
+ return owner;
+ }
+
+ public Object getDefaultValue ()
+ {
+ return defaultValue;
+ }
+
+ public boolean isRequired ()
+ {
+ return required;
+ }
+ }
+
+ private class NodeObjectEnumerated extends NodeObject
+ {
+ protected List enumeratedValues;
+
+ public NodeObjectEnumerated (Element owner,
+ Class classType,
+ boolean required,
+ Object defaultValue,
+ List enumeratedValues)
+ {
+ super (owner, classType, false, defaultValue);
+ this.enumeratedValues = enumeratedValues;
+ valueType = IIOMetadataFormat.VALUE_ENUMERATION;
+ }
+
+ public Object[] getEnumerations ()
+ {
+ return enumeratedValues.toArray();
+ }
+ }
+
+ private class NodeObjectBounded extends NodeObject
+ {
+ protected Comparable minValue;
+ protected Comparable maxValue;
+ protected boolean minInclusive;
+ protected boolean maxInclusive;
+
+ public NodeObjectBounded (Element owner,
+ Class classType,
+ Object defaultValue,
+ Comparable minValue,
+ Comparable maxValue,
+ boolean minInclusive,
+ boolean maxInclusive)
+ {
+ super (owner, classType, false, defaultValue);
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ this.minInclusive = minInclusive;
+ this.maxInclusive = maxInclusive;
+ if (minInclusive)
+ {
+ if (maxInclusive)
+ valueType = IIOMetadataFormat.VALUE_RANGE_MIN_MAX_INCLUSIVE;
+ else
+ valueType = IIOMetadataFormat.VALUE_RANGE_MIN_INCLUSIVE;
+ }
+ else
+ {
+ if (maxInclusive)
+ valueType = IIOMetadataFormat.VALUE_RANGE_MAX_INCLUSIVE;
+ else
+ valueType = IIOMetadataFormat.VALUE_RANGE;
+ }
+ }
+
+ public Comparable getMinValue ()
+ {
+ return minValue;
+ }
+
+ public Comparable getMaxValue ()
+ {
+ return maxValue;
+ }
+ }
+
+ private class NodeObjectArray extends NodeObject
+ {
+ protected Integer arrayMinLength;
+ protected Integer arrayMaxLength;
+
+ public NodeObjectArray (Element owner,
+ Class classType,
+ int arrayMinLength,
+ int arrayMaxLength)
+ {
+ super (owner, classType, false, null);
+ this.arrayMinLength = new Integer (arrayMinLength);
+ this.arrayMaxLength = new Integer (arrayMaxLength);
+ valueType = IIOMetadataFormat.VALUE_LIST;
+ }
+
+ public Comparable getArrayMinLength ()
+ {
+ return arrayMinLength;
+ }
+
+ public Comparable getArrayMaxLength ()
+ {
+ return arrayMaxLength;
+ }
+ }
+
+ /**
+ * Construct a blank IIOMetadataFormatImpl with the given root name
+ * and child policy.
+ *
+ * @param rootName the root element name
+ * @param childPolicy the child policy of the root element
+ *
+ * @exception IllegalArgumentException if rootName is null
+ * @exception IllegalArgumentException if childPolicy is
+ * CHILD_POLICY_REPEAT or if childPolicy is not a CHILD_POLICY
+ * constant
+ */
+ public IIOMetadataFormatImpl (String rootName, int childPolicy)
+ {
+ if (rootName == null)
+ throw new IllegalArgumentException ("null argument");
+
+ if (childPolicy < IIOMetadataFormat.CHILD_POLICY_ALL
+ || childPolicy > IIOMetadataFormat.CHILD_POLICY_SOME
+ || childPolicy == IIOMetadataFormat.CHILD_POLICY_REPEAT)
+ throw new IllegalArgumentException ("wrong child policy");
+
+ nodes.put (rootName, new IIOMetadataNode (rootName));
+ childPolicies.put (rootName, new Integer (childPolicy));
+ this.rootName = rootName;
+ }
+
+ /**
+ * Construct a blank IIOMetadataFormatImpl with the given root name,
+ * a child policy of CHILD_POLICY_REPEAT and the given minimum and
+ * maximum limits on the number of root element children.
+ *
+ * @param rootName the root element name
+ * @param minChildren the minimum number of children that this node
+ * can have
+ * @param maxChildren the maximum number of children that this node
+ * can have
+ *
+ * @exception IllegalArgumentException if rootName is null
+ * @exception IllegalArgumentException if minChildren is less than
+ * zero or greater than maxChildren
+ */
+ public IIOMetadataFormatImpl (String rootName,
+ int minChildren,
+ int maxChildren)
+ {
+ if (rootName == null)
+ throw new IllegalArgumentException ("null argument");
+
+ if (minChildren < 0 || maxChildren < minChildren)
+ throw new IllegalArgumentException ("invalid min or max children argument");
+
+ nodes.put (rootName, new IIOMetadataNode (rootName));
+ childPolicies.put (rootName, new Integer (IIOMetadataFormat.CHILD_POLICY_REPEAT));
+ childRanges.put (rootName, new int [] { minChildren, maxChildren });
+ this.rootName = rootName;
+ }
+
+ protected void addAttribute (String elementName,
+ String attrName,
+ int dataType,
+ boolean required,
+ String defaultValue)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ node.setAttributeNode (new IIOMetadataNodeAttr (node,
+ attrName,
+ dataType,
+ required,
+ defaultValue));
+ }
+
+ protected void addAttribute (String elementName,
+ String attrName,
+ int dataType,
+ boolean required,
+ String defaultValue,
+ List<String> enumeratedValues)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ node.setAttributeNode (new IIOMetadataNodeAttrEnumerated (node,
+ attrName,
+ dataType,
+ required,
+ defaultValue,
+ enumeratedValues));
+ }
+
+ protected void addAttribute (String elementName,
+ String attrName,
+ int dataType,
+ boolean required,
+ String defaultValue,
+ String minValue,
+ String maxValue,
+ boolean minInclusive,
+ boolean maxInclusive)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ node.setAttributeNode (new IIOMetadataNodeAttrBounded (node,
+ attrName,
+ dataType,
+ required,
+ defaultValue,
+ minValue,
+ maxValue,
+ minInclusive,
+ maxInclusive));
+ }
+
+ protected void addAttribute (String elementName,
+ String attrName,
+ int dataType,
+ boolean required,
+ int listMinLength,
+ int listMaxLength)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ node.setAttributeNode (new IIOMetadataNodeAttrList (node,
+ attrName,
+ dataType,
+ required,
+ listMinLength,
+ listMaxLength));
+ }
+
+ protected void addBooleanAttribute (String elementName,
+ String attrName,
+ boolean hasDefaultValue,
+ boolean defaultValue)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+
+ List enumeratedValues = new ArrayList();
+ enumeratedValues.add ("TRUE");
+ enumeratedValues.add ("FALSE");
+
+ node.setAttributeNode (new IIOMetadataNodeAttrEnumerated (node,
+ attrName,
+ IIOMetadataFormat.DATATYPE_BOOLEAN,
+ hasDefaultValue,
+ defaultValue ? "TRUE" : "FALSE",
+ enumeratedValues));
+ }
+
+ protected void addChildElement (String elementName, String parentName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (parentName);
+
+ node.appendChild (new IIOMetadataNode (elementName));
+ childPolicies.put (elementName, new Integer (IIOMetadataFormat.CHILD_POLICY_REPEAT));
+ }
+
+ protected void addElement (String elementName, String parentName, int childPolicy)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (parentName);
+
+ node.appendChild (new IIOMetadataNode (elementName));
+ childPolicies.put (elementName, new Integer (childPolicy));
+ }
+
+ protected void addElement (String elementName, String parentName,
+ int minChildren, int maxChildren)
+ {
+ addChildElement (elementName, parentName);
+ childRanges.put (elementName, new int [] { minChildren, maxChildren });
+ }
+
+ private void addNodeObject (IIOMetadataNode node, NodeObject o)
+ {
+ node.setUserObject (o);
+ }
+
+ private NodeObject getNodeObject (IIOMetadataNode node)
+ {
+ return (NodeObject) node.getUserObject ();
+ }
+
+ private void removeNodeObject (IIOMetadataNode node)
+ {
+ node.setUserObject (null);
+ }
+
+ protected <T> void addObjectValue (String elementName, Class<T> classType,
+ boolean required, T defaultValue)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ addNodeObject (node, new NodeObject (node,
+ classType,
+ required,
+ defaultValue));
+ }
+
+ protected <T> void addObjectValue (String elementName, Class<T> classType,
+ boolean required, T defaultValue,
+ List<? extends T> enumeratedValues)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ addNodeObject (node, new NodeObjectEnumerated (node,
+ classType,
+ required,
+ defaultValue,
+ enumeratedValues));
+ }
+
+ protected <T extends Object & Comparable<? super T>>
+ void addObjectValue (String elementName, Class<T> classType,
+ T defaultValue,
+ Comparable<? super T> minValue,
+ Comparable<? super T> maxValue,
+ boolean minInclusive,
+ boolean maxInclusive)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ addNodeObject (node, new NodeObjectBounded (node,
+ classType,
+ defaultValue,
+ minValue,
+ maxValue,
+ minInclusive,
+ maxInclusive));
+ }
+
+ protected void addObjectValue (String elementName, Class<?> classType,
+ int arrayMinLength, int arrayMaxLength)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ addNodeObject (node, new NodeObjectArray (node,
+ classType,
+ arrayMinLength,
+ arrayMaxLength));
+ }
+
+ public String getRootName ()
+ {
+ return rootName;
+ }
+
+ protected String getResourceBaseName ()
+ {
+ return resourceBaseName;
+ }
+
+ public static IIOMetadataFormat getStandardFormatInstance ()
+ {
+ // FIXME: populate this with the standard metadata format
+ return new IIOMetadataFormatImpl (standardMetadataFormatName,
+ IIOMetadataFormat.CHILD_POLICY_ALL)
+ {
+ public boolean canNodeAppear (String elementName,
+ ImageTypeSpecifier specifier)
+ {
+ return true;
+ }
+ };
+ }
+
+ public abstract boolean canNodeAppear (String elementName,
+ ImageTypeSpecifier specifier);
+
+ protected void removeAttribute (String elementName,
+ String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ node.removeAttribute (attrName);
+ }
+
+ protected void removeElement (String elementName)
+ {
+ nodes.remove (elementName);
+ }
+
+ protected void removeObjectValue (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ removeNodeObject (node);
+ }
+
+ protected void setResourceBaseName (String resourceBaseName)
+ {
+ this.resourceBaseName = resourceBaseName;
+ }
+
+ public int getAttributeDataType (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
+ return attr.getDataType ();
+ }
+
+ public String getAttributeDefaultValue (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
+ return attr.getValue();
+ }
+
+ public String getAttributeDescription (String elementName, String attrName, Locale locale)
+ {
+ return getDescription (elementName + "/" + attrName, locale);
+ }
+
+ public String[] getAttributeEnumerations (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttrEnumerated attr =
+ (IIOMetadataNodeAttrEnumerated) node.getAttributeNode (attrName);
+
+ Object[] attrEnums = attr.getEnumerations();
+
+ String[] attrNames = new String[attrEnums.length];
+
+ for (int i = 0; i < attrEnums.length; i++)
+ {
+ attrNames[i] = (String) attrEnums[i];
+ }
+
+ return attrNames;
+ }
+
+ public int getAttributeListMaxLength (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttrList attr =
+ (IIOMetadataNodeAttrList) node.getAttributeNode (attrName);
+ return attr.getListMaxLength();
+ }
+
+ public int getAttributeListMinLength (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttrList attr =
+ (IIOMetadataNodeAttrList) node.getAttributeNode (attrName);
+ return attr.getListMinLength();
+ }
+
+ public String getAttributeMaxValue (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttrBounded attr =
+ (IIOMetadataNodeAttrBounded) node.getAttributeNode (attrName);
+ return attr.getMaxValue();
+ }
+
+ public String getAttributeMinValue (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttrBounded attr =
+ (IIOMetadataNodeAttrBounded) node.getAttributeNode (attrName);
+ return attr.getMinValue();
+ }
+
+ public String[] getAttributeNames (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+
+ NamedNodeMap attrNodes = node.getAttributes();
+
+ String[] attrNames = new String[attrNodes.getLength()];
+
+ for (int i = 0; i < attrNodes.getLength(); i++)
+ {
+ attrNames[i] = attrNodes.item (i).getLocalName();
+ }
+
+ return attrNames;
+ }
+
+ public int getAttributeValueType (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
+ return attr.getDataType();
+ }
+
+ public String[] getChildNames (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+
+ NodeList childNodes = node.getChildNodes();
+
+ String[] childNames = new String[childNodes.getLength()];
+
+ for (int i = 0; i < childNodes.getLength(); i++)
+ {
+ childNames[i] = childNodes.item (i).getLocalName();
+ }
+
+ return childNames;
+ }
+
+ public int getChildPolicy (String elementName)
+ {
+ return ((Integer) childPolicies.get (elementName)).intValue();
+ }
+
+ private String getDescription (String resourceName, Locale locale)
+ {
+ if (resourceBaseName == null)
+ return null;
+
+ Locale l = locale;
+
+ if (l == null)
+ l = Locale.getDefault();
+
+ ResourceBundle bundle = ResourceBundle.getBundle (resourceBaseName, locale);
+
+ String desc = null;
+
+ if (bundle == null)
+ {
+ try
+ {
+ desc = bundle.getString (resourceName);
+ }
+ catch (MissingResourceException e)
+ {
+ desc = null;
+ }
+ }
+
+ return desc;
+ }
+
+ public String getElementDescription (String elementName, Locale locale)
+ {
+ return getDescription (elementName, locale);
+ }
+
+ public int getElementMaxChildren (String elementName)
+ {
+ return ((int[]) childRanges.get (elementName))[1];
+ }
+
+ public int getElementMinChildren (String elementName)
+ {
+ return ((int[]) childRanges.get (elementName))[0];
+ }
+
+ public int getObjectArrayMaxLength (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return ((Integer) ((NodeObjectArray) getNodeObject (node)).getArrayMaxLength ()).intValue();
+ }
+
+ public int getObjectArrayMinLength (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return ((Integer) ((NodeObjectArray) getNodeObject (node)).getArrayMinLength ()).intValue();
+ }
+
+ public Class<?> getObjectClass (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return getNodeObject (node).getClassType ();
+ }
+
+ public Object getObjectDefaultValue (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return getNodeObject (node).getDefaultValue ();
+ }
+
+ public Object[] getObjectEnumerations (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return ((NodeObjectEnumerated) getNodeObject (node)).getEnumerations ();
+ }
+
+ public Comparable<?> getObjectMaxValue (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return ((NodeObjectBounded) getNodeObject (node)).getMaxValue ();
+ }
+
+ public Comparable<?> getObjectMinValue (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return ((NodeObjectBounded) getNodeObject (node)).getMinValue ();
+ }
+
+ public int getObjectValueType (String elementName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ NodeObject n = getNodeObject (node);
+
+ if (n == null)
+ return IIOMetadataFormat.VALUE_NONE;
+ else
+ return n.getValueType ();
+ }
+
+ public boolean isAttributeRequired (String elementName, String attrName)
+ {
+ IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
+ return ((IIOMetadataNodeAttr) node.getAttributeNode (attrName)).isRequired();
+ }
+}
diff --git a/libjava/classpath/javax/imageio/metadata/IIOMetadataNode.java b/libjava/classpath/javax/imageio/metadata/IIOMetadataNode.java
new file mode 100644
index 000000000..db3de2347
--- /dev/null
+++ b/libjava/classpath/javax/imageio/metadata/IIOMetadataNode.java
@@ -0,0 +1,709 @@
+/* IIOMetadataNode.java --
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.imageio.metadata;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.TypeInfo;
+import org.w3c.dom.UserDataHandler;
+import javax.imageio.metadata.IIOMetadataFormatImpl.IIOMetadataNodeAttr;
+
+public class IIOMetadataNode
+ implements Element, NodeList
+{
+ private String name;
+ private HashMap attrs = new HashMap();
+ private List children = new ArrayList();
+ private IIOMetadataNode parent;
+ private Object obj;
+
+ /**
+ * Simple NamedNodeMap class for IIOMetadataNode.
+ *
+ * @author jlquinn
+ */
+ private class IIONamedNodeMap implements NamedNodeMap
+ {
+ HashMap attrs;
+
+ /**
+ * @param attrs
+ * @param node
+ */
+ public IIONamedNodeMap(HashMap attrs)
+ {
+ this.attrs = attrs;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#getNamedItem(java.lang.String)
+ */
+ public Node getNamedItem(String name)
+ {
+ return (Node)attrs.get(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#setNamedItem(org.w3c.dom.Node)
+ */
+ public Node setNamedItem(Node arg) throws DOMException
+ {
+ if (arg instanceof IIOMetadataNodeAttr)
+ {
+ IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) arg;
+ // The only code that can successfully do this is in this package.
+ if (attr.owner != null)
+ throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, "");
+ return (Node)attrs.put(attr.name, attr);
+ }
+ // Anything else gets treated as an invalid op.
+ throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "");
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#removeNamedItem(java.lang.String)
+ */
+ public Node removeNamedItem(String name) throws DOMException
+ {
+ return (Node)attrs.remove(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#item(int)
+ */
+ public Node item(int index)
+ {
+ return (Node)attrs.values().toArray()[index];
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#getLength()
+ */
+ public int getLength()
+ {
+ return attrs.size();
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#getNamedItemNS(java.lang.String, java.lang.String)
+ */
+ public Node getNamedItemNS(String namespaceURI, String localName)
+ {
+ return getNamedItem(localName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#setNamedItemNS(org.w3c.dom.Node)
+ */
+ public Node setNamedItemNS(Node arg) throws DOMException
+ {
+ return setNamedItem(arg);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NamedNodeMap#removeNamedItemNS(java.lang.String, java.lang.String)
+ */
+ public Node removeNamedItemNS(String namespaceURI, String localName)
+ throws DOMException
+ {
+ return removeNamedItem(localName);
+ }
+ }
+
+ /**
+ * Simple NodeList implementation for IIOMetadataNode.
+ *
+ * @author jlquinn
+ *
+ */
+ private class IIONodeList implements NodeList
+ {
+ List children = new ArrayList();
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NodeList#item(int)
+ */
+ public Node item(int index)
+ {
+ return (index < children.size()) ? (Node)children.get(index) : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NodeList#getLength()
+ */
+ public int getLength()
+ {
+ return children.size();
+ }
+ }
+
+ public IIOMetadataNode()
+ {
+ // Do nothing here.
+ }
+
+ public IIOMetadataNode(String nodename)
+ {
+ name = nodename;
+ }
+
+ public Object getUserObject()
+ {
+ return obj;
+ }
+
+ public void setUserObject(Object o)
+ {
+ obj = o;
+ }
+
+ public short compareDocumentPosition(Node other)
+ throws DOMException
+ {
+ return Element.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#getAttribute(java.lang.String)
+ */
+ public String getAttribute(String name)
+ {
+ Attr anode = (Attr) attrs.get(name);
+ return anode != null ? anode.getValue() : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#getAttributeNode(java.lang.String)
+ */
+ public Attr getAttributeNode(String name)
+ {
+ String val = getAttribute(name);
+ if (val != null)
+ return new IIOMetadataNodeAttr(this, name, val);
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String)
+ */
+ public Attr getAttributeNodeNS(String namespaceURI, String localName)
+ {
+ return getAttributeNode(localName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String)
+ */
+ public String getAttributeNS(String namespaceURI, String localName)
+ {
+ return getAttribute(localName);
+ }
+
+ public String getBaseURI()
+ {
+ return null;
+ }
+
+ // Recursive function for assembling a node list.
+ private void getElementsRecurse(IIONodeList list, String name)
+ {
+ for (int i=0; i < children.size(); i++)
+ {
+ if (((Node)children.get(i)).getNodeName().equals(name))
+ list.children.add(children.get(i));
+ getElementsRecurse(list, name);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String)
+ */
+ public NodeList getElementsByTagName(String name)
+ {
+ IIONodeList list = new IIONodeList();
+ getElementsRecurse(list, name);
+ return list;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#getElementsByTagNameNS(java.lang.String, java.lang.String)
+ */
+ public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
+ {
+ IIONodeList list = new IIONodeList();
+ getElementsRecurse(list, name);
+ return list;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#getTagName()
+ */
+ public String getTagName()
+ {
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#hasAttribute(java.lang.String)
+ */
+ public boolean hasAttribute(String name)
+ {
+ return attrs.containsKey(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#hasAttributeNS(java.lang.String, java.lang.String)
+ */
+ public boolean hasAttributeNS(String namespaceURI, String localName)
+ {
+ return attrs.containsKey(localName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#removeAttribute(java.lang.String)
+ */
+ public void removeAttribute(String name)
+ {
+ attrs.remove(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr)
+ */
+ public Attr removeAttributeNode(Attr oldAttr)
+ {
+ return (Attr)attrs.remove(oldAttr.getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String, java.lang.String)
+ */
+ public void removeAttributeNS(String namespaceURI, String localName)
+ {
+ removeAttribute(localName);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String)
+ */
+ public void setAttribute(String name, String value)
+ {
+ Attr attr = getAttributeNode(name);
+ if (attr != null)
+ attr.setValue(value);
+ else
+ attrs.put(name, new IIOMetadataNodeAttr(this, name, value));
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr)
+ */
+ public Attr setAttributeNode(Attr newAttr)
+ {
+ return (Attr)attrs.put(newAttr.getName(), newAttr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr)
+ */
+ public Attr setAttributeNodeNS(Attr newAttr)
+ {
+ return (Attr)attrs.put(newAttr.getName(), newAttr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Element#setAttributeNS(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void setAttributeNS(String namespaceURI, String qualifiedName, String value)
+ {
+ setAttribute(qualifiedName, value);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NodeList#getLength()
+ */
+ public int getLength()
+ {
+ return children.size();
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.NodeList#item(int)
+ */
+ public Node item(int index)
+ {
+ if (index < children.size())
+ return (Node)children.get(index);
+ else
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
+ */
+ public Node appendChild(Node newChild)
+ {
+ if (newChild == null)
+ throw new IllegalArgumentException("Child node is null");
+
+ IIOMetadataNode child = (IIOMetadataNode) newChild;
+
+ children.add(child);
+ child.parent = this;
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#cloneNode(boolean)
+ */
+ public Node cloneNode(boolean deep)
+ {
+ IIOMetadataNode newnode = new IIOMetadataNode(name);
+ newnode.parent = null;
+ newnode.obj = obj;
+ if (deep)
+ {
+ for (int i=0; i < children.size(); i++)
+ newnode.children.add(((Node)children.get(i)).cloneNode(deep));
+ }
+
+ // clone attrs
+ for (Iterator it = attrs.values().iterator(); it.hasNext();)
+ {
+ IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr)it.next();
+ newnode.attrs.put(attr.name, attr.cloneNode(deep));
+ attr.owner = newnode;
+ }
+
+ return newnode;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getAttributes()
+ */
+ public NamedNodeMap getAttributes()
+ {
+ return new IIONamedNodeMap(attrs);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getChildNodes()
+ */
+ public NodeList getChildNodes()
+ {
+ return this;
+ }
+
+ public Object getFeature(String feature, String version)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getFirstChild()
+ */
+ public Node getFirstChild()
+ {
+ return (children.size() > 0) ? (Node)children.get(0) : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getLastChild()
+ */
+ public Node getLastChild()
+ {
+ return (children.size() > 0) ? (Node)children.get(children.size() - 1)
+ : null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getLocalName()
+ */
+ public String getLocalName()
+ {
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getNamespaceURI()
+ */
+ public String getNamespaceURI()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getNextSibling()
+ */
+ public Node getNextSibling()
+ {
+ // If this op needs to be faster, add links to prev and next nodes.
+ if (parent == null) return null;
+ int idx = parent.children.indexOf(this);
+ return (idx == parent.children.size() - 1) ? null
+ : (Node)parent.children.get(idx + 1);
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getNodeName()
+ */
+ public String getNodeName()
+ {
+ return name;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getNodeType()
+ */
+ public short getNodeType()
+ {
+ return ELEMENT_NODE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getNodeValue()
+ */
+ public String getNodeValue()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getOwnerDocument()
+ */
+ public Document getOwnerDocument()
+ {
+ // IOMetadataNodes have no owner
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getParentNode()
+ */
+ public Node getParentNode()
+ {
+ return parent;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getPrefix()
+ */
+ public String getPrefix()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#getPreviousSibling()
+ */
+ public Node getPreviousSibling()
+ {
+ // If this op needs to be faster, add links to prev and next nodes.
+ if (parent == null) return null;
+ int idx = parent.children.indexOf(this);
+ return (idx == 0) ? null
+ : (Node)parent.children.get(idx - 1);
+ }
+
+ public TypeInfo getSchemaTypeInfo()
+ {
+ return null;
+ }
+
+ public String getTextContent()
+ throws DOMException
+ {
+ return null;
+ }
+
+ public Object getUserData(String key)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#hasAttributes()
+ */
+ public boolean hasAttributes()
+ {
+ return !attrs.isEmpty();
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#hasChildNodes()
+ */
+ public boolean hasChildNodes()
+ {
+ return !children.isEmpty();
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)
+ */
+ public Node insertBefore(Node newChild, Node refChild)
+ {
+ if (newChild == null)
+ throw new IllegalArgumentException();
+
+ int idx = children.indexOf(refChild);
+ if (idx == -1)
+ children.add(newChild);
+ else
+ children.add(idx, newChild);
+ ((IIOMetadataNode)newChild).parent = this;
+
+ return newChild;
+ }
+
+ public boolean isDefaultNamespace(String namespaceURI)
+ {
+ return true;
+ }
+
+ public boolean isEqualNode(Node arg)
+ {
+ return true;
+ }
+
+ public boolean isSameNode(Node other)
+ {
+ return this == other;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#isSupported(java.lang.String, java.lang.String)
+ */
+ public boolean isSupported(String feature, String version)
+ {
+ // No DOM features are supported
+ return false;
+ }
+
+ public String lookupNamespaceURI(String prefix)
+ {
+ return null;
+ }
+
+ public String lookupPrefix(String namespaceURI)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#normalize()
+ */
+ public void normalize()
+ {
+ // No text nodes so no action
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node)
+ */
+ public Node removeChild(Node oldChild)
+ {
+ if (oldChild == null)
+ throw new IllegalArgumentException();
+ children.remove(oldChild);
+ ((IIOMetadataNode)oldChild).parent = null;
+
+ return oldChild;
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
+ */
+ public Node replaceChild(Node newChild, Node oldChild)
+ {
+ if (newChild == null)
+ throw new IllegalArgumentException();
+ children.set(children.indexOf(oldChild), newChild);
+ ((IIOMetadataNode)oldChild).parent = null;
+ return oldChild;
+ }
+
+ public void setIdAttribute(String name, boolean isId)
+ throws DOMException
+ {
+ }
+
+ public void setIdAttributeNode(Attr idAttr, boolean isId)
+ throws DOMException
+ {
+ }
+
+ public void setIdAttributeNS(String namespaceURI, String localName, boolean isId)
+ throws DOMException
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#setNodeValue(java.lang.String)
+ */
+ public void setNodeValue(String nodeValue) throws DOMException
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.w3c.dom.Node#setPrefix(java.lang.String)
+ */
+ public void setPrefix(String prefix)
+ {
+ }
+
+ public void setTextContent(String textContent)
+ throws DOMException
+ {
+ }
+
+ public Object setUserData(String key, Object data, UserDataHandler handler)
+ {
+ return null;
+ }
+}
diff --git a/libjava/classpath/javax/imageio/metadata/package.html b/libjava/classpath/javax/imageio/metadata/package.html
new file mode 100644
index 000000000..5bd77c2a5
--- /dev/null
+++ b/libjava/classpath/javax/imageio/metadata/package.html
@@ -0,0 +1,46 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<!-- package.html - describes classes in javax.imageio.metadata package.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. -->
+
+<html>
+<head><title>GNU Classpath - javax.imageio.metadata</title></head>
+
+<body>
+<p></p>
+
+</body>
+</html>