Search in sources :

Example 6 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription 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 7 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class ImplicitLocalViewProcessor method processComponentConfig.

@Override
protected void processComponentConfig(DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, CompositeIndex index, ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
    if (!(componentDescription instanceof SessionBeanComponentDescription)) {
        return;
    }
    SessionBeanComponentDescription sessionBeanComponentDescription = (SessionBeanComponentDescription) componentDescription;
    // if it already has a no-interface  view, then no need to check for the implicit rules
    if (sessionBeanComponentDescription.hasNoInterfaceView()) {
        return;
    }
    // if the bean already exposes some view(s) then it isn't eligible for an implicit no-interface view.
    if (!sessionBeanComponentDescription.getViews().isEmpty()) {
        return;
    }
    String ejbClassName = sessionBeanComponentDescription.getComponentClassName();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (module == null) {
        throw EjbLogger.ROOT_LOGGER.moduleNotAttachedToDeploymentUnit(deploymentUnit);
    }
    ClassLoader cl = module.getClassLoader();
    Class<?> ejbClass = null;
    try {
        ejbClass = cl.loadClass(ejbClassName);
    } catch (ClassNotFoundException cnfe) {
        throw new DeploymentUnitProcessingException(cnfe);
    }
    // check whether it's eligible for implicit no-interface view
    if (this.exposesNoInterfaceView(ejbClass)) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("Bean: %s will be marked for (implicit) no-interface view", sessionBeanComponentDescription.getEJBName());
        sessionBeanComponentDescription.addNoInterfaceView();
        return;
    }
    // check for default local view
    Class<?> defaultLocalView = this.getDefaultLocalView(ejbClass);
    if (defaultLocalView != null) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("Bean: %s will be marked for default local view: %s", sessionBeanComponentDescription.getEJBName(), defaultLocalView.getName());
        sessionBeanComponentDescription.addLocalBusinessInterfaceViews(Collections.singleton(defaultLocalView.getName()));
        return;
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) Module(org.jboss.modules.Module) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 8 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class EjbJndiBindingsDeploymentUnitProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // Only process EJB deployments
    if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
        return;
    }
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
    if (componentDescriptions != null) {
        for (ComponentDescription componentDescription : componentDescriptions) {
            // process only EJB session beans
            if (componentDescription instanceof SessionBeanComponentDescription) {
                this.setupJNDIBindings((EJBComponentDescription) componentDescription, deploymentUnit);
            }
        }
    }
    if (appclient) {
        for (final ComponentDescription component : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
            this.setupJNDIBindings((EJBComponentDescription) component, deploymentUnit);
        }
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 9 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class BusinessViewAnnotationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) {
        return;
    }
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(EE_MODULE_DESCRIPTION);
    final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (module == null) {
        return;
    }
    final ClassLoader moduleClassLoader = module.getClassLoader();
    if (componentDescriptions != null) {
        for (ComponentDescription componentDescription : componentDescriptions) {
            if (componentDescription instanceof SessionBeanComponentDescription == false) {
                continue;
            }
            final Class<?> ejbClass = this.getEjbClass(componentDescription.getComponentClassName(), moduleClassLoader);
            try {
                this.processViewAnnotations(deploymentUnit, ejbClass, (SessionBeanComponentDescription) componentDescription);
            } catch (Exception e) {
                throw EjbLogger.ROOT_LOGGER.failedToProcessBusinessInterfaces(ejbClass, e);
            }
        }
    }
    if (appclient) {
        for (ComponentDescription componentDescription : deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
            if (componentDescription instanceof SessionBeanComponentDescription == false) {
                continue;
            }
            final Class<?> ejbClass = this.getEjbClass(componentDescription.getComponentClassName(), moduleClassLoader);
            try {
                this.processViewAnnotations(deploymentUnit, ejbClass, (SessionBeanComponentDescription) componentDescription);
            } catch (Exception e) {
                throw EjbLogger.ROOT_LOGGER.failedToProcessBusinessInterfaces(ejbClass, e);
            }
        }
    }
}
Also used : SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 10 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class SessionBeanXmlDescriptorProcessor method processBeanMetaData.

