package jetbrains.mps.project.foreign; /*Generated by MPS */ import jetbrains.mps.project.structure.model.ModelRootDescriptor; import org.jdom.Element; import java.util.List; import java.util.ArrayList; import jetbrains.mps.util.xml.XmlUtil; import org.jetbrains.mps.openapi.persistence.Memento; import jetbrains.mps.persistence.MementoImpl; import jetbrains.mps.persistence.MementoUtil; import jetbrains.mps.internal.collections.runtime.ListSequence; public class MPSFacetConfiguration { private static final String OPT_VALUE = "value"; public String UUID; public String generatorOutputPath; public boolean useModuleSourceFolder = false; public boolean useTransientOutputFolder = false; public String[] usedLanguages; public ModelRootDescriptor[] rootDescriptors; public MPSFacetConfiguration() { } public void readFromXml(Element config) throws FacetConfigurationFormatException { List<ModelRootDescriptor> descriptors = new ArrayList<ModelRootDescriptor>(); for (Element ch : XmlUtil.children(config, "option")) { String optionName = ch.getAttributeValue("name"); if ("UUID".equals(optionName)) { this.UUID = ch.getAttributeValue(OPT_VALUE); } else if ("generatorOutputPath".equals(optionName)) { this.generatorOutputPath = ch.getAttributeValue(OPT_VALUE); } else if ("usedLanguages".equals(optionName)) { this.usedLanguages = readArray(XmlUtil.first(ch, "array")); } else if ("useModuleSourceFolder".equals(optionName)) { this.useModuleSourceFolder = "true".equals(ch.getAttributeValue(OPT_VALUE)); } else if ("useTransientOutputFolder".equals(optionName)) { this.useTransientOutputFolder = "true".equals(ch.getAttributeValue(OPT_VALUE)); } } for (Element modelRoot : XmlUtil.children(XmlUtil.first(config, "modelRoots"), "modelRoot")) { Element settings = XmlUtil.first(modelRoot, "settings"); Memento m = new MementoImpl(); if (settings != null) { MementoUtil.readMemento(m, settings); } descriptors.add(new ModelRootDescriptor(modelRoot.getAttributeValue("type"), m)); } rootDescriptors = descriptors.toArray(new ModelRootDescriptor[descriptors.size()]); } private String[] readArray(Element array) { List<String> res = ListSequence.fromList(new ArrayList<String>()); for (Element o : XmlUtil.children(array, "option")) { ListSequence.fromList(res).addElement(o.getAttributeValue("value")); } return ListSequence.fromList(res).toGenericArray(String.class); } }