Debian Codegraph @

src/com/adobe/internal/xmp/impl/xpath/XMPPath.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.impl.xpath;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15
16 /**
17 * Representates an XMP XMPPath with segment accessor methods.
18 *
19 * @author Stefan Makswit
20 * @version $Revision$
21 * @since 28.02.2006
22 */
23 public class XMPPath
24 {
25 // Bits for XPathStepInfo options.
26
27 /** Marks a struct field step , also for top level nodes (schema "fields"). */
28 public static final int STRUCT_FIELD_STEP = 0x01;
29 /** Marks a qualifier step.
30 * Note: Order is significant to separate struct/qual from array kinds! */
31 public static final int QUALIFIER_STEP = 0x02; //
32 /** Marks an array index step */
33 public static final int ARRAY_INDEX_STEP = 0x03;
34 /** */
35 public static final int ARRAY_LAST_STEP = 0x04;
36 /** */
37 public static final int QUAL_SELECTOR_STEP = 0x05;
38 /** */
39 public static final int FIELD_SELECTOR_STEP = 0x06;
40 /** */
41 public static final int SCHEMA_NODE = 0x80000000;
42 /** */
43 public static final int STEP_SCHEMA = 0;
44 /** */
45 public static final int STEP_ROOT_PROP = 1;
46
47
48 /** stores the segments of an XMPPath */
49 private List segments = new ArrayList(5);
50
51
52 /**
53 * Append a path segment
54 *
55 * @param segment the segment to add
56 */
57 public void add(XMPPathSegment segment)
58 {
59 segments.add(segment);
60 }
61
62
63 /**
64 * @param index the index of the segment to return
65 * @return Returns a path segment.
66 */
67 public XMPPathSegment getSegment(int index)
68 {
69 return (XMPPathSegment) segments.get(index);
70 }
71
72
73 /**
74 * @return Returns the size of the xmp path.
75 */
76 public int size()
77 {
78 return segments.size();
79 }
80
81
82 /**
83 * Serializes the normalized XMP-path.
84 * @see Object#toString()
85 */
86 public String toString()
87 {
88 StringBuffer result = new StringBuffer();
89 int index = 1;
90 while (index < size())
91 {
92 result.append(getSegment(index));
93 if (index < size() - 1)
94 {
95 int kind = getSegment(index + 1).getKind();
96 if (kind == STRUCT_FIELD_STEP ||
97 kind == QUALIFIER_STEP)
98 {
99 // all but last and array indices
100 result.append('/');
101 }
102 }
103 index++;
104 }
105
106 return result.toString();
107 }
108 }