Index: lutingenerator/src/java/org/codelutin/generator/Util.java diff -u lutingenerator/src/java/org/codelutin/generator/Util.java:1.17 lutingenerator/src/java/org/codelutin/generator/Util.java:1.18 --- lutingenerator/src/java/org/codelutin/generator/Util.java:1.17 Thu Jul 15 13:33:38 2004 +++ lutingenerator/src/java/org/codelutin/generator/Util.java Fri Jun 10 10:02:35 2005 @@ -17,8 +17,8 @@ *@author Benjamin Poussin * * Copyright Code Lutin - *@version $Revision: 1.17 $ Mise a jour: $Date: 2004/07/15 13:33:38 $ par : - * $Author: bpoussin $ + *@version $Revision: 1.18 $ Mise a jour: $Date: 2005/06/10 10:02:35 $ par : + * $Author: thimel $ */ package org.codelutin.generator; @@ -98,19 +98,37 @@ public static String getAttributeType(ObjectModelParameter attribute) { String result; if (attribute instanceof ObjectModelAttribute - && isNMultiplicity((ObjectModelAttribute)attribute)){ - result = "java.util.Collection"; - }else{ + && isNMultiplicity((ObjectModelAttribute)attribute)) { + result = "java.util.List"; + } else { result = attribute.getType(); } return result; } - + /** - * + * Indicates if the specified attribute has a basic type (byte, boolean, ...) + * @return true if the atribute has a basic type + */ + public static boolean isBasicAttributeType(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()"; + if (isNMultiplicity(attribute)) + return "new org.codelutin.util.BoundedList(" + + attribute.getMinMultiplicity() + ", " + + attribute.getMaxMultiplicity() + ")"; return getInitValue(attribute.getType()); } @@ -180,12 +198,21 @@ public static boolean isNMultiplicity(ObjectModelAttribute attribute){ return (attribute.getMaxMultiplicity() == -1) || (attribute.getMaxMultiplicity()>1); } + + /** + * @return true is the multiplicity of the given attribute is exactly 1 + */ + public static boolean is1Multiplicity(ObjectModelAttribute attribute) { + if (attribute == null) + return false; + return ((attribute.getMinMultiplicity() == 1) && (attribute.getMaxMultiplicity() == 1)); + } /** * */ public static String toUpperCaseFirstLetter(String word) { - return word.substring(0, 1).toUpperCase() + word.substring(1); + return capitalize(word); } public static String capitalize(String word){ @@ -199,4 +226,15 @@ 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(); + } + } // Util