Search in sources :

Example 1 with IntermediateType

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

the class TypeCoercerImpl method queueIntermediates.

/**
 * Creates and adds to the pool a new set of coercions based on an intermediate tuple. Adds
 * compound coercion tuples
 * to the end of the queue.
 *
 * @param sourceType
 *         the source type of the coercion
 * @param targetType
 *         TODO
 * @param intermediateTuple
 *         a tuple that converts from the source type to some intermediate type (that is not
 *         assignable to the target type)
 * @param consideredTuples
 *         set of tuples that have already been added to the pool (directly, or as a compound
 *         coercion)
 * @param queue
 *         the work queue of tuples
 */
@SuppressWarnings("unchecked")
private void queueIntermediates(Class sourceType, Class targetType, CoercionTuple intermediateTuple, Set<CoercionTuple.Key> consideredTuples, LinkedList<CoercionTuple> queue) {
    Class intermediateType = intermediateTuple.getTargetType();
    for (Class c : new InheritanceSearch(intermediateType)) {
        for (CoercionTuple tuple : getTuples(c, targetType)) {
            if (consideredTuples.contains(tuple.getKey())) {
                continue;
            }
            Class newIntermediateType = tuple.getTargetType();
            if (sourceType.isAssignableFrom(newIntermediateType)) {
                continue;
            }
            // The intermediateTuple coercer gets from S --> I1 (an intermediate type).
            // The current tuple's coercer gets us from I2 --> X. where I2 is assignable
            // from I1 (i.e., I2 is a superclass/superinterface of I1) and X is a new
            // intermediate type, hopefully closer to our eventual target type.
            Coercion compoundCoercer = new CompoundCoercion(intermediateTuple.getCoercion(), tuple.getCoercion());
            CoercionTuple compoundTuple = new CoercionTuple(sourceType, newIntermediateType, compoundCoercer, false);
            // So, every tuple that is added to the queue can take as input the sourceType.
            // The target type may be another intermediate type, or may be something
            // assignable to the target type, which will bring the search to a successful
            // conclusion.
            queue.addLast(compoundTuple);
            consideredTuples.add(tuple.getKey());
        }
    }
}
Also used : CoercionTuple(org.apache.tapestry5.commons.services.CoercionTuple) InheritanceSearch(org.apache.tapestry5.commons.internal.util.InheritanceSearch) StringToEnumCoercion(org.apache.tapestry5.commons.util.StringToEnumCoercion) Coercion(org.apache.tapestry5.commons.services.Coercion)

Example 2 with IntermediateType

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

the class TapestryIOCModule method buildDeferredExecution.

public static ParallelExecutor buildDeferredExecution(@Symbol(IOCSymbols.THREAD_POOL_CORE_SIZE) int coreSize, @Symbol(IOCSymbols.THREAD_POOL_MAX_SIZE) int maxSize, @Symbol(IOCSymbols.THREAD_POOL_KEEP_ALIVE) @IntermediateType(TimeInterval.class) int keepAliveMillis, @Symbol(IOCSymbols.THREAD_POOL_ENABLED) boolean threadPoolEnabled, @Symbol(IOCSymbols.THREAD_POOL_QUEUE_SIZE) int queueSize, PerthreadManager perthreadManager, RegistryShutdownHub shutdownHub, ThunkCreator thunkCreator) {
    if (!threadPoolEnabled)
        return new NonParallelExecutor();
    LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(queueSize);
    final ThreadPoolExecutor executorService = new ThreadPoolExecutor(coreSize, maxSize, keepAliveMillis, TimeUnit.MILLISECONDS, workQueue);
    shutdownHub.addRegistryShutdownListener(new Runnable() {

        @Override
        public void run() {
            executorService.shutdown();
        }
    });
    return new ParallelExecutorImpl(executorService, thunkCreator, perthreadManager);
}
Also used : NonParallelExecutor(org.apache.tapestry5.ioc.internal.services.NonParallelExecutor) ParallelExecutorImpl(org.apache.tapestry5.ioc.internal.services.ParallelExecutorImpl) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) ServiceOverride(org.apache.tapestry5.ioc.services.ServiceOverride)

Example 3 with IntermediateType

use of org.apache.tapestry5.ioc.annotations.IntermediateType 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)

Example 4 with IntermediateType

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

the class ValueObjectProvider method provide.

@Override
public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
    Value annotation = annotationProvider.getAnnotation(Value.class);
    if (annotation == null)
        return null;
    String value = annotation.value();
    Object expanded = symbolSource.expandSymbols(value);
    IntermediateType intermediate = annotationProvider.getAnnotation(IntermediateType.class);
    if (intermediate != null)
        expanded = typeCoercer.coerce(expanded, intermediate.value());
    return typeCoercer.coerce(expanded, objectType);
}
Also used : IntermediateType(org.apache.tapestry5.ioc.annotations.IntermediateType) Value(org.apache.tapestry5.ioc.annotations.Value)

Example 5 with IntermediateType

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

the class TestAdvice method advise.

@Override
public void advise(MethodInvocation invocation) {
    final Method method = invocation.getMethod();
    boolean annotationFoundInMethod = checkAnnotation(method.getAnnotation(Advise.class));
    boolean annotationFoundThroughAnnotationProvider = checkAnnotation(invocation.getAnnotation(Advise.class));
    IntermediateType parameterAnnotation = null;
    final Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    if (parameterAnnotations.length > 0 && parameterAnnotations[0].length > 0) {
        parameterAnnotation = (IntermediateType) parameterAnnotations[0][0];
    }
    boolean annotationParameter = parameterAnnotation != null && parameterAnnotation.value() == String.class;
    if (annotationFoundInMethod && annotationFoundThroughAnnotationProvider && annotationParameter) {
        invocation.setReturnValue(ANNOTATION_FOUND);
    } else {
        invocation.proceed();
    }
}
Also used : IntermediateType(org.apache.tapestry5.ioc.annotations.IntermediateType) Method(java.lang.reflect.Method) Advise(org.apache.tapestry5.ioc.annotations.Advise)

Aggregations

IntermediateType (org.apache.tapestry5.ioc.annotations.IntermediateType)3 Method (java.lang.reflect.Method)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 InheritanceSearch (org.apache.tapestry5.commons.internal.util.InheritanceSearch)1 Coercion (org.apache.tapestry5.commons.services.Coercion)1 CoercionTuple (org.apache.tapestry5.commons.services.CoercionTuple)1 StringToEnumCoercion (org.apache.tapestry5.commons.util.StringToEnumCoercion)1 Advise (org.apache.tapestry5.ioc.annotations.Advise)1 Symbol (org.apache.tapestry5.ioc.annotations.Symbol)1 Value (org.apache.tapestry5.ioc.annotations.Value)1 NonParallelExecutor (org.apache.tapestry5.ioc.internal.services.NonParallelExecutor)1 ParallelExecutorImpl (org.apache.tapestry5.ioc.internal.services.ParallelExecutorImpl)1 ServiceOverride (org.apache.tapestry5.ioc.services.ServiceOverride)1