Search in sources :

Example 1 with MessageDrivenBeanMetaData

use of org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData in project wildfly by wildfly.

the class MessageDrivenComponentDescriptionFactory method processMessageBeans.

private void processMessageBeans(final DeploymentUnit deploymentUnit, final Collection<AnnotationInstance> messageBeanAnnotations, final CompositeIndex compositeIndex) throws DeploymentUnitProcessingException {
    if (messageBeanAnnotations.isEmpty())
        return;
    final EjbJarDescription ejbJarDescription = getEjbJarDescription(deploymentUnit);
    final PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    final ServiceName deploymentUnitServiceName = deploymentUnit.getServiceName();
    DeploymentDescriptorEnvironment deploymentDescriptorEnvironment = null;
    for (final AnnotationInstance messageBeanAnnotation : messageBeanAnnotations) {
        final AnnotationTarget target = messageBeanAnnotation.target();
        final ClassInfo beanClassInfo = (ClassInfo) target;
        if (!EjbValidationsUtil.assertEjbClassValidity(beanClassInfo).isEmpty()) {
            continue;
        }
        final String ejbName = beanClassInfo.name().local();
        final AnnotationValue nameValue = messageBeanAnnotation.value("name");
        final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? ejbName : propertyReplacer.replaceProperties(nameValue.asString());
        final MessageDrivenBeanMetaData beanMetaData = getEnterpriseBeanMetaData(deploymentUnit, beanName, MessageDrivenBeanMetaData.class);
        final String beanClassName;
        final String messageListenerInterfaceName;
        final Properties activationConfigProperties = getActivationConfigProperties(messageBeanAnnotation, propertyReplacer);
        final String messagingType;
        if (beanMetaData != null) {
            beanClassName = override(beanClassInfo.name().toString(), beanMetaData.getEjbClass());
            deploymentDescriptorEnvironment = new DeploymentDescriptorEnvironment("java:comp/env/", beanMetaData);
            messagingType = beanMetaData.getMessagingType();
            final ActivationConfigMetaData activationConfigMetaData = beanMetaData.getActivationConfig();
            if (activationConfigMetaData != null) {
                final ActivationConfigPropertiesMetaData propertiesMetaData = activationConfigMetaData.getActivationConfigProperties();
                if (propertiesMetaData != null) {
                    for (final ActivationConfigPropertyMetaData propertyMetaData : propertiesMetaData) {
                        activationConfigProperties.put(propertyMetaData.getKey(), propertyMetaData.getValue());
                    }
                }
            }
            messageListenerInterfaceName = messagingType != null ? messagingType : getMessageListenerInterface(compositeIndex, messageBeanAnnotation, deploymentUnit);
        } else {
            beanClassName = beanClassInfo.name().toString();
            messageListenerInterfaceName = getMessageListenerInterface(compositeIndex, messageBeanAnnotation, deploymentUnit);
        }
        final String defaultResourceAdapterName = this.getDefaultResourceAdapterName(deploymentUnit.getServiceRegistry());
        final MessageDrivenComponentDescription beanDescription = new MessageDrivenComponentDescription(beanName, beanClassName, ejbJarDescription, deploymentUnit, messageListenerInterfaceName, activationConfigProperties, defaultResourceAdapterName, beanMetaData, defaultMdbPoolAvailable);
        beanDescription.setDeploymentDescriptorEnvironment(deploymentDescriptorEnvironment);
        addComponent(deploymentUnit, beanDescription);
        final AnnotationValue mappedNameValue = messageBeanAnnotation.value("mappedName");
        if (mappedNameValue != null && !mappedNameValue.asString().isEmpty()) {
            EjbLogger.ROOT_LOGGER.mappedNameNotSupported(mappedNameValue != null ? mappedNameValue.asString() : "", ejbName);
        }
    }
    EjbDeploymentMarker.mark(deploymentUnit);
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) MessageDrivenBeanMetaData(org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData) ActivationConfigPropertyMetaData(org.jboss.metadata.ejb.spec.ActivationConfigPropertyMetaData) ActivationConfigMetaData(org.jboss.metadata.ejb.spec.ActivationConfigMetaData) Properties(java.util.Properties) ActivationConfigPropertiesMetaData(org.jboss.metadata.ejb.spec.ActivationConfigPropertiesMetaData) ServiceName(org.jboss.msc.service.ServiceName) MessageDrivenComponentDescription(org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription(org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) AnnotationValue(org.jboss.jandex.AnnotationValue) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with MessageDrivenBeanMetaData

use of org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData 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 MessageDrivenBeanMetaData

use of org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData in project wildfly by wildfly.

the class MessageDrivenBeanRuntimeHandler method executeReadAttribute.

@Override
protected void executeReadAttribute(String attributeName, OperationContext context, MessageDrivenComponent component, PathAddress address) {
    final MessageDrivenComponentDescription componentDescription = (MessageDrivenComponentDescription) component.getComponentDescription();
    final ModelNode result = context.getResult();
    if (DELIVERY_ACTIVE.getName().equals(attributeName)) {
        result.set(component.isDeliveryActive());
    } else if (MESSAGING_TYPE.getName().equals(attributeName)) {
        result.set(componentDescription.getMessageListenerInterfaceName());
    } else if (MESSAGE_DESTINATION_TYPE.getName().equals(attributeName)) {
        final MessageDrivenBeanMetaData descriptorData = componentDescription.getDescriptorData();
        if (descriptorData != null) {
            final String destinationType = descriptorData.getMessageDestinationType();
            if (destinationType != null) {
                result.set(destinationType);
            }
        }
    } else if (MESSAGE_DESTINATION_LINK.getName().equals(attributeName)) {
        final MessageDrivenBeanMetaData descriptorData = componentDescription.getDescriptorData();
        if (descriptorData != null) {
            final String messageDestinationLink = descriptorData.getMessageDestinationLink();
            if (messageDestinationLink != null) {
                result.set(messageDestinationLink);
            }
        }
    } else if (ACTIVATION_CONFIG.getName().equals(attributeName)) {
        final Properties activationProps = componentDescription.getActivationProps();
        for (String k : activationProps.stringPropertyNames()) {
            result.add(k, activationProps.getProperty(k));
        }
    } else {
        super.executeReadAttribute(attributeName, context, component, address);
    }
}
Also used : MessageDrivenComponentDescription(org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription) MessageDrivenBeanMetaData(org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData) ModelNode(org.jboss.dmr.ModelNode) Properties(java.util.Properties)

Aggregations

MessageDrivenBeanMetaData (org.jboss.metadata.ejb.spec.MessageDrivenBeanMetaData)3 Properties (java.util.Properties)2 MessageDrivenComponentDescription (org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription)2 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)1 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)1 EjbJarDescription (org.jboss.as.ejb3.deployment.EjbJarDescription)1 AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription (org.jboss.as.ejb3.deployment.processors.AnnotatedEJBComponentDescriptionDeploymentUnitProcessor.getEjbJarDescription)1 ModelNode (org.jboss.dmr.ModelNode)1 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 AnnotationTarget (org.jboss.jandex.AnnotationTarget)1 AnnotationValue (org.jboss.jandex.AnnotationValue)1 ClassInfo (org.jboss.jandex.ClassInfo)1 ActivationConfigMetaData (org.jboss.metadata.ejb.spec.ActivationConfigMetaData)1 ActivationConfigPropertiesMetaData (org.jboss.metadata.ejb.spec.ActivationConfigPropertiesMetaData)1 ActivationConfigPropertyMetaData (org.jboss.metadata.ejb.spec.ActivationConfigPropertyMetaData)1 AroundInvokeMetaData (org.jboss.metadata.ejb.spec.AroundInvokeMetaData)1 AroundInvokesMetaData (org.jboss.metadata.ejb.spec.AroundInvokesMetaData)1 EnterpriseBeanMetaData (org.jboss.metadata.ejb.spec.EnterpriseBeanMetaData)1 SessionBeanMetaData (org.jboss.metadata.ejb.spec.SessionBeanMetaData)1