Search in sources :

Example 1 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription in project wildfly by wildfly.

the class SessionBeanHomeProcessor method configureHome.

private void configureHome(final DeploymentPhaseContext phaseContext, final ComponentDescription componentDescription, final SessionBeanComponentDescription ejbComponentDescription, final EJBViewDescription homeView, final EJBViewDescription ejbObjectView) {
    homeView.getConfigurators().add(new ViewConfigurator() {

        @Override
        public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
            configuration.addClientPostConstructInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
            configuration.addClientPreDestroyInterceptor(org.jboss.invocation.Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
            //loop over methods looking for create methods:
            for (Method method : configuration.getProxyFactory().getCachedMethods()) {
                if (method.getName().startsWith("create")) {
                    //we have a create method
                    if (ejbObjectView == null) {
                        throw EjbLogger.ROOT_LOGGER.invalidEjbLocalInterface(componentDescription.getComponentName());
                    }
                    Method initMethod = resolveInitMethod(ejbComponentDescription, method);
                    final SessionBeanHomeInterceptorFactory factory = new SessionBeanHomeInterceptorFactory(initMethod);
                    //add a dependency on the view to create
                    configuration.getDependencies().add(new DependencyConfigurator<ViewService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ViewService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(ejbObjectView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, factory, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("getEJBMetaData") && method.getParameterTypes().length == 0 && ((EJBViewDescription) description).getMethodIntf() == MethodIntf.HOME) {
                    final Class<?> ejbObjectClass;
                    try {
                        ejbObjectClass = ClassLoadingUtils.loadClass(ejbObjectView.getViewClassName(), context.getDeploymentUnit());
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getComponentName());
                    }
                    final EjbMetadataInterceptor factory = new EjbMetadataInterceptor(ejbObjectClass, configuration.getViewClass().asSubclass(EJBHome.class), null, true, componentDescription instanceof StatelessComponentDescription);
                    //add a dependency on the view to create
                    componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                        @Override
                        public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                            serviceBuilder.addDependency(configuration.getViewServiceName(), ComponentView.class, factory.getHomeView());
                        }
                    });
                    //add the interceptor
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(factory), InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Object.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, InvalidRemoveExceptionMethodInterceptor.FACTORY, InterceptorOrder.View.INVALID_METHOD_EXCEPTION);
                } else if (method.getName().equals("remove") && method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == Handle.class) {
                    configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
                    configuration.addViewInterceptor(method, HomeRemoveInterceptor.FACTORY, InterceptorOrder.View.HOME_METHOD_INTERCEPTOR);
                }
            }
        }
    });
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBHome(javax.ejb.EJBHome) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) ViewService(org.jboss.as.ee.component.ViewService) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) Handle(javax.ejb.Handle) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) SessionBeanHomeInterceptorFactory(org.jboss.as.ejb3.component.interceptors.SessionBeanHomeInterceptorFactory) ComponentView(org.jboss.as.ee.component.ComponentView) StatelessComponentDescription(org.jboss.as.ejb3.component.stateless.StatelessComponentDescription) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EjbMetadataInterceptor(org.jboss.as.ejb3.component.interceptors.EjbMetadataInterceptor) ComponentStartService(org.jboss.as.ee.component.ComponentStartService)

Example 2 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription in project wildfly by wildfly.

the class EJBComponentDescription method setupRemoteViewInterceptors.

private void setupRemoteViewInterceptors(final EJBViewDescription view) {
    if (view.getMethodIntf() == MethodIntf.REMOTE || view.getMethodIntf() == MethodIntf.HOME) {
        view.getConfigurators().add(new ViewConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
                    configuration.addViewInterceptor(EjbExceptionTransformingInterceptorFactories.REMOTE_INSTANCE, InterceptorOrder.View.REMOTE_EXCEPTION_TRANSFORMER);
                }
            }
        });
        if (view.getMethodIntf() == MethodIntf.HOME) {
            view.getConfigurators().add(new ViewConfigurator() {

                @Override
                public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                    if (Remote.class.isAssignableFrom(configuration.getViewClass())) {
                        final String earApplicationName = componentConfiguration.getComponentDescription().getModuleDescription().getEarApplicationName();
                        configuration.setViewInstanceFactory(new RemoteHomeViewInstanceFactory(earApplicationName, componentConfiguration.getModuleName(), componentConfiguration.getComponentDescription().getModuleDescription().getDistinctName(), componentConfiguration.getComponentName()));
                    }
                }
            });
        }
        // add the remote tx propagating interceptor
        view.getConfigurators().add(new EJBRemoteTransactionsViewConfigurator());
    }
}
Also used : NamespaceViewConfigurator(org.jboss.as.ee.component.NamespaceViewConfigurator) EJBRemoteTransactionsViewConfigurator(org.jboss.as.ejb3.remote.EJBRemoteTransactionsViewConfigurator) EJBSecurityViewConfigurator(org.jboss.as.ejb3.security.EJBSecurityViewConfigurator) ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) EJBRemoteTransactionsViewConfigurator(org.jboss.as.ejb3.remote.EJBRemoteTransactionsViewConfigurator) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) ViewDescription(org.jboss.as.ee.component.ViewDescription) Remote(java.rmi.Remote) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Example 3 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription in project wildfly by wildfly.

