Package org.boco.seamwebappgen.info

Source Code of org.boco.seamwebappgen.info.InfoReader

/***************************************************************************
*  Copyright (c) 2004 - 2008  Fabrizio Boco fabboco@users.sourceforge.net *
*                                                                         *
*                                                                         *
*   This is free software; you can redistribute it and/or                 *
*   modify it under the terms of the GNU Library General Public           *
*   License (version 2.1) as published by the Free Software Foundation    *
*                                                                         *
*   This library  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 Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this library; see the file COPYING.LIB. If not,    *
*   write to the Free Software Foundation, Inc., 59 Temple Place,         *
*   Suite 330, Boston, MA  02111-1307, USA                                *
*                                                                         *
***************************************************************************/


/**
- $Header: /usr/local/cvslocalrepository/SeamWebAppGenerator/src/org/boco/seamwebappgen/info/Attic/InfoReader.java,v 1.1.2.7 2008/06/05 17:16:13 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.7 $
- $Date: 2008/06/05 17:16:13 $
- $Log: InfoReader.java,v $
- Revision 1.1.2.7  2008/06/05 17:16:13  fab
- Modifiche per
-
- - Ajax support on bean fields
- - disableOnCreateIf and disableOnEditIf for the relationship
- - listFormatOff added to @ShowInForm
-
- Revision 1.1.2.6  2008/06/02 09:11:31  fab
- *** empty log message ***
-
- Revision 1.1.2.5  2008/05/25 10:07:23  fab
- Rimossa annotazione @CRUDInSeparatePopUp
- Nuova implementation type CRUDPOPUP e relativa gestione
-
- Revision 1.1.2.4  2008/05/22 19:29:12  fab
- Implementazione 0876/C
-
- Revision 1.1.2.3  2008/05/15 09:30:13  fab
- Gestione di azioni su tutti i bean risultato di una ricerca
-
- Revision 1.1.2.2  2008/04/22 05:37:57  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.1  2008/04/19 13:12:42  fab
- Modifiche varie per rafactoring
-
- Revision 1.1.2.1  2008/04/19 11:18:29  fab
- Refactoring
-
- Revision 1.15.4.8  2008/04/19 10:07:01  fab
- Aggiornamento riferimenti licenza
-
- Revision 1.15.4.7  2008/04/13 09:00:55  fab
- Implementazione 0182/C
-
- Revision 1.15.4.6  2008/04/02 13:25:04  fab
- Implementazione 0626/C
-
- Revision 1.15.4.5  2008/04/02 11:57:08  fab
- Implementazione 0663/C
-
- Revision 1.15.4.4  2008/03/27 20:29:44  fab
- *** empty log message ***
-
- Revision 1.15.4.3  2008/03/27 20:11:16  fab
- Inserita security sulla ricercca globale
-
- Revision 1.15.4.2  2008/03/26 08:36:48  fab
- Implementazione 0627/C
-
- Revision 1.15.4.1  2008/03/22 16:51:58  fab
- *** empty log message ***
-
- Revision 1.15  2008/01/28 16:31:46  fab
- Implementazione 0544/C
-
- Revision 1.14  2008/01/05 09:18:48  fab
- Fix vari per la corretta gestione dello implementationType
-
- Revision 1.13  2007/12/30 12:23:15  fab
- Inserimento HtmlEditor
- Fix generazione jar
-
- Revision 1.12  2007/12/23 13:19:06  fab
- Fix per la corretta gestione delle relazioni da e verso bean padre
-
- Revision 1.11  2007/11/06 15:36:17  fab
- Rinominata Ignore in IgnoreBean
-
- Revision 1.10  2007/11/04 18:12:10  fab
- *** empty log message ***
-
- Revision 1.9  2007/11/02 11:02:09  fab
- Aggiornamento della @ShowList
-
- Revision 1.8  2007/11/02 10:56:47  fab
- Aggiornamento della @ShowList
-
- Revision 1.7  2007/10/30 09:56:31  fab
- Versione iniziale per implmentazione 0303/C
-
- Revision 1.6  2007/10/30 09:07:54  fab
- Implementazione 0301/C
-
- Revision 1.5  2007/10/25 09:54:19  fab
- Dopo merge TRINIDAD_1.2.2
-
- Revision 1.1.2.3  2007/10/24 06:51:06  fab
- Fix vari dal ramo head
-
- Revision 1.4  2007/10/03 11:35:45  fab
- Implementazione 0141/C
-
- Opzione formatOff  in @ShowInForm
-
- Revision 1.3  2007/10/03 08:13:23  fab
- Implementazione 0140/C
-
- Opzione formatOff  in @ShowAttributeInList
-
- Revision 1.2  2007/10/02 05:34:55  fab
- Implementata la 0124/C
- Aggiornata la documentazione
-
- Revision 1.1  2007/09/29 13:17:04  fab
- Nuova versione iniziale del 29/09/2007
-
- Revision 1.10.2.52  2007/09/26 08:02:35  fab
- Supporto per nuova annotazione IgnorePrintListForm e
- Supporto alla nuova opzione per @ShowList
-
- Revision 1.10.2.51  2007/09/26 06:34:56  fab
- Fix per l'ordinamento dei campi transient
-
- Revision 1.10.2.50  2007/09/11 12:25:00  fab
- Fix per formattazione dei metodi transient nei form
-
- Revision 1.10.2.49  2007/09/11 09:07:27  fab
- Inserita l'annotazione CRUDInSeparatePopUp
-
- Revision 1.10.2.48  2007/09/04 13:55:34  fab
- Ordinati i method dei bean letti dalla classe
-
- Revision 1.10.2.47  2007/09/03 20:48:15  fab
- Fix ordinamento campi dei bean letti dalla classe
-
- Revision 1.10.2.46  2007/09/03 20:45:01  fab
- Ordinati i method dei bean letti dalla classe
-
- Revision 1.10.2.45  2007/09/03 20:37:14  fab
- Refactoring dei comparatori in un package separato
- Ordinati i campi dei bean letti dalla classe
-
- Revision 1.10.2.44  2007/09/03 13:35:52  fab
- Nella annotazione @ShowRelationshipAttributesInForm inserite le informazioni per la visualizzazione condizionele:
-
- showOnCreateIf, showOnEditIf, ecc
-
- Revision 1.10.2.43  2007/08/30 20:29:06  fab
- Introdotta gestione annotazione @FormFieldsGroups
-
- Revision 1.10.2.42  2007/08/29 16:39:12  fab
- Gestione degli attributi
-
- showOnEditIf
- showOnDeleteIf
- showOnCreateIf
- showOnDisplayIf
-
- per l'annotazione @Relationship
-
- Revision 1.10.2.41  2007/08/29 12:46:22  bob
- Tolta 'a' ed 'e' accentate
-
- Revision 1.10.2.40  2007/08/21 17:59:54  fab
- Modifiche per supportare l'attributo goToMasterMenuItem nell'annotazione @Relationship
-
- Revision 1.10.2.39  2007/08/02 14:16:17  fab
- Fix per  @ShowRelationshipsAttributesInForm in ordine errato nel form
-
- Revision 1.10.2.38  2007/07/25 14:21:24  fab
- Fix @ShowAttributeInList per relazioni 1:1
-
- Revision 1.10.2.37  2007/07/17 09:52:26  fab
- Fix per evitare che i campi transient con annotazione @ShowTransientInForm comparissero due volte nel form
-
- Revision 1.10.2.36  2007/07/13 16:16:11  fab
- Inserita gestione validatorId nella @ShowInForm
-
- Revision 1.10.2.35  2007/07/10 16:34:32  fab
- Fix per il corretto riferimento al bean MASTER quando un bean è DETAIL in più relazioni MASTER-DETAIL
-
- Revision 1.10.2.34  2007/07/10 07:07:59  fab
- Fix corretta gestione @ShowTransientInForm
-
- Revision 1.10.2.33  2007/07/09 09:03:27  fab
- *** empty log message ***
-
- Revision 1.10.2.32  2007/07/08 16:39:31  fab
- Ordinati i campi del bean dopo la lettura
-
- Revision 1.10.2.31  2007/07/06 13:29:30  fab
- Fix nella getBeanShowAttributes per mantere l'ordinamento relativo degli attributi del bean e quelli provenienti dalle relazioni
-
- Revision 1.10.2.30  2007/07/01 12:43:19  fab
- Corretta lettura delle informazioni onDelete onEdit onDisplay onCreate delle relazioni
-
- Revision 1.10.2.29  2007/06/30 08:10:02  fab
- Inserite opzioni:
-
- onCreateIf
- onEditIf
- onDisplayIf
- onDeleteIf
-
- per le relazioni ma non ancora gestite
-
- Revision 1.10.2.28  2007/06/25 21:18:07  fab
- Eliminata System.out inutile
-
- Revision 1.10.2.27  2007/06/23 09:15:47  fab
- Fix per la gestione di relatedAndNewItemsOnlyInPopUp con chiavi a componenti multiple
-
- Revision 1.10.2.26  2007/06/19 06:58:53  fab
- Fix per la corretta gestione dei @ShowRelationshipAttributesInForm quando gli attributi sono nella forma [relationship.]*attribute
-
- Revision 1.10.2.25  2007/06/16 12:25:11  fab
- Modifiche per supportare l'upload dei files con Trinidad - La versione esistente con Seam non funzionava
-
- Revision 1.10.2.24  2007/06/13 06:37:22  fab
- Inserita l'opzione SELECTITEMS per la PopUpEnabledActionType
-
- Revision 1.10.2.23  2007/06/12 20:35:13  fab
- Introdotta annotazione @IgnoreLists
-
- Revision 1.10.2.22  2007/06/07 21:00:14  fab
- Modifiche per supportare:
-
- RelationshipImplementationType.LISTBOX_AND_FREETEXT
-
- Revision 1.10.2.21  2007/06/01 07:28:52  fab
- Inserite le annotazioni
-
- @IgnorePrintForm
- @IgnoreForm
-
- Revision 1.10.2.20  2007/06/01 06:24:30  fab
- Lettura della RelationshipImplementationType.OPTIONS
-
- Revision 1.10.2.19  2007/05/19 14:00:42  fab
- Eliminata una System.out
-
- Revision 1.10.2.18  2007/05/19 09:33:28  dev
- Moltissime modifiche
-
- Revision 1.10.2.17  2007/04/30 16:34:55  dev
- Rinominato relatedAndNewItemsOnlyInPop in relatedAndNewItemsOnlyInPopUp
-
- Revision 1.10.2.16  2007/04/30 16:05:05  dev
- Acquisizione del parametro relatedAndNewItemsOnlyInPop
-
- Revision 1.10.2.15  2007/04/05 19:57:28  dev
- Supportate le condizioni onCreate, OnEdit, OnDelete, OnDisplay per la ShowInForm
-
- Revision 1.10.2.14  2007/03/31 14:02:41  dev
- Fix vari
-
- Revision 1.10.2.13  2007/03/31 08:53:51  dev
- Fix nell'individuazione della vista principale in assenza di beans
-
- Revision 1.10.2.12  2007/03/25 09:32:44  dev
- Modifiche per la gestione della sicurezza sulle azioni
-
- Revision 1.10.2.11  2007/03/24 17:23:41  dev
- Modifiche alla getLists ed alla getMainList
-
- Revision 1.10.2.10  2007/03/24 12:28:03  dev
- Inserite funzioni per la gestione della lista principale dell'applicazione
-
- Revision 1.10.2.9  2007/03/24 00:42:01  dev
- Reingegnerizzazione della creazione del progetto
-
- Revision 1.10.2.8  2007/03/22 18:15:07  dev
- *** empty log message ***
-
- Revision 1.10.2.7  2007/03/06 09:57:15  dev
- Fix per la corretta lettura del tipo nei selection attributes delle relazioni
-
- Revision 1.10.2.6  2007/03/03 12:25:16  dev
- Fix per la corretta lettura delle relazioni e delle proprietà degli attributi della @SearchOnRelationship
-
- Revision 1.10.2.5  2007/02/16 18:16:25  dev
- Fix vari
-
- Revision 1.10.2.4  2007/02/09 11:19:43  dev
- Fix per la corretta acquisizione delle informazioni sulla categorizazione per le relazioni
-
- Revision 1.10.2.3  2007/02/06 07:08:32  dev
- Fix per l'acquisizione del tipo per gli attributi di relazione mostrati nella lista
-
- Revision 1.10.2.2  2007/02/03 13:10:33  dev
- Fix Vari
-
- Revision 1.10.2.1  2007/01/30 13:40:31  dev
- Modifiche per supportare l'annotazione @AlternateOrderingAttribute
-
- Revision 1.10  2006/12/28 18:32:30  dev
- Modifiche per gestione della search
-
- Revision 1.9  2006/12/17 20:43:11  dev
- Inserita la getInverseRelationship
-
- Revision 1.8  2006/12/03 19:10:31  dev
- Inserita la funzione getDerivedBeans
-
- Revision 1.7  2006/11/27 21:46:38  dev
- Modifiche per supportare gli attributi nella forma
-
- [relazione]*.attributo
-
- come attributi di selezione nelle PopUp
-
- Revision 1.6  2006/11/24 22:24:40  dev
- Fix per la gestione dei campi @Transient nelle liste
-
- Revision 1.5  2006/11/24 19:15:46  dev
- Fix per la gestione dei campi ShowTransientInForm e ShowTransientAttributeInList
-
- Revision 1.4  2006/11/01 11:05:50  dev
- Caching sulla funzione getBeanAttributes
-
- Revision 1.3  2006/10/23 12:32:44  dev
- Eliminata la funzione getAllRelationshipNames2ThisBean che sembra solo di struts
-
- Revision 1.2  2006/10/23 12:13:47  dev
- Modifica per mantenere la lista completa delle relazioni di un attributo come oggetti e non come nomi
-
- Revision 1.1  2006/10/23 08:25:29  dev
- Prima versione separata dal generatore struts
-
- Revision 1.51  2006/10/14 10:14:47  dev
- Modificata l'annotazione LocalSearchOnRelationship e modifiche conseguenti
-
- Revision 1.50  2006/09/26 09:22:32  dev
- Fix sulla gestione errori nella getClass
-
- Revision 1.49  2006/09/23 07:42:52  dev
- Caching di ulteriori funzioni
-
- Revision 1.48  2006/09/23 07:36:25  dev
- Caching di ulteriori funzioni
-
- Revision 1.47  2006/09/23 07:27:28  dev
- Introdotta gestione della cache in altre funzioni di infoReade
-
- Revision 1.46  2006/09/23 07:07:28  dev
- Introdotta gestione della cache in altre funzioni di infoReade
-
- Revision 1.45  2006/09/23 06:54:31  dev
- Introdotta gestione della cache
-
- Revision 1.44  2006/09/14 10:20:17  dev
- Fix nella funzione getBeanSearchAttributes per evitare che modifichi le relazioni del bean
-
- Revision 1.43  2006/09/11 16:33:10  dev
- Fix per corretta gestione della @ShowTransientInForm
-
- Revision 1.42  2006/08/30 15:20:35  dev
- Fix della funzione getAllRelateBeans che restituiva più volte lo stesso bean correlato nel caso di presenza di più relazioni con il bean
-
- Revision 1.41  2006/08/25 10:10:37  dev
- Modifiche per la gestione delle PopUp
-
- Revision 1.40  2006/07/18 15:46:12  bob
- Modifica per supportare i campi @Transient
-
- Revision 1.39  2006/06/22 13:25:57  dev
- Fix per evitare la generazione  dell'help nelle pagine di ricerca
-
- Revision 1.38  2006/06/20 10:43:08  dev
- Fix per supportare l'annotazione @Column nei bean
-
- Revision 1.37  2006/06/20 07:18:07  bob
- Aggiunta su annotazioni @ShowInForm e @Relationship l'attirbuto "required"per i campi obbligatori
-
- Revision 1.35  2006/06/18 15:04:20  dev
- Inserit l'annotazione @SearchResultActions e la sua gestione
-
- Revision 1.34  2006/06/16 18:13:17  dev
- *** empty log message ***
-
- Revision 1.33  2006/06/12 20:38:11  dev
- Modifica per rileggere le annotazioni di sicurezza del BeanManager
-
- Revision 1.32  2006/06/11 08:12:08  dev
- Modificata la @ShowAttributeInList per indicare l'attributo che impone l'ordinamento di default della lista del bean
-
- Revision 1.31  2006/06/10 16:53:00  dev
- Maggiori dettagli nell'eccezione ShowAttributeWrongOrderException
- Possibilità di visualizzare errori nella list
-
- Revision 1.30  2006/06/10 12:28:36  dev
- Fix per le due annotazioni
-
- @ShowTransientInForm
- @ShowTransientAttributeInList
-
- per la gestione dei campi transient
-
- Revision 1.29  2006/06/10 06:40:13  dev
- Inserite le due annotazioni
-
- @ShowTransientInForm
- @ShowTransientAttributeInList
-
- per la gestione dei campi transient
-
- Revision 1.28  2006/06/09 15:40:30  dev
- Chiusura automatica della local search
-
- Revision 1.27  2006/06/08 10:16:22  dev
- Modifiche per la nuova gestione del path nella list di bean detail in relazioni MASTER-DETAIL
-
- Revision 1.26  2006/06/05 15:19:25  dev
- Modificata @Relationship con opzione help e relativa generazione
-
- Revision 1.25  2006/06/05 10:32:58  dev
- Modifica per la generazione della popup di help sui campi del form
-
- Revision 1.24  2006/06/02 06:47:39  dev
- Fix alla documentazione
- Inseriti ulteriori controlli di esistenza dei selectionAttributes nell'annotazione @Relationship
-
- Revision 1.23  2006/06/01 16:00:36  dev
- Introdotta nell'annotazione @Relationship la possibilità di indicare quali sono le azioni abilitate quando la relazione e' implementata come PopUp
-
- Revision 1.22  2006/06/01 10:18:13  dev
- Fix per formattare le date negli attributi di sola visualizzazione nel form
-
- Revision 1.21  2006/05/31 21:10:58  dev
- Fix per disporre di tutto il path nel riferimento al padre di bean DETAIL
-
- Revision 1.20  2006/05/31 07:44:38  dev
- Fix errato ordinamento degli attributi da visualizzare
-
- Revision 1.19  2006/05/24 20:13:53  dev
- Da completare i campi di sola visualizzazione nei form
-
- Revision 1.18  2006/05/24 17:19:14  dev
- Fix gestione attributi nella forma
-
- [relazione.]*attributo
-
- nella selectionAttribute della @Relationship
-
- Revision 1.17  2006/05/01 13:48:05  dev
- Fix nella codice della selezione di relazioni 1:N
-
- Revision 1.15  2006/04/20 10:15:12  dev
- Fix nella generazione delle pagine di ricerca sui listbox
- Intorudzione delle keywords CVS nei file generati
- Introduzione delle keywords per i file del generatore
-
**/
package org.boco.seamwebappgen.info;

