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);
}
}
}
});
}
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;
}
}
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);
}
}
}
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);
}
}
}
}
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);
}
}
Aggregations