use of org.apache.tapestry5.commons.ObjectLocator 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.ObjectLocator in project tapestry-5 by apache.
the class AssetObjectProvider method provide.
/**
* Provides the asset. If the expression does not identify an asset domain, with a prefix, it is assumed to be a
* path on the classpath, relative to the root of the classpath.
*
* @param objectType the type of object (which must be Object or Asset)
* @param locator not used
*/
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
Path path = annotationProvider.getAnnotation(Path.class);
if (path == null)
return null;
String expanded = symbolSource.expandSymbols(path.value());
Asset asset = source.getAsset(null, expanded, null);
return typeCoercer.coerce(asset, objectType);
}
use of org.apache.tapestry5.commons.ObjectLocator in project tapestry-5 by apache.
the class BlockInjectionProvider method provideInjection.
public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
if (!field.getTypeName().equals(BLOCK_TYPE_NAME)) {
return false;
}
Id annotation = field.getAnnotation(Id.class);
String blockId = getBlockId(field.getName(), annotation);
FieldConduit<Object> conduit = createConduit(field, blockId);
field.setConduit(conduit);
// claim the field
return true;
}
use of org.apache.tapestry5.commons.ObjectLocator in project tapestry-5 by apache.
the class JCacheModule method advise.
private static void advise(Class<? extends Annotation> annotationClass, ObjectLocator objectLocator, Class<? extends CacheMethodAdvice> adviceClass, MethodAdviceReceiver methodAdviceReceiver) {
// TAP5-2466: create the advice on-demand to avoid recursion issues
MethodAdvice advice = null;
if (methodAdviceReceiver.getClassAnnotationProvider().getAnnotation(annotationClass) != null) {
advice = build(objectLocator, adviceClass);
methodAdviceReceiver.adviseAllMethods(advice);
} else {
for (Method method : methodAdviceReceiver.getInterface().getMethods()) {
if (methodAdviceReceiver.getMethodAnnotation(method, annotationClass) != null) {
if (advice == null) {
advice = build(objectLocator, adviceClass);
}
methodAdviceReceiver.adviseMethod(method, advice);
}
}
}
}
use of org.apache.tapestry5.commons.ObjectLocator in project tapestry-5 by apache.
the class SymbolObjectProvider method provide.
@Override
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
Symbol annotation = annotationProvider.getAnnotation(Symbol.class);
if (annotation == null)
return null;
Object value = symbolSource.valueForSymbol(annotation.value());
IntermediateType it = annotationProvider.getAnnotation(IntermediateType.class);
if (it != null)
value = typeCoercer.coerce(value, it.value());
return typeCoercer.coerce(value, objectType);
}
Aggregations