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

io.joynr.generator.interfaces.InterfaceSubscriptionTemplate Maven / Gradle / Ivy

There is a newer version: 0.9.3
Show newest version
package io.joynr.generator.interfaces;

import com.google.inject.Inject;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import java.util.TreeSet;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FInterface;

@SuppressWarnings("all")
public class InterfaceSubscriptionTemplate {
  @Inject
  @Extension
  private JoynrJavaGeneratorExtensions _joynrJavaGeneratorExtensions;
  
  @Inject
  @Extension
  private TemplateBase _templateBase;
  
  public CharSequence generate(final FInterface serviceInterface) {
    CharSequence _xblockexpression = null;
    {
      final String interfaceName = this._joynrJavaGeneratorExtensions.joynrName(serviceInterface);
      final String subscriptionClassName = (interfaceName + "SubscriptionInterface");
      final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, ".");
      StringConcatenation _builder = new StringConcatenation();
      CharSequence _warning = this._templateBase.warning();
      _builder.append(_warning, "");
      _builder.newLineIfNotEmpty();
      _builder.append("package ");
      _builder.append(packagePath, "");
      _builder.append(";\t\t\t");
      _builder.newLineIfNotEmpty();
      _builder.append("import com.fasterxml.jackson.core.type.TypeReference;");
      _builder.newLine();
      _builder.newLine();
      _builder.append("import java.util.List;");
      _builder.newLine();
      _builder.newLine();
      _builder.append("import io.joynr.dispatcher.rpc.JoynrSubscriptionInterface;");
      _builder.newLine();
      _builder.append("import io.joynr.dispatcher.rpc.annotation.JoynrRpcSubscription;");
      _builder.newLine();
      _builder.append("import io.joynr.pubsub.subscription.SubscriptionListener;");
      _builder.newLine();
      _builder.append("import io.joynr.pubsub.SubscriptionQos;");
      _builder.newLine();
      _builder.newLine();
      _builder.newLine();
      {
        Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(serviceInterface);
        for(final String datatype : _requiredIncludesFor) {
          _builder.append("import ");
          _builder.append(datatype, "");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      _builder.append("//TODO: Only include the necessary imports in the xtend template. This needs to be checked depending on the fibex. ");
      _builder.newLine();
      _builder.append("@SuppressWarnings(\"unused\")");
      _builder.newLine();
      _builder.newLine();
      _builder.append("public interface ");
      _builder.append(subscriptionClassName, "");
      _builder.append(" extends JoynrSubscriptionInterface, ");
      _builder.append(interfaceName, "");
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      TreeSet _treeSet = new TreeSet();
      final TreeSet attrTypeset = _treeSet;
      _builder.newLineIfNotEmpty();
      {
        EList _attributes = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
        for(final FAttribute attribute : _attributes) {
          String _mappedDatatypeOrList = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute);
          boolean repl = attrTypeset.add(_mappedDatatypeOrList);
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      {
        for(final String attributeType : attrTypeset) {
          _builder.append("public static class ");
          String _tokenTypeForArrayType = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType);
          _builder.append(_tokenTypeForArrayType, "");
          _builder.append("Reference extends TypeReference<");
          _builder.append(attributeType, "");
          _builder.append("> {}");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.newLine();
      {
        EList _attributes_1 = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
        for(final FAttribute attribute_1 : _attributes_1) {
          String attributeName = this._joynrJavaGeneratorExtensions.joynrName(attribute_1);
          _builder.newLineIfNotEmpty();
          String _mappedDatatypeOrList_1 = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute_1);
          String attributeType_1 = this._joynrJavaGeneratorExtensions.getObjectDataTypeForPlainType(_mappedDatatypeOrList_1);
          _builder.append(" ");
          _builder.newLineIfNotEmpty();
          {
            boolean _isReadable = this._joynrJavaGeneratorExtensions.isReadable(attribute_1);
            if (_isReadable) {
              _builder.append("\t");
              _builder.append("@JoynrRpcSubscription(attributeName = \"");
              _builder.append(attributeName, "	");
              _builder.append("\", attributeType = ");
              String _tokenTypeForArrayType_1 = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType_1);
              _builder.append(_tokenTypeForArrayType_1, "	");
              _builder.append("Reference.class)\t\t");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("public String subscribeTo");
              String _firstUpper = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper, "	");
              _builder.append("(SubscriptionListener<");
              _builder.append(attributeType_1, "	");
              _builder.append("> listener, SubscriptionQos subscriptionQos);");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.newLine();
              _builder.append("\t");
              _builder.append("//TODO is the app allowed to specify the subscriptionId?");
              _builder.newLine();
              _builder.append("\t");
              _builder.append("@JoynrRpcSubscription(attributeName = \"");
              _builder.append(attributeName, "	");
              _builder.append("\", attributeType = ");
              String _tokenTypeForArrayType_2 = this._joynrJavaGeneratorExtensions.getTokenTypeForArrayType(attributeType_1);
              _builder.append(_tokenTypeForArrayType_2, "	");
              _builder.append("Reference.class)\t\t");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.append("public String subscribeTo");
              String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper_1, "	");
              _builder.append("(SubscriptionListener<");
              _builder.append(attributeType_1, "	");
              _builder.append("> listener, SubscriptionQos subscriptionQos, String subscriptionId);");
              _builder.newLineIfNotEmpty();
              _builder.append("\t");
              _builder.newLine();
              _builder.append("\t");
              _builder.append("public void unsubscribeFrom");
              String _firstUpper_2 = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper_2, "	");
              _builder.append("(String subscriptionId);");
              _builder.newLineIfNotEmpty();
            }
          }
        }
      }
      _builder.newLine();
      _builder.append("}");
      _builder.newLine();
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy