Package org.boco.seamwebappgen

Source Code of org.boco.seamwebappgen.SeamBasedGenerator

/***************************************************************************
*  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/Attic/SeamBasedGenerator.java,v 1.1.2.4 2008/05/27 17:00:49 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.4 $
- $Date: 2008/05/27 17:00:49 $
- $Log: SeamBasedGenerator.java,v $
- Revision 1.1.2.4  2008/05/27 17:00:49  fab
- Reingegnerizzazione delle CRUD in Poup
-
- Revision 1.1.2.3  2008/05/05 14:30:04  fab
- Modifiche alla procedura di installazione
- Modifiche per gestione entity home
-
- Revision 1.1.2.2.2.1  2008/04/27 20:59:33  fab
- *** empty log message ***
-
- Revision 1.1.2.2  2008/04/22 05:37:58  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.1  2008/04/19 13:12:48  fab
- Modifiche varie per rafactoring
-
- Revision 1.1.2.1  2008/04/19 11:18:34  fab
- Refactoring
-
- Revision 1.6.4.5  2008/04/19 10:07:02  fab
- Aggiornamento riferimenti licenza
-
- Revision 1.6.4.4  2008/04/02 13:25:05  fab
- Implementazione 0626/C
-
- Revision 1.6.4.3  2008/03/27 20:11:16  fab
- Inserita security sulla ricercca globale
-
- Revision 1.6.4.2  2008/03/26 08:36:49  fab
- Implementazione 0627/C
-
- Revision 1.6.4.1  2008/03/22 16:51:58  fab
- *** empty log message ***
-
- Revision 1.7  2008/03/22 09:24:58  fab
- Modifica per supportare condizioni di sicurezza diverse dal solo check dei ruoli sui metodi CRUD dei bean
-
- Revision 1.6  2008/01/28 16:31:47  fab
- Implementazione 0544/C
-
- Revision 1.5  2007/12/21 11:07:05  fab
- Dopo merge per supporto jboss 4.2.2
-
- Revision 1.4.2.2  2007/12/17 08:27:03  fab
- Implementazione generazione vista principale durante la generazione e non nella creazione del progetto (0405/C)
-
- Revision 1.4.2.1  2007/12/17 07:39:18  fab
- Implementazione generazione vista principale durante la generazione e non nella creazione del progetto (0405/C)
-
- Revision 1.4  2007/10/30 09:55:47  fab
- Implementazione 0303/C
-
- Revision 1.3  2007/10/25 09:54:25  fab
- Dopo merge TRINIDAD_1.2.2
-
- Revision 1.1.2.2  2007/10/24 06:51:07  fab
- Fix vari dal ramo head
-
- Revision 1.2  2007/10/06 07:06:11  fab
- Eliminati messaggi inutili sulla console
-
- Revision 1.1  2007/09/29 13:17:26  fab
- Nuova versione iniziale del 29/09/2007
-
- Revision 1.3.2.14  2007/09/29 09:38:34  fab
- Fix per ridurre i messaggi a console
-
- Revision 1.3.2.13  2007/09/26 08:02:39  fab
- Supporto per nuova annotazione IgnorePrintListForm e
- Supporto alla nuova opzione per @ShowList
-
- Revision 1.3.2.12  2007/09/11 09:07:27  fab
- Inserita l'annotazione CRUDInSeparatePopUp
-
- Revision 1.3.2.11  2007/08/30 20:28:11  fab
- Introdotta gestione annotazione @FormFieldsGroups
-
- Revision 1.3.2.10  2007/07/19 09:51:52  fab
- Modifiche per la gestione del form del bean (edit,create,delete,display) in una popup
-
- Revision 1.3.2.9  2007/06/21 09:24:49  fab
- Modifiche per inserire controllo unicità detail nel caso di MASTER-DETAIL 1:1
-
- Revision 1.3.2.8  2007/06/12 20:35:12  fab
- Introdotta annotazione @IgnoreLists
-
- Revision 1.3.2.7  2007/06/01 07:28:52  fab
- Inserite le annotazioni
-
- @IgnorePrintForm
- @IgnoreForm
-
- Revision 1.3.2.6  2007/05/19 09:33:29  dev
- Moltissime modifiche
-
- Revision 1.3.2.5  2007/03/25 09:31:20  dev
- Modifiche per la gestione della sicurezza sulle azioni
-
- Revision 1.3.2.4  2007/03/24 17:21:04  dev
- Modifiche per la gestione di più liste per lo stesso bean
-
- Revision 1.3.2.3  2007/03/24 12:29:19  dev
- Gestione della lista principale dell'applicazione
-
- Revision 1.3.2.2  2007/02/16 18:15:37  dev
- Fix vari
-
- Revision 1.3.2.1  2007/02/01 20:23:01  dev
- Inserita generazione stampa PDF per le liste
-
- Revision 1.3  2006/12/28 18:32:30  dev
- Modifiche per gestione della search
-
- Revision 1.2  2006/11/27 21:46:38  dev
- Modifiche per supportare gli attributi nella forma
-
- [relazione]*.attributo
-
- come attributi di selezione nelle PopUp
-
- Revision 1.1  2006/10/23 08:25:31  dev
- Prima versione separata dal generatore struts
-
- Revision 1.10  2006/09/03 15:49:16  dev
- Generazione delle stringhe di messaggi
- Fix nella lista
-
- Revision 1.9  2006/08/28 06:45:13  dev
- Completata generazione pagina HTML PopUp
-
- Revision 1.8  2006/08/25 10:10:37  dev
- Modifiche per la gestione delle PopUp
-
- Revision 1.7  2006/07/16 17:42:29  dev
- Inserita generazione del file pages.xml
-
- Revision 1.6  2006/07/13 09:51:20  dev
- *** empty log message ***
-
- Revision 1.5  2006/07/09 17:11:01  dev
- *** empty log message ***
-
- Revision 1.4  2006/07/02 16:36:51  dev
- Modificato package
-
- Revision 1.3  2006/07/02 07:52:15  dev
- *** empty log message ***
-
- Revision 1.2  2006/06/30 19:28:44  dev
- Modifiche iniziali per supportare la generazione Seam
-
**/
package org.boco.seamwebappgen;

