Search in sources :

Example 1 with EnunciateJaxbContext

use of com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext in project enunciate by stoicflame.

the class JavaXMLClientModule method generateClientSources.

protected File generateClientSources() {
    File sourceDir = getSourceDir();
    sourceDir.mkdirs();
    Map<String, Object> model = new HashMap<String, Object>();
    Map<String, String> conversions = getClientPackageConversions();
    EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
    model.put("packageFor", new ClientPackageForMethod(conversions, this.context));
    model.put("classnameFor", new ClientClassnameForMethod(conversions, jaxbContext));
    model.put("simpleNameFor", new SimpleNameForMethod(new ClientClassnameForMethod(conversions, jaxbContext, true)));
    model.put("file", new FileDirective(sourceDir, this.enunciate.getLogger()));
    model.put("generatedCodeLicense", this.enunciate.getConfiguration().readGeneratedCodeLicenseFile());
    model.put("annotationValue", new AnnotationValueMethod());
    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));
    boolean upToDate = isUpToDateWithSources(sourceDir);
    if (!upToDate) {
        try {
            debug("Generating the Java client classes...");
            HashMap<String, WebFault> allFaults = new HashMap<String, WebFault>();
            AntPatternMatcher matcher = new AntPatternMatcher();
            matcher.setPathSeparator(".");
            if (this.jaxwsModule != null) {
                Set<String> seeAlsos = new TreeSet<String>();
                // for each endpoint interface.
                for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
                    for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
                        if (facetFilter.accept(ei)) {
                            for (WebMethod webMethod : ei.getWebMethods()) {
                                if (facetFilter.accept(webMethod)) {
                                    for (WebMessage webMessage : webMethod.getMessages()) {
                                        if (webMessage instanceof RequestWrapper) {
                                            model.put("message", webMessage);
                                            processTemplate(getTemplateURL("client-request-bean.fmt"), model);
                                            seeAlsos.add(getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), ((RequestWrapper) webMessage).getRequestBeanName()));
                                        } else if (webMessage instanceof ResponseWrapper) {
                                            model.put("message", webMessage);
                                            processTemplate(getTemplateURL("client-response-bean.fmt"), model);
                                            seeAlsos.add(getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), ((ResponseWrapper) webMessage).getResponseBeanName()));
                                        } else if (webMessage instanceof WebFault) {
                                            WebFault fault = (WebFault) webMessage;
                                            allFaults.put(fault.getQualifiedName().toString(), fault);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                // gather the annotation information and process the possible beans for each web fault.
                for (WebFault webFault : allFaults.values()) {
                    boolean implicit = webFault.isImplicitSchemaElement();
                    String faultBean = implicit ? getBeanName(new ClientClassnameForMethod(conversions, jaxbContext), webFault.getImplicitFaultBeanQualifiedName()) : new ClientClassnameForMethod(conversions, jaxbContext).convert(webFault.getExplicitFaultBeanType());
                    seeAlsos.add(faultBean);
                    if (implicit) {
                        model.put("fault", webFault);
                        processTemplate(getTemplateURL("client-fault-bean.fmt"), model);
                    }
                }
                model.put("seeAlsoBeans", seeAlsos);
                model.put("baseUri", this.enunciate.getConfiguration().getApplicationRoot());
                for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
                    if (wsdlInfo.getWsdlFile() == null) {
                        throw new EnunciateException("WSDL " + wsdlInfo.getId() + " doesn't have a filename.");
                    }
                    for (EndpointInterface ei : wsdlInfo.getEndpointInterfaces()) {
                        if (facetFilter.accept(ei)) {
                            model.put("endpointInterface", ei);
                            model.put("wsdlFileName", wsdlInfo.getFilename());
                            processTemplate(getTemplateURL("client-endpoint-interface.fmt"), model);
                            processTemplate(getTemplateURL("client-soap-endpoint-impl.fmt"), model);
                        }
                    }
                }
                for (WebFault webFault : allFaults.values()) {
                    if (useServerSide(webFault, matcher)) {
                        copyServerSideType(sourceDir, webFault);
                    } else {
                        TypeElement superFault = (TypeElement) ((DeclaredType) webFault.getSuperclass()).asElement();
                        if (superFault != null && allFaults.containsKey(superFault.getQualifiedName().toString()) && allFaults.get(superFault.getQualifiedName().toString()).isImplicitSchemaElement()) {
                            model.put("superFault", allFaults.get(superFault.getQualifiedName().toString()));
                        } else {
                            model.remove("superFault");
                        }
                        model.put("fault", webFault);
                        processTemplate(getTemplateURL("client-web-fault.fmt"), model);
                    }
                }
            }
            for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
                for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
                    if (facetFilter.accept(typeDefinition)) {
                        if (useServerSide(typeDefinition, matcher)) {
                            copyServerSideType(sourceDir, typeDefinition);
                        } else {
                            model.put("rootEl", this.jaxbModule.getJaxbContext().findElementDeclaration(typeDefinition));
                            model.put("type", typeDefinition);
                            URL template = typeDefinition.isEnum() ? typeDefinition instanceof QNameEnumTypeDefinition ? getTemplateURL("client-qname-enum-type.fmt") : getTemplateURL("client-enum-type.fmt") : typeDefinition.isSimple() ? getTemplateURL("client-simple-type.fmt") : getTemplateURL("client-complex-type.fmt");
                            processTemplate(template, model);
                        }
                    }
                }
                for (Registry registry : schemaInfo.getRegistries()) {
                    model.put("registry", registry);
                    processTemplate(getTemplateURL("client-registry.fmt"), model);
                }
            }
        } catch (IOException e) {
            throw new EnunciateException(e);
        } catch (TemplateException e) {
            throw new EnunciateException(e);
        }
    } else {
        info("Skipping generation of Java client sources as everything appears up-to-date...");
    }
    context.setProperty(LIRBARY_DESCRIPTION_PROPERTY, readLibraryDescription(model));
    return sourceDir;
}
Also used : QNameEnumTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.QNameEnumTypeDefinition) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) QNameEnumTypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.QNameEnumTypeDefinition) EnunciateException(com.webcohesion.enunciate.EnunciateException) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) TemplateException(freemarker.template.TemplateException) TypeElement(javax.lang.model.element.TypeElement) Registry(com.webcohesion.enunciate.modules.jaxb.model.Registry) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) AntPatternMatcher(com.webcohesion.enunciate.util.AntPatternMatcher) JavaFileObject(javax.tools.JavaFileObject) WsdlInfo(com.webcohesion.enunciate.modules.jaxws.WsdlInfo)

