Search in sources :

Example 36 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class JavaXMLClientModule method copyResources.

protected File copyResources() {
    File resourcesDir = getResourcesDir();
    resourcesDir.mkdirs();
    try {
        if (this.jaxwsModule != null) {
            for (WsdlInfo wsdlInfo : this.jaxwsModule.getJaxwsContext().getWsdls().values()) {
                if (wsdlInfo.getWsdlFile() != null) {
                    wsdlInfo.getWsdlFile().writeTo(resourcesDir);
                }
            }
        }
        for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().getSchemas().values()) {
            if (schemaInfo.getSchemaFile() != null) {
                schemaInfo.getSchemaFile().writeTo(resourcesDir);
            }
        }
    } catch (IOException e) {
        throw new EnunciateException(e);
    }
    return resourcesDir;
}
Also used : EnunciateException(com.webcohesion.enunciate.EnunciateException) WsdlInfo(com.webcohesion.enunciate.modules.jaxws.WsdlInfo) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)

Example 37 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class EnumTypeDefinition method loadEnumValues.

protected List<EnumValue> loadEnumValues() {
    List<VariableElement> enumConstants = enumValues();
    List<EnumValue> enumValueMap = new ArrayList<EnumValue>();
    HashSet<String> enumValues = new HashSet<String>(enumConstants.size());
    for (VariableElement enumConstant : enumConstants) {
        if (isIgnored(enumConstant)) {
            continue;
        }
        String value = enumConstant.getSimpleName().toString();
        if (context.isHonorJaxb()) {
            XmlEnumValue enumValue = enumConstant.getAnnotation(XmlEnumValue.class);
            if (enumValue != null) {
                value = enumValue.value();
            }
        }
        if (!enumValues.add(value)) {
            throw new EnunciateException(getQualifiedName() + ": duplicate enum value: " + value);
        }
        enumValueMap.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), value));
    }
    return enumValueMap;
}
Also used : EnunciateException(com.webcohesion.enunciate.EnunciateException) XmlEnumValue(javax.xml.bind.annotation.XmlEnumValue) VariableElement(javax.lang.model.element.VariableElement) XmlEnumValue(javax.xml.bind.annotation.XmlEnumValue)

Example 38 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class QNameEnumTypeDefinition method loadEnumValues.

@Override
protected List<EnumValue> loadEnumValues() {
    List<VariableElement> enumConstants = enumValues();
    List<EnumValue> enumValueMap = new ArrayList<EnumValue>();
    HashSet<String> enumValues = new HashSet<String>(enumConstants.size());
    VariableElement unknownQNameConstant = null;
    for (VariableElement enumConstant : enumConstants) {
        if (isIgnored(enumConstant)) {
            continue;
        }
        XmlUnknownQNameEnumValue unknownQNameEnumValue = enumConstant.getAnnotation(XmlUnknownQNameEnumValue.class);
        if (unknownQNameEnumValue != null) {
            if (unknownQNameConstant != null) {
                throw new EnunciateException(getQualifiedName() + ": no more than two constants can be annotated with @XmlUnknownQNameEnumValue.");
            }
            unknownQNameConstant = enumConstant;
            continue;
        }
        String ns = this.namespace;
        String localPart = enumConstant.getSimpleName().toString();
        XmlQNameEnumValue enumValueInfo = enumConstant.getAnnotation(XmlQNameEnumValue.class);
        if (enumValueInfo != null) {
            if (enumValueInfo.exclude()) {
                continue;
            }
            if (!"##default".equals(enumValueInfo.namespace())) {
                ns = enumValueInfo.namespace();
            }
            if (!"##default".equals(enumValueInfo.localPart())) {
                localPart = enumValueInfo.localPart();
            }
        }
        String uri = ns + localPart;
        if (!enumValues.add(uri)) {
            throw new EnunciateException(getQualifiedName() + ": duplicate qname enum value: " + uri);
        }
        enumValueMap.add(new EnumValue(this, enumConstant, enumConstant.getSimpleName().toString(), uri));
    }
    if (unknownQNameConstant != null) {
        // enter the unknown qname constant as a null qname.
        enumValueMap.add(new EnumValue(this, unknownQNameConstant, unknownQNameConstant.getSimpleName().toString(), null));
    }
    return enumValueMap;
}
Also used : XmlQNameEnumValue(com.webcohesion.enunciate.metadata.qname.XmlQNameEnumValue) EnunciateException(com.webcohesion.enunciate.EnunciateException) XmlQNameEnumValue(com.webcohesion.enunciate.metadata.qname.XmlQNameEnumValue) XmlUnknownQNameEnumValue(com.webcohesion.enunciate.metadata.qname.XmlUnknownQNameEnumValue) XmlUnknownQNameEnumValue(com.webcohesion.enunciate.metadata.qname.XmlUnknownQNameEnumValue) VariableElement(javax.lang.model.element.VariableElement)