import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Vector;

import javax.annotation.security.DenyAll;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.boco.seamwebappgen.annotations.AlternateOrderingAttribute;
import org.boco.seamwebappgen.annotations.AttributeImplementationType;
import org.boco.seamwebappgen.annotations.IgnoreBean;
import org.boco.seamwebappgen.annotations.IgnoreBeanManager;
import org.boco.seamwebappgen.annotations.IgnoreForm;
import org.boco.seamwebappgen.annotations.IgnoreLists;
import org.boco.seamwebappgen.annotations.IgnorePrintForm;
import org.boco.seamwebappgen.annotations.IgnorePrintListForm;
import org.boco.seamwebappgen.annotations.LocalSearchOnAttribute;
import org.boco.seamwebappgen.annotations.PopUpEnabledActionType;
import org.boco.seamwebappgen.annotations.RelationshipImplementationType;
import org.boco.seamwebappgen.annotations.SearchResultList;
import org.boco.seamwebappgen.annotations.ShowAttributeInList;
import org.boco.seamwebappgen.annotations.ShowInForm;
import org.boco.seamwebappgen.annotations.ShowRelationshipAttributesInForm;
import org.boco.seamwebappgen.annotations.ShowRelationshipAttributesInList;
import org.boco.seamwebappgen.annotations.ShowTransientAttributeInList;
import org.boco.seamwebappgen.annotations.ShowTransientInForm;
import org.boco.seamwebappgen.cache.Cache;
import org.boco.seamwebappgen.comparators.JavaFieldComparator;
import org.boco.seamwebappgen.comparators.JavaMethodComparator;
import org.boco.seamwebappgen.exception.MissingColumnsException;
import org.boco.seamwebappgen.exception.MissingGetMethodException;
import org.boco.seamwebappgen.exception.MissingKeyException;
import org.boco.seamwebappgen.exception.MissingMasterReferenceException;
import org.boco.seamwebappgen.exception.MissingRowsException;
import org.boco.seamwebappgen.exception.MissingSelectionAttributeException;
import org.boco.seamwebappgen.exception.MissingTargetEntityException;
import org.boco.seamwebappgen.exception.MoreThenOneMainListException;
import org.boco.seamwebappgen.exception.ShowAttributeWrongOrderException;
import org.boco.seamwebappgen.exception.TooManySelectionAttributesException;
import org.boco.seamwebappgen.exception.WrongRelatedBeanException;
import org.boco.seamwebappgen.exception.WrongSelectionAttributeException;
import org.boco.seamwebappgen.exception.WrongShowEnableRolesListException;
import org.boco.seamwebappgen.utils.Utils;


/**
* Classe dedicata alla lettura delle informazioni dalla directory dove sono le
* classi dei bean
*
* @author Fabrizio Boco
*/
public class InfoReader
{

  private String  sourceDir    = "";
  private String  sourcePackage  = "";
  private String  beanDir       = "";

  /**
   * Costruttore
   *
   * @param sourceDir
   * directory sorgente
   *
   *
   *
   */
  public InfoReader(String sourceDir)
  {
    this.sourceDir = sourceDir;

    File dir = new File(sourceDir);

    String files[] = dir.list();

    for (int i = 0; i < files.length; i++)
    {
      String checkPath = sourceDir + File.separator + files[i] + File.separator + "entity";

      File checkFile = new File(checkPath);

      if (checkFile.exists())
      {
        sourcePackage = files[i];
        break;
      }

    }

    /*   
     if (files[0].equals("META-INF"))
     sourcePackage = files[1];
     else
     sourcePackage = files[0];
     */

    beanDir = sourceDir + File.separator + sourcePackage + File.separator + "entity" + File.separator;
  }

  /**
   * Restituisce il package utilizzato per il progetto
   */
  public String getPackage()
  {
    return sourcePackage;
  }

  /**
   * Restituisce la lista dei nomi dei bean presenti nella directory sorgente
   *
   */
  public Vector<String> getBeanNames()
  {
    Vector<String> ret = new Vector<String>();

    if (Cache.exists("", "getBeanNames"))
      return (Vector<String>) Cache.get("", "getBeanNames");

    File dir = new File(beanDir);

    String files[] = dir.list();

    if (files == null)
      return null;

    for (int i = 0; i < files.length; i++)
    {

      if (!files[i].equals("CVS"))
      {
        String shortName = files[i].substring(0, files[i].length() - 6);

        if (!shortName.endsWith("Upload"))
        {
          ret.add(shortName);
        }
      }
    }

    String names[] = ret.toArray(new String[0]);

    java.util.Arrays.sort(names);

    ret.clear();

    for (int i = 0; i < names.length; i++)
      ret.add(names[i]);

    Cache.put("", "getBeanNames", ret);

    return ret;
  }

  /**
   * Restituisce un bean dal nome
   *
   * <b>Sembra essere incompleto !!!!</b>
   *
   */
  public Bean getBean(String beanName) throws Exception
  {
    if (Cache.exists(beanName, "getBean"))
      return (Bean) Cache.get(beanName, "getBean");

    Class cBean = getClass(beanName);

    // Costruisce le informazioni sul bean
    Bean bean = new Bean();

    bean.setClassName(cBean.getName());

    // Attributi NON relativi alle relazioni

    Field fields[] = getFields(cBean);

    // java.util.Arrays.sort(fields);

    for (int j = 0; j < fields.length; j++)
    {

      if (!isRelationshipField(cBean, fields[j]))
      {
        Attribute attr = new Attribute();

        attr.setName(fields[j].getName());
        attr.setType(fields[j].getType().getName());

        attr.setKey(isKey(cBean, fields[j]));

        bean.addAttribute(attr);
      }
    }

    /**
     * Questa setAttributes sembra rompere la generazione dello javascript delle pagine popup
     * inserendo anche i campi non visualizzati nel form del bean di partenza ?????????????
     */
    bean.setAttributes(this.getBeanAttributes(beanName));
    bean.setKey(this.getBeanKey(beanName));
    bean.setRelationships(this.getRelationships(beanName));
    bean.setShowAttributes(this.getBeanShowAttributes(beanName, bean.getRelationships()));
    bean.setShowInFormAttributes(this.getBeanShowInFormAttributes(beanName, bean.getRelationships()));
    bean.setLocalSearchAttributes(this.getBeanLocalSearchAttributes(beanName, bean.getRelationships()));
    bean.setSearchAttributes(this.getBeanSearchAttributes(beanName, bean.getRelationships()));

    Cache.put(beanName, "getBean", bean);

    return bean;
  }