the class TransactionAttributeMergingProcessor method handleAnnotations.

@Override
protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    processTransactionAttributeAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
    processTransactionTimeoutAnnotation(applicationClasses, deploymentReflectionIndex, componentClass, null, componentConfiguration);
    for (ViewDescription view : componentConfiguration.getViews()) {
        try {
            final Class<?> viewClass = module.getClassLoader().loadClass(view.getViewClassName());
            EJBViewDescription ejbView = (EJBViewDescription) view;
            processTransactionAttributeAnnotation(applicationClasses, deploymentReflectionIndex, viewClass, ejbView.getMethodIntf(), componentConfiguration);
            processTransactionTimeoutAnnotation(applicationClasses, deploymentReflectionIndex, viewClass, ejbView.getMethodIntf(), componentConfiguration);
        } catch (ClassNotFoundException e) {
            throw EjbLogger.ROOT_LOGGER.failToLoadEjbViewClass(e);
        }
    }
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) Module(org.jboss.modules.Module)

Example 4 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription in project wildfly by wildfly.

the class AbstractEJBComponentRuntimeHandler method executeReadAttribute.

protected void executeReadAttribute(final String attributeName, final OperationContext context, final T component, final PathAddress address) {
    final boolean hasPool = componentType.hasPool();
    final ModelNode result = context.getResult();
    final EJBComponentDescription componentDescription = component.getComponentDescription();
    if (COMPONENT_CLASS_NAME.getName().equals(attributeName)) {
        result.set(component.getComponentClass().getName());
    } else if (JNDI_NAMES.getName().equals(attributeName)) {
        for (ViewDescription view : componentDescription.getViews()) {
            for (String binding : view.getBindingNames()) {
                result.add(binding);
            }
        }
    } else if (BUSINESS_LOCAL.getName().equals(attributeName)) {
        for (final ViewDescription view : componentDescription.getViews()) {
            final EJBViewDescription ejbViewDescription = (EJBViewDescription) view;
            if (!ejbViewDescription.isEjb2xView() && ejbViewDescription.getMethodIntf() == MethodIntf.LOCAL) {
                result.add(ejbViewDescription.getViewClassName());
            }
        }
    } else if (BUSINESS_REMOTE.getName().equals(attributeName)) {
        for (final ViewDescription view : componentDescription.getViews()) {
            final EJBViewDescription ejbViewDescription = (EJBViewDescription) view;
            if (!ejbViewDescription.isEjb2xView() && ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE) {
                result.add(ejbViewDescription.getViewClassName());
            }
        }
    } else if (TIMEOUT_METHOD.getName().equals(attributeName)) {
        final Method timeoutMethod = component.getTimeoutMethod();
        if (timeoutMethod != null) {
            result.set(timeoutMethod.toString());
        }
    } else if (ASYNC_METHODS.getName().equals(attributeName)) {
        final SessionBeanComponentDescription sessionBeanComponentDescription = (SessionBeanComponentDescription) componentDescription;
        final Set<MethodIdentifier> asynchronousMethods = sessionBeanComponentDescription.getAsynchronousMethods();
        for (MethodIdentifier m : asynchronousMethods) {
            result.add(m.getReturnType() + ' ' + m.getName() + '(' + String.join(", ", m.getParameterTypes()) + ')');
        }
    } else if (TRANSACTION_TYPE.getName().equals(attributeName)) {
        result.set(component.isBeanManagedTransaction() ? TransactionManagementType.BEAN.name() : TransactionManagementType.CONTAINER.name());
    } else if (SECURITY_DOMAIN.getName().equals(attributeName)) {
        EJBSecurityMetaData md = component.getSecurityMetaData();
        if (md != null && md.getSecurityDomainName() != null) {
            result.set(md.getSecurityDomainName());
        }
    } else if (RUN_AS_ROLE.getName().equals(attributeName)) {
        EJBSecurityMetaData md = component.getSecurityMetaData();
        if (md != null && md.getRunAs() != null) {
            result.set(md.getRunAs());
        }
    } else if (DECLARED_ROLES.getName().equals(attributeName)) {
        EJBSecurityMetaData md = component.getSecurityMetaData();
        if (md != null) {
            result.setEmptyList();
            Set<String> roles = md.getDeclaredRoles();
            if (roles != null) {
                for (String role : roles) {
                    result.add(role);
                }
            }
        }
    } else if (componentType.hasTimer() && TimerAttributeDefinition.INSTANCE.getName().equals(attributeName)) {
        TimerAttributeDefinition.addTimers(component, result);
    } else if (hasPool && POOL_AVAILABLE_COUNT.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getAvailableCount());
        }
    } else if (hasPool && POOL_CREATE_COUNT.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getCreateCount());
        }
    } else if (hasPool && POOL_NAME.getName().equals(attributeName)) {
        final String poolName = componentType.pooledComponent(component).getPoolName();
        if (poolName != null) {
            result.set(poolName);
        }
    } else if (hasPool && POOL_REMOVE_COUNT.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getRemoveCount());
        }
    } else if (hasPool && POOL_CURRENT_SIZE.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getCurrentSize());
        }
    } else if (hasPool && POOL_MAX_SIZE.getName().equals(attributeName)) {
        final Pool<?> pool = componentType.getPool(component);
        if (pool != null) {
            result.set(pool.getMaxSize());
        }
    } else {
        // Bug; we were registered for an attribute but there is no code for handling it
        throw EjbLogger.ROOT_LOGGER.unknownAttribute(attributeName);
    }
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) Set(java.util.Set) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) Method(java.lang.reflect.Method) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) EJBSecurityMetaData(org.jboss.as.ejb3.security.EJBSecurityMetaData) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) Pool(org.jboss.as.ejb3.pool.Pool) ModelNode(org.jboss.dmr.ModelNode) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 5 with ViewDescription

