Index: topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.3 topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.4 --- topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java:1.3 Thu Mar 9 10:39:22 2006 +++ topia2/src/java/org/codelutin/topia/generator/TopiaMetaGenerator.java Fri Mar 31 18:11:56 2006 @@ -24,9 +24,9 @@ * @author Grégoire DESSARD Copyright Code Lutin, Grégoire * Dessard * - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Mise a jour: $Date: 2006/03/09 10:39:22 $ par : $Author: thimel $ + * Mise a jour: $Date: 2006/03/31 18:11:56 $ par : $Author: thimel $ */ package org.codelutin.topia.generator; @@ -63,6 +63,8 @@ classValidator.addNameAndReason("constraint", "Nom de classe incompatible avec certains SGBD"); validators.add(classValidator); + validators.add(new TopiaRelationValidator(model)); + boolean isValid = true; for (ObjectModelValidator validator : validators) { if (!validator.validate()) { Index: topia2/src/java/org/codelutin/topia/generator/TopiaRelationValidator.java diff -u /dev/null topia2/src/java/org/codelutin/topia/generator/TopiaRelationValidator.java:1.1 --- /dev/null Fri Mar 31 18:12:01 2006 +++ topia2/src/java/org/codelutin/topia/generator/TopiaRelationValidator.java Fri Mar 31 18:11:56 2006 @@ -0,0 +1,116 @@ +/* *##% +* Copyright (C) 2002, 2003, 2004, 2005 Code Lutin, +* Cédric Pineau, Benjamin Poussin, +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*##%*/ + +/* * +* TopiaRelationValidator.java +* +* Created: 31 mars 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + + +package org.codelutin.topia.generator; + +import java.util.Iterator; + +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelAttribute; +import org.codelutin.generator.models.object.ObjectModelClass; +import org.codelutin.generator.models.object.validator.ObjectModelValidator; + +/** + * Validateur pour les relations du modèle. + * Vérifie que : + * + */ +public class TopiaRelationValidator extends ObjectModelValidator { + + /** + * Constructeur de TopiaRelationValidator + * @param model le modèle à valider + */ + public TopiaRelationValidator(ObjectModel model) { + super(model); + } + + /* (non-Javadoc) + * @see org.codelutin.generator.models.object.validator.ObjectModelValidator#validateAttribute(org.codelutin.generator.models.object.ObjectModelAttribute) + */ + @Override + protected boolean validateAttribute(ObjectModelAttribute attr) { + boolean isValid = true; + ObjectModelAttribute reverse = attr.getReverseAttribute(); + + /* Relation navigabilité */ + //Pour ne pas avoir de doublons, on ne vérifie que sur le premier + //attribut par ordre alphabétique + if (GeneratorUtil.isFirstAttribute(attr)) { + if (!attr.isNavigable() && !reverse.isNavigable()) { + addError(attr, + "La relation entre " + + "\"" + reverse.getType() + "\"[" + attr.getName() + "] et "+ + "\"" + attr.getType() + "\"[" + reverse.getName() + "] " + + "n'est navigable dans aucun sens"); + isValid = false; + } + } + + /* Relation héritage */ + //Relation 1-n + if (reverse != null && GeneratorUtil.isNMultiplicity(attr) && + !GeneratorUtil.isNMultiplicity(reverse)) { + //Pas de navigabilité + if (!reverse.isNavigable()) { + //Il s'agit d'une entity + ObjectModelClass clazz = model.getClass(attr.getType()); + if (clazz != null && clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { + //Cette classe a des sous-classes dans le modèle + Iterator subClasses = model.getClasses().iterator(); + while (subClasses.hasNext()) { + ObjectModelClass subClass = (ObjectModelClass)subClasses.next(); + if (subClass.getSuperclasses().contains(clazz)) { + addError(attr, + "La relation entre " + + "\"" + reverse.getType() + "\"[" + attr.getName() + "] et "+ + "\"" + attr.getType() + "\"[" + reverse.getName() + "] " + + "n'est pas compatible avec Hibernate car:\n" + + "1. La relation est 1-n et n'est navigable que dans un sens;\n" + + "2. \"" + attr.getType() + "\" a des sous-classes."); + isValid = false; + break; + } + } + } + } + } + + return isValid; + } + +} //TopiaRelationValidator