Package org.apache.tapestry5.ioc.services

Examples of org.apache.tapestry5.ioc.services.CoercionTuple


        ClassPath path = new LoaderClassPath(loader);

        classPool.appendClassPath(path);

        classSource = new CtClassSourceImpl(classPool, loader);

        try
        {
            loader.addTranslator(classPool, this);
        }
View Full Code Here


        seedQueue(sourceType, targetType, consideredTuples, queue);

        while (!queue.isEmpty())
        {
            CoercionTuple tuple = queue.removeFirst();

            // If the tuple results in a value type that is assignable to the desired target type,
            // we're done! Later, we may add a concept of "cost" (i.e. number of steps) or
            // "quality" (how close is the tuple target type to the desired target type). Cost
            // is currently implicit, as compound tuples are stored deeper in the queue,
            // so simpler coercions will be located earlier.

            Class tupleTargetType = tuple.getTargetType();

            if (targetType.isAssignableFrom(tupleTargetType))
            {
                return tuple.getCoercion();
            }

            // So .. this tuple doesn't get us directly to the target type.
            // However, it *may* get us part of the way. Each of these
            // represents a coercion from the source type to an intermediate type.
View Full Code Here

                // 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.
View Full Code Here

        // the tuple unnecessarily (such as when an explicit string-to-enum coercion is part of the TypeCoercer
        // configuration), but on the whole, this is cheap and works.

        if (sourceType == String.class && Enum.class.isAssignableFrom(targetType))
        {
            tuples = extend(tuples, new CoercionTuple(sourceType, targetType, new StringToEnumCoercion(targetType)));
        }

        return tuples;
    }
View Full Code Here

                // 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.
View Full Code Here

        // the tuple unnecessarily (such as when an explicit string-to-enum coercion is part of the TypeCoercer
        // configuration), but on the whole, this is cheap and works.

        if (sourceType == String.class && Enum.class.isAssignableFrom(targetType))
        {
            tuples = extend(tuples, new CoercionTuple(sourceType, targetType, new StringToEnumCoercion(targetType)));
        }

        return tuples;
    }
View Full Code Here

        seedQueue(sourceType, targetType, consideredTuples, queue);

        while (!queue.isEmpty())
        {
            CoercionTuple tuple = queue.removeFirst();

            // If the tuple results in a value type that is assignable to the desired target type,
            // we're done! Later, we may add a concept of "cost" (i.e. number of steps) or
            // "quality" (how close is the tuple target type to the desired target type). Cost
            // is currently implicit, as compound tuples are stored deeper in the queue,
            // so simpler coercions will be located earlier.

            Class tupleTargetType = tuple.getTargetType();

            if (targetType.isAssignableFrom(tupleTargetType))
            {
                return tuple.getCoercion();
            }

            // So .. this tuple doesn't get us directly to the target type.
            // However, it *may* get us part of the way. Each of these
            // represents a coercion from the source type to an intermediate type.
View Full Code Here

     *
     * @param configuration lets help the {@link org.apache.tapestry5.ioc.services.TypeCoercer} service
     */
    public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration)
    {
        configuration.add(new CoercionTuple(String.class, WriteConcern.class,
                new Coercion<String, WriteConcern>() {
                    public WriteConcern coerce(String input)
                    {
                        if (input.equalsIgnoreCase("FSYNC_SAFE"))
                        {
                            return WriteConcern.FSYNC_SAFE;
                        }
                        else if (input.equalsIgnoreCase("JOURNAL_SAFE"))
                        {
                            return WriteConcern.JOURNAL_SAFE;
                        }
                        else if (input.equalsIgnoreCase("MAJORITY"))
                        {
                            return WriteConcern.MAJORITY;
                        }
                        else if (input.equalsIgnoreCase("NONE"))
                        {
                            return WriteConcern.NONE;
                        }
                        else if (input.equalsIgnoreCase("REPLICAS_SAFE"))
                        {
                            return WriteConcern.REPLICAS_SAFE;
                        }
                        else if (input.equalsIgnoreCase("SAFE"))
                        {
                            return WriteConcern.SAFE;
                        }
            else if (input.equalsIgnoreCase("NORMAL"))
            {
              return WriteConcern.NORMAL;
            }
                        else // WriteConcern.ACKNOWLEDGED IS OUR DEFAULT
                        {
                            return WriteConcern.ACKNOWLEDGED;
                        }
                    }
                }
        ));

        configuration.add(new CoercionTuple(String.class, ReadPreference.class, new Coercion<String, ReadPreference>() {
            public ReadPreference coerce(String input)
            {
                if (input.equalsIgnoreCase("SECONDARY"))
                {
                    return ReadPreference.secondary();
View Full Code Here

        seedQueue(sourceType, consideredTuples, queue);

        while (!queue.isEmpty())
        {
            CoercionTuple tuple = queue.removeFirst();

            // If the tuple results in a value type that is assignable to the desired target type,
            // we're done! Later, we may add a concept of "cost" (i.e. number of steps) or
            // "quality" (how close is the tuple target type to the desired target type). Cost
            // is currently implicit, as compound tuples are stored deeper in the queue,
            // so simpler coercions will be located earlier.

            Class tupleTargetType = tuple.getTargetType();

            if (targetType.isAssignableFrom(tupleTargetType))
                return tuple.getCoercion();

            // So .. this tuple doesn't get us directly to the target type.
            // However, it *may* get us part of the way. Each of these
            // represents a coercion from the source type to an intermediate type.
            // Now we're going to look for conversions from the intermediate type
View Full Code Here

                // 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 intermdiate type, or may be something
                // assignable to the target type, which will bring the search to a succesful
                // conclusion.
View Full Code Here

TOP

Related Classes of org.apache.tapestry5.ioc.services.CoercionTuple

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.