Search in sources :

Example 1 with LifecycleCallbackMetaData

use of org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData in project wildfly by wildfly.

the class DescriptorEnvironmentLifecycleMethodProcessor method handleMethods.

public static void handleMethods(DeploymentDescriptorEnvironment env, EEModuleDescription eeModuleDescription, String defaultClassName) throws DeploymentUnitProcessingException {
    final RemoteEnvironment environment = env.getEnvironment();
    // post-construct(s) of the interceptor configured (if any) in the deployment descriptor
    LifecycleCallbacksMetaData postConstructs = environment.getPostConstructs();
    if (postConstructs != null) {
        for (LifecycleCallbackMetaData postConstruct : postConstructs) {
            String className = postConstruct.getClassName();
            if (className == null || className.isEmpty()) {
                if (defaultClassName == null) {
                    continue;
                } else {
                    className = defaultClassName;
                }
            }
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = postConstruct.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPostConstruct(methodIdentifier);
            eeModuleDescription.addInterceptorMethodOverride(className, builder.build());
        }
    }
    // pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
    LifecycleCallbacksMetaData preDestroys = environment.getPreDestroys();
    if (preDestroys != null) {
        for (LifecycleCallbackMetaData preDestroy : preDestroys) {
            String className = preDestroy.getClassName();
            if (className == null || className.isEmpty()) {
                if (defaultClassName == null) {
                    continue;
                } else {
                    className = defaultClassName;
                }
            }
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = preDestroy.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPreDestroy(methodIdentifier);
            eeModuleDescription.addInterceptorMethodOverride(className, builder.build());
        }
    }
}
Also used : RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) LifecycleCallbackMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) LifecycleCallbacksMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData)

Example 2 with LifecycleCallbackMetaData

use of org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData in project wildfly by wildfly.

the class DeploymentDescriptorMethodProcessor method handleSessionBean.

