Author: ekoneil
Date: Wed Mar 16 19:19:18 2005
New Revision: 157873

URL: http://svn.apache.org/viewcvs?view=rev&rev=157873
Log:
Cleanup in the data grid.

Also implement custom DataGridConfig implementations.  Also adds an 
ExtensionUtil class that exposes a method to create an instance of a type.

Remove comment block in DataGridTagModel.

BB: self
DRT: NetUI pass


Added:
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/ExtensionUtil.java
   (with props)
Modified:
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/DataGridConfigFactory.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/ConfigurePager.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGridUtil.java
    
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/HeaderCell.java

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/DataGridConfigFactory.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/DataGridConfigFactory.java?view=diff&r1=157872&r2=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/DataGridConfigFactory.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/DataGridConfigFactory.java
 Wed Mar 16 19:19:18 2005
@@ -18,12 +18,14 @@
 package org.apache.beehive.netui.databinding.datagrid.api;
 
 import 
org.apache.beehive.netui.databinding.datagrid.runtime.config.DefaultDataGridConfig;
+import 
org.apache.beehive.netui.databinding.datagrid.runtime.util.ExtensionUtil;
 
 /**
  *
  */
 public final class DataGridConfigFactory {
 
+    /* do not construct */
     private DataGridConfigFactory() {
     }
 
@@ -32,6 +34,7 @@
     }
 
     public static final DataGridConfig getInstance(Class clazz) {
-        throw new UnsupportedOperationException("NYI");
+        DataGridConfig config = 
(DataGridConfig)ExtensionUtil.instantiateClass(clazz, DataGridConfig.class);
+        return config;
     }
 }

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java?view=diff&r1=157872&r2=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/CellModel.java
 Wed Mar 16 19:19:18 2005
@@ -70,8 +70,7 @@
             } catch(JspException e) {
                 e.printStackTrace();
                 /* todo: error reporting */
-                if(LOGGER.isErrorEnabled())
-                    LOGGER.error("A formatter of type \"" + 
formatter.getClass().getName() + "\" threw an exception " + e, e);
+                LOGGER.error("A formatter of type \"" + 
formatter.getClass().getName() + "\" threw an exception " + e, e);
             }
         }
 

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java?view=diff&r1=157872&r2=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/api/rendering/DataGridTagModel.java
 Wed Mar 16 19:19:18 2005
@@ -204,10 +204,8 @@
         overrideResourceProvider.addResourceOverride(key, value);
     }
 
-    /* todo: move to the DataGridConfig object */
+    /* todo: fix the message here to format with the context path */
     public String getResourcePath() {
-        assert _request != null : "Received a null request";
-        /* todo: not sure that this is right in all cases -- probably need to 
provide the ability to override the path from the JSP */
         return _request.getContextPath() + "/" + 
getMessage(IDataGridMessageKeys.DATAGRID_RESOURCE_PATH);
     }
 
@@ -241,41 +239,7 @@
         return _urlBuilder;
     }
 
-    /* todo: Move these methods to a DataGridURL class. */
-/*    
-    public Map<String, String[]> getSortQueryParamsMap(String sortExpression) {
-        return _urlBuilder.buildSortQueryParamsMap(sortExpression);
-    }
-
-    public Map buildSortQueryParamsMap() {
-        return _urlBuilder.getQueryParams();
-    }
-
-    public Map getQueryParamsForFirstPage() {
-        return _urlBuilder.getQueryParamsForFirstPage();
-    }
-
-    public Map getQueryParamsForPreviousPage() {
-        return _urlBuilder.getQueryParamsForPreviousPage();
-    }
-
-    public Map getQueryParamsForNextPage() {
-        return _urlBuilder.getQueryParamsForNextPage();
-    }
-
-    public Map getQueryParamsForLastPage() {
-        return _urlBuilder.getQueryParamsForLastPage();
-    }
-
-    public String[] getPagerParamValues() {
-        return _urlBuilder.getPagerParamValues();
-    }
-
-    public String getPagerRowQueryParamKey() {
-        return _urlBuilder.getPagerRowQueryParamKey();
-    }
-*/
-    /* these should go away in favor of calling them on the PagedDataSet */
+    /* todo: these should go away in favor of calling them on the PagedDataSet 
*/
     public int getCurrentIndex() {
         return _dataSet.getCurrentIndex();
     }

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java?view=diff&r1=157872&r2=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/config/DefaultDataGridStateCodec.java
 Wed Mar 16 19:19:18 2005