use of org.jboss.as.ee.component.ViewDescription in project wildfly by wildfly.

the class StatefulComponentDescription method setupViewInterceptors.

@Override
protected void setupViewInterceptors(EJBViewDescription view) {
    // let super do its job
    super.setupViewInterceptors(view);
    // add the @Remove method interceptor
    this.addRemoveMethodInterceptor(view);
    // setup the instance associating interceptors
    this.addStatefulInstanceAssociatingInterceptor(view);
    this.addViewSerializationInterceptor(view);
    if (view.getMethodIntf() == MethodIntf.REMOTE) {
        view.getConfigurators().add(new ViewConfigurator() {

            @Override
            public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
                final String earApplicationName = componentConfiguration.getComponentDescription().getModuleDescription().getEarApplicationName();
                configuration.setViewInstanceFactory(new StatefulRemoteViewInstanceFactory(earApplicationName, componentConfiguration.getModuleName(), componentConfiguration.getComponentDescription().getModuleDescription().getDistinctName(), componentConfiguration.getComponentName()));
            }
        });
    }
}
Also used : ViewConfigurator(org.jboss.as.ee.component.ViewConfigurator) ComponentConfiguration(org.jboss.as.ee.component.ComponentConfiguration) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) DeploymentPhaseContext(org.jboss.as.server.deployment.DeploymentPhaseContext)

Aggregations

ViewDescription (org.jboss.as.ee.component.ViewDescription)25 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)18 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)17 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)17 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)17 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)16 ViewConfigurator (org.jboss.as.ee.component.ViewConfigurator)16 Method (java.lang.reflect.Method)10 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)7 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)5 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)4 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)4 ClassReflectionIndex (org.jboss.as.server.deployment.reflect.ClassReflectionIndex)4 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)4 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)4 HashSet (java.util.HashSet)3 CapabilityServiceSupport (org.jboss.as.controller.capability.CapabilityServiceSupport)3 ComponentView (org.jboss.as.ee.component.ComponentView)3 NamespaceViewConfigurator (org.jboss.as.ee.component.NamespaceViewConfigurator)3 ViewService (org.jboss.as.ee.component.ViewService)3