Search in sources :

Example 1 with Argument

use of org.jboss.as.service.descriptor.JBossServiceConstructorConfig.Argument in project wildfly by wildfly.

the class ParsedServiceDeploymentProcessor method newInstance.

private static Object newInstance(final JBossServiceConfig serviceConfig, final List<ClassReflectionIndex> mBeanClassHierarchy, final ClassLoader deploymentClassLoader) throws DeploymentUnitProcessingException {
    // set TCCL so that the MBean instantiation happens in the deployment's classloader
    final ClassLoader oldTCCL = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(deploymentClassLoader);
    try {
        final JBossServiceConstructorConfig constructorConfig = serviceConfig.getConstructorConfig();
        final int paramCount = constructorConfig != null ? constructorConfig.getArguments().length : 0;
        final Class<?>[] types = new Class<?>[paramCount];
        final Object[] params = new Object[paramCount];
        if (constructorConfig != null) {
            final Argument[] arguments = constructorConfig.getArguments();
            for (int i = 0; i < paramCount; i++) {
                final Argument argument = arguments[i];
                types[i] = ReflectionUtils.getClass(argument.getType(), deploymentClassLoader);
                params[i] = newValue(ReflectionUtils.getClass(argument.getType(), deploymentClassLoader), argument.getValue());
            }
        }
        final Constructor<?> constructor = mBeanClassHierarchy.get(0).getConstructor(types);
        final Object mBeanInstance = ReflectionUtils.newInstance(constructor, params);
        return mBeanInstance;
    } finally {
        // switch back the TCCL
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTCCL);
    }
}
Also used : JBossServiceConstructorConfig(org.jboss.as.service.descriptor.JBossServiceConstructorConfig) Argument(org.jboss.as.service.descriptor.JBossServiceConstructorConfig.Argument)

Aggregations

JBossServiceConstructorConfig (org.jboss.as.service.descriptor.JBossServiceConstructorConfig)1 Argument (org.jboss.as.service.descriptor.JBossServiceConstructorConfig.Argument)1