1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.jboss.extension.parser;
17
18 import static de.smartics.properties.jboss.extension.resources.PropertiesConfigurationResourceDefinition.AN_NAME;
19 import static de.smartics.properties.jboss.extension.resources.PropertiesConfigurationResourceDefinition.CONFIGS_ELEMENT_NAME;
20 import static de.smartics.properties.jboss.extension.resources.PropertiesConfigurationResourceDefinition.CONFIG_ELEMENT_NAME;
21
22 import javax.xml.stream.XMLStreamException;
23
24 import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
25 import org.jboss.dmr.ModelNode;
26 import org.jboss.staxmapper.XMLElementWriter;
27 import org.jboss.staxmapper.XMLExtendedStreamWriter;
28
29 import de.smartics.properties.jboss.extension.SubsystemExtension;
30 import de.smartics.properties.jboss.extension.resources.PropertiesConfigurationResourceDefinition;
31
32
33
34
35 class ConfigurationWriter implements
36 XMLElementWriter<SubsystemMarshallingContext>
37 {
38
39
40
41
42
43
44
45
46
47
48
49
50
51 ConfigurationWriter()
52 {
53 }
54
55
56
57
58
59
60
61
62
63
64
65 @Override
66 public void writeContent(final XMLExtendedStreamWriter writer,
67 final SubsystemMarshallingContext context) throws XMLStreamException
68 {
69 context.startSubsystemElement(SubsystemExtension.NAMESPACE, false);
70 final ModelNode node = context.getModelNode();
71 final ModelNode configs = node.get(CONFIGS_ELEMENT_NAME);
72 if (configs.isDefined())
73 {
74 writer.writeStartElement(CONFIGS_ELEMENT_NAME);
75 for (final String configName : configs.keys())
76 {
77 final ModelNode config = configs.get(configName);
78 writeConfiguration(writer, config);
79 }
80 writer.writeEndElement();
81 }
82 writer.writeEndElement();
83 }
84
85 private void writeConfiguration(final XMLExtendedStreamWriter writer,
86 final ModelNode config) throws XMLStreamException
87 {
88 writer.writeStartElement(CONFIG_ELEMENT_NAME);
89
90 final String name = config.get("name").asString();
91 writer.writeAttribute(AN_NAME, name);
92 PropertiesConfigurationResourceDefinition.INSTANCE
93 .getDefinitionsComponent().write(writer, config);
94 PropertiesConfigurationResourceDefinition.INSTANCE.getCacheComponent()
95 .write(writer, config);
96 PropertiesConfigurationResourceDefinition.INSTANCE.getDataSourceComponent()
97 .write(writer, config);
98 PropertiesConfigurationResourceDefinition.INSTANCE.getSecurityComponent()
99 .write(writer, config);
100 PropertiesConfigurationResourceDefinition.INSTANCE.getFactoriesComponent()
101 .write(writer, config);
102
103 writer.writeEndElement();
104 }
105
106
107
108 }