FileDocCategorySizeDatePackage
IIOMetadataFormatImpl.javaAPI DocAndroid 1.5 API34152Wed May 06 22:41:54 BST 2009javax.imageio.metadata

IIOMetadataFormatImpl

public abstract class IIOMetadataFormatImpl extends Object implements IIOMetadataFormat
The IIOMetadataFormatImpl class provides an implementation of the IIOMetadataFormat interface.
since
Android 1.0

Fields Summary
public static final String
standardMetadataFormatName
The Constant standardMetadataFormatName.
private static IIOMetadataFormatImpl
standardFormat
The standard format.
private String
rootName
The root name.
private HashMap
elementHash
The element hash.
private String
resourceBaseName
The resource base name.
Constructors Summary
public IIOMetadataFormatImpl(String rootName, int childPolicy)
Instantiates an IIOMetadataFormatImpl with the specified root name and child policy (not CHILD_POLICY_REPEAT).

param
rootName the name of root element.
param
childPolicy the child policy defined by one of the CHILD_POLICY_* constants (except CHILD_POLICY_REPEAT).


                                                                             
         
        if (rootName == null) {
            throw new IllegalArgumentException("rootName is null");
        }
        if (childPolicy < CHILD_POLICY_EMPTY || childPolicy > CHILD_POLICY_MAX
                || childPolicy == CHILD_POLICY_REPEAT) {
            throw new IllegalArgumentException("childPolicy is not one of the predefined constants");
        }

        this.rootName = rootName;
        Element root = new Element();
        root.name = rootName;
        root.childPolicy = childPolicy;
        elementHash.put(rootName, root);
    
public IIOMetadataFormatImpl(String rootName, int minChildren, int maxChildren)
Instantiates an IIOMetadataFormatImpl with the specified root name and CHILD_POLICY_REPEAT child policy.

param
rootName the name of root element.
param
minChildren the minimum number of children.
param
maxChildren the maximum number of children

        if (rootName == null) {
            throw new IllegalArgumentException("rootName is null");
        }
        if (minChildren < 0) {
            throw new IllegalArgumentException("minChildren < 0!");
        }
        if (minChildren > maxChildren) {
            throw new IllegalArgumentException("minChildren > maxChildren!");
        }

        this.rootName = rootName;
        Element root = new Element();
        root.name = rootName;
        root.minChildren = minChildren;
        root.maxChildren = maxChildren;
        root.childPolicy = CHILD_POLICY_REPEAT;
        elementHash.put(rootName, root);
    
Methods Summary
protected voidaddAttribute(java.lang.String elementName, java.lang.String attrName, int dataType, boolean required, int listMinLength, int listMaxLength)
Adds a new attribute to an existing element.

param
elementName the name of the element to which the new attribute will be added.
param
attrName the attribute name.
param
dataType the data type of the new attribute.
param
required the flag which indicates whether this attribute must be present.
param
listMinLength the minimum legal number of list items.
param
listMaxLength the the maximum legal number of list items.

        if (attrName == null) {
            throw new IllegalArgumentException("attrName == null!");
        }
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
            throw new IllegalArgumentException("Invalid value for dataType!");
        }
        if (listMinLength < 0 || listMinLength > listMaxLength) {
            throw new IllegalArgumentException("Invalid list bounds!");
        }

        Element element = findElement(elementName);
        Attlist attr = new Attlist();
        attr.name = attrName;
        attr.dataType = dataType;
        attr.required = required;
        attr.listMinLength = listMinLength;
        attr.listMaxLength = listMaxLength;
        attr.valueType = VALUE_LIST;

        element.attributes.put(attrName, attr);
    
protected voidaddAttribute(java.lang.String elementName, java.lang.String attrName, int dataType, boolean required, java.lang.String defaultValue)
Adds a new attribute to an existing element.

