Author: thimel Date: 2009-01-29 10:58:54 +0000 (Thu, 29 Jan 2009) New Revision: 410 Added: lutingenerator/trunk/src/main/java/org/codelutin/generator/GeneratorUtil.java Removed: lutingenerator/trunk/src/main/java/org/codelutin/generator/Util.java Modified: lutingenerator/trunk/src/main/java/org/codelutin/generator/AbstractObjectModelGenerator.java lutingenerator/trunk/src/main/java/org/codelutin/generator/UIModelGenerator.java lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/ObjectModelElement.java lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModeImplAssociationClassParticipant.java lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelAttributeImpl.java lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelElementImpl.java Log: Rename Util to GeneratorUtil Modified: lutingenerator/trunk/src/main/java/org/codelutin/generator/AbstractObjectModelGenerator.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/AbstractObjectModelGenerator.java 2009-01-06 13:36:31 UTC (rev 409) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/AbstractObjectModelGenerator.java 2009-01-29 10:58:54 UTC (rev 410) @@ -47,7 +47,7 @@ if(name == null){ throw new GeneratorException("L'element "+ e +" doit avoir un nom valide" ); }else{ - return Util.capitalize(name); + return GeneratorUtil.capitalize(name); } } Added: lutingenerator/trunk/src/main/java/org/codelutin/generator/GeneratorUtil.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/GeneratorUtil.java (rev 0) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/GeneratorUtil.java 2009-01-29 10:58:54 UTC (rev 410) @@ -0,0 +1,383 @@ +/* + * *##% Lutin Generator + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +/* * + * Util.java Created: 25 ao?t 2003 + * + *@author Benjamin Poussin <poussin@codelutin.com> + * + * Copyright Code Lutin + *@version $Revision: 317 $ Mise a jour: $Date: 2008-09-25 10:45:22 +0200 (jeu 25 sep 2008) $ par : + * $Author: thimel $ + */ + +package org.codelutin.generator; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +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.ObjectModelOperation; +import org.codelutin.generator.models.object.ObjectModelParameter; + +/** + * TODO Description of the Class + * + *@author poussin + *@created 26 ao?t 2003 + */ +public class GeneratorUtil { + + /** + * return parent package of given package (return given package if it is a root package) + * eg : org.codelutin.generator.models -> org.codelutin.generator + * eg : org -> org + * warning : org.codelutin.generator. -> org.codelutin.generator + */ + public static String getParentPackageName(String packageName) { + String parentPackageName = packageName; + int index = packageName.lastIndexOf('.'); + if (index != -1) { + parentPackageName = packageName.substring(0,index); + } + return parentPackageName; + } + + /** + * return class name fr given fully qualified name (return given name if it is not fully qualified) + * eg : org.codelutin.generator.models.ObjectClass -> ObjectClass + * eg : ObjectClass-> ObjectClass + */ + public static String getClassNameFromQualifiedName(String qualifiedName) { + String className = qualifiedName; + int index = qualifiedName.lastIndexOf('.'); + if (index != -1) { + className = qualifiedName.substring(index+1); + } + return className; + } + + /** + * + */ + public static String getFilenameFromQualifiedName(String qualifiedName) { + return qualifiedName.replace('.', File.separatorChar); + } + + + /** + * return all classifiers belonging to the given package recursively. The Collection may be empty. + * @see ObjectModelCassifier + * + * @return a Collection containing all classifiers belonging to the given package recursively. + */ + public static Collection<ObjectModelClassifier> getClassifiers(ObjectModel model, String packageName) { + List<ObjectModelClassifier> classifiers = new ArrayList<ObjectModelClassifier>(); + for (Iterator i = model.getClassifiers().iterator(); i.hasNext();) { + ObjectModelClassifier classifier = (ObjectModelClassifier) i.next(); + if (classifier.getPackageName().startsWith(packageName)) { + classifiers.add(classifier); + } + } + return classifiers; + } + + /** + * @see {@link #getAttributeType(ObjectModelParameter, boolean)} + */ + public static String getAttributeType(ObjectModelParameter attribute) { + return getAttributeType(attribute, false); + } + + /** + * Retourne le type de l'attribut, c-a-d une List ou une collection + * ou le type defini si la cardinalité n'est pas multiple + * + * @param attribute + * @return + */ + public static String getAttributeType(ObjectModelParameter attribute, boolean useGenerics) { + String result; + if (attribute instanceof ObjectModelAttribute + && isNMultiplicity((ObjectModelAttribute)attribute)) { + if (((ObjectModelAttribute)attribute).isOrdered()) { + result = "java.util.List"; + } else { + result = "java.util.Collection"; + } + if (useGenerics) { + result += "<" + attribute.getType() + ">"; + } + } else { + result = attribute.getType(); + } + return result; + } + + /** + * Indicates if the specified attribute has a primitive type (byte, boolean, ...) + * @return true if the atribute has a primitive type + */ + public static boolean isPrimitiveAttributeType(ObjectModelAttribute attribute) { + if (isNMultiplicity(attribute)) + return false; + String type = attribute.getType(); + return ("byte".equals(type) || "short".equals(type) || + "int".equals(type) || "long".equals(type) || + "float".equals(type) || "double".equals(type) || + "char".equals(type) || "boolean".equals(type)); + } + + /** + * return an init value for the specified attribute + * @return a String with the corresponding attribute init value + */ + public static String getInitValue(ObjectModelAttribute attribute) { + if (isNMultiplicity(attribute)) return "new java.util.ArrayList()"; + return getInitValue(attribute.getType()); + } + + public static String getInitValue(String type){ + if ("byte".equals(type)) return "0"; + if ("short".equals(type)) return "0"; + if ("int".equals(type)) return "0"; + if ("long".equals(type)) return "0"; + if ("float".equals(type)) return "0"; + if ("double".equals(type)) return "0"; + if ("char".equals(type)) return "\u0000"; + if ("boolean".equals(type)) return "false"; + if ("java.lang.String".equals(type)) return null; + if ("java.lang.Date".equals(type)) return null; + return null; + } + + public static String getCastValue(String type, String o){ + if ("byte".equals(type)) return "((Byte)"+o+").byteValue()"; + if ("short".equals(type)) return "((Short)"+o+").shortValue()"; + if ("int".equals(type)) return "((Integer)"+o+").intValue()"; + if ("long".equals(type)) return "((Long)"+o+").longValue()"; + if ("float".equals(type)) return "((Float)"+o+").floatValue()"; + if ("double".equals(type)) return "((Double)"+o+").doubleValue()"; + if ("char".equals(type)) return "((Character)"+o+").charValue()"; + if ("boolean".equals(type)) return "((Boolean)"+o+").booleanValue()"; + if ("void".equals(type)) return ""; + return "(" + type + ")" + o; + } + + public static String getHashCodeExpression(String type, String o){ + String result = o; + if ("byte".equals(type)) result = "new Byte("+o+")"; + if ("short".equals(type)) result = "new Short("+o+")"; + if ("int".equals(type)) result = "new Integer("+o+")"; + if ("long".equals(type)) result = "new Long("+o+")"; + if ("float".equals(type)) result = "new Float("+o+")"; + if ("double".equals(type)) result = "new Double("+o+")"; + if ("char".equals(type)) result = "new Character("+o+")"; + if ("boolean".equals(type)) result = "new Boolean("+o+")"; + return result +".hashCode()"; + } + + /** + * Retourne la chaine de caractere dont on a besoin pour la declaration + * des parametres d'une methode. + */ + public static String getMethodParameterDeclaration(Collection params){ + StringBuffer result = new StringBuffer(); + for (Iterator j = params.iterator(); j.hasNext();){ + ObjectModelParameter parameter = (ObjectModelParameter) j.next(); + result.append(getAttributeType(parameter)+" "+parameter.getName()); + if (j.hasNext()) { + result.append(", "); + } + } + return result.toString(); + } + + /** + * Retourne la chaine de caractere qui represente chaque nom de parametre + * separer par des ','. + */ + public static String getMethodParameterListName(Collection params){ + StringBuffer result = new StringBuffer(); + for (Iterator j = params.iterator(); j.hasNext();){ + ObjectModelParameter parameter = (ObjectModelParameter) j.next(); + result.append(parameter.getName()); + if (j.hasNext()) { + result.append(", "); + } + } + return result.toString(); + } + + /** + *@return vrai si la cardinalite de l'attribut est superieur a 1, c-a-d + * si MaxMultiplicity == -1 ou > 1 + */ + public static boolean isNMultiplicity(ObjectModelAttribute attribute){ + return isNMultiplicity(attribute.getMaxMultiplicity()); + } + + public static boolean isNMultiplicity(int multiplicity){ + return (multiplicity == -1) || (multiplicity>1); + } + + /** + * @return true is the multiplicity of the given attribute is exactly 1 + */ + public static boolean isOneMultiplicity(ObjectModelAttribute attribute) { + if (attribute == null) + return false; + return ((attribute.getMinMultiplicity() == 1) && (attribute.getMaxMultiplicity() == 1)); + } + + + /** + * + */ + public static String toUpperCaseFirstLetter(String word) { + return capitalize(word); + } + + public static String capitalize(String word){ + return StringUtils.capitalize(word); + } + + /** + * + */ + public static String toLowerCaseFirstLetter(String word) { + return word.substring(0, 1).toLowerCase() + word.substring(1); + } + + /** + * @return true if the given attribute is a composition (composant of the reverse attribute) + */ + public static boolean isComposition(ObjectModelAttribute attribute) { + if (attribute == null) + return false; + if (attribute.getReverseAttribute() == null) + return false; + return attribute.getReverseAttribute().isComposite(); + } + + + + + public static String getParsingExpression(String type, String attributeStringName){ + if ("byte".equals(type)) return "Byte.parseByte("+attributeStringName+")"; + if ("short".equals(type)) return "Short.parseShort("+attributeStringName+")"; + if ("int".equals(type)) return "Integer.parseInt("+attributeStringName+")"; + if ("long".equals(type)) return "Long.parseLong("+attributeStringName+")"; + if ("float".equals(type)) return "Float.parseFloat("+attributeStringName+")"; + if ("double".equals(type)) return "Double.parseDouble("+attributeStringName+")"; + if ("char".equals(type)) return attributeStringName+".charAt(0)"; + if ("boolean".equals(type)) return "Boolean.parseBoolean("+attributeStringName+")"; + if ("java.lang.String".equals(type)) return attributeStringName; + if ("java.util.Date".equals(type)) return "dateParser.parse("+attributeStringName+")"; + return null; + } + + public static String getFormatingExpression(String type, String attributeStringName){ + if ("byte".equals(type)) return "Byte.toString("+attributeStringName+")"; + if ("short".equals(type)) return "Short.toString("+attributeStringName+")"; + if ("int".equals(type)) return "Integer.toString("+attributeStringName+")"; + if ("long".equals(type)) return "Long.toString("+attributeStringName+")"; + if ("float".equals(type)) return "Float.toString("+attributeStringName+")"; + if ("double".equals(type)) return "Double.toString("+attributeStringName+")"; + if ("char".equals(type)) return "Character.toString("+attributeStringName+")"; + if ("boolean".equals(type)) return "Boolean.parseBoolean("+attributeStringName+")"; + if ("java.lang.String".equals(type)) return attributeStringName; + if ("java.util.Date".equals(type)) return "dateParser.format("+attributeStringName+")"; + return null; + } + + + + /** + * Retourne la chaine de caractere dont on a besoin pour la declaration + * des parametres d'une methode. + */ + public static String getOperationParametersListDeclaration(ObjectModelOperation operation){ + StringBuffer result = new StringBuffer(); + + Collection params = operation.getParameters(); + for (Iterator j = params.iterator(); j.hasNext();){ + ObjectModelParameter parameter = (ObjectModelParameter) j.next(); + result.append(getAttributeType(parameter)+" "+parameter.getName()); + if (j.hasNext()) { + result.append(", "); + } + } + return result.toString(); + } + + /** + * Retourne la chaine de caractere qui represente chaque nom de parametre + * separer par des ','. + */ + public static String getOperationParametersListName(ObjectModelOperation operation) { + Collection params = operation.getParameters(); + StringBuffer result = new StringBuffer(); + for (Iterator j = params.iterator(); j.hasNext();){ + ObjectModelParameter parameter = (ObjectModelParameter) j.next(); + result.append(parameter.getName()); + if (j.hasNext()) { + result.append(", "); + } + } + return result.toString(); + } + + /** + * Renvoie sous forme de String la liste des déclarations des attributes d'une classe donnée + */ + public static String getClassAttributesListDeclaration(ObjectModelClass clazz) { + StringBuffer result = new StringBuffer(); + + Collection params = clazz.getAttributes(); + for (Iterator j = params.iterator(); j.hasNext();){ + ObjectModelAttribute attr = (ObjectModelAttribute) j.next(); + result.append(getAttributeType(attr, true)+" "+attr.getName()); + if (j.hasNext()) { + result.append(", "); + } + } + return result.toString(); + } + + /** + * Renvoie si l'attribut passé en paramètre est premier lexicographiquement + * par rapport à son attribut inverse (si celui ci existe). + * @param attr L'attribut dont on veut savoir s'il est le premier + * @return true, si l'attribut est premier (lexico ou pas de reverse attribute), false dans les autres cas + */ + public static boolean isFirstAttribute(ObjectModelAttribute attr) { + if (attr.getReverseAttribute() == null) + return true; + return (attr.getName().compareTo(attr.getReverseAttribute().getName()) < 0); + } + +} // Util Modified: lutingenerator/trunk/src/main/java/org/codelutin/generator/UIModelGenerator.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/UIModelGenerator.java 2009-01-06 13:36:31 UTC (rev 409) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/UIModelGenerator.java 2009-01-29 10:58:54 UTC (rev 410) @@ -175,7 +175,7 @@ if(name == null){ throw new GeneratorException("L'objet "+ o.getType() +" doit avoir un nom valide" ); }else{ - return Util.capitalize(name); + return GeneratorUtil.capitalize(name); } } @@ -184,7 +184,7 @@ if(name == null){ throw new GeneratorException("La propriete "+ p +" doit avoir un nom valide"); }else{ - return Util.capitalize(name); + return GeneratorUtil.capitalize(name); } } } Deleted: lutingenerator/trunk/src/main/java/org/codelutin/generator/Util.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/Util.java 2009-01-06 13:36:31 UTC (rev 409) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/Util.java 2009-01-29 10:58:54 UTC (rev 410) @@ -1,383 +0,0 @@ -/* - * *##% Lutin Generator - * Copyright (C) 2004 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ - -/* * - * Util.java Created: 25 ao?t 2003 - * - *@author Benjamin Poussin <poussin@codelutin.com> - * - * Copyright Code Lutin - *@version $Revision$ Mise a jour: $Date$ par : - * $Author$ - */ - -package org.codelutin.generator; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import org.apache.commons.lang.StringUtils; -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.ObjectModelOperation; -import org.codelutin.generator.models.object.ObjectModelParameter; - -/** - * TODO Description of the Class - * - *@author poussin - *@created 26 ao?t 2003 - */ -public class Util { - - /** - * return parent package of given package (return given package if it is a root package) - * eg : org.codelutin.generator.models -> org.codelutin.generator - * eg : org -> org - * warning : org.codelutin.generator. -> org.codelutin.generator - */ - public static String getParentPackageName(String packageName) { - String parentPackageName = packageName; - int index = packageName.lastIndexOf('.'); - if (index != -1) { - parentPackageName = packageName.substring(0,index); - } - return parentPackageName; - } - - /** - * return class name fr given fully qualified name (return given name if it is not fully qualified) - * eg : org.codelutin.generator.models.ObjectClass -> ObjectClass - * eg : ObjectClass-> ObjectClass - */ - public static String getClassNameFromQualifiedName(String qualifiedName) { - String className = qualifiedName; - int index = qualifiedName.lastIndexOf('.'); - if (index != -1) { - className = qualifiedName.substring(index+1); - } - return className; - } - - /** - * - */ - public static String getFilenameFromQualifiedName(String qualifiedName) { - return qualifiedName.replace('.', File.separatorChar); - } - - - /** - * return all classifiers belonging to the given package recursively. The Collection may be empty. - * @see ObjectModelCassifier - * - * @return a Collection containing all classifiers belonging to the given package recursively. - */ - public static Collection<ObjectModelClassifier> getClassifiers(ObjectModel model, String packageName) { - List<ObjectModelClassifier> classifiers = new ArrayList<ObjectModelClassifier>(); - for (Iterator i = model.getClassifiers().iterator(); i.hasNext();) { - ObjectModelClassifier classifier = (ObjectModelClassifier) i.next(); - if (classifier.getPackageName().startsWith(packageName)) { - classifiers.add(classifier); - } - } - return classifiers; - } - - /** - * @see {@link #getAttributeType(ObjectModelParameter, boolean)} - */ - public static String getAttributeType(ObjectModelParameter attribute) { - return getAttributeType(attribute, false); - } - - /** - * Retourne le type de l'attribut, c-a-d une List ou une collection - * ou le type defini si la cardinalité n'est pas multiple - * - * @param attribute - * @return - */ - public static String getAttributeType(ObjectModelParameter attribute, boolean useGenerics) { - String result; - if (attribute instanceof ObjectModelAttribute - && isNMultiplicity((ObjectModelAttribute)attribute)) { - if (((ObjectModelAttribute)attribute).isOrdered()) { - result = "java.util.List"; - } else { - result = "java.util.Collection"; - } - if (useGenerics) { - result += "<" + attribute.getType() + ">"; - } - } else { - result = attribute.getType(); - } - return result; - } - - /** - * Indicates if the specified attribute has a primitive type (byte, boolean, ...) - * @return true if the atribute has a primitive type - */ - public static boolean isPrimitiveAttributeType(ObjectModelAttribute attribute) { - if (isNMultiplicity(attribute)) - return false; - String type = attribute.getType(); - return ("byte".equals(type) || "short".equals(type) || - "int".equals(type) || "long".equals(type) || - "float".equals(type) || "double".equals(type) || - "char".equals(type) || "boolean".equals(type)); - } - - /** - * return an init value for the specified attribute - * @return a String with the corresponding attribute init value - */ - public static String getInitValue(ObjectModelAttribute attribute) { - if (isNMultiplicity(attribute)) return "new java.util.ArrayList()"; - return getInitValue(attribute.getType()); - } - - public static String getInitValue(String type){ - if ("byte".equals(type)) return "0"; - if ("short".equals(type)) return "0"; - if ("int".equals(type)) return "0"; - if ("long".equals(type)) return "0"; - if ("float".equals(type)) return "0"; - if ("double".equals(type)) return "0"; - if ("char".equals(type)) return "\u0000"; - if ("boolean".equals(type)) return "false"; - if ("java.lang.String".equals(type)) return null; - if ("java.lang.Date".equals(type)) return null; - return null; - } - - public static String getCastValue(String type, String o){ - if ("byte".equals(type)) return "((Byte)"+o+").byteValue()"; - if ("short".equals(type)) return "((Short)"+o+").shortValue()"; - if ("int".equals(type)) return "((Integer)"+o+").intValue()"; - if ("long".equals(type)) return "((Long)"+o+").longValue()"; - if ("float".equals(type)) return "((Float)"+o+").floatValue()"; - if ("double".equals(type)) return "((Double)"+o+").doubleValue()"; - if ("char".equals(type)) return "((Character)"+o+").charValue()"; - if ("boolean".equals(type)) return "((Boolean)"+o+").booleanValue()"; - if ("void".equals(type)) return ""; - return "(" + type + ")" + o; - } - - public static String getHashCodeExpression(String type, String o){ - String result = o; - if ("byte".equals(type)) result = "new Byte("+o+")"; - if ("short".equals(type)) result = "new Short("+o+")"; - if ("int".equals(type)) result = "new Integer("+o+")"; - if ("long".equals(type)) result = "new Long("+o+")"; - if ("float".equals(type)) result = "new Float("+o+")"; - if ("double".equals(type)) result = "new Double("+o+")"; - if ("char".equals(type)) result = "new Character("+o+")"; - if ("boolean".equals(type)) result = "new Boolean("+o+")"; - return result +".hashCode()"; - } - - /** - * Retourne la chaine de caractere dont on a besoin pour la declaration - * des parametres d'une methode. - */ - public static String getMethodParameterDeclaration(Collection params){ - StringBuffer result = new StringBuffer(); - for (Iterator j = params.iterator(); j.hasNext();){ - ObjectModelParameter parameter = (ObjectModelParameter) j.next(); - result.append(getAttributeType(parameter)+" "+parameter.getName()); - if (j.hasNext()) { - result.append(", "); - } - } - return result.toString(); - } - - /** - * Retourne la chaine de caractere qui represente chaque nom de parametre - * separer par des ','. - */ - public static String getMethodParameterListName(Collection params){ - StringBuffer result = new StringBuffer(); - for (Iterator j = params.iterator(); j.hasNext();){ - ObjectModelParameter parameter = (ObjectModelParameter) j.next(); - result.append(parameter.getName()); - if (j.hasNext()) { - result.append(", "); - } - } - return result.toString(); - } - - /** - *@return vrai si la cardinalite de l'attribut est superieur a 1, c-a-d - * si MaxMultiplicity == -1 ou > 1 - */ - public static boolean isNMultiplicity(ObjectModelAttribute attribute){ - return isNMultiplicity(attribute.getMaxMultiplicity()); - } - - public static boolean isNMultiplicity(int multiplicity){ - return (multiplicity == -1) || (multiplicity>1); - } - - /** - * @return true is the multiplicity of the given attribute is exactly 1 - */ - public static boolean isOneMultiplicity(ObjectModelAttribute attribute) { - if (attribute == null) - return false; - return ((attribute.getMinMultiplicity() == 1) && (attribute.getMaxMultiplicity() == 1)); - } - - - /** - * - */ - public static String toUpperCaseFirstLetter(String word) { - return capitalize(word); - } - - public static String capitalize(String word){ - return StringUtils.capitalize(word); - } - - /** - * - */ - public static String toLowerCaseFirstLetter(String word) { - return word.substring(0, 1).toLowerCase() + word.substring(1); - } - - /** - * @return true if the given attribute is a composition (composant of the reverse attribute) - */ - public static boolean isComposition(ObjectModelAttribute attribute) { - if (attribute == null) - return false; - if (attribute.getReverseAttribute() == null) - return false; - return attribute.getReverseAttribute().isComposite(); - } - - - - - public static String getParsingExpression(String type, String attributeStringName){ - if ("byte".equals(type)) return "Byte.parseByte("+attributeStringName+")"; - if ("short".equals(type)) return "Short.parseShort("+attributeStringName+")"; - if ("int".equals(type)) return "Integer.parseInt("+attributeStringName+")"; - if ("long".equals(type)) return "Long.parseLong("+attributeStringName+")"; - if ("float".equals(type)) return "Float.parseFloat("+attributeStringName+")"; - if ("double".equals(type)) return "Double.parseDouble("+attributeStringName+")"; - if ("char".equals(type)) return attributeStringName+".charAt(0)"; - if ("boolean".equals(type)) return "Boolean.parseBoolean("+attributeStringName+")"; - if ("java.lang.String".equals(type)) return attributeStringName; - if ("java.util.Date".equals(type)) return "dateParser.parse("+attributeStringName+")"; - return null; - } - - public static String getFormatingExpression(String type, String attributeStringName){ - if ("byte".equals(type)) return "Byte.toString("+attributeStringName+")"; - if ("short".equals(type)) return "Short.toString("+attributeStringName+")"; - if ("int".equals(type)) return "Integer.toString("+attributeStringName+")"; - if ("long".equals(type)) return "Long.toString("+attributeStringName+")"; - if ("float".equals(type)) return "Float.toString("+attributeStringName+")"; - if ("double".equals(type)) return "Double.toString("+attributeStringName+")"; - if ("char".equals(type)) return "Character.toString("+attributeStringName+")"; - if ("boolean".equals(type)) return "Boolean.parseBoolean("+attributeStringName+")"; - if ("java.lang.String".equals(type)) return attributeStringName; - if ("java.util.Date".equals(type)) return "dateParser.format("+attributeStringName+")"; - return null; - } - - - - /** - * Retourne la chaine de caractere dont on a besoin pour la declaration - * des parametres d'une methode. - */ - public static String getOperationParametersListDeclaration(ObjectModelOperation operation){ - StringBuffer result = new StringBuffer(); - - Collection params = operation.getParameters(); - for (Iterator j = params.iterator(); j.hasNext();){ - ObjectModelParameter parameter = (ObjectModelParameter) j.next(); - result.append(getAttributeType(parameter)+" "+parameter.getName()); - if (j.hasNext()) { - result.append(", "); - } - } - return result.toString(); - } - - /** - * Retourne la chaine de caractere qui represente chaque nom de parametre - * separer par des ','. - */ - public static String getOperationParametersListName(ObjectModelOperation operation) { - Collection params = operation.getParameters(); - StringBuffer result = new StringBuffer(); - for (Iterator j = params.iterator(); j.hasNext();){ - ObjectModelParameter parameter = (ObjectModelParameter) j.next(); - result.append(parameter.getName()); - if (j.hasNext()) { - result.append(", "); - } - } - return result.toString(); - } - - /** - * Renvoie sous forme de String la liste des déclarations des attributes d'une classe donnée - */ - public static String getClassAttributesListDeclaration(ObjectModelClass clazz) { - StringBuffer result = new StringBuffer(); - - Collection params = clazz.getAttributes(); - for (Iterator j = params.iterator(); j.hasNext();){ - ObjectModelAttribute attr = (ObjectModelAttribute) j.next(); - result.append(getAttributeType(attr, true)+" "+attr.getName()); - if (j.hasNext()) { - result.append(", "); - } - } - return result.toString(); - } - - /** - * Renvoie si l'attribut passé en paramètre est premier lexicographiquement - * par rapport à son attribut inverse (si celui ci existe). - * @param attr L'attribut dont on veut savoir s'il est le premier - * @return true, si l'attribut est premier (lexico ou pas de reverse attribute), false dans les autres cas - */ - public static boolean isFirstAttribute(ObjectModelAttribute attr) { - if (attr.getReverseAttribute() == null) - return true; - return (attr.getName().compareTo(attr.getReverseAttribute().getName()) < 0); - } - -} // Util Modified: lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/ObjectModelElement.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/ObjectModelElement.java 2009-01-06 13:36:31 UTC (rev 409) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/ObjectModelElement.java 2009-01-29 10:58:54 UTC (rev 410) @@ -101,6 +101,13 @@ public abstract String getTagValue(String tagValue); /** + * Returns whether this element has a tagValue corresponding to the given name, or not. + * + * @return a boolean indicating whether this element has a tagValue corresponding to the given name, or not. + */ + public abstract boolean hasTagValue(String tagValue); + + /** * Returns all comments lied to this particular model element * * @return a List containing all comments for this element as Strings. Modified: lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModeImplAssociationClassParticipant.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModeImplAssociationClassParticipant.java 2009-01-06 13:36:31 UTC (rev 409) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModeImplAssociationClassParticipant.java 2009-01-29 10:58:54 UTC (rev 410) @@ -19,7 +19,7 @@ import java.util.Iterator; -import org.codelutin.generator.Util; +import org.codelutin.generator.GeneratorUtil; /** * @@ -57,7 +57,7 @@ for (Iterator i = associationClass.getParticipantsRefs().iterator(); i.hasNext();) { ObjectModeImplAssociationClassParticipant participant = (ObjectModeImplAssociationClassParticipant)i.next(); if (participant != this) { - attributeName = Util.toLowerCaseFirstLetter(Util.getClassNameFromQualifiedName(participant.getName())); + attributeName = GeneratorUtil.toLowerCaseFirstLetter(GeneratorUtil.getClassNameFromQualifiedName(participant.getName())); break; } } Modified: lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelAttributeImpl.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelAttributeImpl.java 2009-01-06 13:36:31 UTC (rev 409) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelAttributeImpl.java 2009-01-29 10:58:54 UTC (rev 410) @@ -29,7 +29,7 @@ package org.codelutin.generator.models.object.xml; -import org.codelutin.generator.Util; +import org.codelutin.generator.GeneratorUtil; import org.codelutin.generator.models.object.ObjectModelAttribute; import org.codelutin.generator.models.object.ObjectModelClass; import org.codelutin.generator.models.object.ObjectModelClassifier; @@ -56,7 +56,7 @@ public void postInit() { if (name == null) - name = Util.toLowerCaseFirstLetter(Util + name = GeneratorUtil.toLowerCaseFirstLetter(GeneratorUtil .getClassNameFromQualifiedName(type)); super.postInit(); } @@ -180,7 +180,7 @@ public String getReverseAttributeName() { if ((reverseAttributeName == null) || ("".equals(reverseAttributeName))) { - reverseAttributeName = Util + reverseAttributeName = GeneratorUtil .toLowerCaseFirstLetter(getDeclaringElement().getName()); } return reverseAttributeName; @@ -188,7 +188,7 @@ public String getName() { if ((name == null || "".equals(name)) && getClassifier() != null) { - name = Util.toLowerCaseFirstLetter(getClassifier().getName()); + name = GeneratorUtil.toLowerCaseFirstLetter(getClassifier().getName()); } return name; } Modified: lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelElementImpl.java =================================================================== --- lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelElementImpl.java 2009-01-06 13:36:31 UTC (rev 409) +++ lutingenerator/trunk/src/main/java/org/codelutin/generator/models/object/xml/ObjectModelElementImpl.java 2009-01-29 10:58:54 UTC (rev 410) @@ -193,6 +193,15 @@ } /** + * Returns whether this element has a tagValue corresponding to the given name, or not. + * + * @return a boolean indicating whether this element has a tagValue corresponding to the given name, or not. + */ + public boolean hasTagValue(String tagValue) { + return tagValues.containsKey(tagValue); + } + + /** * Returns all comments lied to this particular model element * * @return a List containing all comments for this element as Strings.