Search in sources :

Example 11 with InterceptorFactory

use of org.jboss.invocation.InterceptorFactory in project wildfly by wildfly.

the class NamespaceConfigurator method configure.

/** {@inheritDoc} */
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final ComponentNamingMode namingMode = description.getNamingMode();
    final InjectedEENamespaceContextSelector selector = new InjectedEENamespaceContextSelector();
    final String applicationName = configuration.getApplicationName();
    final String moduleName = configuration.getModuleName();
    final String compName = configuration.getComponentName();
    final ServiceName appContextServiceName = ContextNames.contextServiceNameOfApplication(applicationName);
    final ServiceName moduleContextServiceName = ContextNames.contextServiceNameOfModule(applicationName, moduleName);
    final ServiceName compContextServiceName = ContextNames.contextServiceNameOfComponent(applicationName, moduleName, compName);
    final Injector<NamingStore> appInjector = selector.getAppContextInjector();
    final Injector<NamingStore> moduleInjector = selector.getModuleContextInjector();
    final Injector<NamingStore> compInjector = selector.getCompContextInjector();
    final Injector<NamingStore> jbossInjector = selector.getJbossContextInjector();
    final Injector<NamingStore> globalInjector = selector.getGlobalContextInjector();
    final Injector<NamingStore> exportedInjector = selector.getExportedContextInjector();
    configuration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

        public void configureDependency(final ServiceBuilder<?> serviceBuilder, ComponentStartService service) {
            serviceBuilder.addDependency(appContextServiceName, NamingStore.class, appInjector);
            serviceBuilder.addDependency(moduleContextServiceName, NamingStore.class, moduleInjector);
            if (namingMode == ComponentNamingMode.CREATE) {
                serviceBuilder.addDependency(compContextServiceName, NamingStore.class, compInjector);
            } else if (namingMode == ComponentNamingMode.USE_MODULE) {
                serviceBuilder.addDependency(moduleContextServiceName, NamingStore.class, compInjector);
            }
            serviceBuilder.addDependency(ContextNames.GLOBAL_CONTEXT_SERVICE_NAME, NamingStore.class, globalInjector);
            serviceBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, NamingStore.class, jbossInjector);
            serviceBuilder.addDependency(ContextNames.EXPORTED_CONTEXT_SERVICE_NAME, NamingStore.class, exportedInjector);
        }
    });
    final InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new NamespaceContextInterceptor(selector, context.getDeploymentUnit().getServiceName()));
    configuration.addPostConstructInterceptor(interceptorFactory, InterceptorOrder.ComponentPostConstruct.JNDI_NAMESPACE_INTERCEPTOR);
    configuration.addPreDestroyInterceptor(interceptorFactory, InterceptorOrder.ComponentPreDestroy.JNDI_NAMESPACE_INTERCEPTOR);
    if (description.isPassivationApplicable()) {
        configuration.addPrePassivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
        configuration.addPostActivateInterceptor(interceptorFactory, InterceptorOrder.ComponentPassivation.JNDI_NAMESPACE_INTERCEPTOR);
    }
    configuration.setNamespaceContextInterceptorFactory(interceptorFactory);
    configuration.setNamespaceContextSelector(selector);
}
Also used : NamingStore(org.jboss.as.naming.NamingStore) InterceptorFactory(org.jboss.invocation.InterceptorFactory) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) ServiceName(org.jboss.msc.service.ServiceName) InjectedEENamespaceContextSelector(org.jboss.as.ee.naming.InjectedEENamespaceContextSelector) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory)

Example 12 with InterceptorFactory

use of org.jboss.invocation.InterceptorFactory in project wildfly by wildfly.

the class ViewService method start.

public void start(final StartContext context) throws StartException {
    // Construct the view
    View view = new View(privateData);
    view.initializeInterceptors();
    this.view = view;
    final SimpleInterceptorFactoryContext factoryContext = new SimpleInterceptorFactoryContext();
    final Component component = view.getComponent();
    factoryContext.getContextData().put(Component.class, component);
    factoryContext.getContextData().put(ComponentView.class, view);
    clientPostConstructInterceptor = clientPostConstruct.create(factoryContext);
    clientPreDestroyInterceptor = clientPreDestroy.create(factoryContext);
    final Map<Method, InterceptorFactory> clientInterceptorFactories = ViewService.this.clientInterceptorFactories;
    clientInterceptors = new IdentityHashMap<Method, Interceptor>(clientInterceptorFactories.size());
    for (Method method : clientInterceptorFactories.keySet()) {
        clientInterceptors.put(method, clientInterceptorFactories.get(method).create(factoryContext));
    }
}
Also used : SimpleInterceptorFactoryContext(org.jboss.invocation.SimpleInterceptorFactoryContext) InterceptorFactory(org.jboss.invocation.InterceptorFactory) Method(java.lang.reflect.Method) Interceptor(org.jboss.invocation.Interceptor)

Example 13 with InterceptorFactory

use of org.jboss.invocation.InterceptorFactory in project wildfly by wildfly.

the class ComponentConfiguration method addComponentInterceptors.

/**
     * Adds an interceptor factory to every method on the component.
     *
     * @param factory    The interceptor factory to add
     * @param priority   The interceptors relative order
     * @param publicOnly If true then then interceptor is only added to public methods
     */
public void addComponentInterceptors(List<InterceptorFactory> factory, int priority, boolean publicOnly) {
    for (Method method : (Iterable<Method>) classIndex.getClassMethods()) {
        if (publicOnly && !Modifier.isPublic(method.getModifiers())) {
            continue;
        }
        OrderedItemContainer<List<InterceptorFactory>> interceptors = componentInterceptors.get(method);
        if (interceptors == null) {
            componentInterceptors.put(method, interceptors = new OrderedItemContainer<List<InterceptorFactory>>());
        }
        interceptors.add(factory, priority);
    }
}
Also used : InterceptorFactory(org.jboss.invocation.InterceptorFactory) OrderedItemContainer(org.jboss.as.ee.component.interceptors.OrderedItemContainer) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method)

Aggregations

InterceptorFactory (org.jboss.invocation.InterceptorFactory)13 Method (java.lang.reflect.Method)10 ImmediateInterceptorFactory (org.jboss.invocation.ImmediateInterceptorFactory)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)5 List (java.util.List)4 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)4 Interceptor (org.jboss.invocation.Interceptor)4 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)3 UserInterceptorFactory (org.jboss.as.ee.component.interceptors.UserInterceptorFactory)3 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 Module (org.jboss.modules.Module)3 ServiceName (org.jboss.msc.service.ServiceName)3 ArrayDeque (java.util.ArrayDeque)2 IdentityHashMap (java.util.IdentityHashMap)2 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)2 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)2 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)2