Search in sources :

Example 1 with GenerationException

use of org.raml.jaxrs.generator.GenerationException in project raml-for-jax-rs by mulesoft-labs.

the class ExtensionManager method classList.

private static List<Class> classList(String name, String property) {
    List<Class> classes = new ArrayList<>();
    for (String s : property.split("\\s*,\\s*")) {
        try {
            Class foundClass = Class.forName(s);
            classes.add(foundClass);
        } catch (ClassNotFoundException e) {
            throw new GenerationException("class " + s + " not found for plugin name " + name);
        }
    }
    return classes;
}
Also used : GenerationException(org.raml.jaxrs.generator.GenerationException)

Example 2 with GenerationException

use of org.raml.jaxrs.generator.GenerationException in project raml-for-jax-rs by mulesoft-labs.

the class JAXBHelper method generateClassesFromXmlSchemas.

private static List<JDefinedClass> generateClassesFromXmlSchemas(String pack, JCodeModel codeModel, File schemaFile) throws GenerationException {
    try {
        ArrayList<JDefinedClass> classList = new ArrayList<JDefinedClass>();
        ArrayList<String> argList = new ArrayList<>();
        argList.add("-mark-generated");
        argList.add("-p");
        argList.add(pack);
        argList.add(schemaFile.getAbsolutePath());
        String[] args = argList.toArray(new String[argList.size()]);
        final Options opt = new Options();
        opt.setSchemaLanguage(Language.XMLSCHEMA);
        opt.parseArguments(args);
        ErrorReceiver receiver = new ErrorReceiverFilter() {

            @Override
            public void info(SAXParseException exception) {
                if (opt.verbose)
                    super.info(exception);
            }

            @Override
            public void warning(SAXParseException exception) {
                if (!opt.quiet)
                    super.warning(exception);
            }
        };
        Model model = ModelLoader.load(opt, codeModel, receiver);
        Outline outline = model.generateCode(opt, receiver);
        for (ClassOutline co : outline.getClasses()) {
            JDefinedClass cl = co.implClass;
            if (cl.outer() == null) {
                classList.add(cl);
            }
        }
        return classList;
    } catch (Exception e) {
        throw new GenerationException(e);
    }
}
Also used : Options(com.sun.tools.xjc.Options) JDefinedClass(com.sun.codemodel.JDefinedClass) ArrayList(java.util.ArrayList) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) Outline(com.sun.tools.xjc.outline.Outline) ErrorReceiver(com.sun.tools.xjc.ErrorReceiver) IOException(java.io.IOException) GenerationException(org.raml.jaxrs.generator.GenerationException) SAXParseException(org.xml.sax.SAXParseException) ClassOutline(com.sun.tools.xjc.outline.ClassOutline) ErrorReceiverFilter(com.sun.tools.xjc.util.ErrorReceiverFilter) SAXParseException(org.xml.sax.SAXParseException) Model(com.sun.tools.xjc.model.Model) JCodeModel(com.sun.codemodel.JCodeModel) GenerationException(org.raml.jaxrs.generator.GenerationException)

Example 3 with GenerationException

use of org.raml.jaxrs.generator.GenerationException in project raml-for-jax-rs by mulesoft-labs.

the class ContextImpl method rename.

