Search in sources :

Example 21 with ModuleIdentifier

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);
        }
    }
}
Also used : ModuleLoadException(org.jboss.modules.ModuleLoadException) ServiceTarget(org.jboss.msc.service.ServiceTarget) Driver(java.sql.Driver) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModuleLoadException(org.jboss.modules.ModuleLoadException)

Example 22 with ModuleIdentifier

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);
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ModuleIdentifier(org.jboss.modules.ModuleIdentifier) Module(org.jboss.modules.Module) IOException(java.io.IOException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

ModuleIdentifier (org.jboss.modules.ModuleIdentifier)22 ModuleDependency (org.jboss.as.server.deployment.module.ModuleDependency)12 Module (org.jboss.modules.Module)10 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)8 ModuleSpecification (org.jboss.as.server.deployment.module.ModuleSpecification)6 ModuleLoadException (org.jboss.modules.ModuleLoadException)6 ArrayList (java.util.ArrayList)4 OperationFailedException (org.jboss.as.controller.OperationFailedException)4 ModuleLoader (org.jboss.modules.ModuleLoader)4 ServiceTarget (org.jboss.msc.service.ServiceTarget)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)3 WarMetaData (org.jboss.as.web.common.WarMetaData)3 ServiceName (org.jboss.msc.service.ServiceName)3 IOException (java.io.IOException)2 Driver (java.sql.Driver)2 CompositeIndex (org.jboss.as.server.deployment.annotation.CompositeIndex)2 Index (org.jboss.jandex.Index)2 Closeable (java.io.Closeable)1