  /**
   * Restituisce true se il bean deve essere ignorato
   */
  public boolean ignoreBean(String beanName)
  {
    Class beanClass = getClass(beanName);

    Annotation annotations[] = beanClass.getAnnotations();

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().equals(IgnoreBean.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce true se il beanManager non deve essere generato
   */
  public boolean ignoreBeanManager(String beanName)
  {
    Class beanClass = getClass(beanName);

    Annotation annotations[] = beanClass.getAnnotations();

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().equals(IgnoreBeanManager.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce true se il Form non deve essere generato
   */
  public boolean ignoreForm(String beanName)
  {
    Class beanClass = getClass(beanName);

    Annotation annotations[] = beanClass.getAnnotations();

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().equals(IgnoreForm.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce true se il Form per la stampa non deve essere generato
   */
  public boolean ignorePrintForm(String beanName)
  {
    Class beanClass = getClass(beanName);

    Annotation annotations[] = beanClass.getAnnotations();

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().equals(IgnorePrintForm.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce true se il Form per la stampa della lista dei bean non deve essere generato
   */
  public boolean ignorePrintListForm(String beanName)
  {
    Class beanClass = getClass(beanName);

    Annotation annotations[] = beanClass.getAnnotations();

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().equals(IgnorePrintListForm.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce true se il beanManager non deve essere generato
   */
  public boolean ignoreLists(String beanName)
  {
    Class beanClass = getClass(beanName);

    Annotation annotations[] = beanClass.getAnnotations();

    for (Annotation annotation : annotations)
    {
      if (annotation.annotationType().equals(IgnoreLists.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce tutti gli attributi di un bean
   *
   */
  public Vector<Attribute> getBeanAttributes(String beanName) throws Exception
  {
    Vector<Attribute> tmp = new Vector<Attribute>();

    if (Cache.exists(beanName, "getBeanAttributes"))
      return (Vector<Attribute>) Cache.get(beanName, "getBeanAttributes");

    Class cBean = this.getClass(beanName);
    Field fields[] = getFields(cBean);

    for (int j = 0; j < fields.length; j++)
    {

      if (!isRelationshipField(cBean, fields[j]))
      {
        Attribute attr = new Attribute();

        attr.setName(fields[j].getName());
        attr.setType(fields[j].getType().getName());

        attr.setKey(isKey(cBean, fields[j]));

        if (isShowInForm(fields[j]))
        {
          // Il campo ha una annotazione @ShowInForm

          ShowInForm annotation = fields[j].getAnnotation(ShowInForm.class);

          attr.setImplementationType(annotation.type());

          attr.setOrderInForm(annotation.order());

          attr.setOnCreateIf(annotation.onCreateIf());
          attr.setOnEditIf(annotation.onEditIf());
          attr.setOnDisplayIf(annotation.onDisplayIf());
          attr.setOnDeleteIf(annotation.onDeleteIf());

          attr.setValidatorId(annotation.validatorId());

          attr.setFormFormatOff(annotation.formatOff());
          attr.setListFormatOff(annotation.listFormatOff());
         
          attr.setAjaxEvent(annotation.ajaxEvent());
         
          String ids[] = annotation.idsToRerenderOnAjaxEvent();
          for (int i = 0; i < ids.length; i++)
            attr.addIdToRerenderOnAjaxEvent(ids[i]);


          if (annotation.type() == AttributeImplementationType.TEXTAREA || annotation.type() == AttributeImplementationType.FORMATTEDTEXTAREA)
          {
            if (annotation.columns() == 0)
              throw new MissingColumnsException(beanName, fields[j].getName());

            if (annotation.rows() == 0)
              throw new MissingRowsException(beanName, fields[j].getName());

            attr.setColumns(annotation.columns());
            attr.setRows(annotation.rows());
          }

          if (annotation.type() == AttributeImplementationType.LISTBOX)
          {
            for (int i = 0; i < annotation.labels().length; i++)
            {
              attr.addLabel(annotation.labels()[i]);
            }
          }

          attr.setHelp(annotation.help());
          attr.setRequired(annotation.required());
        }
        else
        {
          attr.setOrderInForm(0);
          attr.setImplementationType(AttributeImplementationType.HIDEINFORM);
        }

        if (isAlternateOrderingAttribute(fields[j]))
        {
          // Il campo ha una annotazione @AlternateOrderingAttribute

          AlternateOrderingAttribute annotation = fields[j].getAnnotation(AlternateOrderingAttribute.class);

          attr.setAlternateOrderingAttribute(annotation.attribute());
        }

        tmp.add(attr);
      }
    }

    // Inserisce i campi di tipo @Transient
    // escludendo getSerialVersionUID

    Method methods[] = cBean.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(methods, new JavaMethodComparator());

    for (int i = 0; i < methods.length; i++)
    {
      if (methods[i].getName().startsWith("get") && !methods[i].getName().equals("getSerialVersionUID") && methods[i].getAnnotation(javax.persistence.Transient.class) != null && methods[i].getAnnotation(ShowTransientInForm.class) != null)
      {
        Attribute attr = new Attribute();

        attr.setName(Utils.makeMethod2Field(methods[i].getName()));
        attr.setType(methods[i].getReturnType().getName());
        attr.setKey(false);

        ShowTransientInForm annotation = methods[i].getAnnotation(ShowTransientInForm.class);

        attr.setImplementationType(AttributeImplementationType.READONLY);
        attr.setOrderInForm(annotation.order());
        attr.setTrans(true);

        tmp.add(attr);
      }
    }

    //if (!cBean.getGenericSuperclass().equals(Object.class))
    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunti gli attributi della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      tmp.addAll(getBeanAttributes(superBeanName));
    }

    Cache.put(beanName, "getBeanAttributes", tmp);

    return tmp;
  }

  /**
   * Restituisce le informazioni di uno specifico attributo del bean indicato
   */
  public Attribute getBeanAttribute(String beanName, String attributeName) throws Exception
  {
    if (Cache.exists(beanName, attributeName))
      return (Attribute) Cache.get(beanName, attributeName);

    Class cBean = this.getClass(beanName);
    Field fields[] = getFields(cBean);

    for (int j = 0; j < fields.length; j++)
    {
      if (fields[j].getName().equals(attributeName))
      {
        if (!isRelationshipField(cBean, fields[j]))
        {
          Attribute attr = new Attribute();

          attr.setName(fields[j].getName());
          attr.setType(fields[j].getType().getName());
          attr.setKey(isKey(cBean, fields[j]));

          if (isShowInForm(fields[j]))
          {
            // Il campo ha una annotazione @ShowInForm

            ShowInForm annotation = fields[j].getAnnotation(ShowInForm.class);

            attr.setImplementationType(annotation.type());

            attr.setOrderInForm(annotation.order());
            attr.setFormFormatOff(annotation.formatOff());
            attr.setListFormatOff(annotation.listFormatOff());

            if (annotation.type() == AttributeImplementationType.TEXTAREA || annotation.type() == AttributeImplementationType.FORMATTEDTEXTAREA)
            {
              if (annotation.columns() == 0)
                throw new MissingColumnsException(beanName, fields[j].getName());

              if (annotation.rows() == 0)
                throw new MissingRowsException(beanName, fields[j].getName());

              attr.setColumns(annotation.columns());
              attr.setRows(annotation.rows());
            }

            if (annotation.type() == AttributeImplementationType.LISTBOX)
            {
              for (int i = 0; i < annotation.labels().length; i++)
              {
                attr.addLabel(annotation.labels()[i]);
              }
            }
          }
          else
          {
            attr.setOrderInForm(0);
            attr.setImplementationType(AttributeImplementationType.HIDEINFORM);
          }

          if (isAlternateOrderingAttribute(fields[j]))
          {
            // Il campo ha una annotazione @AlternateOrderingAttribute

            AlternateOrderingAttribute annotation = fields[j].getAnnotation(AlternateOrderingAttribute.class);

            attr.setAlternateOrderingAttribute(annotation.attribute());
          }

          Cache.put(beanName, attributeName, attr);
          return attr;
        }
      }
    }

    // Se il campo è di tipo @Transient, e' determinato dalla sua funzione get

    String methodName = Utils.makeGet(attributeName);

    Method methods[] = cBean.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(methods, new JavaMethodComparator());

    for (int i = 0; i < methods.length; i++)
    {
      if (methods[i].getName().equals(methodName) && methods[i].getAnnotation(javax.persistence.Transient.class) != null)
      {
        Attribute attr = new Attribute();

        attr.setName(Utils.makeMethod2Field(methods[i].getName()));
        attr.setType(methods[i].getReturnType().getName());
        attr.setKey(false);
        attr.setTrans(true);

        Cache.put(beanName, attributeName, attr);
        return attr;
      }
    }

    //if (!cBean.getGenericSuperclass().equals(Object.class))
    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunti gli attributi della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      Attribute tmp = getBeanAttribute(superBeanName, attributeName);

      Cache.put(beanName, attributeName, tmp);

      return tmp;
    }

    throw new Exception("Missing attribute " + attributeName + " in bean " + beanName);
  }

  /**
   * Restituisce tutti gli attributi da visualizzare nella lista del bean
   */
  public Vector<ShowAttribute> getBeanShowAttributes(String beanName, Vector<Relationship> relationships) throws Exception
  {
    if (Cache.exists(beanName, "getBeanShowAttributes"))
      return (Vector<ShowAttribute>) Cache.get(beanName, "getBeanShowAttributes");

    Vector<ShowAttribute> tmp = new Vector<ShowAttribute>();
    Vector<ShowAttribute> tmpParent = new Vector<ShowAttribute>();

    Class cBean = getClass(beanName);

    Field fields[] = getFields(cBean);

    for (int j = 0; j < fields.length; j++)
    {

      if (!isRelationshipField(cBean, fields[j]) && isToShow(fields[j]))
      {
        Attribute attr = new Attribute();

        attr.setName(fields[j].getName());
        attr.setType(fields[j].getType().getName());
        attr.setKey(isKey(cBean, fields[j]));

        // Recupera l'implementation type        
        attr.setImplementationType(this.getBeanAttribute(beanName, attr.getName()).getImplementationType());

        ShowAttributeInList annotation = (ShowAttributeInList) getFieldAnnotation(fields[j], ShowAttributeInList.class);

        if (annotation.isDefaultOrderingAttribute() && annotation.ascending())
        {
          attr.setDefaultOrderingAttribute("Asc");
        }

        if (annotation.isDefaultOrderingAttribute() && !annotation.ascending())
        {
          attr.setDefaultOrderingAttribute("Desc");
        }

        ShowAttribute showAttr = new ShowAttribute(null, attr);
        showAttr.setListFormatOff(annotation.formatOff());

        for (int i = 0; i < annotation.iconValues().length; i++)
        {
          showAttr.addIconValue(annotation.iconValues()[i]);
        }

        for (int i = 0; i < annotation.icons().length; i++)
        {
          showAttr.addIcon(annotation.icons()[i]);
        }

        if (isAlternateOrderingAttribute(fields[j]))
        {
          // Il campo ha una annotazione @AlternateOrderingAttribute

          AlternateOrderingAttribute ann = fields[j].getAnnotation(AlternateOrderingAttribute.class);

          showAttr.setAlternateOrderingAttribute(ann.attribute());
        }

        showAttr.setWidth(annotation.width());
       
        if (order(fields[j]) != 1000)
        {
          if (tmp.size() <= order(fields[j]))
            tmp.setSize(order(fields[j]) + 1);

          if (tmp.get(order(fields[j])) != null)
            throw new ShowAttributeWrongOrderException(fields[j].getName(), beanName);

          tmp.set(order(fields[j]), showAttr);
        }
        else
          tmp.add(showAttr);
      }
    }

    // Inserisce i campi di tipo @Transient
    // escludendo getSerialVersionUID

    Method methods[] = cBean.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(methods, new JavaMethodComparator());

    for (int i = 0; i < methods.length; i++)
    {
      if (methods[i].getName().startsWith("get") && !methods[i].getName().equals("getSerialVersionUID") && methods[i].getAnnotation(javax.persistence.Transient.class) != null && methods[i].getAnnotation(ShowTransientAttributeInList.class) != null)
      {
        Attribute attr = new Attribute();

        //attr.setName(methods[i].getName());

        attr.setName(Utils.makeMethod2Field(methods[i].getName()));

        attr.setType(methods[i].getReturnType().getName());
        attr.setKey(false);
        attr.setTrans(true);

        ShowAttribute showAttr = new ShowAttribute(null, attr);

        ShowTransientAttributeInList annotation = methods[i].getAnnotation(ShowTransientAttributeInList.class);

        showAttr.setTransientParameters(annotation.parameters());
        showAttr.setWidth(annotation.width());

        if (annotation.order() != 1000)
        {
          if (tmp.size() <= annotation.order())
            tmp.setSize(annotation.order() + 1);

          //          if (tmp.get(order(methods[i])) != null)
          //            throw new ShowAttributeWrongOrderException(methods[i].getName(), beanName);

          tmp.set(annotation.order(), showAttr);
        }
        else
          tmp.add(showAttr);

        //        if (order(methods[i]) != 1000)
        //        {
        //          if (tmp.size() <= order(methods[i]))
        //            tmp.setSize(order(methods[i]) + 1);
        //
        //          if (tmp.get(order(methods[i])) != null)
        //            throw new ShowAttributeWrongOrderException(methods[i].getName(), beanName);
        //
        //          tmp.set(order(methods[i]), showAttr);
        //        }
        //        else
        //          tmp.add(showAttr);
      }
    }

    // Attributi delle relazioni collegate al bean

    for (int j = 0; j < methods.length; j++)
    {
      Annotation annotations[] = methods[j].getAnnotations();

      // System.out.println("Metodo "+methods[j].getName());

      for (int k = 0; k < annotations.length; k++)
      {
        Annotation annotation = annotations[k];

        if (annotation.annotationType().equals(ShowRelationshipAttributesInList.class))
        {
          String attributesName[] = ((ShowRelationshipAttributesInList) annotation).names();
          int    attributesOrder[] = ((ShowRelationshipAttributesInList) annotation).orders();
          String widths[] = ((ShowRelationshipAttributesInList) annotation).widths();
         
          String relationshipName = methods[j].getName();
          Relationship relationship = null;

          for (int i = 0; i < relationships.size(); i++)
          {
            if (relationships.get(i).getName().equals(relationshipName))
              relationship = relationships.get(i);
          }

          for (int i = 0; i < attributesName.length; i++)
          {
            /**
             * Verifica se l'attributo e' nella forma
             *
             * [relationship.]*Attribute
             *
             */
            ShowAttribute showAttr = null;

            if (attributesName[i].contains("."))
            {
              Vector<String> relations = Utils.splitRelationships(attributesName[i]);

              showAttr = new ShowAttribute(relations.get(relations.size() - 1));

              for (int m = 0; m < relations.size() - 1; m++)
              {
                Relationship rel = getRelationship(relations.get(m));
                showAttr.addRelationship(rel);
              }
              showAttr.setRelationship(relationship);
            }
            else
            {
              showAttr = new ShowAttribute(attributesName[i]);
              showAttr.setRelationship(relationship);
            }

            // Viene individuato il tipo dell'attributo

            Relationship lastRelationship = showAttr.getRelationships().get(showAttr.getRelationships().size() - 1);
            if (lastRelationship != null)
              showAttr.setType(getBeanAttribute(lastRelationship.getToBeanName(), showAttr.getName()).getType());

            if (tmp.size() <= attributesOrder[i])
              tmp.setSize(attributesOrder[i] + 1);

            if (tmp.get(attributesOrder[i]) != null)
              throw new ShowAttributeWrongOrderException(attributesName[i], beanName, relationshipName, tmp.get(attributesOrder[i]).getQualifiedName());

            /** QUI **/

            Relationship lastRel = showAttr.getRelationship();

            Attribute attrX = this.getBeanAttribute(lastRel.getToBeanName(), showAttr.getName());
            if (attrX != null)
              showAttr.setAlternateOrderingAttribute(attrX.getAlternateOrderingAttribute());

            /** attributo di default per ordinamento della lista ? **/

            showAttr.setDefaultOrderingAttribute("");
            if (((ShowRelationshipAttributesInList) annotation).defaultOrderingAttributeName().equals(showAttr.getName()))
            {
              if (((ShowRelationshipAttributesInList) annotation).ascending())
                showAttr.setDefaultOrderingAttribute("Asc");
              else
                showAttr.setDefaultOrderingAttribute("Desc");
            }

            /** Dimensione della colonna **/
            if (widths.length>0)
              showAttr.setWidth(widths[i]);
           
            tmp.set(attributesOrder[i], showAttr);
          }
        }

      }
    }

    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunti gli attributi della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      // tmp1.addAll(getBeanShowAttributes(superBeanName, getRelationships(superBeanName)));
      tmpParent = getBeanShowAttributes(superBeanName, getRelationships(superBeanName));
    }

    Vector<ShowAttribute> tmp3 = new Vector<ShowAttribute>();

    if (tmp.size() > tmpParent.size())
    {
      tmp3.addAll(tmp);
      for (int i = 0; i < tmpParent.size(); i++)
      {
        tmp3.set(i, tmpParent.get(i));
      }
    }
    else
    {
      tmp3.addAll(tmpParent);

      for (int i = 0; i < tmp.size(); i++)
      {
        tmp3.set(i, tmp.get(i));
      }
    }

    tmp3.trimToSize();
    Vector<ShowAttribute> tmp1 = new Vector<ShowAttribute>();
    for (int i = 0; i < tmp3.size(); i++)
    {
      if (tmp3.get(i) != null)
        tmp1.add(tmp3.get(i));
    }

    Cache.put(beanName, "getBeanShowAttributes", tmp1);

    return tmp1;
  }

  /**
   * Restituisce tutti gli attributi da visualizzare nel bean provenienti da relazioni
   */
  public Vector<ShowAttribute> getBeanShowInFormAttributes(String beanName, Vector<Relationship> relationships) throws Exception
  {
    if (Cache.exists(beanName, "getBeanShowInFormAttributes"))
      return (Vector<ShowAttribute>) Cache.get(beanName, "getBeanShowInFormAttributes");

    Vector<ShowAttribute> tmp = new Vector<ShowAttribute>();
    Vector<ShowAttribute> tmpParent = new Vector<ShowAttribute>();

    Class cBean = getClass(beanName);

    // Inserisce i campi di tipo @Transient
    // escludendo getSerialVersionUID
    Method methods[] = cBean.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(methods, new JavaMethodComparator());

    // Attributi delle relazioni collegate al bean
    for (int j = 0; j < methods.length; j++)
    {
      Annotation annotations[] = methods[j].getAnnotations();

      for (int k = 0; k < annotations.length; k++)
      {
        Annotation annotation = annotations[k];

        if (annotation.annotationType().equals(ShowRelationshipAttributesInForm.class))
        {
          String attributesName[] = ((ShowRelationshipAttributesInForm) annotation).names();
          int attributesOrder[] = ((ShowRelationshipAttributesInForm) annotation).orders();
          String relationshipName = methods[j].getName();
          Relationship relationship = null;

          for (int i = 0; i < relationships.size(); i++)
          {
            if (relationships.get(i).getName().equals(relationshipName))
              relationship = relationships.get(i);
          }

          for (int i = 0; i < attributesName.length; i++)
          {
            ShowAttribute showAttr = new ShowAttribute(attributesName[i]);

            if (attributesName[i].contains("."))
            {
              Vector<String> relations = Utils.splitRelationships(attributesName[i]);

              showAttr = new ShowAttribute(relations.get(relations.size() - 1));

              String toBeanName = relationship.getToBeanName();

              for (int m = 0; m < relations.size() - 1; m++)
              {
                Relationship rel = this.getRelationship(toBeanName, relations.get(m));
                showAttr.addRelationship(rel);

                toBeanName = rel.getToBeanName();
              }

              showAttr.setRelationship(relationship);

            }
            else
            {
              showAttr = new ShowAttribute(attributesName[i]);
              showAttr.setRelationship(relationship);
            }

            // Viene individuato il tipo dell'attributo

            Relationship lastRelationship = showAttr.getRelationships().get(showAttr.getRelationships().size() - 1);
            if (lastRelationship != null)
              showAttr.setType(getBeanAttribute(lastRelationship.getToBeanName(), showAttr.getName()).getType());

            showAttr.setOrderInForm(attributesOrder[i]);

            if (tmp.size() <= attributesOrder[i])
              tmp.setSize(attributesOrder[i] + 1);

            if (tmp.get(attributesOrder[i]) != null)
              throw new ShowAttributeWrongOrderException(attributesName[i], beanName, relationshipName, tmp.get(attributesOrder[i]).getQualifiedName());

            showAttr.setOnCreateIf(((ShowRelationshipAttributesInForm) annotation).showOnCreateIf());
            showAttr.setOnDeleteIf(((ShowRelationshipAttributesInForm) annotation).showOnDeleteIf());
            showAttr.setOnDisplayIf(((ShowRelationshipAttributesInForm) annotation).showOnDisplayIf());
            showAttr.setOnEditIf(((ShowRelationshipAttributesInForm) annotation).showOnEditIf());

            tmp.set(attributesOrder[i], showAttr);
          }
        }
      }
    }

    //    tmp.trimToSize();
    //    Vector<ShowAttribute> tmp1 = new Vector<ShowAttribute>();
    //    for (int i = 0; i < tmp.size(); i++)
    //    {
    //      if (tmp.get(i) != null)
    //        tmp1.add(tmp.get(i));
    //    }
    //
    //    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    //    {
    //      // Il bean estende un altro bean
    //      // pertanto vanno aggiunti gli attributi della superclasse
    //
    //      String superBeanClass = cBean.getGenericSuperclass().toString();
    //      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());
    //
    //      tmp1.addAll(getBeanShowInFormAttributes(superBeanName, getRelationships(superBeanName)));
    //    }
    //
    //    Cache.put(beanName, "getBeanShowInFormAttributes", tmp1);
    //
    //    return tmp1;

    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunti gli attributi della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      tmpParent = getBeanShowInFormAttributes(superBeanName, getRelationships(superBeanName));
    }

    Vector<ShowAttribute> tmp3 = new Vector<ShowAttribute>();

    if (tmp.size() > tmpParent.size())
    {
      tmp3.addAll(tmp);
      for (int i = 0; i < tmpParent.size(); i++)
      {
        tmp3.set(i, tmpParent.get(i));
      }
    }
    else
    {
      tmp3.addAll(tmpParent);

      for (int i = 0; i < tmp.size(); i++)
      {
        tmp3.set(i, tmp.get(i));
      }
    }

    tmp3.trimToSize();
    Vector<ShowAttribute> tmp1 = new Vector<ShowAttribute>();
    for (int i = 0; i < tmp3.size(); i++)
    {
      if (tmp3.get(i) != null)
        tmp1.add(tmp3.get(i));
    }

    Cache.put(beanName, "getBeanShowInFormAttributes", tmp1);

    return tmp1;
  }

  /**
   * Restituisce tutti gli attributi per la ricerca sul bean
   */
  public Vector<SearchAttribute> getBeanSearchAttributes(String beanName, Vector<Relationship> relationshipsParams) throws Exception
  {
    Vector<SearchAttribute> tmp = new Vector<SearchAttribute>();

    Vector<Relationship> relationships = new Vector<Relationship>();

    for (Relationship item : relationshipsParams)
    {
      relationships.add((Relationship) item.clone());
    }

    Class cBean = this.getClass(beanName);

    Field fields[] = getFields(cBean);

    for (int j = 0; j < fields.length; j++)
    {
      if (!isRelationshipField(cBean, fields[j]) && isSearch(fields[j]))
      {
        SearchAttribute attr = new SearchAttribute(getBeanAttribute(beanName, fields[j].getName()));
        int order = ((org.boco.seamwebappgen.annotations.SearchOnAttribute) getFieldAnnotation(fields[j], org.boco.seamwebappgen.annotations.SearchOnAttribute.class)).order();
        attr.setOrderInForm(order);
        tmp.add(attr);
      }
    }

    // if (!cBean.getGenericSuperclass().equals(Object.class))
    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunti gli attributi della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      Vector<SearchAttribute> attrs = getBeanSearchAttributes(superBeanName, getRelationships(superBeanName));

      for (SearchAttribute attr : attrs)
      {
        if (!tmp.contains(attr))
          tmp.add(attr);
      }
    }

    // Attributi delle relazioni collegate al bean

    Method methods[] = cBean.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(methods, new JavaMethodComparator());

    for (int j = 0; j < methods.length; j++)
    {
      Annotation annotations[] = methods[j].getAnnotations();

      // System.out.println("Metodo "+methods[j].getName());

      for (int k = 0; k < annotations.length; k++)
      {
        if (annotations[k].annotationType().equals(org.boco.seamwebappgen.annotations.SearchOnRelationship.class))
        {
          org.boco.seamwebappgen.annotations.SearchOnRelationship annotation = (org.boco.seamwebappgen.annotations.SearchOnRelationship) annotations[k];

          int order = annotation.orderInForm();

          String attributesName[] = annotation.selectionAttributes();
          String relationshipName = methods[j].getName();
          Relationship relationship = null;

          for (int i = 0; i < relationships.size(); i++)
          {
            if (relationships.get(i).getName().equals(relationshipName))
            {
              relationship = relationships.get(i);
              break;
            }
          }

          // Forza l'eliminazione degli help
          relationship.setHelp(false);

          Vector<ShowAttribute> relatedAttributes = new Vector<ShowAttribute>();
          for (int kk = 0; kk < attributesName.length; kk++)
          {
            ShowAttribute attr = null;

            if (attributesName[kk].contains("."))
            {
              Vector<String> relations = Utils.splitRelationships(attributesName[kk]);

              attr = new ShowAttribute(relations.get(relations.size() - 1));

              for (int m = 0; m < relations.size() - 1; m++)
                attr.addRelationship(getRelationship(relations.get(m)));

              attr.setRelationship(relationship);
            }
            else
              attr = new ShowAttribute(attributesName[kk]);

            relatedAttributes.add(attr);
          }

          relationship.setRelatedAttributes(relatedAttributes);

          for (int i = 0; i < attributesName.length; i++)
          {
            SearchAttribute searchAttr = null;

            searchAttr = new SearchAttribute(attributesName[i]);

            if (annotation.type() == RelationshipImplementationType.LISTBOX)
            {
              relationship.setListBox(true);
            }
            if (annotation.type() == RelationshipImplementationType.POPUP)
            {
              relationship.setListBox(false);
              relationship.setCRUD(false);
            }
            if (annotation.type() == RelationshipImplementationType.CRUDPOPUP)
            {
              relationship.setListBox(false);
              relationship.setCRUD(true);
            }
            if (annotation.type() == RelationshipImplementationType.NONE)
            {
              relationship.setIgnoreImplementation(true);
            }

            searchAttr.setRelationship(relationship);

            if (attributesName[i].contains("."))
            {
              Vector<String> relations = Utils.splitRelationships(attributesName[i]);

              for (int m = 0; m < relations.size() - 1; m++)
                searchAttr.addRelationship(getRelationship(relations.get(m)));

              searchAttr.setName(relations.get(relations.size() - 1));
            }

            String targetBean = searchAttr.getRelationship().getToBeanName();
            searchAttr.setType(getBeanAttribute(targetBean, searchAttr.getName()).getType());
            searchAttr.setImplementationType(AttributeImplementationType.TEXT);

            searchAttr.setOrderInForm(order);
            tmp.add(searchAttr);
          }

          /*
           for (int i = 0; i < attributesName.length; i++)
           {
           SearchAttribute searchAttr = null;

           if (attributesName[i].contains("."))
           {
           // L'attributo appartiene ad un bean collegato a quello indicato
           // mediante una relazione

           // La ricerca delle informazioni deve essere effettuata sul bean correlato

           String relation = Utils.splitRelation(attributesName[i]);
           String attribute = Utils.splitAttribute(attributesName[i]);

           Relationship rel = getRelationship(relation);

           searchAttr = new SearchAttribute(attributesName[i]);
           searchAttr.setRelationship(relationship);
           searchAttr.setImplementationType(AttributeImplementationType.LISTBOX);
           }
           else
           {
           Attribute tmpAttr = getBeanAttribute(relationship.getToBeanName(), attributesName[i]);
           searchAttr = new SearchAttribute(getBeanAttribute(relationship.getToBeanName(), attributesName[i]));
           searchAttr.setRelationship(relationship);
           // searchAttr.setImplementationType(AttributeImplementationType.TEXT);             
           }
           searchAttr.setOrderInForm(order);
           tmp.add(searchAttr);
           }
           */

        }
      }
    }

    /**
     * Probabilmente non serve a nulla
     *
     * */

    SearchAttribute key = new SearchAttribute(this.getBeanKey(beanName));
    if (!tmp.contains(key))
      tmp.add(key);

    return tmp;
  }

  /**
   * Restituisce la classe di un bean caricandola dalla directory entity
   */
  public Class getClass(String beanName)
  {
    URL urls[] = new URL[2];

    try
    {
      urls[0] = new URL("file://" + sourceDir + "/");
      urls[1] = new URL("file:///usr/local/jboss-current/server/default/lib/jbosssx.jar");

      //ClassLoader classLoader = new URLClassLoader(urls, ClassLoader.getSystemClassLoader());
      ClassLoader classLoader = new URLClassLoader(urls);

      // System.out.println("Sto caricando la classe "+sourcePackage + ".entity." + beanName);

      return Class.forName(sourcePackage + ".entity." + beanName, true, classLoader);
    }
    catch (MalformedURLException e)
    {
      e.printStackTrace();
      return null;
    }
    catch (ClassNotFoundException e)
    {
      System.out.print("Bean errato: " + beanName);
      e.printStackTrace();
      return null;
    }
  }

  /**
   * Restituisce la classe di una chiave caricandola dalla directory key
   */
  public Class getKeyClass(String beanName)
  {
    URL urls[] = new URL[2];

    try
    {
      urls[0] = new URL("file://" + sourceDir + "/");
      urls[1] = new URL("file:///usr/local/jboss-current/server/default/lib/jbosssx.jar");

      ClassLoader classLoader = new URLClassLoader(urls);

      //return Class.forName(sourcePackage + ".key." + beanName, true, classLoader);
      return Class.forName(beanName, true, classLoader);
    }
    catch (MalformedURLException e)
    {
      e.printStackTrace();
      return null;
    }
    catch (ClassNotFoundException e)
    {
      System.out.print("Bean errato: " + beanName);
      e.printStackTrace();
      return null;
    }
  }

  /**
   * Restituisce la classe di un bean manager caricandola dalla directory bean
   */
  public Class getBeanManagerClass(String beanManagerName)
  {
    URL urls[] = new URL[1];

    try
    {
      urls[0] = new URL("file://" + sourceDir + "/");

      ClassLoader classLoader = new URLClassLoader(urls);

      return Class.forName(sourcePackage + ".manager.beans." + beanManagerName, true, classLoader);
    }
    catch (MalformedURLException e)
    {
      e.printStackTrace();
      return null;
    }
    catch (ClassNotFoundException e)
    {
      e.printStackTrace();
      return null;
    }
  }

  /**
   * Restituisce tutti gli attributi per la ricerca sul bean nella pagina list
   */
  public Vector<SearchAttribute> getBeanLocalSearchAttributes(String beanName, Vector<Relationship> relationships) throws Exception
  {
    Vector<SearchAttribute> tmp = new Vector<SearchAttribute>();

    Class cBean = this.getClass(beanName);

    Field fields[] = getFields(cBean);

    for (int j = 0; j < fields.length; j++)
    {
      if (!isRelationshipField(cBean, fields[j]) && isLocalSearch(fields[j]))
      {
        SearchAttribute attr = new SearchAttribute(fields[j].getName());

        attr.setType(fields[j].getType().getName());
        attr.setKey(isKey(cBean, fields[j]));

        LocalSearchOnAttribute annotation = fields[j].getAnnotation(LocalSearchOnAttribute.class);

        if (fields[j].getAnnotation(ShowInForm.class) != null)
        {
          ShowInForm showAnnotation = fields[j].getAnnotation(ShowInForm.class);

          attr.setImplementationType(showAnnotation.type());

          Vector<String> tmp1 = new Vector<String>();
          tmp1 = new Vector<String>();
          for (int i = 0; i < showAnnotation.labels().length; i++)
          {
            tmp1.add(showAnnotation.labels()[i]);
          }
          attr.setLabels(tmp1);
        }
        else
          attr.setImplementationType(AttributeImplementationType.TEXT);

        attr.setOrderInForm(annotation.order());

        String events[] = annotation.events();
        for (int i = 0; i < events.length; i++)
          attr.addEvent(events[i]);

        String eventFunctions[] = annotation.eventFunctions();
        for (int i = 0; i < events.length; i++)
          attr.addEventFunction(eventFunctions[i]);

        tmp.add(attr);
      }
    }

    // Attributi delle relazioni collegate al bean

    Method methods[] = cBean.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(methods, new JavaMethodComparator());

    for (int j = 0; j < methods.length; j++)
    {
      Annotation annotations[] = methods[j].getAnnotations();

      for (int k = 0; k < annotations.length; k++)
      {
        Annotation annotation = annotations[k];

        if (annotation.annotationType().equals(org.boco.seamwebappgen.annotations.LocalSearchOnRelationship.class))
        {
          String attributesName[] = ((org.boco.seamwebappgen.annotations.LocalSearchOnRelationship) annotation).attributes();
          String relationshipName = methods[j].getName();
          Relationship relationship = null;

          for (int i = 0; i < relationships.size(); i++)
          {
            if (relationships.get(i).getName().equals(relationshipName))
              relationship = relationships.get(i);
          }

          for (int i = 0; i < attributesName.length; i++)
          {
            SearchAttribute searchAttr = new SearchAttribute(attributesName[i]);
            searchAttr.setRelationship(relationship);
            searchAttr.setImplementationType(AttributeImplementationType.LISTBOX);
            searchAttr.setOrderInForm(((org.boco.seamwebappgen.annotations.LocalSearchOnRelationship) annotation).order());

            String events[] = ((org.boco.seamwebappgen.annotations.LocalSearchOnRelationship) annotation).events();
            for (int l = 0; l < events.length; l++)
              searchAttr.addEvent(events[l]);

            String eventFunctions[] = ((org.boco.seamwebappgen.annotations.LocalSearchOnRelationship) annotation).eventFunctions();
            for (int l = 0; l < events.length; l++)
              searchAttr.addEventFunction(eventFunctions[l]);

            tmp.add(searchAttr);
          }

        }
      }
    }

    // Attributi derivati dal SuperBean

    //if (!cBean.getGenericSuperclass().equals(Object.class))
    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunti gli attributi della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      tmp.addAll(getBeanLocalSearchAttributes(superBeanName, getRelationships(superBeanName)));
    }

    /*
     SearchAttribute key = new SearchAttribute(this.getBeanKey(beanName));
     tmp.add(key);
     */

    return tmp;
  }

  /**
   * Restituisce la lista dei campi di un bean
   * @param cBean
   * @return
   */
  private Field[] getFields(Class cBean)
  {
    Vector<Field> ret = new Vector<Field>();

    Field fields[] = cBean.getDeclaredFields();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(fields, new JavaFieldComparator());

    for (int i = 0; i < fields.length; i++)
    {
      if (!fields[i].getName().equals("serialVersionUID"))
      {
        ret.add(fields[i]);
      }
    }

    return ret.toArray(new Field[0]);
  }

  /**
   * La funzione stabilisce se un campo e' una relazione
   *
   * @param c
   * Classe di un bean
   * @param field
   * Campo di un bean
   * @return
   */
  private boolean isRelationshipField(Class c, Field field) throws MissingGetMethodException
  {
    Method m;
    String getter;

   
   
    // Se il bean contiene delle getX indicate come @Transient viene
    // inserito un campo del tipo:
    // static java.lang.Class NomeBean.class$0
    // che sicuramente non è un campo di una relazione
   
    if (field.getType().equals(Class.class))
      return false;

    /** Field di tipo static final - Non è una relazione **/
    if (field.getModifiers() == 25)
      return false;

    // Individua il metodo getter del campo
    getter = Utils.makeGet(field.getName());
    try
    {
      m = c.getMethod(getter, (Class[]) null);
    }
    catch (SecurityException e)
    {
      e.printStackTrace();
      return false;
    }
    catch (NoSuchMethodException e)
    {
      throw new MissingGetMethodException(c.getName(), field.getName());
    }

    // Individua tutte le annotazioni del metodo getter
    Annotation annotations[] = m.getAnnotations();

    for (int j = 0; j < annotations.length; j++)
    {
      // Se il metodo getter contiene una annotazione diversa da
      // @Id
      // @EmbeddedId     
      // @Transient
      // @GeneratedValue
      // @Column
      // @Basic
      // e' un campo di una relazione
      // System.out.println(annotations[j].annotationType().getCanonicalName());
      if ((annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.Id") != 0) && (annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.EmbeddedId") != 0) && (annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.Transient") != 0) && (annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.GeneratedValue") != 0) && (annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.Column") != 0) && (annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.Basic") != 0))
        return true;
    }

    return false;
  }

  /**
   * Dato il campo di una classe indica se e' chiave o meno
   *
   *
   * @param c
   * Classe
   * @param field
   * Campo
   * @return true se il campo e' chiave
   */
  public static boolean isKey(Class c, Field field)
  {
    Method m;
    String getter;

    // Se il bean contiene delle getX indicate come @Transient viene
    // inserito un campo del tipo:
    // static java.lang.Class NomeBean.class$0
    // che sicuramente non e' un campo di una relazione

    if (field.getType().equals(Class.class))
      return false;

    /** Field di tipo static final - Non è una chiave **/
    if (field.getModifiers() == 25)
      return false;
   
    // Individua il metodo getter del campo
    getter = Utils.makeGet(field.getName());
    try
    {
      m = c.getMethod(getter, (Class[]) null);
    }
    catch (SecurityException e)
    {
      e.printStackTrace();
      return false;
    }
    catch (NoSuchMethodException e)
    {
      e.printStackTrace();
      return false;
    }

    // Individua tutte le annotazioni del metodo getter
    Annotation annotations[] = m.getAnnotations();

    for (int j = 0; j < annotations.length; j++)
    {
      // Se il metodo getter contiene @Id il campo e' chiave
      if (annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.Id") == 0 || annotations[j].annotationType().getCanonicalName().compareTo("javax.persistence.EmbeddedId") == 0)
        return true;
    }

    return false;
  }

  /**
   * Indica se il campo ha o meno una annotazione ShowInForm
   *
   * @param f
   * @return
   */
  private boolean isShowInForm(Field f)
  {
    Annotation showInFormAnnotation = f.getAnnotation(ShowInForm.class);

    if (showInFormAnnotation == null)
      return false;

    return true;
  }

  /**
   * Indica se il campo ha o meno una annotazione AlternateOrderingAttribute
   *
   * @param f
   * @return
   */
  private boolean isAlternateOrderingAttribute(Field f)
  {
    Annotation alternateOrderingAttribute = f.getAnnotation(AlternateOrderingAttribute.class);

    if (alternateOrderingAttribute == null)
      return false;

    return true;
  }

  /**
   * Restituisce l'ordine con cui deve essere inserito l'attributo nel form di
   * gestione
   *
   */
  private int order(Field f)
  {
    Annotation annotations[] = f.getAnnotations();

    for (int i = 0; i < annotations.length; i++)
    {
      Annotation annotation = annotations[i];

      if (annotation.annotationType().equals(ShowAttributeInList.class))
        return ((ShowAttributeInList) annotation).order();
    }

    return 1000;
  }

  /**
   * Restituisce l'ordine con cui deve essere inserito l'attributo @Transient
   * nella lista di visualizzazione del bean
   *
   */
  //  private int order(Method m)
  //  {
  //    Annotation annotations[] = m.getAnnotations();
  //
  //    for (int i = 0; i < annotations.length; i++)
  //    {
  //      Annotation annotation = annotations[i];
  //
  //      if (annotation.annotationType().equals(ShowTransientAttributeInList.class))
  //        return ((ShowTransientAttributeInList) annotation).order();
  //    }
  //
  //    return 1000;
  //  }
  /**
   * Verifica se un campo e' da mostrare nella lista del bean analizzando la
   * presenza o meno dell'annotazione
   *
   * @ShowAttributeInList
   *
   */
  private boolean isToShow(Field f)
  {
    Annotation annotations[] = f.getAnnotations();

    for (int i = 0; i < annotations.length; i++)
    {
      Annotation annotation = annotations[i];

      if (annotation.annotationType().equals(ShowAttributeInList.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce gli attributi della chiave del bean
   */
  public Attribute getBeanKey(String beanName) throws Exception
  {
    Vector<Attribute> attributes = this.getBeanAttributes(beanName);

    for (Attribute tmp : attributes)
    {
      if (tmp.isKey())
        return tmp;
    }

    throw new MissingKeyException(beanName);
  }

  /**
   * Individua la prima relazione di relatedBeanName che lo collega a
   * thisBeanName
   *
   */
  public Relationship getFirstRelationship2ThisBean(String thisBeanName, String relatedBeanName, String mappedBy)
  {
    Vector<Relationship> relationships;
    String superBeanName = null;

    Class cRelatedBean = getClass(thisBeanName);
    if (!cRelatedBean.getGenericSuperclass().equals(Object.class))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunte le relazioni della superclasse

      String superBeanClass = cRelatedBean.getGenericSuperclass().toString();
      superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());
    }

    ;
    ;
    ;
    ;
    try
    {
      relationships = getRelationships(relatedBeanName);
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return null;
    }

    for (int i = 0; i < relationships.size(); i++)
    {
      if (mappedBy.equals(""))
      {
        if ((relationships.get(i).getToBeanName().equals(thisBeanName)) || ((superBeanName != null) && (relationships.get(i).getToBeanName().equals(superBeanName))))

          return relationships.get(i);
      }
      else
      {
        if (relationships.get(i).getToBeanName().equals(thisBeanName) && (Utils.makeGet(mappedBy).equals(relationships.get(i).getName())))
          return relationships.get(i);
      }
    }

    return null;
  }

  /**
   * Restituisce tutte le relazioni di un bean
   *
   */
  public Vector<Relationship> getRelationships(String beanName) throws Exception
  {
    if (Cache.exists(beanName, "getRelationships"))
      return (Vector<Relationship>) Cache.get(beanName, "getRelationships");

    Vector<Relationship> tmp = new Vector<Relationship>();

    Class cBean = getClass(beanName);

    Method methods[] = cBean.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/

    java.util.Arrays.sort(methods, new JavaMethodComparator());

    for (int j = 0; j < methods.length; j++)
    {
      Annotation annotations[] = methods[j].getAnnotations();
      Relationship rel = null;

      // System.out.println("Metodo "+methods[j].getName());

      for (int k = 0; k < annotations.length; k++)
      {
        if (annotations[k].annotationType().equals(javax.persistence.OneToMany.class))
        {
          OneToMany a = (OneToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());

        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToOne.class))
        {
          ManyToOne a = (ManyToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToMany.class))
        {
          ManyToMany a = (ManyToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }

        if (annotations[k].annotationType().equals(javax.persistence.OneToOne.class))
        {
          OneToOne a = (OneToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }

        /**
         * Annotazioni relative alla generazione !!!!
         *
         */
        if (annotations[k].annotationType().equals(org.boco.seamwebappgen.annotations.Relationship.class))
        {

          org.boco.seamwebappgen.annotations.Relationship relAnnotation = (org.boco.seamwebappgen.annotations.Relationship) annotations[k];

          if (relAnnotation.used())
            rel.setUsed(true);

          if (relAnnotation.help())
            rel.setHelp(true);

          if (relAnnotation.required())
            rel.setRequired(true);

          rel.setOrderInForm(relAnnotation.orderInForm());

          rel.setShowOnCreateIf(relAnnotation.showOnCreateIf());
          rel.setShowOnDeleteIf(relAnnotation.showOnDeleteIf());
          rel.setShowOnDisplayIf(relAnnotation.showOnDisplayIf());
          rel.setShowOnEditIf(relAnnotation.showOnEditIf());

          rel.setDisableOnCreateIf(relAnnotation.disableOnCreateIf());
          rel.setDisableOnEditIf(relAnnotation.disableOnEditIf());                   
         
          String events[] = relAnnotation.events();
          for (int i = 0; i < events.length; i++)
            rel.addEvent(events[i]);

          String eventFunctions[] = relAnnotation.eventFunctions();
          for (int i = 0; i < events.length; i++)
            rel.addEventFunction(eventFunctions[i]);

          rel.setAjaxEvent(relAnnotation.ajaxEvent());

          String ids[] = relAnnotation.idsToRerenderOnAjaxEvent();
          for (int i = 0; i < ids.length; i++)
            rel.addIdToRerenderOnAjaxEvent(ids[i]);
                   
          // Incompleto ?

          if ((relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.LISTBOX) || relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.LISTBOX_AND_FREETEXT) || relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.OPTIONS)) && rel.isUsed())
          {
            rel.setListBox(true);

            if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.LISTBOX_AND_FREETEXT))
              rel.setFreeText(true);

            if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.OPTIONS))
              rel.setOptions(true);

            rel.setMasterDetail(false);

            String selectionAttributes[] = relAnnotation.selectionAttributes();

            if (selectionAttributes.length == 0)
              throw new MissingSelectionAttributeException(beanName, rel.getName());

            if (selectionAttributes[0].equals(""))
              throw new MissingSelectionAttributeException(beanName, rel.getName());

            checkSelectionAttributes(beanName, rel, selectionAttributes);

            rel.setRelatedAttributes(Utils.makeShowAttributeVector(rel.getToBeanName(), selectionAttributes, this));
          }

          if ( (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.POPUP) || relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.CRUDPOPUP) ) && rel.isUsed())
          {
            rel.setListBox(false);
            rel.setMasterDetail(false);

            if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.CRUDPOPUP))
              rel.setCRUD(true);
           
           
            String selectionAttributes[] = relAnnotation.selectionAttributes();

            if (selectionAttributes.length == 0)
              throw new MissingSelectionAttributeException(beanName, rel.getName());

            checkSelectionAttributes(beanName, rel, selectionAttributes);

            rel.setRelatedAttributes(Utils.makeShowAttributeVector(rel.getToBeanName(), selectionAttributes, this));

            // Lettura delle azioni abilitate
            rel.setPopUpCreate(false);
            rel.setPopUpDelete(false);
            rel.setPopUpEdit(false);
            rel.setPopUpSelectItems(false);

            PopUpEnabledActionType enablesActions[] = relAnnotation.enabledActions();
            for (int i = 0; i < enablesActions.length; i++)
            {
              if (enablesActions[i].equals(PopUpEnabledActionType.ALL))
              {
                rel.setPopUpCreate(true);
                rel.setPopUpDelete(true);
                rel.setPopUpEdit(true);
                rel.setPopUpSelectItems(true);
              }
              if (enablesActions[i].equals(PopUpEnabledActionType.CREATE))
              {
                rel.setPopUpCreate(true);
              }
              if (enablesActions[i].equals(PopUpEnabledActionType.DELETE))
              {
                rel.setPopUpDelete(true);
              }
              if (enablesActions[i].equals(PopUpEnabledActionType.EDIT))
              {
                rel.setPopUpEdit(true);
              }
              if (enablesActions[i].equals(PopUpEnabledActionType.SELECTITEMS))
              {
                rel.setPopUpSelectItems(true);
              }
            }

            rel.setRelatedAndNewItemsOnlyInPopUp(relAnnotation.relatedAndNewItemsOnlyInPopUp());
          }

          if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.MASTER_DETAIL))
          {
            rel.setListBox(false);
            rel.setMasterDetail(true);

            if (Utils.isMaster(rel))
            {
              // Questo bean e' il master

              rel.setFromMaster(true);
              rel.setCategorized(relAnnotation.categorized());
            }
            else
            {
              // Questo bean e' il detail

              rel.setFromMaster(false);
              rel.setCategorized(false);

              String masterAttributes[] = relAnnotation.masterAttributes();

              if (masterAttributes.length == 0)
                throw new MissingMasterReferenceException(beanName, rel.getName());

              for (int i = 0; i < masterAttributes.length; i++)
              {
                if (masterAttributes[i].equals(""))
                  throw new MissingMasterReferenceException(beanName, rel.getName());
              }

              rel.setGoToMasterMenuItem(relAnnotation.goToMasterMenuItem());

              // FORSE NON FUNZIONA
              rel.setMasterAttributes(Utils.makeShowAttributeVector(rel.getToBeanName(), masterAttributes, this));

              // Legge anche gli attributi di selezione qualora venga inserito il riferimento al master anche nel form

              String selectionAttributes[] = relAnnotation.selectionAttributes();
              rel.setRelatedAttributes(Utils.makeShowAttributeVector(rel.getToBeanName(), selectionAttributes, this));
            }
          }
        }

      }

      if (rel != null)
        tmp.add(rel);
    }

    //System.out.println("SuperClass " + cBean.getSuperclass().getName());

    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunte le relazioni della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      tmp.addAll(this.getRelationships(superBeanName));
    }

    Cache.put(beanName, "getRelationships", tmp);

    return tmp;
  }

  /**
   * Restituisce tutte le relazioni di un bean, completando solo le informazioni provenienti
   * dalle annotazioni EJB3. Utilizzato per i check interni
   *
   */
  public Vector<Relationship> getRelationshipsLight(String beanName) throws Exception
  {
    if (Cache.exists(beanName, "getRelationshipsLight"))
      return (Vector<Relationship>) Cache.get(beanName, "getRelationshipsLight");

    Vector<Relationship> tmp = new Vector<Relationship>();

    Class cBean = getClass(beanName);

    Method methods[] = cBean.getDeclaredMethods();

    for (int j = 0; j < methods.length; j++)
    {
      Annotation annotations[] = methods[j].getAnnotations();
      Relationship rel = null;

      for (int k = 0; k < annotations.length; k++)
      {
        if (annotations[k].annotationType().equals(javax.persistence.OneToMany.class))
        {
          OneToMany a = (OneToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setUsed(true);

          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToOne.class))
        {
          ManyToOne a = (ManyToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToMany.class))
        {
          ManyToMany a = (ManyToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }

        if (annotations[k].annotationType().equals(javax.persistence.OneToOne.class))
        {
          OneToOne a = (OneToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());
        }
      }

      if (rel != null)
        tmp.add(rel);
    }

    //if (!cBean.getGenericSuperclass().equals(Object.class))
    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunte le relazioni della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      tmp.addAll(this.getRelationshipsLight(superBeanName));
    }

    Cache.put(beanName, "getRelationshipsLight", tmp);

    return tmp;
  }

  /**
   * Indica se un attributo e' utilizzato per la ricerca
   *
   */
  private boolean isSearch(Field f)
  {
    Annotation annotations[] = f.getAnnotations();

    for (int i = 0; i < annotations.length; i++)
    {
      Annotation annotation = annotations[i];

      if (annotation.annotationType().equals(org.boco.seamwebappgen.annotations.SearchOnAttribute.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce l'annotazione del tipo specificato di un attributo
   *
   */
  public Object getFieldAnnotation(Field f, Class annotationClass)
  {
    return f.getAnnotation(annotationClass);
  }

  /**
   * Restituisce l'annotazione del tipo specificato di un metodo
   *
   */
  public Object getMethodAnnotation(Method m, Class annotationClass)
  {
    return m.getAnnotation(annotationClass);
  }

  /**
   * Restituisce l'annotazione del tipo specificato di una classe
   *
   */

  public Object getBeanAnnotation(Class c, Class annotationClass)
  {
    return c.getAnnotation(annotationClass);
  }

  /**
   * Indica se un attributo e' utilizzato per la ricerca nella pagina list
   *
   */
  private boolean isLocalSearch(Field f)
  {
    Annotation annotations[] = f.getAnnotations();

    for (int i = 0; i < annotations.length; i++)
    {
      Annotation annotation = annotations[i];

      if (annotation.annotationType().equals(org.boco.seamwebappgen.annotations.LocalSearchOnAttribute.class))
        return true;
    }

    return false;
  }

  /**
   * Restituisce i nomi di tutti i bean correlati (a distanza 1) con il bean
   * indicato
   */
  public Vector<String> getAllRelateBeans(String beanName) throws Exception
  {
    if (Cache.exists(beanName, "getAllRelateBeans"))
      return (Vector<String>) Cache.get(beanName, "getAllRelateBeans");

    Vector<String> ret = new Vector<String>();

    Vector<Relationship> relationships = this.getRelationships(beanName);

    for (Relationship rel : relationships)
    {
      if (!ret.contains(rel.getToBeanName()))
        ret.add(rel.getToBeanName());
    }

    //    Class cBean = getClass(beanName);
    //   
    //    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    //    {
    //      // Il bean estende un altro bean
    //      // pertanto vanno aggiunte le relazioni della superclasse
    //
    //      String superBeanClass = cBean.getGenericSuperclass().toString();
    //      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());
    //
    //      ret.addAll(getAllRelateBeans(superBeanName));
    //    }

    Cache.put(beanName, "getAllRelateBeans", ret);

    return ret;
  }

  /**
   * Individua tutte le relazioni che hanno come target bean thisBeanName
   *
   */
  public Vector<Relationship> getAllRelationship2ThisBean(String thisBeanName) throws Exception
  {
    if (Cache.exists(thisBeanName, "getAllRelationship2ThisBean"))
      return (Vector<Relationship>) Cache.get(thisBeanName, "getAllRelationship2ThisBean");

    Vector<Relationship> ret = new Vector<Relationship>();

    Vector<String> relatedBeans = getAllRelateBeans(thisBeanName);

    for (String bean : relatedBeans)
    {
      Vector<Relationship> beanRealtionships = this.getRelationships(bean);

      for (Relationship rel : beanRealtionships)
      {

        /** Verifica se beanNameToCheck e' il padre di bean **/
        // public boolean isFather(String beanNameToCheck, Bean bean)
        if (rel.getToBeanName().compareTo(thisBeanName) == 0 || isFather(rel.getToBeanName(), thisBeanName))
          ret.add(rel);
      }
    }

    Cache.put(thisBeanName, "getAllRelationship2ThisBean", ret);
    return ret;
  }

  /**
   * Individua i nomi di tutte le relazioni di relatedBeanName che lo collega
   * a thisBeanName
   *
   */
  //  public Vector<String> getAllRelationshipNames2ThisBean(String thisBeanName) throws Exception
  //  {
  //    if (Cache.exists(thisBeanName,"getAllRelationshipNames2ThisBean"))
  //      return (Vector<String>)Cache.get(thisBeanName,"getAllRelationshipNames2ThisBean");
  //   
  //    Vector<String> ret = new Vector<String>();
  //
  //    Vector<String> relatedBeans = getAllRelateBeans(thisBeanName);
  //
  //    for (String bean : relatedBeans)
  //    {
  //      Vector<Relationship> beanRealtionships = this.getRelationships(bean);
  //
  //      for (Relationship rel : beanRealtionships)
  //      {
  //        if (rel.getToBeanName().compareTo(thisBeanName) == 0)
  //          ret.add(rel.getName());
  //      }
  //    }
  //
  //    Cache.put(thisBeanName,"getAllRelationshipNames2ThisBean",ret);
  //    return ret;
  //  }
  /**
   * Restituisce i nomi di tutte le relazioni di un bean
   * <br>
   * <br>
   * <br>
   * <b>Controllare questa funzione perche' probabilmente all'interno c'e' del codice che NON SERVE</b>
   *
   */
  public Vector<String> getRelationshipsNames(String beanName) throws Exception
  {
    if (Cache.exists(beanName, "getRelationshipsNames"))
      return (Vector<String>) Cache.get(beanName, "getRelationshipsNames");

    Vector<String> tmp = new Vector<String>();

    Class cBean = getClass(beanName);

    Method methods[] = cBean.getDeclaredMethods();

    for (int j = 0; j < methods.length; j++)
    {
      Annotation annotations[] = methods[j].getAnnotations();
      Relationship rel = null;

      // System.out.println("Metodo "+methods[j].getName());

      for (int k = 0; k < annotations.length; k++)
      {
        if (annotations[k].annotationType().equals(javax.persistence.OneToMany.class))
        {
          OneToMany a = (OneToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());

          // tmp.add(rel);
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToOne.class))
        {
          ManyToOne a = (ManyToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());

          // tmp.add(rel);
        }

        if (annotations[k].annotationType().equals(javax.persistence.ManyToMany.class))
        {
          ManyToMany a = (ManyToMany) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(true);
          rel.setToMany(true);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());

          // tmp.add(rel);
        }

        if (annotations[k].annotationType().equals(javax.persistence.OneToOne.class))
        {
          OneToOne a = (OneToOne) annotations[k];

          if (a.targetEntity().equals(""))
            throw new MissingTargetEntityException(beanName, methods[j].getName());

          rel = new Relationship(beanName);
          rel.setName(methods[j].getName());

          rel.setFromMany(false);
          rel.setToMany(false);
          rel.setToBeanClassName(a.targetEntity().getCanonicalName());
          rel.setMappedBy(a.mappedBy());

          // tmp.add(rel);
        }

        /**
         * Annotazioni relative alla generazione !!!!
         *
         */
        if (annotations[k].annotationType().equals(org.boco.seamwebappgen.annotations.Relationship.class))
        {

          org.boco.seamwebappgen.annotations.Relationship relAnnotation = (org.boco.seamwebappgen.annotations.Relationship) annotations[k];

          if (relAnnotation.used())
            rel.setUsed(true);

          rel.setOrderInForm(relAnnotation.orderInForm());

          rel.setShowOnCreateIf(relAnnotation.showOnCreateIf());
          rel.setShowOnDeleteIf(relAnnotation.showOnDeleteIf());
          rel.setShowOnDisplayIf(relAnnotation.showOnDisplayIf());
          rel.setShowOnEditIf(relAnnotation.showOnEditIf());
         
          String events[] = relAnnotation.events();
          for (int i = 0; i < events.length; i++)
            rel.addEvent(events[i]);

          String eventFunctions[] = relAnnotation.eventFunctions();
          for (int i = 0; i < events.length; i++)
            rel.addEventFunction(eventFunctions[i]);
         
          rel.setAjaxEvent(relAnnotation.ajaxEvent());

          String ids[] = relAnnotation.idsToRerenderOnAjaxEvent();
          for (int i = 0; i < ids.length; i++)
            rel.addIdToRerenderOnAjaxEvent(ids[i]);
         
          // Incompleto

          if ((relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.LISTBOX) || relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.LISTBOX_AND_FREETEXT) || relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.OPTIONS)) && rel.isUsed())
          {
            rel.setListBox(true);

            if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.LISTBOX_AND_FREETEXT))
              rel.setFreeText(true);

            if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.OPTIONS))
              rel.setOptions(true);

            rel.setMasterDetail(false);

            String selectionAttributes[] = relAnnotation.selectionAttributes();

            if (selectionAttributes.length == 0)
              throw new MissingSelectionAttributeException(beanName, rel.getName());

            if (selectionAttributes.length > 1)
              throw new TooManySelectionAttributesException(beanName, rel.getName());

            if (selectionAttributes[0].equals(""))
              throw new MissingSelectionAttributeException(beanName, rel.getName());

            rel.setRelatedAttributes(Utils.makeShowAttributeVector(rel.getToBeanName(), selectionAttributes, this));
          }

          if ( (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.POPUP) || relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.CRUDPOPUP)) && rel.isUsed())
          {
            rel.setListBox(false);
            rel.setMasterDetail(false);
           
            if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.CRUDPOPUP))
              rel.setCRUD(true);

            String selectionAttributes[] = relAnnotation.selectionAttributes();

            if (selectionAttributes.length == 0)
              throw new MissingSelectionAttributeException(beanName, rel.getName());

            rel.setRelatedAttributes(Utils.makeShowAttributeVector(rel.getToBeanName(), selectionAttributes, this));
          }
          if (relAnnotation.type().equals(org.boco.seamwebappgen.annotations.RelationshipImplementationType.MASTER_DETAIL))
          {
            rel.setListBox(false);
            rel.setMasterDetail(true);

            if (Utils.isMaster(rel))
            {
              rel.setFromMaster(true);
            }
            else
            {
              rel.setFromMaster(false);
              // Questo bean e' il detail
              String masterAttributes[] = relAnnotation.masterAttributes();

              if (masterAttributes.length == 0)
                throw new MissingMasterReferenceException(beanName, rel.getName());

              for (int i = 0; i < masterAttributes.length; i++)
              {
                if (masterAttributes[i].equals(""))
                  throw new MissingMasterReferenceException(beanName, rel.getName());
              }

              // FORSE NON FUNZIONA
              rel.setMasterAttributes(Utils.makeShowAttributeVector(rel.getToBeanName(), masterAttributes, this));
            }
          }
        }

      }

      if (rel != null)
        tmp.add(rel.getName());
    }

    //if (!cBean.getGenericSuperclass().equals(Object.class))
    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      // Il bean estende un altro bean
      // pertanto vanno aggiunte le relazioni della superclasse

      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      tmp.addAll(this.getRelationshipsNames(superBeanName));
    }

    Cache.put(beanName, "getRelationshipsNames", tmp);

    return tmp;
  }

  /**
   * Verifica se un attributo esiste in uno specifico bean
   *
   */
  public boolean isFieldContained(String beanName, String field)
  {
    Class cBean = this.getClass(beanName);

    Field fs[] = getFields(cBean);

    for (Field f : fs)
    {
      if (f.getName().equals(field))
        return true;
    }

    // Nel caso in cui il bean abbia un Super Bean
    // il check di esistenza va fatto anche sugli attributi
    // del super bean

    //if (!cBean.getGenericSuperclass().equals(Object.class))
    if (!cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null && !cBean.getSuperclass().getName().contains("Users$User"))
    {
      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      Class cSuperBean = this.getClass(superBeanName);

      fs = getFields(cSuperBean);

      for (Field f : fs)
      {
        if (f.getName().equals(field))
          return true;
      }
    }

    return false;
  }

  /**
   * Verifica se esiste un bean con il nome indicato
   */
  public boolean beanExist(String beanName)
  {
    Vector<String> beanNames = getBeanNames();

    return beanNames.contains(beanName);
  }

  /**
   * Restituisce la relazione indicata dal nome
   *
   */
  public Relationship getRelationship(String relationshipName) throws Exception
  {
    if (Cache.exists(relationshipName, "getRelationship"))
      return (Relationship) Cache.get(relationshipName, "getRelationship");

    Vector<String> beanNames = this.getBeanNames();

    for (String beanName : beanNames)
    {
      Vector<Relationship> relationships = getRelationshipsLight(beanName);

      for (Relationship rel : relationships)
      {
        if (rel.getName().equals(relationshipName))
        {
          Cache.put(relationshipName, "getRelationship", rel);
          return rel;
        }
      }
    }

    return null;
  }

  /**
   * Effettua il check di esistenza dei selectionAttributes
   *
   */
  public void checkSelectionAttributes(String beanName, Relationship rel, String selectionAttributes[]) throws Exception
  {
    if (selectionAttributes.length == 0)
      throw new MissingSelectionAttributeException(beanName, rel.getName());

    // Verifica esistenza selectionAttributes
    for (String attr : selectionAttributes)
    {
      if (attr.equals(""))
        throw new MissingSelectionAttributeException(beanName, rel.getName());

      if (attr.contains("."))
      {
        Vector<String> relations = Utils.splitRelationships(attr);

        String toBeanName = rel.getToBeanName();

        for (int m = 0; m < relations.size() - 1; m++)
        {
          Relationship rel1 = this.getRelationship(toBeanName, relations.get(m));

          if (rel1 == null)
            throw new WrongRelatedBeanException(beanName, relations.get(m), toBeanName);

          toBeanName = rel1.getToBeanName();

          if (m == relations.size() - 1)
            if (!isFieldContained(toBeanName, relations.get(relations.size())))
              throw new WrongSelectionAttributeException(beanName, rel.getName(), toBeanName, relations.get(relations.size()));

        }

        //        String relatedBean = Utils.splitRelation(attr);
        //        String relatedAttr = Utils.splitAttribute(attr);
        //        Relationship relation = getRelationship(relatedBean);

        //        if (relation == null)
        //          throw new WrongRelatedBeanException(beanName, rel.getName(), relatedBean);

        //        String toBeanName = relation.getToBeanName();
        //
        //        if (!beanExist(toBeanName))
        //          throw new WrongRelatedBeanException(beanName, rel.getName(), relatedBean);

        //        if (!isFieldContained(toBeanName, relatedAttr))
        //          ;
        // throw new WrongSelectionAttributeException(beanName, rel.getName(), toBeanName, relatedAttr);
      }
      else if (!isFieldContained(rel.getToBeanName(), attr))
        throw new WrongSelectionAttributeException(beanName, rel.getName(), rel.getToBeanName(), attr);
    }
  }

  /**
   * Dato un bean restituisce la relazione che conduce al bean master, se esiste, altrimenti null
   */
  public Relationship getRelationshipToMaster(String fromBeanName, String toBeanName) throws Exception
  {
    Relationship ret = null;

    Bean bean = getBean(fromBeanName);

    Vector<Relationship> relationships = bean.getRelationships();

    for (Relationship rel : relationships)
    {
      if (rel.isMasterDetail() && !rel.isFromMaster() && rel.getToBeanName().equals(toBeanName))
        return rel;
    }
    return ret;
  }

  /**
   * Estrae un metodo da una classe a partire dal suo nome
   */
  public Method getMethod(Class c, String methodName)
  {
    if (Cache.exists(c.getName(), methodName))
      return (Method) Cache.get(c.getName(), methodName);

    Method methods[] = c.getMethods();
    for (int i = 0; i < methods.length; i++)
    {
      Method method = methods[i];
      if (method.getName().equals(methodName) || method.toString().contains(methodName))
      {
        Cache.put(c.getName(), methodName, method);

        return method;
      }
    }

    return null;
  }

  /**
   * Restituisce tutte le annotazioni di un metodo in una stringa
   * <br>
   * <b>
   * ATTENZIONE QUESTA FUNZIONE SEMBRA NON FUNZIONARE
   * <br>
   * getAnnotations non ritorna nulla
   * </b>
   */
  public String getMethodAnnotations(Method method)
  {
    String ret = "";

    Annotation annotations[] = method.getAnnotations();

    for (int i = 0; i < annotations.length; i++)
    {
      Annotation annotation = annotations[i];

      ret += annotation.toString() + "\r\n";
    }

    return ret;
  }

  /**
   * Restituisce in una stringa lo scope del bean
   * 
   */
  public String getBeanScope(String beanName)
  {
    String ret = "";

    Class cBean = this.getClass(beanName);

    org.boco.seamwebappgen.annotations.BeanManagerScope beanManagerScopeAnnotation = (org.boco.seamwebappgen.annotations.BeanManagerScope) cBean.getAnnotation(org.boco.seamwebappgen.annotations.BeanManagerScope.class);

    if (beanManagerScopeAnnotation != null && beanManagerScopeAnnotation.scope() != null)
      return beanManagerScopeAnnotation.scope().toString();

    // Non c'è annotazione, quindi viene utilizzato lo stesso scope del bean

    org.jboss.seam.annotations.Scope scopeAnnotation = (org.jboss.seam.annotations.Scope) cBean.getAnnotation(org.jboss.seam.annotations.Scope.class);

    ret = scopeAnnotation.value().toString();

    return ret;
  }

  /**
   * Restituisce in una stringa tutte le annotazione di sicurezza di un metodo, altrimenti una string vuota
   * 
   */
  public String getSecurityMethodAnnotations(Class beanManagerClass, String methodName)
  {
    String ret = "";

    Method method = getMethod(beanManagerClass, methodName);
    if (method != null)
    {
      Object annotation = getMethodAnnotation(method, RolesAllowed.class);

      if (annotation != null)
      {
        String roles[] = ((RolesAllowed) annotation).value();

        ret = "\t@RolesAllowed( {";

        for (int i = 0; i < roles.length; i++)
        {
          if (i > 0)
            ret += ", ";
          ret += "\"" + roles[i] + "\"";
        }

        ret += "} )";
      }

      annotation = getMethodAnnotation(method, PermitAll.class);

      if (annotation != null)
      {
        if (!ret.equals(""))
          ret += "\r\n";

        ret += "\t@PermitAll";
      }

      annotation = getMethodAnnotation(method, DenyAll.class);

      if (annotation != null)
      {
        if (!ret.equals(""))
          ret += "\r\n";

        ret += "\t@DenyAll";
      }
    }

    return ret;
  }

  /**
   * Inserisce le bean le informazioni relative
   * alle eventuali azioni presenti nella pagina di
   * risultato della ricerca
   * @param bean
   */
  public void setSearchListActionsInfo(Bean bean)
  {
    Class cBean = this.getClass(bean.getName());

    SearchResultList searchInfoAnnotation = (SearchResultList) cBean.getAnnotation(SearchResultList.class);

    if (searchInfoAnnotation != null)
    {
      Vector<String> tmp = new Vector<String>();
      for (int i = 0; i < searchInfoAnnotation.actionLabels().length; i++)
      {
        tmp.add(searchInfoAnnotation.actionLabels()[i]);
      }
      bean.setSearchActionLabels(tmp);

      tmp = new Vector<String>();
      for (int i = 0; i < searchInfoAnnotation.actions().length; i++)
      {
        tmp.add(searchInfoAnnotation.actions()[i]);
      }
      bean.setSearchActions(tmp);
     
      tmp = new Vector<String>();
      for (int i = 0; i < searchInfoAnnotation.immediateActionLabels().length; i++)
      {
        tmp.add(searchInfoAnnotation.immediateActionLabels()[i]);
      }
      bean.setSearchImmediateActionLabels(tmp);

      tmp = new Vector<String>();
      for (int i = 0; i < searchInfoAnnotation.immediateActions().length; i++)
      {
        tmp.add(searchInfoAnnotation.immediateActions()[i]);
      }
      bean.setSearchImmediateActions(tmp);     
    }
  }


  /**
   * Dato un bean individua tutti i bean derivati da questo
   * <br>
   * <b>NB</b>: La funzione individua solo i bean derivati di primo livello !
   *
   */
  public Vector<String> getDerivedBeans(String beanName)
  {
    Vector<String> ret = new Vector<String>();

    Class beanClass = getClass(beanName);

    Vector<String> allBeanNames = this.getBeanNames();

    for (String localBeanName : allBeanNames)
    {
      Class localBeanClass = getClass(localBeanName);

      Class localSuperBeanClass = localBeanClass.getSuperclass();

      if (beanClass.getName().equals(localSuperBeanClass.getName()))
        ret.add(localBeanClass.getSimpleName());
    }

    return ret;
  }

  /**
   * Dato un bean ed una relazione.
   *
   * La funzione restituisce la funzione che va dal bean target al bean 
   *
   */
  public Relationship getInverseRelationship(Bean bean, Relationship relationship) throws Exception
  {
    Vector<Relationship> targetBeanRelationships = getRelationships(relationship.getToBeanName());

    for (Relationship rel : targetBeanRelationships)
    {
      if (rel.getToBeanName().equals(bean.getName()) || isFather(rel.getToBeanName(), bean))
      {
        // La relazione punta al bean di partenza
        if (relationship.getMappedBy() != null && !relationship.getMappedBy().equals(""))
        {
          if (Utils.makeGet(relationship.getMappedBy()).equals(rel.getName()))
          {
            return rel;
          }
        }
        else
        {
          if (Utils.makeGet(rel.getMappedBy()).equals(relationship.getName()))
          {
            return rel;
          }
        }
      }
    }

    return null;
  }

  /**
   * Restituisce le liste di visualizzazione del bean
   */
  public Vector<ShowList> getLists(String beanName) throws WrongShowEnableRolesListException
  {
    Vector<ShowList> ret = new Vector<ShowList>();

    if (Cache.exists(beanName, "getLists"))
      return (Vector<ShowList>) Cache.get(beanName, "getLists");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.ShowList listAnnotation = (org.boco.seamwebappgen.annotations.ShowList) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.ShowList.class);

    if (listAnnotation == null)
    {
      ret.add(new ShowList(beanName, "", "", false, "[]", "", ""));
    }
    else
    {
      for (int i = 0; i < listAnnotation.names().length; i++)
      {
        ShowList tmp = new ShowList(beanName, listAnnotation.names()[i], listAnnotation.filters()[i], listAnnotation.mains()[i], listAnnotation.enabledRoles()[i], listAnnotation.printMenuOptionConditionsInList()[i], listAnnotation.newMenuOptionConditions()[i]);
        ret.add(tmp);
      }
    }

    Cache.put(beanName, "getLists", ret);

    return ret;
  }

  /**
   * Restituisce la condizione per la voce di menu Stampa nel form del bean
   */
  public String getPrintMenuOptionConditionInForm(String beanName) throws WrongShowEnableRolesListException
  {
    String ret;

    if (Cache.exists(beanName, "getPrintMenuOptionConditionInForm"))
      return (String) Cache.get(beanName, "getPrintMenuOptionConditionInForm");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.ShowList listAnnotation = (org.boco.seamwebappgen.annotations.ShowList) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.ShowList.class);

    if (listAnnotation == null)
    {
      ret = "";
    }
    else
    {
      ret = listAnnotation.printMenuOptionConditionInForm();
    }

    Cache.put(beanName, "getPrintMenuOptionConditionInForm", ret);

    return ret;
  }

  /**
   * Restituisce le liste di gruppi di form del bean
   */
  public Vector<FormFieldsGroup> getFormGroups(String beanName) throws WrongShowEnableRolesListException
  {
    Vector<FormFieldsGroup> ret = new Vector<FormFieldsGroup>();

    if (Cache.exists(beanName, "getFormGroups"))
      return (Vector<FormFieldsGroup>) Cache.get(beanName, "getFormGroups");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.FormFieldsGroups groupAnnotation = (org.boco.seamwebappgen.annotations.FormFieldsGroups) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.FormFieldsGroups.class);

    if (groupAnnotation == null)
    {
    }
    else
    {
      for (int i = 0; i < groupAnnotation.titles().length; i++)
      {
        FormFieldsGroup tmp = new FormFieldsGroup();

        tmp.setTitle(groupAnnotation.titles()[i]);
        tmp.setFromFieldOrder(groupAnnotation.fromFieldOrders()[i]);
        tmp.setToFieldOrder(groupAnnotation.toFieldOrders()[i]);

        if (groupAnnotation.showOnCreateIf().length > 0)
          tmp.setShowOnCreateIf(groupAnnotation.showOnCreateIf()[i]);

        if (groupAnnotation.showOnDeleteIf().length > 0)
          tmp.setShowOnDeleteIf(groupAnnotation.showOnDeleteIf()[i]);

        if (groupAnnotation.showOnDisplayIf().length > 0)
          tmp.setShowOnDisplayIf(groupAnnotation.showOnDisplayIf()[i]);

        if (groupAnnotation.showOnEditIf().length > 0)
          tmp.setShowOnEditIf(groupAnnotation.showOnEditIf()[i]);

        ret.add(tmp);
      }
    }

    Cache.put(beanName, "getFormGroups", ret);

    return ret;
  }

  /**
   * Restituisce la lista principale della applicazione
   */
  public ShowList getMainList() throws WrongShowEnableRolesListException, MoreThenOneMainListException
  {
    Vector<String> beans = getBeanNames();
    Vector<ShowList> mainLists = new Vector<ShowList>();

    if (beans == null)
      return null;

    for (String bean : beans)
    {
      Vector<ShowList> lists = getLists(bean);

      for (ShowList list : lists)
      {
        if (list.isMain())
          mainLists.add(list);
      }
    }

    if (mainLists.size() == 1)
      return mainLists.get(0);

    if (mainLists.size() > 1)
      throw new MoreThenOneMainListException(mainLists);

    return null;
  }

  /**
   * Restituisce i ruoli abilitati alla creazione di un bean
   */
  public Vector<String> getRolesEnabledToCreate(String beanName)
  {
    Vector<String> ret = new Vector<String>();

    if (Cache.exists(beanName, "getRolesEnabledToCreate"))
      return (Vector<String>) Cache.get(beanName, "getRolesEnabledToCreate");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      String roles[] = securityAnnotation.rolesEnabledToCreate();
      for (String role : roles)
      {
        ret.add(role);
      }
    }

    Cache.put(beanName, "getRolesEnabledToCreate", ret);

    return ret;
  }

  /**
   * Restituisce i ruoli abilitati alla modifica di un bean
   */
  public Vector<String> getRolesEnabledToEdit(String beanName)
  {
    Vector<String> ret = new Vector<String>();

    if (Cache.exists(beanName, "getRolesEnabledToEdit"))
      return (Vector<String>) Cache.get(beanName, "getRolesEnabledToEdit");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      String roles[] = securityAnnotation.rolesEnabledToEdit();
      for (String role : roles)
      {
        ret.add(role);
      }
    }

    Cache.put(beanName, "getRolesEnabledToEdit", ret);

    return ret;
  }

  /**
   * Restituisce i ruoli abilitati alla cancellazione di un bean
   */
  public Vector<String> getRolesEnabledToDelete(String beanName)
  {
    Vector<String> ret = new Vector<String>();

    if (Cache.exists(beanName, "getRolesEnabledToDelete"))
      return (Vector<String>) Cache.get(beanName, "getRolesEnabledToDelete");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      String roles[] = securityAnnotation.rolesEnabledToDelete();
      for (String role : roles)
      {
        ret.add(role);
      }
    }

    Cache.put(beanName, "getRolesEnabledToDelete", ret);

    return ret;
  }

  /**
   * Restituisce i ruoli abilitati alla cancellazione di un bean
   */
  public Vector<String> getRolesEnabledToSearch(String beanName)
  {
    Vector<String> ret = new Vector<String>();

    if (Cache.exists(beanName, "getRolesEnabledToSearch"))
      return (Vector<String>) Cache.get(beanName, "getRolesEnabledToSearch");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      String roles[] = securityAnnotation.rolesEnabledToSearch();
      for (String role : roles)
      {
        ret.add(role);
      }
    }

    Cache.put(beanName, "getRolesEnabledToSearch", ret);

    return ret;
  }

  /**
   * Restituisce la condizione che abilita alla creazione di un bean
   */
  public String getCreateCondition(String beanName)
  {
    String ret = null;

    if (Cache.exists(beanName, "getCreateCondition"))
      return (String) Cache.get(beanName, "getCreateCondition");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      if (!securityAnnotation.createCondition().equals(""))
        ret = securityAnnotation.createCondition();
    }

    Cache.put(beanName, "getCreateCondition", ret);

    return ret;
  }

  /**
   * Restituisce la condizione che abilita alla modifica di un bean
   */
  public String getEditCondition(String beanName)
  {
    String ret = null;

    if (Cache.exists(beanName, "getEditCondition"))
      return (String) Cache.get(beanName, "getEditCondition");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      if (!securityAnnotation.editCondition().equals(""))
        ret = securityAnnotation.editCondition();
    }

    Cache.put(beanName, "getEditCondition", ret);

    return ret;
  }

  /**
   * Restituisce la condizione che abilita alla cancella di un bean
   */
  public String getDeleteCondition(String beanName)
  {
    String ret = null;

    if (Cache.exists(beanName, "getDeleteCondition"))
      return (String) Cache.get(beanName, "getDeleteCondition");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      if (!securityAnnotation.deleteCondition().equals(""))
        ret = securityAnnotation.deleteCondition();
    }

    Cache.put(beanName, "getDeleteCondition", ret);

    return ret;
  }

  /**
   * Restituisce la condizione che abilita alla cancella di un bean
   */
  public String getSearchCondition(String beanName)
  {
    String ret = null;

    if (Cache.exists(beanName, "getSearchCondition"))
      return (String) Cache.get(beanName, "getSearchCondition");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.Security securityAnnotation = (org.boco.seamwebappgen.annotations.Security) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.Security.class);

    if (securityAnnotation != null)
    {
      if (!securityAnnotation.deleteCondition().equals(""))
        ret = securityAnnotation.searchCondition();
    }

    Cache.put(beanName, "getSearchCondition", ret);

    return ret;
  }

  /**
   * Dati un nome di bean ed un nome di relazione, restituisce l'oggetto relazione
   */
  public Relationship getRelationship(String beanName, String relationshipName) throws Exception
  {
    Vector<Relationship> relationships = getRelationships(beanName);

    for (Relationship relationship : relationships)
    {
      if (relationship.getName().equals(relationshipName))
      {
        return relationship;
      }
    }

    return null;
  }

  /**
   * Restituisce tutti i campi che compongono la chiave
   */
  public Vector<KeyInfo> getBeanKeyComponents(Bean bean)
  {
    Vector<KeyInfo> ret = new Vector<KeyInfo>();

    String keyClassName = bean.getKey().getType();

    Class keyClass = getKeyClass(keyClassName);

    if (keyClass.getName().equals("java.lang.Long"))
      return ret;

    Method methods[] = keyClass.getDeclaredMethods();

    /** Ordinamento degli attributi per nome **/
    java.util.Arrays.sort(methods, new JavaMethodComparator());

    for (int i = 0; i < methods.length; i++)
    {
      if (methods[i].getName().startsWith("get") && !methods[i].getName().equals("getSerialVersionUID"))
      {
        KeyInfo keyInfo = new KeyInfo();

        keyInfo.setMethod(methods[i].getName());

        if (methods[i].getReturnType().getCanonicalName().equals("java.lang.Long"))
          keyInfo.setString(false);
        else
          keyInfo.setString(true);

        ret.add(keyInfo);
      }
    }
    return ret;
  }

  /**
   * Restituisce true se per il bean deve essere predisposto il form di gestione del bean in una popup separata
   * <br>
   * <br>
   * Questo si verifica se esiste almeno una relazione verso questo bean implementata come CRUDPOPUP 
   */
  public boolean BeanCrudInPopUp(String beanName)
  {
//    Class beanClass = getClass(beanName);

//    Annotation annotations[] = beanClass.getAnnotations();
//
//    for (Annotation annotation : annotations)
//    {
//      if (annotation.annotationType().equals(CRUDInSeparatePopUp.class))
//        return true;
//    }

    Vector<Relationship> relationships2ThisBean;
    try
    {
      relationships2ThisBean = getAllRelationship2ThisBean(beanName);
     
      for(Relationship rel : relationships2ThisBean)
      {
        if (!rel.isListBox() && rel.isCRUD())
        {
          return true;
        }
      }
           
    }
    catch (Exception e)
    {
      e.printStackTrace();
      return false;
    }
   
    return false;
  }

  /**
   * Restituisce le informazioni sulla lista risultato della ricerca
   */
  public String getNewMenuOptionConditionOnListSearch(String beanName)
  {
    String ret = "";

    if (Cache.exists(beanName, "getNewMenuOptionConditionOnListSearch"))
      return (String) Cache.get(beanName, "getNewMenuOptionConditionOnListSearch");

    Class cBean = this.getClass(beanName);
    org.boco.seamwebappgen.annotations.SearchResultList listAnnotation = (org.boco.seamwebappgen.annotations.SearchResultList) getBeanAnnotation(cBean, org.boco.seamwebappgen.annotations.SearchResultList.class);

    if (listAnnotation == null)
    {
      ;
    }
    else
    {
      ret = listAnnotation.newMenuOptionCondition();
    }

    Cache.put(beanName, "getNewMenuOptionConditionOnListSearch", ret);

    return ret;
  }

  /** Verifica se beanNameToCheck e' il padre di bean **/
  public boolean isFather(String beanNameToCheck, Bean bean)
  {
    Class cBean = getClass(bean.getName());

    while (cBean != null && !cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null)
    {
      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      if (beanNameToCheck.equals(superBeanName))
        return true;

      cBean = cBean.getGenericSuperclass().getClass();
    }

    return false;
  }

  /** Verifica se beanNameToCheck e' il padre di beanName **/
  public boolean isFather(String beanNameToCheck, String beanName)
  {
    Class cBean = getClass(beanName);

    while (cBean != null && !cBean.getGenericSuperclass().equals(Object.class) && cBean.getSuperclass() != null)
    {
      String superBeanClass = cBean.getGenericSuperclass().toString();
      String superBeanName = superBeanClass.substring(superBeanClass.lastIndexOf(".") + 1, superBeanClass.length());

      if (beanNameToCheck.equals(superBeanName))
        return true;

      cBean = cBean.getGenericSuperclass().getClass();
    }

    return false;
  }

}
TOP

Related Classes of org.boco.seamwebappgen.info.InfoReader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.