Example #1
0
 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);
 }
Example #2
0
 private String getPath(Element modelRootElement) {
   for (Element optionChild :
       Sequence.fromIterable(XmlUtil.children(modelRootElement, "option"))) {
     if ("path".equals(optionChild.getAttributeValue("name"))
         && optionChild.getAttributeValue("value") != null) {
       return optionChild.getAttributeValue("value");
     }
   }
   return null;
 }
Example #3
0
 private Set<ModelRoot> readModelRoots(Element array) {
   Set<ModelRoot> res = SetSequence.fromSet(new HashSet<ModelRoot>());
   for (Element o : XmlUtil.children(array, "ModelRoot")) {
     String path = getPath(o);
     if (path != null) {
       SetSequence.fromSet(res).addElement(new ModelRoot(path, null));
     }
   }
   return res;
 }
  private static void saveGeneratorMappingConfigRef(
      MappingConfig_AbstractRef mappingRef, Element parentElement) {
    if (mappingRef instanceof MappingConfig_RefAllLocal) {
      parentElement.addContent(new Element("all-local-mappings"));

    } else if (mappingRef instanceof MappingConfig_RefAllGlobal) {
      parentElement.addContent(new Element("all-mappings"));

    } else if (mappingRef instanceof MappingConfig_SimpleRef) {
      XmlUtil.tagWithAttributes(
          parentElement,
          "mapping-node",
          "modelUID",
          ((MappingConfig_SimpleRef) mappingRef).getModelUID(),
          "nodeID",
          ((MappingConfig_SimpleRef) mappingRef).getNodeID());
    } else if (mappingRef instanceof MappingConfig_ExternalRef) {
      XmlUtil.tagWithAttribute(
          parentElement,
          "generator",
          "generatorUID",
          ((MappingConfig_ExternalRef) mappingRef).getGenerator().toString());
      Element extMapping = new Element("external-mapping");
      saveGeneratorMappingConfigRef(
          ((MappingConfig_ExternalRef) mappingRef).getMappingConfig(), extMapping);
      parentElement.addContent(extMapping);
    } else if (mappingRef instanceof MappingConfig_RefSet) {
      Element mappingSet = new Element("mapping-set");
      for (MappingConfig_AbstractRef mappingRefInner :
          ListSequence.fromList(((MappingConfig_RefSet) mappingRef).getMappingConfigs())) {
        Element mappingSetElement = new Element("mapping-set-element");
        saveGeneratorMappingConfigRef(mappingRefInner, mappingSetElement);
        mappingSet.addContent(mappingSetElement);
      }
      parentElement.addContent(mappingSet);
    }
  }
Example #5
0
 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 ("modelRoots".equals(optionName)) {
       ModelRootDescriptor[] cache = new ModelRootDescriptor[2];
       for (ModelRoot root : SetSequence.fromSet(readModelRoots(XmlUtil.first(ch, "set")))) {
         Memento m = new MementoImpl();
         root.save(m);
         ModelRootDescriptor descr =
             ModuleDescriptorPersistence.createDescriptor(null, m, null, cache);
         if (descr != null) {
           descriptors.add(descr);
         }
       }
     } 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()]);
 }
  public static void saveLanguageDescriptor(
      IFile file, LanguageDescriptor descriptor, MacroHelper macroHelper) {
    if (file.isReadOnly()) {
      if (LOG.isEnabledFor(Priority.ERROR)) {
        LOG.error("Cant't save " + file.getPath());
      }
      return;
    }

    Element languageElement = new Element("language");
    languageElement.setAttribute("namespace", descriptor.getNamespace());
    String uuid = descriptor.getUUID();
    if (uuid != null) {
      languageElement.setAttribute("uuid", uuid);
    }
    if (descriptor.getGenPath() != null) {
      languageElement.setAttribute(
          "generatorOutputPath", macroHelper.shrinkPath(descriptor.getGenPath()));
    }

    Element models = new Element("models");
    ModuleDescriptorPersistence.saveModelRoots(
        models, descriptor.getModelRootDescriptors(), macroHelper);
    languageElement.addContent(models);

    if (!(descriptor.getModuleFacetDescriptors().isEmpty())) {
      Element facets = new Element("facets");
      ModuleDescriptorPersistence.saveFacets(
          facets, descriptor.getModuleFacetDescriptors(), macroHelper);
      languageElement.addContent(facets);
    }

    Element accessoryModels = new Element("accessoryModels");
    for (SModelReference model : SetSequence.fromSet(descriptor.getAccessoryModels())) {
      XmlUtil.tagWithAttribute(accessoryModels, "model", "modelUID", model.toString());
    }
    languageElement.addContent(accessoryModels);

    Element generators = new Element("generators");
    for (GeneratorDescriptor generatorDescriptor :
        ListSequence.fromList(descriptor.getGenerators())) {
      GeneratorDescriptorPersistence.saveGeneratorDescriptor(
          generators, generatorDescriptor, macroHelper);
    }
    languageElement.addContent(generators);

    if (!(descriptor.getAdditionalJavaStubPaths().isEmpty())) {
      Element stubModelEntries = new Element("stubModelEntries");
      ModuleDescriptorPersistence.saveStubModelEntries(
          stubModelEntries, descriptor.getAdditionalJavaStubPaths(), macroHelper);
      languageElement.addContent(stubModelEntries);
    }

    Element sourcePath = new Element("sourcePath");
    for (String p : descriptor.getSourcePaths()) {
      XmlUtil.tagWithAttribute(sourcePath, "source", "path", macroHelper.shrinkPath(p));
    }
    languageElement.addContent(sourcePath);

    ModuleDescriptorPersistence.saveDependencies(languageElement, descriptor);

    Element extendedLanguages = new Element("extendedLanguages");
    for (SModuleReference ref : SetSequence.fromSet(descriptor.getExtendedLanguages())) {
      XmlUtil.tagWithText(extendedLanguages, "extendedLanguage", ref.toString());
    }
    languageElement.addContent(extendedLanguages);

    try {
      OutputStream os = file.openOutputStream();
      JDOMUtil.writeDocument(new Document(languageElement), os);
    } catch (Exception e) {
      if (LOG.isEnabledFor(Priority.ERROR)) {
        LOG.error("", e);
      }
    }
    ModuleDescriptorPersistence.setTimestamp(descriptor, file);
  }
