/* * 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://jsftemplating.dev.java.net/cddl1.html or * jsftemplating/cddl1.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 jsftemplating/cddl1.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 2006 Sun Microsystems, Inc. All rights reserved. */ package com.sun.jsftemplating.component.factory.sun; import com.sun.jsftemplating.annotation.UIComponentFactory; import com.sun.jsftemplating.component.factory.ComponentFactoryBase; import com.sun.jsftemplating.layout.descriptors.LayoutComponent; import com.sun.jsftemplating.util.LogUtil; import com.sun.jsftemplating.util.Util; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Map; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; /** *

This factory is responsible for instantiating a TableRowGroup * UIComponent.

* *

The {@link com.sun.jsftemplating.layout.descriptors.ComponentType} * id for this factory is: "sun:tableRowGroup".

* * @author Ken Paulsen (ken.paulsen@sun.com) */ @UIComponentFactory("sun:tableRowGroup") public class TableRowGroupFactory extends ComponentFactoryBase { /** *

This is the factory method responsible for creating the * UIComponent.

* * @param context The FacesContext * @param descriptor The {@link LayoutComponent} descriptor associated * with the requested UIComponent. * @param parent The parent UIComponent * * @return The newly created TableRowGroup. */ public UIComponent create(FacesContext context, LayoutComponent descriptor, UIComponent parent) { // Create the UIComponent UIComponent comp = context.getApplication().createComponent(COMPONENT_TYPE); // This needs to be done here (before setOptions) so that $...{...} // expressions can be resolved... may want to defer these? if (parent != null) { addChild(context, descriptor, parent, comp); } // Set all the attributes / properties setOptions(context, descriptor, comp); // Handle "data" option specially... Object data = descriptor.getEvaluatedOption(context, "data", comp); if (data != null) { // Create a DataProvider if (!(data instanceof List)) { throw new IllegalArgumentException("TableRowGroupFactory " + "only supports values of type \"java.util.List\" " + "for the 'data' attribute."); } if ((((List) data).size() > 0) && !(((List) data).get(0) instanceof List)) { Object obj = ((List) data).get(0); if (obj == null) { if (LogUtil.configEnabled()) { LogUtil.config("WEBUI0008"); } } else { obj = obj.getClass().getName(); // We don't have a List of List of Object! throw new IllegalArgumentException("TableRowGroupFactory " + "expects a List>. Where the outer " + "List should be a List of sources, and the inner" + " List should be a List of rows. However, the " + "following was passed in: List<" + obj + ">."); } } List> lists = (List>) data; Object dataProvider = createDataProvider(lists); // Remove the data object from the UIComponent, not needed Map atts = comp.getAttributes(); atts.remove("data"); // FIXME: This stores the *data* in the UIComponent... change to use a #{} value binding to push the data somewhere else. Session?? Configurable? atts.put("sourceData", dataProvider); } // Return the component return comp; } /** *

This is a factory method for creating an appropriate * DataProvider.

*/ private Object createDataProvider(List> data) { // Use reflection (for now) to avoid a build dependency // Find the Option constuctor... try { return Util.getClassLoader(data). // loadClass("com.sun.data.provider.impl.ObjectListDataProvider"). loadClass("com.sun.enterprise.tools.admingui.dataprovider.MultipleListDataProvider"). getConstructor(List.class, Boolean.TYPE). newInstance(data, false); } catch (ClassNotFoundException ex) { throw new RuntimeException("Unable to find DataProvider API's! " + "Ensure dataprovider.jar is present.", ex); } catch (NoSuchMethodException ex) { throw new RuntimeException("Unable to create DataProvider! " + "Ensure correct dataprovider.jar is present.", ex); } catch (InstantiationException ex) { throw new RuntimeException("Unable to create DataProvider! " + "Ensure correct dataprovider.jar is present.", ex); } catch (IllegalAccessException ex) { throw new RuntimeException("Unable to create DataProvider! " + "Ensure correct dataprovider.jar is accessible.", ex); } catch (InvocationTargetException ex) { throw new RuntimeException("Unable to create DataProvider!", ex); } } /** *

The UIComponent type that must be registered in the * faces-config.xml file mapping to the UIComponent class * to use for this UIComponent.

*/ public static final String COMPONENT_TYPE = "com.sun.webui.jsf.TableRowGroup"; }