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

com.reprezen.genflow.rapidml.xsd.ResourceApiSchemaGenerator Maven / Gradle / Ivy

/**
 * Copyright © 2013, 2016 Modelsolv, Inc.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is, and remains the property
 * of ModelSolv, Inc. See the file license.html in the root directory of
 * this project for further information.
 */
package com.reprezen.genflow.rapidml.xsd;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.reprezen.genflow.api.template.IGenTemplateContext;
import com.reprezen.genflow.api.trace.GenTemplateTraceBuilder;
import com.reprezen.genflow.api.zenmodel.ZenModelExtractOutputItem;
import com.reprezen.genflow.api.zenmodel.ZenModelLocator;
import com.reprezen.genflow.rapidml.xsd.FeatureHelper;
import com.reprezen.genflow.rapidml.xsd.Helpers;
import com.reprezen.genflow.rapidml.xsd.ParamsHelper;
import com.reprezen.genflow.rapidml.xsd.ReferenceLinkHelper;
import com.reprezen.genflow.rapidml.xsd.TraceHelper;
import com.reprezen.genflow.rapidml.xsd.XMLSchemaHelper;
import com.reprezen.rapidml.CollectionResource;
import com.reprezen.rapidml.Constraint;
import com.reprezen.rapidml.DataModel;
import com.reprezen.rapidml.DataType;
import com.reprezen.rapidml.Extensible;
import com.reprezen.rapidml.Feature;
import com.reprezen.rapidml.Method;
import com.reprezen.rapidml.ObjectRealization;
import com.reprezen.rapidml.ObjectResource;
import com.reprezen.rapidml.PrimitiveProperty;
import com.reprezen.rapidml.PropertyRealization;
import com.reprezen.rapidml.ReferenceElement;
import com.reprezen.rapidml.ReferenceEmbed;
import com.reprezen.rapidml.ReferenceLink;
import com.reprezen.rapidml.ReferenceProperty;
import com.reprezen.rapidml.ReferenceTreatment;
import com.reprezen.rapidml.ResourceAPI;
import com.reprezen.rapidml.ResourceDefinition;
import com.reprezen.rapidml.ServiceDataResource;
import com.reprezen.rapidml.Structure;
import com.reprezen.rapidml.TypedMessage;
import com.reprezen.rapidml.TypedRequest;
import com.reprezen.rapidml.TypedResponse;
import com.reprezen.rapidml.ZenModel;
import com.reprezen.rapidml.util.ResourceFinder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;

@SuppressWarnings("all")
public class ResourceApiSchemaGenerator extends ZenModelExtractOutputItem {
  @Extension
  private FeatureHelper featureHelper;
  
  @Extension
  private ReferenceLinkHelper referenceLinkHelper;
  
  @Extension
  private XMLSchemaHelper xmlSchemaHelper;
  
  @Extension
  private ParamsHelper paramsHelper;
  
  @Extension
  private TraceHelper traceHelper;
  
  private ZenModelLocator locator;
  
  private ResourceFinder resourceFinder;
  
  @Override
  public void init(final IGenTemplateContext context) {
    super.init(context);
  }
  