Example 2 with EnunciateJaxbContext

use of com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext 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 3 with EnunciateJaxbContext

use of com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext in project enunciate by stoicflame.

the class ObjCXMLClientModule method call.

@Override
public void call(EnunciateContext context) {
    if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
        info("No JAXB XML data types: Objective-C XML client will not be generated.");
        return;
    }
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the Objective-C XML client. Objective-C XML client will not be generated.");
        return;
    }
    List<String> namingConflicts = JAXBCodeErrors.findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext());
    if (namingConflicts != null && !namingConflicts.isEmpty()) {
        error("JAXB naming conflicts have been found:");
        for (String namingConflict : namingConflicts) {
            error(namingConflict);
        }
        error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:");
        error("1. Explicitly exclude one or the other.");
        error("2. Put the annotations on the property instead of the field.");
        error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation.");
        throw new EnunciateException("JAXB naming conflicts detected.");
    }
    EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
    Map<String, String> packageIdentifiers = getPackageIdentifiers();
    String packageIdentifierPattern = getPackageIdentifierPattern();
    if ((packageIdentifierPattern != null)) {
        for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
            for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
                String pckg = typeDefinition.getPackage().getQualifiedName().toString();
                if (!packageIdentifiers.containsKey(pckg)) {
                    try {
                        packageIdentifiers.put(pckg, String.format(packageIdentifierPattern, pckg.split("\\.", 9)));
                    } catch (IllegalFormatException e) {
                        warn("Unable to format package %s with format pattern %s (%s)", pckg, packageIdentifierPattern, e.getMessage());
                    }
                }
            }
        }
    }
    Map<String, Object> model = new HashMap<String, Object>();
    String slug = getSlug();
    model.put("slug", slug);
    File srcDir = getSourceDir();
    TreeMap<String, String> translations = new TreeMap<String, String>();
    translations.put("id", getTranslateIdTo());
    model.put("clientSimpleName", new ClientSimpleNameMethod(translations));
    List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>();
    ExtensionDepthComparator comparator = new ExtensionDepthComparator();
    for (SchemaInfo schemaInfo : jaxbContext.getSchemas().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(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers);
    model.put("nameForTypeDefinition", nameForTypeDefinition);
    model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, jaxbContext.getNamespacePrefixes(), packageIdentifiers));
    TreeMap<String, String> conversions = new TreeMap<String, String>();
    for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            if (typeDefinition.isEnum()) {
                conversions.put(typeDefinition.getQualifiedName().toString(), "enum " + nameForTypeDefinition.calculateName(typeDefinition));
            } else {
                conversions.put(typeDefinition.getQualifiedName().toString(), (String) nameForTypeDefinition.calculateName(typeDefinition));
            }
        }
    }
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, jaxbContext);
    model.put("classnameFor", classnameFor);
    model.put("functionIdentifierFor", new FunctionIdentifierForMethod(nameForTypeDefinition, jaxbContext));
    model.put("objcBaseName", slug);
    model.put("separateCommonCode", isSeparateCommonCode());
    model.put("findRootElement", new FindRootElementMethod(jaxbContext));
    model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext));
    model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes()));
    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 data structures and (de)serialization functions...");
        URL apiTemplate = 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.");
    }
    ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "objc.client.library", "Objective C Client Library");
    FileArtifact sourceHeader = new FileArtifact(getName(), "objc.client.h", new File(srcDir, slug + ".h"));
    sourceHeader.setPublic(false);
    sourceHeader.setArtifactType(ArtifactType.sources);
    FileArtifact sourceImpl = new FileArtifact(getName(), "objc.client.m", new File(srcDir, slug + ".m"));
    sourceImpl.setPublic(false);
    sourceImpl.setArtifactType(ArtifactType.sources);
    // read in the description from file
    String description = readResource("library_description.fmt", model, nameForTypeDefinition);
    artifactBundle.setDescription(description);
    artifactBundle.addArtifact(sourceHeader);
    artifactBundle.addArtifact(sourceImpl);
    if (isSeparateCommonCode()) {
        FileArtifact commonSourceHeader = new FileArtifact(getName(), "objc.common.client.h", new File(srcDir, "enunciate-common.h"));
        commonSourceHeader.setPublic(false);
        commonSourceHeader.setArtifactType(ArtifactType.sources);
        commonSourceHeader.setDescription("Common header needed for all projects.");
        FileArtifact commonSourceImpl = new FileArtifact(getName(), "objc.common.client.m", new File(srcDir, "enunciate-common.m"));
        commonSourceImpl.setPublic(false);
        commonSourceImpl.setArtifactType(ArtifactType.sources);
        commonSourceImpl.setDescription("Common implementation code needed for all projects.");
        artifactBundle.addArtifact(commonSourceHeader);
        artifactBundle.addArtifact(commonSourceImpl);
    }
    this.enunciate.addArtifact(artifactBundle);
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) IsFacetExcludedMethod(com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact)

