KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > list > ui > CommandContextImpl


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.riot.list.ui;
25
26 import javax.servlet.http.HttpServletRequest JavaDoc;
27
28 import org.riotfamily.common.i18n.MessageResolver;
29 import org.riotfamily.riot.dao.ListParams;
30 import org.riotfamily.riot.dao.RiotDao;
31 import org.riotfamily.riot.editor.EditorDefinitionUtils;
32 import org.riotfamily.riot.editor.ListDefinition;
33 import org.riotfamily.riot.list.ListConfig;
34 import org.riotfamily.riot.list.command.CommandContext;
35
36 class CommandContextImpl implements CommandContext {
37
38     private ListSession session;
39
40     private ListItem item;
41
42     private int itemsTotal;
43
44     private Object JavaDoc bean;
45
46     private Object JavaDoc parent;
47
48     private HttpServletRequest JavaDoc request;
49
50     public CommandContextImpl(ListSession session, HttpServletRequest JavaDoc request) {
51         this.session = session;
52         this.request = request;
53     }
54
55     public void setItem(ListItem item) {
56         this.item = item;
57     }
58
59     public Class JavaDoc getBeanClass() {
60         return session.getBeanClass();
61     }
62
63     public RiotDao getDao() {
64         return session.getListDefinition().getListConfig().getDao();
65     }
66
67     public Object JavaDoc getBean() {
68         if (bean == null && getObjectId() != null) {
69             bean = session.loadBean(getObjectId());
70         }
71         return bean;
72     }
73
74     public void setBean(Object JavaDoc bean) {
75         this.bean = bean;
76     }
77
78     public Object JavaDoc getParent() {
79         if (parent == null && getParentId() != null) {
80             ListDefinition listDef = getListDefinition();
81             parent = EditorDefinitionUtils.loadParent(listDef, getParentId());
82         }
83         return parent;
84     }
85
86     public void setItemsTotal(int itemsTotal) {
87         this.itemsTotal = itemsTotal;
88     }
89
90     public int getItemsTotal() {
91         return itemsTotal;
92     }
93
94     public ListDefinition getListDefinition() {
95         return session.getListDefinition();
96     }
97
98     public ListConfig getListConfig() {
99         return getListDefinition().getListConfig();
100     }
101
102     public MessageResolver getMessageResolver() {
103         return session.getMessageResolver();
104     }
105
106     public String JavaDoc getObjectId() {
107         return item != null ? item.getObjectId() : null;
108     }
109
110     public ListParams getParams() {
111         return session.getParams();
112     }
113
114     public String JavaDoc getParentId() {
115         return session.getParentId();
116     }
117
118     public HttpServletRequest JavaDoc getRequest() {
119         return request;
120     }
121
122     public int getRowIndex() {
123         return item.getRowIndex();
124     }
125
126 }
Popular Tags