if (context.getType() == OperationContext.Type.SERVER) {
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ServiceTarget serviceTarget = context.getServiceTarget();
final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler();
final ModelNode address = operation.require(OP_ADDR);
final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
final String jndiName = model.get(JNDINAME.getName()).asString();
final ServiceRegistry registry = context.getServiceRegistry(true);
final List<ServiceName> serviceNames = registry.getServiceNames();
if (isXa()) {
final ModifiableXaDataSource dataSourceConfig;
try {
dataSourceConfig = xaFrom(context, model);
} catch (ValidateException e) {
throw new OperationFailedException(e, new ModelNode().set(MESSAGES.failedToCreate("XaDataSource", operation, e.getLocalizedMessage())));
}
final ServiceName xaDataSourceConfigServiceName = XADataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
final XADataSourceConfigService xaDataSourceConfigService = new XADataSourceConfigService(dataSourceConfig);
final ServiceBuilder<?> builder = serviceTarget.addService(xaDataSourceConfigServiceName, xaDataSourceConfigService);
builder.addListener(verificationHandler);
for (ServiceName name : serviceNames) {
if (xaDataSourceConfigServiceName.append("xa-datasource-properties").isParentOf(name)) {
final ServiceController<?> xaConfigProperyController = registry.getService(name);
XaDataSourcePropertiesService xaPropService = (XaDataSourcePropertiesService) xaConfigProperyController.getService();
if (xaConfigProperyController != null) {
if (! ServiceController.State.UP.equals(xaConfigProperyController.getState())) {
xaConfigProperyController.setMode(ServiceController.Mode.ACTIVE);
builder.addDependency(name, String.class, xaDataSourceConfigService.getXaDataSourcePropertyInjector(xaPropService.getName()));
} else {
throw new OperationFailedException(new ModelNode().set(MESSAGES.serviceAlreadyStarted("Data-source.xa-config-property", name)));
}
} else {
throw new OperationFailedException(new ModelNode().set(MESSAGES.serviceNotAvailable("Data-source.xa-config-property", name)));
}
}
}
builder.install();
} else {
final ModifiableDataSource dataSourceConfig;
try {
dataSourceConfig = from(context, model);
} catch (ValidateException e) {
throw new OperationFailedException(e, new ModelNode().set(MESSAGES.failedToCreate("DataSource", operation, e.getLocalizedMessage())));
}
final ServiceName dataSourceCongServiceName = DataSourceConfigService.SERVICE_NAME_BASE.append(dsName);
final DataSourceConfigService configService = new DataSourceConfigService(dataSourceConfig);
final ServiceBuilder<?> builder = serviceTarget.addService(dataSourceCongServiceName, configService);
builder.addListener(verificationHandler);
for (ServiceName name : serviceNames) {
if (dataSourceCongServiceName.append("connetion-properties").isParentOf(name)) {
final ServiceController<?> dataSourceController = registry.getService(name);
ConnectionPropertiesService connPropService = (ConnectionPropertiesService) dataSourceController.getService();
if (dataSourceController != null) {
if (!ServiceController.State.UP.equals(dataSourceController.getState())) {
dataSourceController.setMode(ServiceController.Mode.ACTIVE);
builder.addDependency(name, String.class, configService.getConnectionPropertyInjector(connPropService.getName()));
} else {
throw new OperationFailedException(new ModelNode().set(MESSAGES.serviceAlreadyStarted("Data-source.connectionProperty", name)));
}
} else {
throw new OperationFailedException(new ModelNode().set(MESSAGES.serviceNotAvailable("Data-source.connectionProperty", name)));
}
}
}
builder.install();
}
context.completeStep();
}
}, OperationContext.Stage.RUNTIME);
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ServiceTarget serviceTarget = context.getServiceTarget();
final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler();
final ModelNode address = operation.require(OP_ADDR);
final String dsName = PathAddress.pathAddress(address).getLastElement().getValue();
final String jndiName = model.get(JNDINAME.getName()).asString();
final ServiceRegistry registry = context.getServiceRegistry(true);