param
elementName the name of the element to which the new attribute will be added.
param
attrName the attribute name.
param
dataType the data type of the new attribute.
param
required the flag which indicates whether this attribute must be present.
param
defaultValue the default value of the attribute.

        if (attrName == null) {
            throw new IllegalArgumentException("attrName == null!");
        }
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
            throw new IllegalArgumentException("Invalid value for dataType!");
        }

        Element element = findElement(elementName);
        Attlist attr = new Attlist();
        attr.name = attrName;
        attr.dataType = dataType;
        attr.required = required;
        attr.defaultValue = defaultValue;
        attr.valueType = VALUE_ARBITRARY;

        element.attributes.put(attrName, attr);
    
protected voidaddAttribute(java.lang.String elementName, java.lang.String attrName, int dataType, boolean required, java.lang.String defaultValue, java.util.List enumeratedValues)
Adds a new attribute to an existing element.

param
elementName the name of the element to which the new attribute will be added.
param
attrName the attribute name.
param
dataType the data type of the new attribute.
param
required the flag which indicates whether this attribute must be present.
param
defaultValue the default value of the attribute.
param
enumeratedValues the legal values for the attribute as a list of strings.

        if (attrName == null) {
            throw new IllegalArgumentException("attrName == null!");
        }
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
            throw new IllegalArgumentException("Invalid value for dataType!");
        }
        if (enumeratedValues == null || enumeratedValues.isEmpty()) {
            throw new IllegalArgumentException("enumeratedValues is empty or null");
        }

        try {
            for (String enumeratedValue : enumeratedValues) {
                if (enumeratedValue == null) {
                    throw new IllegalArgumentException("enumeratedValues contains a null!");
                }
            }
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("enumeratedValues contains a non-String value!");
        }

        Element element = findElement(elementName);
        Attlist attr = new Attlist();
        attr.name = attrName;
        attr.dataType = dataType;
        attr.required = required;
        attr.defaultValue = defaultValue;
        attr.enumeratedValues = enumeratedValues;
        attr.valueType = VALUE_ENUMERATION;

        element.attributes.put(attrName, attr);
    
protected voidaddAttribute(java.lang.String elementName, java.lang.String attrName, int dataType, boolean required, java.lang.String defaultValue, java.lang.String minValue, java.lang.String maxValue, boolean minInclusive, boolean maxInclusive)
Adds a new attribute to an existing element.

param
elementName the name of the element to which the new attribute will be added.
param
attrName the attribute name.
param
dataType the data type of the new attribute.
param
required the flag which indicates whether this attribute must be present.
param
defaultValue the default value of attribute.
param
minValue the minimum legal value of an attribute.
param
maxValue the maximum legal value of an attribute.
param
minInclusive the flag which indicates whether the minValue is inclusive.
param
maxInclusive the flag which indicates whether the maxValue is inclusive.

        if (attrName == null) {
            throw new IllegalArgumentException("attrName == null!");
        }
        if (dataType < DATATYPE_STRING || dataType > DATATYPE_DOUBLE) {
            throw new IllegalArgumentException("Invalid value for dataType!");
        }

        Element element = findElement(elementName);
        Attlist attr = new Attlist();
        attr.name = attrName;
        attr.dataType = dataType;
        attr.required = required;
        attr.defaultValue = defaultValue;
        attr.minValue = minValue;
        attr.maxValue = maxValue;
        attr.minInclusive = minInclusive;
        attr.maxInclusive = maxInclusive;

        attr.valueType = VALUE_RANGE;
        attr.valueType |= minInclusive ? VALUE_RANGE_MIN_INCLUSIVE_MASK : 0;
        attr.valueType |= maxInclusive ? VALUE_RANGE_MAX_INCLUSIVE_MASK : 0;

        element.attributes.put(attrName, attr);
    
protected voidaddBooleanAttribute(java.lang.String elementName, java.lang.String attrName, boolean hasDefaultValue, boolean defaultValue)
Adds a new attribute with boolean data type to an existing element.

