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;
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations