r1428 - topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator
Author: tchemit Date: 2009-04-19 18:19:50 +0000 (Sun, 19 Apr 2009) New Revision: 1428 Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java Log: improve import in BeanGenerator Modified: topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java =================================================================== --- topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-18 15:15:00 UTC (rev 1427) +++ topia/trunk/topia-persistence/src/main/java/org/codelutin/topia/generator/BeanGenerator.java 2009-04-19 18:19:50 UTC (rev 1428) @@ -16,15 +16,15 @@ * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%*/ /* * -* EntityAbstractGenerator.java +* BeanGenerator.java * -* Created: 12 déc. 2005 +* Created: 17 avril 2009 * -* @author Arnaud Thimel <thimel@codelutin.com> +* @author tony Chemit <chemit@codelutin.com> * @version $Revision: 1334 $ * * Mise a jour: $Date: 2009-01-29 16:47:42 +0100 (jeu 29 jan 2009) $ -* par : $Author: thimel $ +* par : $Author: chemit $ */ package org.codelutin.topia.generator; @@ -80,17 +80,12 @@ String copyright = TopiaGeneratorUtil.getCopyright(model); String clazzName = clazz.getName(); String abstractStr = isAbstract(clazz)?"abstract ":" "; + boolean needGetEntityMethod = false; boolean generateToString = TopiaGeneratorUtil.generateToString(clazz, model); - List<String> imports = TopiaGeneratorUtil.getImports(clazz, - List.class.getName(), - Collection.class.getName(), - TopiaEntity.class.getName(), - java.beans.PropertyChangeSupport.class.getName(), - java.beans.PropertyChangeListener.class.getName() - ); - if (generateToString) { - imports.add(org.apache.commons.lang.builder.ToStringBuilder.class.getName()); - } + List<String> includeImports = new java.util.ArrayList<String>(); + includeImports.add(java.beans.PropertyChangeSupport.class.getName()); + includeImports.add(java.beans.PropertyChangeListener.class.getName()); + String extendClass = ""; Iterator<ObjectModelClass> j = clazz.getSuperclasses().iterator(); if (j.hasNext()) { @@ -111,14 +106,42 @@ List<ObjectModelAttribute> multipleAttr; attributes = new ArrayList<ObjectModelAttribute>(); multipleAttr = new ArrayList<ObjectModelAttribute>(); + boolean needListInImport=false; + for (ObjectModelAttribute attr : clazz.getAttributes()) { if (attr.isNavigable()) { attributes.add(attr); if (GeneratorUtil.isNMultiplicity(attr)) { multipleAttr.add(attr); + ObjectModelClass attrEntity = null; + if (model.hasClass(attr.getType())) { + attrEntity = model.getClass(attr.getType()); + } + boolean isEntity = (attrEntity != null && attrEntity.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_ENTITY)); + needGetEntityMethod |= isEntity; + if (attr.isOrdered()) { + needListInImport = true; + } } - } + } } + + if (needGetEntityMethod) { + includeImports.add(TopiaEntity.class.getName()); + } + if (!multipleAttr.isEmpty()) { + includeImports.add(Collection.class.getName()); + } + if (needListInImport) { + includeImports.add(List.class.getName()); + } + if (generateToString) { + includeImports.add(org.apache.commons.lang.builder.ToStringBuilder.class.getName()); + } + List<String> imports = TopiaGeneratorUtil.getImports(clazz, + includeImports.toArray(new String[includeImports.size()]) + ); + boolean sortAttribute = TopiaGeneratorUtil.sortAttribute(clazz, model); if (sortAttribute) { Comparator<ObjectModelAttribute> comp = new Comparator<ObjectModelAttribute>(){ @@ -137,6 +160,7 @@ } /*{package <%=clazz.getPackageName()%>; + }*/ if (log.isDebugEnabled()) { @@ -228,7 +252,9 @@ return null; } - protected <T extends TopiaEntity> T getEntity(Collection<T> childs, String topiaId) { + }*/ + if (needGetEntityMethod) { +/*{ protected <T extends TopiaEntity> T getEntity(Collection<T> childs, String topiaId) { if (childs != null) { for (T o : childs) { if (topiaId.equals(o.getTopiaId())) { @@ -238,7 +264,8 @@ } return null; } - }*/ + }*/ + } } /*{
participants (1)
-
tchemit@users.labs.libre-entreprise.org