Debian Codegraph @

src/com/adobe/internal/xmp/options/PropertyOptions.java

raw symbols SCIP
1 // =================================================================================================
2 // ADOBE SYSTEMS INCORPORATED
3 // Copyright 2006 Adobe Systems Incorporated
4 // All Rights Reserved
5 //
6 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms
7 // of the Adobe license agreement accompanying it.
8 // =================================================================================================
9
10 package com.adobe.internal.xmp.options;
11
12 import com.adobe.internal.xmp.XMPError;
13 import com.adobe.internal.xmp.XMPException;
14
15
16 /**
17 * The property flags are used when properties are fetched from the <code>XMPMeta</code>-object
18 * and provide more detailed information about the property.
19 *
20 * @author Stefan Makswit
21 * @version $Revision$
22 * @since 03.07.2006
23 */
24 public final class PropertyOptions extends Options
25 {
26 /** */
27 public static final int NO_OPTIONS = 0x00000000;
28 /** */
29 public static final int URI = 0x00000002;
30 /** */
31 public static final int HAS_QUALIFIERS = 0x00000010;
32 /** */
33 public static final int QUALIFIER = 0x00000020;
34 /** */
35 public static final int HAS_LANGUAGE = 0x00000040;
36 /** */
37 public static final int HAS_TYPE = 0x00000080;
38 /** */
39 public static final int STRUCT = 0x00000100;
40 /** */
41 public static final int ARRAY = 0x00000200;
42 /** */
43 public static final int ARRAY_ORDERED = 0x00000400;
44 /** */
45 public static final int ARRAY_ALTERNATE = 0x00000800;
46 /** */
47 public static final int ARRAY_ALT_TEXT = 0x00001000;
48 /** */
49 public static final int SCHEMA_NODE = 0x80000000;
50 /** may be used in the future */
51 public static final int DELETE_EXISTING = 0x20000000;
52
53
54 private int arrayElementsLimit = -1; // unlimited
55 /**
56 * Default constructor
57 */
58 public PropertyOptions()
59 {
60 // reveal default constructor
61 }
62
63
64 /**
65 * Intialization constructor
66 *
67 * @param options the initialization options
68 * @throws XMPException If the options are not valid
69 */
70 public PropertyOptions(int options) throws XMPException
71 {
72 super(options);
73 }
74
75
76 /**
77 * @return Return whether the property value is a URI. It is serialized to RDF using the
78 * <tt>rdf:resource</tt> attribute. Not mandatory for URIs, but considered RDF-savvy.
79 */
80 public boolean isURI()
81 {
82 return getOption(URI);
83 }
84
85
86 /**
87 * @param value the value to set
88 * @return Returns this to enable cascaded options.
89 */
90 public PropertyOptions setURI(boolean value)
91 {
92 setOption(URI, value);
93 return this;
94 }
95
96
97 /**
98 * @return Return whether the property has qualifiers. These could be an <tt>xml:lang</tt>
99 * attribute, an <tt>rdf:type</tt> property, or a general qualifier. See the
100 * introductory discussion of qualified properties for more information.
101 */
102 public boolean getHasQualifiers()
103 {
104 return getOption(HAS_QUALIFIERS);
105 }
106
107
108 /**
109 * @param value the value to set
110 * @return Returns this to enable cascaded options.
111 */
112 public PropertyOptions setHasQualifiers(boolean value)
113 {
114 setOption(HAS_QUALIFIERS, value);
115 return this;
116 }
117
118
119 /**
120 * @return Return whether this property is a qualifier for some other property. Note that if the
121 * qualifier itself has a structured value, this flag is only set for the top node of
122 * the qualifier's subtree. Qualifiers may have arbitrary structure, and may even have
123 * qualifiers.
124 */
125 public boolean isQualifier()
126 {
127 return getOption(QUALIFIER);
128 }
129
130
131 /**
132 * @param value the value to set
133 * @return Returns this to enable cascaded options.
134 */
135 public PropertyOptions setQualifier(boolean value)
136 {
137 setOption(QUALIFIER, value);
138 return this;
139 }
140
141
142 /** @return Return whether this property has an <tt>xml:lang</tt> qualifier. */
143 public boolean getHasLanguage()
144 {
145 return getOption(HAS_LANGUAGE);
146 }
147
148
149 /**
150 * @param value the value to set
151 * @return Returns this to enable cascaded options.
152 */
153 public PropertyOptions setHasLanguage(boolean value)
154 {
155 setOption(HAS_LANGUAGE, value);
156 return this;
157 }
158
159
160 /** @return Return whether this property has an <tt>rdf:type</tt> qualifier. */
161 public boolean getHasType()
162 {
163 return getOption(HAS_TYPE);
164 }
165
166
167 /**
168 * @param value the value to set
169 * @return Returns this to enable cascaded options.
170 */
171 public PropertyOptions setHasType(boolean value)
172 {
173 setOption(HAS_TYPE, value);
174 return this;
175 }
176
177
178 /** @return Return whether this property contains nested fields. */
179 public boolean isStruct()
180 {
181 return getOption(STRUCT);
182 }
183
184
185 /**
186 * @param value the value to set
187 * @return Returns this to enable cascaded options.
188 */
189 public PropertyOptions setStruct(boolean value)
190 {
191 setOption(STRUCT, value);
192 return this;
193 }
194
195
196 /**
197 * @return Return whether this property is an array. By itself this indicates a general
198 * unordered array. It is serialized using an <tt>rdf:Bag</tt> container.
199 */
200 public boolean isArray()
201 {
202 return getOption(ARRAY);
203 }
204
205
206 /**
207 * @param value the value to set
208 * @return Returns this to enable cascaded options.
209 */
210 public PropertyOptions setArray(boolean value)
211 {
212 setOption(ARRAY, value);
213 return this;
214 }
215
216
217 /**
218 * @return Return whether this property is an ordered array. Appears in conjunction with
219 * getPropValueIsArray(). It is serialized using an <tt>rdf:Seq</tt> container.
220 */
221 public boolean isArrayOrdered()
222 {
223 return getOption(ARRAY_ORDERED);
224 }
225
226
227 /**
228 * @param value the value to set
229 * @return Returns this to enable cascaded options.
230 */
231 public PropertyOptions setArrayOrdered(boolean value)
232 {
233 setOption(ARRAY_ORDERED, value);
234 return this;
235 }
236
237
238 /**
239 * @return Return whether this property is an alternative array. Appears in conjunction with
240 * getPropValueIsArray(). It is serialized using an <tt>rdf:Alt</tt> container.
241 */
242 public boolean isArrayAlternate()
243 {
244 return getOption(ARRAY_ALTERNATE);
245 }
246
247
248 /**
249 * @param value the value to set
250 * @return Returns this to enable cascaded options.
251 */
252 public PropertyOptions setArrayAlternate(boolean value)
253 {
254 setOption(ARRAY_ALTERNATE, value);
255 return this;
256 }
257
258
259 /**
260 * @return Return whether this property is an alt-text array. Appears in conjunction with
261 * getPropArrayIsAlternate(). It is serialized using an <tt>rdf:Alt</tt> container.
262 * Each array element is a simple property with an <tt>xml:lang</tt> attribute.
263 */
264 public boolean isArrayAltText()
265 {
266 return getOption(ARRAY_ALT_TEXT);
267 }
268
269
270 /**
271 * @param value the value to set
272 * @return Returns this to enable cascaded options.
273 */
274 public PropertyOptions setArrayAltText(boolean value)
275 {
276 setOption(ARRAY_ALT_TEXT, value);
277 return this;
278 }
279
280
281 /**
282 * @return Return whether this property is an array with a limit on number-of-elements.
283 */
284 public boolean isArrayLimited()
285 {
286 return (arrayElementsLimit != -1);
287 }
288
289
290 /**
291 * @param arrayLimit the limit to set on number-of-elements
292 * @return Returns this to enable cascaded options.
293 */
294 public PropertyOptions setArrayElementLimit(int arrayLimit)
295 {
296 arrayElementsLimit = arrayLimit;
297 return this;
298 }
299
300
301 /**
302 * @return Returns the current limit on number-of-elements
303 */
304 public int getArrayElementsLimit()
305 {
306 return arrayElementsLimit;
307 }
308
309 /**
310 * @return Returns whether the SCHEMA_NODE option is set.
311 */
312 public boolean isSchemaNode()
313 {
314 return getOption(SCHEMA_NODE);
315 }
316
317
318 /**
319 * @param value the option DELETE_EXISTING to set
320 * @return Returns this to enable cascaded options.
321 */
322 public PropertyOptions setSchemaNode(boolean value)
323 {
324 setOption(SCHEMA_NODE, value);
325 return this;
326 }
327
328
329 //-------------------------------------------------------------------------- convenience methods
330
331 /**
332 * @return Returns whether the property is of composite type - an array or a struct.
333 */
334 public boolean isCompositeProperty()
335 {
336 return (getOptions() & (ARRAY | STRUCT)) > 0;
337 }
338
339
340 /**
341 * @return Returns whether the property is of composite type - an array or a struct.
342 */
343 public boolean isSimple()
344 {
345 return (getOptions() & (ARRAY | STRUCT)) == 0;
346 }
347
348
349 /**
350 * Compares two options set for array compatibility.
351 *
352 * @param options other options
353 * @return Returns true if the array options of the sets are equal.
354 */
355 public boolean equalArrayTypes(PropertyOptions options)
356 {
357 return
358 isArray() == options.isArray() &&
359 isArrayOrdered() == options.isArrayOrdered() &&
360 isArrayAlternate() == options.isArrayAlternate() &&
361 isArrayAltText() == options.isArrayAltText();
362 }
363
364
365
366 /**
367 * Merges the set options of a another options object with this.
368 * If the other options set is null, this objects stays the same.
369 * @param options other options
370 * @throws XMPException If illegal options are provided
371 */
372 public void mergeWith(PropertyOptions options) throws XMPException
373 {
374 if (options != null)
375 {
376 setOptions(getOptions() | options.getOptions());
377 }
378 }
379
380
381 /**
382 * @return Returns true if only array options are set.
383 */
384 public boolean isOnlyArrayOptions()
385 {
386 return (getOptions() &
387 ~(ARRAY | ARRAY_ORDERED | ARRAY_ALTERNATE | ARRAY_ALT_TEXT)) == 0;
388 }
389
390
391 /**
392 * @see Options#getValidOptions()
393 */
394 protected int getValidOptions()
395 {
396 return
397 URI |
398 HAS_QUALIFIERS |
399 QUALIFIER |
400 HAS_LANGUAGE |
401 HAS_TYPE |
402 STRUCT |
403 ARRAY |
404 ARRAY_ORDERED |
405 ARRAY_ALTERNATE |
406 ARRAY_ALT_TEXT |
407 DELETE_EXISTING |
408 SCHEMA_NODE;
409 }
410
411
412 /**
413 * @see Options#defineOptionName(int)
414 */
415 protected String defineOptionName(int option)
416 {
417 switch (option)
418 {
419 case URI : return "URI";
420 case HAS_QUALIFIERS : return "HAS_QUALIFIER";
421 case QUALIFIER : return "QUALIFIER";
422 case HAS_LANGUAGE : return "HAS_LANGUAGE";
423 case HAS_TYPE: return "HAS_TYPE";
424 case STRUCT : return "STRUCT";
425 case ARRAY : return "ARRAY";
426 case ARRAY_ORDERED : return "ARRAY_ORDERED";
427 case ARRAY_ALTERNATE : return "ARRAY_ALTERNATE";
428 case ARRAY_ALT_TEXT : return "ARRAY_ALT_TEXT";
429 case SCHEMA_NODE : return "SCHEMA_NODE";
430 default: return null;
431 }
432 }
433
434
435 /**
436 * Checks that a node not a struct and array at the same time;
437 * and URI cannot be a struct.
438 *
439 * @param options the bitmask to check.
440 * @throws XMPException Thrown if the options are not consistent.
441 */
442 public void assertConsistency(int options) throws XMPException
443 {
444 if ((options & STRUCT) > 0 && (options & ARRAY) > 0)
445 {
446 throw new XMPException("IsStruct and IsArray options are mutually exclusive",
447 XMPError.BADOPTIONS);
448 }
449 else if ((options & URI) > 0 && (options & (ARRAY | STRUCT)) > 0)
450 {
451 throw new XMPException("Structs and arrays can't have \"value\" options",
452 XMPError.BADOPTIONS);
453 }
454 }
455 }