private void handleSessionBean(final EJBComponentDescription component, final Module module, final DeploymentReflectionIndex reflectionIndex) throws ClassNotFoundException, DeploymentUnitProcessingException {
    if (component.getDescriptorData() == null) {
        return;
    }
    final Class<?> componentClass = ClassLoadingUtils.loadClass(component.getComponentClassName(), module);
    final EnterpriseBeanMetaData metaData = component.getDescriptorData();
    AroundInvokesMetaData aroundInvokes = null;
    if (metaData instanceof SessionBeanMetaData) {
        aroundInvokes = ((SessionBeanMetaData) metaData).getAroundInvokes();
    } else if (metaData instanceof MessageDrivenBeanMetaData) {
        aroundInvokes = ((MessageDrivenBeanMetaData) metaData).getAroundInvokes();
    }
    if (aroundInvokes != null) {
        for (AroundInvokeMetaData aroundInvoke : aroundInvokes) {
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = aroundInvoke.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
            builder.setAroundInvoke(methodIdentifier);
            if (aroundInvoke.getClassName() == null || aroundInvoke.getClassName().isEmpty()) {
                final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
                component.addInterceptorMethodOverride(className, builder.build());
            } else {
                component.addInterceptorMethodOverride(aroundInvoke.getClassName(), builder.build());
            }
        }
    }
    // post-construct(s) of the interceptor configured (if any) in the deployment descriptor
    LifecycleCallbacksMetaData postConstructs = metaData.getPostConstructs();
    if (postConstructs != null) {
        for (LifecycleCallbackMetaData postConstruct : postConstructs) {
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            String methodName = postConstruct.getMethodName();
            MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPostConstruct(methodIdentifier);
            if (postConstruct.getClassName() == null || postConstruct.getClassName().isEmpty()) {
                final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
                component.addInterceptorMethodOverride(className, builder.build());
            } else {
                component.addInterceptorMethodOverride(postConstruct.getClassName(), builder.build());
            }
        }
    }
    // pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
    final LifecycleCallbacksMetaData preDestroys = metaData.getPreDestroys();
    if (preDestroys != null) {
        for (final LifecycleCallbackMetaData preDestroy : preDestroys) {
            final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
            final String methodName = preDestroy.getMethodName();
            final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
            builder.setPreDestroy(methodIdentifier);
            if (preDestroy.getClassName() == null || preDestroy.getClassName().isEmpty()) {
                final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
                component.addInterceptorMethodOverride(className, builder.build());
            } else {
                component.addInterceptorMethodOverride(preDestroy.getClassName(), builder.build());
            }
        }
    }
    if (component.isStateful()) {
        final SessionBeanMetaData sessionBeanMetadata = (SessionBeanMetaData) metaData;
        // pre-passivate(s) of the interceptor configured (if any) in the deployment descriptor
        final LifecycleCallbacksMetaData prePassivates = sessionBeanMetadata.getPrePassivates();
        if (prePassivates != null) {
            for (final LifecycleCallbackMetaData prePassivate : prePassivates) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                final String methodName = prePassivate.getMethodName();
                final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
                builder.setPrePassivate(methodIdentifier);
                if (prePassivate.getClassName() == null || prePassivate.getClassName().isEmpty()) {
                    final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
                    component.addInterceptorMethodOverride(className, builder.build());
                } else {
                    component.addInterceptorMethodOverride(prePassivate.getClassName(), builder.build());
                }
            }
        }
        final LifecycleCallbacksMetaData postActivates = sessionBeanMetadata.getPostActivates();
        if (postActivates != null) {
            for (final LifecycleCallbackMetaData postActivate : postActivates) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                final String methodName = postActivate.getMethodName();
                final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName);
                builder.setPostActivate(methodIdentifier);
                if (postActivate.getClassName() == null || postActivate.getClassName().isEmpty()) {
                    final String className = ClassReflectionIndexUtil.findRequiredMethod(reflectionIndex, componentClass, methodIdentifier).getDeclaringClass().getName();
                    component.addInterceptorMethodOverride(className, builder.build());
                } else {
                    component.addInterceptorMethodOverride(postActivate.getClassName(), builder.build());
                }
            }
        }
    }
}
Also used : AroundInvokesMetaData(org.jboss.metadata.ejb.spec.AroundInvokesMetaData) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) MessageDrivenBeanMetaData(org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData) SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) LifecycleCallbackMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData) AroundInvokeMetaData(org.jboss.metadata.ejb.spec.AroundInvokeMetaData) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) EnterpriseBeanMetaData(org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData) LifecycleCallbacksMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData)

Example 3 with LifecycleCallbackMetaData

use of org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData in project wildfly by wildfly.

the class InterceptorClassDeploymentDescriptorProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (metaData == null) {
        return;
    }
    if (metaData.getInterceptors() == null) {
        return;
    }
    for (InterceptorMetaData interceptor : metaData.getInterceptors()) {
        String interceptorClassName = interceptor.getInterceptorClass();
        AroundInvokesMetaData aroundInvokes = interceptor.getAroundInvokes();
        if (aroundInvokes != null) {
            for (AroundInvokeMetaData aroundInvoke : aroundInvokes) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = aroundInvoke.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
                builder.setAroundInvoke(methodIdentifier);
                if (aroundInvoke.getClassName() == null || aroundInvoke.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(aroundInvoke.getClassName(), builder.build());
                }
            }
        }
        AroundTimeoutsMetaData aroundTimeouts = interceptor.getAroundTimeouts();
        if (aroundTimeouts != null) {
            for (AroundTimeoutMetaData aroundTimeout : aroundTimeouts) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = aroundTimeout.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(Object.class, methodName, InvocationContext.class);
                builder.setAroundTimeout(methodIdentifier);
                if (aroundTimeout.getClassName() == null || aroundTimeout.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(aroundTimeout.getClassName(), builder.build());
                }
            }
        }
        // post-construct(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData postConstructs = interceptor.getPostConstructs();
        if (postConstructs != null) {
            for (LifecycleCallbackMetaData postConstruct : postConstructs) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = postConstruct.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPostConstruct(methodIdentifier);
                if (postConstruct.getClassName() == null || postConstruct.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(postConstruct.getClassName(), builder.build());
                }
            }
        }
        // pre-destroy(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData preDestroys = interceptor.getPreDestroys();
        if (preDestroys != null) {
            for (LifecycleCallbackMetaData preDestroy : preDestroys) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = preDestroy.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPreDestroy(methodIdentifier);
                if (preDestroy.getClassName() == null || preDestroy.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(preDestroy.getClassName(), builder.build());
                }
            }
        }
        // pre-passivates(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData prePassivates = interceptor.getPrePassivates();
        if (prePassivates != null) {
            for (LifecycleCallbackMetaData prePassivate : prePassivates) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = prePassivate.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPrePassivate(methodIdentifier);
                if (prePassivate.getClassName() == null || prePassivate.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(prePassivate.getClassName(), builder.build());
                }
            }
        }
        // pre-passivates(s) of the interceptor configured (if any) in the deployment descriptor
        LifecycleCallbacksMetaData postActivates = interceptor.getPostActivates();
        if (postActivates != null) {
            for (LifecycleCallbackMetaData postActivate : postActivates) {
                final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder();
                String methodName = postActivate.getMethodName();
                MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(void.class, methodName, InvocationContext.class);
                builder.setPostActivate(methodIdentifier);
                if (postActivate.getClassName() == null || postActivate.getClassName().isEmpty()) {
                    eeModuleDescription.addInterceptorMethodOverride(interceptorClassName, builder.build());
                } else {
                    eeModuleDescription.addInterceptorMethodOverride(postActivate.getClassName(), builder.build());
                }
            }
        }
        if (interceptor.getJndiEnvironmentRefsGroup() != null) {
            final DeploymentDescriptorEnvironment environment = new DeploymentDescriptorEnvironment("java:comp/env", interceptor.getJndiEnvironmentRefsGroup());
            eeModuleDescription.addInterceptorEnvironment(interceptor.getInterceptorClass(), new InterceptorEnvironment(environment));
        }
    }
}
Also used : AroundInvokesMetaData(org.jboss.metadata.ejb.spec.AroundInvokesMetaData) AroundTimeoutsMetaData(org.jboss.metadata.ejb.spec.AroundTimeoutsMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) AroundInvokeMetaData(org.jboss.metadata.ejb.spec.AroundInvokeMetaData) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) InterceptorMetaData(org.jboss.metadata.ejb.spec.InterceptorMetaData) LifecycleCallbacksMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) InterceptorClassDescription(org.jboss.as.ee.component.interceptors.InterceptorClassDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) LifecycleCallbackMetaData(org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData) AroundTimeoutMetaData(org.jboss.metadata.ejb.spec.AroundTimeoutMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) InterceptorEnvironment(org.jboss.as.ee.component.InterceptorEnvironment)

Aggregations

InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 LifecycleCallbackMetaData (org.jboss.metadata.javaee.spec.LifecycleCallbackMetaData)3 LifecycleCallbacksMetaData (org.jboss.metadata.javaee.spec.LifecycleCallbacksMetaData)3 AroundInvokeMetaData (org.jboss.metadata.ejb.spec.AroundInvokeMetaData)2 AroundInvokesMetaData (org.jboss.metadata.ejb.spec.AroundInvokesMetaData)2 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 InterceptorEnvironment (org.jboss.as.ee.component.InterceptorEnvironment)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 AroundTimeoutMetaData (org.jboss.metadata.ejb.spec.AroundTimeoutMetaData)1 AroundTimeoutsMetaData (org.jboss.metadata.ejb.spec.AroundTimeoutsMetaData)1 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)1 EnterpriseBeanMetaData (org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData)1 InterceptorMetaData (org.jboss.metadata.ejb.spec.InterceptorMetaData)1 MessageDrivenBeanMetaData (org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData)1 SessionBeanMetaData (org.jboss.metadata.ejb.spec.SessionBeanMetaData)1 RemoteEnvironment (org.jboss.metadata.javaee.spec.RemoteEnvironment)1