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.ServiceVerificationHandler;
24 import org.jboss.as.naming.ManagedReferenceInjector;
25 import org.jboss.as.naming.ServiceBasedNamingStore;
26 import org.jboss.as.naming.deployment.ContextNames;
27 import org.jboss.as.naming.service.BinderService;
28 import org.jboss.as.naming.service.NamingService;
29 import org.jboss.dmr.ModelNode;
30 import org.jboss.logging.Logger;
31 import org.jboss.msc.service.ServiceController;
32 import org.jboss.msc.service.ServiceController.Mode;
33 import org.jboss.msc.service.ServiceTarget;
34
35 import de.smartics.properties.api.core.app.JndiContext;
36 import de.smartics.properties.spi.config.config.ExtensionConfiguration;
37
38
39
40
41 final class SubsystemAdd extends AbstractAddStepHandler
42 {
43
44
45
46
47
48
49
50 static final SubsystemAdd INSTANCE = new SubsystemAdd();
51
52
53
54
55 private static final Logger LOG = Logger.getLogger(SubsystemAdd.class);
56
57
58
59
60
61
62
63 private SubsystemAdd()
64 {
65 }
66
67
68
69
70
71
72
73
74
75
76
77 @Override
78 protected void populateModel(final ModelNode operation, final ModelNode model)
79 throws OperationFailedException
80 {
81 model.setEmptyObject();
82 }
83
84 @Override
85 protected void performRuntime(final OperationContext context,
86 final ModelNode operation, final ModelNode model,
87 final ServiceVerificationHandler verificationHandler,
88 final List<ServiceController<?>> newControllers)
89 throws OperationFailedException
90 {
91 LOG.debug("Properties configuration extension is being started ...");
92 newControllers.add(installService(context, model, verificationHandler,
93 newControllers));
94 newControllers.add(installJndi(context));
95 LOG.info("Properties configuration extension started successfully.");
96 }
97
98 private ServiceController<ExtensionConfiguration> installService(
99 final OperationContext context, final ModelNode model,
100 final ServiceVerificationHandler verificationHandler,
101 final List<ServiceController<?>> newControllers)
102 throws OperationFailedException
103 {
104 LOG.debug(" Properties configuration extension is starting service ...");
105 final ExtensionConfiguration config = new ExtensionConfiguration();
106 final ExtensionConfigurationService service =
107 new ExtensionConfigurationService(config);
108 final ServiceController<ExtensionConfiguration> controller =
109 context.getServiceTarget()
110 .addService(ExtensionConfigurationService.SERVICE_NAME, service)
111 .addDependency(NamingService.SERVICE_NAME)
112 .addListener(verificationHandler).setInitialMode(Mode.ACTIVE)
113 .install();
114 LOG.debug(" Properties configuration extension started sucessfully.");
115 return controller;
116 }
117
118 private ServiceController<?> installJndi(final OperationContext context)
119 throws OperationFailedException
120 {
121 LOG.debug(" Properties configuration extension is starting adding to JNDI ...");
122 final ServiceTarget target = context.getServiceTarget();
123 final String jndiName = JndiContext.extensionConfigPath();
124
125 final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(jndiName);
126 final BinderService binder = new BinderService(bindInfo.getBindName());
127 final ServiceController<?> controller =
128 target
129 .addService(bindInfo.getBinderServiceName(), binder)
130 .addAliases(ContextNames.NAMING.append(jndiName))
131 .addDependency(
132 ExtensionConfigurationService.SERVICE_NAME,
133 ExtensionConfiguration.class,
134 new ManagedReferenceInjector<ExtensionConfiguration>(binder
135 .getManagedObjectInjector()))
136 .addDependency(bindInfo.getParentContextServiceName(),
137 ServiceBasedNamingStore.class, binder.getNamingStoreInjector())
138 .setInitialMode(ServiceController.Mode.PASSIVE).install();
139 LOG.debug(" Properties configuration extension added to JNDI successfully.");
140 return controller;
141 }
142
143
144 }