Example 39 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class JavaXMLClientModule method packageArtifacts.

protected File packageArtifacts(File sourceDir, File resourcesDir, File compileDir) {
    File packageDir = getPackageDir();
    packageDir.mkdirs();
    try {
        String jarName = getJarName();
        File clientJarFile = null;
        if (!isDisableCompile()) {
            clientJarFile = new File(packageDir, jarName);
            if (!isUpToDateWithSources(clientJarFile)) {
                if (isBundleSourcesWithClasses()) {
                    boolean anyFiles = this.enunciate.jar(clientJarFile, getManifest(), sourceDir, resourcesDir, compileDir);
                    if (!anyFiles) {
                        clientJarFile = null;
                    }
                } else {
                    boolean anyFiles = this.enunciate.jar(clientJarFile, getManifest(), resourcesDir, compileDir);
                    if (!anyFiles) {
                        clientJarFile = null;
                    }
                }
            } else {
                info("Skipping creation of Java client jar as everything appears up-to-date...");
            }
        }
        File clientSourcesJarFile = null;
        if (!isBundleSourcesWithClasses()) {
            clientSourcesJarFile = new File(packageDir, jarName.replaceFirst("\\.jar", "-xml-sources.jar"));
            if (!isUpToDateWithSources(clientSourcesJarFile)) {
                boolean anyFiles = this.enunciate.zip(clientSourcesJarFile, sourceDir, resourcesDir);
                if (!anyFiles) {
                    clientSourcesJarFile = null;
                }
            } else {
                info("Skipping creation of the Java client source jar as everything appears up-to-date...");
            }
        }
        ClientLibraryJavaArtifact artifactBundle = new ClientLibraryJavaArtifact(getName(), "java.xml.client.library", "Java XML Client Library");
        artifactBundle.setGroupId(getGroupId());
        artifactBundle.setArtifactId(getArtifactId());
        artifactBundle.setVersion(getVersion());
        artifactBundle.setPlatform("Java (Version 5+)");
        // read in the description from file:
        artifactBundle.setDescription((String) context.getProperty(LIRBARY_DESCRIPTION_PROPERTY));
        if (clientJarFile != null) {
            FileArtifact binariesJar = new FileArtifact(getName(), "java.xml.client.library.binaries", clientJarFile);
            binariesJar.setDescription("The binaries for the Java XML client library.");
            binariesJar.setPublic(false);
            binariesJar.setArtifactType(ArtifactType.binaries);
            artifactBundle.addArtifact(binariesJar);
            this.enunciate.addArtifact(binariesJar);
        }
        if (clientSourcesJarFile != null) {
            FileArtifact sourcesJar = new FileArtifact(getName(), "java.xml.client.library.sources", clientSourcesJarFile);
            sourcesJar.setDescription("The sources for the Java XML client library.");
            sourcesJar.setPublic(false);
            sourcesJar.setArtifactType(ArtifactType.sources);
            artifactBundle.addArtifact(sourcesJar);
            this.enunciate.addArtifact(sourcesJar);
        }
        if (clientJarFile != null || clientSourcesJarFile != null) {
            this.enunciate.addArtifact(artifactBundle);
        }
    } catch (IOException e) {
        throw new EnunciateException(e);
    }
    return packageDir;
}
Also used : ClientLibraryJavaArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryJavaArtifact) EnunciateException(com.webcohesion.enunciate.EnunciateException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact)

Example 40 with EnunciateException

use of com.webcohesion.enunciate.EnunciateException in project enunciate by stoicflame.

