/** * Copyright (C) 2008-2010, Squale Project - http://www.squale.org * * This file is part of Squale. * * Squale is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 of the * License, or any later version. * * Squale is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Squale. If not, see <http://www.gnu.org/licenses/>. */ package org.squale.squaleweb.transformer; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import org.squale.squalecommon.datatransfertobject.result.ErrorDTO; import org.squale.squaleweb.applicationlayer.formbean.component.ErrorForm; import org.squale.squaleweb.applicationlayer.formbean.component.ErrorListForm; import org.squale.squaleweb.resources.WebMessages; import org.squale.welcom.struts.bean.WActionForm; import org.squale.welcom.struts.transformer.WITransformer; import org.squale.welcom.struts.transformer.WTransformArrayList; import org.squale.welcom.struts.transformer.WTransformerException; import org.squale.welcom.struts.transformer.WTransformerFactory; /** * Transforme des listes d'erreurs Form <-> DTO * * @author M400842 */ public class ErrorListTransformer extends AbstractListTransformer { /** * @param pObject le tableau de ProjectDTO � transformer en formulaires. * @throws WTransformerException si un pb appara�t. * @return le formulaire associ� */ public WActionForm objToForm( Object[] pObject ) throws WTransformerException { ErrorListForm form = new ErrorListForm(); objToForm( pObject, form ); return form; } /** * @param pObject le tableau de ProjectDTO � transformer en formulaires. * @param pForm le formulaire � remplir. * @throws WTransformerException si un pb appara�t. */ public void objToForm( Object[] pObject, WActionForm pForm ) throws WTransformerException { Collection dto = (Collection) pObject[1]; HashMap map = new HashMap(); ErrorListForm form = (ErrorListForm) pForm; if ( null != dto ) { Iterator it = dto.iterator(); while ( it.hasNext() ) { ErrorForm error = null; if (pObject.length == 4){ Object[] objects = new Object[]{ (ErrorDTO) it.next(), (Locale) pObject[3] }; error = (ErrorForm) WTransformerFactory.objToForm( ErrorTransformer.class, objects ); } else { error = (ErrorForm) WTransformerFactory.objToForm( ErrorTransformer.class, (ErrorDTO) it.next() ); } // On ins�re dans la map avec le message en cl� if ( map.get( error.getMessage() ) != null ) { error = (ErrorForm) map.get( error.getMessage() ); error.setNbOcc( error.getNbOcc() + 1 ); } map.put( error.getMessage(), error ); } } form.setList( new ArrayList( map.values() ) ); if (pObject.length == 4){ form.setTaskName( WebMessages.getString( (Locale) pObject[3], (String) pObject[0] + ".name" ) ); } else { form.setTaskName( WebMessages.getString( (String) pObject[0] + ".name" ) ); } form.setMaxErrorLevel( (String) pObject[2] ); } /** * @param pForm le formulaire � lire. * @param pObject le tableau de ProjectDTO qui r�cup�re les donn�es du formulaire. * @throws WTransformerException si un pb appara�t. */ public void formToObj( WActionForm pForm, Object[] pObject ) throws WTransformerException { ArrayList listObject = (ArrayList) pObject[0]; ArrayList listForm = (ArrayList) ( (ErrorListForm) pForm ).getList(); WITransformer auditTransformer = WTransformerFactory.getSingleTransformer( AuditTransformer.class ); WTransformArrayList.formToObj( listForm, listObject, auditTransformer ); } }