Package org.codehaus.enunciate.apt

Examples of org.codehaus.enunciate.apt.EnunciateFreemarkerModel


        default:
          return (((PrimitiveType) typeMirror).getKind()).toString();
      }
    }
    else if (typeMirror instanceof EnumType) {
      EnunciateFreemarkerModel model = (EnunciateFreemarkerModel) FreemarkerModel.get();
      TypeDefinition typeDefinition = model.findTypeDefinition(((EnumType) typeMirror).getDeclaration());
      if (typeDefinition != null) {
        return typeDefName.calculateName(typeDefinition);
      }
    }
    else if ((typeMirror instanceof DeclaredType) && (((DeclaredType)typeMirror).getDeclaration() != null)) {
View Full Code Here


  @Override
  public void doFreemarkerGenerate() throws IOException, TemplateException, EnunciateException {
    File genDir = getGenerateDir();
    String label = getLabel() == null ? getEnunciate().getConfig() == null ? "enunciate" : getEnunciate().getConfig().getLabel() : getLabel();
    if (!enunciate.isUpToDateWithSources(genDir)) {
      EnunciateFreemarkerModel model = getModel();
      TreeMap<String, String> translations = new TreeMap<String, String>();
      translations.put("id", this.translateIdTo);
      model.put("clientSimpleName", new ClientSimpleNameMethod(translations));

      List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>();
      ExtensionDepthComparator comparator = new ExtensionDepthComparator();
      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
          if (position < 0) {
            position = -position - 1;
          }
          schemaTypes.add(position, typeDefinition);
        }
      }
      model.put("schemaTypes", schemaTypes);

      NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), label, model.getNamespacesToPrefixes(), this.packageIdentifiers);
      model.put("nameForTypeDefinition", nameForTypeDefinition);
      model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), label, model.getNamespacesToPrefixes(), this.packageIdentifiers));
      TreeMap<String, String> conversions = new TreeMap<String, String>();
      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          if (typeDefinition.isEnum()) {
            conversions.put(typeDefinition.getQualifiedName(), "enum " + nameForTypeDefinition.calculateName(typeDefinition));
          }
          else {
            conversions.put(typeDefinition.getQualifiedName(), (String) nameForTypeDefinition.calculateName(typeDefinition));
          }
        }
      }
      ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions);
      model.put("classnameFor", classnameFor);
      model.put("functionIdentifierFor", new FunctionIdentifierForMethod(nameForTypeDefinition));
      model.put("objcBaseName", label);
      model.put("separateCommonCode", isSeparateCommonCode());
      model.put("findRootElement", new FindRootElementMethod());
      model.put("referencedNamespaces", new ReferencedNamespacesMethod());
      model.put("prefix", new PrefixMethod());
      model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());

      debug("Generating the C data structures and (de)serialization functions...");
      URL apiTemplate = getTemplateURL("api.fmt");
      processTemplate(apiTemplate, model);
    }
