admin@glassfish.java.net

Re: review

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Thu, 29 Mar 2007 16:15:01 -0700

This looks good!  Thanks for doing this, Senthil.

Ken

Senthil Chidambaram wrote:
Mike,
I'm checking in ComponentConfigPropsTableHandler.java with the changes for the MultipleDataProvider being moved to jsftemplating. I'm attaching the diffs with this, let me know if you've any questions.

We're going to remove the files under admin-gui/.../dataprovider folder once the tree opens.

thx
Senthil


/* * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the license at * https://glassfish.dev.java.net/public/CDDLv1.0.html or * glassfish/bootstrap/legal/CDDLv1.0.txt. * See the License for the specific language governing * permissions and limitations under the License. * * When distributing Covered Code, include this CDDL * Header Notice in each file and include the License file * at glassfish/bootstrap/legal/CDDLv1.0.txt. * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by * you own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * Copyright 2007 Sun Microsystems, Inc. All rights reserved. */ package com.sun.jbi.jsf.handlers; import java.io.StringReader; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Properties; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.xml.sax.InputSource; import com.sun.data.provider.RowKey; import com.sun.data.provider.TableDataProvider; import com.sun.jbi.jsf.bean.ArchiveBean; import com.sun.jbi.jsf.bean.JBIComponentConfigBean; import com.sun.jbi.jsf.bean.ComponentConfigurationEntry; import com.sun.jbi.jsf.bean.ShowBean; import com.sun.jbi.jsf.util.BeanUtilities; import com.sun.jsftemplating.annotation.Handler; import com.sun.jsftemplating.annotation.HandlerInput; import com.sun.jsftemplating.annotation.HandlerOutput; import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext; import com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider; import com.sun.webui.jsf.component.TableRowGroup; import com.sun.data.provider.impl.ObjectListDataProvider; import com.sun.jbi.ui.common.JBIAdminCommands; public class ComponentConfigPropsTableHandler { private static Logger logger = Logger.getLogger(ComponentConfigPropsTableHandler.class.getName()); /** Creates a new instance of TableHandler */ public ComponentConfigPropsTableHandler() { } /** * <p> This handler returns the selected row keys.</p> * * @param context The HandlerContext. */ @Handler(id="getSelectedTableRowKeys", input={ @HandlerInput(name="tableRowGroup", type=TableRowGroup.class, required=true)}, output={ @HandlerOutput(name="rowKeys", type=RowKey[].class)}) public static void getSelectedTableRowKeys(HandlerContext handlerCtx) { TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("tableRowGroup"); RowKey[] keys = trg.getSelectedRowKeys(); logger.fine("ComponentConfigPropsTableHandler.getSelectedTableRowKeys() = " + keys); handlerCtx.setOutputValue("rowKeys", keys); } /** * <p> This handler deletes the given <code>RowKey</code>s.</p> * * @param context The HandlerContext. */ @Handler(id="deleteTableRows", input={ @HandlerInput(name="tableRowGroup", type=TableRowGroup.class, required=true), @HandlerInput(name="rowKeys", type=RowKey[].class, required=true)}) public static void deleteTableRows(HandlerContext handlerCtx) { TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("tableRowGroup"); RowKey[] keys = (RowKey []) handlerCtx.getInputValue("rowKeys"); logger.fine("ComponentConfigPropsTableHandler.deleteTableRows() = " + keys); ObjectListDataProvider dp = (ObjectListDataProvider) trg.getSourceData(); for (RowKey key : keys) { dp.removeRow(key); logger.fine("delete Row with id = " + key.getRowId()); } } /** * <p> This handler commits the changes to a <code>TableRowGroup</code>'s * DataProvider.</p> * * @param context The HandlerContext. */ @Handler(id="commitTableRowGroup", input={ @HandlerInput(name="tableRowGroup", type=TableRowGroup.class, required=true)}) public static void commitTableRowGroup(HandlerContext handlerCtx) { TableRowGroup trg = (TableRowGroup) handlerCtx.getInputValue("tableRowGroup"); logger.fine("ComponentConfigPropsTableHandler.commitTableRowGroup() = " + trg); ObjectListDataProvider dp = (ObjectListDataProvider) trg.getSourceData(); dp.commitChanges(); } /** * <p> This handler takes in a HashMap, the name-value pair being the Properties. * It turns each name-value pair to one hashMap, representing one row of table data, * and returns the list of Map. * * <p> Output value: "TableList" -- Type: <code>java.util.List</code>/</p> * @param context The HandlerContext. */ @Handler(id="getJBIComponentConfigTableList", output={ @HandlerOutput(name="TableList", type=List.class)}) public static void getJBIComponentConfigTableList(HandlerContext handlerCtx) { JBIComponentConfigBean configBean = BeanUtilities.getJBIComponentConfigBean(); ObjectListDataProvider provider = (ObjectListDataProvider)configBean.getComponentNewConfigurationData(); List<ComponentConfigurationEntry> JbiXMLdata = provider.getList(); List data = new ArrayList(); logger.fine("ComponentConfigPropsTableHandler.getJBIComponentConfigTableList()"); if(JbiXMLdata != null && JbiXMLdata.size() > 0){ for(ComponentConfigurationEntry entry : JbiXMLdata){ HashMap oneRow = new HashMap(); oneRow.put("name", entry.getName()); oneRow.put("value", entry.getDefaultValue()); oneRow.put("selected", false); oneRow.put("rendered", false); oneRow.put("disabled", true); data.add(oneRow); logger.fine("property name =" + entry.getName()+ " def. value =" + entry.getDefaultValue()); } } handlerCtx.setOutputValue("TableList", data); } /** * <p> This handler takes TableRowGroup as input and returns a List of Map objects. * <p> The List returned contains Map objects with each Map representing one single row. * <p> This method only works for tables where each row consists of one single map * * <p> Input value: "TableRowGroup" -- Type: <code> com.sun.webui.jsf.component.TableRowGroup</code></p> * <p> Output value: "Rows" -- Type: <code> java.util.List</code></p> * @param context The HandlerContext. */ @Handler(id="getAllSingleMapRows", input={ @HandlerInput(name="TableRowGroup", type=TableRowGroup.class, required=true)}, output={ @HandlerOutput(name="Rows", type=List.class)}) public static void getAllSingleMapRows(HandlerContext handlerCtx) { TableRowGroup trg = (TableRowGroup)handlerCtx.getInputValue("TableRowGroup"); MultipleListDataProvider dp = (MultipleListDataProvider)trg.getSourceData(); List<List<Object>> data = dp.getLists(); logger.fine("ComponentConfigPropsTableHandler.getAllSingleMapRows() = " + data.get(0)); handlerCtx.setOutputValue("Rows", data.get(0)); } /** * <p> This handler adds one row to table * <p> Input value: "TableRowGroup" -- Type: <code> com.sun.webui.jsf.component.TableRowGroup</code></p> * <p> Input value: "NameList" -- Type:<code>java.util.List</code></p> * <p> Input value: "DefaultValueList" -- Type:<code>java.util.List</code></p> * <p> Input value: "HasSelected" -- Type:<code>java.lang.Boolean</code></p> * @param context The HandlerContext. */ @Handler(id="addRowToJBIComponentPropertiesTable", input={ @HandlerInput(name="TableRowGroup", type=TableRowGroup.class, required=true), @HandlerInput(name="NameList", type=List.class), @HandlerInput(name="HasSelected", type=Boolean.class), @HandlerInput(name="DefaultValueList", type=List.class)} ) public static void addRowToJBIComponentPropertiesTable(HandlerContext handlerCtx) { logger.fine("ComponentConfigPropsTableHandler.addRowToJBIComponentPropertiesTable()"); TableRowGroup trg = (TableRowGroup)handlerCtx.getInputValue("TableRowGroup"); List names = (List)handlerCtx.getInputValue("NameList"); List defaults = (List)handlerCtx.getInputValue("DefaultValueList"); Boolean hasSelected = (Boolean)handlerCtx.getInputValue("HasSelected"); MultipleListDataProvider dp = (MultipleListDataProvider)trg.getSourceData(); List<List<Object>> data = dp.getLists(); ListIterator li = data.listIterator(); while(li.hasNext()) { String name = null; String value = null; List list = (List)li.next(); Map map = new HashMap<String, Object>(); if(defaults != null && names != null) { if(names.size() == defaults.size()) { ListIterator ni = names.listIterator(); ListIterator dv = defaults.listIterator(); while(ni.hasNext() && dv.hasNext()) { name = (String)ni.next(); value = (String)dv.next(); map.put(name, value); } } else { ListIterator ni = names.listIterator(); while(ni.hasNext()) { name = (String)ni.next(); map.put(name, " "); } } } if( names != null && defaults == null) { ListIterator ni = names.listIterator(); while(ni.hasNext()) { name = (String)ni.next(); map.put(name, " "); } } if(names == null && defaults == null) { map.put("name", " "); map.put("value", " "); } if(hasSelected == null) { map.put("selected", false); } else { if(hasSelected.booleanValue()) { map.put("selected", false); } } // add row has it checkbox alway rendered map.put("rendered", true); // add row has it name columns alway enabled map.put("disabled", false); list.add(0, map); logger.fine("added property named =" + name + " with value = " + value); } } /** * <p> This handler returns the properties to be removed and added.</p> * * @param context The HandlerContext. */ @Handler(id="getAddRemoveJBIComponentProps", input={ @HandlerInput(name="NewList", type=List.class, required=true), @HandlerInput(name="NameList", type=ArrayList.class, required=true)}, output={ @HandlerOutput(name="AddProps", type=Map.class), @HandlerOutput(name="RemoveProps", type=ArrayList.class)}) public static void getAddRemoveJBIComponentProps(HandlerContext handlerCtx) { logger.fine("ComponentConfigPropsTableHandler.getAddRemoveJBIComponentProps()"); List newList = (List)handlerCtx.getInputValue("NewList"); ArrayList names = (ArrayList)handlerCtx.getInputValue("NameList"); JBIComponentConfigBean configBean = BeanUtilities.getJBIComponentConfigBean(); ObjectListDataProvider provider = (ObjectListDataProvider)configBean.getComponentNewConfigurationData(); List<ComponentConfigurationEntry> origList = provider.getList(); ListIterator nli = newList.listIterator(); ArrayList removeProps = new ArrayList(); Map addProps = new HashMap<String, String>(); while(nli.hasNext()) { Map props = (Map)nli.next(); if(!isOriginalEntry(origList,(String)props.get("name"))){ String name = (String)props.get("name"); if (name != null && (! name.trim().equals(""))) { addProps.put((String)props.get("name"), (String)props.get("value")); String value = (String)props.get("value"); value = value == null ? "" : value; ComponentConfigurationEntry entry = new ComponentConfigurationEntry(name,value,value,true); origList.add(entry); logger.fine("add new property named =" + props.get("name") + " with value=" + props.get("value")); } } else { UpdateOriginalEntry(origList,(String)props.get("name"),(String)props.get("value")); logger.fine("updating property named =" + props.get("name") + " with value=" + props.get("value")); } } provider.commitChanges(); handlerCtx.setOutputValue("AddProps", addProps); handlerCtx.setOutputValue("RemoveProps", removeProps); } /** * <p> This handler converts the table List to a Property map. * * @param context The HandlerContext. */ @Handler(id="convertRowsToJBIComponentProperties", input={ @HandlerInput(name="NewList", type=List.class, required=true)}, output={ @HandlerOutput(name="AddProps", type=Map.class)}) public static void convertRowsToProperties(HandlerContext handlerCtx) { List newList = (List)handlerCtx.getInputValue("NewList"); ListIterator li = newList.listIterator(); Map addProps = new HashMap<String, String>(); while(li.hasNext()) { Map props = (Map)li.next(); String name = (String)props.get("name"); if (name != null && (! name.trim().equals(""))) { addProps.put(name, (String)props.get("value")); } } handlerCtx.setOutputValue("AddProps", addProps); } /** * <p> This handler converts the table List to a Properties map. * * @param context The HandlerContext. */ @Handler(id="getJBIComponentProperties", input={ @HandlerInput(name="NewList", type=List.class, required=true)}, output={ @HandlerOutput(name="AddProps", type=Map.class)}) public static void getJBIComponentProperties(HandlerContext handlerCtx) { logger.fine("ComponentConfigPropsTableHandler.getJBIComponentProperties()"); List newList = (List)handlerCtx.getInputValue("NewList"); ListIterator li = newList.listIterator(); Map addProps = new Properties(); while(li.hasNext()) { Map props = (Map)li.next(); String name = (String)props.get("name"); if (name != null && (! name.trim().equals(""))) { String value = (String)props.get("value"); if (value != null && (! value.trim().equals(""))) { addProps.put(name, value); logger.fine("add to map property named =" + name + " and value=" + value); } } } handlerCtx.setOutputValue("AddProps", addProps); } private static boolean isOriginalEntry(List<ComponentConfigurationEntry> oldList, String newPropName) { for (Iterator iter = oldList.iterator(); iter.hasNext();) { ComponentConfigurationEntry entry = (ComponentConfigurationEntry) iter.next(); if(entry.getName().equals(newPropName)) { return true; } } return false; } private static void UpdateOriginalEntry(List<ComponentConfigurationEntry> oldList, String propName,String newValue) { for (Iterator iter = oldList.iterator(); iter.hasNext();) { ComponentConfigurationEntry entry = (ComponentConfigurationEntry) iter.next(); if(entry.getName().equals(propName)) { entry.setNewValue(newValue); } } } }

Index: ComponentConfigPropsTableHandler.java =================================================================== RCS file: /cvs/glassfish/admin-gui/src/java/com/sun/jbi/jsf/handlers/ComponentConfigPropsTableHandler.java,v retrieving revision 1.3 diff -c -r1.3 ComponentConfigPropsTableHandler.java *** ComponentConfigPropsTableHandler.java 27 Mar 2007 19:38:48 -0000 1.3 --- ComponentConfigPropsTableHandler.java 29 Mar 2007 23:02:40 -0000 *************** *** 49,57 **** import com.sun.jsftemplating.annotation.HandlerInput; import com.sun.jsftemplating.annotation.HandlerOutput; import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext; import com.sun.webui.jsf.component.TableRowGroup; import com.sun.data.provider.impl.ObjectListDataProvider; - import com.sun.enterprise.tools.admingui.dataprovider.MultipleListDataProvider; import com.sun.jbi.ui.common.JBIAdminCommands; --- 49,57 ---- import com.sun.jsftemplating.annotation.HandlerInput; import com.sun.jsftemplating.annotation.HandlerOutput; import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext; + import com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider; import com.sun.webui.jsf.component.TableRowGroup; import com.sun.data.provider.impl.ObjectListDataProvider; import com.sun.jbi.ui.common.JBIAdminCommands; *************** *** 175,181 **** TableRowGroup trg = (TableRowGroup)handlerCtx.getInputValue("TableRowGroup"); MultipleListDataProvider dp = (MultipleListDataProvider)trg.getSourceData(); ! List data = dp.getLists(); logger.fine("ComponentConfigPropsTableHandler.getAllSingleMapRows() = " + data.get(0)); handlerCtx.setOutputValue("Rows", data.get(0)); --- 175,181 ---- TableRowGroup trg = (TableRowGroup)handlerCtx.getInputValue("TableRowGroup"); MultipleListDataProvider dp = (MultipleListDataProvider)trg.getSourceData(); ! List<List<Object>> data = dp.getLists(); logger.fine("ComponentConfigPropsTableHandler.getAllSingleMapRows() = " + data.get(0)); handlerCtx.setOutputValue("Rows", data.get(0)); *************** *** 202,208 **** List defaults = (List)handlerCtx.getInputValue("DefaultValueList"); Boolean hasSelected = (Boolean)handlerCtx.getInputValue("HasSelected"); MultipleListDataProvider dp = (MultipleListDataProvider)trg.getSourceData(); ! List data = dp.getLists(); ListIterator li = data.listIterator(); while(li.hasNext()) { String name = null; --- 202,208 ---- List defaults = (List)handlerCtx.getInputValue("DefaultValueList"); Boolean hasSelected = (Boolean)handlerCtx.getInputValue("HasSelected"); MultipleListDataProvider dp = (MultipleListDataProvider)trg.getSourceData(); ! List<List<Object>> data = dp.getLists(); ListIterator li = data.listIterator(); while(li.hasNext()) { String name = null;