Search in sources :

Example 1 with ObjectProvider

use of org.apache.tapestry5.commons.ObjectProvider in project tapestry-5 by apache.

the class TapestryIOCModule method setupObjectProviders.

/**
 * <dl>
 * <dt>AnnotationBasedContributions</dt>
 * <dd>Empty placeholder used to separate annotation-based ObjectProvider contributions (which come before) from
 * non-annotation based (such as ServiceOverride) which come after.</dd>
 * <dt>Value</dt>
 * <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Value} annotation</dd>
 * <dt>Symbol</dt>
 * <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Symbol} annotations</dd>
 * <dt>Autobuild</dt>
 * <dd>Supports the {@link org.apache.tapestry5.ioc.annotations.Autobuild} annotation</dd>
 * <dt>ServiceOverride</dt>
 * <dd>Allows simple service overrides via the {@link org.apache.tapestry5.ioc.services.ServiceOverride} service
 * (and its configuration)
 * </dl>
 */
@Contribute(MasterObjectProvider.class)
public static void setupObjectProviders(OrderedConfiguration<ObjectProvider> configuration, @Local final ServiceOverride serviceOverride) {
    configuration.add("AnnotationBasedContributions", null);
    configuration.addInstance("Value", ValueObjectProvider.class, before("AnnotationBasedContributions").build());
    configuration.addInstance("Symbol", SymbolObjectProvider.class, before("AnnotationBasedContributions").build());
    configuration.add("Autobuild", new AutobuildObjectProvider(), before("AnnotationBasedContributions").build());
    ObjectProvider wrapper = new ObjectProvider() {

        @Override
        public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
            return serviceOverride.getServiceOverrideProvider().provide(objectType, annotationProvider, locator);
        }
    };
    configuration.add("ServiceOverride", wrapper, after("AnnotationBasedContributions").build());
}
Also used : AutobuildObjectProvider(org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider) ValueObjectProvider(org.apache.tapestry5.ioc.internal.services.ValueObjectProvider) MasterObjectProvider(org.apache.tapestry5.ioc.services.MasterObjectProvider) SymbolObjectProvider(org.apache.tapestry5.ioc.internal.services.SymbolObjectProvider) AutobuildObjectProvider(org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider)

Example 2 with ObjectProvider

use of org.apache.tapestry5.commons.ObjectProvider in project tapestry-5 by apache.

the class RegistryImpl method getOrderedConfiguration.

@Override
@SuppressWarnings("unchecked")
public <T> List<T> getOrderedConfiguration(ServiceDef3 serviceDef, Class<T> objectType) {
    lock.check();
    String serviceId = serviceDef.getServiceId();
    Logger logger = getServiceLogger(serviceId);
    Orderer<T> orderer = new Orderer<T>(logger);
    Map<String, OrderedConfigurationOverride<T>> overrides = CollectionFactory.newCaseInsensitiveMap();
    // TAP5-2129. NOTICE: if someday an ordering between modules is added, this should be reverted
    // or a notice added to the documentation.
    List<Module> modules = new ArrayList<Module>(moduleToServiceDefs.keySet());
    Collections.sort(modules, new ModuleComparator());
    for (Module m : modules) addToOrderedConfiguration(orderer, overrides, objectType, serviceDef, m);
    if (serviceId.equals("MasterObjectProvider")) {
        ObjectProvider contribution = new ObjectProvider() {

            @Override
            public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
                return findServiceByMarkerAndType(objectType, annotationProvider, null);
            }
        };
        orderer.add("ServiceByMarker", (T) contribution);
    }
    for (OrderedConfigurationOverride<T> override : overrides.values()) override.apply();
    final List<T> result = orderer.getOrdered();
    if (!isServiceConfigurationListenerServiceDef(serviceDef)) {
        serviceConfigurationListener.onOrderedConfiguration(serviceDef, result);
    }
    return result;
}
Also used : NullAnnotationProvider(org.apache.tapestry5.commons.internal.NullAnnotationProvider) Logger(org.slf4j.Logger) MasterObjectProvider(org.apache.tapestry5.ioc.services.MasterObjectProvider) TapestryIOCModule(org.apache.tapestry5.ioc.modules.TapestryIOCModule) Orderer(org.apache.tapestry5.ioc.internal.util.Orderer)

Example 3 with ObjectProvider