View Full Code Here

      URL typeTemplate = getTemplateURL("gwt-type.fmt");
      URL overlayTypeTemplate = getTemplateURL("gwt-overlay-type.fmt");
      URL enumTypeTemplate = getTemplateURL("gwt-enum-15-type.fmt");
      URL overlayEnumTypeTemplate = getTemplateURL("gwt-enum-overlay-type.fmt");

      EnunciateFreemarkerModel model = getModel();
      model.put("useSpringDI", this.springDIFound);
      model.put("useWrappedServices", this.isUseWrappedServices());
      Map<String, String> conversions = new LinkedHashMap<String, String>();
      Set<String> knownGwtPackages = this.gwtClasspathHandler != null ? this.gwtClasspathHandler.getSourcePackagesToModules().keySet() : Collections.<String>emptySet();
      for (String knownGwtPackage : knownGwtPackages) {
        //makes sure any known gwt packages are preserved.
        conversions.put(knownGwtPackage, knownGwtPackage);
      }
      Map<String, String> overlayConversions = new HashMap<String, String>();
      String clientNamespace = this.rpcModuleNamespace + ".client";
      conversions.put(this.rpcModuleNamespace, clientNamespace);
      overlayConversions.put(this.rpcModuleNamespace, clientNamespace + ".json");
      if (!this.enforceNamespaceConformance) {
        TreeSet<WebFault> allFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());
        for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
          for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
            if (!isFacetExcluded(ei)) {
              String pckg = ei.getPackage().getQualifiedName();
              if (!pckg.startsWith(this.rpcModuleNamespace) && !conversions.containsKey(pckg)) {
                conversions.put(pckg, clientNamespace + "." + pckg);
              }
              for (WebMethod webMethod : ei.getWebMethods()) {
                for (WebFault webFault : webMethod.getWebFaults()) {
                  allFaults.add(webFault);
                }
              }
            }
          }
        }
        for (WebFault webFault : allFaults) {
          if (!isFacetExcluded(webFault)) {
            String pckg = webFault.getPackage().getQualifiedName();
            if (!pckg.startsWith(this.rpcModuleNamespace) && !conversions.containsKey(pckg) && (getKnownGwtModule(webFault) == null)) {
              conversions.put(pckg, clientNamespace + "." + pckg);
            }
          }
        }
        for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
          for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (!isFacetExcluded(typeDefinition)) {
              String pckg = typeDefinition.getPackage().getQualifiedName();
              if (!pckg.startsWith(this.rpcModuleNamespace) && !conversions.containsKey(pckg)) {
                if (getKnownGwtModule(typeDefinition) == null) {
                  conversions.put(pckg, clientNamespace + "." + pckg);
                }
                overlayConversions.put(pckg, clientNamespace + ".json." + pckg);
              }
            }
          }
        }
      }

      ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions);
      classnameFor.setJdk15(true);
      OverlayClientClassnameForMethod overlayClassnameFor = new OverlayClientClassnameForMethod(overlayConversions);
      overlayClassnameFor.setJdk15(true);
      model.put("packageFor", new ClientPackageForMethod(conversions));
      model.put("overlayPackageFor", new ClientPackageForMethod(overlayConversions));
      model.put("isAccessorOfTypeLong", new IsAccessorOfTypeLongMethod());
      model.put("classnameFor", classnameFor);
      model.put("overlayClassnameFor", overlayClassnameFor);
      model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
      model.put("overlaySimpleNameFor", new SimpleNameWithParamsMethod(overlayClassnameFor));
      model.put("gwtSubcontext", getGwtSubcontext());
      model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());

      model.setFileOutputDirectory(clientSideGenerateDir);
      Properties gwt2jaxbMappings = new Properties();
      TreeSet<WebFault> allFaults = new TreeSet<WebFault>(new TypeDeclarationComparator());

      Set<String> importedModules = new TreeSet<String>();
      if (isGenerateRPCSupport()) {
        debug("Generating the GWT endpoints...");
        for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
          for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
            if (!isFacetExcluded(ei)) {
              model.put("endpointInterface", ei);
              processTemplate(eiTemplate, model);

              for (WebMethod webMethod : ei.getWebMethods()) {
                for (WebFault webFault : webMethod.getWebFaults()) {
                  allFaults.add(webFault);
                }
              }
            }
          }
        }

        debug("Generating the GWT faults...");
        for (WebFault webFault : allFaults) {
          if (!isFacetExcluded(webFault)) {
            String knownGwtModule = getKnownGwtModule(webFault);
            if (knownGwtModule == null) {
              model.put("fault", webFault);
              processTemplate(faultTemplate, model);
            }
            else {
              importedModules.add(knownGwtModule);
              debug("Skipping generating fault for %s because it's in a known GWT module.", webFault.getQualifiedName());
            }
          }
        }

        debug("Generating the GWT types...");
        for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
          for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (!isFacetExcluded(typeDefinition)) {
              String knownGwtModule = getKnownGwtModule(typeDefinition);
              if (knownGwtModule == null) {

                model.put("type", typeDefinition);

                URL template = typeDefinition.isEnum() ? enumTypeTemplate : typeTemplate;
                processTemplate(template, model);
              }
              else {
                importedModules.add(knownGwtModule);
                debug("Skipping generating GWT type for %s because it's in a known GWT module.", typeDefinition.getQualifiedName());
              }
            }
          }
        }
      }

      if (isGenerateJsonOverlays()) {
        debug("Generating the GWT json overlay types...");
        for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
          for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (!isFacetExcluded(typeDefinition)) {
              model.put("type", typeDefinition);
              URL template = typeDefinition.isEnum() ? overlayEnumTypeTemplate : overlayTypeTemplate;
              processTemplate(template, model);
            }
          }
        }
      }

      model.put("gwtModuleName", this.rpcModuleName);
      model.put("importedGwtModules", importedModules);
      processTemplate(moduleXmlTemplate, model);

      model.setFileOutputDirectory(serverSideGenerateDir);
      if (isGenerateRPCSupport()) {
        debug("Generating the GWT endpoint implementations...");
        for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
          for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
            if (!isFacetExcluded(ei)) {
              model.put("endpointInterface", ei);
              processTemplate(endpointImplTemplate, model);
            }
          }
        }

        debug("Generating the GWT type mappers...");
        for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
          for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (!isFacetExcluded(typeDefinition)) {
              if (typeDefinition.isEnum()) {
                model.put("type", typeDefinition);
                processTemplate(enumTypeMapperTemplate, model);
                gwt2jaxbMappings.setProperty(classnameFor.convert(typeDefinition), typeDefinition.getQualifiedName());
              }
              else if (getKnownGwtModule(typeDefinition) == null) {
                if (!typeDefinition.isEnum()) {
                  model.put("type", typeDefinition);
                  processTemplate(typeMapperTemplate, model);
                  gwt2jaxbMappings.setProperty(classnameFor.convert(typeDefinition), typeDefinition.getQualifiedName());
                }
              }
              else {
                debug("Skipping generation of type mapper for %s because it's a known GWT type.", typeDefinition.getQualifiedName());
              }
            }
          }
        }

        debug("Generating the GWT fault mappers...");
        for (WebFault webFault : allFaults) {
          if (!isFacetExcluded(webFault) && (getKnownGwtModule(webFault) == null)) {
            model.put("fault", webFault);
            processTemplate(faultMapperTemplate, model);
            gwt2jaxbMappings.setProperty(classnameFor.convert(webFault), webFault.getQualifiedName());
          }
        }
