}
@Override
public void postProcessEvents(ApplicationMetaModel metaModel) {
ElementHandle.Package packageHandle = metaModel.getHandle();
JSON config = enableMap.get(packageHandle);
if (config != null) {
ControllersMetaModel controllersModel = metaModel.getChild(ControllersMetaModel.KEY);
for (ControllerMetaModel controller : controllersModel) {
Map<AnnotationKey, AnnotationState> annotations = controllers.get(controller.getHandle());
if (annotations != null) {
JSON controllerJSON = new JSON();
config.set(controller.getHandle().getName().toString(), controllerJSON);
for (Map.Entry<AnnotationKey, AnnotationState> entry : annotations.entrySet()) {
AnnotationKey key = entry.getKey();
if (controllerJSON.get("require") != null) {
throw new UnsupportedOperationException("Unsupported multiple requirements at " + key.getElement());
}
if (key.getType().equals(Name.create(RequiresGuest.class))) {
controllerJSON.set("require", "guest");
} else if (key.getType().equals(Name.create(RequiresAuthentication.class))) {
controllerJSON.set("require", "authenticate");
} else if (key.getType().equals(Name.create(RequiresUser.class))) {
controllerJSON.set("require", "user");
}
}
}
for (HandlerMetaModel handler : controller) {
annotations = methods.get(handler.getMethod());
String methodId = handler.getMethod().getMethodHandle().toString();
if (annotations != null) {
JSON controllerJSON = config.getJSON(controller.getHandle().getName().toString());
if (controllerJSON == null) {
controllerJSON = new JSON();
config.set(controller.getHandle().getName().toString(), controllerJSON);
}
JSON methodJSON = new JSON();;
for (Map.Entry<AnnotationKey, AnnotationState> entry : annotations.entrySet()) {
emitConfig(methodJSON, entry.getKey(), entry.getValue());
}
JSON methodsJSON = controllerJSON.getJSON("methods");
if (methodsJSON == null) {
methodsJSON = new JSON();
controllerJSON.set("methods", methodsJSON);
}
methodsJSON.set(methodId.substring(methodId.lastIndexOf('#') + 1), methodJSON);
}
}
}
}
}