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