Example #7
0
    private void load(File file, Element root) {
      FileMPSProject.ProjectDescriptor result_dkknya_a0a5o = this;
      final String result_dkknya_a0a0a5o = file.getName();
      result_dkknya_a0a5o.setName(result_dkknya_a0a0a5o);

      if (root == null) {
        return;
      }

      List<Element> moduleList = ListSequence.fromList(new ArrayList<Element>());
      ListSequence.fromList(moduleList)
          .addSequence(
              Sequence.fromIterable(
                  XmlUtil.children(XmlUtil.first(root, "projectSolutions"), "solutionPath")));
      ListSequence.fromList(moduleList)
          .addSequence(
              Sequence.fromIterable(
                  XmlUtil.children(XmlUtil.first(root, "projectLanguages"), "languagePath")));
      ListSequence.fromList(moduleList)
          .addSequence(
              Sequence.fromIterable(
                  XmlUtil.children(XmlUtil.first(root, "projectDevkits"), "devkitPath")));
      ListSequence.fromList(moduleList)
          .addSequence(
              Sequence.fromIterable(
                  XmlUtil.children(XmlUtil.first(root, "projectModules"), "modulePath")));
      for (Element moduleElement : ListSequence.fromList(moduleList)) {
        Path modulePath = new Path();
        Path result_dkknya_a1a9a0a5o = modulePath;
        final String result_dkknya_a0a1a9a0a5o =
            MacrosFactory.forProjectFile(FileSystem.getInstance().getFileByPath(file.getPath()))
                .expandPath(moduleElement.getAttributeValue("path"));
        result_dkknya_a1a9a0a5o.setPath(result_dkknya_a0a1a9a0a5o);
        final String result_dkknya_a1a1a9a0a5o = moduleElement.getAttributeValue("folder");
        result_dkknya_a1a9a0a5o.setMPSFolder(result_dkknya_a1a1a9a0a5o);
        result_dkknya_a0a5o.addModule(modulePath);
      }

      for (Element e :
          Sequence.fromIterable(
              XmlUtil.children(XmlUtil.first(root, "genConfs"), "genConfModels"))) {
        ModelsTestConfiguration tc = new ModelsTestConfiguration();
        tc.setName(e.getAttributeValue("name"));
        for (Element me :
            Sequence.fromIterable(XmlUtil.children(XmlUtil.first(e, "models"), "model"))) {
          tc.addModel(SModelReference.fromString(me.getAttributeValue("modelRef")));
        }
        result_dkknya_a0a5o.getTestConfigurations().add(tc);
      }

      for (Element e :
          Sequence.fromIterable(
              XmlUtil.children(XmlUtil.first(root, "genConfs"), "genConfModule"))) {
        ModuleTestConfiguration tc = new ModuleTestConfiguration();
        tc.setName(e.getAttributeValue("name"));
        String moduleRef = e.getAttributeValue("moduleRef");
        if (moduleRef != null) {
          tc.setModuleRef(ModuleReference.fromString(moduleRef));
          result_dkknya_a0a5o.getTestConfigurations().add(tc);
        }
      }
    }
  public static MappingConfig_AbstractRef loadGeneratorMappingConfigRef(
      final Element parentElement, final String genUID, boolean childOfGen) {
    if (Sequence.fromIterable(XmlUtil.children(parentElement, "all-mappings")).isNotEmpty()) {
      return new MappingConfig_RefAllGlobal();
    } else if (Sequence.fromIterable(XmlUtil.children(parentElement, "all-local-mappings"))
        .isNotEmpty()) {
      final MappingConfig_RefAllLocal local = new MappingConfig_RefAllLocal();
      if (childOfGen) {
        return local;
      }

      return new _FunctionTypes._return_P0_E0<MappingConfig_ExternalRef>() {
        public MappingConfig_ExternalRef invoke() {
          final MappingConfig_ExternalRef result_wk2vdq_a0a3a0a0e = new MappingConfig_ExternalRef();
          final SModuleReference result_wk2vdq_a0a0a3a0a0e =
              PersistenceFacade.getInstance().createModuleReference(genUID);
          result_wk2vdq_a0a3a0a0e.setGenerator(result_wk2vdq_a0a0a3a0a0e);
          final MappingConfig_AbstractRef result_wk2vdq_a1a0a3a0a0e = local;
          result_wk2vdq_a0a3a0a0e.setMappingConfig(result_wk2vdq_a1a0a3a0a0e);
          return result_wk2vdq_a0a3a0a0e;
        }
      }.invoke();
    } else if (XmlUtil.first(parentElement, "mapping-set") != null) {
      final MappingConfig_RefSet mappingSet = new MappingConfig_RefSet();
      for (Element mappingSetElement :
          Sequence.fromIterable(
              XmlUtil.children(
                  XmlUtil.first(parentElement, "mapping-set"), "mapping-set-element"))) {
        mappingSet
            .getMappingConfigs()
            .add(loadGeneratorMappingConfigRef(mappingSetElement, genUID, true));
      }

      if (childOfGen) {
        return mappingSet;
      }

      return new _FunctionTypes._return_P0_E0<MappingConfig_ExternalRef>() {
        public MappingConfig_ExternalRef invoke() {
          final MappingConfig_ExternalRef result_wk2vdq_a0a5a1a0e = new MappingConfig_ExternalRef();
          final SModuleReference result_wk2vdq_a0a0a5a1a0e =
              PersistenceFacade.getInstance().createModuleReference(genUID);
          result_wk2vdq_a0a5a1a0e.setGenerator(result_wk2vdq_a0a0a5a1a0e);
          final MappingConfig_AbstractRef result_wk2vdq_a1a0a5a1a0e = mappingSet;
          result_wk2vdq_a0a5a1a0e.setMappingConfig(result_wk2vdq_a1a0a5a1a0e);
          return result_wk2vdq_a0a5a1a0e;
        }
      }.invoke();
    } else if (XmlUtil.first(parentElement, "generator") != null) {
      // external reference
      final Element generator = XmlUtil.first(parentElement, "generator");
      return new _FunctionTypes._return_P0_E0<MappingConfig_ExternalRef>() {
        public MappingConfig_ExternalRef invoke() {
          final MappingConfig_ExternalRef result_wk2vdq_a0a2a2a0e = new MappingConfig_ExternalRef();
          final SModuleReference result_wk2vdq_a0a0a2a2a0e =
              PersistenceFacade.getInstance()
                  .createModuleReference(generator.getAttributeValue("generatorUID"));
          result_wk2vdq_a0a2a2a0e.setGenerator(result_wk2vdq_a0a0a2a2a0e);
          final MappingConfig_AbstractRef result_wk2vdq_a1a0a2a2a0e =
              loadGeneratorMappingConfigRef(
                  XmlUtil.first(parentElement, "external-mapping"),
                  generator.getAttributeValue("generatorUID"),
                  true);
          result_wk2vdq_a0a2a2a0e.setMappingConfig(result_wk2vdq_a1a0a2a2a0e);
          return result_wk2vdq_a0a2a2a0e;
        }
      }.invoke();
    } else if (XmlUtil.first(parentElement, "mapping-node") != null) {
      // simple reference
      Element mappingNode = XmlUtil.first(parentElement, "mapping-node");
      final MappingConfig_SimpleRef mapping_SimpleRef = new MappingConfig_SimpleRef();
      MappingConfig_SimpleRef result_wk2vdq_a3a3a0e = mapping_SimpleRef;
      final String result_wk2vdq_a0a3a3a0e = mappingNode.getAttributeValue("modelUID");
      result_wk2vdq_a3a3a0e.setModelUID(result_wk2vdq_a0a3a3a0e);
      final String result_wk2vdq_a1a3a3a0e = mappingNode.getAttributeValue("nodeID");
      result_wk2vdq_a3a3a0e.setNodeID(result_wk2vdq_a1a3a3a0e);

      if (childOfGen) {
        return mapping_SimpleRef;
      }

      return new _FunctionTypes._return_P0_E0<MappingConfig_ExternalRef>() {
        public MappingConfig_ExternalRef invoke() {
          final MappingConfig_ExternalRef result_wk2vdq_a0a7a3a0e = new MappingConfig_ExternalRef();
          final SModuleReference result_wk2vdq_a0a0a7a3a0e =
              PersistenceFacade.getInstance().createModuleReference(genUID);
          result_wk2vdq_a0a7a3a0e.setGenerator(result_wk2vdq_a0a0a7a3a0e);
          final MappingConfig_AbstractRef result_wk2vdq_a1a0a7a3a0e = mapping_SimpleRef;
          result_wk2vdq_a0a7a3a0e.setMappingConfig(result_wk2vdq_a1a0a7a3a0e);
          return result_wk2vdq_a0a7a3a0e;
        }
      }.invoke();
    }

    // empty?
    return new MappingConfig_AbstractRef();
  }
  public static void saveGeneratorDescriptor(
      Element languageGeneratorsElement, GeneratorDescriptor descriptor, MacroHelper macroHelper) {
    Element generator = new Element("generator");
    if (descriptor.getNamespace() != null) {
      generator.setAttribute("name", descriptor.getNamespace());
    }
    if (descriptor.getGeneratorUID() != null) {
      generator.setAttribute("generatorUID", descriptor.getGeneratorUID());
    }
    if (descriptor.getUUID() != null) {
      generator.setAttribute("uuid", descriptor.getUUID());
    }
    if (descriptor.isGenerateTemplates()) {
      generator.setAttribute(
          "generate-templates", Boolean.toString(descriptor.isGenerateTemplates()));
    }
    if (!(descriptor.isReflectiveQueries())) {
      generator.setAttribute("reflective-queries", Boolean.toString(false));
    }
    if (!(descriptor.needsOperationContext())) {
      generator.setAttribute("needs-opctx", Boolean.toString(false));
    }

    Element models = new Element("models");
    ModuleDescriptorPersistence.saveModelRoots(
        models, descriptor.getModelRootDescriptors(), macroHelper);
    generator.addContent(models);

    if (!(descriptor.getModuleFacetDescriptors().isEmpty())) {
      Element facets = new Element("facets");
      ModuleDescriptorPersistence.saveFacets(
          facets, descriptor.getModuleFacetDescriptors(), macroHelper);
      generator.addContent(facets);
    }

    // "depends on" generators
    Element extTemplates = new Element("external-templates");
    for (SModuleReference generatorReference : SetSequence.fromSet(descriptor.getDepGenerators())) {
      XmlUtil.tagWithAttribute(
          extTemplates, "generator", "generatorUID", generatorReference.toString());
    }
    generator.addContent(extTemplates);

    ModuleDescriptorPersistence.saveDependencies(generator, descriptor);

    // mapping priority rules
    Element mapPrio = new Element("mapping-priorities");
    for (MappingPriorityRule rule : ListSequence.fromList(descriptor.getPriorityRules())) {
      Element ruleElement = new Element("mapping-priority-rule");
      ruleElement.setAttribute("kind", rule.getType().getName());

      Element gpm = new Element("greater-priority-mapping");
      saveGeneratorMappingConfigRef(rule.getLeft(), gpm);
      ruleElement.addContent(gpm);

      Element lpm = new Element("lesser-priority-mapping");
      saveGeneratorMappingConfigRef(rule.getRight(), lpm);
      ruleElement.addContent(lpm);

      mapPrio.addContent(ruleElement);
    }
    generator.addContent(mapPrio);

    languageGeneratorsElement.addContent(generator);
  }