@@ -75,9 +75,9 @@
     private DefaultDataGridURLBuilder _urlBuilder = null;
 
     DefaultDataGridStateCodec(DataGridConfig config) {
-        _state = new DataGridState();
-        _urlBuilder = new DefaultDataGridURLBuilder(getGridName(), this, 
_state);
         _config = config;
+        _state = _config.createDataGridState();
+        _urlBuilder = new DefaultDataGridURLBuilder(getGridName(), this, 
_state);
     }
 
     public DataGridState getDataGridState() {
@@ -208,7 +208,7 @@
             else addParam(key, values);
         }
 
-        /* hack! -- there are wireup issues here! */
+        /* todo: -- there are wireup issues here! */
         if(_state.getSortModel() == null)
             _state.setSortModel(_config.createSortModel(null));
         if(_state.getFilterModel() == null)
@@ -279,8 +279,9 @@
                 sortDirection = SortDirection.DESCENDING;
             else sortDirection = SortDirection.ASCENDING;
             String sortExpression = (sortDirection == SortDirection.DESCENDING 
? sort.substring(1) : sort);
-            Sort gridSort = new Sort(sortExpression, sortDirection);
-
+            Sort gridSort = _config.createSort();
+            gridSort.setSortExpression(sortExpression);
+            gridSort.setDirection(sortDirection);
             sorts.add(gridSort);
         }
 
