use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class JdbcDriverRemove method recoverServices.
protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) {
final String driverName = model.require(DRIVER_NAME.getName()).asString();
final String moduleName = model.require(DRIVER_MODULE_NAME.getName()).asString();
final Integer majorVersion = model.hasDefined(DRIVER_MAJOR_VERSION.getName()) ? model.get(DRIVER_MAJOR_VERSION.getName()).asInt() : null;
final Integer minorVersion = model.hasDefined(DRIVER_MINOR_VERSION.getName()) ? model.get(DRIVER_MINOR_VERSION.getName()).asInt() : null;
final String driverClassName = model.hasDefined(DRIVER_CLASS_NAME.getName()) ? model.get(DRIVER_CLASS_NAME.getName()).asString() : null;
final String dataSourceClassName = model.hasDefined(DRIVER_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).asString() : null;
final String xaDataSourceClassName = model.hasDefined(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()) ? model.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).asString() : null;
final ServiceTarget target = context.getServiceTarget();
final ModuleIdentifier moduleId;
final Module module;
try {
moduleId = ModuleIdentifier.fromString(moduleName);
module = Module.getCallerModuleLoader().loadModule(moduleId);
} catch (ModuleLoadException e) {
context.getFailureDescription().set(ConnectorLogger.ROOT_LOGGER.failedToLoadModuleDriver(moduleName));
return;
}
if (driverClassName == null) {
final ServiceLoader<Driver> serviceLoader = module.loadService(Driver.class);
if (serviceLoader != null)
for (Driver driver : serviceLoader) {
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
}
} else {
try {
final Class<? extends Driver> driverClass = module.getClassLoader().loadClass(driverClassName).asSubclass(Driver.class);
final Constructor<? extends Driver> constructor = driverClass.getConstructor();
final Driver driver = constructor.newInstance();
startDriverServices(target, moduleId, driver, driverName, majorVersion, minorVersion, dataSourceClassName, xaDataSourceClassName);
} catch (Exception e) {
SUBSYSTEM_DATASOURCES_LOGGER.cannotInstantiateDriverClass(driverClassName, e);
}
}
}
use of org.jboss.modules.ModuleIdentifier in project wildfly by wildfly.
the class ServerAdd method unwrapClass.
private static Class unwrapClass(ModelNode classModel) throws OperationFailedException {
String className = classModel.get(NAME).asString();
String moduleName = classModel.get(MODULE).asString();
try {
ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName);
Module module = Module.getCallerModuleLoader().loadModule(moduleID);
Class<?> clazz = module.getClassLoader().loadClass(className);
return clazz;
} catch (Exception e) {
throw MessagingLogger.ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName);
}
}
Aggregations