Example 4 with EnunciateJaxbContext

use of com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext in project enunciate by stoicflame.

the class PHPXMLClientModule method call.

@Override
public void call(EnunciateContext context) {
    if (this.jaxbModule == null || this.jaxbModule.getJaxbContext() == null || this.jaxbModule.getJaxbContext().getSchemas().isEmpty()) {
        info("No JAXB XML data types: PHP XML client will not be generated.");
        return;
    }
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the PHP XML client. PHP XML client will not be generated.");
        return;
    }
    List<String> namingConflicts = JAXBCodeErrors.findConflictingAccessorNamingErrors(this.jaxbModule.getJaxbContext());
    if (namingConflicts != null && !namingConflicts.isEmpty()) {
        error("JAXB naming conflicts have been found:");
        for (String namingConflict : namingConflicts) {
            error(namingConflict);
        }
        error("These naming conflicts are often between the field and it's associated property, in which case you need to use one or two of the following strategies to avoid the conflicts:");
        error("1. Explicitly exclude one or the other.");
        error("2. Put the annotations on the property instead of the field.");
        error("3. Tell JAXB to use a different process for detecting accessors using the @XmlAccessorType annotation.");
        throw new EnunciateException("JAXB naming conflicts detected.");
    }
    Map<String, String> packageToNamespaceConversions = getPackageToNamespaceConversions();
    List<TypeDefinition> schemaTypes = new ArrayList<TypeDefinition>();
    ExtensionDepthComparator comparator = new ExtensionDepthComparator();
    EnunciateJaxbContext jaxbContext = this.jaxbModule.getJaxbContext();
    for (SchemaInfo schemaInfo : jaxbContext.getSchemas().values()) {
        for (TypeDefinition typeDefinition : schemaInfo.getTypeDefinitions()) {
            String pckg = typeDefinition.getPackage().getQualifiedName().toString();
            if (!packageToNamespaceConversions.containsKey(pckg)) {
                packageToNamespaceConversions.put(pckg, packageToNamespace(pckg));
            }
            int position = Collections.binarySearch(schemaTypes, typeDefinition, comparator);
            if (position < 0) {
                position = -position - 1;
            }
            schemaTypes.add(position, typeDefinition);
        }
    }
    File srcDir = getSourceDir();
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("schemaTypes", schemaTypes);
    model.put("namespaceFor", new ClientPackageForMethod(packageToNamespaceConversions, this.context));
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(packageToNamespaceConversions, jaxbContext);
    model.put("classnameFor", classnameFor);
    model.put("typeNameFor", new TypeNameForMethod(packageToNamespaceConversions, jaxbContext));
    model.put("simpleNameFor", new SimpleNameWithParamsMethod(classnameFor));
    model.put("phpFileName", getSourceFileName());
    model.put("findRootElement", new FindRootElementMethod(jaxbContext));
    model.put("referencedNamespaces", new ReferencedNamespacesMethod(jaxbContext));
    model.put("prefix", new PrefixMethod(jaxbContext.getNamespacePrefixes()));
    model.put("file", new FileDirective(srcDir, 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));
    if (!isUpToDateWithSources(srcDir)) {
        debug("Generating the PHP XML data 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 PHP XML code generation because everything appears up-to-date.");
    }
    File packageDir = getPackageDir();
    packageDir.mkdirs();
    File bundle = new File(packageDir, getBundleFileName());
    boolean anyFiles = bundle.exists();
    if (!isUpToDateWithSources(packageDir)) {
        try {
            anyFiles = enunciate.zip(bundle, srcDir);
        } catch (IOException e) {
            throw new EnunciateException(e);
        }
    }
    if (anyFiles) {
        ClientLibraryArtifact artifactBundle = new ClientLibraryArtifact(getName(), "php.xml.client.library", "PHP XML Client Library");
        artifactBundle.setPlatform("PHP");
        FileArtifact sourceScript = new FileArtifact(getName(), "php.xml.client", bundle);
        // binaries and sources are the same thing in php
        sourceScript.setArtifactType(ArtifactType.binaries);
        sourceScript.setPublic(false);
        // read in the description from file
        String description = readResource("library_description.fmt", model);
        artifactBundle.setDescription(description);
        artifactBundle.addArtifact(sourceScript);
        this.enunciate.addArtifact(artifactBundle);
    }
}
Also used : FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) URL(java.net.URL) TypeDefinition(com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition) FindRootElementMethod(com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod) ReferencedNamespacesMethod(com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) EnunciateJaxbContext(com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) PrefixMethod(com.webcohesion.enunciate.modules.jaxb.util.PrefixMethod) File(java.io.File)

Aggregations

EnunciateException (com.webcohesion.enunciate.EnunciateException)4 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)4 EnunciateJaxbContext (com.webcohesion.enunciate.modules.jaxb.EnunciateJaxbContext)4 URL (java.net.URL)4 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)3 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)3 FindRootElementMethod (com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod)3 TemplateException (freemarker.template.TemplateException)3 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)2 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)2 AccessorOverridesAnotherMethod (com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod)2 WsdlInfo (com.webcohesion.enunciate.modules.jaxws.WsdlInfo)2 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)2 IsFacetExcludedMethod (com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod)2 QNameEnumTypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.QNameEnumTypeDefinition)1 Registry (com.webcohesion.enunciate.modules.jaxb.model.Registry)1 PrefixMethod (com.webcohesion.enunciate.modules.jaxb.util.PrefixMethod)1 ReferencedNamespacesMethod (com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod)1 AntPatternMatcher (com.webcohesion.enunciate.util.AntPatternMatcher)1 ClientPackageForMethod (com.webcohesion.enunciate.util.freemarker.ClientPackageForMethod)1