@@ -332,10 +333,8 @@
                 continue;
             else if(terms.length == 3) {
                 try {
-                    /* todo: refactor.  need to map String to FilterOperation 
*/
                     FilterOperation fOp = 
SQLSupport.mapStringToOperation(terms[1]);
-
-                    filter = new Filter();
+                    filter = _config.createFilter();
                     filter.setFilterExpression(terms[0]);
                     filter.setOperation(fOp);
                     filter.setValue(terms[2]);

Added: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/ExtensionUtil.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/ExtensionUtil.java?view=auto&rev=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/ExtensionUtil.java
 (added)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/ExtensionUtil.java
 Wed Mar 16 19:19:18 2005
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * 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.
+ *
+ * $Header:$
+ */
+package org.apache.beehive.netui.databinding.datagrid.runtime.util;
+
+import 
org.apache.beehive.netui.databinding.datagrid.api.exceptions.DataGridExtensionException;
+import org.apache.beehive.netui.util.logging.Logger;
+
+/**
+ *
+ */
+public final class ExtensionUtil {
+
+    private static final Logger LOGGER = 
Logger.getInstance(ExtensionUtil.class);
+
+    private ExtensionUtil() {}
+
+    /**
+     * Utility method that helps instantiate a class used to extend the data 
grid.
+     *
+     * @param className the name of a class to instantiate
+     * @return an instance of the given class
+     * @throws 
org.apache.beehive.netui.databinding.datagrid.api.exceptions.DataGridExtensionException
 when an error occurs creating an instance of the class
+     */
+    public static final Object instantiateClass(String className, Class 
assignableFrom) {
+        if(className == null)
+            throw new IllegalArgumentException("Can not create an instance of 
a null class");
+
+        Class clazz = null;
+        try {
+            clazz = Class.forName(className, false, 
Thread.currentThread().getContextClassLoader());
+        }
+        catch(Exception e) {
+            assert e instanceof IllegalAccessException ||
+                   e instanceof InstantiationException ||
+                   e instanceof ClassNotFoundException : "Caught exception of 
unexpected type: " + e.getClass().getName();
+
+            String msg = "Unable to extend data grid.  Can't instantiate 
extension class.  Cause: " + e.getMessage();
+            LOGGER.error(msg, e);
+
+            throw new DataGridExtensionException(msg, e);
+        }
+
+        return instantiateClass(clazz, assignableFrom);
+    }
+
+    /**
+     * Utility method that helps instantiate a class used to extend the data 
grid.
+     *
+     * @param clazz the name of a class to instantiate
+     * @return an instance of the given class
+     * @throws 
org.apache.beehive.netui.databinding.datagrid.api.exceptions.DataGridExtensionException
 when an error occurs creating an instance of the class
+     */
+    public static final Object instantiateClass(Class clazz, Class 
assignableFrom) {
+
+        if(clazz == null)
+            throw new IllegalArgumentException("Can not create an instance of 
a null class");
+
+        try {
+            Object obj = clazz.newInstance();
+
+            if(assignableFrom == null || 
assignableFrom.isAssignableFrom(clazz))
+                return obj;
+            else throw new DataGridExtensionException("Invalid data grid 
extension.  The class \"" + clazz.getName() + "\" is not a subclass or sub 
interface of \"" + assignableFrom + "\"");
+        }
+        catch(Exception e) {
+            assert
+                e instanceof DataGridExtensionException ||
+                e instanceof IllegalAccessException ||
+                e instanceof InstantiationException ||
+                e instanceof ClassNotFoundException : "Caught exception of 
unexpected type " + e.getClass().getName();
+
+            String msg = "Unable to extend data grid.  Can't instantiate 
extension class.  Cause: " + e.getMessage();
+            if(LOGGER.isErrorEnabled())
+                LOGGER.error(msg, e);
+
+            throw new DataGridExtensionException(msg, e);
+        }
+    }
+}

Propchange: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/databinding/datagrid/runtime/util/ExtensionUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/ConfigurePager.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/ConfigurePager.java?view=diff&r1=157872&r2=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/ConfigurePager.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/ConfigurePager.java
 Wed Mar 16 19:19:18 2005
@@ -26,6 +26,7 @@
 import 
org.apache.beehive.netui.databinding.datagrid.runtime.rendering.pager.FirstPreviousNextLastPagerRenderer;
 import 
org.apache.beehive.netui.databinding.datagrid.runtime.rendering.pager.PreviousNextPagerRenderer;
 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
+import 
org.apache.beehive.netui.databinding.datagrid.runtime.util.ExtensionUtil;
 import org.apache.beehive.netui.databinding.datagrid.api.pager.PagerModel;
 import org.apache.beehive.netui.tags.AbstractSimpleTag;
 import org.apache.beehive.netui.util.logging.Logger;
@@ -133,7 +134,7 @@
 
         if(_pagerRendererClass != null) {
             try {
-                pagerRenderer = 
(PagerRenderer)DataGridUtil.instantiateClass(_pagerRendererClass, 
PagerRenderer.class);
+                pagerRenderer = 
(PagerRenderer)ExtensionUtil.instantiateClass(_pagerRendererClass, 
PagerRenderer.class);
 
                 assert pagerRenderer != null : "Expected a non-null pager 
renderer of type \"" + _pagerRendererClass + "\"";
             }

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGridUtil.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGridUtil.java?view=diff&r1=157872&r2=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGridUtil.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/DataGridUtil.java
 Wed Mar 16 19:19:18 2005
@@ -71,39 +71,4 @@
         assert jspContext.getAttribute(CELL_MODEL_KEY) != null : "Did not find 
a ColumnModel under the key " + CELL_MODEL_KEY;
         jspContext.removeAttribute(CELL_MODEL_KEY);
     }
-
-    /**
-     * Package protected method that helps instantiate a class used to extend 
the
-     * data grid.
-     *
-     * @param className the name of a class to instantiate
-     * @return an instance of the given class
-     * @throws DataGridExtensionException when an error occurs creating an 
instance of the class
-     */
-    static final Object instantiateClass(String className, Class 
assignableFrom) {
-        if(className == null)
-            throw new IllegalArgumentException("Can not create an instance of 
a null class for the type \"" + assignableFrom + "\"");
-
-        try {
-            Class clazz = Class.forName(className, true, 
Thread.currentThread().getContextClassLoader());
-            Object obj = clazz.newInstance();
-
-            if(assignableFrom == null || 
assignableFrom.isAssignableFrom(clazz))
-                return obj;
-            else throw new DataGridExtensionException("Invalid data grid 
extension.  The class \"" + className + "\" is not a subclass or sub interface 
of \"" + assignableFrom + "\"");
-        }
-        catch(Exception e) {
-            assert
-                e instanceof DataGridExtensionException ||
-                e instanceof IllegalAccessException ||
-                e instanceof InstantiationException ||
-                e instanceof ClassNotFoundException : "Caught exception of 
unexpected type " + e.getClass().getName();
-
-            String msg = "Unable to extend data grid.  Can't instantiate 
extension class.  Cause: " + e.getMessage();
-            if(LOGGER.isErrorEnabled())
-                LOGGER.error(msg, e);
-
-            throw new DataGridExtensionException(msg, e);
-        }
-    }
 }

Modified: 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/HeaderCell.java
URL: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/HeaderCell.java?view=diff&r1=157872&r2=157873
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/HeaderCell.java
 (original)
+++ 
incubator/beehive/trunk/netui/src/tags-databinding/org/apache/beehive/netui/tags/databinding/datagrid/HeaderCell.java
 Wed Mar 16 19:19:18 2005
@@ -37,6 +37,7 @@
 import 
org.apache.beehive.netui.databinding.datagrid.runtime.rendering.cell.SortedCellDecorator;
 import 
org.apache.beehive.netui.databinding.datagrid.runtime.rendering.table.TableRenderer;
 import org.apache.beehive.netui.databinding.datagrid.runtime.util.JspUtil;
+import 
org.apache.beehive.netui.databinding.datagrid.runtime.util.ExtensionUtil;
 import org.apache.beehive.netui.databinding.datagrid.api.sort.SortModel;
 import org.apache.beehive.netui.databinding.datagrid.api.filter.FilterModel;
 
@@ -520,19 +521,19 @@
         else if(facet != null && facet.equals(FACET_RENDERER_NAME)) {
             /* provides a way to extend the existing decorators */
             if(name.equals(FACET_RENDERER_NAME_EXTENDS)) {
-                CellDecorator cellDecorator = 
(CellDecorator)DataGridUtil.instantiateClass(value, CellDecorator.class);
+                CellDecorator cellDecorator = 
(CellDecorator)ExtensionUtil.instantiateClass(value, CellDecorator.class);
                 cellDecorator.setNestedDecorator(getCellDecorator());
                 _cellDecorator = cellDecorator;
                 return;
             }
             else if(name.equals(FACET_RENDERER_NAME_SORT)) {
-                CellDecorator cellDecorator = 
(CellDecorator)DataGridUtil.instantiateClass(value, CellDecorator.class);
+                CellDecorator cellDecorator = 
(CellDecorator)ExtensionUtil.instantiateClass(value, CellDecorator.class);
                 cellDecorator.setNestedDecorator(DECORATOR_HEADER_SORTED);
                 _cellDecorator = cellDecorator;
             }
             /* replace the core cell decorator with a new default */
             else if(name.equals(FACET_RENDERER_NAME_DEFAULT)) {
-                CellDecorator cellDecorator = 
(CellDecorator)DataGridUtil.instantiateClass(value, CellDecorator.class);
+                CellDecorator cellDecorator = 
(CellDecorator)ExtensionUtil.instantiateClass(value, CellDecorator.class);
                 _cellDecorator = cellDecorator;
             }
         }


Reply via email to