param
elementName the name of the element to which the new attribute will be added.
param
attrName the attribute name.
param
hasDefaultValue the flag which indicates whether this attribute must have a default value.
param
defaultValue the default value.

        String defaultVal = hasDefaultValue ? (defaultValue ? "TRUE" : "FALSE") : null;
        ArrayList<String> values = new ArrayList<String>(2);
        values.add("TRUE");
        values.add("FALSE");

        addAttribute(elementName, attrName, DATATYPE_BOOLEAN, true, defaultVal, values);
    
protected voidaddChildElement(java.lang.String elementName, java.lang.String parentName)
Adds an existing element to the list of child elements of the specified parent element.

param
elementName the name of the element to be added.
param
parentName the parent element name.

        Element parent = findElement(parentName);
        Element element = findElement(elementName);
        parent.children.add(element.name);
    
protected voidaddElement(java.lang.String elementName, java.lang.String parentName, int childPolicy)
Adds a new element type to this IIOMetadataFormat with a child policy (if policy is not CHILD_POLICY_REPEAT).

param
elementName the name of the element to be added.
param
parentName the parent element name.
param
childPolicy one of the CHILD_POLICY_* constants defined by IIOMetadataFormat.

        if (childPolicy < CHILD_POLICY_EMPTY || childPolicy > CHILD_POLICY_MAX
                || childPolicy == CHILD_POLICY_REPEAT) {
            throw new IllegalArgumentException("childPolicy is not one of the predefined constants");
        }

        Element parent = findElement(parentName);
        Element element = new Element();
        element.name = elementName;
        element.childPolicy = childPolicy;
        elementHash.put(elementName, element);
        parent.children.add(elementName);
    
protected voidaddElement(java.lang.String elementName, java.lang.String parentName, int minChildren, int maxChildren)
Adds a new element type to this IIOMetadataFormat with CHILD_POLICY_REPEAT and the specified minimum and maximum number of child elements.

param
elementName the element name to be added.
param
parentName the parent element name.
param
minChildren the minimum number of child elements.
param
maxChildren the maximum number of child elements.

        if (minChildren < 0) {
            throw new IllegalArgumentException("minChildren < 0!");
        }
        if (minChildren > maxChildren) {
            throw new IllegalArgumentException("minChildren > maxChildren!");
        }

        Element parent = findElement(parentName);
        Element element = new Element();
        element.name = elementName;
        element.childPolicy = CHILD_POLICY_REPEAT;
        element.minChildren = minChildren;
        element.maxChildren = maxChildren;
        elementHash.put(elementName, element);
        parent.children.add(elementName);
    
protected voidaddObjectValue(java.lang.String elementName, java.lang.Class classType, int arrayMinLength, int arrayMaxLength)
Adds an Object reference with the specified class type to be stored as element's value.

param
elementName the element name.
param
classType the class indicates the legal types for the object's value.
param
arrayMinLength the minimum legal length for the array.
param
arrayMaxLength the maximum legal length for the array.

        Element element = findElement(elementName);

        ObjectValue objVal = new ObjectValue();
        objVal.classType = classType;
        objVal.arrayMaxLength = arrayMaxLength;
        objVal.arrayMinLength = arrayMinLength;
        objVal.valueType = VALUE_LIST;

        element.objectValue = objVal;
    
protected voidaddObjectValue(java.lang.String elementName, java.lang.Class classType, boolean required, T defaultValue)
Adds an Object reference with the specified class type to be stored as an element's value.

param
elementName the element name.
param
classType the class indicates the legal types for the object's value.
param
required a flag indicated that this object value must be present.
param
defaultValue the default value, or null.

        // note: reqired is an unused parameter
        Element element = findElement(elementName);

        ObjectValue<T> objVal = new ObjectValue<T>();
        objVal.classType = classType;
        objVal.defaultValue = defaultValue;
        objVal.valueType = VALUE_ARBITRARY;

        element.objectValue = objVal;
    
