use of org.jboss.hal.spi.Requires in project console by hal.
the class RequiredResourcesProcessor method onProcess.
@Override
protected boolean onProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (Element e : roundEnv.getElementsAnnotatedWith(Requires.class)) {
TypeElement requiredElement = (TypeElement) e;
Requires requires = requiredElement.getAnnotation(Requires.class);
// Get the related id. Currently @Requires can be placed at named proxies or (async) columns
String id = null;
NameToken token = requiredElement.getAnnotation(NameToken.class);
if (token != null) {
id = token.value()[0];
} else {
AsyncColumn asyncColumn = requiredElement.getAnnotation(AsyncColumn.class);
if (asyncColumn != null) {
id = asyncColumn.value();
} else {
Column column = requiredElement.getAnnotation(Column.class);
if (column != null) {
id = column.value();
}
}
}
// noinspection ConstantConditions
if (id != null) {
RequiredInfo requiredInfo = new RequiredInfo(id, requiredElement);
requiredInfo.addResources(requires.value());
requiredInfo.setRecursive(requires.recursive());
if (requiredInfos.containsKey(id)) {
RequiredInfo other = requiredInfos.get(id);
if (!requiredInfo.getResources().equals(other.getResources())) {
error(requiredElement, "Different required resources for the same id \"%s\". This class conflicts with %s", id, other.source.getQualifiedName());
}
}
requiredInfos.put(id, requiredInfo);
}
}
if (!requiredInfos.isEmpty()) {
debug("Generating code for required resources registry");
code(REQUIRED_RESOURCES_TEMPLATE, REQUIRED_RESOURCES_PACKAGE, REQUIRED_RESOURCES_CLASS, context(REQUIRED_RESOURCES_PACKAGE, REQUIRED_RESOURCES_CLASS));
List<RegistryBinding> bindings = ImmutableList.of(new RegistryBinding(REQUIRED_RESOURCES_PACKAGE + ".RequiredResources", REQUIRED_RESOURCES_PACKAGE + "." + REQUIRED_RESOURCES_CLASS));
debug("Generating code for registry module");
code(REGISTRY_MODULE_TEMPLATE, REGISTRY_MODULE_PACKAGE, REGISTRY_MODULE_CLASS, () -> {
Map<String, Object> context = new HashMap<>();
context.put(GENERATED_WITH, RequiredResourcesProcessor.class.getName());
context.put(PACKAGE_NAME, REGISTRY_MODULE_PACKAGE);
context.put(CLASS_NAME, REGISTRY_MODULE_CLASS);
context.put("bindings", bindings);
return context;
});
info("Successfully generated required resources registry [%s] and related module [%s].", REQUIRED_RESOURCES_CLASS, REGISTRY_MODULE_CLASS);
requiredInfos.clear();
}
return false;
}
use of org.jboss.hal.spi.Requires in project console by hal.
the class ClusteringPresenter method showBroadcastOrDiscoveryGroupAddDialog.
void showBroadcastOrDiscoveryGroupAddDialog(ServerSubResource ssr, Consumer<ModelNodeForm.Builder<ModelNode>> formBuilderAugmenter, Consumer<Form<ModelNode>> formAugmenter) {
Metadata metadata = metadataRegistry.lookup(ssr.template);
NameItem nameItem = new NameItem();
ModelNodeForm.Builder<ModelNode> formBuilder = new ModelNodeForm.Builder<>(Ids.build(ssr.baseId, Ids.ADD), metadata).unboundFormItem(nameItem, 0).fromRequestProperties().include(JGROUPS_CLUSTER, SOCKET_BINDING).unsorted();
formBuilderAugmenter.accept(formBuilder);
Form<ModelNode> form = formBuilder.build();
formAugmenter.accept(form);
// validation that requires one of jgroups-cluster and socket-binding to be configured
FormValidation<ModelNode> jgroupsOrSocketValidation = new FormValidation<ModelNode>() {
@Override
public ValidationResult validate(Form<ModelNode> form) {
if (form.getFormItem(JGROUPS_CLUSTER).isEmpty() && form.getFormItem(SOCKET_BINDING).isEmpty()) {
return ValidationResult.invalid(resources.messages().jgroupsClusterOrSocketBindingMustBeSet());
}
return ValidationResult.OK;
}
};
form.getFormItem(SOCKET_BINDING).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, SOCKET_BINDING_TEMPLATE));
form.addFormValidation(jgroupsOrSocketValidation);
new AddResourceDialog(resources.messages().addResourceTitle(ssr.type), form, (name, model) -> {
name = nameItem.getValue();
ResourceAddress address = SELECTED_SERVER_TEMPLATE.append(ssr.resource + "=" + name).resolve(statementContext);
crud.add(ssr.type, name, address, model, (n, a) -> reload());
}).show();
}
Aggregations