View Full Code Here

  }

  @Override
  public void doFreemarkerGenerate() throws IOException, TemplateException {
    if (!isUpToDate()) {
      EnunciateFreemarkerModel model = getModel();
      Map<String, String> conversions = Collections.<String, String>emptyMap();
      ClassnameForMethod classnameFor = new ClassnameForMethod(conversions);
      classnameFor.setJdk15(true);
      model.put("packageFor", new ClientPackageForMethod(conversions));
      model.put("classnameFor", classnameFor);
      model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
      model.put("docsDir", enunciate.getProperty("docs.webapp.dir"));
      URL configTemplate = isSpringEnabled() ? getJAXWSSpringTemplateURL() : getSunJAXWSTemplateURL();
      File configDir = getConfigGenerateDir();
      configDir.mkdirs();
      model.setFileOutputDirectory(configDir);
      processTemplate(configTemplate, model);

      File javaSourcesDir = new File(getGenerateDir(), "java");
      javaSourcesDir.mkdirs();
      model.setFileOutputDirectory(javaSourcesDir);
      URL eiTemplate = getInstrumentedEndpointTemplateURL();
      for (WsdlInfo wsdlInfo : model.getNamespacesToWSDLs().values()) {
        for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
          model.put("endpointInterface", ei);
          processTemplate(eiTemplate, model);
        }
      }

      getEnunciate().addAdditionalSourceRoot(javaSourcesDir);
View Full Code Here

  }

  @Override
  public void doFreemarkerGenerate() throws IOException, TemplateException {
    if (!isUpToDate()) {
      EnunciateFreemarkerModel model = getModel();
      model.put("jaxwsProperties", this.jaxwsProperties);
      model.put("provideJaxws", enableJaxws);
      model.put("provideJaxrs", enableJaxrs);
      model.put("useExtensionMappings", useExtensionMappings);
      model.put("jacksonAvailable", jacksonAvailable);
      model.put("amfEnabled", getEnunciate().isModuleEnabled("amf"));
      model.put("restSubcontext", this.useSubcontext ? getRestSubcontext() : "/");
      model.put("docsDir", enunciate.getProperty("docs.webapp.dir"));
      model.put("loggingFeatureEnabled", (enableJaxrs && isLoggingFeatureEnabled()));
      processTemplate(getCXFServletTemplateURL(), model);
    }
    else {
      info("Skipping generation of CXF config as everything appears up-to-date....");
    }
View Full Code Here

  /**
   * The generate logic builds the XML documentation structure for the enunciated API.
   */
  public void doFreemarkerGenerate() throws EnunciateException, IOException, TemplateException {
    if (!getEnunciate().isUpToDateWithSources(getGenerateDir())) {
      EnunciateFreemarkerModel model = getModel();
      if (this.splashPackage != null) {
        PackageDeclaration packageDeclaration = Context.getCurrentEnvironment().getPackage(this.splashPackage);
        if (packageDeclaration != null) {
          debug("Including documentation for package %s as the splash documentation.", this.splashPackage);
          model.setVariable("apiDoc", new DecoratedPackageDeclaration(packageDeclaration).getJavaDoc());
        }
        else {
          warn("Splash package %s not found.  No splash documentation included.", this.splashPackage);
        }
      }

      if (this.copyright != null) {
        debug("Documentation copyright: %s", this.copyright);
        model.setVariable("copyright", this.copyright);
      }

      String title = this.title;
      if (title == null) {
        title = "Web API";
      }

      debug("Documentation title: %s", title);
      model.setVariable("title", title);

      model.setVariable("uniqueContentTypes", new UniqueContentTypesMethod());
      model.setVariable("schemaForNamespace", new SchemaForNamespaceMethod(model.getNamespacesToSchemas()));
      model.setVariable(JsonSchemaForType.NAME, new JsonSchemaForType(model));
      model.setVariable(JsonTypeNameForQualifiedName.NAME, new JsonTypeNameForQualifiedName(model));
      model.put("isDefinedGlobally", new IsDefinedGloballyMethod());
      model.put("includeExampleXml", isIncludeExampleXml());
      model.put("generateExampleXml", new GenerateExampleXmlMethod(getDefaultNamespace(), model, isIncludeDeprecatedFieldsInExample()));
      model.put("includeExampleJson", (forceExampleJson || (jacksonXcAvailable && isIncludeExampleJson())));
      model.put("generateExampleJson", new GenerateExampleJsonMethod(model, isIncludeDeprecatedFieldsInExample()));
      processTemplate(getDocsTemplateURL(), model);
    }
    else {
      info("Skipping documentation source generation as everything appears up-to-date...");
    }
View Full Code Here

  /**
   * Generates the downloads xml indicating the available downloads.
   */
  protected void generateDownloadsXML() throws IOException, EnunciateException {
    EnunciateFreemarkerModel model = getModel();
    model.put("defaultDate", new Date());

    try {
      processTemplate(getDownloadsTemplateURL(), model);
    }
    catch (TemplateException e) {
View Full Code Here

      debug("File %s to be added as an additional css file.", additionalCss);
      enunciate.copyFile(additionalCssFile, new File(buildDir, additionalCssFile.getName()));
      additionalCssFiles.add(additionalCssFile.getName());
    }

    EnunciateFreemarkerModel model = getModel();
    model.put("downloads", downloads);
    model.put("additionalCssFiles", additionalCssFiles);
  }
View Full Code Here

  @Override
  public void doFreemarkerGenerate() throws IOException, TemplateException, EnunciateException {
    File genDir = getGenerateDir();
    if (!enunciate.isUpToDateWithSources(genDir)) {
      EnunciateFreemarkerModel model = getModel();

      String label = getLabel() == null ? getEnunciate().getConfig() == null ? "enunciate" : getEnunciate().getConfig().getLabel() : getLabel();
      NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), label, model.getNamespacesToPrefixes());
      model.put("nameForTypeDefinition", nameForTypeDefinition);
      model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), label, model.getNamespacesToPrefixes()));
      TreeMap<String, String> conversions = new TreeMap<String, String>();
      for (SchemaInfo schemaInfo : model.getNamespacesToSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
          if (typeDefinition.isEnum()) {
            conversions.put(typeDefinition.getQualifiedName(), "enum " + nameForTypeDefinition.calculateName(typeDefinition));
          }
          else {
            conversions.put(typeDefinition.getQualifiedName(), "struct " + nameForTypeDefinition.calculateName(typeDefinition));
          }
        }
      }
      ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions);
      model.put("classnameFor", classnameFor);
      model.put("cFileName", getSourceFileName());
      model.put("separateCommonCode", isSeparateCommonCode());
      model.put("findRootElement", new FindRootElementMethod());
      model.put("referencedNamespaces", new ReferencedNamespacesMethod());
      model.put("prefix", new PrefixMethod());
      model.put("xmlFunctionIdentifier", new XmlFunctionIdentifierMethod());
      model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());

      debug("Generating the C data structures and (de)serialization functions...");
      URL apiTemplate = getTemplateURL("api.fmt");
      processTemplate(apiTemplate, model);
    }