protected voidaddObjectValue(java.lang.String elementName, java.lang.Class classType, boolean required, T defaultValue, java.util.List enumeratedValues)
Adds an Object reference with the specified class type to be stored as the element's value.

param
elementName the element name.
param
classType the class indicates the legal types for the object value.
param
required a flag indicated that this object value must be present.
param
defaultValue the default value, or null.
param
enumeratedValues the list of legal values for the object.

        // note: reqired is an unused parameter
        if (enumeratedValues == null || enumeratedValues.isEmpty()) {
            throw new IllegalArgumentException("enumeratedValues is empty or null");
        }

        try {
            for (T enumeratedValue : enumeratedValues) {
                if (enumeratedValue == null) {
                    throw new IllegalArgumentException("enumeratedValues contains a null!");
                }
            }
        } catch (ClassCastException e) {
            throw new IllegalArgumentException(
                    "enumeratedValues contains a value not of class classType!");
        }

        Element element = findElement(elementName);

        ObjectValue<T> objVal = new ObjectValue<T>();
        objVal.classType = classType;
        objVal.defaultValue = defaultValue;
        objVal.enumeratedValues = enumeratedValues;
        objVal.valueType = VALUE_ENUMERATION;

        element.objectValue = objVal;
    
protected voidaddObjectValue(java.lang.String elementName, java.lang.Class classType, T defaultValue, java.lang.Comparable minValue, java.lang.Comparable maxValue, boolean minInclusive, boolean maxInclusive)
Adds an Object reference with the specified class type to be stored as the element's value.

param
elementName the element name.
param
classType the class indicates the legal types for the object value.
param
defaultValue the default value, or null.
param
minValue the minimum legal value for the object value.
param
maxValue the maximum legal value for the object value.
param
minInclusive the flag which indicates whether the minValue is inclusive.
param
maxInclusive the flag which indicates whether the maxValue is inclusive.

        Element element = findElement(elementName);

        ObjectValue<T> objVal = new ObjectValue<T>();
        objVal.classType = classType;
        objVal.defaultValue = defaultValue;
        objVal.minValue = minValue;
        objVal.maxValue = maxValue;
        objVal.minInclusive = minInclusive;
        objVal.maxInclusive = maxInclusive;

        objVal.valueType = VALUE_RANGE;
        objVal.valueType |= minInclusive ? VALUE_RANGE_MIN_INCLUSIVE_MASK : 0;
        objVal.valueType |= maxInclusive ? VALUE_RANGE_MAX_INCLUSIVE_MASK : 0;

        element.objectValue = objVal;
    
public abstract booleancanNodeAppear(java.lang.String elementName, javax.imageio.ImageTypeSpecifier imageType)

private javax.imageio.metadata.IIOMetadataFormatImpl$AttlistfindAttribute(java.lang.String elementName, java.lang.String attributeName)
Find attribute.

param
elementName the element name.
param
attributeName the attribute name.
return
the attlist.

        Element element = findElement(elementName);
        Attlist attribute;
        if ((attribute = element.attributes.get(attributeName)) == null) {
            throw new IllegalArgumentException("attribute name is null or no such attribute: "
                    + attributeName);
        }

        return attribute;
    
private javax.imageio.metadata.IIOMetadataFormatImpl$ElementfindElement(java.lang.String name)
Find element.

param
name the name.
return
the element.

        Element element;
        if ((element = elementHash.get(name)) == null) {
            throw new IllegalArgumentException("element name is null or no such element: " + name);
        }

        return element;
    
private javax.imageio.metadata.IIOMetadataFormatImpl$ObjectValuefindObjectValue(java.lang.String elementName)
Find object value.

param
elementName the element name.
return
the object value.

        Element element = findElement(elementName);
        ObjectValue v = element.objectValue;
        if (v == null) {
            throw new IllegalArgumentException("No object within element");
        }
        return v;
    
