Skip to content

Commit 1ddc349

Browse files
committed
Generalize PersistentSubsystemSchema as a SubsystemResourceXMLSchema.
Deprecate PersistentResourceXMLDescription and its reader/writer in favour of SubsystemResourceXMLElement.
1 parent f7ecfe2 commit 1ddc349

7 files changed

+257
-14
lines changed

controller/src/main/java/org/jboss/as/controller/PersistentResourceDefinition.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
* simplify the process of creating parsers and persisters.
2121
*
2222
* @author <a href="mailto:[email protected]">Tomaz Cerar</a> (c) 2013 Red Hat Inc.
23+
* @deprecated Build {@link ResourceDefinition} via {@link ResourceDefinition#builder(ResourceRegistration, ResourceDescriptionResolver)} or extend {@link SimpleResourceDefinition} directly.
2324
*/
25+
@Deprecated(forRemoval = true, since = "28.0")
2426
public abstract class PersistentResourceDefinition extends SimpleResourceDefinition {
2527

2628
protected PersistentResourceDefinition(PathElement pathElement, ResourceDescriptionResolver descriptionResolver) {

controller/src/main/java/org/jboss/as/controller/PersistentResourceXMLDescription.java

+7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
*
4242
* @author Tomaz Cerar
4343
* @author Stuart Douglas
44+
* @deprecated Superseded by {@link org.jboss.as.controller.persistence.xml.ResourceXMLParticleFactory}
4445
*/
46+
@Deprecated(forRemoval = true, since = "28.0")
4547
public final class PersistentResourceXMLDescription implements ResourceParser, ResourceMarshaller {
4648

4749
private final PathElement pathElement;
@@ -133,13 +135,18 @@ public PathElement getPathElement() {
133135
return this.pathElement;
134136
}
135137

138+
String getNamespaceURI() {
139+
return this.namespaceURI;
140+
}
141+
136142
/**
137143
* Parse xml from provided <code>reader</code> and add resulting operations to passed list
138144
* @param reader xml reader to parse from
139145
* @param parentAddress address of the parent, used as base for all child elements
140146
* @param list list of operations where result will be put to.
141147
* @throws XMLStreamException if any error occurs while parsing
142148
*/
149+
@Override
143150
public void parse(final XMLExtendedStreamReader reader, PathAddress parentAddress, List<ModelNode> list) throws XMLStreamException {
144151
if (decoratorElement != null) {
145152
parseDecorator(reader, parentAddress, list);

controller/src/main/java/org/jboss/as/controller/PersistentResourceXMLDescriptionReader.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
/**
1818
* An {@link XMLElementReader} based on a {@link PersistentResourceXMLDescription}.
1919
* @author Paul Ferraro
20+
* @deprecated Superseded by {@link org.jboss.as.controller.persistence.xml.SubsystemResourceXMLElementReader}.
2021
*/
22+
@Deprecated(forRemoval = true, since = "28.0")
2123
public class PersistentResourceXMLDescriptionReader implements XMLElementReader<List<ModelNode>> {
2224
private final Supplier<PersistentResourceXMLDescription> description;
2325

controller/src/main/java/org/jboss/as/controller/PersistentResourceXMLDescriptionWriter.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
/**
1818
* An {@link XMLElementWriter} based on a {@link PersistentResourceXMLDescription}.
1919
* @author Paul Ferraro
20+
* @deprecated Superseded by {@link org.jboss.as.controller.persistence.xml.SubsystemResourceXMLElementWriter}.
2021
*/
22+
@Deprecated(forRemoval = true, since = "28.0")
2123
public class PersistentResourceXMLDescriptionWriter implements XMLElementWriter<SubsystemMarshallingContext> {
2224
private final Supplier<PersistentResourceXMLDescription> description;
2325

controller/src/main/java/org/jboss/as/controller/PersistentSubsystemSchema.java

+221-3
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,242 @@
44
*/
55
package org.jboss.as.controller;
66

7+
import java.util.AbstractCollection;
8+
import java.util.Collection;
9+
import java.util.Iterator;
10+
import java.util.LinkedList;
711
import java.util.List;
12+
import java.util.ListIterator;
13+
import java.util.Map;
814

15+
import javax.xml.namespace.QName;
916
import javax.xml.stream.XMLStreamException;
1017

18+
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
19+
import org.jboss.as.controller.persistence.xml.SubsystemResourceRegistrationXMLElement;
20+
import org.jboss.as.controller.persistence.xml.SubsystemResourceXMLSchema;
21+
import org.jboss.as.controller.xml.XMLCardinality;
22+
import org.jboss.as.controller.xml.XMLContentWriter;
1123
import org.jboss.dmr.ModelNode;
24+
import org.jboss.staxmapper.XMLElementReader;
1225
import org.jboss.staxmapper.XMLExtendedStreamReader;
26+
import org.jboss.staxmapper.XMLExtendedStreamWriter;
1327

1428
/**
1529
* Defines a versioned schema for a subsystem defined via a {@link PersistentResourceXMLDescription}.
1630
* @author Paul Ferraro
1731
* @param <S> the schema type
1832
*/
19-
public interface PersistentSubsystemSchema<S extends PersistentSubsystemSchema<S>> extends SubsystemSchema<S> {
33+
public interface PersistentSubsystemSchema<S extends PersistentSubsystemSchema<S>> extends SubsystemResourceXMLSchema<S> {
2034

2135
PersistentResourceXMLDescription getXMLDescription();
2236

2337
@Override
24-
default void readElement(XMLExtendedStreamReader reader, List<ModelNode> value) throws XMLStreamException {
25-
new PersistentResourceXMLDescriptionReader(this.getXMLDescription()).readElement(reader, value);
38+
default SubsystemResourceRegistrationXMLElement getSubsystemXMLElement() {
39+
PersistentResourceXMLDescription description = this.getXMLDescription();
40+
return new SubsystemResourceRegistrationXMLElement() {
41+
@Override
42+
public XMLCardinality getCardinality() {
43+
return XMLCardinality.Single.REQUIRED;
44+
}
45+
46+
@Override
47+
public XMLElementReader<Map.Entry<PathAddress, Map<PathAddress, ModelNode>>> getReader() {
48+
return new XMLElementReader<>() {
49+
@Override
50+
public void readElement(XMLExtendedStreamReader reader, Map.Entry<PathAddress, Map<PathAddress, ModelNode>> context) throws XMLStreamException {
51+
description.parse(reader, context.getKey(), new OperationList(context.getValue()));
52+
}
53+
};
54+
}
55+
56+
@Override
57+
public XMLContentWriter<ModelNode> getWriter() {
58+
return new XMLContentWriter<>() {
59+
@Override
60+
public void writeContent(XMLExtendedStreamWriter streamWriter, ModelNode model) throws XMLStreamException {
61+
description.persist(streamWriter, model);
62+
}
63+
64+
@Override
65+
public boolean isEmpty(ModelNode content) {
66+
return false;
67+
}
68+
};
69+
}
70+
71+
@Override
72+
public QName getName() {
73+
return new QName(description.getNamespaceURI(), ModelDescriptionConstants.SUBSYSTEM);
74+
}
75+
76+
@Override
77+
public PathElement getPathElement() {
78+
return description.getPathElement();
79+
}
80+
};
81+
}
82+
83+
class OperationList extends AbstractCollection<ModelNode> implements List<ModelNode> {
84+
private final Map<PathAddress, ModelNode> operations;
85+
private final List<PathAddress> keys;
86+
87+
OperationList(Map<PathAddress, ModelNode> operations) {
88+
this(operations, new LinkedList<>(operations.keySet()));
89+
}
90+
91+
private OperationList(Map<PathAddress, ModelNode> operations, List<PathAddress> keys) {
92+
this.operations = operations;
93+
this.keys = keys;
94+
}
95+
96+
@Override
97+
public boolean add(ModelNode operation) {
98+
PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
99+
if (this.operations.put(address, operation) == null) {
100+
this.keys.add(address);
101+
}
102+
return true;
103+
}
104+
105+
@Override
106+
public boolean remove(Object object) {
107+
ModelNode operation = (ModelNode) object;
108+
PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
109+
if (this.operations.remove(address) != null) {
110+
return this.keys.remove(address);
111+
}
112+
return false;
113+
}
114+
115+
@Override
116+
public int size() {
117+
return this.keys.size();
118+
}
119+
120+
@Override
121+
public Iterator<ModelNode> iterator() {
122+
return new OperationListIterator(this.operations, this.keys.listIterator());
123+
}
124+
125+
@Override
126+
public boolean addAll(int index, Collection<? extends ModelNode> operations) {
127+
int start = index;
128+
for (ModelNode operation : operations) {
129+
PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
130+
if (this.operations.put(address, operation) == null) {
131+
this.keys.add(start++, address);
132+
}
133+
}
134+
return !operations.isEmpty();
135+
}
136+
137+
@Override
138+
public ModelNode get(int index) {
139+
return this.operations.get(this.keys.get(index));
140+
}
141+
142+
@Override
143+
public ModelNode set(int index, ModelNode operation) {
144+
return this.operations.put(this.keys.get(index), operation);
145+
}
146+
147+
@Override
148+
public void add(int index, ModelNode operation) {
149+
PathAddress address = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
150+
this.keys.add(index, address);
151+
this.operations.put(address, operation);
152+
}
153+
154+
@Override
155+
public ModelNode remove(int index) {
156+
return this.operations.remove(this.keys.remove(index));
157+
}
158+
159+
@Override
160+
public int indexOf(Object object) {
161+
int result = -1;
162+
for (Map.Entry<PathAddress, ModelNode> entry : this.operations.entrySet()) {
163+
if (entry.getValue().equals(object)) {
164+
return this.keys.indexOf(entry.getKey());
165+
}
166+
}
167+
return result;
168+
}
169+
170+
@Override
171+
public int lastIndexOf(Object object) {
172+
return this.indexOf(object);
173+
}
174+
175+
@Override
176+
public ListIterator<ModelNode> listIterator() {
177+
return new OperationListIterator(this.operations, this.keys.listIterator());
178+
}
179+
180+
@Override
181+
public ListIterator<ModelNode> listIterator(int index) {
182+
return new OperationListIterator(this.operations, this.keys.listIterator(index));
183+
}
184+
185+
@Override
186+
public List<ModelNode> subList(int fromIndex, int toIndex) {
187+
return new OperationList(this.operations, this.keys.subList(fromIndex, toIndex));
188+
}
189+
190+
private static class OperationListIterator implements ListIterator<ModelNode> {
191+
private final Map<PathAddress, ModelNode> operations;
192+
private final ListIterator<PathAddress> keys;
193+
194+
OperationListIterator(Map<PathAddress, ModelNode> operations, ListIterator<PathAddress> keys) {
195+
this.operations = operations;
196+
this.keys = keys;
197+
}
198+
199+
@Override
200+
public boolean hasNext() {
201+
return this.keys.hasNext();
202+
}
203+
204+
@Override
205+
public ModelNode next() {
206+
return this.operations.get(this.keys.next());
207+
}
208+
209+
@Override
210+
public boolean hasPrevious() {
211+
return this.keys.hasPrevious();
212+
}
213+
214+
@Override
215+
public ModelNode previous() {
216+
return this.operations.get(this.keys.previous());
217+
}
218+
219+
@Override
220+
public int nextIndex() {
221+
return this.keys.nextIndex();
222+
}
223+
224+
@Override
225+
public int previousIndex() {
226+
return this.keys.previousIndex();
227+
}
228+
229+
@Override
230+
public void remove() {
231+
throw new UnsupportedOperationException();
232+
}
233+
234+
@Override
235+
public void set(ModelNode operation) {
236+
throw new UnsupportedOperationException();
237+
}
238+
239+
@Override
240+
public void add(ModelNode operation) {
241+
throw new UnsupportedOperationException();
242+
}
243+
}
26244
}
27245
}

subsystem/src/main/java/org/wildfly/subsystem/SubsystemConfiguration.java

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.function.Supplier;
88

99
import org.jboss.as.controller.SubsystemModel;
10+
import org.jboss.as.controller.SubsystemResourceRegistration;
1011
import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar;
1112

1213
/**
@@ -33,6 +34,17 @@ public interface SubsystemConfiguration {
3334
*/
3435
SubsystemResourceDefinitionRegistrar getRegistrar();
3536

37+
/**
38+
* Factory method creating a basic SubsystemConfiguration.
39+
* @param registration a subsystem registration
40+
* @param currentModel the current subsystem model version
41+
* @param registrarFactory a supplier of the resource definition registrar for this subsystem
42+
* @return a new subsystem configuration
43+
*/
44+
static SubsystemConfiguration of(SubsystemResourceRegistration registration, SubsystemModel model, Supplier<SubsystemResourceDefinitionRegistrar> registrarFactory) {
45+
return of(registration.getName(), model, registrarFactory);
46+
}
47+
3648
/**
3749
* Factory method creating a basic SubsystemConfiguration.
3850
* @param subsystemName the subsystem name

subsystem/src/main/java/org/wildfly/subsystem/SubsystemPersistence.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import java.util.Set;
1313

1414
import org.jboss.as.controller.Feature;
15-
import org.jboss.as.controller.PersistentResourceXMLDescription;
16-
import org.jboss.as.controller.PersistentResourceXMLDescriptionReader;
17-
import org.jboss.as.controller.PersistentResourceXMLDescriptionWriter;
18-
import org.jboss.as.controller.PersistentSubsystemSchema;
1915
import org.jboss.as.controller.SubsystemSchema;
2016
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
17+
import org.jboss.as.controller.persistence.xml.SubsystemResourceRegistrationXMLElement;
18+
import org.jboss.as.controller.persistence.xml.SubsystemResourceXMLElementReader;
19+
import org.jboss.as.controller.persistence.xml.SubsystemResourceXMLElementWriter;
20+
import org.jboss.as.controller.persistence.xml.SubsystemResourceXMLSchema;
2121
import org.jboss.as.version.Stability;
2222
import org.jboss.dmr.ModelNode;
2323
import org.jboss.staxmapper.XMLElementReader;
@@ -58,7 +58,7 @@ default XMLElementReader<List<ModelNode>> getReader(S schema) {
5858
* @param currentSchema the current schema version
5959
* @return a subsystem persistence configuration
6060
*/
61-
static <S extends Enum<S> & PersistentSubsystemSchema<S>> SubsystemPersistence<S> of(S currentSchema) {
61+
static <S extends Enum<S> & SubsystemResourceXMLSchema<S>> SubsystemPersistence<S> of(S currentSchema) {
6262
return of(EnumSet.of(currentSchema));
6363
}
6464

@@ -68,13 +68,13 @@ static <S extends Enum<S> & PersistentSubsystemSchema<S>> SubsystemPersistence<S
6868
* @param currentSchemas the current schema versions
6969
* @return a subsystem persistence configuration
7070
*/
71-
static <S extends Enum<S> & PersistentSubsystemSchema<S>> SubsystemPersistence<S> of(Set<S> currentSchemas) {
71+
static <S extends Enum<S> & SubsystemResourceXMLSchema<S>> SubsystemPersistence<S> of(Set<S> currentSchemas) {
7272
Assert.assertFalse(currentSchemas.isEmpty());
7373
Class<S> schemaClass = currentSchemas.iterator().next().getDeclaringClass();
74-
// Build PersistentResourceXMLDescription for current schemas to share between reader and writer.
75-
Map<S, PersistentResourceXMLDescription> currentXMLDescriptions = new EnumMap<>(schemaClass);
74+
// Build SubsystemResourceRegistrationXMLElement for current schemas to share between reader and writer.
75+
Map<S, SubsystemResourceRegistrationXMLElement> elements = new EnumMap<>(schemaClass);
7676
for (S currentSchema : currentSchemas) {
77-
currentXMLDescriptions.put(currentSchema, currentSchema.getXMLDescription());
77+
elements.put(currentSchema, currentSchema.getSubsystemXMLElement());
7878
}
7979
Map<Stability, S> currentSchemaPerStability = Feature.map(currentSchemas);
8080
return new SubsystemPersistence<>() {
@@ -85,13 +85,13 @@ public Set<S> getSchemas() {
8585

8686
@Override
8787
public XMLElementReader<List<ModelNode>> getReader(S schema) {
88-
return Optional.ofNullable(currentXMLDescriptions.get(schema)).<XMLElementReader<List<ModelNode>>>map(PersistentResourceXMLDescriptionReader::new).orElse(schema);
88+
return Optional.ofNullable(elements.get(schema)).<XMLElementReader<List<ModelNode>>>map(SubsystemResourceXMLElementReader::new).orElse(schema);
8989
}
9090

9191
@Override
9292
public XMLElementWriter<SubsystemMarshallingContext> getWriter(Stability stability) {
9393
S currentSchema = currentSchemaPerStability.get(stability);
94-
return new PersistentResourceXMLDescriptionWriter(currentXMLDescriptions.get(currentSchema));
94+
return new SubsystemResourceXMLElementWriter(elements.get(currentSchema));
9595
}
9696
};
9797
}

0 commit comments

Comments
 (0)