View Full Code Here

    }
  }

  protected void doFreemarkerXMLProcessing(URL freemarkerXMLProcessingTemplateURL) throws IOException, EnunciateException {
    debug("Using freemarker XML processing template %s", freemarkerXMLProcessingTemplateURL);
    EnunciateFreemarkerModel model = getModel();
    File docsXml = new File(getGenerateDir(), "docs.xml");
    model.put("docsxml", loadNodeModel(docsXml));
    File downloadsXml = new File(getGenerateDir(), "downloads.xml");
    if (downloadsXml.exists()) {
      model.put("downloadsxml", loadNodeModel(downloadsXml));
    }
    File buildDir = getDocsBuildDir();
    buildDir.mkdirs();
    model.setFileOutputDirectory(buildDir);
    model.put("apiRelativePath", getRelativePathToRootDir());
    model.put("indexPageName", getIndexPageName());
    model.put("disableRestMountpoint", isDisableRestMountpoint());
    model.put("groupRestResources", getGroupRestResources());
    model.put("additionalCss", getAdditionalCss());
    try {
      processTemplate(freemarkerXMLProcessingTemplateURL, model);
    }
    catch (TemplateException e) {
      throw new EnunciateException(e);
View Full Code Here

TOP

Related Classes of org.codehaus.enunciate.apt.EnunciateFreemarkerModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.