KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tags > databinding > datagrid > DataGridUtil


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.tags.databinding.datagrid;
19
20 import javax.servlet.jsp.JspContext JavaDoc;
21
22 import org.apache.beehive.netui.databinding.datagrid.api.rendering.DataGridTagModel;
23 import org.apache.beehive.netui.databinding.datagrid.api.rendering.CellModel;
24
25 /**
26  * Package protected class that provides utility methods for managing adding and removing
27  * {@link DataGridTagModel} and {@link CellModel} instances in the {@link JspContext}.
28  */

29 final class DataGridUtil {
30
31     private static final String JavaDoc KEY_GRID_MODEL = "dataGrid";
32     private static final String JavaDoc KEY_CELL_MODEL = "cell";
33
34     /* do not construct */
35     private DataGridUtil() {}
36
37     /**
38      * Get the {@link DataGridTagModel} instance from the {@link JspContext} using the
39      * {@link #KEY_GRID_MODEL} as the key.
40      * @param jspContext the jsp context
41      * @return the {@link DataGridTagModel} if one is found
42      */

43     public static final DataGridTagModel getDataGridTagModel(JspContext JavaDoc jspContext) {
44         Object JavaDoc model = jspContext.getAttribute(KEY_GRID_MODEL);
45         assert model != null ? model instanceof DataGridTagModel : true;
46         return (DataGridTagModel)model;
47     }
48
49     /**
50      * Put the {@link DataGridTagModel} in the {@link JspContext} using the {@link #KEY_GRID_MODEL}
51      * as the key.
52      * @param jspContext the jsp context
53      * @param dataGridTagModel the {@link DataGridTagModel}
54      */

55     public static final void putDataGridTagModel(JspContext JavaDoc jspContext, DataGridTagModel dataGridTagModel) {
56         jspContext.setAttribute(KEY_GRID_MODEL, dataGridTagModel);
57     }
58
59     /**
60      * Remove a {@link DataGridTagModel} from the {@link JspContext}
61      * @param jspContext the jsp context
62      */

63     public static final void removeDataGridTagModel(JspContext JavaDoc jspContext) {
64         jspContext.removeAttribute(KEY_GRID_MODEL);
65     }
66
67     /**
68      * Get the {@link CellModel} instance from the {@link JspContext} using the
69      * {@link #KEY_CELL_MODEL} as the key.
70      * @param jspContext the jsp context
71      * @return the {@link CellModel} if one is found
72      */

73     public static final CellModel getCellModel(JspContext JavaDoc jspContext) {
74         Object JavaDoc model = jspContext.getAttribute(KEY_CELL_MODEL);
75         assert model != null ? model instanceof CellModel : true;
76         return (CellModel)model;
77     }
78
79     /**
80      * Put the {@link CellModel} in the {@link JspContext} using the {@link #KEY_CELL_MODEL}
81      * as the key.
82      * @param jspContext the jsp context
83      * @param cellModel the {@link CellModel}
84      */

85     public static final void putCellModel(JspContext JavaDoc jspContext, CellModel cellModel) {
86         jspContext.setAttribute(KEY_CELL_MODEL, cellModel);
87     }
88
89     /**
90      * Remove a {@link CellModel} from the {@link JspContext}
91      * @param jspContext the jsp context
92      */

93     public static final void removeCellModel(JspContext JavaDoc jspContext) {
94         jspContext.removeAttribute(KEY_CELL_MODEL);
95     }
96 }
97
Popular Tags