27
27
import java .util .List ;
28
28
import java .util .Locale ;
29
29
import java .util .ResourceBundle ;
30
-
31
30
import javax .xml .stream .XMLStreamException ;
32
31
import javax .xml .stream .XMLStreamWriter ;
33
32
@@ -71,19 +70,20 @@ public abstract class AttributeDefinition {
71
70
private final ParameterCorrector valueCorrector ;
72
71
private final ParameterValidator validator ;
73
72
private final EnumSet <AttributeAccess .Flag > flags ;
73
+ protected final AttributeMarshaller attributeMarshaller ;
74
74
75
75
protected AttributeDefinition (String name , String xmlName , final ModelNode defaultValue , final ModelType type ,
76
76
final boolean allowNull , final boolean allowExpression , final MeasurementUnit measurementUnit ,
77
77
final ParameterValidator validator , final String [] alternatives , final String [] requires ,
78
78
final AttributeAccess .Flag ... flags ) {
79
79
this (name , xmlName , defaultValue , type , allowNull , allowExpression , measurementUnit ,
80
- null , validator , true , alternatives , requires , flags );
80
+ null , validator , true , alternatives , requires , null , flags );
81
81
}
82
82
83
83
protected AttributeDefinition (String name , String xmlName , final ModelNode defaultValue , final ModelType type ,
84
84
final boolean allowNull , final boolean allowExpression , final MeasurementUnit measurementUnit ,
85
85
final ParameterCorrector valueCorrector , final ParameterValidator validator ,
86
- boolean validateNull , final String [] alternatives , final String [] requires ,
86
+ boolean validateNull , final String [] alternatives , final String [] requires , AttributeMarshaller attributeMarshaller ,
87
87
final AttributeAccess .Flag ... flags ) {
88
88
89
89
this .name = name ;
@@ -113,6 +113,11 @@ protected AttributeDefinition(String name, String xmlName, final ModelNode defau
113
113
} else {
114
114
this .flags = EnumSet .of (flags [0 ], flags );
115
115
}
116
+ if (attributeMarshaller != null ) {
117
+ this .attributeMarshaller = attributeMarshaller ;
118
+ } else {
119
+ this .attributeMarshaller = new DefaultAttributeMarshaller ();
120
+ }
116
121
}
117
122
118
123
public String getName () {
@@ -170,7 +175,7 @@ public EnumSet<AttributeAccess.Flag> getFlags() {
170
175
* @return {@code true} if the given {@code resourceModel} has a defined value under this attribute's {@link #getName()} () name}.
171
176
*/
172
177
public boolean isMarshallable (final ModelNode resourceModel ) {
173
- return isMarshallable (resourceModel , true );
178
+ return attributeMarshaller . isMarshallable (this , resourceModel , true );
174
179
}
175
180
176
181
/**
@@ -183,7 +188,7 @@ public boolean isMarshallable(final ModelNode resourceModel) {
183
188
* and {@code marshallDefault} is {@code true} or that value differs from this attribute's {@link #getDefaultValue() default value}.
184
189
*/
185
190
public boolean isMarshallable (final ModelNode resourceModel , final boolean marshallDefault ) {
186
- return resourceModel . hasDefined ( name ) && ( marshallDefault || ! resourceModel . get ( name ). equals ( defaultValue ) );
191
+ return attributeMarshaller . isMarshallable ( this , resourceModel , marshallDefault );
187
192
}
188
193
189
194
/**
@@ -279,14 +284,27 @@ public boolean hasAlternative(final ModelNode operationObject) {
279
284
}
280
285
281
286
/**
282
- * Marshalls the value from the given {@code resourceModel} as an xml element , if it
287
+ * Marshalls the value from the given {@code resourceModel} as an xml attribute , if it
283
288
* {@link #isMarshallable(org.jboss.dmr.ModelNode, boolean) is marshallable}.
284
289
*
285
290
* @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}.
286
291
* @param writer stream writer to use for writing the attribute
287
292
* @throws javax.xml.stream.XMLStreamException if thrown by {@code writer}
288
293
*/
289
- public abstract void marshallAsElement (final ModelNode resourceModel , final XMLStreamWriter writer ) throws XMLStreamException ;
294
+ public void marshallAsElement (final ModelNode resourceModel , final XMLStreamWriter writer ) throws XMLStreamException {
295
+ marshallAsElement (resourceModel ,true ,writer );
296
+ }
297
+
298
+ /**
299
+ * Marshalls the value from the given {@code resourceModel} as an xml element, if it
300
+ * {@link #isMarshallable(org.jboss.dmr.ModelNode, boolean) is marshallable}.
301
+ *
302
+ * @param resourceModel the model, a non-null node of {@link org.jboss.dmr.ModelType#OBJECT}.
303
+ * @param writer stream writer to use for writing the attribute
304
+ * @throws javax.xml.stream.XMLStreamException
305
+ * if thrown by {@code writer}
306
+ */
307
+ public abstract void marshallAsElement (final ModelNode resourceModel , final boolean marshallDefault , final XMLStreamWriter writer ) throws XMLStreamException ;
290
308
291
309
/**
292
310
* Creates a returns a basic model node describing the attribute, after attaching it to the given overall resource
@@ -470,6 +488,10 @@ private ModelNode validateOperation(final ModelNode operationObject, final boole
470
488
return node ;
471
489
}
472
490
491
+ public AttributeMarshaller getAttributeMarshaller () {
492
+ return attributeMarshaller ;
493
+ }
494
+
473
495
private final OperationContext NO_OPERATION_CONTEXT_FOR_RESOLVING_MODEL_PARAMETERS = new OperationContext () {
474
496
475
497
@ Override
0 commit comments