@Override
public TypeSpec.Builder rename(TypeSpec.Builder builder, String name) {
    TypeSpec type = builder.build();
    TypeSpec.Builder newType;
    switch(type.kind) {
        case ANNOTATION:
            newType = TypeSpec.annotationBuilder(name);
            break;
        case ENUM:
            newType = TypeSpec.enumBuilder(name);
            break;
        case INTERFACE:
            newType = TypeSpec.interfaceBuilder(name);
            break;
        case CLASS:
            newType = TypeSpec.classBuilder(name);
            break;
        default:
            throw new GenerationException("this can't happen...");
    }
    for (AnnotationSpec annotation : type.annotations) {
        newType.addAnnotation(annotation);
    }
    for (Modifier modifier : type.modifiers) {
        newType.addModifiers(modifier);
    }
    for (TypeVariableName typeVariable : type.typeVariables) {
        newType.addTypeVariable(typeVariable);
    }
    for (TypeName typeVariable : type.superinterfaces) {
        newType.addSuperinterface(typeVariable);
    }
    for (FieldSpec fieldSpec : type.fieldSpecs) {
        newType.addField(fieldSpec);
    }
    for (MethodSpec methodSpec : type.methodSpecs) {
        newType.addMethod(methodSpec);
    }
    for (TypeSpec typeSpec : type.typeSpecs) {
        newType.addType(typeSpec);
    }
    for (Map.Entry<String, TypeSpec> enumConstant : type.enumConstants.entrySet()) {
        newType.addEnumConstant(enumConstant.getKey(), enumConstant.getValue());
    }
    if (type.javadoc != null) {
        newType.addJavadoc("$L", type.javadoc);
    }
    if (type.superclass != null) {
        newType.superclass(type.superclass);
    }
    if (type.staticBlock != null && !type.staticBlock.isEmpty()) {
        newType.addStaticBlock(type.staticBlock);
    }
    if (type.initializerBlock != null && !type.initializerBlock.isEmpty()) {
        newType.addInitializerBlock(type.initializerBlock);
    }
    return newType;
}
Also used : GenerationException(org.raml.jaxrs.generator.GenerationException) Modifier(javax.lang.model.element.Modifier) Map(java.util.Map)

Example 4 with GenerationException

use of org.raml.jaxrs.generator.GenerationException in project raml-for-jax-rs by mulesoft-labs.

the class ContextImpl method rename.

@Override
public MethodSpec.Builder rename(MethodSpec.Builder builder, String name) {
    MethodSpec method = builder.build();
    if (method.isConstructor()) {
        throw new GenerationException("Can't rename a constructor: " + name);
    }
    MethodSpec.Builder newBuilder = MethodSpec.methodBuilder(name);
    for (AnnotationSpec annotation : method.annotations) {
        newBuilder.addAnnotation(annotation);
    }
    for (Modifier modifier : method.modifiers) {
        newBuilder.addModifiers(modifier);
    }
    for (TypeVariableName typeVariable : method.typeVariables) {
        newBuilder.addTypeVariable(typeVariable);
    }
    for (ParameterSpec parameter : method.parameters) {
        newBuilder.addParameter(parameter);
    }
    for (TypeName exception : method.exceptions) {
        newBuilder.addException(exception);
    }
    if (method.code != null) {
        newBuilder.addCode(method.code);
    }
    if (method.defaultValue != null) {
        newBuilder.defaultValue(method.defaultValue);
    }
    if (method.returnType != null) {
        newBuilder.returns(method.returnType);
    }
    if (method.javadoc != null) {
        newBuilder.addJavadoc("$L", method.javadoc);
    }
    newBuilder.varargs(method.varargs);
    return newBuilder;
}
Also used : GenerationException(org.raml.jaxrs.generator.GenerationException) Modifier(javax.lang.model.element.Modifier)

Example 5 with GenerationException

use of org.raml.jaxrs.generator.GenerationException in project raml-for-jax-rs by mulesoft-labs.

the class ExtensionManager method createExtensionManager.

static ExtensionManager createExtensionManager(String pluginFileName) {
    try {
        SetMultimap<String, Class> info = LinkedHashMultimap.create();
        Enumeration<URL> resourcesFiles = ExtensionManager.class.getClassLoader().getResources(pluginFileName);
        while (resourcesFiles.hasMoreElements()) {
            URL url = resourcesFiles.nextElement();
            Properties properties = new Properties();
            loadProperties(url, properties);
            buildPluginNames(info, properties);
        }
        return new ExtensionManager(info);
    } catch (IOException e) {
        throw new GenerationException(e);
    }
}
Also used : GenerationException(org.raml.jaxrs.generator.GenerationException) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

GenerationException (org.raml.jaxrs.generator.GenerationException)5 IOException (java.io.IOException)2 Modifier (javax.lang.model.element.Modifier)2 JCodeModel (com.sun.codemodel.JCodeModel)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 ErrorReceiver (com.sun.tools.xjc.ErrorReceiver)1 Options (com.sun.tools.xjc.Options)1 Model (com.sun.tools.xjc.model.Model)1 ClassOutline (com.sun.tools.xjc.outline.ClassOutline)1 Outline (com.sun.tools.xjc.outline.Outline)1 ErrorReceiverFilter (com.sun.tools.xjc.util.ErrorReceiverFilter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 SAXParseException (org.xml.sax.SAXParseException)1