All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.reprezen.genflow.rapidml.wadl.xtend.TraceHelper Maven / Gradle / Ivy

The newest version!
package com.reprezen.genflow.rapidml.wadl.xtend;

import com.google.common.collect.Maps;
import com.reprezen.genflow.api.source.ILocator;
import com.reprezen.genflow.api.template.IGenTemplateContext;
import com.reprezen.genflow.api.trace.GenTemplateTrace;
import com.reprezen.genflow.api.trace.GenTemplateTraceItem;
import com.reprezen.genflow.api.trace.GenTemplateTraceUtils;
import com.reprezen.genflow.api.zenmodel.ZenModelLocator;
import com.reprezen.rapidml.ResourceAPI;
import com.reprezen.rapidml.ResourceDefinition;
import com.reprezen.rapidml.ZenModel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

@SuppressWarnings("all")
public class TraceHelper {
  private final IGenTemplateContext context;
  
  private final ILocator locator;
  
  private final GenTemplateTrace xsdTrace;
  
  private final Map namesItems = Maps.newHashMap();
  
  private final Map apiItems = Maps.newHashMap();
  
  public TraceHelper(final IGenTemplateContext context, final ZenModel model) {
    try {
      this.context = context;
      ZenModelLocator _zenModelLocator = new ZenModelLocator(model);
      this.locator = _zenModelLocator;
      this.xsdTrace = context.getPrerequisiteTrace("xsdGenerator");
      List _traceItemsOfType = GenTemplateTraceUtils.getTraceItemsOfType(this.xsdTrace, "namesInSchema");
      for (final GenTemplateTraceItem item : _traceItemsOfType) {
        this.namesItems.put(item.getLocator(), item);
      }
      EList _resourceAPIs = model.getResourceAPIs();
      for (final ResourceAPI api : _resourceAPIs) {
        this.apiItems.put(api, GenTemplateTraceUtils.getTraceItem(this.xsdTrace, "resourceAPI", "sourceData", this.locator.locate(api)));
      }
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  public String getTypeName(final EObject obj) {
    return this.namesProperty(obj, "typeName");
  }
  
  public String getRootElementName(final EObject obj) {
    return this.namesProperty(obj, "rootElementName");
  }
  
  public String getElementName(final EObject obj) {
    return this.namesProperty(obj, "elementName");
  }
  
  public String getListElementName(final EObject obj) {
    return this.namesProperty(obj, "listElementName");
  }
  
  public String getListItemElementName(final EObject obj) {
    return this.namesProperty(obj, "listItemElementName");
  }
  
  public String getAttributeName(final EObject obj) {
    return this.namesProperty(obj, "attributeName");
  }
  
  public String getIdInTrace(final EObject obj) {
    return this.namesProperty(obj, "id");
  }
  
  public String namesProperty(final EObject obj, final String property) {
    try {
      GenTemplateTraceItem _get = this.namesItems.get(this.locator.locate(obj));
      Map _properties = null;
      if (_get!=null) {
        _properties=_get.getProperties();
      }
      String _get_1 = null;
      if (_properties!=null) {
        _get_1=_properties.get(property);
      }
      return _get_1;
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  public String getXsdFilePath(final ResourceAPI resourceAPI) {
    try {
      final GenTemplateTraceItem item = GenTemplateTraceUtils.getTraceItem(this.xsdTrace, "file", "sourceData", this.locator.locate(resourceAPI));
      final Path outDir = Paths.get(this.context.getOutputDirectory().getAbsolutePath());
      final Path file = Paths.get(item.getOutputFile().getAbsolutePath());
      return IterableExtensions.join(outDir.relativize(file), "/");
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  public String getNsPrefix(final ResourceAPI resourceAPI) {
    return this.apiItems.get(resourceAPI).getProperties().get("namespacePrefix");
  }
  
  public String getNamespace(final ResourceAPI resourceAPI) {
    return this.apiItems.get(resourceAPI).getProperties().get("namespace");
  }
  
  public String getComplexTypeQName(final ResourceDefinition resource) {
    String _xblockexpression = null;
    {
      EObject _eContainer = resource.eContainer();
      final ResourceAPI api = ((ResourceAPI) _eContainer);
      String _nsPrefix = this.getNsPrefix(api);
      String _plus = (_nsPrefix + ":");
      String _typeName = this.getTypeName(resource);
      _xblockexpression = (_plus + _typeName);
    }
    return _xblockexpression;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy