1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.jboss.extension.resources;
17
18 import java.util.List;
19
20 import org.jboss.as.controller.AbstractAddStepHandler;
21 import org.jboss.as.controller.OperationContext;
22 import org.jboss.as.controller.OperationFailedException;
23 import org.jboss.as.controller.PathAddress;
24 import org.jboss.as.controller.ServiceVerificationHandler;
25 import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
26 import org.jboss.dmr.ModelNode;
27 import org.jboss.logging.Logger;
28 import org.jboss.msc.service.ServiceController;
29
30 import de.smartics.properties.api.core.app.JndiContext;
31 import de.smartics.properties.spi.config.config.PropertiesConfiguration;
32
33
34
35
36 public final class PropertiesConfigurationResourceAdd extends
37 AbstractAddStepHandler
38 {
39
40
41
42
43
44
45
46 public static final PropertiesConfigurationResourceAdd INSTANCE =
47 new PropertiesConfigurationResourceAdd();
48
49
50
51
52 private static final Logger LOG = Logger
53 .getLogger(PropertiesConfigurationResourceAdd.class);
54
55
56
57
58
59
60
61 private PropertiesConfigurationResourceAdd()
62 {
63 }
64
65
66
67
68
69
70
71
72
73
74
75 @Override
76 protected void populateModel(final ModelNode operation, final ModelNode model)
77 throws OperationFailedException
78 {
79 PropertiesConfigurationResourceDefinition.NAME.validateAndSet(operation,
80 model);
81
82 PropertiesConfigurationResourceDefinition.INSTANCE
83 .getDefinitionsComponent().populateModel(operation, model);
84 PropertiesConfigurationResourceDefinition.INSTANCE.getCacheComponent()
85 .populateModel(operation, model);
86 PropertiesConfigurationResourceDefinition.INSTANCE.getDataSourceComponent()
87 .populateModel(operation, model);
88 PropertiesConfigurationResourceDefinition.INSTANCE.getSecurityComponent()
89 .populateModel(operation, model);
90 PropertiesConfigurationResourceDefinition.INSTANCE.getFactoriesComponent()
91 .populateModel(operation, model);
92 }
93
94 @Override
95 protected void performRuntime(final OperationContext context,
96 final ModelNode operation, final ModelNode model,
97 final ServiceVerificationHandler verificationHandler,
98 final List<ServiceController<?>> newControllers)
99 throws OperationFailedException
100 {
101 LOG.debug("Properties configuration started to be added ...");
102 final String configName =
103 PathAddress
104 .pathAddress(operation.get(ModelDescriptionConstants.ADDRESS))
105 .getLastElement().getValue();
106 addConfiguration(context, configName, model);
107 LOG.info("Properties configuration '" + configName
108 + "' added successfully.");
109 }
110
111 private void addConfiguration(final OperationContext context,
112 final String configName, final ModelNode model)
113 throws OperationFailedException
114 {
115 final ServiceController<?> controller =
116 context.getServiceRegistry(false).getService(
117 ExtensionConfigurationService.SERVICE_NAME);
118 final ExtensionConfigurationService service =
119 (ExtensionConfigurationService) controller.getService();
120
121 final PropertiesConfiguration propertiesConfig =
122 new PropertiesConfiguration();
123 propertiesConfig.setName(configName);
124 final String identifier =
125 JndiContext.extensionConfigPath() + ':' + configName;
126 PropertiesConfigurationResourceDefinition.INSTANCE.apply(identifier,
127 propertiesConfig, model);
128
129 service.addConfiguration(propertiesConfig);
130 }
131
132
133
134 }