/
JGroupsSubsystemXMLReader.java
996 lines (888 loc) · 44.7 KB
/
JGroupsSubsystemXMLReader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.as.clustering.jgroups.subsystem;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.AttributeParser;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* XML reader for the JGroups subsystem.
* @author Paul Ferraro
*/
@SuppressWarnings({ "deprecation", "static-method" })
public class JGroupsSubsystemXMLReader implements XMLElementReader<List<ModelNode>> {
private final JGroupsSchema schema;
JGroupsSubsystemXMLReader(JGroupsSchema schema) {
this.schema = schema;
}
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> result) throws XMLStreamException {
Map<PathAddress, ModelNode> operations = new LinkedHashMap<>();
PathAddress address = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
if (!this.schema.since(JGroupsSchema.VERSION_3_0)) {
String defaultStack = require(reader, XMLAttribute.DEFAULT_STACK);
setAttribute(reader, defaultStack, operation, JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK);
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case CHANNELS: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseChannels(reader, address, operations);
break;
}
}
case STACKS: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseStacks(reader, address, operations);
break;
}
}
case STACK: {
if (!this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseStack(reader, address, operations);
break;
}
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
// Version prior to 4_0 schema did not require stack being defined,
// thus iterate over channel add operations and set the stack explicitly.
if (!this.schema.since(JGroupsSchema.VERSION_4_0)) {
ModelNode defaultStack = operation.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName());
for (Map.Entry<PathAddress, ModelNode> entry : operations.entrySet()) {
PathAddress opAddr = entry.getKey();
if (opAddr.getLastElement().getKey().equals(ChannelResourceDefinition.WILDCARD_PATH.getKey())) {
ModelNode op = entry.getValue();
if (!op.hasDefined(ChannelResourceDefinition.Attribute.STACK.getName())) {
op.get(ChannelResourceDefinition.Attribute.STACK.getName()).set(defaultStack);
}
}
}
}
result.addAll(operations.values());
}
private void parseChannels(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case DEFAULT: {
readAttribute(reader, i, operation, JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case CHANNEL: {
this.parseChannel(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseChannel(XMLExtendedStreamReader reader, PathAddress subsystemAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String name = require(reader, XMLAttribute.NAME);
PathAddress address = subsystemAddress.append(ChannelResourceDefinition.pathElement(name));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
case STACK: {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.STACK);
break;
}
case MODULE: {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.MODULE);
break;
}
case CLUSTER: {
if (this.schema.since(JGroupsSchema.VERSION_4_0)) {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.CLUSTER);
break;
}
}
case STATISTICS_ENABLED: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
readAttribute(reader, i, operation, ChannelResourceDefinition.Attribute.STATISTICS_ENABLED);
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (this.schema.since(JGroupsSchema.VERSION_4_0)) {
require(reader, operation, ChannelResourceDefinition.Attribute.STACK);
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case FORK: {
this.parseFork(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseFork(XMLExtendedStreamReader reader, PathAddress channelAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String name = require(reader, XMLAttribute.NAME);
PathAddress address = channelAddress.append(ForkResourceDefinition.pathElement(name));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case PROTOCOL: {
this.parseProtocol(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseStacks(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case DEFAULT: {
readAttribute(reader, i, operation, JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case STACK: {
this.parseStack(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseStack(XMLExtendedStreamReader reader, PathAddress subsystemAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String name = require(reader, XMLAttribute.NAME);
PathAddress address = subsystemAddress.append(StackResourceDefinition.pathElement(name));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
ParseUtils.requireNoNamespaceAttribute(reader, i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
case STATISTICS_ENABLED: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
readAttribute(reader, i, operation, StackResourceDefinition.Attribute.STATISTICS_ENABLED);
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case TRANSPORT: {
this.parseTransport(reader, address, operations);
break;
}
case PROTOCOL: {
this.parseProtocol(reader, address, operations);
break;
}
case RELAY: {
if (this.schema.since(JGroupsSchema.VERSION_2_0)) {
this.parseRelay(reader, address, operations);
break;
}
}
case SOCKET_PROTOCOL: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
this.parseSocketProtocol(reader, address, operations);
break;
}
}
case SOCKET_DISCOVERY_PROTOCOL: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
this.parseSocketDiscoveryProtocol(reader, address, operations);
break;
}
}
case JDBC_PROTOCOL: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
this.parseJDBCProtocol(reader, address, operations);
break;
}
}
case ENCRYPT_PROTOCOL: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
this.parseEncryptProtocol(reader, address, operations);
break;
}
}
case AUTH_PROTOCOL: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
this.parseAuthProtocol(reader, address, operations);
break;
}
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseTransport(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(TransportResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case SHARED: {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.SHARED);
break;
}
case SOCKET_BINDING: {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.SOCKET_BINDING);
break;
}
case DIAGNOSTICS_SOCKET_BINDING: {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.DIAGNOSTICS_SOCKET_BINDING);
break;
}
case DEFAULT_EXECUTOR: {
readAttribute(reader, i, operation, TransportResourceDefinition.ThreadingAttribute.DEFAULT_EXECUTOR);
break;
}
case OOB_EXECUTOR: {
readAttribute(reader, i, operation, TransportResourceDefinition.ThreadingAttribute.OOB_EXECUTOR);
break;
}
case TIMER_EXECUTOR: {
readAttribute(reader, i, operation, TransportResourceDefinition.ThreadingAttribute.TIMER_EXECUTOR);
break;
}
case THREAD_FACTORY: {
readAttribute(reader, i, operation, TransportResourceDefinition.ThreadingAttribute.THREAD_FACTORY);
break;
}
case SITE: {
if (this.schema.since(JGroupsSchema.VERSION_1_1)) {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.SITE);
break;
}
}
case RACK: {
if (this.schema.since(JGroupsSchema.VERSION_1_1)) {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.RACK);
break;
}
}
case MACHINE: {
if (this.schema.since(JGroupsSchema.VERSION_1_1)) {
readAttribute(reader, i, operation, TransportResourceDefinition.Attribute.MACHINE);
break;
}
}
default: {
this.parseProtocolAttribute(reader, i, operation);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case DEFAULT_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.DEFAULT, reader, address, operations);
break;
}
}
case INTERNAL_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_6_0)) {
throw ParseUtils.unexpectedElement(reader);
}
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.INTERNAL, reader, address, operations);
break;
}
}
case OOB_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_6_0)) {
throw ParseUtils.unexpectedElement(reader);
}
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.OOB, reader, address, operations);
break;
}
}
case TIMER_THREAD_POOL: {
if (this.schema.since(JGroupsSchema.VERSION_6_0)) {
throw ParseUtils.unexpectedElement(reader);
}
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
this.parseThreadPool(ThreadPoolResourceDefinition.TIMER, reader, address, operations);
break;
}
}
default: {
this.parseProtocolElement(reader, address, operations);
}
}
}
// Set default port_range for pre-WF11 schemas
if (!this.schema.since(JGroupsSchema.VERSION_5_0)) {
String portRangeProperty = "port_range";
if (!operation.hasDefined(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName(), portRangeProperty)) {
operation.get(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getName()).get(portRangeProperty).set("50");
}
}
}
private void parseSocketProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseSocketProtocolAttribute(reader, i, operation);
}
require(reader, operation, SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseSocketDiscoveryProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseSocketDiscoveryProtocolAttribute(reader, i, operation);
}
require(reader, operation, SocketDiscoveryProtocolResourceDefinition.Attribute.OUTBOUND_SOCKET_BINDINGS);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseJDBCProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseJDBCProtocolAttribute(reader, i, operation);
}
require(reader, operation, JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseEncryptProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseEncryptProtocolAttribute(reader, i, operation);
}
require(reader, operation, EncryptProtocolResourceDefinition.Attribute.KEY_ALIAS, EncryptProtocolResourceDefinition.Attribute.KEY_STORE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseEncryptProtocolElement(reader, address, operations);
}
}
private void parseAuthProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseProtocolAttribute(reader, i, operation);
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseAuthProtocolElement(reader, address, operations);
}
if (!operations.containsKey(address.append(AuthTokenResourceDefinition.WILDCARD_PATH))) {
throw ParseUtils.missingOneOf(reader, EnumSet.of(XMLElement.PLAIN_TOKEN, XMLElement.DIGEST_TOKEN, XMLElement.CIPHER_TOKEN));
}
}
private void parseProtocol(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String type = require(reader, XMLAttribute.TYPE);
PathAddress address = stackAddress.append(ProtocolResourceDefinition.pathElement(type));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
this.parseProtocolAttribute(reader, i, operation);
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseProtocolElement(reader, address, operations);
}
}
private void parseSocketProtocolAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation) throws XMLStreamException {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(index));
switch (attribute) {
case SOCKET_BINDING: {
readAttribute(reader, index, operation, SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING);
break;
}
default: {
parseProtocolAttribute(reader, index, operation);
}
}
}
private void parseSocketDiscoveryProtocolAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation) throws XMLStreamException {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(index));
switch (attribute) {
case OUTBOUND_SOCKET_BINDINGS: {
readAttribute(reader, index, operation, SocketDiscoveryProtocolResourceDefinition.Attribute.OUTBOUND_SOCKET_BINDINGS);
break;
}
default: {
parseProtocolAttribute(reader, index, operation);
}
}
}
private void parseJDBCProtocolAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation) throws XMLStreamException {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(index));
switch (attribute) {
case DATA_SOURCE: {
readAttribute(reader, index, operation, JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE);
break;
}
default: {
parseProtocolAttribute(reader, index, operation);
}
}
}
private void parseEncryptProtocolAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation) throws XMLStreamException {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(index));
switch (attribute) {
case KEY_ALIAS: {
readAttribute(reader, index, operation, EncryptProtocolResourceDefinition.Attribute.KEY_ALIAS);
break;
}
case KEY_STORE: {
readAttribute(reader, index, operation, EncryptProtocolResourceDefinition.Attribute.KEY_STORE);
break;
}
default: {
parseProtocolAttribute(reader, index, operation);
}
}
}
private void parseProtocolAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation) throws XMLStreamException {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(index));
switch (attribute) {
case TYPE: {
// Already parsed
break;
}
case SOCKET_BINDING: {
readAttribute(reader, index, operation, GenericProtocolResourceDefinition.DeprecatedAttribute.SOCKET_BINDING);
break;
}
case DATA_SOURCE: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
throw ParseUtils.unexpectedAttribute(reader, index);
}
readAttribute(reader, index, operation, JDBCProtocolResourceDefinition.Attribute.DATA_SOURCE);
break;
}
case MODULE: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
readAttribute(reader, index, operation, AbstractProtocolResourceDefinition.Attribute.MODULE);
break;
}
}
case STATISTICS_ENABLED: {
if (this.schema.since(JGroupsSchema.VERSION_5_0)) {
readAttribute(reader, index, operation, AbstractProtocolResourceDefinition.Attribute.STATISTICS_ENABLED);
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, index);
}
}
}
private void parseEncryptProtocolElement(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case KEY_CREDENTIAL_REFERENCE: {
readElement(reader, operation, EncryptProtocolResourceDefinition.Attribute.KEY_CREDENTIAL);
break;
}
default: {
this.parseProtocolElement(reader, address, operations);
}
}
}
private void parseAuthProtocolElement(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case PLAIN_TOKEN: {
this.parsePlainAuthToken(reader, address, operations);
break;
}
case DIGEST_TOKEN: {
this.parseDigestAuthToken(reader, address, operations);
break;
}
case CIPHER_TOKEN: {
this.parseCipherAuthToken(reader, address, operations);
break;
}
default: {
this.parseProtocolElement(reader, address, operations);
}
}
}
private void parseProtocolElement(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case PROPERTY: {
this.parseProperty(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
private void parsePlainAuthToken(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = protocolAddress.append(PlainAuthTokenResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH), operation);
ParseUtils.requireNoAttributes(reader);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseAuthTokenElement(reader, protocolAddress, operations);
}
require(reader, operation, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
}
private void parseDigestAuthToken(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = protocolAddress.append(DigestAuthTokenResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH), operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case ALGORITHM: {
readAttribute(reader, i, operation, DigestAuthTokenResourceDefinition.Attribute.ALGORITHM);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
this.parseAuthTokenElement(reader, protocolAddress, operations);
}
require(reader, operation, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
}
private void parseCipherAuthToken(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = protocolAddress.append(CipherAuthTokenResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH), operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case KEY_ALIAS: {
readAttribute(reader, i, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_ALIAS);
break;
}
case KEY_STORE: {
readAttribute(reader, i, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_STORE);
break;
}
case ALGORITHM: {
readAttribute(reader, i, operation, CipherAuthTokenResourceDefinition.Attribute.ALGORITHM);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
require(reader, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_ALIAS, CipherAuthTokenResourceDefinition.Attribute.KEY_STORE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case KEY_CREDENTIAL_REFERENCE: {
readElement(reader, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_CREDENTIAL);
break;
}
default: {
this.parseAuthTokenElement(reader, protocolAddress, operations);
}
}
}
require(reader, operation, CipherAuthTokenResourceDefinition.Attribute.KEY_CREDENTIAL, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
}
private void parseAuthTokenElement(XMLExtendedStreamReader reader, PathAddress protocolAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(protocolAddress.append(AuthTokenResourceDefinition.WILDCARD_PATH));
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case SHARED_SECRET_CREDENTIAL_REFERENCE: {
readElement(reader, operation, AuthTokenResourceDefinition.Attribute.SHARED_SECRET);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
private void parseProperty(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
ParseUtils.requireSingleAttribute(reader, XMLAttribute.NAME.getLocalName());
readElement(reader, operation, AbstractProtocolResourceDefinition.Attribute.PROPERTIES);
}
private void parseThreadPool(ThreadPoolResourceDefinition pool, XMLExtendedStreamReader reader, PathAddress parentAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = parentAddress.append(pool.getPathElement());
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case MIN_THREADS:
readAttribute(reader, i, operation, pool.getMinThreads());
break;
case MAX_THREADS:
readAttribute(reader, i, operation, pool.getMaxThreads());
break;
case QUEUE_LENGTH:
if (this.schema.since(JGroupsSchema.VERSION_6_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
readAttribute(reader, i, operation, pool.getQueueLength());
break;
case KEEPALIVE_TIME:
readAttribute(reader, i, operation, pool.getKeepAliveTime());
break;
default:
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
ParseUtils.requireNoContent(reader);
}
private void parseRelay(XMLExtendedStreamReader reader, PathAddress stackAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = stackAddress.append(RelayResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); i++) {
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case SITE: {
readAttribute(reader, i, operation, RelayResourceDefinition.Attribute.SITE);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
require(reader, operation, RelayResourceDefinition.Attribute.SITE);
while (reader.hasNext() && (reader.nextTag() != XMLStreamConstants.END_ELEMENT)) {
XMLElement element = XMLElement.forName(reader.getLocalName());
switch (element) {
case REMOTE_SITE: {
this.parseRemoteSite(reader, address, operations);
break;
}
case PROPERTY: {
this.parseProperty(reader, address, operations);
break;
}
default: {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseRemoteSite(XMLExtendedStreamReader reader, PathAddress relayAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String site = require(reader, XMLAttribute.NAME);
PathAddress address = relayAddress.append(RemoteSiteResourceDefinition.pathElement(site));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
String cluster = null;
for (int i = 0; i < reader.getAttributeCount(); i++) {
String value = reader.getAttributeValue(i);
XMLAttribute attribute = XMLAttribute.forName(reader.getAttributeLocalName(i));
switch (attribute) {
case NAME: {
// Already parsed
break;
}
case STACK: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
readAttribute(reader, i, operation, RemoteSiteResourceDefinition.DeprecatedAttribute.STACK);
break;
}
case CLUSTER: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
throw ParseUtils.unexpectedAttribute(reader, i);
}
cluster = value;
break;
}
case CHANNEL: {
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
readAttribute(reader, i, operation, RemoteSiteResourceDefinition.Attribute.CHANNEL);
// We need to populate the deprecated STACK attribute so that we have enough context for transforming the add operation
PathAddress subsystemAddress = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
PathAddress channelAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement(value));
ModelNode channelOperation = operations.get(channelAddress);
if (channelOperation != null) {
String stack;
if (channelOperation.hasDefined(ChannelResourceDefinition.Attribute.STACK.getName())) {
stack = channelOperation.get(ChannelResourceDefinition.Attribute.STACK.getName()).asString();
} else {
stack = operations.get(subsystemAddress).get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName()).asString();
}
setAttribute(reader, stack, operation, RemoteSiteResourceDefinition.DeprecatedAttribute.STACK);
}
break;
}
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
if (this.schema.since(JGroupsSchema.VERSION_3_0)) {
require(reader, operation, RemoteSiteResourceDefinition.Attribute.CHANNEL);
} else {
require(reader, operation, RemoteSiteResourceDefinition.DeprecatedAttribute.STACK);
String channel = (cluster != null) ? cluster : site;
setAttribute(reader, channel, operation, RemoteSiteResourceDefinition.Attribute.CHANNEL);
// We need to create a corresponding channel add operation
PathAddress subsystemAddress = PathAddress.pathAddress(JGroupsSubsystemResourceDefinition.PATH);
PathAddress channelAddress = subsystemAddress.append(ChannelResourceDefinition.pathElement(channel));
ModelNode channelOperation = Util.createAddOperation(channelAddress);
String stack = operation.get(RemoteSiteResourceDefinition.DeprecatedAttribute.STACK.getName()).asString();
setAttribute(reader, stack, channelOperation, ChannelResourceDefinition.Attribute.STACK);
operations.put(channelAddress, channelOperation);
}
ParseUtils.requireNoContent(reader);
}
private static String require(XMLExtendedStreamReader reader, XMLAttribute attribute) throws XMLStreamException {
String value = reader.getAttributeValue(null, attribute.getLocalName());
if (value == null) {
throw ParseUtils.missingRequired(reader, attribute.getLocalName());
}
return value;
}
private static void require(XMLExtendedStreamReader reader, ModelNode operation, Attribute... attributes) throws XMLStreamException {
for (Attribute attribute : attributes) {
if (!operation.hasDefined(attribute.getName())) {
AttributeDefinition definition = attribute.getDefinition();
Set<String> names = Collections.singleton(definition.getXmlName());
throw definition.getParser().isParseAsElement() ? ParseUtils.missingRequiredElement(reader, names) : ParseUtils.missingRequired(reader, names);
}
}
}
private static void readAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation, Attribute attribute) throws XMLStreamException {
setAttribute(reader, reader.getAttributeValue(index), operation, attribute);
}
private static void setAttribute(XMLExtendedStreamReader reader, String value, ModelNode operation, Attribute attribute) throws XMLStreamException {
attribute.getDefinition().getParser().parseAndSetParameter(attribute.getDefinition(), value, operation, reader);
}
private static void readElement(XMLExtendedStreamReader reader, ModelNode operation, Attribute attribute) throws XMLStreamException {
AttributeDefinition definition = attribute.getDefinition();
AttributeParser parser = definition.getParser();
if (parser.isParseAsElement()) {
parser.parseElement(definition, reader, operation);
} else {
parser.parseAndSetParameter(definition, reader.getElementText(), operation, reader);
}
}
}