use of org.apache.tapestry5.commons.ObjectProvider in project tapestry-5 by apache.

the class ServiceAnnotationObjectProviderTest method annotation_present.

@SuppressWarnings("unchecked")
@Test
public void annotation_present() {
    Class objectType = Runnable.class;
    AnnotationProvider provider = mockAnnotationProvider();
    ObjectLocator locator = mockObjectLocator();
    Service service = newMock(Service.class);
    String serviceId = "JiffyPop";
    Runnable instance = mockRunnable();
    train_getAnnotation(provider, Service.class, service);
    expect(service.value()).andReturn(serviceId);
    train_getService(locator, serviceId, objectType, instance);
    replay();
    ObjectProvider objectProvider = new ServiceAnnotationObjectProvider();
    assertSame(objectProvider.provide(objectType, provider, locator), instance);
    verify();
}
Also used : AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) ObjectLocator(org.apache.tapestry5.commons.ObjectLocator) Service(org.apache.tapestry5.annotations.Service) ObjectProvider(org.apache.tapestry5.commons.ObjectProvider) Test(org.testng.annotations.Test)

Example 4 with ObjectProvider

use of org.apache.tapestry5.commons.ObjectProvider in project tapestry-5 by apache.

the class ServiceAnnotationObjectProviderTest method no_annotation.

@SuppressWarnings("unchecked")
@Test
public void no_annotation() {
    Class objectType = Runnable.class;
    AnnotationProvider provider = mockAnnotationProvider();
    ObjectLocator locator = mockObjectLocator();
    train_getAnnotation(provider, Service.class, null);
    replay();
    ObjectProvider objectProvider = new ServiceAnnotationObjectProvider();
    assertNull(objectProvider.provide(objectType, provider, locator));
    verify();
}
Also used : AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) ObjectLocator(org.apache.tapestry5.commons.ObjectLocator) ObjectProvider(org.apache.tapestry5.commons.ObjectProvider) Test(org.testng.annotations.Test)

Example 5 with ObjectProvider

use of org.apache.tapestry5.commons.ObjectProvider in project tapestry-5 by apache.

the class AssetObjectProviderTest method no_path_annotation.

@Test
public void no_path_annotation() {
    AssetSource source = mockAssetSource();
    ObjectLocator locator = mockObjectLocator();
    AnnotationProvider annotationProvider = mockAnnotationProvider();
    TypeCoercer typeCoercer = mockTypeCoercer();
    SymbolSource symbolSource = mockSymbolSource();
    train_getAnnotation(annotationProvider, Path.class, null);
    replay();
    ObjectProvider provider = new AssetObjectProvider(source, typeCoercer, symbolSource);
    assertNull(provider.provide(Asset.class, annotationProvider, locator));
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) TypeCoercer(org.apache.tapestry5.commons.services.TypeCoercer) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) ObjectLocator(org.apache.tapestry5.commons.ObjectLocator) Asset(org.apache.tapestry5.Asset) ObjectProvider(org.apache.tapestry5.commons.ObjectProvider) Test(org.testng.annotations.Test)

Aggregations

AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)4 ObjectLocator (org.apache.tapestry5.commons.ObjectLocator)4 ObjectProvider (org.apache.tapestry5.commons.ObjectProvider)4 Test (org.testng.annotations.Test)4 Asset (org.apache.tapestry5.Asset)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 MasterObjectProvider (org.apache.tapestry5.ioc.services.MasterObjectProvider)2 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)2 AssetSource (org.apache.tapestry5.services.AssetSource)2 Map (java.util.Map)1 Path (org.apache.tapestry5.annotations.Path)1 Service (org.apache.tapestry5.annotations.Service)1 NullAnnotationProvider (org.apache.tapestry5.commons.internal.NullAnnotationProvider)1 AbstractContributionDef (org.apache.tapestry5.http.internal.AbstractContributionDef)1 ModuleBuilderSource (org.apache.tapestry5.ioc.ModuleBuilderSource)1 OperationTracker (org.apache.tapestry5.ioc.OperationTracker)1 ServiceResources (org.apache.tapestry5.ioc.ServiceResources)1 ContributionDef (org.apache.tapestry5.ioc.def.ContributionDef)1 AutobuildObjectProvider (org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider)1 SymbolObjectProvider (org.apache.tapestry5.ioc.internal.services.SymbolObjectProvider)1