1 24 package org.riotfamily.riot.list; 25 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 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 42 public class ListRepository implements ApplicationContextAware { 43 44 private Log log = LogFactory.getLog(ListRepository.class); 45 46 private HashMap listConfigs = new HashMap (); 47 48 private HashMap listConfigsByClass = new HashMap (); 49 50 private HashMap commands = new HashMap (); 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 commands = applicationContext.getBeansOfType(Command.class); 66 Iterator 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 80 protected ApplicationContext getApplicationContext() { 81 return applicationContext; 82 } 83 84 public void addListener(ConfigurationEventListener listener) { 85 } 86 87 public Command getCommand(String 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 listId) { 96 return (ListConfig) listConfigs.get(listId); 97 } 98 99 public ListConfig getListConfig(Class 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 getListConfigsByClass() { 112 return this.listConfigsByClass; 113 } 114 115 protected Map 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 |