001/*
002 * $RCSfile: TIFFImageMetadataFormat.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:46 $
043 * $State: Exp $
044 */
045package com.github.jaiimageio.impl.plugins.tiff;
046
047import javax.imageio.ImageTypeSpecifier;
048import javax.imageio.metadata.IIOMetadataFormat;
049
050public class TIFFImageMetadataFormat extends TIFFMetadataFormat {
051
052    private static TIFFImageMetadataFormat theInstance = null;
053
054    static {
055    }
056
057    public boolean canNodeAppear(String elementName,
058                                 ImageTypeSpecifier imageType) {
059        return false;
060    }
061
062    private TIFFImageMetadataFormat() {
063        this.resourceBaseName =
064     "com.github.jaiimageio.impl.plugins.tiff.TIFFImageMetadataFormatResources";
065        this.rootName = TIFFImageMetadata.nativeMetadataFormatName;
066
067        TIFFElementInfo einfo;
068        TIFFAttrInfo ainfo;
069        String[] empty = new String[0];
070        String[] childNames;
071        String[] attrNames;
072
073        childNames = new String[] { "TIFFIFD" };
074        einfo = new TIFFElementInfo(childNames, empty, CHILD_POLICY_SEQUENCE);
075
076        elementInfoMap.put(TIFFImageMetadata.nativeMetadataFormatName,
077                           einfo);
078
079        childNames = new String[] { "TIFFField", "TIFFIFD" };
080        attrNames =
081            new String[] { "tagSets", "parentTagNumber", "parentTagName" };
082        einfo = new TIFFElementInfo(childNames, attrNames, CHILD_POLICY_SEQUENCE);
083        elementInfoMap.put("TIFFIFD", einfo);
084
085        ainfo = new TIFFAttrInfo();
086        ainfo.dataType = DATATYPE_STRING;
087        ainfo.isRequired = true;
088        attrInfoMap.put("TIFFIFD/tagSets", ainfo);
089
090        ainfo = new TIFFAttrInfo();
091        ainfo.dataType = DATATYPE_INTEGER;
092        ainfo.isRequired = false;
093        attrInfoMap.put("TIFFIFD/parentTagNumber", ainfo);
094
095        ainfo = new TIFFAttrInfo();
096        ainfo.dataType = DATATYPE_STRING;
097        ainfo.isRequired = false;
098        attrInfoMap.put("TIFFIFD/parentTagName", ainfo);
099
100        String[] types = {
101            "TIFFByte",
102            "TIFFAscii",
103            "TIFFShort",
104            "TIFFSShort",
105            "TIFFLong",
106            "TIFFSLong",
107            "TIFFRational",
108            "TIFFSRational",
109            "TIFFFloat",
110            "TIFFDouble",
111            "TIFFUndefined"
112        };
113
114        attrNames = new String[] { "value", "description" };
115        String[] attrNamesValueOnly = new String[] { "value" };
116        TIFFAttrInfo ainfoValue = new TIFFAttrInfo();
117        TIFFAttrInfo ainfoDescription = new TIFFAttrInfo();
118
119        for (int i = 0; i < types.length; i++) {
120            if (!types[i].equals("TIFFUndefined")) {
121                childNames = new String[1];
122                childNames[0] = types[i];
123                einfo =
124                    new TIFFElementInfo(childNames, empty, CHILD_POLICY_SEQUENCE);
125                elementInfoMap.put(types[i] + "s", einfo);
126            }
127
128            boolean hasDescription =
129                !types[i].equals("TIFFUndefined") &&
130                !types[i].equals("TIFFAscii") &&
131                !types[i].equals("TIFFRational") &&
132                !types[i].equals("TIFFSRational") &&
133                !types[i].equals("TIFFFloat") &&
134                !types[i].equals("TIFFDouble");
135
136            String[] anames = hasDescription ? attrNames : attrNamesValueOnly;
137            einfo = new TIFFElementInfo(empty, anames, CHILD_POLICY_EMPTY);
138            elementInfoMap.put(types[i], einfo);
139
140            attrInfoMap.put(types[i] + "/value", ainfoValue);
141            if (hasDescription) {
142                attrInfoMap.put(types[i] + "/description", ainfoDescription);
143            }
144        }
145            
146        childNames = new String[2*types.length - 1];
147        for (int i = 0; i < types.length; i++) {
148            childNames[2*i] = types[i];
149            if (!types[i].equals("TIFFUndefined")) {
150                childNames[2*i + 1] = types[i] + "s";
151            }
152        }
153        attrNames = new String[] { "number", "name" };
154        einfo = new TIFFElementInfo(childNames, attrNames, CHILD_POLICY_CHOICE);
155        elementInfoMap.put("TIFFField", einfo);
156
157        ainfo = new TIFFAttrInfo();
158        ainfo.isRequired = true;
159        attrInfoMap.put("TIFFField/number", ainfo);
160
161        ainfo = new TIFFAttrInfo();
162        attrInfoMap.put("TIFFField/name", ainfo);
163    }
164
165    public static synchronized IIOMetadataFormat getInstance() {
166        if (theInstance == null) {
167            theInstance = new TIFFImageMetadataFormat();
168        }
169        return theInstance;
170    }
171}