/**
     * Processes the passed {@link org.jboss.metadata.ejb.spec.SessionBeanMetaData} and creates appropriate {@link org.jboss.as.ejb3.component.session.SessionBeanComponentDescription} out of it.
     * The {@link org.jboss.as.ejb3.component.session.SessionBeanComponentDescription} is then added to the {@link org.jboss.as.ee.component.EEModuleDescription module description} available
     * in the deployment unit of the passed {@link DeploymentPhaseContext phaseContext}
     *
     * @param sessionBean  The session bean metadata
     * @param phaseContext
     * @throws DeploymentUnitProcessingException
     *
     */
@Override
protected void processBeanMetaData(final SessionBeanMetaData sessionBean, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    // get the module description
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final String beanName = sessionBean.getName();
    ComponentDescription bean = moduleDescription.getComponentByName(beanName);
    if (appclient) {
        if (bean == null) {
            for (final ComponentDescription component : deploymentUnit.getAttachmentList(Attachments.ADDITIONAL_RESOLVABLE_COMPONENTS)) {
                if (component.getComponentName().equals(beanName)) {
                    bean = component;
                    break;
                }
            }
        }
    }
    if (!(bean instanceof SessionBeanComponentDescription)) {
        //if this is a GenericBeanMetadata it may actually represent an MDB
        return;
    }
    SessionBeanComponentDescription sessionBeanDescription = (SessionBeanComponentDescription) bean;
    sessionBeanDescription.setDeploymentDescriptorEnvironment(new DeploymentDescriptorEnvironment("java:comp/env/", sessionBean));
    // mapped-name
    sessionBeanDescription.setMappedName(sessionBean.getMappedName());
    // local business interface views
    final BusinessLocalsMetaData businessLocals = sessionBean.getBusinessLocals();
    if (businessLocals != null && !businessLocals.isEmpty()) {
        sessionBeanDescription.addLocalBusinessInterfaceViews(businessLocals);
    }
    final String local = sessionBean.getLocal();
    if (local != null) {
        sessionBeanDescription.addEjbLocalObjectView(local);
    }
    final String remote = sessionBean.getRemote();
    if (remote != null) {
        sessionBeanDescription.addEjbObjectView(remote);
    }
    // remote business interface views
    final BusinessRemotesMetaData businessRemotes = sessionBean.getBusinessRemotes();
    if (businessRemotes != null && !businessRemotes.isEmpty()) {
        sessionBeanDescription.addRemoteBusinessInterfaceViews(businessRemotes);
    }
    // process EJB3.1 specific session bean description
    if (sessionBean instanceof SessionBean31MetaData) {
        this.processSessionBean31((SessionBean31MetaData) sessionBean, sessionBeanDescription);
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) SessionBean31MetaData(org.jboss.metadata.ejb.spec.SessionBean31MetaData) BusinessLocalsMetaData(org.jboss.metadata.ejb.spec.BusinessLocalsMetaData) BusinessRemotesMetaData(org.jboss.metadata.ejb.spec.BusinessRemotesMetaData)

Aggregations

SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)17 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)11 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)9 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)9 Method (java.lang.reflect.Method)7 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)7 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)5 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)3 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)3 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)3 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)3 StatelessComponentDescription (org.jboss.as.ejb3.component.stateless.StatelessComponentDescription)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 SessionBean31MetaData (org.jboss.metadata.ejb.spec.SessionBean31MetaData)3 SessionBeanMetaData (org.jboss.metadata.ejb.spec.SessionBeanMetaData)3 Module (org.jboss.modules.Module)3 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)2 ComponentStartService (org.jboss.as.ee.component.ComponentStartService)2 ComponentView (org.jboss.as.ee.component.ComponentView)2