1:
37:
38:
39: package ;
40:
41:
44: public abstract class IIOMetadata
45: {
46: protected IIOMetadataController controller;
47: protected IIOMetadataController defaultController;
48: protected String[] extraMetadataFormatClassNames;
49: protected String[] extraMetadataFormatNames;
50: protected String nativeMetadataFormatClassName;
51: protected String nativeMetadataFormatName;
52: protected boolean standardFormatSupported;
53:
54:
57: protected IIOMetadata()
58: {
59:
60: }
61:
62:
75: protected IIOMetadata(boolean standardMetadataFormatSupported,
76: String nativeMetadataFormatName,
77: String nativeMetadataFormatClassName,
78: String[] extraMetadataFormatNames,
79: String[] extraMetadataFormatClassNames)
80: {
81: if (extraMetadataFormatNames != null
82: && extraMetadataFormatNames.length == 0)
83: throw new IllegalArgumentException
84: ("extraMetadataFormatNames may not be empty");
85:
86: if (((extraMetadataFormatNames == null)
87: && (extraMetadataFormatClassNames != null))
88: || ((extraMetadataFormatNames != null)
89: && (extraMetadataFormatClassNames == null))
90: || ((extraMetadataFormatNames != null)
91: && (extraMetadataFormatClassNames != null)
92: && (extraMetadataFormatNames.length !=
93: extraMetadataFormatClassNames.length)))
94: throw new IllegalArgumentException
95: ("extraMetadataFormatNames and extraMetadataFormatClassNames " +
96: "have different lengths");
97:
98: this.standardFormatSupported = standardMetadataFormatSupported;
99: this.nativeMetadataFormatName = nativeMetadataFormatName;
100: this.nativeMetadataFormatClassName = nativeMetadataFormatClassName;
101: this.extraMetadataFormatNames = extraMetadataFormatNames;
102: this.extraMetadataFormatClassNames = extraMetadataFormatClassNames;
103: }
104:
105: public boolean activateController()
106: {
107: if (! hasController())
108: return false;
109:
110: return getDefaultController().activate(this);
111: }
112:
113: public IIOMetadataController getController()
114: {
115: return controller;
116: }
117:
118: public IIOMetadataController getDefaultController()
119: {
120: return defaultController;
121: }
122:
123: public String[] getExtraMetadataFormatNames()
124: {
125: return (String[]) extraMetadataFormatNames.clone();
126: }
127:
128: public IIOMetadataFormat getMetadataFormat(String formatName)
129: {
130: if (formatName == null)
131: throw new IllegalArgumentException("formatName may not be null");
132:
133: String formatClassName = null;
134:
135: if (isStandardMetadataFormatSupported()
136: && formatName.equals(nativeMetadataFormatName))
137: formatClassName = nativeMetadataFormatClassName;
138: else
139: {
140: String[] extraFormatNames = getExtraMetadataFormatNames();
141:
142: for (int i = extraFormatNames.length - 1; i >= 0; --i)
143: if (extraFormatNames[i].equals(formatName))
144: {
145: formatClassName = extraFormatNames[i];
146: break;
147: }
148: }
149:
150: if (formatClassName == null)
151: throw new IllegalArgumentException("unknown format");
152:
153: IIOMetadataFormat format;
154:
155: try
156: {
157: format = (IIOMetadataFormat) Class.forName(formatClassName)
158: .newInstance();
159: }
160: catch (Exception e)
161: {
162: IllegalStateException ise = new IllegalStateException();
163: ise.initCause(e);
164: throw ise;
165: }
166:
167: return format;
168: }
169:
170: public String[] getMetadataFormatNames()
171: {
172: String[] formatNames = getExtraMetadataFormatNames();
173:
174: if (isStandardMetadataFormatSupported())
175: {
176:
177:
178: String[] tmp = new String[formatNames.length + 1];
179: tmp[0] = getNativeMetadataFormatName();
180:
181: for (int i = 1; i < tmp.length; ++i)
182: tmp[i] = formatNames[i - 1];
183:
184: formatNames = tmp;
185: }
186:
187: return formatNames;
188: }
189:
190: public String getNativeMetadataFormatName()
191: {
192: return nativeMetadataFormatName;
193: }
194:
195: public boolean hasController()
196: {
197: return getController() != null;
198: }
199:
200: public abstract boolean isReadOnly();
201:
202: public boolean isStandardMetadataFormatSupported()
203: {
204: return standardFormatSupported;
205: }
206:
207: public abstract void reset();
208:
209: public void setController(IIOMetadataController controller)
210: {
211: this.controller = controller;
212: }
213: }