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

com.webcohesion.enunciate.modules.gwt_json_overlay.SimpleNameForMethod Maven / Gradle / Ivy

Go to download

The Enunciate GWT module generates the artifacts to support the GWT JSON Overlays for the JSON API data.

There is a newer version: 2.18.1
Show newest version
package com.webcohesion.enunciate.modules.gwt_json_overlay;

import com.webcohesion.enunciate.api.datatype.DataTypeReference;
import com.webcohesion.enunciate.api.resources.Entity;
import com.webcohesion.enunciate.api.resources.MediaTypeDescriptor;
import com.webcohesion.enunciate.util.freemarker.ClientClassnameForMethod;
import com.webcohesion.enunciate.util.freemarker.SimpleNameWithParamsMethod;
import freemarker.template.TemplateModelException;

import java.util.List;

/**
 * @author Ryan Heaton
 */
public class SimpleNameForMethod extends SimpleNameWithParamsMethod {

  private final MergedJsonContext jsonContext;

  public SimpleNameForMethod(ClientClassnameForMethod typeConversion, MergedJsonContext jsonContext) {
    super(typeConversion);
    this.jsonContext = jsonContext;
  }

  @Override
  public String simpleNameFor(Object unwrapped, boolean noParams) throws TemplateModelException {
    if (unwrapped instanceof Entity) {
      List mediaTypes = ((Entity) unwrapped).getMediaTypes();
      for (MediaTypeDescriptor mediaType : mediaTypes) {
        if (this.jsonContext.getLabel().equals(mediaType.getSyntax())) {
          DataTypeReference dataType = mediaType.getDataType();
          unwrapped = this.jsonContext.findType(dataType);
          if (unwrapped == null) {
            return "JavaScriptObject";
          }
        }
      }
    }

    if (unwrapped instanceof Entity) {
      return "JavaScriptObject";
    }

    return super.simpleNameFor(unwrapped, noParams);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy