-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic ExtensionTransformerRegistration implementation for subsystem…
…s using SubsystemModel enumerations.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...rc/main/java/org/jboss/as/controller/transform/SubsystemModelTransformerRegistration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<E extends Enum<E> & SubsystemModel> implements ExtensionTransformerRegistration { | ||
|
||
private final String subsystemName; | ||
private final E currentSubsystemModel; | ||
private final BiConsumer<ResourceTransformationDescriptionBuilder, ModelVersion> 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<ResourceTransformationDescriptionBuilder, ModelVersion> 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); | ||
} | ||
} | ||
} |