Search in sources :

Example 1 with EnunciateException

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

the class AnnotationValueMethod method exec.

/**
 * Returns the qname of the element that has the first parameter as the namespace, the second as the element.
 *
 * @param list The arguments.
 * @return The qname.
 */
public Object exec(List list) throws TemplateModelException {
    if (list.size() < 1) {
        throw new TemplateModelException("The annotationValue method must have a declaration as a parameter.");
    }
    TemplateModel from = (TemplateModel) list.get(0);
    Object unwrapped = DeepUnwrap.unwrap(from);
    String method = "value";
    if (list.size() > 1) {
        method = (String) DeepUnwrap.unwrap((TemplateModel) list.get(1));
    }
    if (unwrapped instanceof DecoratedAnnotationMirror) {
        return invoke(method, ((DecoratedAnnotationMirror) unwrapped));
    }
    throw new EnunciateException(String.format("Unsupported method %s on %s", method, unwrapped));
}
Also used : TemplateModelException(freemarker.template.TemplateModelException) DecoratedAnnotationMirror(com.webcohesion.enunciate.javac.decorations.element.DecoratedAnnotationMirror) EnunciateException(com.webcohesion.enunciate.EnunciateException) TemplateModel(freemarker.template.TemplateModel)

Example 2 with EnunciateException

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

the class JAXBUtil method getAdaptersOfPackage.

/**
 * Gets the adapters of the specified package.
 *
 * @param pckg the package for which to get the adapters.
 * @param context The context.
 * @return The adapters for the package.
 */
private static Map<String, XmlJavaTypeAdapter> getAdaptersOfPackage(PackageElement pckg, EnunciateJaxbContext context) {
    if (pckg == null) {
        return null;
    }
    Map<String, Map<String, XmlJavaTypeAdapter>> adaptersOfAllPackages = (Map<String, Map<String, XmlJavaTypeAdapter>>) context.getContext().getProperty(ADAPTERS_BY_PACKAGE_PROPERTY);
    if (adaptersOfAllPackages == null) {
        adaptersOfAllPackages = new HashMap<String, Map<String, XmlJavaTypeAdapter>>();
        context.getContext().setProperty(ADAPTERS_BY_PACKAGE_PROPERTY, adaptersOfAllPackages);
    }
    Map<String, XmlJavaTypeAdapter> adaptersOfPackage = adaptersOfAllPackages.get(pckg.getQualifiedName().toString());
    if (adaptersOfPackage == null) {
        adaptersOfPackage = new HashMap<String, XmlJavaTypeAdapter>();
        adaptersOfAllPackages.put(pckg.getQualifiedName().toString(), adaptersOfPackage);
        XmlJavaTypeAdapter javaType = pckg.getAnnotation(XmlJavaTypeAdapter.class);
        XmlJavaTypeAdapters javaTypes = pckg.getAnnotation(XmlJavaTypeAdapters.class);
        if ((javaType != null) || (javaTypes != null)) {
            ArrayList<XmlJavaTypeAdapter> allAdaptedTypes = new ArrayList<XmlJavaTypeAdapter>();
            if (javaType != null) {
                allAdaptedTypes.add(javaType);
            }
            if (javaTypes != null) {
                allAdaptedTypes.addAll(Arrays.asList(javaTypes.value()));
            }
            for (final XmlJavaTypeAdapter adaptedTypeInfo : allAdaptedTypes) {
                DecoratedTypeMirror typeMirror = Annotations.mirrorOf(new Callable<Class<?>>() {

                    @Override
                    public Class<?> call() throws Exception {
                        return adaptedTypeInfo.type();
                    }
                }, context.getContext().getProcessingEnvironment(), XmlJavaTypeAdapter.DEFAULT.class);
                if (typeMirror == null) {
                    throw new EnunciateException("Package " + pckg.getQualifiedName() + ": a type must be specified in " + XmlJavaTypeAdapter.class.getName() + " at the package-level.");
                }
                if (!(typeMirror instanceof DeclaredType)) {
                    throw new EnunciateException("Package " + pckg.getQualifiedName() + ": unadaptable type: " + typeMirror);
                }
                TypeElement typeDeclaration = (TypeElement) ((DeclaredType) typeMirror).asElement();
                if (typeDeclaration == null) {
                    throw new EnunciateException("Element not found: " + typeMirror);
                }
                adaptersOfPackage.put(typeDeclaration.getQualifiedName().toString(), adaptedTypeInfo);
            }
        }
    }
    return adaptersOfPackage;
}
Also used : DecoratedTypeMirror(com.webcohesion.enunciate.javac.decorations.type.DecoratedTypeMirror) TypeElement(javax.lang.model.element.TypeElement) XmlJavaTypeAdapter(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter) EnunciateException(com.webcohesion.enunciate.EnunciateException) EnunciateException(com.webcohesion.enunciate.EnunciateException) XmlJavaTypeAdapters(javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters) DecoratedDeclaredType(com.webcohesion.enunciate.javac.decorations.type.DecoratedDeclaredType) DeclaredType(javax.lang.model.type.DeclaredType)

