KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > data > ListDefinition


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ListDefinition.java,v 1.10 2007/02/20 04:13:02 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.patterns.listdata.data;
23
24 import java.sql.Timestamp JavaDoc;
25 import java.util.Arrays JavaDoc;
26
27 import org.opensubsystems.core.data.DataObject;
28 import org.opensubsystems.core.data.ModifiableDataObject;
29 import org.opensubsystems.core.util.GlobalConstants;
30
31 /**
32  * This class describes the list of data objects. It allows to specify what
33  * attributes of the data objects to load, what conditions have to data objects
34  * satisfy to be included in the list, what should be the order of data elements,
35  * etc.
36  *
37  * @version $Id: ListDefinition.java,v 1.10 2007/02/20 04:13:02 bastafidli Exp $
38  * @author Julo Legeny
39  * @code.reviewer Miro Halas
40  * @code.reviewed 1.7 2006/02/18 05:31:33 bastafidl
41  */

42 public class ListDefinition extends ModifiableDataObject
43 {
44    // Constants ////////////////////////////////////////////////////////////////
45

46    /**
47     * Default number of items to display at once page.
48     */

49    public static final int DEFAULT_PAGE_SIZE = 10;
50    
51    /**
52     * Order the list in ascending order by specified column. This needs to be
53     * valid SQL modifier since it will be directly appended to the SQL query.
54     * There has to be extra space in the front since there needs to be space
55     * between column name and the identifier.
56     */

57    public static final String JavaDoc ORDER_ASCENDING = " asc";
58    
59    /**
60     * Convenience constant of array type.
61     */

62    public static final String JavaDoc[] ORDER_ASCENDING_ARRAY = {ORDER_ASCENDING};
63
64    /**
65     * Convenience constant of array type.
66     */

67    public static final String JavaDoc[] ORDER_ASCENDING2_ARRAY = {ORDER_ASCENDING,
68                                                           ORDER_ASCENDING,
69                                                          };
70
71    /**
72     * Order the list in descending order by specified column. This needs to be
73     * valid SQL modifier since it will be directly appended to the SQL query.
74     * There has to be extra space in the front since there needs to be space
75     * between column name and the identifier.
76     */

77    public static final String JavaDoc ORDER_DESCENDING = " desc";
78    
79    /**
80     * Convenience constant of array type.
81     */

82    public static final String JavaDoc[] ORDER_DESCENDING_ARRAY = {ORDER_DESCENDING};
83
84    /**
85     * Convenience constant of array type.
86     */

87    public static final String JavaDoc[] ORDER_DESCENDING2_ARRAY = {ORDER_DESCENDING,
88                                                            ORDER_DESCENDING,
89                                                           };
90
91    // Attributes ///////////////////////////////////////////////////////////////
92

93    /**
94     * Generated serial version id for this class.
95     */

96    private static final long serialVersionUID = -5492694489131987153L;
97
98    /**
99     * Code of the columns to order by, for each column at the same index is in
100     * m_arrOrderDirections setup the type of ordering.
101     */

102    protected int[] m_arrOrderColumnCodes;
103    
104    /**
105     * Type of the ordering ASC/DESC. See ORDER_XXX constants
106     * in the ListDefinition. The constant coresponds to the column code in
107     * m_iOrderColumnsCodes.
108     */

109    protected String JavaDoc[] m_arrOrderDirections;
110    
111    /**
112     * Default page size that is how many items are retrieved at once.
113     */

114    protected int m_iPageSize;
115    
116    /**
117     * Default list of attributes to retrieve for each data objects.
118     */

119    protected int[] m_arrShowColumnCodes;
120    
121    /**
122     * Rule, which the data objects in the list have to satisfy.
123     */

124    protected SimpleRule m_rule;
125    
126    // Constructors /////////////////////////////////////////////////////////////
127

128    /**
129     * Empty constructor - default values
130     */

131    public ListDefinition(
132    )
133    {
134       this(null, null, null);
135    }
136   
137    /**
138     * Default constructor with only the necessary paramaters
139     *
140     * @param arrOrderColumnCodes - codes for columns to order by, pass null if none
141     * @param arrOrderDirections - order directions (ASC/DESC), see ORDER_XXX constants
142     * @param arrShowColumnCodes - array of attributes to retrieve for each data object
143     */

144    public ListDefinition(
145       int[] arrOrderColumnCodes,
146       String JavaDoc[] arrOrderDirections,
147       int[] arrShowColumnCodes
148    )
149    {
150       this(DataObject.NEW_ID, DataObject.NEW_ID,
151            DEFAULT_PAGE_SIZE, arrOrderColumnCodes, arrOrderDirections,
152            arrShowColumnCodes, SimpleRule.ALL_DATA, null, null);
153    }
154
155    /**
156     * Complete constructor with all paramaters
157     *
158     * @param iId - List definition ID
159     * @param iDomainId - domain ID
160     * @param iPageSize - page size determines how many items are retrieved at once
161     * @param arrOrderColumnCodes - codes for columns to order by, pass null if none
162     * @param arrOrderDirections - order directions (ASC/DESC), see ORDER_XXX constants
163     * @param arrShowColumnCodes - array of column codes to show
164     * @param rule - rule which the data in the list have to satisfy
165     * @param creationTimestamp - creation date
166     * @param modificationTimestamp - last modification date
167     */

168    public ListDefinition(
169       int iId,
170       int iDomainId,
171       int iPageSize,
172       int[] arrOrderColumnCodes,
173       String JavaDoc[] arrOrderDirections,
174       int[] arrShowColumnCodes,
175       SimpleRule rule,
176       Timestamp JavaDoc creationTimestamp,
177       Timestamp JavaDoc modificationTimestamp
178       
179    )
180    {
181       super(iId, iDomainId, creationTimestamp, modificationTimestamp);
182       
183       m_iPageSize = iPageSize;
184       setOrdering(arrOrderColumnCodes, arrOrderDirections);
185       m_arrShowColumnCodes = arrShowColumnCodes;
186       m_rule = rule;
187    }
188
189    /**
190     * This is the default direction of ordering (ASC/DESC) which should be fetched
191     * when this definition is used unless otherwise overriden.
192     *
193     * @return String[] - one of the ORDER_XXX constants
194     */

195    public String JavaDoc[] getOrderDirections(
196    )
197    {
198       return m_arrOrderDirections;
199    }
200
201    /**
202     * This is the list of column codes to order by which should be taken
203     * into account when this filter is used unless otherwise overriden.
204     * Direction of ordering is set in getOrderDirections.
205     *
206     * @return int[]
207     */

208    public int[] getOrderColumnCodes()
209    {
210       return m_arrOrderColumnCodes;
211    }
212
213    /**
214     * This is the default page size which should be retrieved and determines
215     * how many data objects are retrieved at once.
216     *
217     * @return int
218     */

219    public int getPageSize(
220    )
221    {
222       return m_iPageSize;
223    }
224    
225    /**
226     * Set column codes of columns which should be displayed on GUI.
227     *
228     * @return int[]
229     */

230    public int[] getShowColumnCodes()
231    {
232       return m_arrShowColumnCodes;
233    }
234    
235    /**
236     * @return SimpleRule - rule that data object has to match to be included in
237     * the list
238     */

239    public SimpleRule getRule()
240    {
241       return m_rule;
242    }
243
244    /**
245     * Set the rule for list definition.
246     *
247     * @param rule - simple rule
248     */

249    public void setRule(
250       SimpleRule rule
251    )
252    {
253       m_rule = rule;
254    }
255
256    /**
257     * Set page size for items displayed on GUI.
258     *
259     * @param iPageSize - array of column codes to show
260     */

261    public void setPageSize(
262       int iPageSize
263    )
264    {
265       m_iPageSize = iPageSize;
266    }
267
268    /**
269     * Set column codes of data object attributes, which should be retrieved.
270     * This is not necessary the list of fields, which will be retrieved from
271     * the database since some fields such as IDs of the objects are never shown
272     * on the GUI but they are still needed to construct the page.
273     *
274     * @param wShowColumnCodes - array of column codes to show
275     */

276    public void setShowColumnCodes(
277       int[] wShowColumnCodes
278    )
279    {
280       m_arrShowColumnCodes = wShowColumnCodes;
281    }
282
283    /**
284     * @param arrOrderColumnCodes - codes for columns to order by, pass null if none
285     * @param arrOrderTypes - types of ordering for each column
286     */

287    public void setOrdering(
288       int[] arrOrderColumnCodes,
289       String JavaDoc[] arrOrderTypes
290    )
291    {
292       if (GlobalConstants.ERROR_CHECKING)
293       {
294          assert (((arrOrderColumnCodes == null) && (arrOrderTypes == null))
295                 || (arrOrderColumnCodes.length == arrOrderTypes.length))
296                 : "Length of order column code and order direction arrays has to be the same";
297       }
298       
299       m_arrOrderColumnCodes = arrOrderColumnCodes;
300       m_arrOrderDirections = arrOrderTypes;
301    }
302
303    /**
304     * {@inheritDoc}
305     */

306    public boolean isSame(
307       Object JavaDoc oObject
308    )
309    {
310       boolean bReturn = false;
311       ListDefinition lfHelp;
312
313       if (oObject == this)
314       {
315          bReturn = true;
316       }
317       else
318       {
319          if (oObject != null && oObject instanceof ListDefinition)
320          {
321             // cast Object to ListDefinition
322
lfHelp = (ListDefinition) oObject;
323
324             // check all data attributes for equals
325
bReturn = (lfHelp.m_iPageSize == m_iPageSize)
326                       && (lfHelp.m_rule.equals(m_rule))
327                       && (Arrays.equals(lfHelp.m_arrOrderColumnCodes, m_arrOrderColumnCodes))
328                       && (Arrays.equals(lfHelp.m_arrOrderDirections, m_arrOrderDirections))
329                       && (Arrays.equals(lfHelp.m_arrShowColumnCodes, m_arrShowColumnCodes));
330          }
331       }
332       return bReturn;
333    }
334 }
335
Popular Tags