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

io.joynr.generator.provider.InterfaceProviderImplTemplate Maven / Gradle / Ivy

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

import com.google.common.base.Objects;
import com.google.inject.Inject;
import io.joynr.generator.util.JoynrJavaGeneratorExtensions;
import io.joynr.generator.util.TemplateBase;
import java.util.Iterator;
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.IterableExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.franca.core.franca.FArgument;
import org.franca.core.franca.FAttribute;
import org.franca.core.franca.FEnumerationType;
import org.franca.core.franca.FEnumerator;
import org.franca.core.franca.FInterface;
import org.franca.core.franca.FMethod;
import org.franca.core.franca.FTypeRef;

@SuppressWarnings("all")
public class InterfaceProviderImplTemplate {
  @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);
      String _plus = ("Default" + interfaceName);
      final String className = (_plus + "Provider");
      final String abstractProviderName = (interfaceName + "AbstractProvider");
      final String packagePath = this._joynrJavaGeneratorExtensions.getPackagePathWithJoynrPrefix(serviceInterface, ".");
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("\t\t");
      CharSequence _warning = this._templateBase.warning();
      _builder.append(_warning, "		");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("package ");
      _builder.append(packagePath, "		");
      _builder.append(";");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.append("import java.util.List;");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("import java.util.ArrayList;");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("import java.util.UUID;");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("import com.google.inject.Singleton;");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("import org.slf4j.Logger;");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("import org.slf4j.LoggerFactory;");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("import ");
      String _joynTypePackagePrefix = this._joynrJavaGeneratorExtensions.getJoynTypePackagePrefix();
      _builder.append(_joynTypePackagePrefix, "		");
      _builder.append(".types.ProviderQos;");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t");
      _builder.newLine();
      {
        Iterable _requiredIncludesFor = this._joynrJavaGeneratorExtensions.getRequiredIncludesFor(serviceInterface);
        for(final String datatype : _requiredIncludesFor) {
          _builder.append("\t\t");
          _builder.append("import ");
          _builder.append(datatype, "		");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        }
      }
      _builder.append("//The current generator is not able to check wether some of the imports are acutally necessary for this specific interface.");
      _builder.newLine();
      _builder.append("//Therefore some imports migth be unused in this version of the interface.");
      _builder.newLine();
      _builder.append("//To prevent warnings @SuppressWarnings(\"unused\") is being used. ");
      _builder.newLine();
      _builder.append("//To prevent warnings about an unnecessary SuppressWarnings we have to import something that is not used. (e.g. TreeSet)");
      _builder.newLine();
      _builder.append("import java.util.TreeSet;");
      _builder.newLine();
      _builder.append("@SuppressWarnings(\"unused\")");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("@Singleton");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("public class ");
      _builder.append(className, "		");
      _builder.append(" extends ");
      _builder.append(abstractProviderName, "		");
      _builder.append(" {");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t\t");
      _builder.append("private static final Logger logger = LoggerFactory.getLogger(");
      _builder.append(className, "			");
      _builder.append(".class);");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t\t    ");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("public ");
      _builder.append(className, "			");
      _builder.append("() {\t\t\t\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t\t\t\t");
      _builder.append("// default uses a priority that is the current time, causing arbitration to the last started instance");
      _builder.newLine();
      _builder.append("\t\t\t\t");
      _builder.append("//providerQos.put(ArbitrationConstants.PRIORITY_PARAMETER, \"\" + System.currentTimeMillis());");
      _builder.newLine();
      _builder.append("\t\t\t\t");
      _builder.append("providerQos.setPriority(System.currentTimeMillis());");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("}\t");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t\t");
      _builder.newLine();
      {
        EList _attributes = this._joynrJavaGeneratorExtensions.getAttributes(serviceInterface);
        for(final FAttribute attribute : _attributes) {
          _builder.append("\t\t");
          _builder.append("\t");
          final String attributeName = this._joynrJavaGeneratorExtensions.joynrName(attribute);
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("\t");
          final String attributeType = this._joynrJavaGeneratorExtensions.getMappedDatatypeOrList(attribute);
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.newLine();
          {
            boolean _isReadable = this._joynrJavaGeneratorExtensions.isReadable(attribute);
            if (_isReadable) {
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("@Override");
              _builder.newLine();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("public ");
              _builder.append(attributeType, "			");
              _builder.append(" get");
              String _firstUpper = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper, "			");
              _builder.append("() {");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("\t");
              _builder.append("return ");
              _builder.append(attributeName, "				");
              _builder.append(";");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("}");
              _builder.newLine();
            }
          }
          _builder.append("\t\t");
          _builder.newLine();
          {
            boolean _isWritable = this._joynrJavaGeneratorExtensions.isWritable(attribute);
            if (_isWritable) {
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("@Override");
              _builder.newLine();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("public void set");
              String _firstUpper_1 = StringExtensions.toFirstUpper(attributeName);
              _builder.append(_firstUpper_1, "			");
              _builder.append("(");
              _builder.append(attributeType, "			");
              _builder.append(" ");
              _builder.append(attributeName, "			");
              _builder.append(") {");
              _builder.newLineIfNotEmpty();
              {
                boolean _isNotifiable = this._joynrJavaGeneratorExtensions.isNotifiable(attribute);
                if (_isNotifiable) {
                  _builder.append("\t\t");
                  _builder.append("\t");
                  _builder.append("\t");
                  _builder.append("super.");
                  String _firstLower = StringExtensions.toFirstLower(attributeName);
                  _builder.append(_firstLower, "				");
                  _builder.append("Changed(");
                  _builder.append(attributeName, "				");
                  _builder.append(");");
                  _builder.newLineIfNotEmpty();
                }
              }
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("\t");
              _builder.append("this.");
              _builder.append(attributeName, "				");
              _builder.append(" = ");
              _builder.append(attributeName, "				");
              _builder.append(";");
              _builder.newLineIfNotEmpty();
              _builder.append("\t\t");
              _builder.append("\t");
              _builder.append("}");
              _builder.newLine();
            }
          }
        }
      }
      _builder.append("\t\t");
      _builder.newLine();
      _builder.append("\t\t\t\t");
      _builder.newLine();
      {
        EList _methods = this._joynrJavaGeneratorExtensions.getMethods(serviceInterface);
        for(final FMethod method : _methods) {
          _builder.append("\t\t");
          final String methodName = this._joynrJavaGeneratorExtensions.joynrName(method);
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          final Iterable outputParameters = this._joynrJavaGeneratorExtensions.getOutputParameters(method);
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("\t");
          Iterable _mapOutputParameters = this._joynrJavaGeneratorExtensions.mapOutputParameters(outputParameters);
          Iterator _iterator = _mapOutputParameters.iterator();
          final String outputParameterType = _iterator.next();
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("\t");
          FArgument _xifexpression = null;
          boolean _isEmpty = IterableExtensions.isEmpty(outputParameters);
          boolean _not = (!_isEmpty);
          if (_not) {
            Iterator _iterator_1 = outputParameters.iterator();
            FArgument _next = _iterator_1.next();
            _xifexpression = _next;
          } else {
            _xifexpression = null;
          }
          final FArgument outputParameter = _xifexpression;
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("\t");
          _builder.append("@Override");
          _builder.newLine();
          _builder.append("\t\t");
          _builder.append("\t");
          _builder.append("public ");
          _builder.append(outputParameterType, "			");
          _builder.append(" ");
          _builder.append(methodName, "			");
          _builder.append("(");
          String _commaSeperatedTypedParameterList = this._joynrJavaGeneratorExtensions.getCommaSeperatedTypedParameterList(method);
          _builder.append(_commaSeperatedTypedParameterList, "			");
          _builder.append(") {");
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("\t\t");
          _builder.append("logger.warn(\"**********************************************\");");
          _builder.newLine();
          _builder.append("\t\t");
          _builder.append("\t\t");
          _builder.append("logger.warn(\"* ");
          _builder.append(interfaceName, "				");
          _builder.append(".");
          _builder.append(methodName, "				");
          _builder.append(" called\");");
          _builder.newLineIfNotEmpty();
          _builder.append("\t\t");
          _builder.append("\t\t");
          _builder.append("logger.warn(\"**********************************************\");\t");
          _builder.newLine();
          _builder.append("\t\t");
          _builder.newLine();
          {
            boolean _equals = Objects.equal(outputParameterType, "void");
            if (_equals) {
            } else {
              boolean _equals_1 = Objects.equal(outputParameterType, "String");
              if (_equals_1) {
                _builder.append("\t\t");
                _builder.append("\t");
                _builder.append("return \"Hello World\";");
                _builder.newLine();
              } else {
                boolean _equals_2 = Objects.equal(outputParameterType, "Boolean");
                if (_equals_2) {
                  _builder.append("\t\t");
                  _builder.append("\t");
                  _builder.append("return false;");
                  _builder.newLine();
                } else {
                  boolean _equals_3 = Objects.equal(outputParameterType, "Integer");
                  if (_equals_3) {
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("return 42;");
                    _builder.newLine();
                  } else {
                    boolean _equals_4 = Objects.equal(outputParameterType, "Double");
                    if (_equals_4) {
                      _builder.append("\t\t");
                      _builder.append("\t");
                      _builder.append("return 3.1415;");
                      _builder.newLine();
                    } else {
                      boolean _equals_5 = Objects.equal(outputParameterType, "Long");
                      if (_equals_5) {
                        _builder.append("\t\t");
                        _builder.append("\t");
                        _builder.append("return (long) 42;");
                        _builder.newLine();
                      } else {
                        boolean _equals_6 = Objects.equal(outputParameterType, "Byte");
                        if (_equals_6) {
                          _builder.append("\t\t");
                          _builder.append("\t");
                          _builder.append("return (byte) 42;");
                          _builder.newLine();
                        } else {
                          boolean _startsWith = outputParameterType.startsWith("List<");
                          if (_startsWith) {
                            _builder.append("\t\t");
                            _builder.append("\t");
                            _builder.append("return new Array");
                            _builder.append(outputParameterType, "			");
                            _builder.append("();");
                            _builder.newLineIfNotEmpty();
                          } else {
                            FTypeRef _type = outputParameter.getType();
                            boolean _isEnum = this._joynrJavaGeneratorExtensions.isEnum(_type);
                            if (_isEnum) {
                              _builder.append("\t\t");
                              _builder.append("\t");
                              _builder.append("return ");
                              _builder.append(outputParameterType, "			");
                              _builder.append(".");
                              FTypeRef _type_1 = outputParameter.getType();
                              FEnumerationType _enumType = this._joynrJavaGeneratorExtensions.getEnumType(_type_1);
                              EList _enumElements = this._joynrJavaGeneratorExtensions.getEnumElements(_enumType);
                              Iterator _iterator_2 = _enumElements.iterator();
                              FEnumerator _next_1 = _iterator_2.next();
                              String _joynrName = this._joynrJavaGeneratorExtensions.joynrName(_next_1);
                              _builder.append(_joynrName, "			");
                              _builder.append(";");
                              _builder.newLineIfNotEmpty();
                            } else {
                              _builder.append("\t\t");
                              _builder.append("\t");
                              _builder.append("return new ");
                              _builder.append(outputParameterType, "			");
                              _builder.append("();\t");
                              _builder.newLineIfNotEmpty();
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
          _builder.append("\t\t");
          _builder.newLine();
          _builder.append("\t\t");
          _builder.append("\t");
          _builder.append("}");
          _builder.newLine();
        }
      }
      _builder.append("\t\t\t");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("@Override");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("public ProviderQos getProviderQos() {");
      _builder.newLine();
      _builder.append("\t\t\t    ");
      _builder.append("return providerQos;");
      _builder.newLine();
      _builder.append("\t\t\t");
      _builder.append("}\t");
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("}");
      _builder.newLine();
      _xblockexpression = (_builder);
    }
    return _xblockexpression;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy