use of org.glassfish.admin.rest.composite.RestModelExtension in project Payara by payara.
the class RestModelExtensionProcessor method process.
@Override
public boolean process(Set<? extends TypeElement> elements, RoundEnvironment env) {
Messager messager = processingEnv.getMessager();
BufferedWriter bw = null;
try {
Map<String, List<String>> classes = new HashMap<String, List<String>>();
for (TypeElement te : elements) {
for (Element e : env.getElementsAnnotatedWith(te)) {
final RestModelExtension annotation = e.getAnnotation(RestModelExtension.class);
final String parent = annotation.parent();
List<String> list = classes.get(parent);
if (list == null) {
list = new ArrayList<String>();
classes.put(parent, list);
}
list.add(e.toString());
}
}
if (!classes.isEmpty()) {
final Filer filer = processingEnv.getFiler();
FileObject fo = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/restmodelextensions");
bw = new BufferedWriter(fo.openWriter());
// parent model:model extension
for (Map.Entry<String, List<String>> entry : classes.entrySet()) {
final String key = entry.getKey();
for (String ext : entry.getValue()) {
bw.write(key + ":" + ext + "\n");
}
}
bw.close();
}
} catch (IOException ex) {
messager.printMessage(Kind.ERROR, ex.getLocalizedMessage());
if (bw != null) {
try {
bw.close();
} catch (Exception e) {
}
}
}
return true;
}
Aggregations