Index: lutingenerator/src/java/org/codelutin/generator/models/object/validator/AttributeNamesValidator.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/object/validator/AttributeNamesValidator.java:1.1 --- /dev/null Thu Mar 9 10:37:33 2006 +++ lutingenerator/src/java/org/codelutin/generator/models/object/validator/AttributeNamesValidator.java Thu Mar 9 10:37:28 2006 @@ -0,0 +1,59 @@ +/* *##% +* 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. +*##%*/ + +/* * +* AttributeNamesValidator.java +* +* Created: 7 mars 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + + +package org.codelutin.generator.models.object.validator; + +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelAttribute; + +public class AttributeNamesValidator extends NameBasedValidator { + + public AttributeNamesValidator(ObjectModel model) { + super(model, false); + } + + public AttributeNamesValidator(ObjectModel model, boolean caseSensitive) { + super(model, caseSensitive); + } + + @Override + protected boolean validateAttribute(ObjectModelAttribute attr) { + String name = attr.getName(); + if (containsName(name)) { + addError(attr.getDeclaringElement(), getReason(name)); + return false; + } + return true; + } + +} //AttributeNamesValidator Index: lutingenerator/src/java/org/codelutin/generator/models/object/validator/NameBasedValidator.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/object/validator/NameBasedValidator.java:1.1 --- /dev/null Thu Mar 9 10:37:33 2006 +++ lutingenerator/src/java/org/codelutin/generator/models/object/validator/NameBasedValidator.java Thu Mar 9 10:37:28 2006 @@ -0,0 +1,88 @@ +/* *##% +* 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. +*##%*/ + +/* * +* NameBasedValidator.java +* +* Created: 9 mars 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + + +package org.codelutin.generator.models.object.validator; + +import java.util.HashMap; +import java.util.Map; + +import org.codelutin.generator.models.object.ObjectModel; + +public abstract class NameBasedValidator extends ObjectModelValidator { + + private boolean caseSensitive; + + private Map namesAndReasons; + + public NameBasedValidator(ObjectModel model, boolean caseSensitive) { + super(model); + this.caseSensitive = caseSensitive; + } + + private Map getNameAndReasons() { + if (namesAndReasons == null) { + namesAndReasons = new HashMap(); + } + return namesAndReasons; + } + + public void addNameAndReason(String name, String reason) { + if (name != null) { + if (!caseSensitive) { + name = name.toLowerCase(); + } + getNameAndReasons().put(name, reason); + } + } + + public void addNamesAndReasons(Map namesAndReasons) { + for (String key : namesAndReasons.keySet()) { + addNameAndReason(key, namesAndReasons.get(key)); + } + } + + public boolean containsName(String name) { + if (!caseSensitive) { + name = name.toLowerCase(); + } + return getNameAndReasons().containsKey(name); + } + + public String getReason(String name) { + if (!caseSensitive) { + name = name.toLowerCase(); + } + return getNameAndReasons().get(name); + } + +} //NameBasedValidator Index: lutingenerator/src/java/org/codelutin/generator/models/object/validator/ClassNamesValidator.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/object/validator/ClassNamesValidator.java:1.1 --- /dev/null Thu Mar 9 10:37:33 2006 +++ lutingenerator/src/java/org/codelutin/generator/models/object/validator/ClassNamesValidator.java Thu Mar 9 10:37:28 2006 @@ -0,0 +1,59 @@ +/* *##% +* 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. +*##%*/ + +/* * +* ClassNamesValidator.java +* +* Created: 9 mars 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + + +package org.codelutin.generator.models.object.validator; + +import org.codelutin.generator.models.object.ObjectModel; +import org.codelutin.generator.models.object.ObjectModelClass; + +public class ClassNamesValidator extends NameBasedValidator { + + public ClassNamesValidator(ObjectModel model) { + super(model, false); + } + + public ClassNamesValidator(ObjectModel model, boolean caseSensitive) { + super(model, caseSensitive); + } + + @Override + protected boolean validateClass(ObjectModelClass clazz) { + String name = clazz.getName(); + if (containsName(name)) { + addError(clazz, getReason(name)); + return false; + } + return true; + } + +} //ClassNamesValidator Index: lutingenerator/src/java/org/codelutin/generator/models/object/validator/ObjectModelValidator.java diff -u /dev/null lutingenerator/src/java/org/codelutin/generator/models/object/validator/ObjectModelValidator.java:1.1 --- /dev/null Thu Mar 9 10:37:33 2006 +++ lutingenerator/src/java/org/codelutin/generator/models/object/validator/ObjectModelValidator.java Thu Mar 9 10:37:28 2006 @@ -0,0 +1,128 @@ +/* *##% +* 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. +*##%*/ + +/* * +* ObjectModelValidator.java +* +* Created: 7 mars 2006 +* +* @author Arnaud Thimel +* @version $Revision$ +* +* Mise a jour: $Date$ +* par : $Author$ +*/ + + +package org.codelutin.generator.models.object.validator; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +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.ObjectModelClassifier; +import org.codelutin.generator.models.object.ObjectModelElement; +import org.codelutin.generator.models.object.ObjectModelInterface; +import org.codelutin.generator.models.object.ObjectModelOperation; + +public class ObjectModelValidator { + + private ObjectModel model; + + private List errors; + + public ObjectModelValidator(ObjectModel model) { + this.model = model; + errors = new ArrayList(); + } + + /** + * Renvoie la liste des erreurs constatées pdt la validation. Si aucune + * erreur n'a été constatée ou si la validation n'a pas été effectuée, la + * liste renvoyeé sera vide. + */ + public List getErrors() { + return errors; + } + + /** + * Valide le modèle et renvoie faux si il n'est pas valide + */ + public boolean validate() { + if (errors.size() > 0) { + //On recréé une nouvelle liste + errors = new ArrayList(); + } + boolean isValid = validateModel(this.model); + for (Iterator classifiers = model.getClassifiers().iterator(); + classifiers.hasNext(); ){ + ObjectModelClassifier classifier = (ObjectModelClassifier)classifiers.next(); + isValid &= validateClassifier(classifier); + if (classifier instanceof ObjectModelInterface) { + isValid &= validateInterface((ObjectModelInterface)classifier); + } + if (classifier instanceof ObjectModelClass) { + ObjectModelClass clazz = (ObjectModelClass)classifier; + isValid &= validateClass(clazz); + for (Iterator attributes = clazz.getAttributes().iterator(); + attributes.hasNext(); ) { + isValid &= validateAttribute((ObjectModelAttribute)attributes.next()); + } + } + for (Iterator operations = classifier.getOperations().iterator(); + operations.hasNext(); ) { + isValid &= validateOperation((ObjectModelOperation)operations.next()); + } + } + return isValid; + } + + protected boolean validateModel(ObjectModel model) { + return true; + } + + protected boolean validateClassifier(ObjectModelClassifier classifier) { + return true; + } + + protected boolean validateInterface(ObjectModelInterface interfacezz) { + return true; + } + + protected boolean validateClass(ObjectModelClass clazz) { + return true; + } + + protected boolean validateAttribute(ObjectModelAttribute attr) { + return true; + } + + protected boolean validateOperation(ObjectModelOperation operation) { + return true; + } + + protected void addError(ObjectModelElement onElement, String reason) { + this.errors.add("[" + onElement + "] " + reason); + } + +} //ObjectModelValidator