001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.sessioninspector.jsf.model; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.nuxeo.ecm.platform.ui.web.binding.alias.AliasVariableMapper; 023 024/** 025 * Wrapper for a generic UIComponent state. 026 * 027 * @since 5.9.2 028 */ 029public class UIComponentWrapper { 030 031 protected final String id; 032 033 protected final Object[] state; 034 035 public UIComponentWrapper(String id, Object[] object) { 036 this.id = id; 037 this.state = object; 038 } 039 040 public String getId() { 041 return id; 042 } 043 044 public List<String> getFlatState() { 045 List<String> res = new ArrayList<String>(); 046 if (state != null) { 047 for (Object item : state) { 048 if (item == null) { 049 continue; 050 } 051 if (item instanceof Object[]) { 052 res.addAll(new UIComponentWrapper(id, (Object[]) item).getFlatState()); 053 } else if (item instanceof AliasVariableMapper) { 054 AliasVariableMapper vm = (AliasVariableMapper) item; 055 res.add(String.format("AliasVariableMapper(%s, %s)", vm.getId(), vm.getVariables())); 056 } else { 057 res.add(item.toString()); 058 } 059 } 060 } 061 return res; 062 } 063}