Example 3 with EnunciateException

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

the class GWTJSONOverlayModule method packageArtifacts.

protected File packageArtifacts(File sourceDir) {
    File packageDir = getPackageDir();
    packageDir.mkdirs();
    try {
        String jarName = getJarName();
        File jarFile = new File(packageDir, jarName);
        if (!isUpToDateWithSources(jarFile)) {
            boolean anyFiles = this.enunciate.jar(jarFile, getManifest(), sourceDir);
            if (!anyFiles) {
                jarFile = null;
            }
        } else {
            info("Skipping creation of the GWT overlay source jar as everything appears up-to-date...");
        }
        ClientLibraryJavaArtifact artifactBundle = new ClientLibraryJavaArtifact(getName(), "gwt.json.overlay", "GWT JSON Overlay");
        artifactBundle.setGroupId(getGroupId());
        artifactBundle.setArtifactId(getArtifactId());
        artifactBundle.setVersion(getVersion());
        artifactBundle.setPlatform("Google Web Toolkit");
        // read in the description from file:
        artifactBundle.setDescription((String) context.getProperty(LIRBARY_DESCRIPTION_PROPERTY));
        FileArtifact sourcesJar = new FileArtifact(getName(), "gwt.json.overlay.sources", jarFile);
        sourcesJar.setDescription("The sources for the GWT JSON overlay.");
        sourcesJar.setPublic(false);
        sourcesJar.setArtifactType(ArtifactType.sources);
        artifactBundle.addArtifact(sourcesJar);
        this.enunciate.addArtifact(sourcesJar);
        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) IOException(java.io.IOException) File(java.io.File)

Example 4 with EnunciateException

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

the class IDLModule method getSchemaConfigs.

public Map<String, SchemaConfig> getSchemaConfigs() {
    HashMap<String, SchemaConfig> configs = new HashMap<String, SchemaConfig>();
    List<HierarchicalConfiguration> schemas = this.config.configurationsAt("schema");
    for (HierarchicalConfiguration schema : schemas) {
        SchemaConfig schemaConfig = new SchemaConfig();
        schemaConfig.setAppinfo(schema.getString("[@appinfo]", null));
        schemaConfig.setFilename(schema.getString("[@filename]", null));
        schemaConfig.setJaxbBindingVersion(schema.getString("[@jaxbBindingVersion]", null));
        schemaConfig.setLocation(schema.getString("[@location]", null));
        String ns = schema.getString("[@namespace]", null);
        if ("".equals(ns)) {
            // default namspace to be represented as null.
            ns = null;
        }
        schemaConfig.setNamespace(ns);
        String useFile = schema.getString("[@useFile]", null);
        if (useFile != null) {
            File file = resolveFile(useFile);
            if (!file.exists()) {
                throw new EnunciateException(String.format("Invalid schema config: file %s does not exist.", useFile));
            }
            schemaConfig.setUseFile(file);
        }
        configs.put(schemaConfig.getNamespace(), schemaConfig);
    }
    return configs;
}
Also used : EnunciateException(com.webcohesion.enunciate.EnunciateException) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) StaticInterfaceDescriptionFile(com.webcohesion.enunciate.util.StaticInterfaceDescriptionFile) File(java.io.File)

Example 5 with EnunciateException

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

the class JavaJSONClientModule method packageArtifacts.

protected File packageArtifacts(File sourceDir, 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, compileDir);
                    if (!anyFiles) {
                        clientJarFile = null;
                    }
                } else {
                    boolean anyFiles = this.enunciate.jar(clientJarFile, getManifest(), 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", "-json-sources.jar"));
            if (!isUpToDateWithSources(clientSourcesJarFile)) {
                boolean anyFiles = this.enunciate.zip(clientSourcesJarFile, sourceDir);
                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.json.client.library", "Java JSON 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.json.client.library.binaries", clientJarFile);
            binariesJar.setDescription("The binaries for the Java JSON 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.json.client.library.sources", clientSourcesJarFile);
            sourcesJar.setDescription("The sources for the Java JSON 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)

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