📄 basemodel.java
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremecomponents.table.core;import java.util.ArrayList;import java.util.Collection;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.servlet.jsp.PageContext;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.extremecomponents.table.callback.RetrieveRowsCallback;import org.extremecomponents.table.cell.Cell;import org.extremecomponents.table.handler.ColumnHandler;import org.extremecomponents.table.handler.ExportHandler;import org.extremecomponents.table.handler.FormHandler;import org.extremecomponents.table.handler.RowHandler;import org.extremecomponents.table.handler.TableHandler;import org.extremecomponents.table.handler.TreeHandler;import org.extremecomponents.table.handler.ViewHandler;import org.extremecomponents.table.limit.Limit;import org.extremecomponents.table.limit.ModelLimitFactory;import org.extremecomponents.util.ExceptionUtils;/** * @author Paul Horn */public abstract class BaseModel { private static Log logger = LogFactory.getLog(BaseModel.class); private PageContext pageContext; protected BaseProperties properties; protected TableHandler tableHandler; private ParameterRegistry registry = new ParameterRegistry(this); private TableResourceBundle resourceBundle = new TableResourceBundle(this); private ExportHandler exportHandler = new ExportHandler(this); private FormHandler formHandler = new FormHandler(); private RowHandler rowHandler = new RowHandler(this); private ColumnHandler columnHandler = new ColumnHandler(this); private ViewHandler viewHandler = new ViewHandler(this); // model objects private Limit limit; private Object collectionOfBeans; private Object currentCollectionBean; // cache out some objects private Map cellCache = new HashMap(); private Map callbacks = new HashMap(); private AutoGenerateColumns autoGenerateColumns; public BaseModel(PageContext pageContext) { this.pageContext = pageContext; } /** * Access to the Servlet pageContext() */ public PageContext getPageContext() { return pageContext; } /** * A simple implementation of a cache for the Cell definitions. */ public Cell getCachedCell(Class classDefinition) { Cell cell = (Cell) cellCache.get(classDefinition); if (cell == null) { try { Object object = classDefinition.newInstance(); cell = (Cell) object; cellCache.put(classDefinition, cell); if (logger.isDebugEnabled()) { logger.debug("Cache the Cell [" + classDefinition + "]"); } } catch (Exception e) { logger.error("BaseModel.getCachedCell() " + ExceptionUtils.formatStackTrace(e)); } } return cell; } /** * Return the proper callback. The trick here is that could return the same * class for different callbacks. This is a feature so that do not have to * make different classes for each individual callback. */ public Object getCallback(String callbackClassName) throws Exception { Object result = callbacks.get(callbackClassName); if (result != null) { return result; } Class classDefinition = Class.forName(callbackClassName); result = classDefinition.newInstance(); callbacks.put(callbackClassName, result); return result; } public Map getCellCache() { return cellCache; } public ParameterRegistry getRegistry() { return registry; } public ColumnHandler getColumnHandler() { return columnHandler; } public TableHandler getTableHandler() { return tableHandler; } public TreeHandler getTreeHandler() { return (TreeHandler) tableHandler; } public RowHandler getRowHandler() { return rowHandler; } public ExportHandler getExportHandler() { return exportHandler; } public FormHandler getFormHandler() { return formHandler; } public BaseProperties getProperties() { return properties; } public TableResourceBundle getResourceBundle() { return resourceBundle; } public ViewHandler getViewHandler() { return viewHandler; } public List getCollectionOfBeans() { return (List) collectionOfBeans; } private void setCollectionOfBeans(Collection collectionOfBeans) throws Exception { this.collectionOfBeans = collectionOfBeans; if (collectionOfBeans == null) { String message = "The collection sent into the eXtremeTable is NULL."; logger.error(message); throw new Exception(message); } } public Object getCurrentCollectionBean() { return currentCollectionBean; } public void setCurrentCollectionBean(Object currentCollectionBean) { this.currentCollectionBean = currentCollectionBean; } public Limit getLimit() { return limit; } public AutoGenerateColumns getAutoGenerateColumns() { return autoGenerateColumns; } public void setAutoGenerateColumns(AutoGenerateColumns autoGenerateColumns) { this.autoGenerateColumns = autoGenerateColumns; } public Collection execute() throws Exception { this.limit = ModelLimitFactory.createInstanceOfLimit(this); ModelLimitFactory.setLimitFilterAndSortAttr(limit); RetrieveRowsCallback retrieveRowsCallback = (RetrieveRowsCallback) getCallback(getTableHandler().getTable() .getRetrieveRowsCallback()); Collection rows = retrieveRowsCallback.retrieveRows(this); rows = new ArrayList(rows); // copy for thread safety setCollectionOfBeans(rows); rows = executeInternal(rows, limit); viewHandler.setView(); return rows; } public void destroy() { properties = null; resourceBundle = null; tableHandler.destroy(); tableHandler = null; exportHandler.destroy(); exportHandler = null; formHandler.destroy(); formHandler = null; columnHandler.destroy(); columnHandler = null; rowHandler.destroy(); rowHandler = null; cellCache.clear(); cellCache = null; callbacks.clear(); callbacks = null; limit = null; collectionOfBeans = null; currentCollectionBean = null; autoGenerateColumns = null; } abstract Collection executeInternal(Collection rows, Limit limit) throws Exception;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -