Index: lutingenerator/src/java/org/codelutin/generator/Util.java diff -u lutingenerator/src/java/org/codelutin/generator/Util.java:1.19 lutingenerator/src/java/org/codelutin/generator/Util.java:1.20 --- lutingenerator/src/java/org/codelutin/generator/Util.java:1.19 Fri Jun 10 17:02:16 2005 +++ lutingenerator/src/java/org/codelutin/generator/Util.java Fri Nov 18 16:59:28 2005 @@ -17,8 +17,8 @@ *@author Benjamin Poussin * * Copyright Code Lutin - *@version $Revision: 1.19 $ Mise a jour: $Date: 2005/06/10 17:02:16 $ par : - * $Author: thimel $ + *@version $Revision: 1.20 $ Mise a jour: $Date: 2005/11/18 16:59:28 $ par : + * $Author: pineau $ */ package org.codelutin.generator; @@ -31,6 +31,7 @@ import org.codelutin.generator.models.object.ObjectModel; import org.codelutin.generator.models.object.ObjectModelAttribute; import org.codelutin.generator.models.object.ObjectModelClassifier; +import org.codelutin.generator.models.object.ObjectModelOperation; import org.codelutin.generator.models.object.ObjectModelParameter; import org.codelutin.util.StringUtil; @@ -78,6 +79,7 @@ return qualifiedName.replace('.', File.separatorChar); } + /** * return all classifiers belonging to the given package recursively. The Collection may be empty. * @see ObjectModelCassifier @@ -95,6 +97,11 @@ return classifiers; } + /** + * TODO Changer pour renvoyer Collection par defaut et list que si presence d'un stereotype <> + * @param attribute + * @return + */ public static String getAttributeType(ObjectModelParameter attribute) { String result; if (attribute instanceof ObjectModelAttribute @@ -105,6 +112,17 @@ } return result; } + +// public static String getAttributeType(ObjectModelParameter attribute) { +// String result; +// if (attribute instanceof ObjectModelAttribute +// && isNMultiplicity((ObjectModelAttribute)attribute)){ +// result = "java.util.Collection"; +// }else{ +// result = attribute.getType(); +// } +// return result; +// } /** * Indicates if the specified attribute has a primitive type (byte, boolean, ...) @@ -120,18 +138,27 @@ "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 org.codelutin.util.BoundedList(" + +// attribute.getMinMultiplicity() + ", " + +// attribute.getMaxMultiplicity() + ")"; +// return getInitValue(attribute.getType()); +// } + /** * 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 org.codelutin.util.BoundedList(" + - attribute.getMinMultiplicity() + ", " + - attribute.getMaxMultiplicity() + ")"; + 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"; @@ -145,7 +172,7 @@ 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()"; @@ -208,6 +235,7 @@ return ((attribute.getMinMultiplicity() == 1) && (attribute.getMaxMultiplicity() == 1)); } + /** * */ @@ -236,5 +264,72 @@ 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 getOperationParameterListName(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(); + } + } // Util