Author: agiraudet Date: 2013-06-11 12:11:42 +0200 (Tue, 11 Jun 2013) New Revision: 1271 Url: http://nuiton.org/projects/eugene/repository/revisions/1271 Log: r?\195?\169?\195?\169criture du parser yaml (optimisation, plus propre) Added: 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 trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserPureYaml.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserUserFriendly.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/yaml/Parser.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxePureYaml.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxeUserFriendly.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadObjectModel.java trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadYamlFile.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-06-10 14:09:12 UTC (rev 1270) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/YamlObjectModelReader.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -29,8 +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.TestLoadYamlFile; -import org.nuiton.eugene.models.object.reader.yaml.YamlToObjectModel; +import org.nuiton.eugene.models.object.reader.yaml.LoadYamlFile; import org.yaml.snakeyaml.error.YAMLException; import java.io.File; @@ -47,7 +46,7 @@ private static final Log log = LogFactory.getLog(YamlObjectModelReader.class); //protected YamlToObjectModel yamlToObjectModel; - protected TestLoadYamlFile test; + protected LoadYamlFile test; @Override public String getInputType() { @@ -58,14 +57,14 @@ protected void beforeReadFile(File... files) { super.beforeReadFile(files); //yamlToObjectModel = new YamlToObjectModel(); - test = new TestLoadYamlFile(); + test = new LoadYamlFile(); } @Override protected void readFileToModel(File file, ObjectModel model) throws IOException { try { //yamlToObjectModel.loadFile(file,model); - test.LoadYamlFile(file,model); + test.loadFile(file,model); } catch (YAMLException e) { throw new IOException("Unable to parse ObjectModel input file : " + file, e); } Added: 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 (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadObjectModel.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -0,0 +1,539 @@ +package org.nuiton.eugene.models.object.reader.yaml; + +import org.nuiton.eugene.models.object.xml.*; + +import java.util.List; +import java.util.Map; + +/** + * User: agiraudet + * Date: 11/06/13 + * Time: 10:37 + */ +public class LoadObjectModel extends KeyWords { + protected String packageL; + protected YamlObject modelYAMLO; + protected ObjectModelImpl modelOM; + + public LoadObjectModel(YamlObject modelYAMLO, ObjectModelImpl modelOM) + { + this.packageL = "default"; + this.modelOM = modelOM; + this.modelYAMLO = modelYAMLO; + //log + //Log.initLog(modelYAMLO.toString(),"/tmp/log.LoadObjectModel.txt"); + //log + } + + public void loadModel() { + String packageYAMLO = modelYAMLO.getFirstMapStringListString(PACKAGE); + if(packageYAMLO == null) + { + //valeur par defaut + } + else + { + packageL = packageYAMLO; + } + + String nameYAMLO = modelYAMLO.getFirstMapStringListString(NAME); + if(nameYAMLO == null) + { + ;//valeur par defaut + } + else + { + modelOM.setName(nameYAMLO); + } + + String versionYAMLO = modelYAMLO.getFirstMapStringListString(VERSION); + if(versionYAMLO == null) + { + ;//valeur par defaut + } + else + { + modelOM.setVersion(versionYAMLO); + } + + //tageValues + //TODO: tester + YamlObject tagValues = modelYAMLO.getFirstMapStringListYamlObject(TAG_VALUES); + if(tagValues != null) + { + for(Map.Entry<String,List<String>> tagValue :tagValues.getMapStringListString().entrySet()) + { + if(!tagValue.getValue().isEmpty())//taille strictement = 1 + { + modelOM.addTagValue(tagValue.getKey(),tagValue.getValue().get(0)); + } + } + } + + //classes + for(YamlObject classYAMLO : modelYAMLO.getMapStringListYamlObject(CLASS)) + { + ObjectModelClassImpl classOM = new ObjectModelClassImpl(); + loadClass(classYAMLO,classOM); + modelOM.addClass(classOM); + } + //interfaces + for(YamlObject interfaceYAMLO : modelYAMLO.getMapStringListYamlObject(INTERFACE)) + { + ObjectModelInterfaceImpl interfaceOM = new ObjectModelInterfaceImpl(); + loadInterface(interfaceYAMLO,interfaceOM); + modelOM.addInterface(interfaceOM); + } + //classes d'association + for(YamlObject associationClassYAMLO : modelYAMLO.getMapStringListYamlObject(ASSOCIATION_CLASS)) + { + ObjectModelAssociationClassImpl associationClassOM = new ObjectModelAssociationClassImpl(); + loadAssociationClass(associationClassYAMLO,associationClassOM); + modelOM.addAssociationClass(associationClassOM); + } + //enumerations + for(YamlObject enumerationYAMLO : modelYAMLO.getMapStringListYamlObject(ENUMERATION)) + { + ObjectModelEnumerationImpl enumerationOM = new ObjectModelEnumerationImpl(); + loadEnumeration(enumerationYAMLO,enumerationOM); + modelOM.addEnumeration(enumerationOM); + } + } + + public void loadElement(YamlObject elementYAMLO, ObjectModelElementImpl elementOM) + { + String nameYAMLO = elementYAMLO.getFirstMapStringListString(NAME); + if(nameYAMLO == null) + { + ;//valeur par defaut + } + else + { + elementOM.setName(nameYAMLO); + } + + String staticYAMLO = elementYAMLO.getFirstMapStringListString(STATIC); + if(staticYAMLO == null) + { + ;//valeur par defaut + } + else + { + elementOM.setStatic(Boolean.valueOf(staticYAMLO)); + } + + String documentationYAMLO = elementYAMLO.getFirstMapStringListString(DOCUMENTATION); + if(documentationYAMLO == null) + { + ;//valeur par defaut + } + else + { + elementOM.setDocumentation(documentationYAMLO); + } + + //TODO: tester + YamlObject tagValues = elementYAMLO.getFirstMapStringListYamlObject(TAG_VALUES); + if(tagValues != null) + { + for(Map.Entry<String,List<String>> tagValue :tagValues.getMapStringListString().entrySet()) + { + if(!tagValue.getValue().isEmpty())//taille strictement = 1 + { + elementOM.addTagValue(tagValue.getKey(),tagValue.getValue().get(0)); + } + } + } + + List<String> comments = elementYAMLO.getMapStringListString(COMMENTS); + for(String comment : comments) + { + elementOM.addComment(comment); + } + + List<String> stereotypes = elementYAMLO.getMapStringListString(STEREOTYPES); + for(String stereotype : stereotypes) + { + ObjectModelImplRef stereotypeOM = new ObjectModelImplRef(); + stereotypeOM.setName(stereotype); + elementOM.addStereotype(stereotypeOM); + } + } + + public void loadClassifier(YamlObject classifierYAMLO, ObjectModelClassifierImpl classifierOM) + { + loadElement(classifierYAMLO, classifierOM); + + String packageYAMLO = classifierYAMLO.getFirstMapStringListString(PACKAGE); + if(packageYAMLO == null) + { + classifierOM.setPackage(packageL); + } + else + { + classifierOM.setPackage(packageYAMLO); + } + + + String externYAMLO = classifierYAMLO.getFirstMapStringListString(EXTERN); + if(externYAMLO == null) + { + ;//valeur par defaut + } + else + { + classifierOM.setExtern(Boolean.valueOf(externYAMLO)); + + } + + String innerYAMLO = classifierYAMLO.getFirstMapStringListString(INNER); + if(innerYAMLO == null) + { + ;//valeur par defaut + } + else + { + classifierOM.setInner(Boolean.valueOf(innerYAMLO)); + } + + String typeYAMLO = classifierYAMLO.getFirstMapStringListString(TYPE); + if(typeYAMLO == null) + { + ;//valeur par defaut + } + else + { + classifierOM.setType(typeYAMLO); + } + + for(YamlObject attributeYAMLO : classifierYAMLO.getMapStringListYamlObject(ATTRIBUTE)) + { + ObjectModelAttributeImpl attributeOM = new ObjectModelAttributeImpl(); + loadAttribute(attributeYAMLO,attributeOM); + classifierOM.addAttribute(attributeOM); + } + + for(YamlObject operationYAMLO : classifierYAMLO.getMapStringListYamlObject(OPERATION)) + { + ObjectModelOperationImpl operationOM = new ObjectModelOperationImpl(); + loadOperation(operationYAMLO,operationOM); + classifierOM.addOperation(operationOM); + } + + List<String> superInterfacesYAMLO = classifierYAMLO.getMapStringListString(SUPER_INTERFACES); + for(String superInterfaceYAMLO : superInterfacesYAMLO) + { + ObjectModelImplRef superInterfaceOM = new ObjectModelImplRef(); + superInterfaceOM.setName(superInterfaceYAMLO); + classifierOM.addInterface(superInterfaceOM); + } + } + + public void loadClass(YamlObject classYAMLO, ObjectModelClassImpl classOM) + { + loadClassifier(classYAMLO, classOM); + + String abstractYAMLO = classYAMLO.getFirstMapStringListString(ABSTRACT); + if(abstractYAMLO == null) + { + ;//valeur par defaut + } + else + { + classOM.setAbstract(Boolean.valueOf(abstractYAMLO)); + } + + List<String> superClassesYAMLO = classYAMLO.getMapStringListString(SUPER_CLASSES); + for(String superClassYAMLO : superClassesYAMLO) + { + ObjectModelImplSuperClassRef superClassOM = new ObjectModelImplSuperClassRef(); + superClassOM.setName(superClassYAMLO); + classOM.addSuperclass(superClassOM); + } + } + + public void loadInterface(YamlObject interfaceYAMLO, ObjectModelInterfaceImpl interfaceOM) + { + loadClassifier(interfaceYAMLO,interfaceOM); + } + + public void loadAssociationClass(YamlObject associationClassYAML, ObjectModelAssociationClassImpl associationClassOM) + { + loadClass(associationClassYAML, associationClassOM); + + //TODO: remplacer name par type et attribute par name ? + for(YamlObject participantYAMLO : associationClassYAML.getMapStringListYamlObject(PARTICIPANT)) + { + ObjectModeImplAssociationClassParticipant participantOM = new ObjectModeImplAssociationClassParticipant(); + participantOM.setAssociationClass(associationClassOM); + + String nameYAMLO = participantYAMLO.getFirstMapStringListString(NAME); + if(nameYAMLO == null) + { + ;//valeur par defaut + } + else + { + participantOM.setName(nameYAMLO); + } + + String attributeYAMLO = participantYAMLO.getFirstMapStringListString(ATTRIBUTE); + if(attributeYAMLO == null) + { + ;//valeur par defaut + } + else + { + participantOM.setAttribute(attributeYAMLO); + } + + associationClassOM.addParticipant(participantOM); + } + } + + public void loadEnumeration(YamlObject enumerationYAMLO, ObjectModelEnumerationImpl enumerationOM) + { + loadElement(enumerationYAMLO, enumerationOM); + + //TODO: remplacer LITERAL par LITERALS (List) + List<String> literalsYAMLO = enumerationYAMLO.getMapStringListString(LITERAL); + for(String literalYAMLO : literalsYAMLO) + { + ObjectModelImplRef literalOM = new ObjectModelImplRef(); + literalOM.setName(literalYAMLO); + enumerationOM.addLiteral(literalOM); + } + + String packageYAMLO = enumerationYAMLO.getFirstMapStringListString(PACKAGE); + if(packageYAMLO == null) + { + enumerationOM.setPackage(packageL); + } + else + { + enumerationOM.setPackage(packageYAMLO); + } + } + + public void loadParameter(YamlObject parameterYAMLO, ObjectModelParameterImpl parameterOM) + { + loadElement(parameterYAMLO,parameterOM); + + String orderingYAMLO = parameterYAMLO.getFirstMapStringListString(ORDERING); + if(orderingYAMLO == null) + { + ;//valeur par defaut + } + else + { + parameterOM.setOrdering(orderingYAMLO); + } + + String typeYAMLO = parameterYAMLO.getFirstMapStringListString(TYPE); + if(typeYAMLO == null) + { + ;//valeur par defaut + } + else + { + parameterOM.setType(typeYAMLO); + } + + String defaultValueYAMLO = parameterYAMLO.getFirstMapStringListString(DEFAULT_VALUE); + if(defaultValueYAMLO == null) + { + ;//default + } + else + { + parameterOM.setDefaultValue(defaultValueYAMLO); + } + + String minMultiplicityYAMLO = parameterYAMLO.getFirstMapStringListString(MIN_MULTIPLICITY); + if(minMultiplicityYAMLO == null) + { + ;//valeur par defaut + } + else + { + parameterOM.setMinMultiplicity(Integer.valueOf(minMultiplicityYAMLO)); + } + + String maxMultiplicityYAMLO = parameterYAMLO.getFirstMapStringListString(MAX_MULTIPLICITY); + if(maxMultiplicityYAMLO == null) + { + ;//valeur par defaut + } + else + { + parameterOM.setMaxMultiplicity(Integer.valueOf(maxMultiplicityYAMLO)); + + } + + String orderedYAMLO = parameterYAMLO.getFirstMapStringListString(ORDERED); + if(orderedYAMLO == null) + { + ;//valeur par defaut + } + else + { + parameterOM.setOrdered(Boolean.valueOf(orderedYAMLO)); + } + + String uniqueYAMLO = parameterYAMLO.getFirstMapStringListString(UNIQUE); + if(uniqueYAMLO == null) + { + ;//valeur par defaut + } + else + { + parameterOM.setUnique(Boolean.valueOf(uniqueYAMLO)); + } + } + + public void loadAttribute(YamlObject attributeYAMLO, ObjectModelAttributeImpl attributeOM) + { + loadParameter(attributeYAMLO,attributeOM); + + String navigableYAMLO = attributeYAMLO.getFirstMapStringListString(NAVIGABLE); + if(navigableYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setNavigable(Boolean.valueOf(navigableYAMLO)); + } + + String associationTypeYAMLO = attributeYAMLO.getFirstMapStringListString(ASSOCIATION_TYPE); + if(associationTypeYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setAssociationType(associationTypeYAMLO); + } + + String finalYAMLO = attributeYAMLO.getFirstMapStringListString(FINAL); + if(finalYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setFinal(Boolean.valueOf(finalYAMLO)); + } + + String staticYAMLO = attributeYAMLO.getFirstMapStringListString(STATIC); + if(staticYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setStatic(Boolean.valueOf(staticYAMLO)); + } + + String associationClassNameYAMLO = attributeYAMLO.getFirstMapStringListString(ASSOCIATION_CLASS_NAME); + if(associationClassNameYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setAssociationClassName(associationClassNameYAMLO); + } + + String reverseAttributeNameYAMLO = attributeYAMLO.getFirstMapStringListString(REVERSE_ATTRIBUTE_NAME); + if(reverseAttributeNameYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setReverseAttributeName(reverseAttributeNameYAMLO); + } + + String reverseMaxMultiplicityYAMLO = attributeYAMLO.getFirstMapStringListString(REVERSE_MAX_MULTIPLICITY); + if(reverseMaxMultiplicityYAMLO == null) + { + //test + attributeOM.setReverseMaxMultiplicity(1);//valeur par defaut + //test + } + else + { + attributeOM.setReverseMaxMultiplicity(Integer.valueOf(reverseMaxMultiplicityYAMLO)); + } + + String transientYAMLO = attributeYAMLO.getFirstMapStringListString(TRANSIENT); + if(transientYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setTransient(Boolean.valueOf(transientYAMLO)); + } + + String visibilityYAMLO = attributeYAMLO.getFirstMapStringListString(VISIBILITY); + if(visibilityYAMLO == null) + { + ;//valeur par defaut + } + else + { + attributeOM.setVisibility(visibilityYAMLO); + } + } + + public void loadOperation(YamlObject operationYAMLO, ObjectModelOperationImpl operationOM) + { + loadElement(operationYAMLO,operationOM); + + String abstractYAMLO = operationYAMLO.getFirstMapStringListString(ABSTRACT); + if(abstractYAMLO == null) + { + ;//valeur par defaut + } + else + { + operationOM.setAbstract(Boolean.valueOf(abstractYAMLO)); + } + + String visibilityYAMLO = operationYAMLO.getFirstMapStringListString(VISIBILITY); + if(visibilityYAMLO == null) + { + ;//valeur par defaut + } + else + { + operationOM.setVisibility(visibilityYAMLO); + } + + for(YamlObject returnParameterYAMLO : operationYAMLO.getMapStringListYamlObject(RETURN_PARAMETER)) + { + ObjectModelParameterImpl returnParameterOM = new ObjectModelAttributeImpl(); + loadParameter(returnParameterYAMLO,returnParameterOM); + operationOM.setReturnParameter(returnParameterOM); + } + + for(YamlObject parameterYAMLO : operationYAMLO.getMapStringListYamlObject(PARAMETER)) + { + ObjectModelParameterImpl parameterOM = new ObjectModelAttributeImpl(); + loadParameter(parameterYAMLO,parameterOM); + operationOM.addParameter(parameterOM); + } + + String bodyCodeYAMLO = operationYAMLO.getFirstMapStringListString(BODY_CODE); + if(bodyCodeYAMLO == null) + { + ;//valeur par defaut + } + else + { + operationOM.setBodyCode(bodyCodeYAMLO); + } + } +} Added: 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 (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/LoadYamlFile.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -0,0 +1,75 @@ +package org.nuiton.eugene.models.object.reader.yaml; + +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.xml.ObjectModelImpl; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map; + +/** + * User: agiraudet + * Date: 10/06/13 + * Time: 16:11 + */ +public class LoadYamlFile extends KeyWords { + Yaml yaml; + + public LoadYamlFile() + { + yaml = new Yaml(); + } + + public void loadFile(File file, ObjectModel model) throws IOException + { + InputStream inputModel = new FileInputStream(file); + Object modelYAML = yaml.load(inputModel); + inputModel.close(); + + ObjectModelImpl modelOM = (ObjectModelImpl) model; + YamlObject modelYAMLO = new YamlObject(); + + Object version = null; + String syntaxeVersion = "0"; + String defaultVersion = "0"; + + if(modelYAML instanceof List) + { + version = YamlUtil.collectElementList((List) modelYAML, SYNTAXE); + syntaxeVersion = "1"; + defaultVersion = "0"; + } + else if(modelYAML instanceof Map) + { + version = YamlUtil.collectElementMap((Map) modelYAML, SYNTAXE); + syntaxeVersion = "2"; + defaultVersion = "0"; + } + + if(version != null) + { + syntaxeVersion = YamlUtil.beforeChar(String.valueOf(version),'.'); + defaultVersion = YamlUtil.afterChar(String.valueOf(version),'.'); + } + + if(syntaxeVersion.equals("1")) + { + SyntaxePureYaml.loadYamlObject(modelYAML,modelYAMLO); + } + else if(syntaxeVersion.equals("2")) + { + SyntaxeUserFriendly.loadYamlObject(modelYAML,modelYAMLO); + } + else + { + ;//impossible de charger le modele + } + + LoadObjectModel loader = new LoadObjectModel(modelYAMLO,modelOM);//+defaultVersion + loader.loadModel(); + } +} Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/Parser.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/Parser.java 2013-06-10 14:09:12 UTC (rev 1270) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/Parser.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -20,6 +20,7 @@ * methode2 : syntaxe moins restrictive, supprimer les élément et en déduir les restant * methode3 : la methode3 (ninja hybride) */ +@Deprecated public class Parser extends KeyWords { private static boolean _loginit = true; Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserPureYaml.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserPureYaml.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserPureYaml.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -0,0 +1,39 @@ +package org.nuiton.eugene.models.object.reader.yaml; + +import java.util.List; +import java.util.Map; + +/** + * User: agiraudet + * Date: 11/06/13 + * Time: 10:25 + */ +public class ParserPureYaml { + + public static void parseModel(Object modelYAML, YamlObject modelYAMLO) + { + if(modelYAML instanceof List) + { + for(Object tmp1 : (List) modelYAML) + { + parseModel(tmp1, modelYAMLO); + } + } + else if(modelYAML instanceof Map) + { + for(Object tmp1 : ((Map) modelYAML).entrySet()) + { + if(((Map.Entry) tmp1).getValue() instanceof List || ((Map.Entry) tmp1).getValue() instanceof Map) + { + YamlObject tmp2 = new YamlObject(); + parseModel(((Map.Entry) tmp1).getValue(),tmp2); + modelYAMLO.addYamlObjectToMap(String.valueOf(((Map.Entry) tmp1).getKey()).toLowerCase(), tmp2); + } + else + { + modelYAMLO.addStringToMap(String.valueOf(((Map.Entry) tmp1).getKey()).toLowerCase(), String.valueOf(((Map.Entry) tmp1).getValue())); + } + } + } + } +} Added: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserUserFriendly.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserUserFriendly.java (rev 0) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/ParserUserFriendly.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -0,0 +1,990 @@ +package org.nuiton.eugene.models.object.reader.yaml; + +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * User: agiraudet + * Date: 10/06/13 + * Time: 16:48 + */ +public class ParserUserFriendly extends KeyWords { + protected Map<String,String> imports; + protected Map<String,String> importsI; + protected Map<String,String> importsE; + protected String packageM; + protected Object modelYAML; + protected YamlObject modelYAMLO; + + public ParserUserFriendly(Object modelYAML, YamlObject modelYAMLO) + { + this.imports = new LinkedHashMap<String, String>(); + this.importsI = new LinkedHashMap<String, String>(); + this.importsE = new LinkedHashMap<String, String>(); + this.packageM = "default"; + this.modelYAML = modelYAML; + this.modelYAMLO = modelYAMLO; + } + + public void parseModel() + { + if(modelYAML instanceof Map) + { + for(Object entry : ((Map) modelYAML).entrySet()) + { + if(entry instanceof Map.Entry) + { + String key = String.valueOf(((Map.Entry) entry).getKey()); + Object value = ((Map.Entry) entry).getValue(); + if(key.equals(PACKAGE)) + { + modelYAMLO.addStringToMap(PACKAGE,String.valueOf(value)); + packageM = String.valueOf(value); + } + + if(key.equals(NAME)) + { + modelYAMLO.addStringToMap(NAME,String.valueOf(value)); + } + + if(key.equals(VERSION)) + { + modelYAMLO.addStringToMap(VERSION,String.valueOf(value)); + } + + if(key.equals(IMPORTS)) + { + if(value instanceof List) + { + for(Object imp : (List) value) + { + //modelYAMLO.addStringToMap(IMPORTS,String.valueOf(imp)); + importsE.put(YamlUtil.afterChar(String.valueOf(imp),'.'),String.valueOf(imp)); + } + } + } + + List<String> tmp = YamlUtil.charParseIgnore(key,' ','<','>'); + if(tmp.contains(CLASS)) + { YamlObject classYAMLO = new YamlObject(); + parseClass(key,value,classYAMLO); + modelYAMLO.addYamlObjectToMap(CLASS,classYAMLO); + } + else if(tmp.contains(INTERFACE)) + { + YamlObject interfaceYAMLO = new YamlObject(); + parseInterface(key,value,interfaceYAMLO); + modelYAMLO.addYamlObjectToMap(INTERFACE,interfaceYAMLO); + } + else if(tmp.contains(ASSOCIATION_CLASS)) + { + YamlObject associationClassYAMLO = new YamlObject(); + parseAssociationClass(key,value,associationClassYAMLO); + modelYAMLO.addYamlObjectToMap(ASSOCIATION_CLASS,associationClassYAMLO); + } + else if(tmp.contains(ENUMERATION)) + { + YamlObject enumerationYAMLO = new YamlObject(); + parseEnumeration(key,value,enumerationYAMLO); + modelYAMLO.addYamlObjectToMap(ENUMERATION,enumerationYAMLO); + } + } + } + } + } + + public void parseClass(String key, Object value, YamlObject classYAMLO) + { + List<String> classPARSE = YamlUtil.charParseIgnore(key,' ','<','>'); + if(classPARSE.contains(CLASS)) + { + classPARSE.remove(classPARSE.indexOf(CLASS)); + } + if(classPARSE.contains(ABSTRACT)) + { + classYAMLO.addStringToMap(ABSTRACT,String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(ABSTRACT)); + } + if(classPARSE.contains(STATIC)) + { + classYAMLO.addStringToMap(STATIC,String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(STATIC)); + } + if(classPARSE.contains(EXTERN)) + { + classYAMLO.addStringToMap(EXTERN,String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(EXTERN)); + } + if(classPARSE.contains(INNER)) + { + classYAMLO.addStringToMap(INNER,String.valueOf(true)); + classPARSE.remove(classPARSE.indexOf(INNER)); + } + if(classPARSE.contains(PUBLIC)) + { + classYAMLO.addStringToMap(VISIBILITY,PUBLIC); + classPARSE.remove(classPARSE.indexOf(PUBLIC)); + } + else if(classPARSE.contains(PRIVATE)) + { + classYAMLO.addStringToMap(VISIBILITY,PRIVATE); + classPARSE.remove(classPARSE.indexOf(PRIVATE)); + } + else if(classPARSE.contains(PROTECTED)) + { + classYAMLO.addStringToMap(VISIBILITY,PROTECTED); + classPARSE.remove(classPARSE.indexOf(PROTECTED)); + } + + for(String str1 : classPARSE) + { + if(str1.contains("<<") && str1.contains(">>")) + { + List<Character> targets = new LinkedList<Character>(); + targets.add('<'); + targets.add('>'); + String str2 = YamlUtil.removeMultiChar(str1, targets); + targets = new LinkedList<Character>(); + targets.add(' '); + targets.add(','); + List<String> list = YamlUtil.multiCharParse(str2, targets); + for(String str3 : list) + { + classYAMLO.addStringToMap(STEREOTYPES, str3); + } + } + } + + if(classPARSE.size() > 0) + { + String name = classPARSE.get(0); + classYAMLO.addStringToMap(NAME, name); + importsI.put(name,packageM+"."+name); + } + + if(value instanceof Map) + { + for(Object entry : ((Map) value).entrySet()) + { + if(entry instanceof Map.Entry) + { + String keyP = String.valueOf(((Map.Entry) entry).getKey()); + Object valueP = ((Map.Entry) entry).getValue(); + + if(keyP.equals(SUPER_CLASSES)) + { + if(valueP instanceof List) + { + for(Object superClass : (List) valueP) + { + classYAMLO.addStringToMap(SUPER_CLASSES,String.valueOf(superClass)); + } + } + } + else if(keyP.equals(SUPER_INTERFACES)) + { + if(valueP instanceof List) + { + for(Object superInterface : (List) valueP) + { + classYAMLO.addStringToMap(SUPER_INTERFACES,String.valueOf(superInterface)); + } + } + } + else + { + if(keyP.contains("(") && keyP.contains(")")) + { + YamlObject operationYAMLO = new YamlObject(); + parseOperation(keyP,valueP,operationYAMLO); + classYAMLO.addYamlObjectToMap(OPERATION,operationYAMLO); + } + else + { + YamlObject attributeYAMLO = new YamlObject(); + parseAttribute(keyP,valueP,attributeYAMLO); + classYAMLO.addYamlObjectToMap(ATTRIBUTE,attributeYAMLO); + } + } + } + } + } + } + + //TODO: factoriser le code (classifier) + public void parseInterface(String key, Object value, YamlObject interfaceYAMLO) + { + List<String> interfacePARSE = YamlUtil.charParseIgnore(key,' ','<','>'); + if(interfacePARSE.contains(INTERFACE)) + { + interfacePARSE.remove(interfacePARSE.indexOf(INTERFACE)); + } + if(interfacePARSE.contains(ABSTRACT)) + { + interfaceYAMLO.addStringToMap(ABSTRACT, String.valueOf(true)); + interfacePARSE.remove(interfacePARSE.indexOf(ABSTRACT)); + } + if(interfacePARSE.contains(STATIC)) + { + interfaceYAMLO.addStringToMap(STATIC, String.valueOf(true)); + interfacePARSE.remove(interfacePARSE.indexOf(STATIC)); + } + if(interfacePARSE.contains(EXTERN)) + { + interfaceYAMLO.addStringToMap(EXTERN, String.valueOf(true)); + interfacePARSE.remove(interfacePARSE.indexOf(EXTERN)); + } + if(interfacePARSE.contains(INNER)) + { + interfaceYAMLO.addStringToMap(INNER, String.valueOf(true)); + interfacePARSE.remove(interfacePARSE.indexOf(INNER)); + } + if(interfacePARSE.contains(PUBLIC)) + { + interfaceYAMLO.addStringToMap(VISIBILITY, PUBLIC); + interfacePARSE.remove(interfacePARSE.indexOf(PUBLIC)); + } + else if(interfacePARSE.contains(PRIVATE)) + { + interfaceYAMLO.addStringToMap(VISIBILITY, PRIVATE); + interfacePARSE.remove(interfacePARSE.indexOf(PRIVATE)); + } + else if(interfacePARSE.contains(PROTECTED)) + { + interfaceYAMLO.addStringToMap(VISIBILITY, PROTECTED); + interfacePARSE.remove(interfacePARSE.indexOf(PROTECTED)); + } + + for(String str1 : interfacePARSE) + { + if(str1.contains("<<") && str1.contains(">>")) + { + List<Character> targets = new LinkedList<Character>(); + targets.add('<'); + targets.add('>'); + String str2 = YamlUtil.removeMultiChar(str1, targets); + targets = new LinkedList<Character>(); + targets.add(' '); + targets.add(','); + List<String> list = YamlUtil.multiCharParse(str2, targets); + for(String str3 : list) + { + interfaceYAMLO.addStringToMap(STEREOTYPES, str3); + } + } + } + + if(interfacePARSE.size() > 0) + { + String name = interfacePARSE.get(0); + interfaceYAMLO.addStringToMap(NAME, name); + importsI.put(name,packageM+"."+name); + } + + if(value instanceof Map) + { + for(Object entry : ((Map) value).entrySet()) + { + if(entry instanceof Map.Entry) + { + String keyP = String.valueOf(((Map.Entry) entry).getKey()); + Object valueP = ((Map.Entry) entry).getValue(); + + if(keyP.equals(SUPER_CLASSES)) + { + if(valueP instanceof List) + { + for(Object superClass : (List) valueP) + { + interfaceYAMLO.addStringToMap(SUPER_CLASSES, String.valueOf(superClass)); + } + } + } + else if(keyP.equals(SUPER_INTERFACES)) + { + if(valueP instanceof List) + { + for(Object superInterface : (List) valueP) + { + interfaceYAMLO.addStringToMap(SUPER_INTERFACES, String.valueOf(superInterface)); + } + } + } + else + { + if(keyP.contains("(") && keyP.contains(")")) + { + YamlObject operationYAMLO = new YamlObject(); + parseOperation(keyP,valueP,operationYAMLO); + interfaceYAMLO.addYamlObjectToMap(OPERATION, operationYAMLO); + } + else + { + YamlObject attributeYAMLO = new YamlObject(); + parseAttribute(keyP,valueP,attributeYAMLO); + interfaceYAMLO.addYamlObjectToMap(ATTRIBUTE, attributeYAMLO); + } + } + } + } + } + } + + public void parseAssociationClass(String key, Object value, YamlObject associationClassYAMLO) + { + List<String> associationClassPARSE = YamlUtil.charParseIgnore(key,' ','<','>'); + if(associationClassPARSE.contains(ASSOCIATION_CLASS)) + { + associationClassPARSE.remove(associationClassPARSE.indexOf(ASSOCIATION_CLASS)); + } + if(associationClassPARSE.contains(ABSTRACT)) + { + associationClassYAMLO.addStringToMap(ABSTRACT, String.valueOf(true)); + associationClassPARSE.remove(associationClassPARSE.indexOf(ABSTRACT)); + } + if(associationClassPARSE.contains(STATIC)) + { + associationClassYAMLO.addStringToMap(STATIC, String.valueOf(true)); + associationClassPARSE.remove(associationClassPARSE.indexOf(STATIC)); + } + if(associationClassPARSE.contains(EXTERN)) + { + associationClassYAMLO.addStringToMap(EXTERN, String.valueOf(true)); + associationClassPARSE.remove(associationClassPARSE.indexOf(EXTERN)); + } + if(associationClassPARSE.contains(INNER)) + { + associationClassYAMLO.addStringToMap(INNER, String.valueOf(true)); + associationClassPARSE.remove(associationClassPARSE.indexOf(INNER)); + } + if(associationClassPARSE.contains(PUBLIC)) + { + associationClassYAMLO.addStringToMap(VISIBILITY, PUBLIC); + associationClassPARSE.remove(associationClassPARSE.indexOf(PUBLIC)); + } + else if(associationClassPARSE.contains(PRIVATE)) + { + associationClassYAMLO.addStringToMap(VISIBILITY, PRIVATE); + associationClassPARSE.remove(associationClassPARSE.indexOf(PRIVATE)); + } + else if(associationClassPARSE.contains(PROTECTED)) + { + associationClassYAMLO.addStringToMap(VISIBILITY, PROTECTED); + associationClassPARSE.remove(associationClassPARSE.indexOf(PROTECTED)); + } + + for(String str1 : associationClassPARSE) + { + if(str1.contains("<<") && str1.contains(">>")) + { + List<Character> targets = new LinkedList<Character>(); + targets.add('<'); + targets.add('>'); + String str2 = YamlUtil.removeMultiChar(str1, targets); + targets = new LinkedList<Character>(); + targets.add(' '); + targets.add(','); + List<String> list = YamlUtil.multiCharParse(str2, targets); + for(String str3 : list) + { + associationClassYAMLO.addStringToMap(STEREOTYPES, str3); + } + } + } + + if(associationClassPARSE.size() > 0) + { + String name = associationClassPARSE.get(0); + associationClassYAMLO.addStringToMap(NAME, name); + importsI.put(name,packageM+"."+name); + } + + if(value instanceof Map) + { + //TODO: utiliser variable locales pour plus de clartee + if(((Map) value).containsKey(PARTICIPANT)) + { + if(((Map) value).get(PARTICIPANT) instanceof Map) + { + for(Object entry : ((Map) ((Map) value).get(PARTICIPANT)).entrySet()) + { + if(entry instanceof Map.Entry) + { + List<String> participantPARSE = YamlUtil.charParse(String.valueOf(((Map.Entry) entry).getKey()),' '); + YamlObject participantYAMLO = new YamlObject(); + if(participantPARSE.contains("\""+YamlUtil.extract('"',String.valueOf(((Map.Entry) entry).getKey()))+"\"")) + { + String label = YamlUtil.extract('"',String.valueOf(((Map.Entry) entry).getKey())); + + participantYAMLO.addStringToMap(LABEL,label); + + participantPARSE.remove("\""+YamlUtil.extract('"',String.valueOf(((Map.Entry) entry).getKey()))+"\""); + } + + if(participantPARSE.size() > 0)//ajout type + { + participantYAMLO.addStringToMap(NAME,participantPARSE.get(0)); + } + if(participantPARSE.size() > 1)//ajout name + { + participantYAMLO.addStringToMap(ATTRIBUTE,participantPARSE.get(1)); + } + associationClassYAMLO.addYamlObjectToMap(PARTICIPANT,participantYAMLO); + } + } + } + ((Map) value).remove(PARTICIPANT); + } + + for(Object entry : ((Map) value).entrySet()) + { + if(entry instanceof Map.Entry) + { + String keyP = String.valueOf(((Map.Entry) entry).getKey()); + Object valueP = ((Map.Entry) entry).getValue(); + + if(keyP.equals(SUPER_CLASSES)) + { + if(valueP instanceof List) + { + for(Object superClass : (List) valueP) + { + associationClassYAMLO.addStringToMap(SUPER_CLASSES, String.valueOf(superClass)); + } + } + } + else if(keyP.equals(SUPER_INTERFACES)) + { + if(valueP instanceof List) + { + for(Object superInterface : (List) valueP) + { + associationClassYAMLO.addStringToMap(SUPER_INTERFACES, String.valueOf(superInterface)); + } + } + } + else + { + if(keyP.contains("(") && keyP.contains(")")) + { + YamlObject operationYAMLO = new YamlObject(); + parseOperation(keyP,valueP,operationYAMLO); + associationClassYAMLO.addYamlObjectToMap(OPERATION, operationYAMLO); + } + else + { + YamlObject attributeYAMLO = new YamlObject(); + parseAttribute(keyP,valueP,attributeYAMLO); + associationClassYAMLO.addYamlObjectToMap(ATTRIBUTE, attributeYAMLO); + } + } + } + } + } + } + + public void parseEnumeration(String key, Object value, YamlObject enumerationYAMLO) + { + List<String> enumerationPARSE = YamlUtil.charParseIgnore(key,' ','<','>'); + if(enumerationPARSE.contains(ENUMERATION)) + { + enumerationPARSE.remove(enumerationPARSE.indexOf(ENUMERATION)); + } + if(enumerationPARSE.contains(STATIC)) + { + enumerationYAMLO.addStringToMap(STATIC,String.valueOf(true)); + enumerationPARSE.remove(enumerationPARSE.indexOf(STATIC)); + } + + for(String str1 : enumerationPARSE) + { + if(str1.contains("<<") && str1.contains(">>")) + { + List<Character> targets = new LinkedList<Character>(); + targets.add('<'); + targets.add('>'); + String str2 = YamlUtil.removeMultiChar(str1, targets); + targets = new LinkedList<Character>(); + targets.add(' '); + targets.add(','); + List<String> list = YamlUtil.multiCharParse(str2, targets); + for(String str3 : list) + { + enumerationYAMLO.addStringToMap(STEREOTYPES, str3); + } + } + } + if(enumerationPARSE.size() > 0) + { + String name = enumerationPARSE.get(0); + enumerationYAMLO.addStringToMap(NAME, name); + importsI.put(name,packageM+"."+name); + } + //TODO: parser literals + } + + //TODO: factoriser code + /*public void parseClassifier(String type, String key, Object value, YamlObject classYAMLO) + { + ; + }*/ + + public void parseAttribute(String key, Object value, YamlObject attributeYAMLO) + { + List<String> attributePARSE = YamlUtil.charParseIgnore(key,' ','<','>'); + if(attributePARSE.contains(STATIC)) + { + attributeYAMLO.addStringToMap(STATIC,String.valueOf(true)); + attributePARSE.remove(attributePARSE.indexOf(STATIC)); + } + if(attributePARSE.contains(FINAL)) + { + attributeYAMLO.addStringToMap(FINAL,String.valueOf(true)); + attributePARSE.remove(attributePARSE.indexOf(FINAL)); + } + if(attributePARSE.contains(UNIQUE)) + { + attributeYAMLO.addStringToMap(UNIQUE,String.valueOf(true)); + attributePARSE.remove(attributePARSE.indexOf(UNIQUE)); + } + if(attributePARSE.contains(NAVIGABLE)) + { + attributeYAMLO.addStringToMap(NAVIGABLE,String.valueOf(true)); + attributePARSE.remove(attributePARSE.indexOf(NAVIGABLE)); + } + if(attributePARSE.contains(TRANSIENT)) + { + attributeYAMLO.addStringToMap(TRANSIENT,String.valueOf(true)); + attributePARSE.remove(attributePARSE.indexOf(TRANSIENT)); + } + if(attributePARSE.contains(PUBLIC)) + { + attributeYAMLO.addStringToMap(VISIBILITY,PUBLIC); + attributePARSE.remove(attributePARSE.indexOf(PUBLIC)); + } + else if(attributePARSE.contains(PROTECTED)) + { + attributeYAMLO.addStringToMap(VISIBILITY,PROTECTED); + attributePARSE.remove(attributePARSE.indexOf(PUBLIC)); + } + else if(attributePARSE.contains(PRIVATE)) + { + attributeYAMLO.addStringToMap(VISIBILITY,PRIVATE); + attributePARSE.remove(attributePARSE.indexOf(PUBLIC)); + } + + if(attributePARSE.contains(ORDERED)) + { + attributeYAMLO.addStringToMap(ORDERING,ORDERED); + attributePARSE.remove(attributePARSE.indexOf(ORDERED)); + } + else if(attributePARSE.contains(UNORDERED)) + { + attributeYAMLO.addStringToMap(ORDERING,UNORDERED); + attributePARSE.remove(attributePARSE.indexOf(UNORDERED)); + } + + //TODO: utiliser variables locales + if(attributePARSE.contains("\""+YamlUtil.extract('"',key)+"\"")) + { + String label = YamlUtil.extract('"',key); + attributeYAMLO.addStringToMap(LABEL,label); + attributePARSE.remove("\""+YamlUtil.extract('"',key)+"\""); + } + + if(attributePARSE.contains("["+YamlUtil.extract('[',']',key)+"]")) + { + String multiplicity = YamlUtil.extract('[',']',key); + if(multiplicity.equals("*")) + { + attributeYAMLO.addStringToMap(MIN_MULTIPLICITY,"0"); + attributeYAMLO.addStringToMap(MAX_MULTIPLICITY,"-1"); + } + else if(multiplicity.contains("..")) + { + String min = YamlUtil.beforeChar(multiplicity,'.'); + String max = YamlUtil.afterChar(multiplicity, '.'); + if(min.equals("*")) + { + min = "-1"; + } + if(max.equals("*")) + { + max = "-1"; + } + attributeYAMLO.addStringToMap(MIN_MULTIPLICITY,min); + attributeYAMLO.addStringToMap(MAX_MULTIPLICITY,max); + } + attributePARSE.remove("["+YamlUtil.extract('[',']',key)+"]"); + } + + if(attributePARSE.size() > 0) + { + attributeYAMLO.addStringToMap(TYPE,attributePARSE.get(0)); + } + if(attributePARSE.size() > 1) + { + attributeYAMLO.addStringToMap(NAME,attributePARSE.get(1)); + } + } + + public void parseOperation(String key, Object value, YamlObject operationYAMLO) + { + List<Character> ignoreStart = new LinkedList<Character>(); + ignoreStart.add('('); + ignoreStart.add('<'); + List<Character> ignoreEnd = new LinkedList<Character>(); + ignoreEnd.add(')'); + ignoreEnd.add('>'); + List<String> operationPARSE = YamlUtil.charParseMultiIgnore(key,' ',ignoreStart,ignoreEnd); + + if(operationPARSE.contains(STATIC)) + { + operationYAMLO.addStringToMap(STATIC,String.valueOf(true)); + operationPARSE.remove(operationPARSE.indexOf(STATIC)); + } + if(operationPARSE.contains(ABSTRACT)) + { + operationYAMLO.addStringToMap(ABSTRACT,String.valueOf(true)); + operationPARSE.remove(operationPARSE.indexOf(ABSTRACT)); + } + if(operationPARSE.contains(PUBLIC)) + { + operationYAMLO.addStringToMap(VISIBILITY,PUBLIC); + operationPARSE.remove(operationPARSE.indexOf(PUBLIC)); + } + else if(operationPARSE.contains(PROTECTED)) + { + operationYAMLO.addStringToMap(VISIBILITY,PROTECTED); + operationPARSE.remove(operationPARSE.indexOf(PROTECTED)); + } + else if(operationPARSE.contains(PRIVATE)) + { + operationYAMLO.addStringToMap(VISIBILITY,PRIVATE); + operationPARSE.remove(operationPARSE.indexOf(PRIVATE)); + } + + for(String str1 : operationPARSE) + { + if(str1.contains("(") && str1.contains(")")) + { + operationYAMLO.addStringToMap(NAME,YamlUtil.beforeChar(str1,'(')); + for(String str2 : YamlUtil.charParseIgnore(YamlUtil.extract('(', ')', str1), ',', '<', '>')) + { + List<String> list = YamlUtil.charParse(str2,' '); + if(list.size() == 2) + { + YamlObject parameterYAMLO = new YamlObject(); + parameterYAMLO.addStringToMap(TYPE, list.get(0)); + parameterYAMLO.addStringToMap(NAME, list.get(1)); + operationYAMLO.addYamlObjectToMap(PARAMETER, parameterYAMLO); + } + } + } + } + + if(value != null) + { + YamlObject returnParameterYAMLO = new YamlObject(); + returnParameterYAMLO.addStringToMap(TYPE,String.valueOf(value)); + operationYAMLO.addYamlObjectToMap(RETURN_PARAMETER,returnParameterYAMLO); + } + } + + public void resolveImports() + { + imports.putAll(importsE); + imports.putAll(importsI); + for(Map.Entry<String,List<YamlObject>> entry : modelYAMLO.getMapStringListYamlObject().entrySet()) + { + for(YamlObject importable : entry.getValue()) + { + if(importable.containsKeyMapStringListString(SUPER_CLASSES)) + { + for(String value : importable.getMapStringListString(SUPER_CLASSES)) + { + if(imports.containsKey(value)) + { + importable.setMapStringListString(SUPER_CLASSES,value,imports.get(value)); + } + } + } + if(importable.containsKeyMapStringListString(SUPER_INTERFACES)) + { + for(String value : importable.getMapStringListString(SUPER_INTERFACES)) + { + if(imports.containsKey(value)) + { + importable.setMapStringListString(SUPER_INTERFACES,value,imports.get(value)); + } + } + } + if(importable.containsKeyYamlMapStringListYamlObject(ATTRIBUTE)) + { + for(YamlObject attributeYAMLO : importable.getMapStringListYamlObject(ATTRIBUTE)) + { + if(attributeYAMLO.containsKeyMapStringListString(TYPE)) + { + attributeYAMLO.setMapStringListString(TYPE,attributeYAMLO.getFirstMapStringListString(TYPE),resolveType(attributeYAMLO.getFirstMapStringListString(TYPE))); + } + } + } + if(importable.containsKeyYamlMapStringListYamlObject(OPERATION)) + { + for(YamlObject operationYAMLO : importable.getMapStringListYamlObject(OPERATION)) + { + if(operationYAMLO.containsKeyYamlMapStringListYamlObject(PARAMETER)) + { + for(YamlObject parameterYAMLO : operationYAMLO.getMapStringListYamlObject(PARAMETER)) + { + if(parameterYAMLO.containsKeyMapStringListString(TYPE)) + { + parameterYAMLO.setMapStringListString(TYPE,parameterYAMLO.getFirstMapStringListString(TYPE),resolveType(parameterYAMLO.getFirstMapStringListString(TYPE))); + } + } + } + if(operationYAMLO.containsKeyYamlMapStringListYamlObject(RETURN_PARAMETER)) + { + for(YamlObject parameterYAMLO : operationYAMLO.getMapStringListYamlObject(RETURN_PARAMETER)) + { + if(parameterYAMLO.containsKeyMapStringListString(TYPE)) + { + parameterYAMLO.setMapStringListString(TYPE,parameterYAMLO.getFirstMapStringListString(TYPE),resolveType(parameterYAMLO.getFirstMapStringListString(TYPE))); + } + } + } + } + } + if(importable.containsKeyYamlMapStringListYamlObject(PARTICIPANT)) + { + for(YamlObject participantYAMLO : importable.getMapStringListYamlObject(PARTICIPANT)) + { + if(participantYAMLO.containsKeyMapStringListString(NAME)) + { + participantYAMLO.setMapStringListString(NAME,participantYAMLO.getFirstMapStringListString(NAME),resolveType(participantYAMLO.getFirstMapStringListString(NAME))); + } + } + } + } + } + } + + public String browseType(String type) + { + StringBuilder res = new StringBuilder(); + boolean first = true; + for(String tmp : YamlUtil.charParseIgnore(type,',','<','>')) + { + if(first) + { + first = false; + } + else + { + res.append(","); + } + if(tmp.contains("<") && tmp.contains(">")) + { + String ninja = YamlUtil.beforeChar(tmp,'<'); + if(imports.containsKey(ninja)) + { + res.append(imports.get(ninja)); + } + else + { + res.append(tmp); + } + res.append("<"); + res.append(browseType(YamlUtil.extract('<','>',tmp))); + res.append(">"); + } + else + { + if(imports.containsKey(tmp)) + { + res.append(imports.get(tmp)); + } + else + { + res.append(tmp); + } + } + } + return res.toString(); + } + + public String resolveType(String type) + { + List<Character> ignore = new LinkedList<Character>(); + ignore.add(' '); + String typePARSE = YamlUtil.removeMultiChar(type,ignore); + return browseType(typePARSE); + } + + public void resolveLabels() + { + for(List<YamlObject> objectYAMLO : modelYAMLO.getMapStringListYamlObject().values()) + { + for(YamlObject labelisable : objectYAMLO) + { + if(labelisable.containsKeyYamlMapStringListYamlObject(ATTRIBUTE)) + { + for(YamlObject attribute : labelisable.getMapStringListYamlObject(ATTRIBUTE)) + { + if(attribute.containsKeyMapStringListString(TYPE)) + { + String type = attribute.getFirstMapStringListString(TYPE); + if(importsI.containsValue(type)) + { + if(!attribute.containsKeyMapStringListString(NAVIGABLE)) + { + if(attribute.containsKeyMapStringListString(LABEL)) + { + String label = attribute.getFirstMapStringListString(LABEL); + YamlObject reverseAttribute = getReverseAttribute(YamlUtil.afterChar(type,'.'),label); + if(reverseAttribute != null) + { + attribute.addStringToMap(NAVIGABLE,String.valueOf(true)); + reverseAttribute.addStringToMap(NAVIGABLE,String.valueOf(true)); + if(attribute.containsKeyMapStringListString(MAX_MULTIPLICITY)) + { + reverseAttribute.addStringToMap(REVERSE_MAX_MULTIPLICITY,attribute.getFirstMapStringListString(MAX_MULTIPLICITY)); + } + if(reverseAttribute.containsKeyMapStringListString(MAX_MULTIPLICITY)) + { + attribute.addStringToMap(REVERSE_MAX_MULTIPLICITY,reverseAttribute.getFirstMapStringListString(MAX_MULTIPLICITY)); + } + if(attribute.containsKeyMapStringListString(NAME)) + { + reverseAttribute.addStringToMap(REVERSE_ATTRIBUTE_NAME,attribute.getFirstMapStringListString(NAME)); + } + if(reverseAttribute.containsKeyMapStringListString(NAME)) + { + attribute.addStringToMap(REVERSE_ATTRIBUTE_NAME,reverseAttribute.getFirstMapStringListString(NAME)); + } + } + } + else + { + YamlObject reverseObject = getReverseObject(YamlUtil.afterChar(type,'.')); + if(reverseObject != null) + { + YamlObject reverseAttribute = new YamlObject(); + reverseAttribute.addStringToMap(NAVIGABLE,String.valueOf(false)); + reverseAttribute.addStringToMap(TYPE,imports.get(labelisable.getFirstMapStringListString(NAME))); + if(attribute.containsKeyMapStringListString(MAX_MULTIPLICITY)) + { + reverseAttribute.addStringToMap(REVERSE_MAX_MULTIPLICITY,attribute.getFirstMapStringListString(MAX_MULTIPLICITY)); + } + if(attribute.containsKeyMapStringListString(NAME)) + { + reverseAttribute.addStringToMap(REVERSE_ATTRIBUTE_NAME,attribute.getFirstMapStringListString(NAME)); + } + if(attribute.containsKeyMapStringListString(ORDERING)) + { + if(attribute.getFirstMapStringListString(ORDERING).equals(ORDERED)) + { + reverseAttribute.addStringToMap(ORDERING,UNORDERED); + } + else if(attribute.getFirstMapStringListString(ORDERING).equals(UNORDERED)) + { + reverseAttribute.addStringToMap(ORDERING,ORDERED); + } + } + reverseObject.addYamlObjectToMap(ATTRIBUTE,reverseAttribute); + + attribute.addStringToMap(NAVIGABLE,String.valueOf(true)); + } + } + } + } + /*else//simple attribut + { + ; + }*/ + } + } + } + if(labelisable.containsKeyYamlMapStringListYamlObject(PARTICIPANT)) + { + for(YamlObject participant : labelisable.getMapStringListYamlObject(PARTICIPANT)) + { + if(participant.containsKeyMapStringListString(NAME)) + { + String name = participant.getFirstMapStringListString(NAME); + if(importsI.containsValue(name))//refClassifier + { + if(participant.containsKeyMapStringListString(LABEL)) + { + String label = participant.getFirstMapStringListString(LABEL); + YamlObject reverseAttribute = getReverseAttribute(YamlUtil.afterChar(name,'.'),label); + if(reverseAttribute != null) + { + if(labelisable.containsKeyMapStringListString(NAME)) + { + reverseAttribute.addStringToMap(ASSOCIATION_CLASS_NAME,packageM+"."+labelisable.getFirstMapStringListString(NAME)); + } + } + } + } + } + } + } + } + } + } + + public YamlObject getReverseAttribute(String type, String label) + { + for(List<YamlObject> objectsYAMLO : modelYAMLO.getMapStringListYamlObject().values()) + { + for(YamlObject objectYAMLO : objectsYAMLO) + { + if(objectYAMLO.containsKeyMapStringListString(NAME)) + { + String name = objectYAMLO.getFirstMapStringListString(NAME); + if(name.equals(type)) + { + if(objectYAMLO.containsKeyYamlMapStringListYamlObject(ATTRIBUTE)) + { + for(YamlObject attributeYAMLO : objectYAMLO.getMapStringListYamlObject(ATTRIBUTE)) + { + if(attributeYAMLO.containsKeyMapStringListString(LABEL)) + { + String reverseLabel = attributeYAMLO.getFirstMapStringListString(LABEL); + if(reverseLabel.equals(label)) + { + return attributeYAMLO; + } + } + } + } + } + } + } + } + return null; + } + + public YamlObject getReverseObject(String type) + { + for(List<YamlObject> objectsYAMLO : modelYAMLO.getMapStringListYamlObject().values()) + { + for(YamlObject objectYAMLO : objectsYAMLO) + { + if(objectYAMLO.containsKeyMapStringListString(NAME)) + { + String name = objectYAMLO.getFirstMapStringListString(NAME); + if(name.equals(type)) + { + return objectYAMLO; + } + } + } + } + return null; + } + +} Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxePureYaml.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxePureYaml.java 2013-06-10 14:09:12 UTC (rev 1270) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxePureYaml.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -1,52 +1,14 @@ package org.nuiton.eugene.models.object.reader.yaml; -import org.nuiton.eugene.models.object.ObjectModel; - -import java.util.List; -import java.util.Map; - /** * User: agiraudet * Date: 30/05/13 * Time: 11:23 */ -//TODO: interface Syntaxe ou classe abstraite (appel l'operation suivante : charger l'ObjectModel) -//key.toLowerCase() ? public class SyntaxePureYaml { - /* - public static void loadModelYaml(Object modelYAML, YamlObject modelYAMLO) + + public static void loadYamlObject(Object modelYAML, YamlObject modelYAMLO) { - loadYamlObject(modelYAML, modelYAMLO); + ParserPureYaml.parseModel(modelYAML,modelYAMLO); } - */ - public static void loadYamlObject(Object objectYaml, YamlObject modelYaml) - { - if(objectYaml instanceof List) - { - for(Object tmp1 : (List) objectYaml) - { - loadYamlObject(tmp1, modelYaml); - } - } - else if(objectYaml instanceof Map) - { - for(Object tmp1 : ((Map) objectYaml).entrySet()) - { - if(((Map.Entry) tmp1).getValue() instanceof List || ((Map.Entry) tmp1).getValue() instanceof Map) - { - YamlObject tmp2 = new YamlObject(); - loadYamlObject(((Map.Entry) tmp1).getValue(),tmp2); - modelYaml.addYamlObjectToMap(String.valueOf(((Map.Entry) tmp1).getKey()).toLowerCase(),tmp2); - } - else - { - modelYaml.addStringToMap(String.valueOf(((Map.Entry) tmp1).getKey()).toLowerCase(),String.valueOf(((Map.Entry) tmp1).getValue())); - } - } - } - /*else - { - modelYaml.addStringToMap(previous,String.valueOf(objectYaml)); - }*/ - } } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxeUserFriendly.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxeUserFriendly.java 2013-06-10 14:09:12 UTC (rev 1270) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/SyntaxeUserFriendly.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -7,4 +7,12 @@ */ //TODO: interface Syntaxe pour futures syntaxes public class SyntaxeUserFriendly { + + public static void loadYamlObject(Object modelYAML, YamlObject modelYAMLO) + { + ParserUserFriendly parser = new ParserUserFriendly(modelYAML,modelYAMLO); + parser.parseModel(); + parser.resolveImports(); + parser.resolveLabels(); + } } Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadObjectModel.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadObjectModel.java 2013-06-10 14:09:12 UTC (rev 1270) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadObjectModel.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -12,6 +12,7 @@ * Date: 30/05/13 * Time: 11:58 */ +@Deprecated public class TestLoadObjectModel extends KeyWords { List<String> imports; String packageL;//package local Modified: trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadYamlFile.java =================================================================== --- trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadYamlFile.java 2013-06-10 14:09:12 UTC (rev 1270) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/TestLoadYamlFile.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -17,6 +17,7 @@ * parser si besoin et charger le YAMLobject * parse en fonction de la version */ +@Deprecated public class TestLoadYamlFile extends KeyWords { Yaml yaml; ObjectModelImpl modelOM; 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-06-10 14:09:12 UTC (rev 1270) +++ trunk/eugene/src/main/java/org/nuiton/eugene/models/object/reader/yaml/YamlToObjectModel.java 2013-06-11 10:11:42 UTC (rev 1271) @@ -15,7 +15,7 @@ * Date: 15/05/13 * Time: 11:15 */ - + @Deprecated public class YamlToObjectModel { protected Yaml yaml; protected String packageOM;
participants (1)
-
agiraudet@users.nuiton.org