Author: agiraudet Date: 2013-06-11 16:22:32 +0200 (Tue, 11 Jun 2013) New Revision: 1274 Url: http://nuiton.org/projects/eugene/repository/revisions/1274 Log: ajout de la gestion des valeurs par defaut : org.nuiton.eugene.models.object.reader.yaml.DefaultValues Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/DefaultValues.java Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadObjectModel.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadYamlFile.java Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/DefaultValues.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/DefaultValues.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/DefaultValues.java 2013-06-11 14:22:32 UTC (rev 1274) @@ -0,0 +1,63 @@ +package org.nuiton.eugene.models.object.reader.yaml; + +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * User: agiraudet + * Date: 11/06/13 + * Time: 14:51 + */ +public class DefaultValues extends KeyWords { + Yaml yaml; + + public DefaultValues() + { + yaml = new Yaml(); + } + + public static Map<String,String> getDefaultValues(String version) + { + Map<String,String> values = new LinkedHashMap<String, String>(); + + if(version.equals("0")) + { + values.put(ATTRIBUTE+SEPARATOR+MIN_MULTIPLICITY,"1"); + values.put(ATTRIBUTE+SEPARATOR+MAX_MULTIPLICITY,"1"); + values.put(ATTRIBUTE+SEPARATOR+REVERSE_MAX_MULTIPLICITY,"1"); + } + /*else if(version.equals("")) + { + ; + }*/ + + return values; + } + + //retourne les valeurs par defaut du fichier YAML passe an parametre + public Map<String,String> getDefaultValues(File file) throws IOException { + InputStream inputModel = new FileInputStream(file); + Object valuesYAML = yaml.load(inputModel); + inputModel.close(); + + Map<String,String> values = new LinkedHashMap<String, String>(); + if(valuesYAML instanceof Map) + { + for(Object entry : ((Map) valuesYAML).entrySet()) + { + if(entry instanceof Map.Entry) + { + values.put(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue())); + } + } + } + + return values; + } +} Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java 2013-06-11 12:25:25 UTC (rev 1273) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/KeyWords.java 2013-06-11 14:22:32 UTC (rev 1274) @@ -6,6 +6,8 @@ * Time: 10:10 */ public class KeyWords { + public static final String SEPARATOR = "."; + public static final String ABSTRACT = "abstract"; public static final String ASSOCIATION_CLASS = "associationclass"; public static final String ASSOCIATION_CLASS_NAME = "associationclassname"; @@ -13,6 +15,7 @@ public static final String ATTRIBUTE = "attribute"; public static final String BODY_CODE = "bodeycode"; public static final String CLASS = "class"; + public static final String CLASSIFIER = "classifier"; public static final String COMMENTS = "comments"; public static final String DEFAULT_VALUE = "defaultvalue"; public static final String DOCUMENTATION = "documentation"; Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadObjectModel.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadObjectModel.java 2013-06-11 12:25:25 UTC (rev 1273) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadObjectModel.java 2013-06-11 14:22:32 UTC (rev 1274) @@ -14,11 +14,13 @@ protected String packageL; protected YamlObject modelYAMLO; protected ObjectModelImpl modelOM; + protected Map<String,String> defaultValues; - public LoadObjectModel(YamlObject modelYAMLO, ObjectModelImpl modelOM) { + public LoadObjectModel(YamlObject modelYAMLO, ObjectModelImpl modelOM, Map<String,String> defaultValues) { this.packageL = "default"; this.modelOM = modelOM; this.modelYAMLO = modelYAMLO; + this.defaultValues = defaultValues; //log //Log.initLog(modelYAMLO.toString(),"/tmp/log.LoadObjectModel.txt"); //log @@ -27,21 +29,33 @@ public void loadModel() { String packageYAMLO = modelYAMLO.getFirstMapStringListString(PACKAGE); if (packageYAMLO == null) { - //valeur par defaut + String key = PACKAGE; + if(defaultValues.containsKey(key)) + { + packageL = defaultValues.get(key); + } } else { packageL = packageYAMLO; } String nameYAMLO = modelYAMLO.getFirstMapStringListString(NAME); if (nameYAMLO == null) { - ;//valeur par defaut + String key = NAME; + if(defaultValues.containsKey(key)) + { + modelOM.setName(defaultValues.get(key)); + } } else { modelOM.setName(nameYAMLO); } String versionYAMLO = modelYAMLO.getFirstMapStringListString(VERSION); if (versionYAMLO == null) { - ;//valeur par defaut + String key = VERSION; + if(defaultValues.containsKey(key)) + { + modelOM.setVersion(defaultValues.get(key)); + } } else { modelOM.setVersion(versionYAMLO); } @@ -87,21 +101,33 @@ public void loadElement(YamlObject elementYAMLO, ObjectModelElementImpl elementOM) { String nameYAMLO = elementYAMLO.getFirstMapStringListString(NAME); if (nameYAMLO == null) { - ;//valeur par defaut + String key = ELEMENT+SEPARATOR+NAME; + if(defaultValues.containsKey(key)) + { + elementOM.setName(defaultValues.get(key)); + } } else { elementOM.setName(nameYAMLO); } String staticYAMLO = elementYAMLO.getFirstMapStringListString(STATIC); if (staticYAMLO == null) { - ;//valeur par defaut + String key = ELEMENT+SEPARATOR+STATIC; + if(defaultValues.containsKey(key)) + { + elementOM.setStatic(Boolean.valueOf(defaultValues.get(key))); + } } else { elementOM.setStatic(Boolean.valueOf(staticYAMLO)); } String documentationYAMLO = elementYAMLO.getFirstMapStringListString(DOCUMENTATION); if (documentationYAMLO == null) { - ;//valeur par defaut + String key = ELEMENT+SEPARATOR+DOCUMENTATION; + if(defaultValues.containsKey(key)) + { + elementOM.setDocumentation(defaultValues.get(key)); + } } else { elementOM.setDocumentation(documentationYAMLO); } @@ -122,6 +148,7 @@ elementOM.addComment(comment); } + //TODO: ajouter setereotype par defaut List<String> stereotypes = elementYAMLO.getMapStringListString(STEREOTYPES); for (String stereotype : stereotypes) { ObjectModelImplRef stereotypeOM = new ObjectModelImplRef(); @@ -143,7 +170,11 @@ String externYAMLO = classifierYAMLO.getFirstMapStringListString(EXTERN); if (externYAMLO == null) { - ;//valeur par defaut + String key = CLASSIFIER+SEPARATOR+EXTERN; + if(defaultValues.containsKey(key)) + { + classifierOM.setExtern(Boolean.valueOf(defaultValues.get(key))); + } } else { classifierOM.setExtern(Boolean.valueOf(externYAMLO)); @@ -151,14 +182,22 @@ String innerYAMLO = classifierYAMLO.getFirstMapStringListString(INNER); if (innerYAMLO == null) { - ;//valeur par defaut + String key = CLASSIFIER+SEPARATOR+INNER; + if(defaultValues.containsKey(key)) + { + classifierOM.setInner(Boolean.valueOf(defaultValues.get(key))); + } } else { classifierOM.setInner(Boolean.valueOf(innerYAMLO)); } String typeYAMLO = classifierYAMLO.getFirstMapStringListString(TYPE); if (typeYAMLO == null) { - ;//valeur par defaut + String key = CLASSIFIER+SEPARATOR+TYPE; + if(defaultValues.containsKey(key)) + { + classifierOM.setType(defaultValues.get(key)); + } } else { classifierOM.setType(typeYAMLO); } @@ -188,7 +227,11 @@ String abstractYAMLO = classYAMLO.getFirstMapStringListString(ABSTRACT); if (abstractYAMLO == null) { - ;//valeur par defaut + String key = CLASS+SEPARATOR+ABSTRACT; + if(defaultValues.containsKey(key)) + { + classOM.setAbstract(Boolean.valueOf(defaultValues.get(key))); + } } else { classOM.setAbstract(Boolean.valueOf(abstractYAMLO)); } @@ -208,21 +251,30 @@ public void loadAssociationClass(YamlObject associationClassYAML, ObjectModelAssociationClassImpl associationClassOM) { loadClass(associationClassYAML, associationClassOM); - //TODO: remplacer name par type et attribute par name ? + //TODO: remplacer name par type et attribute par name ? -> confusion + //TODO: remplacer PARTICIPANT par PARTICIPANTS (List) for (YamlObject participantYAMLO : associationClassYAML.getMapStringListYamlObject(PARTICIPANT)) { ObjectModeImplAssociationClassParticipant participantOM = new ObjectModeImplAssociationClassParticipant(); participantOM.setAssociationClass(associationClassOM); String nameYAMLO = participantYAMLO.getFirstMapStringListString(NAME); if (nameYAMLO == null) { - ;//valeur par defaut + String key = ASSOCIATION_CLASS+SEPARATOR+PARTICIPANT+SEPARATOR+NAME; + if(defaultValues.containsKey(key)) + { + participantOM.setName(defaultValues.get(key)); + } } else { participantOM.setName(nameYAMLO); } String attributeYAMLO = participantYAMLO.getFirstMapStringListString(ATTRIBUTE); if (attributeYAMLO == null) { - ;//valeur par defaut + String key = ASSOCIATION_CLASS+SEPARATOR+PARTICIPANT+SEPARATOR+ATTRIBUTE; + if(defaultValues.containsKey(key)) + { + participantOM.setAttribute(defaultValues.get(key)); + } } else { participantOM.setAttribute(attributeYAMLO); } @@ -255,35 +307,55 @@ String orderingYAMLO = parameterYAMLO.getFirstMapStringListString(ORDERING); if (orderingYAMLO == null) { - ;//valeur par defaut + String key = PARAMETER+SEPARATOR+ORDERING; + if(defaultValues.containsKey(key)) + { + parameterOM.setOrdering(defaultValues.get(key)); + } } else { parameterOM.setOrdering(orderingYAMLO); } String typeYAMLO = parameterYAMLO.getFirstMapStringListString(TYPE); if (typeYAMLO == null) { - ;//valeur par defaut + String key = PARAMETER+SEPARATOR+TYPE; + if(defaultValues.containsKey(key)) + { + parameterOM.setType(defaultValues.get(key)); + } } else { parameterOM.setType(typeYAMLO); } String defaultValueYAMLO = parameterYAMLO.getFirstMapStringListString(DEFAULT_VALUE); if (defaultValueYAMLO == null) { - ;//default + String key = PARAMETER+SEPARATOR+DEFAULT_VALUE; + if(defaultValues.containsKey(key)) + { + parameterOM.setDefaultValue(defaultValues.get(key)); + } } else { parameterOM.setDefaultValue(defaultValueYAMLO); } String minMultiplicityYAMLO = parameterYAMLO.getFirstMapStringListString(MIN_MULTIPLICITY); if (minMultiplicityYAMLO == null) { - ;//valeur par defaut + String key = PARAMETER+SEPARATOR+MIN_MULTIPLICITY; + if(defaultValues.containsKey(key)) + { + parameterOM.setMinMultiplicity(Integer.valueOf(defaultValues.get(key))); + } } else { parameterOM.setMinMultiplicity(Integer.valueOf(minMultiplicityYAMLO)); } String maxMultiplicityYAMLO = parameterYAMLO.getFirstMapStringListString(MAX_MULTIPLICITY); if (maxMultiplicityYAMLO == null) { - ;//valeur par defaut + String key = PARAMETER+SEPARATOR+MAX_MULTIPLICITY; + if(defaultValues.containsKey(key)) + { + parameterOM.setMaxMultiplicity(Integer.valueOf(defaultValues.get(key))); + } } else { parameterOM.setMaxMultiplicity(Integer.valueOf(maxMultiplicityYAMLO)); @@ -291,14 +363,22 @@ String orderedYAMLO = parameterYAMLO.getFirstMapStringListString(ORDERED); if (orderedYAMLO == null) { - ;//valeur par defaut + String key = PARAMETER+SEPARATOR+ORDERED; + if(defaultValues.containsKey(key)) + { + parameterOM.setOrdered(Boolean.valueOf(defaultValues.get(key))); + } } else { parameterOM.setOrdered(Boolean.valueOf(orderedYAMLO)); } String uniqueYAMLO = parameterYAMLO.getFirstMapStringListString(UNIQUE); if (uniqueYAMLO == null) { - ;//valeur par defaut + String key = PARAMETER+SEPARATOR+UNIQUE; + if(defaultValues.containsKey(key)) + { + parameterOM.setUnique(Boolean.valueOf(defaultValues.get(key))); + } } else { parameterOM.setUnique(Boolean.valueOf(uniqueYAMLO)); } @@ -309,65 +389,99 @@ String navigableYAMLO = attributeYAMLO.getFirstMapStringListString(NAVIGABLE); if (navigableYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+NAVIGABLE; + if(defaultValues.containsKey(key)) + { + attributeOM.setNavigable(Boolean.valueOf(defaultValues.get(key))); + } } else { attributeOM.setNavigable(Boolean.valueOf(navigableYAMLO)); } String associationTypeYAMLO = attributeYAMLO.getFirstMapStringListString(ASSOCIATION_TYPE); if (associationTypeYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+ASSOCIATION_TYPE; + if(defaultValues.containsKey(key)) + { + attributeOM.setAssociationType(defaultValues.get(key)); + } } else { attributeOM.setAssociationType(associationTypeYAMLO); } String finalYAMLO = attributeYAMLO.getFirstMapStringListString(FINAL); if (finalYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+FINAL; + if(defaultValues.containsKey(key)) + { + attributeOM.setFinal(Boolean.valueOf(defaultValues.get(key))); + } } else { attributeOM.setFinal(Boolean.valueOf(finalYAMLO)); } String staticYAMLO = attributeYAMLO.getFirstMapStringListString(STATIC); if (staticYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+STATIC; + if(defaultValues.containsKey(key)) + { + attributeOM.setStatic(Boolean.valueOf(defaultValues.get(key))); + } } else { attributeOM.setStatic(Boolean.valueOf(staticYAMLO)); } String associationClassNameYAMLO = attributeYAMLO.getFirstMapStringListString(ASSOCIATION_CLASS_NAME); if (associationClassNameYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+ASSOCIATION_CLASS_NAME; + if(defaultValues.containsKey(key)) + { + attributeOM.setAssociationClassName(defaultValues.get(key)); + } } else { attributeOM.setAssociationClassName(associationClassNameYAMLO); } String reverseAttributeNameYAMLO = attributeYAMLO.getFirstMapStringListString(REVERSE_ATTRIBUTE_NAME); if (reverseAttributeNameYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+REVERSE_ATTRIBUTE_NAME; + if(defaultValues.containsKey(key)) + { + attributeOM.setReverseAttributeName(defaultValues.get(key)); + } } else { attributeOM.setReverseAttributeName(reverseAttributeNameYAMLO); } String reverseMaxMultiplicityYAMLO = attributeYAMLO.getFirstMapStringListString(REVERSE_MAX_MULTIPLICITY); if (reverseMaxMultiplicityYAMLO == null) { - //test - attributeOM.setReverseMaxMultiplicity(1);//valeur par defaut - //test + String key = ATTRIBUTE+SEPARATOR+REVERSE_MAX_MULTIPLICITY; + if(defaultValues.containsKey(key)) + { + attributeOM.setReverseMaxMultiplicity(Integer.valueOf(defaultValues.get(key))); + } } else { attributeOM.setReverseMaxMultiplicity(Integer.valueOf(reverseMaxMultiplicityYAMLO)); } String transientYAMLO = attributeYAMLO.getFirstMapStringListString(TRANSIENT); if (transientYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+TRANSIENT; + if(defaultValues.containsKey(key)) + { + attributeOM.setTransient(Boolean.valueOf(defaultValues.get(key))); + } } else { attributeOM.setTransient(Boolean.valueOf(transientYAMLO)); } String visibilityYAMLO = attributeYAMLO.getFirstMapStringListString(VISIBILITY); if (visibilityYAMLO == null) { - ;//valeur par defaut + String key = ATTRIBUTE+SEPARATOR+VISIBILITY; + if(defaultValues.containsKey(key)) + { + attributeOM.setVisibility(defaultValues.get(key)); + } } else { attributeOM.setVisibility(visibilityYAMLO); } @@ -378,14 +492,22 @@ String abstractYAMLO = operationYAMLO.getFirstMapStringListString(ABSTRACT); if (abstractYAMLO == null) { - ;//valeur par defaut + String key = OPERATION+SEPARATOR+ABSTRACT; + if(defaultValues.containsKey(key)) + { + operationOM.setAbstract(Boolean.valueOf(defaultValues.get(key))); + } } else { operationOM.setAbstract(Boolean.valueOf(abstractYAMLO)); } String visibilityYAMLO = operationYAMLO.getFirstMapStringListString(VISIBILITY); if (visibilityYAMLO == null) { - ;//valeur par defaut + String key = OPERATION+SEPARATOR+VISIBILITY; + if(defaultValues.containsKey(key)) + { + operationOM.setVisibility(defaultValues.get(key)); + } } else { operationOM.setVisibility(visibilityYAMLO); } @@ -404,7 +526,11 @@ String bodyCodeYAMLO = operationYAMLO.getFirstMapStringListString(BODY_CODE); if (bodyCodeYAMLO == null) { - ;//valeur par defaut + String key = OPERATION+SEPARATOR+BODY_CODE; + if(defaultValues.containsKey(key)) + { + operationOM.setBodyCode(defaultValues.get(key)); + } } else { operationOM.setBodyCode(bodyCodeYAMLO); } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadYamlFile.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadYamlFile.java 2013-06-11 12:25:25 UTC (rev 1273) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadYamlFile.java 2013-06-11 14:22:32 UTC (rev 1274) @@ -58,7 +58,7 @@ ;//impossible de charger le modele } - LoadObjectModel loader = new LoadObjectModel(modelYAMLO, modelOM);//+defaultVersion + LoadObjectModel loader = new LoadObjectModel(modelYAMLO, modelOM, DefaultValues.getDefaultValues(defaultVersion));//sortir getDefaultValues ? loader.loadModel(); } }
participants (1)
-
agiraudet@users.nuiton.org