KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > util > word > QueryResult


1 package org.tigris.scarab.util.word;
2
3 /* ================================================================
4  * Copyright (c) 2000-2002 CollabNet. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * 3. The end-user documentation included with the redistribution, if
18  * any, must include the following acknowlegement: "This product includes
19  * software developed by Collab.Net <http://www.Collab.Net/>."
20  * Alternately, this acknowlegement may appear in the software itself, if
21  * and wherever such third-party acknowlegements normally appear.
22  *
23  * 4. The hosted project names must not be used to endorse or promote
24  * products derived from this software without prior written
25  * permission. For written permission, please contact info@collab.net.
26  *
27  * 5. Products derived from this software may not use the "Tigris" or
28  * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
29  * prior written permission of Collab.Net.
30  *
31  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
32  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34  * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
35  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
37  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
39  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  *
43  * ====================================================================
44  *
45  * This software consists of voluntary contributions made by many
46  * individuals on behalf of Collab.Net.
47  */

48
49 import java.util.List JavaDoc;
50 import java.util.ArrayList JavaDoc;
51 import java.util.Iterator JavaDoc;
52 import org.apache.torque.TorqueException;
53 import org.tigris.scarab.om.Module;
54 import org.tigris.scarab.om.RModuleIssueType;
55
56 /**
57  * This class is created by the IssueSearch object to contain a single result.
58  * It represents a row on the IssueList.vm screen. It is mostly
59  * a data structure with some additional functionality to format a
60  * multivalued attribute as CSV.
61  *
62  * @author <a HREF="mailto:jmcnally@collab.net">John McNally</a>
63  */

64 public class QueryResult
65 {
66     /** the search that created this QueryResult */
67     private final IssueSearch search;
68     private String JavaDoc issueId;
69     private String JavaDoc idPrefix;
70     private String JavaDoc idCount;
71     private String JavaDoc uniqueId;
72     private List JavaDoc attributeValues;
73     private Integer JavaDoc moduleId;
74     private Integer JavaDoc issueTypeId;
75
76     /**
77      * Ctor. Should only be called by an IssueSearch.
78      *
79      * @param search the <code>IssueSearch</code> that created this result
80      */

81     QueryResult(IssueSearch search)
82     {
83         this.search = search;
84     }
85
86     /**
87      * Get the IssueId value.
88      * @return the IssueId value.
89      */

90     public final String JavaDoc getIssueId()
91     {
92         return issueId;
93     }
94
95     /**
96      * Set the IssueId value.
97      * @param newIssueId The new IssueId value.
98      */

99     public final void setIssueId(String JavaDoc newIssueId)
100     {
101         this.issueId = newIssueId;
102     }
103
104     /**
105      * Get the IdPrefix value.
106      * @return the IdPrefix value.
107      */

108     public final String JavaDoc getIdPrefix()
109     {
110         return idPrefix;
111     }
112
113     /**
114      * Set the IdPrefix value.
115      * @param newIdPrefix The new IdPrefix value.
116      */

117     public final void setIdPrefix(String JavaDoc newIdPrefix)
118     {
119         this.idPrefix = newIdPrefix;
120     }
121
122     /**
123      * Get the IdCount value.
124      * @return the IdCount value.
125      */

126     public final String JavaDoc getIdCount()
127     {
128         return idCount;
129     }
130
131     /**
132      * Set the IdCount value.
133      * @param newIdCount The new IdCount value.
134      */

135     public final void setIdCount(String JavaDoc newIdCount)
136     {
137         this.idCount = newIdCount;
138     }
139
140
141     /**
142      * Combines getIdPrefix() and getIdCount()
143      */

144     public final String JavaDoc getUniqueId()
145     {
146         if (uniqueId == null)
147         {
148             uniqueId = getIdPrefix() + getIdCount();
149         }
150             
151         return uniqueId;
152     }
153
154     /**
155      * Get the AttributeValues value.
156      * @return the AttributeValues value.
157      */

158     public final List JavaDoc getAttributeValues()
159     {
160         return attributeValues;
161     }
162
163     /**
164      * Get the AttributeValues value.
165      * @return the AttributeValues value.
166      */

167     public final List JavaDoc getAttributeValuesAsCSV()
168     {
169         List JavaDoc result = null;
170         if (attributeValues != null)
171         {
172             result = new ArrayList JavaDoc(attributeValues.size());
173             for (Iterator JavaDoc i = attributeValues.iterator(); i.hasNext();)
174             {
175                 String JavaDoc csv = null;
176                 List JavaDoc multiVal = (List JavaDoc)i.next();
177                 if (multiVal.size() == 1)
178                 {
179                     csv = (String JavaDoc)multiVal.get(0);
180                     if (csv == null)
181                     {
182                         csv = "";
183                     }
184                 }
185                 else
186                 {
187                     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
188                     boolean addComma = false;
189                     for (Iterator JavaDoc j = multiVal.iterator(); j.hasNext();)
190                     {
191                         if (addComma)
192                         {
193                             sb.append(", ");
194                         }
195                         else
196                         {
197                             addComma = true;
198                         }
199                             
200                         sb.append(j.next().toString());
201                     }
202                     csv = sb.toString();
203                 }
204                 result.add(csv);
205             }
206         }
207             
208         return result;
209     }
210
211     /**
212      * Set the AttributeValues value.
213      * @param newAttributeValues The new AttributeValues value.
214      */

215     public final void setAttributeValues(List JavaDoc newAttributeValues)
216     {
217         this.attributeValues = newAttributeValues;
218     }
219         
220
221     /**
222      * Get the ModuleId value.
223      * @return the ModuleId value.
224      */

225     public final Integer JavaDoc getModuleId()
226     {
227         return moduleId;
228     }
229
230     /**
231      * Set the ModuleId value.
232      * @param newModuleId The new ModuleId value.
233      */

234     public final void setModuleId(Integer JavaDoc newModuleId)
235     {
236         this.moduleId = newModuleId;
237     }
238
239     /**
240      * Get the <code>Module</code> related thru getModuleId(). This method
241      * provides caching so that multiple QueryResult objects in the same
242      * resultset save db hits.
243      */

244     public final Module getModule()
245         throws TorqueException
246     {
247         return search.getModule(moduleId);
248     }
249
250     /**
251      * Get the IssueTypeId value.
252      * @return the IssueTypeId value.
253      */

254     public final Integer JavaDoc getIssueTypeId()
255     {
256         return issueTypeId;
257     }
258
259     /**
260      * Set the IssueTypeId value.
261      * @param newIssueTypeId The new IssueTypeId value.
262      */

263     public final void setIssueTypeId(Integer JavaDoc newIssueTypeId)
264     {
265         this.issueTypeId = newIssueTypeId;
266     }
267
268     /**
269      * Get the <code>RModuleIssueType</code> related thru getModuleId() and
270      * getIssueTypeId(). This method provides caching so that multiple
271      * QueryResult objects in the same resultset save db hits.
272      */

273     public final RModuleIssueType getRModuleIssueType()
274         throws TorqueException
275     {
276         return search.getRModuleIssueType(moduleId, issueTypeId);
277     }
278 }
279
Popular Tags