import java.awt.Color;
import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Vector;

import javax.swing.JProgressBar;
import javax.swing.JTextArea;

import org.boco.seamwebappgen.cache.Cache;
import org.boco.seamwebappgen.info.Bean;
import org.boco.seamwebappgen.info.InfoReader;
import org.boco.seamwebappgen.info.ShowList;
import org.boco.seamwebappgen.seamGeneration.BeanManagerGenerator;
import org.boco.seamwebappgen.seamGeneration.HTMLGenerator;
import org.boco.seamwebappgen.seamGeneration.MessagesGenerator;
import org.boco.seamwebappgen.seamGeneration.PagesConfig;
import org.boco.seamwebappgen.utils.CustomCodeType;
import org.boco.seamwebappgen.utils.EntityCheck;
import org.boco.seamwebappgen.utils.Utils;


/**
* Il generatore per Seam
*
*  * @author Fabrizio Boco
*/
public class SeamBasedGenerator implements Runnable
{

  private String       sourceDir = "";
  private String       targetDir = "";
  private InfoReader   infoReader;
  private String       basePackage;
  private JTextArea    messageArea;
  private JProgressBar progressBar;

  /**
   * Crea una istanza del generatore
   *
   * @param sourceDir
   * directory in cui sono presenti le classi dei bean di cui generare
   * l'applicazione
   * @param targetDir
   * directory in cui verranno generati tutti i file
   */
  public SeamBasedGenerator(String sourceDir, String targetDir, JProgressBar progressBar, JTextArea messageArea)
  {
    if (sourceDir.endsWith(File.separator))
      this.sourceDir = sourceDir;
    else
      this.sourceDir = sourceDir + File.separator;

    if (targetDir.endsWith(File.separator))
      this.targetDir = targetDir;
    else
      this.targetDir = targetDir + File.separator;

    infoReader = new InfoReader(sourceDir);
    basePackage = infoReader.getPackage();

    this.messageArea = messageArea;
    this.progressBar = progressBar;
  }

