r1246 - in trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader: . yaml
Author: agiraudet Date: 2013-05-15 17:38:03 +0200 (Wed, 15 May 2013) New Revision: 1246 Url: http://nuiton.org/projects/eugene/repository/revisions/1246 Log: modification de eugene/models/object/reader/YamlObjectModelReader.java : nouveaux appels des m?\195?\169thodes de la classe YamlToObjectModel modification de eugene/models/object/reader/yaml/YamlToObjectModel.java : nouvelle impl?\195?\169mentation et nouvelles fonctionnalit?\195?\169s Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-14 09:45:39 UTC (rev 1245) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-05-15 15:38:03 UTC (rev 1246) @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.nuiton.eugene.ModelHelper; import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.reader.yaml.Test; import org.nuiton.eugene.models.object.reader.yaml.YamlToObjectModel; import org.yaml.snakeyaml.error.YAMLException; @@ -55,18 +56,13 @@ @Override protected void beforeReadFile(File... files) { super.beforeReadFile(files); - //TODO : instancier parser yaml + controler clefs des maps yamlToObjectModel = new YamlToObjectModel(); } @Override protected void readFileToModel(File file, ObjectModel model) throws IOException { try { - //TODO - //test - //NOTE: model deja instance - yamlToObjectModel.test(file, model); - //test + yamlToObjectModel.loadFile(file,model); } catch (YAMLException e) { throw new IOException("Unable to parse ObjectModel input file : " + file, e); } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-14 09:45:39 UTC (rev 1245) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-05-15 15:38:03 UTC (rev 1246) @@ -7,431 +7,687 @@ import java.io.*; import java.util.*; +import static org.nuiton.eugene.models.object.reader.yaml.YamlUtil.browseKeySetToLowerCase; /** * User: agiraudet - * Date: 06/05/13 - * Time: 12:08 - * <p/> - * Note1: le parsage se base sur la syntaxe 5-1uml.yaml - * Note2: surcharger les méthodes ou le langage pour les prochaines syntaxes ? + * Date: 15/05/13 + * Time: 11:15 */ public class YamlToObjectModel { protected Yaml yaml; - protected Object modelYAML; - protected ObjectModelImpl modelOM; - protected String packageOM; protected Map<String,String> imports; - private String _log = "/tmp/log.yaml.txt"; + //mots clefs + public static final String IMPORTS = "imports"; + public static final String PACKAGE = "package"; + public static final String VERSION = "version"; + public static final String NAME = "name"; + public static final String CLASS = "class"; + public static final String INTERFACE = "interface"; + public static final String CLASS_ASSOCIATION = "classassociation"; + public static final String ENUMERATION = "enumeration"; + public static final String STATIC = "static"; + public static final String DOCUMENTATION = "documentation"; + public static final String TAG_VALUES = "tagvalues"; + public static final String COMMENTS = "comments"; + public static final String STEREOTYPES = "stereotype"; + public static final String EXTERN = "extern"; + public static final String INNER = "inner"; + public static final String TYPE = "type"; + public static final String ATTRIBUTE = "attribute"; + public static final String OPERATION = "operation"; + public static final String SUPER_INTERFACES = "superinterfaces"; + public static final String SUPER_CLASSES = "superclasses"; + public static final String ORDERING = "ordering"; + public static final String DEFAULT_VALUE = "defaultvalue"; + public static final String MIN_MULTIPLICITY = "minmultiplicity"; + public static final String MAX_MULTIPLICITY = "maxmultiplicity"; + public static final String ORDERED = "ordered"; + public static final String UNIQUE = "unique"; + public static final String NAVIGABLE = "navigable"; + public static final String ASSOCIATION_TYPE = "associationtype"; + public static final String FINAL = "final"; + public static final String ASSOCIATION_CLASS_NAME = "associationclassname"; + public static final String REVERSE_ATTRIBUTE_NAME = "reverseattributename"; + public static final String REVERSE_MAX_MULTIPLICITY = "reversemaxmultiplicity"; + public static final String TRANSIENT = "transient"; + public static final String VISIBILITY = "visibility"; + public static final String ABSTRACT = "abstract"; + public static final String PARAMETER = "parameter"; + public static final String RETURN_PARAMETER = "returnparameter"; + public static final String BODY_CODE = "bodeycode"; + public static final String PARTICIPANT = "participant"; + public static final String LITERAL = "literal"; - public YamlToObjectModel() { - //TODO : mettre toutes les clefs des Maps en minuscules - //TODO : instancier le parseur YAML (éviter une instance par fichier chargé) - //TODO : verifier syntaxe du code -> utiliser convention de Sun - //TODO : differencier attributs optionnels/obligatoires :: if null -> valeur par defaut, else -> valeur | valeurs par defaut dans fichier yaml ? - //TODO : charger les éléments du même niveau dans la même méthode - //TODO : Impl or not Impl ? - yaml = new Yaml(); - modelYAML = null; - modelOM = null; - this.startLog(); - } - - private void startLog() { + private boolean _log = false; + private void log(String str) throws IOException { FileWriter log = null; - try { - log = new FileWriter(this._log, false); + String path = "/tmp/log.yaml.txt"; + if(_log) + { + log = new FileWriter(path, _log); + log.write("[LOG] " + str + "\n"); + log.close(); + } + else + { + log = new FileWriter(path, _log); log.write("[LOG] start v1.0\n"); log.close(); - } catch (IOException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + _log = true; } } - private void writeLog(String str) { - FileWriter log = null; - try { - log = new FileWriter(this._log, true); - log.write("[LOG] " + str + "\n"); - log.close(); - } catch (IOException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - } + public YamlToObjectModel() + { + yaml = new Yaml(); } - public void test(File file, ObjectModel model) throws IOException { - //load file + public void loadFile(File file, ObjectModel model) throws IOException { + ObjectModelImpl modelOM = (ObjectModelImpl) model; InputStream input = new FileInputStream(file); - modelYAML = this.yaml.load(input); + Object modelYAML = yaml.load(input); input.close(); - //file loaded - modelOM = (ObjectModelImpl) model; - loadModel(); + + List<String> ignore = new LinkedList<String>(); + ignore.add("imports"); + ignore.add("tagvalues"); + browseKeySetToLowerCase(modelYAML, ignore); + + loadModel(modelYAML,modelOM); } - //TODO : utiliser design pattern - //TODO : utiliser genericite - public void loadModel() { - if (modelYAML instanceof List) { - loadImports(); - Object nameYAML = collectElement((List) modelYAML, "name"); - if(nameYAML != null) + public Object collectElement(List data, Object key) { + for (Object obj : data) { + if (obj instanceof Map) { + if (((Map) obj).containsKey(key)) { + return ((Map) obj).get(key); + } + } + } + return null; + } + + public List collectAllElements(List data, Object key) { + List res = new LinkedList(); + for (Object obj : data) { + if (obj instanceof Map) { + if (((Map) obj).containsKey(key)) { + res.add(((Map) obj).get(key)); + } + } + } + return res; + } + + public void loadModel(Object modelYAML, ObjectModelImpl modelOM) + { + if(modelYAML instanceof List) + { + //load imports + imports = new LinkedHashMap<String, String>(); + Object importsYAML = collectElement((List) modelYAML, IMPORTS); + if(importsYAML instanceof Map) { - modelOM.setName(String.valueOf(nameYAML)); + for(Object entry : ((Map) importsYAML).entrySet()) + { + if(entry instanceof Map.Entry) + { + imports.put(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue())); + } + } } + + //load package + Object packageYAML = collectElement((List) modelYAML, PACKAGE); + if(packageYAML == null) + { + ; + } else { - ;//TODO : charger valeur par defaut ou lever exception ? + packageOM = String.valueOf(packageYAML); } - Object versionYAML = collectElement((List) modelYAML, "version"); - if(versionYAML != null) + Object nameYAML = collectElement((List) modelYAML, NAME); + if(nameYAML == null) { - modelOM.setVersion(String.valueOf(versionYAML)); + ; } else { - ;//TODO : charger valeur par defaut + modelOM.setName(String.valueOf(nameYAML)); } - Object packageYAML = collectElement((List) modelYAML, "package"); - if(packageYAML != null) + Object versionYAML = collectElement((List) modelYAML, VERSION); + if(versionYAML == null) { - packageOM = String.valueOf(packageYAML); + ; } else { - ;//TODO : charger valeur par defaut + modelOM.setVersion(String.valueOf(versionYAML)); } - //modelOM.setName(String.valueOf(this.collectElement((List) modelYAML, "name"))); - //modelOM.setVersion(String.valueOf(this.collectElement((List) modelYAML, "version"))); + Object tagValuesYAML = collectElement((List) modelYAML, TAG_VALUES); + if(tagValuesYAML instanceof Map) + { + for(Object entry : ((Map) tagValuesYAML).entrySet()) + { + if(entry instanceof Map.Entry) + { + modelOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue())); + } + } + } - List classesYAML = this.collectAllElement((List) modelYAML, "class"); - for (Object classYAML : classesYAML) { - ObjectModelClassImpl classOM = loadClass(classYAML); - //tester null ? + List classesYAML = collectAllElements((List) modelYAML, CLASS); + for(Object classYAML : classesYAML) + { + ObjectModelClassImpl classOM = new ObjectModelClassImpl(); + loadClass(classYAML,classOM); modelOM.addClass(classOM); } - } else { - ;//TODO : lever exception + + List interfacesYAML = collectAllElements((List) modelYAML, INTERFACE); + for(Object interfaceYAML : interfacesYAML) + { + ObjectModelInterfaceImpl interfaceOM = new ObjectModelInterfaceImpl(); + loadInterface(interfaceYAML,interfaceOM); + modelOM.addInterface(interfaceOM); + } + + List classesAssociationYAML = collectAllElements((List) modelYAML, CLASS_ASSOCIATION); + for(Object classAssociationYAML : classesAssociationYAML) + { + ObjectModelAssociationClassImpl classAssociationOM = new ObjectModelAssociationClassImpl(); + loadAssociationClass(classAssociationYAML,classAssociationOM); + modelOM.addAssociationClass(classAssociationOM); + } + + List enumerationsYAML = collectAllElements((List) modelYAML, ENUMERATION); + for(Object enumerationYAML : enumerationsYAML) + { + ObjectModelEnumerationImpl enumerationOM = new ObjectModelEnumerationImpl(); + loadEnumeration(enumerationYAML,enumerationOM); + modelOM.addEnumeration(enumerationOM); + } + } + //return true/false -> chargement reussi ? } - public ObjectModelClassImpl loadClass(Object classYAML) { - if (classYAML instanceof List) { - ObjectModelClassImpl classOM = new ObjectModelClassImpl(); + public void loadElement(Object elementYAML, ObjectModelElementImpl elementOM) + { + if(elementYAML instanceof List) + { + //TODO: setDeclaringElement + //TODO: setObjectModelImpl + //TODO: addModifier - this.loadStereotypes((List) classYAML, classOM); - this.loadTagValues((List) classYAML, classOM); - this.loadComments((List) classYAML, classOM); + Object nameYAML = collectElement((List) elementYAML, NAME); + if(nameYAML == null) + { + ; + } + else + { + elementOM.setName(String.valueOf(nameYAML)); + } - classOM.setPackage(packageOM); + Object staticYAML = collectElement((List) elementYAML, STATIC); + if(staticYAML == null) + { + ; + } + else + { + elementOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML))); + } - Object nameYAML = collectElement((List) classYAML, "name"); - if(nameYAML != null) + Object documentationYAML = collectElement((List) elementYAML, DOCUMENTATION); + if(documentationYAML == null) { - classOM.setName(String.valueOf(nameYAML)); + ; } else { - //TODO : lever exception ? + elementOM.setDocumentation(String.valueOf(documentationYAML)); } - Object abstractYAML = collectElement((List) classYAML, "abstract"); - if(abstractYAML != null) + Object tagValuesYAML = collectElement((List) elementYAML, TAG_VALUES); + if(tagValuesYAML instanceof Map) { - classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML)));//degolass + for(Object entry : ((Map) tagValuesYAML).entrySet()) + { + if(entry instanceof Map.Entry) + { + elementOM.addTagValue(String.valueOf(((Map.Entry) entry).getKey()),String.valueOf(((Map.Entry) entry).getValue())); + } + } } + + Object commentsYAML = collectElement((List) elementYAML, COMMENTS); + if(commentsYAML instanceof List) + { + for(Object comment : (List) commentsYAML) + { + elementOM.addComment(String.valueOf(comment)); + } + } + + Object stereotypesYAML = collectElement((List) elementYAML, STEREOTYPES); + { + if(stereotypesYAML instanceof List) + { + for(Object stereotype : (List) stereotypesYAML) + { + ObjectModelImplRef stereotypeOM = new ObjectModelImplRef(); + stereotypeOM.setName(String.valueOf(stereotype)); + elementOM.addStereotype(stereotypeOM); + } + } + } + } + } + + public void loadClassifier(Object classifierYAML, ObjectModelClassifierImpl classifierOM) + { + if(classifierYAML instanceof List) + { + //TODO: addDependency + + loadElement(classifierYAML, classifierOM); + + Object packageYAML = collectElement((List) classifierYAML, PACKAGE); + if(packageYAML == null) + { + classifierOM.setPackage(packageOM); + } else { - ;//TODO : charger la valeur par defaut + classifierOM.setPackage(String.valueOf(packageYAML)); } - /*classOM.setName(String.valueOf(this.collectElement((List) classYAML, "name"))); - //Object finalYAML = this.collectElement((List) classYAML, "final");//final not implemented by ObjectModel - Object abstractYAML = this.collectElement((List) classYAML, "abstract"); - //TODO : utiliser operateur ternaire - if (abstractYAML instanceof Boolean) { - classOM.setAbstract((Boolean) abstractYAML); - } else//sale + Object externYAML = collectElement((List) classifierYAML, EXTERN); + if(externYAML == null) { - classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML))); - }*/ + ; + } + else + { + classifierOM.setExtern(Boolean.valueOf(String.valueOf(externYAML))); + } - //TODO : loadAttributes - List attributesYAML = this.collectAllElement((List) classYAML, "attribute"); - for (Object attributeYAML : attributesYAML) { - ObjectModelAttributeImpl attributeOM = loadAttribute(attributeYAML); - classOM.addAttribute(attributeOM); + Object innerYAML = collectElement((List) classifierYAML, INNER); + if(innerYAML == null) + { + ; } - //TODO : loadOperations + else + { + classifierOM.setInner(Boolean.valueOf(String.valueOf(innerYAML))); + } - //this.modelOM.addClass(classOM); - return classOM; - } else { - ;//TODO : lever exception - return null; + Object typeYAML = collectElement((List) classifierYAML, TYPE); + if(typeYAML == null) + { + ; + } + else + { + classifierOM.setType(String.valueOf(typeYAML)); + } + + List attributesYAML = collectAllElements((List) classifierYAML, ATTRIBUTE); + for(Object attributeYAML : attributesYAML) + { + ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl(); + loadAttribute(attributeYAML, attributeOM); + classifierOM.addAttribute(attributeOM); + } + + List operationsYAML = collectAllElements((List) classifierYAML, OPERATION); + for(Object operationYAML : operationsYAML) + { + ObjectModelOperationImpl operationOM = new ObjectModelOperationImpl(); + loadOperation(operationYAML, operationOM); + classifierOM.addOperation(operationOM); + } + + Object superInterfacesYAML = collectElement((List) classifierYAML, SUPER_INTERFACES); + if(superInterfacesYAML instanceof List) + { + for(Object superInterface : (List) superInterfacesYAML) + { + ObjectModelImplRef superInterfaceOM = new ObjectModelImplRef(); + superInterfaceOM.setName(String.valueOf(superInterface)); + classifierOM.addInterface(superInterfaceOM); + } + } } } - public void loadInterface(Object _interface) { - ;//TODO + public void loadClass(Object classYAML, ObjectModelClassImpl classOM) + { + if(classYAML instanceof List) + { + //TODO: addInnerClassifier + + loadClassifier(classYAML, classOM); + + Object abstractYAML = collectElement((List) classYAML, ABSTRACT); + if(abstractYAML == null) + { + ; + } + else + { + classOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML))); + } + + Object superClassesYAML = collectElement((List) classYAML, SUPER_CLASSES); + if(superClassesYAML instanceof List) + { + for(Object superClass : (List) superClassesYAML) + { + ObjectModelImplRef superClassOM = new ObjectModelImplRef(); + superClassOM.setName(String.valueOf(superClass)); + classOM.addSuperclass(superClassOM); + } + } + } } - public void loadAssociationClass(Object _associationClass) { - ;//TODO + public void loadInterface(Object interfaceYAML, ObjectModelInterfaceImpl interfaceOM) + { + if(interfaceYAML instanceof List) + { + loadClassifier(interfaceYAML, interfaceOM); + } } - public void loadEnumeration(Object _enumeration) { - ;//TODO + public void loadAssociationClass(Object associationClassYAML, ObjectModelAssociationClassImpl associationClassOM) + { + if(associationClassYAML instanceof List) + { + loadClass(associationClassYAML, associationClassOM); + + List participantsYAML = collectAllElements((List) associationClassYAML, PARTICIPANT); + for(Object participantYAML : participantsYAML) + { + ObjectModeImplAssociationClassParticipant participant = new ObjectModeImplAssociationClassParticipant(); + //TODO: + } + } } - public ObjectModelAttributeImpl loadAttribute(Object attributeYAML) { - if(attributeYAML instanceof List) + public void loadEnumeration(Object enumerationYAML, ObjectModelEnumerationImpl enumerationOM) + { + if(enumerationYAML instanceof List) { - ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl(); + loadElement(enumerationYAML, enumerationOM); - this.loadStereotypes((List) attributeYAML, attributeOM); - this.loadTagValues((List) attributeYAML, attributeOM); - this.loadComments((List) attributeYAML, attributeOM); + Object literalsYAML = collectElement((List) enumerationYAML, LITERAL); + if(literalsYAML instanceof List) + { + for(Object literalYAML : (List) literalsYAML) + { + ObjectModelImplRef literalOM = new ObjectModelImplRef(); + literalOM.setName(String.valueOf(literalYAML)); + enumerationOM.addLiteral(literalOM); + } + } + } + } - Object nameYAML = collectElement((List) attributeYAML, "name"); - if(nameYAML != null) + public void loadParameter(Object parameterYAML, ObjectModelParameterImpl parameterOM) + { + if(parameterYAML instanceof List) + { + loadElement(parameterYAML, parameterOM); + + Object orderingYAML = collectElement((List) parameterYAML, ORDERING); + if(orderingYAML == null) { - attributeOM.setName(String.valueOf(nameYAML)); + ; } else { - //TODO : charger la valeur par defaut + parameterOM.setOrdering(String.valueOf(orderingYAML)); } - Object typeYAML = collectElement((List) attributeYAML, "type"); - if(typeYAML != null) + Object typeYAML = collectElement((List) parameterYAML, TYPE); + if(typeYAML == null) { - //TODO : gerer les imports et detection des types primitifs... + ; + } + else + { String type = String.valueOf(typeYAML); if(imports.containsKey(type)) { - attributeOM.setType(imports.get(type)); + parameterOM.setType(imports.get(type)); } else { - attributeOM.setType(type); + parameterOM.setType(type); } } + + Object defaultValueYAML = collectElement((List) parameterYAML, DEFAULT_VALUE); + if(defaultValueYAML == null) + { + ; + } else { - ;//TODO : lever exception + parameterOM.setDefaultValue(String.valueOf(defaultValueYAML)); } - Object visibilityYAML = collectElement((List) attributeYAML, "visibility"); - if(visibilityYAML != null) + Object minMultiplicityYAML = collectElement((List) parameterYAML, MIN_MULTIPLICITY); + if(minMultiplicityYAML == null) { - attributeOM.setVisibility(String.valueOf(visibilityYAML)); + ; } else { - //TODO : charger valeur par defaut + parameterOM.setMinMultiplicity(Integer.valueOf(String.valueOf(minMultiplicityYAML))); } - Object staticYAML = collectElement((List) attributeYAML, "static"); - if(staticYAML != null) + Object maxMultiplicityYAML = collectElement((List) parameterYAML, MAX_MULTIPLICITY); + if(maxMultiplicityYAML == null) { - attributeOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML)));//tester boolean ? + ; } else { - //TODO : charger valeur par defaut + parameterOM.setMaxMultiplicity(Integer.valueOf(String.valueOf(maxMultiplicityYAML))); } - Object finalYAML = collectElement((List) attributeYAML, "final"); - if(finalYAML != null) + Object orderedYAML = collectElement((List) parameterYAML, ORDERED); + if(orderedYAML == null) { - attributeOM.setFinal(Boolean.valueOf(String.valueOf(finalYAML))); + ; } else { - //TODO : charger la valeur par defaut + parameterOM.setOrdered(Boolean.valueOf(String.valueOf(orderedYAML))); } - Object associationTypeYAML = collectElement((List) attributeYAML, "asociationType"); - if(associationTypeYAML != null) + Object uniqueYAML = collectElement((List) parameterYAML, UNIQUE); + if(uniqueYAML == null) { - attributeOM.setAssociationType(String.valueOf(associationTypeYAML)); + ; } else { - //TODO : charger la valeur par defaut + parameterOM.setUnique(Boolean.valueOf(String.valueOf(uniqueYAML))); } + } + } - Object minMultiplicityYAML = collectElement((List) attributeYAML, "minMultiplicity"); - if(minMultiplicityYAML != null) + public void loadAttribute(Object attributeYAML, ObjectModelAttributeImpl attributeOM) + { + if(attributeYAML instanceof List) + { + loadParameter(attributeYAML, attributeOM); + + Object navigableYAML = collectElement((List) attributeYAML, NAVIGABLE); + if(navigableYAML == null) { - attributeOM.setMinMultiplicity(Integer.valueOf(String.valueOf(minMultiplicityYAML))); + ; } else { - //TODO : charger la valeur par defaut + attributeOM.setNavigable(Boolean.valueOf(String.valueOf(navigableYAML))); } - Object maxMultiplicityYAML = collectElement((List) attributeYAML, "maxMultiplicity"); - if(maxMultiplicityYAML != null) + Object associationTypeYAML = collectElement((List) attributeYAML, ASSOCIATION_TYPE); + if(associationTypeYAML == null) { - attributeOM.setMaxMultiplicity(Integer.valueOf(String.valueOf(maxMultiplicityYAML))); + ; } else { - //TODO : charger la valeur par defaut + attributeOM.setAssociationType(String.valueOf(associationTypeYAML)); } - Object navigableYAML = collectElement((List) attributeYAML, "navigable"); - if(navigableYAML != null) + Object finalYAML = collectElement((List) attributeYAML, FINAL); + if(finalYAML == null) { - attributeOM.setNavigable(Boolean.valueOf(String.valueOf(navigableYAML))); + ; } else { - //TODO : charger la valeur par defaut + attributeOM.setFinal(Boolean.valueOf(String.valueOf(finalYAML))); } - Object orderingYAML = collectElement((List) attributeYAML, "ordering"); - if(orderingYAML != null) + Object staticYAML = collectElement((List) attributeYAML, STATIC); + if(staticYAML == null) { - attributeOM.setOrdering(String.valueOf(orderingYAML)); + ; } else { - //TODO : charger la valeur par defaut + attributeOM.setStatic(Boolean.valueOf(String.valueOf(staticYAML))); } - Object labelYAML = collectElement((List) attributeYAML, "label"); - if(labelYAML != null) + Object associationClassNameYAML = collectElement((List) attributeYAML, ASSOCIATION_CLASS_NAME); + if(associationClassNameYAML == null) { - //TODO : gestion des labels et operations correspondantes - writeLog("label="+String.valueOf(labelYAML)); + ; } + else + { + attributeOM.setAssociationClassName(String.valueOf(associationClassNameYAML)); + } - return attributeOM; - } - return null; - } + Object reverseAttributeNameYAML = collectElement((List) attributeYAML, REVERSE_ATTRIBUTE_NAME); + if(reverseAttributeNameYAML == null) + { + ; + } + else + { + attributeOM.setReverseAttributeName(String.valueOf(reverseAttributeNameYAML)); + } - public void loadOperation(Object operationYAML) { - ;//TODO - } + Object reverseMaxMultiplicityYAML = collectElement((List) attributeYAML, REVERSE_MAX_MULTIPLICITY); + if(reverseMaxMultiplicityYAML == null) + { + ; + } + else + { + attributeOM.setReverseMaxMultiplicity(Integer.valueOf(String.valueOf(reverseMaxMultiplicityYAML))); + } - public void loadImports() - { //pour etre sur que les imports seront des <String,String> - if(modelYAML instanceof List)//verification inutile ? - { - Map<Object,Object> tmp = collectMap((List) modelYAML,"imports"); - imports = new LinkedHashMap(); - for(Map.Entry<Object,Object> entry : tmp.entrySet()) + + Object transientYAML = collectElement((List) attributeYAML, TRANSIENT); + if(transientYAML == null) { - imports.put(String.valueOf(entry.getKey()),String.valueOf(entry.getValue())); + ; } - writeLog("imports="+imports); - } - } + else + { + attributeOM.setTransient(Boolean.valueOf(String.valueOf(transientYAML))); + } - public void loadStereotypes(List elementYAML, ObjectModelElementImpl elementOM) { - Object stereotypes = this.collectElement(elementYAML, "stereotype"); - if (stereotypes instanceof List) { - for (Object stereotype : (List) stereotypes) { - ObjectModelImplRef ref = new ObjectModelImplRef(); - ref.setName(String.valueOf(stereotype)); - elementOM.addStereotype(ref); + Object visibilityYAML = collectElement((List) attributeYAML, VISIBILITY); + if(visibilityYAML == null) + { + ; } + else + { + attributeOM.setVisibility(String.valueOf(visibilityYAML)); + } } } - //TODO : pour model - public void loadComments(List elementYAML, ObjectModelElementImpl elementOM) { - Object comments = this.collectElement(elementYAML, "comments"); - if (comments instanceof List) { - for (Object comment : (List) comments) { - elementOM.addComment(String.valueOf(comment)); + public void loadOperation(Object operationYAML, ObjectModelOperationImpl operationOM) + { + if(operationYAML instanceof List) + { + //TODO: addExceptionParameter + + loadElement(operationYAML, operationOM); + + Object abstractYAML = collectElement((List) operationYAML, ABSTRACT); + if(abstractYAML == null) + { + ; } - } - } + else + { + operationOM.setAbstract(Boolean.valueOf(String.valueOf(abstractYAML))); + } - //TODO : pour model - public void loadTagValues(List elementYAML, ObjectModelElementImpl elementOM) { - Object tagValues = this.collectElement(elementYAML, "tagValues"); - if (tagValues instanceof Map) { - for (Object entry : ((Map) tagValues).entrySet()) { - String key = String.valueOf(((Map.Entry) entry).getKey()); - String value = String.valueOf(((Map.Entry) entry).getValue()); - elementOM.addTagValue(key, value); + Object visibilityYAML = collectElement((List) operationYAML, VISIBILITY); + if(visibilityYAML == null) + { + ; } - } - } + else + { + operationOM.setVisibility(String.valueOf(visibilityYAML)); + } - public Object collectElement(List data, Object key) { - for (Object obj : data) { - if (obj instanceof Map) { - if (((Map) obj).containsKey(key)) { - return ((Map) obj).get(key); - } + Object returnParameterYAML = collectElement((List) operationYAML, RETURN_PARAMETER); + if(returnParameterYAML == null) + { + ; } - } - return null; - } + else + { + ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl(); + loadParameter(returnParameterYAML, parameterOM); + operationOM.setReturnParameter(parameterOM); + } - public List collectList(List data, Object key) { - for (Object obj : data) { - if (obj instanceof Map) { - if (((Map) obj).containsKey(key)) { - if (((Map) obj).get(key) instanceof List) { - return (List) ((Map) obj).get(key); - /*List res = new LinkedList(); - for(Object tmp : (List) ((Map) obj).get(_key)) - { - res.add(tmp); - } - return res;*/ - } - } + Object bodyCodeYAML = collectElement((List) operationYAML, BODY_CODE); + if(bodyCodeYAML == null) + { + ; } - } - return null; - } + else + { + operationOM.setBodyCode(String.valueOf(bodyCodeYAML)); + } - public Map collectMap(List data, Object key) { - for (Object obj : data) { - if (obj instanceof Map) { - if (((Map) obj).containsKey(key)) { - if (((Map) obj).get(key) instanceof Map) { - return (Map) ((Map) obj).get(key); - /*Map res = new LinkedHashMap(); - for(Object tmp : ((Map) ((Map) obj).get(_key)).entrySet()) - { - if(tmp instanceof Map.Entry)//ou cast - { - res.put(((Map.Entry) tmp).getKey(),((Map.Entry) tmp).getValue()); - } - } - return res;*/ - } + List parametersYAML = collectAllElements((List) operationYAML, PARAMETER); + { + for(Object parameterYAML : parametersYAML) + { + ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl(); + loadParameter(parameterYAML, parameterOM); + operationOM.addParameter(parameterOM); } } } - return null; } - //collectElements - public List collectAllElement(List data, Object key) { - List res = new LinkedList(); - for (Object obj : data) { - if (obj instanceof Map) { - if (((Map) obj).containsKey(key)) { - res.add(((Map) obj).get(key)); - } - } - } - return res; - } }
participants (1)
-
agiraudet@users.nuiton.org