private static final Class<?>[] EMPTY_CLASS_ARRAY = new Class<?>[0];
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final DeploymentClassIndex classIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CLASS_INDEX);
final boolean metadataComplete = MetadataCompleteMarker.isMetadataComplete(deploymentUnit);
// Module stuff
final Deque<InterceptorFactory> instantiators = new ArrayDeque<>();
final Deque<InterceptorFactory> injectors = new ArrayDeque<>();
final Deque<InterceptorFactory> uninjectors = new ArrayDeque<>();
final Deque<InterceptorFactory> destructors = new ArrayDeque<>();
final Map<String, List<InterceptorFactory>> userAroundInvokesByInterceptorClass = new HashMap<>();
final Map<String, List<InterceptorFactory>> userAroundConstructsByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
final Map<String, List<InterceptorFactory>> userAroundTimeoutsByInterceptorClass;
final Map<String, List<InterceptorFactory>> userPrePassivatesByInterceptorClass;
final Map<String, List<InterceptorFactory>> userPostActivatesByInterceptorClass;
final Map<String, List<InterceptorFactory>> userPostConstructByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
final Map<String, List<InterceptorFactory>> userPreDestroyByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
final Set<MethodIdentifier> timeoutMethods = description.getTimerMethods();
if (description.isTimerServiceRequired()) {
userAroundTimeoutsByInterceptorClass = new HashMap<>();
} else {
userAroundTimeoutsByInterceptorClass = null;
}
if (description.isPassivationApplicable()) {
userPrePassivatesByInterceptorClass = new HashMap<>();
userPostActivatesByInterceptorClass = new HashMap<>();
} else {
userPrePassivatesByInterceptorClass = null;
userPostActivatesByInterceptorClass = null;
}
//the actual component creation interceptor
//this really belongs in DefaultComponentConfigurator, but all the other AroundConstruct chain is assembled here
final InterceptorFactory instantiator;
// Primary instance
final ComponentFactory instanceFactory = configuration.getInstanceFactory();
if (instanceFactory != null) {
instantiator = new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(instanceFactory, BasicComponentInstance.INSTANCE_KEY, true));
} else {
final ClassReflectionIndex<?> componentClassIndex = deploymentReflectionIndex.getClassIndex(configuration.getComponentClass());
//use the default constructor if no instanceFactory has been set
final Constructor<?> constructor = componentClassIndex.getConstructor(EMPTY_CLASS_ARRAY);
if (constructor == null) {
throw EeLogger.ROOT_LOGGER.defaultConstructorNotFound(configuration.getComponentClass());
}
instantiator = new ImmediateInterceptorFactory(new ComponentInstantiatorInterceptor(new ConstructorComponentFactory(constructor), BasicComponentInstance.INSTANCE_KEY, true));
}
//all interceptors with lifecycle callbacks, in the correct order
final List<InterceptorDescription> interceptorWithLifecycleCallbacks = new ArrayList<InterceptorDescription>();
if (!description.isExcludeDefaultInterceptors()) {
interceptorWithLifecycleCallbacks.addAll(description.getDefaultInterceptors());
}
interceptorWithLifecycleCallbacks.addAll(description.getClassInterceptors());
for (final InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
final String interceptorClassName = interceptorDescription.getInterceptorClassName();
final ClassIndex interceptorClass;
try {
interceptorClass = classIndex.classIndex(interceptorClassName);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptorClassName);
}
final InterceptorEnvironment interceptorEnvironment = moduleDescription.getInterceptorEnvironment().get(interceptorClassName);
if (interceptorEnvironment != null) {
//if the interceptor has environment config we merge it into the components environment
description.getBindingConfigurations().addAll(interceptorEnvironment.getBindingConfigurations());
for (final ResourceInjectionConfiguration injection : interceptorEnvironment.getResourceInjections()) {
description.addResourceInjection(injection);
}
}
//we store the interceptor instance under the class key
final Object contextKey = interceptorClass.getModuleClass();
configuration.getInterceptorContextKeys().add(contextKey);
final ClassReflectionIndex<?> interceptorIndex = deploymentReflectionIndex.getClassIndex(interceptorClass.getModuleClass());
final Constructor<?> constructor = interceptorIndex.getConstructor(EMPTY_CLASS_ARRAY);
if (constructor == null) {
throw EeLogger.ROOT_LOGGER.defaultConstructorNotFoundOnComponent(interceptorClassName, configuration.getComponentClass());
}