public intgetAttributeDataType(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        return attr.dataType;
    
public java.lang.StringgetAttributeDefaultValue(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        return attr.defaultValue;
    
public java.lang.StringgetAttributeDescription(java.lang.String elementName, java.lang.String attrName, java.util.Locale locale)

        findAttribute(elementName, attrName);
        return getResourceString(elementName + "/" + attrName, locale);
    
public java.lang.String[]getAttributeEnumerations(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        if (attr.valueType != VALUE_ENUMERATION) {
            throw new IllegalArgumentException("Attribute is not an enumeration!");
        }

        return attr.enumeratedValues.toArray(new String[attr.enumeratedValues.size()]);
    
public intgetAttributeListMaxLength(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        if (attr.valueType != VALUE_LIST) {
            throw new IllegalArgumentException("Attribute is not a list!");
        }
        return attr.listMaxLength;
    
public intgetAttributeListMinLength(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        if (attr.valueType != VALUE_LIST) {
            throw new IllegalArgumentException("Attribute is not a list!");
        }
        return attr.listMinLength;
    
public java.lang.StringgetAttributeMaxValue(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        if ((attr.valueType & VALUE_RANGE) == 0) {
            throw new IllegalArgumentException("Attribute is not a range!");
        }
        return attr.maxValue;
    
public java.lang.StringgetAttributeMinValue(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        if ((attr.valueType & VALUE_RANGE) == 0) {
            throw new IllegalArgumentException("Attribute is not a range!");
        }
        return attr.minValue;
    
public java.lang.String[]getAttributeNames(java.lang.String elementName)

        Element element = findElement(elementName);
        return element.attributes.keySet().toArray(new String[element.attributes.size()]);
    
public intgetAttributeValueType(java.lang.String elementName, java.lang.String attrName)

        Attlist attr = findAttribute(elementName, attrName);
        return attr.valueType;
    
public java.lang.String[]getChildNames(java.lang.String elementName)

        Element element = findElement(elementName);
        if (element.childPolicy == CHILD_POLICY_EMPTY) { // Element cannot have
            // children
            return null;
        }
        return element.children.toArray(new String[element.children.size()]);
    
public intgetChildPolicy(java.lang.String elementName)

        Element element = findElement(elementName);
        return element.childPolicy;
    
public java.lang.StringgetElementDescription(java.lang.String elementName, java.util.Locale locale)

        findElement(elementName); // Check if there is such element
        return getResourceString(elementName, locale);
    
public intgetElementMaxChildren(java.lang.String elementName)

        Element element = findElement(elementName);
        if (element.childPolicy != CHILD_POLICY_REPEAT) {
            throw new IllegalArgumentException("Child policy is not CHILD_POLICY_REPEAT!");
        }
        return element.maxChildren;
    
public intgetElementMinChildren(java.lang.String elementName)

        Element element = findElement(elementName);
        if (element.childPolicy != CHILD_POLICY_REPEAT) {
            throw new IllegalArgumentException("Child policy is not CHILD_POLICY_REPEAT!");
        }
        return element.minChildren;
    
public intgetObjectArrayMaxLength(java.lang.String elementName)

        Element element = findElement(elementName);
        ObjectValue v = element.objectValue;
        if (v == null || v.valueType != VALUE_LIST) {
            throw new IllegalArgumentException("Not a list!");
        }
        return v.arrayMaxLength;
    
public intgetObjectArrayMinLength(java.lang.String elementName)

        Element element = findElement(elementName);
        ObjectValue v = element.objectValue;
        if (v == null || v.valueType != VALUE_LIST) {
            throw new IllegalArgumentException("Not a list!");
        }
        return v.arrayMinLength;
    
public java.lang.ClassgetObjectClass(java.lang.String elementName)

        ObjectValue v = findObjectValue(elementName);
        return v.classType;
    
public java.lang.ObjectgetObjectDefaultValue(java.lang.String elementName)

        ObjectValue v = findObjectValue(elementName);
        return v.defaultValue;
    
public java.lang.Object[]getObjectEnumerations(java.lang.String elementName)

        Element element = findElement(elementName);
        ObjectValue v = element.objectValue;
        if (v == null || v.valueType != VALUE_ENUMERATION) {
            throw new IllegalArgumentException("Not an enumeration!");
        }
        return v.enumeratedValues.toArray();
    
public java.lang.ComparablegetObjectMaxValue(java.lang.String elementName)

        Element element = findElement(elementName);
        ObjectValue v = element.objectValue;
        if (v == null || (v.valueType & VALUE_RANGE) == 0) {
            throw new IllegalArgumentException("Not a range!");
        }
        return v.maxValue;
    
public java.lang.ComparablegetObjectMinValue(java.lang.String elementName)

        Element element = findElement(elementName);
        ObjectValue v = element.objectValue;
        if (v == null || (v.valueType & VALUE_RANGE) == 0) {
            throw new IllegalArgumentException("Not a range!");
        }
        return v.minValue;
    
public intgetObjectValueType(java.lang.String elementName)

        Element element = findElement(elementName);
        if (element.objectValue == null) {
            return VALUE_NONE;
        }
        return element.objectValue.valueType;
    
protected java.lang.StringgetResourceBaseName()
Gets the resource base name for locating ResourceBundles.

return
the current resource base name.

        return resourceBaseName;
    
private java.lang.StringgetResourceString(java.lang.String key, java.util.Locale locale)
Gets the resource string.

param
key the key.
param
locale the locale.
return
the resource string.

        if (locale == null) {
            locale = Locale.getDefault();
        }

        // Get the context class loader and try to locate the bundle with it
        // first
        ClassLoader contextClassloader = AccessController
                .doPrivileged(new PrivilegedAction<ClassLoader>() {
                    public ClassLoader run() {
                        return Thread.currentThread().getContextClassLoader();
                    }
                });

        // Now try to get the resource bundle
        ResourceBundle rb;
        try {
            rb = ResourceBundle.getBundle(resourceBaseName, locale, contextClassloader);
        } catch (MissingResourceException e) {
            try {
                rb = ResourceBundle.getBundle(resourceBaseName, locale);
            } catch (MissingResourceException e1) {
                return null;
            }
        }

        try {
            return rb.getString(key);
        } catch (MissingResourceException e) {
            return null;
        } catch (ClassCastException e) {
            return null; // Not a string resource
        }
    
public java.lang.StringgetRootName()

        return rootName;
    
public static javax.imageio.metadata.IIOMetadataFormatgetStandardFormatInstance()
Gets the standard format instance.

return
the IIOMetadataFormat instance.

        if (standardFormat == null) {
            standardFormat = new IIOStandardMetadataFormat();
        }

        return standardFormat;
    
public booleanisAttributeRequired(java.lang.String elementName, java.lang.String attrName)

        return findAttribute(elementName, attrName).required;
    
protected voidremoveAttribute(java.lang.String elementName, java.lang.String attrName)
Removes the specified attribute from the specified element.

param
elementName the specified element name.
param
attrName the specified attribute name.

        Element element = findElement(elementName);
        element.attributes.remove(attrName);
    
protected voidremoveElement(java.lang.String elementName)
Removes the specified element from this format.

param
elementName the specified element name.

        Element element;
        if ((element = elementHash.get(elementName)) != null) {
            elementHash.remove(elementName);
            for (Element e : elementHash.values()) {
                e.children.remove(element.name);
            }
        }
    
protected voidremoveObjectValue(java.lang.String elementName)
Removes the object value from the specified element.

param
elementName the element name.

        Element element = findElement(elementName);
        element.objectValue = null;
    
protected voidsetResourceBaseName(java.lang.String resourceBaseName)
Sets a new base name for ResourceBundles containing descriptions of elements and attributes for this format.

param
resourceBaseName the new resource base name.

        if (resourceBaseName == null) {
            throw new IllegalArgumentException("resourceBaseName == null!");
        }
        this.resourceBaseName = resourceBaseName;