From 7be71fb8a418f63da2357afa10dca22523c5aa1c Mon Sep 17 00:00:00 2001 From: Paul Ferraro Date: Thu, 17 Oct 2024 18:35:39 +0100 Subject: [PATCH] Generic ExtensionTransformerRegistration implementation for subsystems using SubsystemModel enumerations. --- ...SubsystemModelTransformerRegistration.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 controller/src/main/java/org/jboss/as/controller/transform/SubsystemModelTransformerRegistration.java diff --git a/controller/src/main/java/org/jboss/as/controller/transform/SubsystemModelTransformerRegistration.java b/controller/src/main/java/org/jboss/as/controller/transform/SubsystemModelTransformerRegistration.java new file mode 100644 index 00000000000..9b90944c05e --- /dev/null +++ b/controller/src/main/java/org/jboss/as/controller/transform/SubsystemModelTransformerRegistration.java @@ -0,0 +1,52 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.jboss.as.controller.transform; + +import java.util.EnumSet; +import java.util.function.BiConsumer; + +import org.jboss.as.controller.ModelVersion; +import org.jboss.as.controller.SubsystemModel; +import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; +import org.jboss.as.controller.transform.description.TransformationDescription; + +/** + * A transformer registration of a single subsystem. + */ +public class SubsystemModelTransformerRegistration & SubsystemModel> implements ExtensionTransformerRegistration { + + private final String subsystemName; + private final E currentSubsystemModel; + private final BiConsumer transformation; + + /** + * Creates a transformer registration for a subsystem. + * @param subsystemName the subsystem name + * @param currentSubsystemModel the current subsystem model + * @param transformation a consumer that builds a transformer description for a given target model version + */ + public SubsystemModelTransformerRegistration(String subsystemName, E currentSubsystemModel, BiConsumer transformation) { + this.subsystemName = subsystemName; + this.currentSubsystemModel = currentSubsystemModel; + this.transformation = transformation; + } + + @Override + public String getSubsystemName() { + return this.subsystemName; + } + + @Override + public void registerTransformers(SubsystemTransformerRegistration registration) { + // Build and register transformation descriptions for all but the current subsystem model version + for (E model : EnumSet.complementOf(EnumSet.of(this.currentSubsystemModel))) { + ModelVersion version = model.getVersion(); + ResourceTransformationDescriptionBuilder builder = registration.createResourceTransformationDescriptionBuilder(); + this.transformation.accept(builder, version); + TransformationDescription.Tools.register(builder.build(), registration, version); + } + } +}