- All Implemented Interfaces:
IIOMetadataFormat
public abstract class IIOMetadataFormatImpl extends Object implements IIOMetadataFormat
IIOMetadataFormat interface. In addition, a static
instance representing the standard, plug-in neutral
javax_imageio_1.0 format is provided by the
getStandardFormatInstance method.
In order to supply localized descriptions of elements and
attributes, a ResourceBundle with a base name of
this.getClass().getName() + "Resources" should be
supplied via the usual mechanism used by
ResourceBundle.getBundle. Briefly, the subclasser
supplies one or more additional classes according to a naming
convention (by default, the fully-qualified name of the subclass
extending IIMetadataFormatImpl, plus the string
"Resources", plus the country, language, and variant codes
separated by underscores). At run time, calls to
getElementDescription or
getAttributeDescription will attempt to load such
classes dynamically according to the supplied locale, and will use
either the element name, or the element name followed by a '/'
character followed by the attribute name as a key. This key will
be supplied to the ResourceBundle's
getString method, and the resulting localized
description of the node or attribute is returned.
The subclass may supply a different base name for the resource
bundles using the setResourceBaseName method.
A subclass may choose its own localization mechanism, if so
desired, by overriding the supplied implementations of
getElementDescription and
getAttributeDescription.
- See Also:
ResourceBundle.getBundle(String,Locale)
-
Field Summary
Fields Modifier and Type Field Description static StringstandardMetadataFormatNameAStringconstant containing the standard format name,"javax_imageio_1.0".Fields declared in interface javax.imageio.metadata.IIOMetadataFormat
CHILD_POLICY_ALL, CHILD_POLICY_CHOICE, CHILD_POLICY_EMPTY, CHILD_POLICY_MAX, CHILD_POLICY_REPEAT, CHILD_POLICY_SEQUENCE, CHILD_POLICY_SOME, DATATYPE_BOOLEAN, DATATYPE_DOUBLE, DATATYPE_FLOAT, DATATYPE_INTEGER, DATATYPE_STRING, VALUE_ARBITRARY, VALUE_ENUMERATION, VALUE_LIST, VALUE_NONE, VALUE_RANGE, VALUE_RANGE_MAX_INCLUSIVE, VALUE_RANGE_MAX_INCLUSIVE_MASK, VALUE_RANGE_MIN_INCLUSIVE, VALUE_RANGE_MIN_INCLUSIVE_MASK, VALUE_RANGE_MIN_MAX_INCLUSIVE -
Constructor Summary
Constructors Constructor Description IIOMetadataFormatImpl(String rootName, int childPolicy)Constructs a blankIIOMetadataFormatImplinstance, with a given root element name and child policy (other thanCHILD_POLICY_REPEAT).IIOMetadataFormatImpl(String rootName, int minChildren, int maxChildren)Constructs a blankIIOMetadataFormatImplinstance, with a given root element name and a child policy ofCHILD_POLICY_REPEAT. -
Method Summary
Modifier and Type Method Description protected voidaddAttribute(String elementName, String attrName, int dataType, boolean required, int listMinLength, int listMaxLength)Adds a new attribute to a previously defined element that will be defined by a list of values.protected voidaddAttribute(String elementName, String attrName, int dataType, boolean required, String defaultValue)Adds a new attribute to a previously defined element that may be set to an arbitrary value.protected voidaddAttribute(String elementName, String attrName, int dataType, boolean required, String defaultValue, String minValue, String maxValue, boolean minInclusive, boolean maxInclusive)Adds a new attribute to a previously defined element that will be defined by a range of values.protected voidaddAttribute(String elementName, String attrName, int dataType, boolean required, String defaultValue, List<String> enumeratedValues)Adds a new attribute to a previously defined element that will be defined by a set of enumerated values.protected voidaddBooleanAttribute(String elementName, String attrName, boolean hasDefaultValue, boolean defaultValue)Adds a new attribute to a previously defined element that will be defined by the enumerated valuesTRUEandFALSE, with a datatype ofDATATYPE_BOOLEAN.protected voidaddChildElement(String elementName, String parentName)Adds an existing element to the list of legal children for a given parent node type.protected voidaddElement(String elementName, String parentName, int childPolicy)Adds a new element type to this metadata document format with a child policy other thanCHILD_POLICY_REPEAT.protected voidaddElement(String elementName, String parentName, int minChildren, int maxChildren)Adds a new element type to this metadata document format with a child policy ofCHILD_POLICY_REPEAT.protected voidaddObjectValue(String elementName, Class<?> classType, int arrayMinLength, int arrayMaxLength)Allows anObjectreference of a given class type to be stored in nodes implementing the named element.protected <T> voidaddObjectValue(String elementName, Class<T> classType, boolean required, T defaultValue)Allows anObjectreference of a given class type to be stored in nodes implementing the named element.protected <T> voidaddObjectValue(String elementName, Class<T> classType, boolean required, T defaultValue, List<? extends T> enumeratedValues)Allows anObjectreference of a given class type to be stored in nodes implementing the named element.protected <T extends Object & Comparable<? super T>>
voidaddObjectValue(String elementName, Class<T> classType, T defaultValue, Comparable<? super T> minValue, Comparable<? super T> maxValue, boolean minInclusive, boolean maxInclusive)Allows anObjectreference of a given class type to be stored in nodes implementing the named element.StringgetAttributeDescription(String elementName, String attrName, Locale locale)Returns aStringcontaining a description of the named attribute, ornull.StringgetElementDescription(String elementName, Locale locale)Returns aStringcontaining a description of the named element, ornull.protected StringgetResourceBaseName()Returns the currently set base name for locatingResourceBundles.static IIOMetadataFormatgetStandardFormatInstance()Returns anIIOMetadataFormatobject describing the standard, plug-in neutraljavax.imageio_1.0metadata document format described in the comment of thejavax.imageio.metadatapackage.protected voidremoveAttribute(String elementName, String attrName)Removes an attribute from a previously defined element.protected voidremoveElement(String elementName)Removes an element from the format.protected voidremoveObjectValue(String elementName)Disallows anObjectreference from being stored in nodes implementing the named element.protected voidsetResourceBaseName(String resourceBaseName)Sets a new base name for locatingResourceBundles containing descriptions of elements and attributes for this format.Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface javax.imageio.metadata.IIOMetadataFormat
canNodeAppear, getAttributeDataType, getAttributeDefaultValue, getAttributeEnumerations, getAttributeListMaxLength, getAttributeListMinLength, getAttributeMaxValue, getAttributeMinValue, getAttributeNames, getAttributeValueType, getChildNames, getChildPolicy, getElementMaxChildren, getElementMinChildren, getObjectArrayMaxLength, getObjectArrayMinLength, getObjectClass, getObjectDefaultValue, getObjectEnumerations, getObjectMaxValue, getObjectMinValue, getObjectValueType, getRootName, isAttributeRequired
-
Field Details
-
standardMetadataFormatName
AStringconstant containing the standard format name,"javax_imageio_1.0".- See Also:
- Constant Field Values
-
-
Constructor Details
-
IIOMetadataFormatImpl
Constructs a blankIIOMetadataFormatImplinstance, with a given root element name and child policy (other thanCHILD_POLICY_REPEAT). Additional elements, and their attributes andObjectreference information may be added using the variousaddmethods.- Parameters:
rootName- the name of the root element.childPolicy- one of theCHILD_POLICY_*constants, other thanCHILD_POLICY_REPEAT.- Throws:
IllegalArgumentException- ifrootNameisnull.IllegalArgumentException- ifchildPolicyis not one of the predefined constants.
-
IIOMetadataFormatImpl
Constructs a blankIIOMetadataFormatImplinstance, with a given root element name and a child policy ofCHILD_POLICY_REPEAT. Additional elements, and their attributes andObjectreference information may be added using the variousaddmethods.- Parameters:
rootName- the name of the root element.minChildren- the minimum number of children of the node.maxChildren- the maximum number of children of the node.- Throws:
IllegalArgumentException- ifrootNameisnull.IllegalArgumentException- ifminChildrenis negative or larger thanmaxChildren.
-
-
Method Details
-
setResourceBaseName
Sets a new base name for locatingResourceBundles containing descriptions of elements and attributes for this format.Prior to the first time this method is called, the base name will be equal to
this.getClass().getName() + "Resources".- Parameters:
resourceBaseName- aStringcontaining the new base name.- Throws:
IllegalArgumentException- ifresourceBaseNameisnull.- See Also:
getResourceBaseName()
-
getResourceBaseName
Returns the currently set base name for locatingResourceBundles.- Returns:
- a
Stringcontaining the base name. - See Also:
setResourceBaseName(java.lang.String)
-
addElement
Adds a new element type to this metadata document format with a child policy other thanCHILD_POLICY_REPEAT.- Parameters:
elementName- the name of the new element.parentName- the name of the element that will be the parent of the new element.childPolicy- one of theCHILD_POLICY_*constants, other thanCHILD_POLICY_REPEAT, indicating the child policy of the new element.- Throws:
IllegalArgumentException- ifparentNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifchildPolicyis not one of the predefined constants.
-
addElement
Adds a new element type to this metadata document format with a child policy ofCHILD_POLICY_REPEAT.- Parameters:
elementName- the name of the new element.parentName- the name of the element that will be the parent of the new element.minChildren- the minimum number of children of the node.maxChildren- the maximum number of children of the node.- Throws:
IllegalArgumentException- ifparentNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifminChildrenis negative or larger thanmaxChildren.
-
addChildElement
Adds an existing element to the list of legal children for a given parent node type.- Parameters:
parentName- the name of the element that will be the new parent of the element.elementName- the name of the element to be added as a child.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifparentNameisnull, or is not a legal element name for this format.
-
removeElement
Removes an element from the format. If no element with the given name was present, nothing happens and no exception is thrown.- Parameters:
elementName- the name of the element to be removed.
-
addAttribute
protected void addAttribute(String elementName, String attrName, int dataType, boolean required, String defaultValue)Adds a new attribute to a previously defined element that may be set to an arbitrary value.- Parameters:
elementName- the name of the element.attrName- the name of the attribute being added.dataType- the data type (string format) of the attribute, one of theDATATYPE_*constants.required-trueif the attribute must be present.defaultValue- the default value for the attribute, ornull.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifattrNameisnull.IllegalArgumentException- ifdataTypeis not one of the predefined constants.
-
addAttribute
protected void addAttribute(String elementName, String attrName, int dataType, boolean required, String defaultValue, List<String> enumeratedValues)Adds a new attribute to a previously defined element that will be defined by a set of enumerated values.- Parameters:
elementName- the name of the element.attrName- the name of the attribute being added.dataType- the data type (string format) of the attribute, one of theDATATYPE_*constants.required-trueif the attribute must be present.defaultValue- the default value for the attribute, ornull.enumeratedValues- aListofStrings containing the legal values for the attribute.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifattrNameisnull.IllegalArgumentException- ifdataTypeis not one of the predefined constants.IllegalArgumentException- ifenumeratedValuesisnull.IllegalArgumentException- ifenumeratedValuesdoes not contain at least one entry.IllegalArgumentException- ifenumeratedValuescontains an element that is not aStringor isnull.
-
addAttribute
protected void addAttribute(String elementName, String attrName, int dataType, boolean required, String defaultValue, String minValue, String maxValue, boolean minInclusive, boolean maxInclusive)Adds a new attribute to a previously defined element that will be defined by a range of values.- Parameters:
elementName- the name of the element.attrName- the name of the attribute being added.dataType- the data type (string format) of the attribute, one of theDATATYPE_*constants.required-trueif the attribute must be present.defaultValue- the default value for the attribute, ornull.minValue- the smallest (inclusive or exclusive depending on the value ofminInclusive) legal value for the attribute, as aString.maxValue- the largest (inclusive or exclusive depending on the value ofminInclusive) legal value for the attribute, as aString.minInclusive-trueifminValueis inclusive.maxInclusive-trueifmaxValueis inclusive.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifattrNameisnull.IllegalArgumentException- ifdataTypeis not one of the predefined constants.
-
addAttribute
protected void addAttribute(String elementName, String attrName, int dataType, boolean required, int listMinLength, int listMaxLength)Adds a new attribute to a previously defined element that will be defined by a list of values.- Parameters:
elementName- the name of the element.attrName- the name of the attribute being added.dataType- the data type (string format) of the attribute, one of theDATATYPE_*constants.required-trueif the attribute must be present.listMinLength- the smallest legal number of list items.listMaxLength- the largest legal number of list items.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifattrNameisnull.IllegalArgumentException- ifdataTypeis not one of the predefined constants.IllegalArgumentException- iflistMinLengthis negative or larger thanlistMaxLength.
-
addBooleanAttribute
protected void addBooleanAttribute(String elementName, String attrName, boolean hasDefaultValue, boolean defaultValue)Adds a new attribute to a previously defined element that will be defined by the enumerated valuesTRUEandFALSE, with a datatype ofDATATYPE_BOOLEAN.- Parameters:
elementName- the name of the element.attrName- the name of the attribute being added.hasDefaultValue-trueif a default value should be present.defaultValue- the default value for the attribute as aboolean, ignored ifhasDefaultValueisfalse.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifattrNameisnull.
-
removeAttribute
Removes an attribute from a previously defined element. If no attribute with the given name was present in the given element, nothing happens and no exception is thrown.- Parameters:
elementName- the name of the element.attrName- the name of the attribute being removed.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.
-
addObjectValue
protected <T> void addObjectValue(String elementName, Class<T> classType, boolean required, T defaultValue)Allows anObjectreference of a given class type to be stored in nodes implementing the named element. The value of theObjectis unconstrained other than by its class type.If an
Objectreference was previously allowed, the previous settings are overwritten.- Type Parameters:
T- the type of the object.- Parameters:
elementName- the name of the element.classType- aClassvariable indicating the legal class type for the object value.required-trueif an object value must be present.defaultValue- the default value for theObjectreference, ornull.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.
-
addObjectValue
protected <T> void addObjectValue(String elementName, Class<T> classType, boolean required, T defaultValue, List<? extends T> enumeratedValues)Allows anObjectreference of a given class type to be stored in nodes implementing the named element. The value of theObjectmust be one of the values given byenumeratedValues.If an
Objectreference was previously allowed, the previous settings are overwritten.- Type Parameters:
T- the type of the object.- Parameters:
elementName- the name of the element.classType- aClassvariable indicating the legal class type for the object value.required-trueif an object value must be present.defaultValue- the default value for theObjectreference, ornull.enumeratedValues- aListofObjects containing the legal values for the object reference.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifenumeratedValuesisnull.IllegalArgumentException- ifenumeratedValuesdoes not contain at least one entry.IllegalArgumentException- ifenumeratedValuescontains an element that is not an instance of the class type denoted byclassTypeor isnull.
-
addObjectValue
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)Allows anObjectreference of a given class type to be stored in nodes implementing the named element. The value of theObjectmust be within the range given byminValueandmaxValue. Furthermore, the class type must implement theComparableinterface.If an
Objectreference was previously allowed, the previous settings are overwritten.- Type Parameters:
T- the type of the object.- Parameters:
elementName- the name of the element.classType- aClassvariable indicating the legal class type for the object value.defaultValue- the default value for theminValue- the smallest (inclusive or exclusive depending on the value ofminInclusive) legal value for the object value, as aString.maxValue- the largest (inclusive or exclusive depending on the value ofminInclusive) legal value for the object value, as aString.minInclusive-trueifminValueis inclusive.maxInclusive-trueifmaxValueis inclusive.- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.
-
addObjectValue
protected void addObjectValue(String elementName, Class<?> classType, int arrayMinLength, int arrayMaxLength)Allows anObjectreference of a given class type to be stored in nodes implementing the named element. The value of theObjectmust an array of objects of class type given byclassType, with at leastarrayMinLengthand at mostarrayMaxLengthelements.If an
Objectreference was previously allowed, the previous settings are overwritten.- Parameters:
elementName- the name of the element.classType- aClassvariable indicating the legal class type for the object value.arrayMinLength- the smallest legal length for the array.arrayMaxLength- the largest legal length for the array.- Throws:
IllegalArgumentException- ifelementNameis not a legal element name for this format.
-
removeObjectValue
Disallows anObjectreference from being stored in nodes implementing the named element.- Parameters:
elementName- the name of the element.- Throws:
IllegalArgumentException- ifelementNameis not a legal element name for this format.
-
getElementDescription
Returns aStringcontaining a description of the named element, ornull. The description will be localized for the suppliedLocaleif possible.The default implementation will first locate a
ResourceBundleusing the current resource base name set bysetResourceBaseNameand the suppliedLocale, using the fallback mechanism described in the comments forResourceBundle.getBundle. If aResourceBundleis found, the element name will be used as a key to itsgetStringmethod, and the result returned. If noResourceBundleis found, or no such key is present,nullwill be returned.If
localeisnull, the current defaultLocalereturned byLocale.getLocalewill be used.- Specified by:
getElementDescriptionin interfaceIIOMetadataFormat- Parameters:
elementName- the name of the element.locale- theLocalefor which localization will be attempted.- Returns:
- the element description.
- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.- See Also:
setResourceBaseName(java.lang.String)
-
getAttributeDescription
Returns aStringcontaining a description of the named attribute, ornull. The description will be localized for the suppliedLocaleif possible.The default implementation will first locate a
ResourceBundleusing the current resource base name set bysetResourceBaseNameand the suppliedLocale, using the fallback mechanism described in the comments forResourceBundle.getBundle. If aResourceBundleis found, the element name followed by a "/" character followed by the attribute name (elementName + "/" + attrName) will be used as a key to itsgetStringmethod, and the result returned. If noResourceBundleis found, or no such key is present,nullwill be returned.If
localeisnull, the current defaultLocalereturned byLocale.getLocalewill be used.- Specified by:
getAttributeDescriptionin interfaceIIOMetadataFormat- Parameters:
elementName- the name of the element.attrName- the name of the attribute.locale- theLocalefor which localization will be attempted, ornull.- Returns:
- the attribute description.
- Throws:
IllegalArgumentException- ifelementNameisnull, or is not a legal element name for this format.IllegalArgumentException- ifattrNameisnullor is not a legal attribute name for this element.- See Also:
setResourceBaseName(java.lang.String)
-
getStandardFormatInstance
Returns anIIOMetadataFormatobject describing the standard, plug-in neutraljavax.imageio_1.0metadata document format described in the comment of thejavax.imageio.metadatapackage.- Returns:
- a predefined
IIOMetadataFormatinstance.
-