Search in sources :

Example 1 with OperationTracker

use of org.apache.tapestry5.ioc.OperationTracker in project tapestry-5 by apache.

the class IOCTestCase method mockServiceBuilderResources.

protected final ServiceBuilderResources mockServiceBuilderResources(OperationTracker tracker) {
    ServiceBuilderResources resources = mockServiceBuilderResources();
    train_getTracker(resources, tracker);
    return resources;
}
Also used : ServiceBuilderResources(org.apache.tapestry5.ioc.ServiceBuilderResources)

Example 2 with OperationTracker

use of org.apache.tapestry5.ioc.OperationTracker in project tapestry-5 by apache.

the class JavaScriptModule method setupModuleDispatchers.

@Contribute(Dispatcher.class)
@Primary
public static void setupModuleDispatchers(OrderedConfiguration<Dispatcher> configuration, ModuleManager moduleManager, OperationTracker tracker, ResourceStreamer resourceStreamer, PathConstructor pathConstructor, JavaScriptStackSource javaScriptStackSource, JavaScriptStackPathConstructor javaScriptStackPathConstructor, LocalizationSetter localizationSetter, @Symbol(SymbolConstants.MODULE_PATH_PREFIX) String modulePathPrefix, @Symbol(SymbolConstants.ASSET_PATH_PREFIX) String assetPathPrefix) {
    configuration.add("Modules", new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor, javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix, assetPathPrefix, false), "after:Asset", "before:ComponentEvent");
    configuration.add("ComnpressedModules", new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor, javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix, assetPathPrefix, true), "after:Modules", "before:ComponentEvent");
}
Also used : ModuleDispatcher(org.apache.tapestry5.internal.services.javascript.ModuleDispatcher) Primary(org.apache.tapestry5.ioc.annotations.Primary) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 3 with OperationTracker

use of org.apache.tapestry5.ioc.OperationTracker in project tapestry-5 by apache.

the class IOCTestCase method mockServiceResources.

protected final ServiceResources mockServiceResources(OperationTracker tracker) {
    ServiceResources resources = mockServiceResources();
    train_getTracker(resources, tracker);
    return resources;
}
Also used : ServiceResources(org.apache.tapestry5.ioc.ServiceResources)

Example 4 with OperationTracker

use of org.apache.tapestry5.ioc.OperationTracker in project tapestry-5 by apache.

the class SpringModuleDef method createContributionToMasterObjectProvider.

private ContributionDef createContributionToMasterObjectProvider() {
    ContributionDef def = new AbstractContributionDef() {

        @Override
        public String getServiceId() {
            return "MasterObjectProvider";
        }

        @Override
        public void contribute(ModuleBuilderSource moduleSource, ServiceResources resources, OrderedConfiguration configuration) {
            final OperationTracker tracker = resources.getTracker();
            final ApplicationContext context = resources.getService(SERVICE_ID, ApplicationContext.class);
            final ObjectProvider springBeanProvider = new ObjectProvider() {

                @Override
                public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
                    Map beanMap = context.getBeansOfType(objectType);
                    switch(beanMap.size()) {
                        case 0:
                            return null;
                        case 1:
                            Object bean = beanMap.values().iterator().next();
                            return objectType.cast(bean);
                        default:
                            String message = String.format("Spring context contains %d beans assignable to type %s: %s.", beanMap.size(), PlasticUtils.toTypeName(objectType), InternalUtils.joinSorted(beanMap.keySet()));
                            throw new IllegalArgumentException(message);
                    }
                }
            };
            final ObjectProvider springBeanProviderInvoker = new ObjectProvider() {

                @Override
                public <T> T provide(final Class<T> objectType, final AnnotationProvider annotationProvider, final ObjectLocator locator) {
                    return tracker.invoke("Resolving dependency by searching Spring ApplicationContext", new Invokable<T>() {

                        @Override
                        public T invoke() {
                            return springBeanProvider.provide(objectType, annotationProvider, locator);
                        }
                    });
                }
            };
            ObjectProvider outerCheck = new ObjectProvider() {

                @Override
                public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
                    if (!applicationContextCreated.get())
                        return null;
                    return springBeanProviderInvoker.provide(objectType, annotationProvider, locator);
                }
            };
            configuration.add("SpringBean", outerCheck, "after:AnnotationBasedContributions", "after:ServiceOverride");
        }
    };
    return def;
}
Also used : OperationTracker(org.apache.tapestry5.ioc.OperationTracker) ModuleBuilderSource(org.apache.tapestry5.ioc.ModuleBuilderSource) ContributionDef(org.apache.tapestry5.ioc.def.ContributionDef) AbstractContributionDef(org.apache.tapestry5.http.internal.AbstractContributionDef) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) AbstractContributionDef(org.apache.tapestry5.http.internal.AbstractContributionDef) ServiceResources(org.apache.tapestry5.ioc.ServiceResources) Map(java.util.Map)

Aggregations

ServiceResources (org.apache.tapestry5.ioc.ServiceResources)2 Map (java.util.Map)1 AbstractContributionDef (org.apache.tapestry5.http.internal.AbstractContributionDef)1 ModuleDispatcher (org.apache.tapestry5.internal.services.javascript.ModuleDispatcher)1 ModuleBuilderSource (org.apache.tapestry5.ioc.ModuleBuilderSource)1 OperationTracker (org.apache.tapestry5.ioc.OperationTracker)1 ServiceBuilderResources (org.apache.tapestry5.ioc.ServiceBuilderResources)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 Primary (org.apache.tapestry5.ioc.annotations.Primary)1 ContributionDef (org.apache.tapestry5.ioc.def.ContributionDef)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1