Search in sources :

Example 6 with ObjectLocator

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

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);
}
Also used : Path(org.apache.tapestry5.annotations.Path) Asset(org.apache.tapestry5.Asset)

Example 8 with ObjectLocator

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;
}
Also used : Id(org.apache.tapestry5.annotations.Id)

Example 9 with ObjectLocator

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);
            }
        }
    }
}
Also used : CacheMethodAdvice(org.apache.tapestry5.jcache.internal.CacheMethodAdvice) CacheRemoveAllMethodAdvice(org.apache.tapestry5.jcache.internal.CacheRemoveAllMethodAdvice) CacheRemoveMethodAdvice(org.apache.tapestry5.jcache.internal.CacheRemoveMethodAdvice) MethodAdvice(org.apache.tapestry5.plastic.MethodAdvice) CacheResultMethodAdvice(org.apache.tapestry5.jcache.internal.CacheResultMethodAdvice) CachePutMethodAdvice(org.apache.tapestry5.jcache.internal.CachePutMethodAdvice) Method(java.lang.reflect.Method)

Example 10 with ObjectLocator

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);
}
Also used : IntermediateType(org.apache.tapestry5.ioc.annotations.IntermediateType) Symbol(org.apache.tapestry5.ioc.annotations.Symbol)

Aggregations

Asset (org.apache.tapestry5.Asset)5 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)5 ObjectLocator (org.apache.tapestry5.commons.ObjectLocator)5 Test (org.testng.annotations.Test)5 ObjectProvider (org.apache.tapestry5.commons.ObjectProvider)4 Path (org.apache.tapestry5.annotations.Path)3 Map (java.util.Map)2 ComponentResources (org.apache.tapestry5.ComponentResources)2 NullAnnotationProvider (org.apache.tapestry5.commons.internal.NullAnnotationProvider)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 IntermediateType (org.apache.tapestry5.ioc.annotations.IntermediateType)2 MasterObjectProvider (org.apache.tapestry5.ioc.services.MasterObjectProvider)2 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)2 AssetSource (org.apache.tapestry5.services.AssetSource)2 ObjectStreamException (java.io.ObjectStreamException)1 Annotation (java.lang.annotation.Annotation)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 DateFormat (java.text.DateFormat)1