1 | /* |
2 | * Copyright 2007 brunella ltd |
3 | * |
4 | * Licensed under the LGPL Version 3 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * |
7 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
8 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
9 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
10 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
11 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
12 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
13 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
14 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
15 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
16 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
17 | * THE POSSIBILITY OF SUCH DAMAGE. |
18 | */ |
19 | package sf.qof.parser; |
20 | |
21 | /** |
22 | * Default implementation of a result definition. |
23 | */ |
24 | public class ResultDefinitionImpl implements ResultDefinition { |
25 | |
26 | private String[] columns; |
27 | private String field; |
28 | private int[] indexes; |
29 | private String type; |
30 | private boolean isMapKey; |
31 | private int constructorParameter; |
32 | private String partialDefinitionGroup; |
33 | private int partialDefinitionPart; |
34 | |
35 | public String[] getColumns() { |
36 | return columns; |
37 | } |
38 | |
39 | public String getField() { |
40 | return field; |
41 | } |
42 | |
43 | public int getConstructorParameter() { |
44 | return constructorParameter; |
45 | } |
46 | |
47 | public int[] getIndexes() { |
48 | return indexes; |
49 | } |
50 | |
51 | public String getType() { |
52 | return type; |
53 | } |
54 | |
55 | public void setColumns(String[] columns) { |
56 | if (columns == null || columns.length == 0) { |
57 | this.columns = null; |
58 | } else { |
59 | this.columns = columns; |
60 | } |
61 | } |
62 | |
63 | public void setField(String field) { |
64 | if (field == null || "".equals(field)) { |
65 | this.field = null; |
66 | } else { |
67 | this.field = field; |
68 | } |
69 | } |
70 | |
71 | public void setConstructorParameter(int parameter) { |
72 | this.constructorParameter = parameter; |
73 | } |
74 | |
75 | public void setIndexes(int[] indexes) { |
76 | if (indexes == null || indexes.length == 0) { |
77 | this.indexes = null; |
78 | } else { |
79 | this.indexes = indexes; |
80 | } |
81 | } |
82 | |
83 | public void setType(String type) { |
84 | if (type == null || "".equals(type)) { |
85 | this.type = "auto"; |
86 | } else { |
87 | this.type = type; |
88 | } |
89 | } |
90 | |
91 | public void setIsMapKey(boolean isMapKey) { |
92 | this.isMapKey = isMapKey; |
93 | } |
94 | |
95 | private String getColumnsString() { |
96 | if (columns == null) { |
97 | return ""; |
98 | } |
99 | StringBuilder sb = new StringBuilder(); |
100 | for (int i = 0; i < columns.length; i++) { |
101 | if (i > 0) { |
102 | sb.append(','); |
103 | } |
104 | sb.append('"').append(columns[i]).append('"'); |
105 | } |
106 | return sb.toString(); |
107 | } |
108 | |
109 | private String getIndexesString() { |
110 | if (indexes == null) { |
111 | return ""; |
112 | } |
113 | StringBuilder sb = new StringBuilder(); |
114 | for (int i = 0; i < indexes.length; i++) { |
115 | if (i > 0) { |
116 | sb.append(','); |
117 | } |
118 | sb.append(indexes[i]); |
119 | } |
120 | return sb.toString(); |
121 | } |
122 | |
123 | public String toString() { |
124 | return "Result: " + type + " (" + getColumnsString() + " " + getIndexesString() + ") " + field; |
125 | |
126 | } |
127 | |
128 | public boolean isMapKey() { |
129 | return isMapKey; |
130 | } |
131 | |
132 | public String getPartialDefinitionGroup() { |
133 | return partialDefinitionGroup; |
134 | } |
135 | |
136 | public void setPartialDefinitionGroup(String partialDefinitionGroup) { |
137 | this.partialDefinitionGroup = partialDefinitionGroup; |
138 | } |
139 | |
140 | public int getPartialDefinitionPart() { |
141 | return partialDefinitionPart; |
142 | } |
143 | |
144 | public void setPartialDefinitionPart(int partialDefinitionPart) { |
145 | this.partialDefinitionPart = partialDefinitionPart; |
146 | } |
147 | |
148 | public boolean isPartialDefinition() { |
149 | return partialDefinitionPart > 0; |
150 | } |
151 | |
152 | } |