1 package org.apache.velocity.util.introspection; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.lang.reflect.Type; 23 24 /** 25 * A conversion handler adds admissible conversions between Java types whenever Velocity introspection has to map 26 * VTL methods and property accessors to Java methods. 27 * Both methods must be consistent: <code>getNeededConverter</code> must not return <code>null</code> whenever 28 * <code>isExplicitlyConvertible</code> returned true with the same arguments. 29 * 30 * @author <a href="mailto:claude.brisson@gmail.com">Claude Brisson</a> 31 * @version $Id: ConversionHandler.java $ 32 * @since 2.1 33 */ 34 35 public interface TypeConversionHandler 36 { 37 /** 38 * Check to see if the conversion can be done using an explicit conversion 39 * @param formal expected formal type 40 * @param actual provided argument type 41 * @param possibleVarArg whether var arg is possible 42 * @return null if no conversion is needed, or the appropriate Converter object 43 * @since 2.1 44 */ isExplicitlyConvertible(Type formal, Class<?> actual, boolean possibleVarArg)45 boolean isExplicitlyConvertible(Type formal, Class<?> actual, boolean possibleVarArg); 46 47 /** 48 * Returns the appropriate Converter object needed for an explicit conversion 49 * Returns null if no conversion is needed. 50 * 51 * @param formal expected formal type 52 * @param actual provided argument type 53 * @return null if no conversion is needed, or the appropriate Converter object 54 * @since 2.1 55 */ getNeededConverter(Type formal, Class<?> actual)56 Converter<?> getNeededConverter(Type formal, Class<?> actual); 57 58 /** 59 * Add the given converter to the handler. Implementation should be thread-safe. 60 * 61 * @param formal expected formal type 62 * @param actual provided argument type 63 * @param converter converter 64 * @since 2.1 65 */ addConverter(Type formal, Class<?> actual, Converter<?> converter)66 void addConverter(Type formal, Class<?> actual, Converter<?> converter); 67 68 } 69