Search in sources :

Example 1 with ClientPackageForMethod

use of com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod in project enunciate by stoicflame.

the class CSharpXMLClientModule method generateSources.

private File generateSources(Map<String, String> packageToNamespaceConversions) {
    File srcDir = getSourceDir();
    srcDir.mkdirs();
    Map<String, Object> model = new HashMap<String, Object>();
    ClientPackageForMethod namespaceFor = new ClientPackageForMethod(packageToNamespaceConversions, this.context);
    Collection<WsdlInfo> wsdls = new ArrayList<WsdlInfo>();
    if (this.jaxwsModule != null) {
        wsdls = this.jaxwsModule.getJaxwsContext().getWsdls().values();
    }
    model.put("wsdls", wsdls);
    EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
    model.put("schemas", jaxbContext.getSchemas().values());
    model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    model.put("namespaceFor", namespaceFor);
    model.put("findRootElement", new FindRootElementMethod(jaxbContext));
    model.put("requestDocumentQName", new RequestDocumentQNameMethod());
    model.put("responseDocumentQName", new ResponseDocumentQNameMethod());
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
    model.put("classnameFor", classnameFor);
    model.put("listsAsArraysClassnameFor", new ListsAsArraysClientClassnameForMethod(packageToNamespaceConversions, jaxbContext));
    model.put("simpleNameFor", new SimpleNameFor(classnameFor));
    model.put("csFileName", getSourceFileName());
    model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
    facetIncludes.addAll(getFacetIncludes());
    Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
    facetExcludes.addAll(getFacetExcludes());
    FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
    model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
    if (!isUpToDateWithSources(srcDir)) {
        debug("Generating the C# client classes...");
        URL apiTemplate = isSingleFilePerClass() ? getTemplateURL("api-multiple-files.fmt") : getTemplateURL("api.fmt");
        try {
            processTemplate(apiTemplate, model);
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping C# code generation because everything appears up-to-date.");
    }
    this.context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
    return srcDir;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) IsFacetExcludedMethod(com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod) ClientPackageForMethod(com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod) URL(java.net.URL) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) WsdlInfo(com.webcohesion.enunciate.modules.jaxws.WsdlInfo)

Example 2 with ClientPackageForMethod

use of com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod in project enunciate by stoicflame.

the class GWTJSONOverlayModule method generateClientSources.

protected File generateClientSources() {
    File sourceDir = getSourceDir();
    sourceDir.mkdirs();
    Map<String, Object> model = new HashMap<String, Object>();
    Map<String, String> conversions = getClientPackageConversions();
    EnunciateJacksonContext jacksonContext = this.jacksonModule != null ? this.jacksonModule.getJacksonContext() : null;
    EnunciateJackson1Context jackson1Context = this.jackson1Module != null ? this.jackson1Module.getJacksonContext() : null;
    MergedJsonContext jsonContext = new MergedJsonContext(jacksonContext, jackson1Context);
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jsonContext);
    model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
    model.put("classnameFor", classnameFor);
    model.put("simpleNameFor", new SimpleNameForMethod(classnameFor, jsonContext));
    model.put("isAccessorOfTypeLong", new IsAccessorOfTypeLongMethod());
    model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger()));
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
    facetIncludes.addAll(getFacetIncludes());
    Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
    facetExcludes.addAll(getFacetExcludes());
    FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
    model.put("isFacetExcluded", new IsFacetExcludedMethod(facetFilter));
    AntPatternMatcher matcher = new AntPatternMatcher();
    matcher.setPathSeparator(".");
    boolean upToDate = isUpToDateWithSources(sourceDir);
    if (!upToDate) {
        try {
            debug("Generating the GWT JSON Overlay...");
            if (jacksonContext != null) {
                for (TypeDefinition typeDefinition : jacksonContext.getTypeDefinitions()) {
                    if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
                        model.put("type", typeDefinition);
                        URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
                        processTemplate(template, model);
                    }
                }
            }
            if (jackson1Context != null) {
                for (com.webcohesion.enunciate.modules.jackson1.model.TypeDefinition typeDefinition : jackson1Context.getTypeDefinitions()) {
                    if (!typeDefinition.isSimple() && facetFilter.accept(typeDefinition)) {
                        model.put("type", typeDefinition);
                        URL template = typeDefinition.isEnum() ? getTemplateURL("gwt-enum-type.fmt") : getTemplateURL("gwt-type.fmt");
                        processTemplate(template, model);
                    }
                }
            }
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping generation of GWT JSON Overlay as everything appears up-to-date...");
    }
    context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
    return sourceDir;
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) IsFacetExcludedMethod(com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod) ClientPackageForMethod(com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jackson.model.TypeDefinition) EnunciateException(com.webcohesion.enunciate.EnunciateException) EnunciateJackson1Context(com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) EnunciateJacksonContext(com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext) IOException(java.io.IOException) AntPatternMatcher(com.webcohesion.enunciate.util.AntPatternMatcher) File(java.io.File)

Aggregations

EnunciateException (com.webcohesion.enunciate.EnunciateException)2 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)2 ClientPackageForMethod (com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod)2 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)2 IsFacetExcludedMethod (com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod)2 TemplateException (freemarker.template.TemplateException)2 URL (java.net.URL)2 EnunciateJacksonContext (com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext)1 TypeDefinition (com.webcohesion.enunciate.modules.jackson.model.TypeDefinition)1 EnunciateJackson1Context (com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context)1 EnunciateJaxbContext (com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext)1 AccessorOverridesAnotherMethod (com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod)1 FindRootElementMethod (com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod)1 WsdlInfo (com.webcohesion.enunciate.modules.jaxws.WsdlInfo)1 AntPatternMatcher (com.webcohesion.enunciate.util.AntPatternMatcher)1 File (java.io.File)1 IOException (java.io.IOException)1