/***************************************************************************
* 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/EJB3PlugIn/src/boco/ejb3PlugIn/popup/actions/bean/Attic/EditEJB.java,v 1.1.2.6 2008/06/02 20:04:33 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.6 $
- $Date: 2008/06/02 20:04:33 $
- $Log: EditEJB.java,v $
- Revision 1.1.2.6 2008/06/02 20:04:33 fab
- Eliminate System.out
-
- Revision 1.1.2.5 2008/04/22 06:17:38 fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.4 2008/04/19 10:28:43 fab
- *** empty log message ***
-
- Revision 1.1.2.3 2008/04/19 10:26:49 fab
- Aggiornamento riferimenti licenza
-
- Revision 1.1.2.2 2008/04/06 15:59:31 fab
- Fix nella edit del bean
-
- Revision 1.1.2.1 2008/03/28 18:44:26 fab
- Refactoring delle azioni
- Internazionalizzazione di tutte le voci di menu
-
- Revision 1.1.2.8 2008/03/26 12:03:27 fab
- *** empty log message ***
-
- Revision 1.1.2.7 2008/03/22 12:00:00 fab
- Fix 0643/B
- Rimoninate alcune classi
-
- Revision 1.1.2.6 2008/02/22 07:16:14 fab
- *** empty log message ***
-
- Revision 1.1.2.5 2008/01/07 10:41:38 fab
- *** empty log message ***
-
- Revision 1.1.2.4 2007/11/07 10:35:44 fab
- Fix vari
-
- Revision 1.1.2.3 2007/11/07 10:19:28 fab
- Fix vari
- Gestione errori
-
- Revision 1.1.2.2 2007/11/05 13:31:16 fab
- Modifica delle annotazioni relative ai bean
- @ShowLists
- @Security
-
- Revision 1.1.2.1 2007/11/04 20:56:14 fab
- Review Interfaccia
-
- Revision 1.5.2.17 2007/10/01 15:16:05 fab
- Aggiornata dialog per la creazione del bean
- Riletta l'annotazione @ShowInForm
-
- Revision 1.5.2.16 2007/09/29 20:13:10 fab
- Fix del bug 0122/B
-
- Revision 1.5.2.15 2007/03/27 06:25:53 dev
- Completata gestione dei ruoli sulle azioni del bean
-
- Revision 1.5.2.14 2007/03/26 07:50:59 dev
- Acquisizione dati per liste multiple
-
- Revision 1.5.2.13 2007/03/25 21:33:11 dev
- Modifica interfaccia per supportare le liste multiple e la security dei bean
-
- Revision 1.5.2.12 2007/03/25 14:40:20 dev
- Acquisita la lista principale dell'applicazione
-
- Revision 1.5.2.11 2007/02/13 09:59:12 dev
- Modifica alla equals del bean
-
- Revision 1.5.2.10 2007/02/13 09:57:54 dev
- Modifica alla equals del bean
-
- Revision 1.5.2.9 2007/01/07 14:38:20 dev
- Modifiche Dicembre 2006
-
- Revision 1.5.2.8 2007/01/03 12:51:13 dev
- Fix per i tag CVS
-
- Revision 1.5.2.7 2007/01/03 12:50:24 dev
- Fix per i tag CVS
-
- Revision 1.5.2.6 2007/01/03 11:36:05 dev
- Inseriti disclaymer e tag cvs
-
- Revision 1.5.2.5 2007/01/03 10:39:10 dev
- I Bean sono creati nella CONVERSATION
-
- Revision 1.5.2.4 2006/12/25 11:10:18 dev
- Introdotta gestione degli errori
- Fix per le relazioni N:M che avevano l'ownership invertita
-
- Revision 1.5.2.3 2006/12/24 16:15:57 dev
- Acquisito il nome della relazione per le relazioni N:M
-
- Revision 1.5.2.2 2006/12/17 16:15:35 dev
- Riorganizzata la classe Utils che era divisia in due !?
-
- Revision 1.5.2.1 2006/08/28 08:48:49 dev
- Modifiche principli per il supporto di seam
-
- Revision 1.5 2006/05/21 13:41:18 dev
- Corretta annotazione cvs
-
**/
package boco.ejb3PlugIn.popup.actions.bean;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.StringReader;
import java.util.StringTokenizer;
import java.util.Vector;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import boco.ejb3PlugIn.gui.BeanDialog;
import boco.ejb3PlugIn.gui.ErrorMessageDialog;
import boco.ejb3PlugIn.gui.ListInfo;
import boco.ejb3PlugIn.utils.Utils;
public class EditEJB implements IObjectActionDelegate
{
private IJavaProject javaProject;
private IPackageFragment packageFragment;
private ICompilationUnit iCompilationUnit;
public EditEJB()
{
super();
}
public void setActivePart(IAction action, IWorkbenchPart targetPart)
{
}
public void run(IAction action)
{
try
{
String source = iCompilationUnit.getSource();
BeanDialog beanDialog = new BeanDialog(javaProject.getProject().getLocation().toOSString());
beanDialog.setBeanName(getBeanName(source));
/** Estrae le annotazioni **/
String beforeShowListAnnotation = getShowListAnnotation(source);
String beforeSecurityAnnotation = getSecurityAnnotation(source);
boolean beforeIgnoreBean = ignoreBean(source);
boolean beforeIgnoreBeanManager = ignoreBeanManager(source);
/** Caricamento dei dati annotazione @ShowList **/
if (!beforeShowListAnnotation.equals(""))
{
Vector<ListInfo> lists = getListsInfo(beforeShowListAnnotation);
beanDialog.setLists(lists);
}
/** Caricamento dei dati annotazione @Security **/
if (!beforeSecurityAnnotation.equals(""))
{
Vector<String> rolesEnabledToCreate = getRolesEnabledToCreate(beforeSecurityAnnotation);
beanDialog.setCreateEnabledRoles(rolesEnabledToCreate);
beanDialog.setCreateCondition(getCreateCondition(beforeSecurityAnnotation));
Vector<String> rolesEnabledToEdit = getRolesEnabledToEdit(beforeSecurityAnnotation);
beanDialog.setEditEnabledRoles(rolesEnabledToEdit);
beanDialog.setEditCondition(getEditCondition(beforeSecurityAnnotation));
Vector<String> rolesEnabledToDelete = getRolesEnabledToDelete(beforeSecurityAnnotation);
beanDialog.setDeleteEnabledRoles(rolesEnabledToDelete);
beanDialog.setDeleteCondition(getDeleteCondition(beforeSecurityAnnotation));
}
/** Caricamento dei dati sulle annotazioni sulla generazione **/
beanDialog.setIgnoreBean(beforeIgnoreBean);
beanDialog.setIgnoreBeanManager(beforeIgnoreBeanManager);
beanDialog.pack();
beanDialog.setLocationRelativeTo(null);
beanDialog.setVisible(true);
if (!beanDialog.isCancelled())
{
/** Rigenerazione del codice delle annotazioni **/
String afterShowListAnnotation = Utils.makeShowListAnnotation(beanDialog).replace(" = ", "=").replace(", ", ",").replace("\r", "").replace("\n", "");
String afterSecurityAnnotation = Utils.makeSecurityAnnotation(beanDialog).replace(" = ", "=").replace(", ", ",").replace("\r", "").replace("\n", "");
boolean afterIgnoreBean = beanDialog.ignoreBean();
boolean afterIgnoreBeanManager = beanDialog.ignoreBeanManager();
if (!beforeShowListAnnotation.replace(" = ", "=").replace(", ", ",").equals(afterShowListAnnotation) || !beforeSecurityAnnotation.replace(" = ", "=").replace(", ", ",").equals(afterSecurityAnnotation) || beforeIgnoreBean != afterIgnoreBean || beforeIgnoreBeanManager != afterIgnoreBeanManager
)
{
/** Deve essere rigenerato il codice **/
// System.out.println("\r\n");
// System.out.println(""+beforeShowListAnnotation.replace(" = ", "=").replace(", ", ","));
// System.out.println(""+afterShowListAnnotation);
// System.out.println("Equals "+beforeShowListAnnotation.replace(" = ", "=").replace(", ", ",").equals(afterShowListAnnotation));
//
//
// System.out.println(""+beforeSecurityAnnotation.replace(" = ", "=").replace(", ", ","));
// System.out.println(""+afterSecurityAnnotation);
// System.out.println("Equals "+beforeSecurityAnnotation.replace(" = ", "=").replace(", ", ",").equals(afterSecurityAnnotation));
//
// System.out.println("Rigenerazione del codice ");
String newSource = source.replace(beforeShowListAnnotation, afterShowListAnnotation);
newSource = newSource.replace(beforeSecurityAnnotation, afterSecurityAnnotation);
if (!afterIgnoreBean && source.contains("@IgnoreBean()"))
{
/** Deve essere rimossa l'annotazione **/
newSource = source.replace("@IgnoreBean()\r\n", "").replace("@IgnoreBean()", "");
}
if (afterIgnoreBean && !source.contains("@IgnoreBean()"))
{
/** Deve essere inserita l'annotazione **/
newSource = source.replace("public class", "@IgnoreBean()\r\npublic class");
}
if (!afterIgnoreBeanManager && source.contains("@IgnoreBeanManager()"))
{
/** Deve essere rimossa l'annotazione **/
newSource = source.replace("@IgnoreBeanManager()\r\n", "").replace("@IgnoreBeanManager()", "");
}
if (afterIgnoreBeanManager && !source.contains("@IgnoreBeanManager()"))
{
/** Deve essere inserita l'annotazione **/
newSource = source.replace("public class", "@IgnoreBeanManager()\r\npublic class");
}
iCompilationUnit.getBuffer().setContents(newSource);
iCompilationUnit.save(null, true);
}
}
}
catch (Exception e)
{
ErrorMessageDialog errorMessageDialog = new ErrorMessageDialog(e.getMessage());
errorMessageDialog.pack();
errorMessageDialog.setLocationRelativeTo(null);
errorMessageDialog.setVisible(true);
//e.printStackTrace();
}
}
public void selectionChanged(IAction action, ISelection selection)
{
StructuredSelection structSelection = (StructuredSelection) selection;
// System.out.println("Class " + structSelection.getFirstElement().getClass());
if (structSelection.getFirstElement().getClass().equals(org.eclipse.jdt.internal.core.CompilationUnit.class))
{
iCompilationUnit = (ICompilationUnit) structSelection.getFirstElement();
javaProject = iCompilationUnit.getJavaProject();
}
}
public static Object getGUIBuilderInstance()
{
return new EditEJB(Boolean.FALSE);
}
public EditEJB(Boolean initGUI)
{
super();
}
private String getBeanName(String source) throws Exception
{
String line;
int start;
int end;
LineNumberReader lr = new LineNumberReader(new StringReader(source));
while ((line = lr.readLine()) != null)
{
if (line.contains("public class "))
{
start = line.indexOf("public class ") + 13;
if (start == -1)
throw new Exception("Errore nella lettura del nome del bean");
if (line.indexOf(" extends")!=-1)
{
end = line.indexOf(" extends");
}
else
{
end = line.indexOf(" implements Serializable");
}
if (end == -1)
throw new Exception("Errore nella lettura del nome del bean");
lr.close();
return line.substring(start, end);
}
}
return "";
}
private String getShowListAnnotation(String source) throws IOException
{
String line;
LineNumberReader lr = new LineNumberReader(new StringReader(source));
while ((line = lr.readLine()) != null)
{
if (line.contains("@ShowList("))
{
lr.close();
return line;
}
}
return "";
}
private String getSecurityAnnotation(String source) throws IOException
{
String line;
LineNumberReader lr = new LineNumberReader(new StringReader(source));
while ((line = lr.readLine()) != null)
{
if (line.contains("@Security("))
{
lr.close();
return line;
}
}
return "";
}
private Vector<String> getRolesEnabledToCreate(String securityAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = securityAnnotation.replace(" = ", "=").replace(" =", "=").replace("= ", "=").replace(", ", ",").replace("\r\n", "");
int start = tmp.indexOf("rolesEnabledToCreate=") + 22;
if (start == 21)
return null;
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione rolesEnabledToCreate");
String roles = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(roles, ",");
while (st.hasMoreTokens())
{
String role = st.nextToken();
ret.add(role.substring(1, role.length() - 1));
}
return ret;
}
private String getCreateCondition(String securityAnnotation) throws Exception
{
String ret = new String();
String tmp = securityAnnotation.replace(" = ", "=").replace(" =", "=").replace("= ", "=").replace(", ", ",").replace("\r\n", "");
int start = tmp.indexOf("createCondition=") + 19;
if (start == 18)
return "";
int end = tmp.indexOf("}", start);
if (end == -1)
return "";
ret = tmp.substring(start, end);
return ret;
}
private Vector<String> getRolesEnabledToEdit(String securityAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = securityAnnotation.replace(" = ", "=").replace(" =", "=").replace("= ", "=").replace(", ", ",");
int start = tmp.indexOf("rolesEnabledToEdit=") + 20;
if (start == 19)
return null;
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione rolesEnabledToEdit");
String roles = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(roles, ",");
while (st.hasMoreTokens())
{
String role = st.nextToken();
ret.add(role.substring(1, role.length() - 1));
}
return ret;
}
private String getEditCondition(String securityAnnotation) throws Exception
{
String ret = new String();
String tmp = securityAnnotation.replace(" = ", "=").replace(" =", "=").replace("= ", "=").replace(", ", ",").replace("\r\n", "");
int start = tmp.indexOf("editCondition=") + 17;
if (start == 16)
return "";
int end = tmp.indexOf("}", start);
if (end == -1)
return "";
ret = tmp.substring(start, end);
return ret;
}
private Vector<String> getRolesEnabledToDelete(String securityAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = securityAnnotation.replace(" = ", "=").replace(" =", "=").replace("= ", "=").replace(", ", ",");
int start = tmp.indexOf("rolesEnabledToDelete=") + 22;
if (start == 21)
return null;
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione Exception");
String roles = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(roles, ",");
while (st.hasMoreTokens())
{
String role = st.nextToken();
ret.add(role.substring(1, role.length() - 1));
}
return ret;
}
private String getDeleteCondition(String securityAnnotation) throws Exception
{
String ret = new String();
String tmp = securityAnnotation.replace(" = ", "=").replace(" =", "=").replace("= ", "=").replace(", ", ",").replace("\r\n", "");
int start = tmp.indexOf("deleteCondition=") + 19;
if (start == 18)
return "";
int end = tmp.indexOf("}", start);
if (end == -1)
return "";
ret = tmp.substring(start, end);
return ret;
}
private Vector<ListInfo> getListsInfo(String showListAnnotation) throws Exception
{
Vector<ListInfo> ret = new Vector<ListInfo>();
Vector<String> listsNames = getListsNames(showListAnnotation);
Vector<Boolean> listsMains = getListsMains(showListAnnotation);
Vector<String> listsSelectionCondition = getListSelectionConditions(showListAnnotation);
Vector<String> listsNewMenuOptionCondition = getListNewMenuOptionConditions(showListAnnotation);
//Vector<String> listsEditMenuOptionCondition = getListEditMenuOptionConditions(showListAnnotation);
Vector<String> listsPrintMenuOptionCondition = getListprintMenuOptionConditionsInList(showListAnnotation);
Vector<Vector<String>> listsEnabledRoles = getListEnabledRoles(showListAnnotation);
for (int i = 0; i < listsNames.size(); i++)
{
ListInfo li = new ListInfo();
if (listsNames.get(i).equals(""))
li.setName("Default");
else
li.setName(listsNames.get(i));
li.setMain(listsMains.get(i));
li.setSelectionCondition(listsSelectionCondition.get(i));
li.setNewMenuCondition(listsNewMenuOptionCondition.get(i));
//li.setEditMenuCondition(listsEditMenuOptionCondition.get(i)); // Manca ancora l'annotazione !!!
if (listsPrintMenuOptionCondition.size() > 0)
li.setPrintMenuCondition(listsPrintMenuOptionCondition.get(i));
else
li.setPrintMenuCondition(null);
li.setEnabledRoles(listsEnabledRoles.get(i));
ret.add(li);
}
return ret;
}
private Vector<String> getListsNames(String showListAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = showListAnnotation.replace(" = ", "=");
tmp = tmp.replace(", ", ",");
int start = tmp.indexOf("names=") + 7;
if (start == -1)
throw new Exception("Formato errato dell'annotazione names");
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione names");
String names = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(names, ",");
while (st.hasMoreTokens())
{
String name = st.nextToken();
ret.add(name.substring(1, name.length() - 1));
}
return ret;
}
private Vector<Boolean> getListsMains(String showListAnnotation) throws Exception
{
Vector<Boolean> ret = new Vector<Boolean>();
String tmp = showListAnnotation.replace(" = ", "=");
tmp = tmp.replace(", ", ",");
int start = tmp.indexOf("mains=") + 7;
if (start == -1)
throw new Exception("Formato errato dell'annotazione mains");
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione mains");
String names = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(names, ",");
while (st.hasMoreTokens())
{
String name = st.nextToken();
ret.add(new Boolean(name));
}
return ret;
}
private Vector<String> getListSelectionConditions(String showListAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = showListAnnotation.replace(" = ", "=");
tmp = tmp.replace(", ", ",");
int start = tmp.indexOf("filters=") + 9;
if (start == -1)
throw new Exception("Formato errato dell'annotazione filters");
int end = tmp.indexOf("},", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione filters");
String conditions = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(conditions, ",");
while (st.hasMoreTokens())
{
String name = st.nextToken();
ret.add(name.substring(1, name.length() - 1));
}
return ret;
}
private Vector<String> getListNewMenuOptionConditions(String showListAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = showListAnnotation.replace(" = ", "=");
int start = tmp.indexOf("newMenuOptionConditions=") + 25;
if (start == 24)
throw new Exception("Formato errato dell'annotazione newMenuOptionConditions");
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione newMenuOptionConditions");
String names = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(names, ",");
while (st.hasMoreTokens())
{
String name = st.nextToken();
ret.add(name.substring(1, name.length() - 1));
}
return ret;
}
private Vector<String> getListEditMenuOptionConditions(String showListAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = showListAnnotation.replace(" = ", "=");
int start = tmp.indexOf("editMenuOptionConditions=") + 25;
if (start == 24)
throw new Exception("Formato errato dell'annotazione editMenuOptionConditions");
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione editMenuOptionConditions");
String names = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(names, ",");
while (st.hasMoreTokens())
{
String name = st.nextToken();
ret.add(name.substring(1, name.length() - 1));
}
return ret;
}
private Vector<String> getListprintMenuOptionConditionsInList(String showListAnnotation) throws Exception
{
Vector<String> ret = new Vector<String>();
String tmp = showListAnnotation.replace(" ", "");
int start = tmp.indexOf("printMenuOptionConditionsInList=") + 33;
if (start == 32)
throw new Exception("Formato errato dell'annotazione printMenuOptionConditionsInList");
int end = tmp.indexOf("}", start);
if (start == -1)
throw new Exception("Formato errato dell'annotazione printMenuOptionConditionsInList");
String names = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(names, ",");
while (st.hasMoreTokens())
{
String name = st.nextToken();
ret.add(name.substring(1, name.length() - 1));
}
return ret;
}
private Vector<Vector<String>> getListEnabledRoles(String showListAnnotation) throws Exception
{
Vector<Vector<String>> ret = new Vector<Vector<String>>();
String tmp = showListAnnotation.replace(" ", "");
int start = tmp.indexOf("enabledRoles=") + 14;
if (start == -1)
throw new Exception("Formato errato dell'annotazione enabledRoles");
int end = tmp.indexOf("}", start);
if (end == -1)
throw new Exception("Formato errato dell'annotazione enabledRoles");
String names = tmp.substring(start, end);
StringTokenizer st = new StringTokenizer(names, "]\"");
int idx = 0;
while (st.hasMoreTokens())
{
String name = st.nextToken();
if (!name.equals(","))
{
Vector<String> roles = new Vector<String>();
// System.out.println(".... " + name.substring(1));
StringTokenizer st1 = new StringTokenizer(name, ",");
while (st1.hasMoreTokens())
{
String role = st1.nextToken();
if (role.startsWith("[", 0))
role = role.substring(1);
roles.add(role);
}
ret.add(roles);
}
}
return ret;
}
private boolean ignoreBean(String source)
{
return source.contains("@IgnoreBean");
}
private boolean ignoreBeanManager(String source)
{
return source.contains("@IgnoreBeanManager");
}
}