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