-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue_14] Refactor the subsystem to use wildfly-subsystem
This brings also the stability=preview concept into the xml handling
- Loading branch information
1 parent
9254f2c
commit 41939cf
Showing
13 changed files
with
222 additions
and
154 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
|
@@ -6,103 +6,110 @@ | |
|
||
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; | ||
|
||
import java.util.List; | ||
|
||
import javax.xml.stream.XMLStreamConstants; | ||
import javax.xml.stream.XMLStreamException; | ||
|
||
import org.jboss.as.controller.Extension; | ||
import org.jboss.as.controller.ExtensionContext; | ||
import org.jboss.as.controller.ModelVersion; | ||
import org.jboss.as.controller.PathAddress; | ||
import org.jboss.as.controller.PathElement; | ||
import org.jboss.as.controller.PersistentResourceXMLDescription; | ||
import org.jboss.as.controller.SubsystemRegistration; | ||
import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; | ||
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; | ||
import org.jboss.as.controller.parsing.ExtensionParsingContext; | ||
import org.jboss.as.controller.persistence.SubsystemMarshallingContext; | ||
import org.jboss.as.controller.registry.ManagementResourceRegistration; | ||
import org.jboss.dmr.ModelNode; | ||
import org.jboss.staxmapper.XMLElementReader; | ||
import org.jboss.staxmapper.XMLElementWriter; | ||
import org.jboss.staxmapper.XMLExtendedStreamReader; | ||
import org.jboss.staxmapper.XMLExtendedStreamWriter; | ||
import org.jboss.as.controller.PersistentSubsystemSchema; | ||
import org.jboss.as.controller.SubsystemModel; | ||
import org.jboss.as.controller.SubsystemSchema; | ||
import org.jboss.as.controller.xml.VersionedNamespace; | ||
import org.jboss.as.version.Stability; | ||
import org.jboss.staxmapper.IntVersion; | ||
import org.wildfly.subsystem.SubsystemConfiguration; | ||
import org.wildfly.subsystem.SubsystemExtension; | ||
import org.wildfly.subsystem.SubsystemPersistence; | ||
|
||
|
||
/** | ||
* WildFly extension that provides Jakarta MVC support based on Eclipse Krazo. | ||
* | ||
* @author <a href="mailto:[email protected]">Brian Stansberry</a> | ||
*/ | ||
public final class MVCKrazoExtension implements Extension { | ||
|
||
/** | ||
* The name space used for the {@code substystem} element | ||
*/ | ||
public static final String NAMESPACE = "urn:jboss:domain:mvc-krazo:1.0"; | ||
public final class MVCKrazoExtension extends SubsystemExtension<MVCKrazoExtension.MVCKrazoSubsystemSchema> { | ||
|
||
/** | ||
* The name of our subsystem within the model. | ||
*/ | ||
public static final String SUBSYSTEM_NAME = "mvc-krazo"; | ||
|
||
/** | ||
* The parser used for parsing our subsystem | ||
*/ | ||
private final SubsystemParser parser = new SubsystemParser(); | ||
static final String SUBSYSTEM_NAME = "mvc-krazo"; | ||
private static final Stability FEATURE_STABILITY = Stability.PREVIEW; | ||
|
||
static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME); | ||
private static final String RESOURCE_NAME = MVCKrazoExtension.class.getPackage().getName() + ".LocalDescriptions"; | ||
|
||
static StandardResourceDescriptionResolver getResourceDescriptionResolver() { | ||
return new StandardResourceDescriptionResolver(SUBSYSTEM_NAME, RESOURCE_NAME, MVCKrazoExtension.class.getClassLoader(), true, false); | ||
public MVCKrazoExtension() { | ||
super(SubsystemConfiguration.of(SUBSYSTEM_NAME, MVCKrazoSubsystemModel.CURRENT, MVCKrazoSubsystemRegistrar::new), | ||
SubsystemPersistence.of(MVCKrazoSubsystemSchema.CURRENT)); | ||
} | ||
|
||
@Override | ||
public void initializeParsers(ExtensionParsingContext context) { | ||
context.setSubsystemXmlMapping(SUBSYSTEM_NAME, NAMESPACE, parser); | ||
} | ||
// TODO enable this when WildFly Galleon Plugin can handle it | ||
// @Override | ||
// public Stability getStability() { | ||
// return FEATURE_STABILITY; | ||
// } | ||
|
||
/** | ||
* Model for the 'mvc-krazo' subsystem. | ||
*/ | ||
public enum MVCKrazoSubsystemModel implements SubsystemModel { | ||
VERSION_1_0_0(1, 0, 0), | ||
; | ||
|
||
static final MVCKrazoSubsystemModel CURRENT = VERSION_1_0_0; | ||
|
||
@Override | ||
public void initialize(ExtensionContext context) { | ||
final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, ModelVersion.create(1, 0)); | ||
final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(MVCKrazoSubsystemDefinition.INSTANCE); | ||
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE); | ||
private final ModelVersion version; | ||
|
||
subsystem.registerXMLElementWriter(parser); | ||
MVCKrazoSubsystemModel(int major, int minor, int micro) { | ||
this.version = ModelVersion.create(major, minor, micro); | ||
} | ||
|
||
@Override | ||
public ModelVersion getVersion() { | ||
return this.version; | ||
} | ||
} | ||
|
||
/** | ||
* The subsystem parser, which uses stax to read and write to and from xml. | ||
* Schema for the 'mvc-krazo' subsystem. | ||
*/ | ||
private static class SubsystemParser implements XMLStreamConstants, XMLElementReader<List<ModelNode>>, XMLElementWriter<SubsystemMarshallingContext> { | ||
public enum MVCKrazoSubsystemSchema implements PersistentSubsystemSchema<MVCKrazoSubsystemSchema> { | ||
|
||
private final PersistentResourceXMLDescription xmlDescription; | ||
/* urn:jboss:domain variant from WF Preview 31 | ||
It wasn't really DEFAULT stability, but its namespace didn't include 'preview' | ||
so we work around that. See also getStability(). */ | ||
VERSION_1_0_LEGACY(1, 0, Stability.DEFAULT, true), | ||
// first urn:wildfly variant | ||
VERSION_1_1_PREVIEW(1, 1, FEATURE_STABILITY), | ||
; | ||
|
||
private SubsystemParser() { | ||
this.xmlDescription = PersistentResourceXMLDescription.builder(MVCKrazoSubsystemDefinition.INSTANCE.getPathElement()) | ||
.build(); | ||
static final MVCKrazoSubsystemSchema CURRENT = VERSION_1_1_PREVIEW; | ||
|
||
private final VersionedNamespace<IntVersion, MVCKrazoSubsystemSchema> namespace; | ||
|
||
MVCKrazoSubsystemSchema(int major, int minor, Stability stability) { | ||
this(major, minor, stability, false); | ||
} | ||
MVCKrazoSubsystemSchema(int major, int minor, Stability stability, boolean legacy) { | ||
if (legacy) { | ||
this.namespace = SubsystemSchema.createLegacySubsystemURN(SUBSYSTEM_NAME, stability, new IntVersion(major, minor)); | ||
} else { | ||
this.namespace = SubsystemSchema.createSubsystemURN(SUBSYSTEM_NAME, stability, new IntVersion(major, minor)); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { | ||
ModelNode model = new ModelNode(); | ||
model.get(MVCKrazoSubsystemDefinition.INSTANCE.getPathElement().getKeyValuePair()).set(context.getModelNode()); | ||
xmlDescription.persist(writer, model, MVCKrazoExtension.NAMESPACE); | ||
public VersionedNamespace<IntVersion, MVCKrazoSubsystemSchema> getNamespace() { | ||
return this.namespace; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException { | ||
xmlDescription.parse(reader, PathAddress.EMPTY_ADDRESS, list); | ||
public Stability getStability() { | ||
return this == VERSION_1_0_LEGACY ? Stability.PREVIEW : this.getNamespace().getStability(); | ||
} | ||
} | ||
|
||
@Override | ||
public PersistentResourceXMLDescription getXMLDescription() { | ||
PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this); | ||
return factory.builder(SUBSYSTEM_PATH) | ||
.build(); | ||
} | ||
} | ||
} |
78 changes: 0 additions & 78 deletions
78
subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemDefinition.java
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
subsystem/src/main/java/org/wildfly/extension/mvc/krazo/MVCKrazoSubsystemRegistrar.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,59 @@ | ||
/* | ||
* Copyright The WildFly Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.wildfly.extension.mvc.krazo; | ||
|
||
import static org.wildfly.extension.mvc.krazo.MVCKrazoExtension.SUBSYSTEM_NAME; | ||
import static org.wildfly.extension.mvc.krazo.MVCKrazoExtension.SUBSYSTEM_PATH; | ||
|
||
import org.jboss.as.controller.ResourceDefinition; | ||
import org.jboss.as.controller.ResourceRegistration; | ||
import org.jboss.as.controller.SubsystemRegistration; | ||
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver; | ||
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver; | ||
import org.jboss.as.controller.registry.ManagementResourceRegistration; | ||
import org.jboss.as.controller.registry.RuntimePackageDependency; | ||
import org.jboss.as.server.DeploymentProcessorTarget; | ||
import org.wildfly.subsystem.resource.ManagementResourceRegistrar; | ||
import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext; | ||
import org.wildfly.subsystem.resource.ResourceDescriptor; | ||
import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar; | ||
|
||
/** | ||
* Resource definition for the mvc-krazo subsystem root resource. | ||
* | ||
* @author <a href="mailto:[email protected]">Brian Stansberry</a> | ||
*/ | ||
final class MVCKrazoSubsystemRegistrar implements SubsystemResourceDefinitionRegistrar { | ||
|
||
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME, MVCKrazoSubsystemRegistrar.class); | ||
|
||
static final String MVC_API = "jakarta.mvc.api"; | ||
static final String KRAZO_CORE = "org.eclipse.krazo.core"; | ||
static final String KRAZO_RESTEASY = "org.eclipse.krazo.resteasy"; | ||
|
||
@Override | ||
public ManagementResourceRegistration register(SubsystemRegistration parent, ManagementResourceRegistrationContext managementResourceRegistrationContext) { | ||
ResourceDefinition definition = ResourceDefinition.builder(ResourceRegistration.of(SUBSYSTEM_PATH), RESOLVER).build(); | ||
ManagementResourceRegistration registration = parent.registerSubsystemModel(definition); | ||
ResourceDescriptor descriptor = ResourceDescriptor.builder(RESOLVER) | ||
.withDeploymentChainContributor(MVCKrazoSubsystemRegistrar::registerDeploymentUnitProcessors) | ||
.build(); | ||
ManagementResourceRegistrar.of(descriptor).register(registration); | ||
registration.registerAdditionalRuntimePackages( | ||
RuntimePackageDependency.required(MVC_API), | ||
RuntimePackageDependency.required(KRAZO_CORE), | ||
RuntimePackageDependency.required(KRAZO_RESTEASY) | ||
); | ||
return registration; | ||
} | ||
|
||
private static void registerDeploymentUnitProcessors(DeploymentProcessorTarget processorTarget) { | ||
processorTarget.addDeploymentProcessor(MVCKrazoExtension.SUBSYSTEM_NAME, | ||
DeploymentDependenciesProcessor.PHASE, | ||
DeploymentDependenciesProcessor.PRIORITY, | ||
new DeploymentDependenciesProcessor()); | ||
} | ||
|
||
} |
Oops, something went wrong.