  //public void generate() throws Exception
  public void run()
  {
    Long startTime = System.currentTimeMillis();
    int idx = 0;
    messageArea.setText("");

    // Pulisce la cache
   
    Cache.clear();
       
    // Prende la lista di tutti i bean
    Vector<String> beanNames = infoReader.getBeanNames();

    progressBar.setIndeterminate(true);
    progressBar.setMinimum(0);
    progressBar.setMaximum(beanNames.size() - 1);
    progressBar.setValue(idx);
    progressBar.setIndeterminate(false);
    progressBar.setForeground(Color.BLUE);
    progressBar.setStringPainted(true);

    try
    {
      // Generazione messaggi globali applicazione
      MessagesGenerator.generateApplicationMessages(sourceDir, targetDir);

      for (String beanName : beanNames)
      {
        messageArea.setText(beanName + " ...");
        System.out.println(beanName);

        if (!infoReader.ignoreBean(beanName))
        {
          EntityCheck ck = new EntityCheck();

          ck.check(beanName, infoReader.getClass(beanName), infoReader.getRelationships(beanName));

          Bean bean = new Bean();

          bean.setName(beanName, infoReader.getPackage());
          bean.setBasePackage(basePackage);
          bean.setAttributes(infoReader.getBeanAttributes(beanName));
          bean.setKey(infoReader.getBeanKey(beanName));
          bean.setRelationships(infoReader.getRelationships(beanName));

          bean.setScope(infoReader.getBeanScope(beanName));
         
          // Attributi da visualizzare nella lista del bean
          bean.setShowAttributes(infoReader.getBeanShowAttributes(beanName, bean.getRelationships()));

          // Attributi provenienti da relazioni da visualizzare nel form del bean
          bean.setShowInFormAttributes(infoReader.getBeanShowInFormAttributes(beanName, bean.getRelationships()));

          // Attributi da utilizzare per la ricerca
          bean.setSearchAttributes(infoReader.getBeanSearchAttributes(beanName, bean.getRelationships()));

          // Legge le informazioni relative alle azioni nella pagina risultato della ricerca
          infoReader.setSearchListActionsInfo(bean);

          // Attributi da utilizzare per la ricerca nella pagina list
          bean.setLocalSearchAttributes(infoReader.getBeanLocalSearchAttributes(beanName, bean.getRelationships()));
          bean.setPrintMenuConditionInForm(infoReader.getNewMenuOptionConditionOnListSearch(beanName));
         
         
          // Liste di visualizzazione del bean
          bean.setLists(infoReader.getLists(beanName));

          // Informazioni sulla lista risultato della ricerca
          bean.setNewMenuOptionConditionOnListSearch(infoReader.getNewMenuOptionConditionOnListSearch(beanName));
          bean.setPrintMenuOptionConditionOnListSearch("");

          // Abilitazioni per la sicurezza
          bean.setRolesEnabledToCreate(infoReader.getRolesEnabledToCreate(beanName));
          bean.setRolesEnabledToEdit(infoReader.getRolesEnabledToEdit(beanName));
          bean.setRolesEnabledToDelete(infoReader.getRolesEnabledToDelete(beanName));
          bean.setRolesEnabledToSearch(infoReader.getRolesEnabledToSearch(beanName));

          bean.setCreateCondition(infoReader.getCreateCondition(beanName));
          bean.setEditCondition(infoReader.getEditCondition(beanName));
          bean.setDeleteCondition(infoReader.getDeleteCondition(beanName));
          bean.setSearchCondition(infoReader.getSearchCondition(beanName));

          // Gruppi di attributi nel form
          bean.setFormFieldsGroups(infoReader.getFormGroups(beanName));

          /*
           * Tutti i passaggi precedenti potrebbero essere
           * accorpati nella funzione
           *
           * public Bean getBean(String beanName) throws Exception
           *
           * che al momento sembra essere incompleta !!!!!
           *
           */

          //System.out.println(bean);
          /**
           * Genera il session bean di gestione del bean
           */
          if (!infoReader.ignoreBeanManager(beanName))
            BeanManagerGenerator.generateManager(sourceDir, targetDir, basePackage, bean);

          /**
           * Configura Callback e Sicurezza
           */
          PagesConfig.addListPages(targetDir, bean);

          /**
           * Genera le pagine per la gestione delle popup
           */
          HTMLGenerator.generatePopUp(bean, sourceDir, targetDir, basePackage);

          /**
           * Genera la pagina di gestione del bean
           */
          if (!infoReader.ignoreForm(beanName))
          {
            // Genera il form standard
            HTMLGenerator.generateFormPage(sourceDir, targetDir, bean, false);

            // Genera il form per le operazioni sul form nella popup
            if (infoReader.BeanCrudInPopUp(beanName))
              HTMLGenerator.generateFormPage(sourceDir, targetDir, bean, true);
          }
          /**
           * Genera le pagine html di help
           */
          HTMLGenerator.generateHelp(sourceDir, targetDir, bean);

          /**
           * Genera la pagina di ricerca del bean
           */
          if (bean.getSearchAttributes().size() > 1)
            HTMLGenerator.generateFormPageSearch(sourceDir, targetDir, bean);

          /**
           * Genera le pagine per le liste dei bean
           */
          if (!infoReader.ignoreLists(beanName))
            HTMLGenerator.generateListPages(sourceDir, targetDir, basePackage, bean);

          /**
           * Genera la lista dei bean stampabile
           */
          if (!infoReader.ignorePrintListForm(beanName))
            HTMLGenerator.generateListPagePrint(sourceDir, targetDir, basePackage, bean);
          /**
           * Genera il form del bean stampabile
           */
          if (!infoReader.ignorePrintForm(beanName))
            HTMLGenerator.generateFormPagePrint(sourceDir, targetDir, basePackage, bean);

          if (bean.getSearchAttributes().size() > 1)
            HTMLGenerator.generateListPageSearch(sourceDir, targetDir, basePackage, bean);

          MessagesGenerator.generateMessages(sourceDir, targetDir, bean);
        }

        progressBar.setValue(idx++);
      }

      /** Gestione della vista principale **/

      ShowList mainList = infoReader.getMainList();

      if (mainList != null)
      {
        String template = "." + File.separator + "projectSkeleton" + File.separator + "src" + File.separator + "packageName" + File.separator + "manager" + File.separator + "MainListManagerBean.java";
       
        String sourceFile = sourceDir + ".." + File.separator + "src" + File.separator + basePackage + File.separator + "manager" + File.separator + "MainListManagerBean.java";
        String targetFile = sourceDir + ".." + File.separator + "src" + File.separator + basePackage + File.separator + "manager" + File.separator + "MainListManagerBean.java";
       
        LinkedList<String> yourCode = Utils.getYourCode(sourceFile, CustomCodeType.JAVA);
        LinkedList<String> yourJavaScriptCode = Utils.getYourCode(sourceFile, CustomCodeType.JAVA);
       
        HashMap<String, String> tags = new HashMap<String, String>();
       
        tags.put("@basePackage", basePackage);
        tags.put("@MainShowList", mainList.getName());

        Utils.SeamReplaceTagAndSave(tags, yourJavaScriptCode, yourCode, template, targetFile);
      }

      Long elapsed = System.currentTimeMillis() - startTime;
      messageArea.setText("OK\r\nElapsed time: " + elapsed + " ms - " + (elapsed / 1000) + " s - " + (elapsed / 1000 / 60) + " min");
    }
    catch (Exception e)
    {
      e.printStackTrace();
      messageArea.setText(e.getMessage());
      return;
    }

  }
}
TOP

Related Classes of org.boco.seamwebappgen.SeamBasedGenerator

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.