the class CXMLClientModule 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: C XML client will not be generated.");
        return;
    }
    if (usesUnmappableElements()) {
        warn("Web service API makes use of elements that cannot be handled by the C XML client. 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.");
    }
    File srcDir = getSourceDir();
    srcDir.mkdirs();
    Map<String, Object> model = new HashMap<String, Object>();
    String slug = getSlug();
    Map<String, String> ns2prefix = this.jaxbModule.getJaxbContext().getNamespacePrefixes();
    NameForTypeDefinitionMethod nameForTypeDefinition = new NameForTypeDefinitionMethod(getTypeDefinitionNamePattern(), slug, ns2prefix);
    model.put("nameForTypeDefinition", nameForTypeDefinition);
    model.put("nameForEnumConstant", new NameForEnumConstantMethod(getEnumConstantNamePattern(), slug, ns2prefix));
    TreeMap<String, String> conversions = new TreeMap<String, String>();
    for (SchemaInfo schemaInfo : this.jaxbModule.getJaxbContext().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(), "struct " + nameForTypeDefinition.calculateName(typeDefinition));
            }
        }
    }
    ClientClassnameForMethod classnameFor = new ClientClassnameForMethod(conversions, this.jaxbModule.getJaxbContext());
    model.put("classnameFor", classnameFor);
    String sourceFileName = getSourceFileName(slug);
    model.put("cFileName", sourceFileName);
    model.put("separateCommonCode", isSeparateCommonCode());
    model.put("findRootElement", new FindRootElementMethod(this.jaxbModule.getJaxbContext()));
    model.put("referencedNamespaces", new ReferencedNamespacesMethod(this.jaxbModule.getJaxbContext()));
    model.put("prefix", new PrefixMethod(ns2prefix));
    model.put("xmlFunctionIdentifier", new XmlFunctionIdentifierMethod(ns2prefix));
    model.put("accessorOverridesAnother", new AccessorOverridesAnotherMethod());
    model.put("filename", sourceFileName);
    model.put("file", new FileDirective(srcDir, this.enunciate.getLogger()));
    model.put("schemas", this.jaxbModule.getJaxbContext().getSchemas().values());
    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 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(), "c.client.library", "C Client Library");
    FileArtifact sourceScript = new FileArtifact(getName(), "c.client", new File(srcDir, sourceFileName));
    sourceScript.setArtifactType(ArtifactType.sources);
    sourceScript.setPublic(false);
    // read in the description from file
    String description = readResource("library_description.fmt", model, nameForTypeDefinition);
    artifactBundle.setDescription(description);
    artifactBundle.addArtifact(sourceScript);
    if (isSeparateCommonCode()) {
        FileArtifact commonSourceHeader = new FileArtifact(getName(), "c.common.client", new File(srcDir, "enunciate-common.c"));
        commonSourceHeader.setPublic(false);
        commonSourceHeader.setArtifactType(ArtifactType.sources);
        commonSourceHeader.setDescription("Common code needed for all projects.");
        artifactBundle.addArtifact(commonSourceHeader);
    }
    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) ReferencedNamespacesMethod(com.webcohesion.enunciate.modules.jaxb.util.ReferencedNamespacesMethod) EnunciateException(com.webcohesion.enunciate.EnunciateException) SchemaInfo(com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) AccessorOverridesAnotherMethod(com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) File(java.io.File)

Aggregations

EnunciateException (com.webcohesion.enunciate.EnunciateException)53 URL (java.net.URL)21 TemplateException (freemarker.template.TemplateException)19 IOException (java.io.IOException)16 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)12 File (java.io.File)12 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)11 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)8 DecoratedTypeMirror (com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror)7 TypeElement (javax.lang.model.element.TypeElement)7 TypeDefinition (com.webcohesion.enunciate.modules.jaxb.model.TypeDefinition)6 FindRootElementMethod (com.webcohesion.enunciate.modules.jaxb.util.FindRootElementMethod)6 IsFacetExcludedMethod (com.webcohesion.enunciate.util.freemarker.IsFacetExcludedMethod)6 VariableElement (javax.lang.model.element.VariableElement)6 EnunciateJacksonContext (com.webcohesion.enunciate.modules.jackson.EnunciateJacksonContext)5 TypeDefinition (com.webcohesion.enunciate.modules.jackson.model.TypeDefinition)5 EnunciateJackson1Context (com.webcohesion.enunciate.modules.jackson1.EnunciateJackson1Context)5 SchemaInfo (com.webcohesion.enunciate.modules.jaxb.model.SchemaInfo)5 AccessorOverridesAnotherMethod (com.webcohesion.enunciate.modules.jaxb.util.AccessorOverridesAnotherMethod)5 FileDirective (com.webcohesion.enunciate.util.freemarker.FileDirective)5