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