Home » tapestry-src-5.0.19 » org.apache.tapestry5.ioc.services » [javadoc | source]

    1   // Copyright 2006, 2007, 2008 The Apache Software Foundation
    2   //
    3   // Licensed under the Apache License, Version 2.0 (the "License");
    4   // you may not use this file except in compliance with the License.
    5   // You may obtain a copy of the License at
    6   //
    7   //     http://www.apache.org/licenses/LICENSE-2.0
    8   //
    9   // Unless required by applicable law or agreed to in writing, software
   10   // distributed under the License is distributed on an "AS IS" BASIS,
   11   // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12   // See the License for the specific language governing permissions and
   13   // limitations under the License.
   14   
   15   package org.apache.tapestry5.ioc.services;
   16   
   17   import org.apache.tapestry5.ioc.annotations.UsesConfiguration;
   18   
   19   /**
   20    * Makes use of {@link org.apache.tapestry5.ioc.services.Coercion}s  to convert between an input value (of some specific
   21    * type) and a desired output type. Smart about coercing, even if it requires multiple coercion steps (i.e., via an
   22    * intermediate type, such as String).
   23    */
   24   @UsesConfiguration(CoercionTuple.class)
   25   public interface TypeCoercer
   26   {
   27       /**
   28        * Performs a coercion from an input type to a desired output type. When the target type is a primitive, the actual
   29        * conversion will be to the equivalent wrapper type. In some cases, the TypeCoercer will need to search for an
   30        * appropriate coercion, and may even combine existing coercions to form new ones; in those cases, the results of
   31        * the search are cached.
   32        * <p/>
   33        * <p/>
   34        * The TypeCoercer also caches the results of a coercion search.
   35        *
   36        * @param <S>        source type (input)
   37        * @param <T>        target type (output)
   38        * @param input
   39        * @param targetType defines the target type
   40        * @return the coerced value
   41        */
   42       <S, T> T coerce(S input, Class<T> targetType);
   43   
   44       /**
   45        * Used primarily inside test suites, this method performs the same steps as {@link #coerce(Object, Class)}, but
   46        * returns a string describing the series of coercision, such as "Object --&gt; String --&gt; Long --&gt; Integer".
   47        *
   48        * @param <S>        source type (input)
   49        * @param <T>        target type (output)
   50        * @param inputType  the source coercion type (use void.class for coercions from null)
   51        * @param targetType defines the target type
   52        * @return a string identifying the series of coercions, or the empty string if no coercion is necessary
   53        */
   54       <S, T> String explain(Class<S> inputType, Class<T> targetType);
   55   
   56       /**
   57        * Clears cached information stored by the TypeCoercer.
   58        */
   59       void clearCache();
   60   }

Home » tapestry-src-5.0.19 » org.apache.tapestry5.ioc.services » [javadoc | source]