  @Override
  public String generate(final ZenModel zenModel, final ResourceAPI api) {
    try {
      String _xblockexpression = null;
      {
        final Helpers helpers = new Helpers(this.context, zenModel);
        FeatureHelper _featureHelper = helpers.getFeatureHelper();
        this.featureHelper = _featureHelper;
        ReferenceLinkHelper _referecneLinkHelper = helpers.getReferecneLinkHelper();
        this.referenceLinkHelper = _referecneLinkHelper;
        XMLSchemaHelper _xmlSchemaHelper = helpers.getXmlSchemaHelper();
        this.xmlSchemaHelper = _xmlSchemaHelper;
        ParamsHelper _paramsHelper = helpers.getParamsHelper();
        this.paramsHelper = _paramsHelper;
        TraceHelper _traceHelper = helpers.getTraceHelper();
        this.traceHelper = _traceHelper;
        ZenModelLocator _zenModelLocator = new ZenModelLocator(zenModel);
        this.locator = _zenModelLocator;
        ResourceFinder _resourceFinder = new ResourceFinder(api);
        this.resourceFinder = _resourceFinder;
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _traceForApi = this.traceHelper.traceForApi(api);
        String _namespace = this.xmlSchemaHelper.namespace(api);
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _withProperty = _traceForApi.withProperty("namespace", _namespace);
        String _nsPrefix = this.xmlSchemaHelper.nsPrefix(api);
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _withProperty_1 = _withProperty.withProperty("namespacePrefix", _nsPrefix);
        String _locate = this.locator.locate(api);
        _withProperty_1.withPrimarySourceItem(_locate);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append(" _usedDataModels = this.xmlSchemaHelper.getUsedDataModels(api);
          boolean _hasElements = false;
          for(final DataModel dm : _usedDataModels) {
            if (!_hasElements) {
              _hasElements = true;
            } else {
              _builder.appendImmediate("", "\t");
            }
            _builder.append("\t");
            _builder.append("xmlns:");
            String _nsPrefix_1 = this.xmlSchemaHelper.nsPrefix(dm, api);
            _builder.append(_nsPrefix_1, "\t");
            _builder.append("=\"");
            String _namespace_4 = this.xmlSchemaHelper.namespace(dm);
            _builder.append(_namespace_4, "\t");
            _builder.append("\"");
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.append("\t");
        _builder.append("xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"");
        _builder.newLine();
        _builder.append("\t");
        String _generateNamespaceAdditions = this.generateNamespaceAdditions(api);
        _builder.append(_generateNamespaceAdditions, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append(">");
        _builder.newLine();
        String _generateSchemaImports = this.generateSchemaImports(api);
        _builder.append(_generateSchemaImports, "");
        _builder.newLineIfNotEmpty();
        {
          Iterable _usedDataModels_1 = this.xmlSchemaHelper.getUsedDataModels(api);
          boolean _hasElements_1 = false;
          for(final DataModel dm_1 : _usedDataModels_1) {
            if (!_hasElements_1) {
              _hasElements_1 = true;
            } else {
              _builder.appendImmediate("", "");
            }
            _builder.append("");
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.append("");
        _builder.newLine();
        {
          EList _ownedResourceDefinitions = api.getOwnedResourceDefinitions();
          boolean _hasElements_2 = false;
          for(final ResourceDefinition resource : _ownedResourceDefinitions) {
            if (!_hasElements_2) {
              _hasElements_2 = true;
            } else {
              _builder.appendImmediate("", "");
            }
            CharSequence _generateForResource = this.generateForResource(((ServiceDataResource) resource), api);
            _builder.append(_generateForResource, "");
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.append("");
        _builder.newLine();
        {
          EList _ownedResourceDefinitions_1 = api.getOwnedResourceDefinitions();
          boolean _hasElements_3 = false;
          for(final ResourceDefinition resource_1 : _ownedResourceDefinitions_1) {
            if (!_hasElements_3) {
              _hasElements_3 = true;
            } else {
              _builder.appendImmediate("", "");
            }
            {
              EList _methods = resource_1.getMethods();
              boolean _hasElements_4 = false;
              for(final Method method : _methods) {
                if (!_hasElements_4) {
                  _hasElements_4 = true;
                } else {
                  _builder.appendImmediate("", "");
                }
                _builder.append("\t\t\t\t\t");
                Object _xblockexpression_1 = null;
                {
                  this.traceHelper.setIdInTrace(method);
                  _xblockexpression_1 = null;
                }
                _builder.append(_xblockexpression_1, "\t\t\t\t\t");
                _builder.newLineIfNotEmpty();
                TypedRequest _request = method.getRequest();
                CharSequence _generateForMessage = null;
                if (_request!=null) {
                  _generateForMessage=this.generateForMessage(_request);
                }
                _builder.append(_generateForMessage, "");
                _builder.newLineIfNotEmpty();
                {
                  EList _responses = method.getResponses();
                  boolean _hasElements_5 = false;
                  for(final TypedResponse response : _responses) {
                    if (!_hasElements_5) {
                      _hasElements_5 = true;
                    } else {
                      _builder.appendImmediate("", "");
                    }
                    CharSequence _generateForMessage_1 = this.generateForMessage(response);
                    _builder.append(_generateForMessage_1, "");
                    _builder.newLineIfNotEmpty();
                  }
                }
              }
            }
          }
        }
        {
          ZenModel _zenModel_1 = this.xmlSchemaHelper.zenModel(api);
          EList _dataModels = _zenModel_1.getDataModels();
          final Function1> _function = (DataModel it) -> {
            EList _ownedDataTypes = it.getOwnedDataTypes();
            return Iterables.filter(_ownedDataTypes, Structure.class);
          };
          List> _map = ListExtensions.>map(_dataModels, _function);
          Iterable _flatten = Iterables.concat(_map);
          boolean _hasElements_6 = false;
          for(final Structure dataType : _flatten) {
            if (!_hasElements_6) {
              _hasElements_6 = true;
            } else {
              _builder.appendImmediate("", "");
            }
            CharSequence _generateForStructure = this.generateForStructure(dataType, api);
            _builder.append(_generateForStructure, "");
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.append("");
        _builder.newLine();
        _xblockexpression = _builder.toString();
      }
      return _xblockexpression;
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  private String generateNamespaceAdditions(final ResourceAPI api) {
    return "xmlns:atom=\"http://www.w3.org/2005/Atom\"";
  }
  
  private String generateSchemaImports(final ResourceAPI api) {
    return this.generateAtomImports(api);
  }
  
  private CharSequence generateForResource(final ServiceDataResource resource, final ResourceAPI api) {
    try {
      CharSequence _xblockexpression = null;
      {
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _traceForComplexType = this.traceHelper.traceForComplexType(resource);
        String _typeName = this.xmlSchemaHelper.typeName(resource);
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _withProperty = _traceForComplexType.withProperty("complexType", _typeName);
        String _rootElementName = this.xmlSchemaHelper.getRootElementName(resource);
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _withProperty_1 = _withProperty.withProperty("elementName", _rootElementName);
        String _namespace = this.xmlSchemaHelper.namespace(api);
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _withProperty_2 = _withProperty_1.withProperty("namespace", _namespace);
        String _nsPrefix = this.xmlSchemaHelper.nsPrefix(api);
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _withProperty_3 = _withProperty_2.withProperty("namespacePrefix", _nsPrefix);
        String _locate = this.locator.locate(api);
        GenTemplateTraceBuilder.GenTemplateTraceItemBuilder _withPrimarySourceItem = _withProperty_3.withPrimarySourceItem(_locate);
        String _locate_1 = this.locator.locate(resource);
        _withPrimarySourceItem.withPrimarySourceItem(_locate_1);
        StringConcatenation _builder = new StringConcatenation();
        Structure _dataType = resource.getDataType();
        CharSequence _generateResourceComplexType = this.generateResourceComplexType(_dataType, resource, api);
        _builder.append(_generateResourceComplexType, "");
        _builder.newLineIfNotEmpty();
        CharSequence _generateResourceElement = this.generateResourceElement(resource);
        _builder.append(_generateResourceElement, "");
        _builder.newLineIfNotEmpty();
        CharSequence _generateTransitionalContainersForReferenceLinks = this.generateTransitionalContainersForReferenceLinks(resource, api);
        _builder.append(_generateTransitionalContainersForReferenceLinks, "");
        _builder.newLineIfNotEmpty();
        String _name = resource.getName();
        EList _referenceTreatments = resource.getReferenceTreatments();
        CharSequence _generateContainersForReferenceEmbeds = this.generateContainersForReferenceEmbeds(_name, resource, _referenceTreatments, api);
        _builder.append(_generateContainersForReferenceEmbeds, "");
        _builder.newLineIfNotEmpty();
        _xblockexpression = _builder;
      }
      return _xblockexpression;
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  private CharSequence _generateResourceComplexType(final Structure complexType, final CollectionResource resource, final ResourceAPI api) {
    CharSequence _xblockexpression = null;
    {
      EList _referenceLinks = resource.getReferenceLinks();
      Iterable _referenceEmbeds = this.featureHelper.getReferenceEmbeds(resource);
      final Iterable elementProperties = Iterables.concat(_referenceLinks, _referenceEmbeds);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLineIfNotEmpty();
      String _generateXSDDoc = this.xmlSchemaHelper.generateXSDDoc(complexType);
      _builder.append(_generateXSDDoc, "");
      _builder.newLineIfNotEmpty();
      CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, resource, api);
      _builder.append(_generateAllBlock, "");
      _builder.newLineIfNotEmpty();
      _builder.append("");
      _builder.newLine();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
  
  private CharSequence _generateResourceComplexType(final Structure complexType, final ObjectResource resource, final ResourceAPI api) {
    CharSequence _xblockexpression = null;
    {
      EList _includedProperties = resource.getIncludedProperties();
      Iterable _filterForElements = this.filterForElements(_includedProperties);
      EList _referenceLinks = resource.getReferenceLinks();
      Iterable _referenceEmbeds = this.featureHelper.getReferenceEmbeds(resource);
      final Iterable elementProperties = Iterables.concat(_filterForElements, _referenceLinks, _referenceEmbeds);
      EList _includedProperties_1 = resource.getIncludedProperties();
      final Iterable attributeProperties = this.filterForAttributes(_includedProperties_1);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      String _generateXSDDoc = this.xmlSchemaHelper.generateXSDDoc(complexType);
      _builder.append(_generateXSDDoc, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, resource, api);
      _builder.append(_generateAllBlock, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      String _generateAttributeDecls = this.generateAttributeDecls(attributeProperties, api);
      _builder.append(_generateAttributeDecls, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("");
      _builder.newLine();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
  
  private CharSequence generateAllBlock(final Iterable properties, final EObject context, final ResourceAPI api) {
    return this.generateAllBlock(properties, context, api, null);
  }
  
  private CharSequence generateAllBlock(final Iterable properties, final EObject context, final ResourceAPI api, final Function1 special) {
    CharSequence _xifexpression = null;
    boolean _isEmpty = IterableExtensions.isEmpty(properties);
    boolean _not = (!_isEmpty);
    if (_not) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLine();
      {
        boolean _hasElements = false;
        for(final EObject prop : properties) {
          if (!_hasElements) {
            _hasElements = true;
          } else {
            _builder.appendImmediate("", "");
          }
          String _elvis = null;
          String _apply = null;
          if (special!=null) {
            _apply=special.apply(prop);
          }
          if (_apply != null) {
            _elvis = _apply;
          } else {
            String _generatePropertyDecl = this.generatePropertyDecl(prop, context, api, true);
            _elvis = _generatePropertyDecl;
          }
          _builder.append(_elvis, "");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("");
      _builder.newLine();
      _xifexpression = _builder;
    }
    return _xifexpression;
  }
  
  private CharSequence generateResourceElement(final ServiceDataResource resource) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  private CharSequence generateTransitionalContainersForReferenceLinks(final ServiceDataResource resource, final ResourceAPI api) {
    CharSequence _xblockexpression = null;
    {
      EList _referenceLinks = resource.getReferenceLinks();
      final Function1 _function = (ReferenceLink it) -> {
        return ((ReferenceTreatment) it);
      };
      final List links = ListExtensions.map(_referenceLinks, _function);
      StringConcatenation _builder = new StringConcatenation();
      {
        Iterable _containmentReferencesAtPosition = this.referenceLinkHelper.getContainmentReferencesAtPosition(links, Integer.valueOf(1));
        for(final ReferenceProperty referenceProperty : _containmentReferencesAtPosition) {
          String _generateContainmentSegment = this.generateContainmentSegment(referenceProperty, resource, api);
          _builder.append(_generateContainmentSegment, "");
          _builder.newLineIfNotEmpty();
        }
      }
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
  
  private String generateContainmentSegment(final ReferenceProperty referenceProperty, final ServiceDataResource resource, final ResourceAPI api) {
    return this.generateContainmentSegment(Collections.unmodifiableList(CollectionLiterals.newArrayList(referenceProperty)), resource, api);
  }
  
  private String generateContainmentSegment(final List path, final ServiceDataResource resource, final ResourceAPI api) {
    String _xblockexpression = null;
    {
      final Function1 _function = (ReferenceProperty it) -> {
        return null;
      };
      ReferenceProperty _findLast = IterableExtensions.findLast(path, _function);
      final Structure currentType = _findLast.getType();
      final int levelOfContainment = ((Object[])Conversions.unwrapArray(path, Object.class)).length;
      EList _ownedFeatures = currentType.getOwnedFeatures();
      Iterable _filterForElements = this.filterForElements(_ownedFeatures);
      EList _referenceLinks = resource.getReferenceLinks();
      final Function1 _function_1 = (ReferenceLink it) -> {
        return Boolean.valueOf(this.referenceLinkHelper.startsWithPath(it, path));
      };
      Iterable _filter = IterableExtensions.filter(_referenceLinks, _function_1);
      final Function1 _function_2 = (ReferenceLink it) -> {
        int _containmentDepth = this.referenceLinkHelper.getContainmentDepth(it);
        return Boolean.valueOf((_containmentDepth < (levelOfContainment + 1)));
      };
      Iterable _filter_1 = IterableExtensions.filter(_filter, _function_2);
      final Iterable elementProperties = Iterables.concat(_filterForElements, _filter_1);
      EList _ownedFeatures_1 = currentType.getOwnedFeatures();
      final Iterable attributeProperties = this.filterForAttributes(_ownedFeatures_1);
      EList _referenceLinks_1 = resource.getReferenceLinks();
      final Function1 _function_3 = (ReferenceLink it) -> {
        return ((ReferenceTreatment) it);
      };
      final List nextLevelReferences = ListExtensions.map(_referenceLinks_1, _function_3);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      final Function1 _function_4 = (EObject it) -> {
        String _switchResult = null;
        boolean _matched = false;
        if (!_matched) {
          if (it instanceof ReferenceProperty) {
            _matched=true;
            _switchResult = this.generateReferenceProperty(((Extensible)it), resource, api, path);
          }
        }
        if (!_matched) {
          _switchResult = null;
        }
        return _switchResult;
      };
      CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, resource, api, _function_4);
      _builder.append(_generateAllBlock, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      String _generateAttributeDecls = this.generateAttributeDecls(attributeProperties, api);
      _builder.append(_generateAttributeDecls, "\t");
      _builder.newLineIfNotEmpty();
      _builder.append("");
      _builder.newLine();
      {
        Iterable _containmentReferencesAtPosition = this.referenceLinkHelper.getContainmentReferencesAtPosition(nextLevelReferences, Integer.valueOf((levelOfContainment + 1)));
        for(final ReferenceProperty referenceProperty : _containmentReferencesAtPosition) {
          List _concat = this.concat(path, referenceProperty);
          String _generateContainmentSegment = this.generateContainmentSegment(_concat, resource, api);
          _builder.append(_generateContainmentSegment, "");
          _builder.newLineIfNotEmpty();
        }
      }
      _xblockexpression = _builder.toString();
    }
    return _xblockexpression;
  }
  
  private CharSequence generateForMessage(final TypedMessage message) {
    CharSequence _xifexpression = null;
    Structure _actualType = message.getActualType();
    boolean _tripleNotEquals = (_actualType != null);
    if (_tripleNotEquals) {
      CharSequence _xblockexpression = null;
      {
        final ResourceAPI api = this.getResourceAPI(message);
        StringConcatenation _builder = new StringConcatenation();
        Structure _actualType_1 = message.getActualType();
        CharSequence _generateMessageComplexType = this.generateMessageComplexType(_actualType_1, message, api);
        _builder.append(_generateMessageComplexType, "");
        _builder.newLineIfNotEmpty();
        CharSequence _generateMessageTypeElement = this.generateMessageTypeElement(message);
        _builder.append(_generateMessageTypeElement, "");
        _builder.newLineIfNotEmpty();
        CharSequence _generateTransitionalContainersForReferenceLinks = this.generateTransitionalContainersForReferenceLinks(message, api);
        _builder.append(_generateTransitionalContainersForReferenceLinks, "");
        _builder.newLineIfNotEmpty();
        String _typeName = this.xmlSchemaHelper.typeName(message);
        EList _referenceTreatments = message.getReferenceTreatments();
        CharSequence _generateContainersForReferenceEmbeds = this.generateContainersForReferenceEmbeds(_typeName, message, _referenceTreatments, api);
        _builder.append(_generateContainersForReferenceEmbeds, "");
        _builder.newLineIfNotEmpty();
        _xblockexpression = _builder;
      }
      _xifexpression = _xblockexpression;
    }
    return _xifexpression;
  }
  
  private CharSequence generateMessageComplexType(final Structure complexType, final TypedMessage message, final ResourceAPI api) {
    CharSequence _xblockexpression = null;
    {
      EList _includedProperties = message.getIncludedProperties();
      Iterable _filterForElements = this.filterForElements(_includedProperties);
      EList _referenceLinks = message.getReferenceLinks();
      Iterable _referenceEmbeds = this.featureHelper.getReferenceEmbeds(message);
      final Iterable elementProperties = Iterables.concat(_filterForElements, _referenceLinks, _referenceEmbeds);
      EList _includedProperties_1 = message.getIncludedProperties();
      final Iterable attributeProperties = this.filterForAttributes(_includedProperties_1);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLineIfNotEmpty();
      String _generateXSDDoc = this.xmlSchemaHelper.generateXSDDoc(complexType);
      _builder.append(_generateXSDDoc, "");
      _builder.newLineIfNotEmpty();
      final Function1 _function = (EObject it) -> {
        String _switchResult = null;
        boolean _matched = false;
        if (!_matched) {
          if (it instanceof ReferenceEmbed) {
            _matched=true;
            String _xblockexpression_1 = null;
            {
              ReferenceElement _referenceElement = ((ReferenceEmbed)it).getReferenceElement();
              final ReferenceProperty nextReference = ((ReferenceProperty) _referenceElement);
              String _typeName_1 = this.xmlSchemaHelper.typeName(message);
              String _extend = this.xmlSchemaHelper.extend(_typeName_1, Collections.unmodifiableList(CollectionLiterals.newArrayList(nextReference)));
              _xblockexpression_1 = this.generateNestedReference(nextReference, _extend);
            }
            _switchResult = _xblockexpression_1;
          }
        }
        if (!_matched) {
          _switchResult = null;
        }
        return _switchResult;
      };
      CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, message, api, _function);
      _builder.append(_generateAllBlock, "");
      _builder.newLineIfNotEmpty();
      String _generateAttributeDecls = this.generateAttributeDecls(attributeProperties, api);
      _builder.append(_generateAttributeDecls, "");
      _builder.newLineIfNotEmpty();
      _builder.append("");
      _builder.newLine();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
  
  private CharSequence generateMessageTypeElement(final TypedMessage message) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("");
    _builder.newLineIfNotEmpty();
    return _builder;
  }
  
  private CharSequence generateTransitionalContainersForReferenceLinks(final TypedMessage message, final ResourceAPI api) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList _referenceLinks = message.getReferenceLinks();
      final Function1 _function = (ReferenceLink it) -> {
        return ((ReferenceTreatment) it);
      };
      List _map = ListExtensions.map(_referenceLinks, _function);
      Iterable _containmentReferencesAtPosition = this.referenceLinkHelper.getContainmentReferencesAtPosition(_map, Integer.valueOf(1));
      for(final ReferenceProperty referenceProperty : _containmentReferencesAtPosition) {
        String _generateContainmentSegment = this.generateContainmentSegment(referenceProperty, message, api);
        _builder.append(_generateContainmentSegment, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  private String generateContainmentSegment(final ReferenceProperty referenceProperty, final TypedMessage message, final ResourceAPI api) {
    return this.generateContainmentSegment(Collections.unmodifiableList(CollectionLiterals.newArrayList(referenceProperty)), message, api);
  }
  
  private String generateContainmentSegment(final List path, final TypedMessage message, final ResourceAPI api) {
    String _xblockexpression = null;
    {
      final Function1 _function = (ReferenceProperty it) -> {
        return null;
      };
      ReferenceProperty _findLast = IterableExtensions.findLast(path, _function);
      final Structure currentType = _findLast.getType();
      final int levelOfContainment = ((Object[])Conversions.unwrapArray(path, Object.class)).length;
      EList _ownedFeatures = currentType.getOwnedFeatures();
      Iterable _filterForElements = this.filterForElements(_ownedFeatures);
      EList _referenceLinks = message.getReferenceLinks();
      final Function1 _function_1 = (ReferenceLink it) -> {
        return Boolean.valueOf(this.referenceLinkHelper.startsWithPath(it, path));
      };
      Iterable _filter = IterableExtensions.filter(_referenceLinks, _function_1);
      final Function1 _function_2 = (ReferenceLink it) -> {
        int _containmentDepth = this.referenceLinkHelper.getContainmentDepth(it);
        return Boolean.valueOf((_containmentDepth < (levelOfContainment + 1)));
      };
      Iterable _filter_1 = IterableExtensions.filter(_filter, _function_2);
      final Iterable elementProperties = Iterables.concat(_filterForElements, _filter_1);
      EList _ownedFeatures_1 = currentType.getOwnedFeatures();
      final Iterable attributeProperties = this.filterForAttributes(_ownedFeatures_1);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLine();
      CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, message, api);
      _builder.append(_generateAllBlock, "");
      _builder.newLineIfNotEmpty();
      String _generateAttributeDecls = this.generateAttributeDecls(attributeProperties, api);
      _builder.append(_generateAttributeDecls, "");
      _builder.newLineIfNotEmpty();
      _builder.append("");
      _builder.newLine();
      {
        EList _referenceLinks_1 = message.getReferenceLinks();
        final Function1 _function_3 = (ReferenceLink it) -> {
          return ((ReferenceTreatment) it);
        };
        List _map = ListExtensions.map(_referenceLinks_1, _function_3);
        Iterable _containmentReferencesAtPosition = this.referenceLinkHelper.getContainmentReferencesAtPosition(_map, Integer.valueOf((levelOfContainment + 1)));
        for(final ReferenceProperty referenceProperty : _containmentReferencesAtPosition) {
          List _concat = this.concat(path, referenceProperty);
          String _generateContainmentSegment = this.generateContainmentSegment(_concat, message, api);
          _builder.append(_generateContainmentSegment, "");
          _builder.newLineIfNotEmpty();
        }
      }
      _xblockexpression = _builder.toString();
    }
    return _xblockexpression;
  }
  
  private CharSequence generateContainersForReferenceEmbeds(final String name, final EObject obj, final Iterable referenceTreatments, final ResourceAPI api) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Iterable _filter = Iterables.filter(referenceTreatments, ReferenceEmbed.class);
      for(final ReferenceEmbed referenceEmbed : _filter) {
        String _generateContainersForReferenceEmbed = this.generateContainersForReferenceEmbed(referenceEmbed, name, obj, api);
        _builder.append(_generateContainersForReferenceEmbed, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  private String generateContainersForReferenceEmbed(final ReferenceEmbed referenceEmbed, final String name, final EObject obj, final ResourceAPI api) {
    String _xblockexpression = null;
    {
      final List path = this.getPathTo(referenceEmbed);
      StringConcatenation _builder = new StringConcatenation();
      CharSequence _generateEmbedSegment = this.generateEmbedSegment(path, name, obj, referenceEmbed);
      _builder.append(_generateEmbedSegment, "");
      _builder.newLineIfNotEmpty();
      {
        EList _nestedReferenceTreatments = referenceEmbed.getNestedReferenceTreatments();
        Iterable _filter = Iterables.filter(_nestedReferenceTreatments, ReferenceEmbed.class);
        for(final ReferenceEmbed childReferenceEmbed : _filter) {
          String _generateContainersForReferenceEmbed = this.generateContainersForReferenceEmbed(childReferenceEmbed, name, obj, api);
          _builder.append(_generateContainersForReferenceEmbed, "");
          _builder.newLineIfNotEmpty();
        }
      }
      _xblockexpression = _builder.toString();
    }
    return _xblockexpression;
  }
  
  private List getPathTo(final ReferenceEmbed referenceEmbed) {
    List _xblockexpression = null;
    {
      final Collection containers = Lists.newArrayList();
      final Collection references = Lists.newArrayList();
      Iterable _containmentReferences = this.referenceLinkHelper.getContainmentReferences(referenceEmbed);
      Iterables.addAll(references, _containmentReferences);
      EObject _eContainer = referenceEmbed.eContainer();
      EObject _eContainer_1 = _eContainer.eContainer();
      if ((_eContainer_1 instanceof ReferenceEmbed)) {
        EObject _eContainer_2 = referenceEmbed.eContainer();
        EObject _eContainer_3 = _eContainer_2.eContainer();
        List _pathTo = this.getPathTo(((ReferenceEmbed) _eContainer_3));
        containers.addAll(_pathTo);
      }
      ReferenceElement _referenceElement = referenceEmbed.getReferenceElement();
      references.add(((ReferenceProperty) _referenceElement));
      Iterable _concat = Iterables.concat(containers, references);
      _xblockexpression = IterableExtensions.toList(_concat);
    }
    return _xblockexpression;
  }
  
  private CharSequence generateEmbedSegment(final List path, final String baseName, final EObject obj, final ReferenceEmbed referenceEmbed) {
    CharSequence _xblockexpression = null;
    {
      ObjectRealization _linkDescriptor = referenceEmbed.getLinkDescriptor();
      EList _allIncludedProperties = _linkDescriptor.getAllIncludedProperties();
      final Function1 _function = (PropertyRealization it) -> {
        return it.getBaseProperty();
      };
      List _map = ListExtensions.map(_allIncludedProperties, _function);
      Iterable _filterForElements = this.filterForElements(_map);
      EList _nestedReferenceTreatments = referenceEmbed.getNestedReferenceTreatments();
      Iterable _filter = Iterables.filter(_nestedReferenceTreatments, ReferenceLink.class);
      EList _nestedReferenceTreatments_1 = referenceEmbed.getNestedReferenceTreatments();
      Iterable _filter_1 = Iterables.filter(_nestedReferenceTreatments_1, ReferenceEmbed.class);
      final Iterable elementProperties = Iterables.concat(_filterForElements, _filter, _filter_1);
      ObjectRealization _linkDescriptor_1 = referenceEmbed.getLinkDescriptor();
      EList _allIncludedProperties_1 = _linkDescriptor_1.getAllIncludedProperties();
      final Function1 _function_1 = (PropertyRealization it) -> {
        return it.getBaseProperty();
      };
      List _map_1 = ListExtensions.map(_allIncludedProperties_1, _function_1);
      final Iterable attributeProperties = this.filterForAttributes(_map_1);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLineIfNotEmpty();
      {
        ObjectRealization _linkDescriptor_2 = referenceEmbed.getLinkDescriptor();
        boolean _tripleNotEquals = (_linkDescriptor_2 != null);
        if (_tripleNotEquals) {
          ResourceAPI _resourceAPI = this.getResourceAPI(obj);
          final Function1 _function_2 = (EObject it) -> {
            String _switchResult = null;
            boolean _matched = false;
            if (!_matched) {
              if (it instanceof ReferenceEmbed) {
                _matched=true;
                String _xblockexpression_1 = null;
                {
                  ReferenceElement _referenceElement = ((ReferenceEmbed)it).getReferenceElement();
                  final ReferenceProperty nextSegment = ((ReferenceProperty) _referenceElement);
                  List _concat = this.concat(path, nextSegment);
                  String _extend_1 = this.xmlSchemaHelper.extend(baseName, _concat);
                  _xblockexpression_1 = this.generateNestedReference(nextSegment, _extend_1);
                }
                _switchResult = _xblockexpression_1;
              }
            }
            if (!_matched) {
              _switchResult = null;
            }
            return _switchResult;
          };
          CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, obj, _resourceAPI, _function_2);
          _builder.append(_generateAllBlock, "");
          _builder.newLineIfNotEmpty();
          ResourceAPI _resourceAPI_1 = this.getResourceAPI(obj);
          String _generateAttributeDecls = this.generateAttributeDecls(attributeProperties, _resourceAPI_1);
          _builder.append(_generateAttributeDecls, "");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("");
      _builder.newLine();
      _xblockexpression = _builder;
    }
    return _xblockexpression;
  }
  
  private String _generatePropertyDecl(final EObject prop, final EObject context, final ResourceAPI api, final boolean asElement) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("Cannot gernerate property decl for ");
    Class _class = null;
    if (prop!=null) {
      _class=prop.getClass();
    }
    _builder.append(_class, "");
    _builder.append(" in context ");
    Class _class_1 = null;
    if (context!=null) {
      _class_1=context.getClass();
    }
    _builder.append(_class_1, "");
    throw new IllegalArgumentException(_builder.toString());
  }
  
  private String _generatePropertyDecl(final PrimitiveProperty prop, final EObject context, final ResourceAPI api, final boolean asElement) {
    String _xifexpression = null;
    if (asElement) {
      String _xifexpression_1 = null;
      boolean _isMultiValued = prop.isMultiValued();
      if (_isMultiValued) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("");
        _builder.newLine();
        _xifexpression_1 = _builder.toString();
      } else {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("");
        _xifexpression_1 = _builder_1.toString();
      }
      _xifexpression = _xifexpression_1;
    } else {
      String _xblockexpression = null;
      {
        boolean _isMultiValued_1 = prop.isMultiValued();
        if (_isMultiValued_1) {
          throw new IllegalArgumentException("Cannot declare multi-valued property as a schema attribute");
        }
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("");
        _builder_2.newLineIfNotEmpty();
        _xblockexpression = _builder_2.toString();
      }
      _xifexpression = _xblockexpression;
    }
    return _xifexpression;
  }
  
  private String _generatePropertyDecl(final PropertyRealization property, final EObject context, final ResourceAPI api, final boolean asElement) {
    String _switchResult = null;
    Feature _baseProperty = property.getBaseProperty();
    boolean _matched = false;
    if (!_matched) {
      if (_baseProperty instanceof PrimitiveProperty) {
        _matched=true;
        String _xifexpression = null;
        if (asElement) {
          String _xifexpression_1 = null;
          boolean _isMultiValued = this.featureHelper.isMultiValued(property);
          if (_isMultiValued) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("");
            _builder.newLine();
            _builder.append("\t\t\t");
            _builder.append("");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("");
            _builder.newLine();
            _builder.append("");
            _builder.newLine();
            _xifexpression_1 = _builder.toString();
          } else {
            StringConcatenation _builder_1 = new StringConcatenation();
            _builder_1.append("");
            _xifexpression_1 = _builder_1.toString();
          }
          _xifexpression = _xifexpression_1;
        } else {
          String _xblockexpression = null;
          {
            boolean _isMultiValued_1 = this.featureHelper.isMultiValued(property);
            if (_isMultiValued_1) {
              throw new IllegalArgumentException("Cannot declare multi-valued property as a schema attribute");
            }
            StringConcatenation _builder_2 = new StringConcatenation();
            _builder_2.append(" _allConstraints = property.getAllConstraints();
              boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(_allConstraints);
              if (_isNullOrEmpty) {
                _builder_2.append("type=\"");
                String _typeName_2 = this.featureHelper.getTypeName(property, api);
                _builder_2.append(_typeName_2, "");
                _builder_2.append("\"");
                _builder_2.newLineIfNotEmpty();
              }
            }
            _builder_2.append("use=\"");
            String _propertyUse = this.getPropertyUse(property);
            _builder_2.append(_propertyUse, "");
            _builder_2.append("\">");
            _builder_2.newLineIfNotEmpty();
            {
              EList _allConstraints_1 = property.getAllConstraints();
              boolean _isNullOrEmpty_1 = IterableExtensions.isNullOrEmpty(_allConstraints_1);
              boolean _not = (!_isNullOrEmpty_1);
              if (_not) {
                _builder_2.append("");
                _builder_2.newLine();
                _builder_2.append("\t");
                PrimitiveProperty _basePrimitiveProperty = this.getBasePrimitiveProperty(property);
                String _typeName_3 = this.featureHelper.getTypeName(_basePrimitiveProperty, api);
                EList _allConstraints_2 = property.getAllConstraints();
                CharSequence _generateRestriction = this.xmlSchemaHelper.generateRestriction(_typeName_3, _allConstraints_2);
                _builder_2.append(_generateRestriction, "\t");
                _builder_2.newLineIfNotEmpty();
                _builder_2.append("");
                _builder_2.newLine();
              }
            }
            _builder_2.append("");
            _builder_2.newLine();
            _xblockexpression = _builder_2.toString();
          }
          _xifexpression = _xblockexpression;
        }
        _switchResult = _xifexpression;
      }
    }
    if (!_matched) {
      if (_baseProperty instanceof ReferenceProperty) {
        _matched=true;
        _switchResult = this.generateReferenceProperty(property, context, api, Collections.unmodifiableList(CollectionLiterals.newArrayList()));
      }
    }
    return _switchResult;
  }
  
  private String _generatePropertyDecl(final ReferenceLink link, final EObject context, final ResourceAPI api, final boolean asElement) {
    String _xblockexpression = null;
    {
      final ReferenceElement referenceProperty = this.referenceLinkHelper.getReferenceProperty(link);
      final ObjectRealization linkDescriptor = link.getLinkDescriptor();
      Iterable _elvis = null;
      EList _allIncludedProperties = null;
      if (linkDescriptor!=null) {
        _allIncludedProperties=linkDescriptor.getAllIncludedProperties();
      }
      List _map = null;
      if (_allIncludedProperties!=null) {
        final Function1 _function = (PropertyRealization it) -> {
          return it.getBaseProperty();
        };
        _map=ListExtensions.map(_allIncludedProperties, _function);
      }
      Iterable _primitiveProperties = null;
      if (_map!=null) {
        _primitiveProperties=this.featureHelper.getPrimitiveProperties(_map);
      }
      Iterable _filterForElements = null;
      if (_primitiveProperties!=null) {
        _filterForElements=this.filterForElements(_primitiveProperties);
      }
      if (_filterForElements != null) {
        _elvis = _filterForElements;
      } else {
        _elvis = Collections.unmodifiableList(CollectionLiterals.newArrayList());
      }
      final Iterable elementProperties = Iterables.concat(
        Collections.unmodifiableList(CollectionLiterals.newArrayList(link)), _elvis);
      Iterable _elvis_1 = null;
      EList _allIncludedProperties_1 = null;
      if (linkDescriptor!=null) {
        _allIncludedProperties_1=linkDescriptor.getAllIncludedProperties();
      }
      List _map_1 = null;
      if (_allIncludedProperties_1!=null) {
        final Function1 _function_1 = (PropertyRealization it) -> {
          return it.getBaseProperty();
        };
        _map_1=ListExtensions.map(_allIncludedProperties_1, _function_1);
      }
      Iterable _primitiveProperties_1 = null;
      if (_map_1!=null) {
        _primitiveProperties_1=this.featureHelper.getPrimitiveProperties(_map_1);
      }
      Iterable _filterForAttributes = null;
      if (_primitiveProperties_1!=null) {
        _filterForAttributes=this.filterForAttributes(_primitiveProperties_1);
      }
      if (_filterForAttributes != null) {
        _elvis_1 = _filterForAttributes;
      } else {
        _elvis_1 = Collections.unmodifiableList(CollectionLiterals.newArrayList());
      }
      final Iterable attributeProperties = _elvis_1;
      String _xifexpression = null;
      boolean _isMultiValued = referenceProperty.isMultiValued();
      if (_isMultiValued) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t\t\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t\t\t\t\t\t");
        final Function1 _function_2 = (EObject it) -> {
          String _switchResult = null;
          boolean _matched = false;
          if (!_matched) {
            if (it instanceof ReferenceLink) {
              _matched=true;
              _switchResult = this.generateAtomLink(((ReferenceLink)it));
            }
          }
          if (!_matched) {
            _switchResult = null;
          }
          return _switchResult;
        };
        CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, context, api, _function_2);
        _builder.append(_generateAllBlock, "\t\t\t\t\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t\t\t\t");
        String _generateAttributeDecls = this.generateAttributeDecls(attributeProperties, api);
        _builder.append(_generateAttributeDecls, "\t\t\t\t\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t\t\t\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("");
        _builder.newLine();
        _builder.append("");
        _builder.newLine();
        _xifexpression = _builder.toString();
      } else {
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("\t");
        _builder_1.append("");
        _builder_1.newLine();
        _builder_1.append("\t\t");
        final Function1 _function_3 = (EObject it) -> {
          String _switchResult = null;
          boolean _matched = false;
          if (!_matched) {
            if (it instanceof ReferenceLink) {
              _matched=true;
              _switchResult = this.generateAtomLink(((ReferenceLink)it));
            }
          }
          if (!_matched) {
            _switchResult = null;
          }
          return _switchResult;
        };
        CharSequence _generateAllBlock_1 = this.generateAllBlock(elementProperties, context, api, _function_3);
        _builder_1.append(_generateAllBlock_1, "\t\t");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("\t\t");
        String _generateAttributeDecls_1 = this.generateAttributeDecls(attributeProperties, api);
        _builder_1.append(_generateAttributeDecls_1, "\t\t");
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("\t");
        _builder_1.append("");
        _builder_1.newLine();
        _builder_1.append("");
        _builder_1.newLine();
        _xifexpression = _builder_1.toString();
      }
      _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
  }
  
  private String _generatePropertyDecl(final ReferenceEmbed embed, final EObject context, final ResourceAPI api, final boolean asElement) {
    String _xblockexpression = null;
    {
      String _switchResult = null;
      boolean _matched = false;
      if (!_matched) {
        if (context instanceof TypedMessage) {
          _matched=true;
          _switchResult = this.xmlSchemaHelper.typeName(context);
        }
      }
      if (!_matched) {
        if (context instanceof ServiceDataResource) {
          _matched=true;
          _switchResult = ((ServiceDataResource)context).getName();
        }
      }
      final String baseName = _switchResult;
      ReferenceElement _referenceElement = embed.getReferenceElement();
      final String complexTypeName = this.xmlSchemaHelper.extend(baseName, Collections.unmodifiableList(CollectionLiterals.newArrayList(_referenceElement)));
      ReferenceElement _referenceElement_1 = embed.getReferenceElement();
      _xblockexpression = this.generateNestedReference(_referenceElement_1, complexTypeName);
    }
    return _xblockexpression;
  }
  
  private String _generatePropertyDecl(final ReferenceProperty prop, final EObject context, final ResourceAPI api, final boolean asElement) {
    return this.generateReferenceProperty(prop, context, api, Collections.unmodifiableList(CollectionLiterals.newArrayList()));
  }
  
  private String _generateReferenceProperty(final PropertyRealization referenceProperty, final ServiceDataResource resource, final ResourceAPI api, final List path) {
    String _xifexpression = null;
    ReferenceProperty _baseReferenceProperty = this.getBaseReferenceProperty(referenceProperty);
    boolean _isPropertyOverridenByReferenceLink = this.referenceLinkHelper.isPropertyOverridenByReferenceLink(_baseReferenceProperty, resource, path);
    if (_isPropertyOverridenByReferenceLink) {
      String _typeName = this.xmlSchemaHelper.typeName(resource);
      ReferenceProperty _baseReferenceProperty_1 = this.getBaseReferenceProperty(referenceProperty);
      List _concat = this.concat(path, _baseReferenceProperty_1);
      String _extend = this.xmlSchemaHelper.extend(_typeName, _concat);
      _xifexpression = this.generateContainmentProperty(referenceProperty, _extend);
    }
    return _xifexpression;
  }
  
  private String _generateReferenceProperty(final ReferenceProperty referenceProperty, final ServiceDataResource resource, final ResourceAPI api, final List path) {
    String _xifexpression = null;
    boolean _isPropertyOverridenByReferenceLink = this.referenceLinkHelper.isPropertyOverridenByReferenceLink(referenceProperty, resource, path);
    if (_isPropertyOverridenByReferenceLink) {
      String _typeName = this.xmlSchemaHelper.typeName(resource);
      List _concat = this.concat(path, referenceProperty);
      String _extend = this.xmlSchemaHelper.extend(_typeName, _concat);
      _xifexpression = this.generateNestedReference(referenceProperty, _extend);
    }
    return _xifexpression;
  }
  
  private String _generateReferenceProperty(final ReferenceProperty referenceProperty, final TypedMessage message, final ResourceAPI api, final List path) {
    String _xifexpression = null;
    boolean _isPropertyOverridenByReferenceLink = this.referenceLinkHelper.isPropertyOverridenByReferenceLink(referenceProperty, message, path);
    if (_isPropertyOverridenByReferenceLink) {
      String _typeName = this.xmlSchemaHelper.typeName(message);
      List _concat = this.concat(path, referenceProperty);
      String _extend = this.xmlSchemaHelper.extend(_typeName, _concat);
      _xifexpression = this.generateNestedReference(referenceProperty, _extend);
    }
    return _xifexpression;
  }
  
  private String generateNestedReference(final ReferenceElement referenceElement, final String typeName) {
    String _xifexpression = null;
    boolean _isMultiValued = referenceElement.isMultiValued();
    boolean _not = (!_isMultiValued);
    if (_not) {
      _xifexpression = this.generateSimpleNestedReference(referenceElement, typeName);
    } else {
      _xifexpression = this.generateMultiNestedReference(referenceElement, typeName);
    }
    return _xifexpression;
  }
  
  private String generateSimpleNestedReference(final ReferenceElement referenceElement, final String typeName) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("");
    _builder.newLineIfNotEmpty();
    return _builder.toString();
  }
  
  private String generateMultiNestedReference(final ReferenceElement referenceElement, final String typeName) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("");
    _builder.newLine();
    return _builder.toString();
  }
  
  private String generateContainmentProperty(final PropertyRealization property, final String typeName) {
    String _xifexpression = null;
    boolean _isMultiValued = this.featureHelper.isMultiValued(property);
    boolean _not = (!_isMultiValued);
    if (_not) {
      _xifexpression = this.generateSimpleContainmentProperty(property, typeName);
    } else {
      _xifexpression = this.generateMultiContainmentProperty(property, typeName);
    }
    return _xifexpression;
  }
  
  private String generateSimpleContainmentProperty(final PropertyRealization property, final String typeName) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("");
    _builder.newLineIfNotEmpty();
    return _builder.toString();
  }
  
  private String generateMultiContainmentProperty(final PropertyRealization property, final String typeName) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("");
    _builder.newLine();
    _builder.append("");
    _builder.newLine();
    return _builder.toString();
  }
  
  private String generateAtomImports(final ResourceAPI api) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("");
    _builder.newLine();
    return _builder.toString();
  }
  
  private String generateAtomLink(final ReferenceLink referenceLink) {
    String _xifexpression = null;
    ResourceDefinition _targetResource = referenceLink.getTargetResource();
    boolean _tripleNotEquals = (_targetResource != null);
    if (_tripleNotEquals) {
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("");
      _builder.newLine();
      _xifexpression = _builder.toString();
    }
    return _xifexpression;
  }
  
  private String _generateReferenceProperty(final PropertyRealization referenceProperty, final TypedMessage message, final ResourceAPI api, final List path) {
    String _xifexpression = null;
    ReferenceProperty _baseReferenceProperty = this.getBaseReferenceProperty(referenceProperty);
    boolean _isPropertyOverridenByReferenceLink = this.referenceLinkHelper.isPropertyOverridenByReferenceLink(_baseReferenceProperty, message, path);
    if (_isPropertyOverridenByReferenceLink) {
      String _typeName = this.xmlSchemaHelper.typeName(message);
      ReferenceProperty _baseReferenceProperty_1 = this.getBaseReferenceProperty(referenceProperty);
      List _concat = this.concat(path, _baseReferenceProperty_1);
      String _extend = this.xmlSchemaHelper.extend(_typeName, _concat);
      _xifexpression = this.generateContainmentProperty(referenceProperty, _extend);
    }
    return _xifexpression;
  }
  
  private String getPropertyUse(final PropertyRealization property) {
    String _xifexpression = null;
    boolean _isRequired = this.featureHelper.isRequired(property);
    if (_isRequired) {
      _xifexpression = "required";
    } else {
      _xifexpression = "optional";
    }
    return _xifexpression;
  }
  
  private CharSequence generateForStructure(final Structure structure, final ResourceAPI api) {
    CharSequence _xifexpression = null;
    ServiceDataResource _findResource = this.resourceFinder.findResource(structure, true);
    boolean _tripleEquals = (_findResource == null);
    if (_tripleEquals) {
      CharSequence _xblockexpression = null;
      {
        EList _ownedFeatures = structure.getOwnedFeatures();
        final Function1 _function = (Feature it) -> {
          return Boolean.valueOf(this.featureHelper.isPrimitiveProperty(it));
        };
        Iterable _filter = IterableExtensions.filter(_ownedFeatures, _function);
        final Iterable elementProperties = this.filterForElements(_filter);
        EList _ownedFeatures_1 = structure.getOwnedFeatures();
        final Iterable attrProperties = this.filterForAttributes(_ownedFeatures_1);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        String _generateXSDDoc = this.xmlSchemaHelper.generateXSDDoc(structure);
        _builder.append(_generateXSDDoc, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        CharSequence _generateAllBlock = this.generateAllBlock(elementProperties, structure, api);
        _builder.append(_generateAllBlock, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        String _generateAttributeDecls = this.generateAttributeDecls(attrProperties, api);
        _builder.append(_generateAttributeDecls, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("");
        _builder.newLine();
        _xblockexpression = _builder;
      }
      _xifexpression = _xblockexpression;
    }
    return _xifexpression;
  }
  
  private String _generateAttributeDecls(final ReferenceEmbed embed, final ResourceAPI api) {
    ObjectRealization _linkDescriptor = embed.getLinkDescriptor();
    return this.generateAttributeDecls(_linkDescriptor, api);
  }
  
  private String _generateAttributeDecls(final ObjectRealization objectRealization, final ResourceAPI api) {
    EList _allIncludedProperties = objectRealization.getAllIncludedProperties();
    Iterable _primitiveSingleProperties = this.featureHelper.getPrimitiveSingleProperties(_allIncludedProperties);
    return this.generateAttributeDecls(_primitiveSingleProperties, api);
  }
  
  private String _generateAttributeDecls(final Iterable properties, final ResourceAPI api) {
    StringConcatenation _builder = new StringConcatenation();
    {
      boolean _hasElements = false;
      for(final EObject property : properties) {
        if (!_hasElements) {
          _hasElements = true;
        } else {
          _builder.appendImmediate("", "");
        }
        String _generatePropertyDecl = this.generatePropertyDecl(property, api, api, false);
        _builder.append(_generatePropertyDecl, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder.toString();
  }
  
  private ReferenceProperty getBaseReferenceProperty(final PropertyRealization property) {
    Feature _baseProperty = property.getBaseProperty();
    return ((ReferenceProperty) _baseProperty);
  }
  
  private PrimitiveProperty getBasePrimitiveProperty(final PropertyRealization property) {
    Feature _baseProperty = property.getBaseProperty();
    return ((PrimitiveProperty) _baseProperty);
  }
  
  private ResourceAPI _getResourceAPI(final TypedMessage message) {
    Method _eContainer = this.xmlSchemaHelper.getEContainer(message, Method.class);
    ResourceDefinition _containingResourceDefinition = _eContainer.getContainingResourceDefinition();
    return this.getResourceAPI(_containingResourceDefinition);
  }
  
  private ResourceAPI _getResourceAPI(final ResourceDefinition resource) {
    EObject _eContainer = resource.eContainer();
    return ((ResourceAPI) _eContainer);
  }
  
  private  List concat(final List list, final T value) {
    final ArrayList copy = Lists.newArrayList(list);
    copy.add(value);
    return copy;
  }
  
  private  Iterable filterForElements(final Iterable properties) {
    final Function1 _function = (T it) -> {
      boolean _or = false;
      boolean _eltStyle = this.paramsHelper.eltStyle();
      if (_eltStyle) {
        _or = true;
      } else {
        boolean _isAttributeEligible = this.isAttributeEligible(it);
        boolean _not = (!_isAttributeEligible);
        _or = _not;
      }
      return Boolean.valueOf(_or);
    };
    Iterable _filter = IterableExtensions.filter(properties, _function);
    final Function1 _function_1 = (T it) -> {
      return ((EObject) it);
    };
    return IterableExtensions.map(_filter, _function_1);
  }
  
  private  Iterable filterForAttributes(final Iterable properties) {
    final Function1 _function = (T it) -> {
      boolean _and = false;
      boolean _attrStyle = this.paramsHelper.attrStyle();
      if (!_attrStyle) {
        _and = false;
      } else {
        boolean _isAttributeEligible = this.isAttributeEligible(it);
        _and = _isAttributeEligible;
      }
      return Boolean.valueOf(_and);
    };
    Iterable _filter = IterableExtensions.filter(properties, _function);
    final Function1 _function_1 = (T it) -> {
      return ((EObject) it);
    };
    return IterableExtensions.map(_filter, _function_1);
  }
  
  private boolean isAttributeEligible(final EObject property) {
    boolean _switchResult = false;
    boolean _matched = false;
    if (!_matched) {
      if (property instanceof Feature) {
        _matched=true;
        boolean _and = false;
        boolean _isPrimitiveProperty = this.featureHelper.isPrimitiveProperty(((Feature)property));
        if (!_isPrimitiveProperty) {
          _and = false;
        } else {
          boolean _isSingleValued = this.featureHelper.isSingleValued(((Feature)property));
          _and = _isSingleValued;
        }
        _switchResult = _and;
      }
    }
    if (!_matched) {
      if (property instanceof PropertyRealization) {
        _matched=true;
        boolean _and = false;
        Feature _baseProperty = ((PropertyRealization)property).getBaseProperty();
        boolean _isPrimitiveProperty = this.featureHelper.isPrimitiveProperty(_baseProperty);
        if (!_isPrimitiveProperty) {
          _and = false;
        } else {
          boolean _isSingleValued = this.featureHelper.isSingleValued(((PropertyRealization)property));
          _and = _isSingleValued;
        }
        _switchResult = _and;
      }
    }
    if (!_matched) {
      throw new IllegalArgumentException();
    }
    return _switchResult;
  }
  
  private CharSequence generateResourceComplexType(final Structure complexType, final ServiceDataResource resource, final ResourceAPI api) {
    if (resource instanceof CollectionResource) {
      return _generateResourceComplexType(complexType, (CollectionResource)resource, api);
    } else if (resource instanceof ObjectResource) {
      return _generateResourceComplexType(complexType, (ObjectResource)resource, api);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(complexType, resource, api).toString());
    }
  }
  
  private String generatePropertyDecl(final EObject prop, final EObject context, final ResourceAPI api, final boolean asElement) {
    if (prop instanceof PrimitiveProperty) {
      return _generatePropertyDecl((PrimitiveProperty)prop, context, api, asElement);
    } else if (prop instanceof PropertyRealization) {
      return _generatePropertyDecl((PropertyRealization)prop, context, api, asElement);
    } else if (prop instanceof ReferenceEmbed) {
      return _generatePropertyDecl((ReferenceEmbed)prop, context, api, asElement);
    } else if (prop instanceof ReferenceLink) {
      return _generatePropertyDecl((ReferenceLink)prop, context, api, asElement);
    } else if (prop instanceof ReferenceProperty) {
      return _generatePropertyDecl((ReferenceProperty)prop, context, api, asElement);
    } else if (prop != null) {
      return _generatePropertyDecl(prop, context, api, asElement);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(prop, context, api, asElement).toString());
    }
  }
  
  private String generateReferenceProperty(final Extensible referenceProperty, final EObject resource, final ResourceAPI api, final List path) {
    if (referenceProperty instanceof PropertyRealization
         && resource instanceof ServiceDataResource) {
      return _generateReferenceProperty((PropertyRealization)referenceProperty, (ServiceDataResource)resource, api, path);
    } else if (referenceProperty instanceof ReferenceProperty
         && resource instanceof ServiceDataResource) {
      return _generateReferenceProperty((ReferenceProperty)referenceProperty, (ServiceDataResource)resource, api, path);
    } else if (referenceProperty instanceof PropertyRealization
         && resource instanceof TypedMessage) {
      return _generateReferenceProperty((PropertyRealization)referenceProperty, (TypedMessage)resource, api, path);
    } else if (referenceProperty instanceof ReferenceProperty
         && resource instanceof TypedMessage) {
      return _generateReferenceProperty((ReferenceProperty)referenceProperty, (TypedMessage)resource, api, path);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(referenceProperty, resource, api, path).toString());
    }
  }
  
  private String generateAttributeDecls(final Object embed, final ResourceAPI api) {
    if (embed instanceof ReferenceEmbed) {
      return _generateAttributeDecls((ReferenceEmbed)embed, api);
    } else if (embed instanceof ObjectRealization) {
      return _generateAttributeDecls((ObjectRealization)embed, api);
    } else if (embed instanceof Iterable) {
      return _generateAttributeDecls((Iterable)embed, api);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(embed, api).toString());
    }
  }
  
  private ResourceAPI getResourceAPI(final EObject resource) {
    if (resource instanceof ResourceDefinition) {
      return _getResourceAPI((ResourceDefinition)resource);
    } else if (resource instanceof TypedMessage) {
      return _getResourceAPI((TypedMessage)resource);
    } else {
      throw new IllegalArgumentException("Unhandled parameter types: " +
        Arrays.asList(resource).toString());
    }
  }
}