KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > riot > list > ListRepository


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;
25
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.riotfamily.common.xml.ConfigurationEventListener;
33 import org.riotfamily.riot.list.command.Command;
34 import org.riotfamily.riot.list.ui.render.CellRenderer;
35 import org.riotfamily.riot.list.ui.render.ObjectRenderer;
36 import org.springframework.context.ApplicationContext;
37 import org.springframework.context.ApplicationContextAware;
38
39 /**
40  *
41  */

42 public class ListRepository implements ApplicationContextAware {
43
44     private Log log = LogFactory.getLog(ListRepository.class);
45     
46     private HashMap JavaDoc listConfigs = new HashMap JavaDoc();
47     
48     private HashMap JavaDoc listConfigsByClass = new HashMap JavaDoc();
49     
50     private HashMap JavaDoc commands = new HashMap JavaDoc();
51     
52     private ApplicationContext applicationContext;
53     
54     private CellRenderer defaultCellRenderer;
55     
56     private int defaultPageSize = 50;
57
58     public ListRepository() {
59         setDefaultCellRenderer(new ObjectRenderer());
60     }
61
62     public void setApplicationContext(ApplicationContext applicationContext) {
63         this.applicationContext = applicationContext;
64         log.debug("Looking up command implementations ...");
65         Map JavaDoc commands = applicationContext.getBeansOfType(Command.class);
66         Iterator JavaDoc it = commands.values().iterator();
67         while (it.hasNext()) {
68             Command command = (Command) it.next();
69             this.commands.put(command.getId(), command);
70         }
71     }
72     
73     public void setRiotDaoService(RiotDaoService riotDaoService) {
74         riotDaoService.setListRepository(this);
75     }
76     
77     /**
78      * @return Returns the applicationContext.
79      */

80     protected ApplicationContext getApplicationContext() {
81         return applicationContext;
82     }
83     
84     public void addListener(ConfigurationEventListener listener) {
85     }
86     
87     public Command getCommand(String JavaDoc commandId) {
88         Command command = (Command) commands.get(commandId);
89         if (command == null) {
90             log.error("No such command: " + commandId);
91         }
92         return command;
93     }
94
95     public ListConfig getListConfig(String JavaDoc listId) {
96         return (ListConfig) listConfigs.get(listId);
97     }
98     
99     public ListConfig getListConfig(Class JavaDoc entityClass) {
100         return (ListConfig) listConfigsByClass.get(entityClass);
101     }
102     
103     public void addListConfig(ListConfig listConfig) {
104         listConfigs.put(listConfig.getId(), listConfig);
105         listConfigsByClass.put(listConfig.getDao().getEntityClass(), listConfig);
106         if (listConfig.getPageSize() == 0) {
107             listConfig.setPageSize(defaultPageSize);
108         }
109     }
110     
111     protected Map JavaDoc getListConfigsByClass() {
112         return this.listConfigsByClass;
113     }
114     
115     protected Map JavaDoc getListConfigs() {
116         return listConfigs;
117     }
118     
119     public CellRenderer getDefaultCellRenderer() {
120         return defaultCellRenderer;
121     }
122
123     public void setDefaultCellRenderer(CellRenderer defaultCellRenderer) {
124         this.defaultCellRenderer = defaultCellRenderer;
125     }
126     
127     public int getDefaultPageSize() {
128         return defaultPageSize;
129     }
130
131     public void setDefaultPageSize(int defaultPageSize) {
132         this.defaultPageSize = defaultPageSize;
133     }
134     
135 }
136
Popular Tags