Search in sources :

Example 1 with InheritanceSearch

use of org.apache.tapestry5.commons.internal.util.InheritanceSearch 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 InheritanceSearch

use of org.apache.tapestry5.commons.internal.util.InheritanceSearch in project tapestry-5 by apache.

the class TypeCoercerImpl method seedQueue.

/**
 * Seeds the pool with the initial set of coercions for the given type.
 */
private void seedQueue(Class sourceType, Class targetType, Set<CoercionTuple.Key> consideredTuples, LinkedList<CoercionTuple> queue) {
    for (Class c : new InheritanceSearch(sourceType)) {
        List<CoercionTuple> tuples = getTuples(c, targetType);
        if (tuples == null) {
            continue;
        }
        for (CoercionTuple tuple : tuples) {
            queue.addLast(tuple);
            consideredTuples.add(tuple.getKey());
        }
        if (sourceType == Void.class) {
            return;
        }
    }
}
Also used : CoercionTuple(org.apache.tapestry5.commons.services.CoercionTuple) InheritanceSearch(org.apache.tapestry5.commons.internal.util.InheritanceSearch)

Aggregations

InheritanceSearch (org.apache.tapestry5.commons.internal.util.InheritanceSearch)2 CoercionTuple (org.apache.tapestry5.commons.services.CoercionTuple)2 Coercion (org.apache.tapestry5.commons.services.Coercion)1 StringToEnumCoercion (org.apache.tapestry5.commons.util.StringToEnumCoercion)1