001: /*
002: * $RCSfile: TIFFMetadataFormat.java,v $
003: *
004: *
005: * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * - Redistribution of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * - Redistribution in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * Neither the name of Sun Microsystems, Inc. or the names of
020: * contributors may be used to endorse or promote products derived
021: * from this software without specific prior written permission.
022: *
023: * This software is provided "AS IS," without a warranty of any
024: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
025: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
026: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
027: * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
028: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
029: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
030: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
031: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
032: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
033: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
034: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
035: * POSSIBILITY OF SUCH DAMAGES.
036: *
037: * You acknowledge that this software is not designed or intended for
038: * use in the design, construction, operation or maintenance of any
039: * nuclear facility.
040: *
041: * $Revision: 1.1 $
042: * $Date: 2005/02/11 05:01:48 $
043: * $State: Exp $
044: */
045: package com.sun.media.imageioimpl.plugins.tiff;
046:
047: import java.util.Collection;
048: import java.util.HashMap;
049: import java.util.Iterator;
050: import java.util.Locale;
051: import java.util.Map;
052: import java.util.MissingResourceException;
053: import java.util.ResourceBundle;
054: import javax.imageio.ImageTypeSpecifier;
055: import javax.imageio.metadata.IIOMetadataFormat;
056: import com.sun.media.imageio.plugins.tiff.BaselineTIFFTagSet;
057: import com.sun.media.imageio.plugins.tiff.TIFFTag;
058: import com.sun.media.imageio.plugins.tiff.TIFFTagSet;
059:
060: public abstract class TIFFMetadataFormat implements IIOMetadataFormat {
061:
062: protected Map elementInfoMap = new HashMap();
063: protected Map attrInfoMap = new HashMap();
064:
065: protected String resourceBaseName;
066: protected String rootName;
067:
068: public String getRootName() {
069: return rootName;
070: }
071:
072: private String getResource(String key, Locale locale) {
073: if (locale == null) {
074: locale = Locale.getDefault();
075: }
076: try {
077: ResourceBundle bundle = ResourceBundle.getBundle(
078: resourceBaseName, locale);
079: return bundle.getString(key);
080: } catch (MissingResourceException e) {
081: return null;
082: }
083: }
084:
085: private TIFFElementInfo getElementInfo(String elementName) {
086: if (elementName == null) {
087: throw new IllegalArgumentException("elementName == null!");
088: }
089: TIFFElementInfo info = (TIFFElementInfo) elementInfoMap
090: .get(elementName);
091: if (info == null) {
092: throw new IllegalArgumentException("No such element: "
093: + elementName);
094: }
095: return info;
096: }
097:
098: private TIFFAttrInfo getAttrInfo(String elementName, String attrName) {
099: if (elementName == null) {
100: throw new IllegalArgumentException("elementName == null!");
101: }
102: if (attrName == null) {
103: throw new IllegalArgumentException("attrName == null!");
104: }
105: String key = elementName + "/" + attrName;
106: TIFFAttrInfo info = (TIFFAttrInfo) attrInfoMap.get(key);
107: if (info == null) {
108: throw new IllegalArgumentException("No such attribute: "
109: + key);
110: }
111: return info;
112: }
113:
114: public int getElementMinChildren(String elementName) {
115: TIFFElementInfo info = getElementInfo(elementName);
116: return info.minChildren;
117: }
118:
119: public int getElementMaxChildren(String elementName) {
120: TIFFElementInfo info = getElementInfo(elementName);
121: return info.maxChildren;
122: }
123:
124: public String getElementDescription(String elementName,
125: Locale locale) {
126: if (!elementInfoMap.containsKey(elementName)) {
127: throw new IllegalArgumentException("No such element: "
128: + elementName);
129: }
130: return getResource(elementName, locale);
131: }
132:
133: public int getChildPolicy(String elementName) {
134: TIFFElementInfo info = getElementInfo(elementName);
135: return info.childPolicy;
136: }
137:
138: public String[] getChildNames(String elementName) {
139: TIFFElementInfo info = getElementInfo(elementName);
140: return info.childNames;
141: }
142:
143: public String[] getAttributeNames(String elementName) {
144: TIFFElementInfo info = getElementInfo(elementName);
145: return info.attributeNames;
146: }
147:
148: public int getAttributeValueType(String elementName, String attrName) {
149: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
150: return info.valueType;
151: }
152:
153: public int getAttributeDataType(String elementName, String attrName) {
154: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
155: return info.dataType;
156: }
157:
158: public boolean isAttributeRequired(String elementName,
159: String attrName) {
160: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
161: return info.isRequired;
162: }
163:
164: public String getAttributeDefaultValue(String elementName,
165: String attrName) {
166: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
167: return info.defaultValue;
168: }
169:
170: public String[] getAttributeEnumerations(String elementName,
171: String attrName) {
172: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
173: return info.enumerations;
174: }
175:
176: public String getAttributeMinValue(String elementName,
177: String attrName) {
178: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
179: return info.minValue;
180: }
181:
182: public String getAttributeMaxValue(String elementName,
183: String attrName) {
184: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
185: return info.maxValue;
186: }
187:
188: public int getAttributeListMinLength(String elementName,
189: String attrName) {
190: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
191: return info.listMinLength;
192: }
193:
194: public int getAttributeListMaxLength(String elementName,
195: String attrName) {
196: TIFFAttrInfo info = getAttrInfo(elementName, attrName);
197: return info.listMaxLength;
198: }
199:
200: public String getAttributeDescription(String elementName,
201: String attrName, Locale locale) {
202: String key = elementName + "/" + attrName;
203: if (!attrInfoMap.containsKey(key)) {
204: throw new IllegalArgumentException("No such attribute: "
205: + key);
206: }
207: return getResource(key, locale);
208: }
209:
210: public int getObjectValueType(String elementName) {
211: TIFFElementInfo info = getElementInfo(elementName);
212: return info.objectValueType;
213: }
214:
215: public Class getObjectClass(String elementName) {
216: TIFFElementInfo info = getElementInfo(elementName);
217: if (info.objectValueType == VALUE_NONE) {
218: throw new IllegalArgumentException(
219: "Element cannot contain an object value: "
220: + elementName);
221: }
222: return info.objectClass;
223: }
224:
225: public Object getObjectDefaultValue(String elementName) {
226: TIFFElementInfo info = getElementInfo(elementName);
227: if (info.objectValueType == VALUE_NONE) {
228: throw new IllegalArgumentException(
229: "Element cannot contain an object value: "
230: + elementName);
231: }
232: return info.objectDefaultValue;
233: }
234:
235: public Object[] getObjectEnumerations(String elementName) {
236: TIFFElementInfo info = getElementInfo(elementName);
237: if (info.objectValueType == VALUE_NONE) {
238: throw new IllegalArgumentException(
239: "Element cannot contain an object value: "
240: + elementName);
241: }
242: return info.objectEnumerations;
243: }
244:
245: public Comparable getObjectMinValue(String elementName) {
246: TIFFElementInfo info = getElementInfo(elementName);
247: if (info.objectValueType == VALUE_NONE) {
248: throw new IllegalArgumentException(
249: "Element cannot contain an object value: "
250: + elementName);
251: }
252: return info.objectMinValue;
253: }
254:
255: public Comparable getObjectMaxValue(String elementName) {
256: TIFFElementInfo info = getElementInfo(elementName);
257: if (info.objectValueType == VALUE_NONE) {
258: throw new IllegalArgumentException(
259: "Element cannot contain an object value: "
260: + elementName);
261: }
262: return info.objectMaxValue;
263: }
264:
265: public int getObjectArrayMinLength(String elementName) {
266: TIFFElementInfo info = getElementInfo(elementName);
267: if (info.objectValueType == VALUE_NONE) {
268: throw new IllegalArgumentException(
269: "Element cannot contain an object value: "
270: + elementName);
271: }
272: return info.objectArrayMinLength;
273: }
274:
275: public int getObjectArrayMaxLength(String elementName) {
276: TIFFElementInfo info = getElementInfo(elementName);
277: if (info.objectValueType == VALUE_NONE) {
278: throw new IllegalArgumentException(
279: "Element cannot contain an object value: "
280: + elementName);
281: }
282: return info.objectArrayMaxLength;
283: }
284:
285: public TIFFMetadataFormat() {
286: }
287: }
|