| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 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 net.sourceforge.hiveutils.service.impl; |
| 16 | |
| 17 | import java.lang.reflect.Method; |
| 18 | |
| 19 | import org.apache.commons.logging.Log; |
| 20 | |
| 21 | import net.sourceforge.hiveutils.util.MethodMappingErrorHandler; |
| 22 | |
| 23 | /** |
| 24 | * Default implmentation of <code>MethodMappingErrorHandler</code>, used by |
| 25 | * <code>AdapterBuilderFactory</code> to log warnings. |
| 26 | * |
| 27 | * @author Jean-Francois Poilpret |
| 28 | */ |
| 29 | public class DefaultMethodMappingErrorHandler implements MethodMappingErrorHandler |
| 30 | { |
| 31 | public DefaultMethodMappingErrorHandler(Log logger) |
| 32 | { |
| 33 | _logger = logger; |
| 34 | } |
| 35 | |
| 36 | public boolean handleIncompatibleMethods(Method source, Method target) |
| 37 | { |
| 38 | Class srcReturn = source.getReturnType(); |
| 39 | Class tgtReturn = target.getReturnType(); |
| 40 | _logger.warn( srcReturn.getName() + " " + source.getClass().getName() + |
| 41 | "." + source.getName() + |
| 42 | "() return type is not assignable from " + |
| 43 | tgtReturn.getName() + " " + target.getClass().getName() + |
| 44 | "." + target.getName() + "()"); |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | public void handleNonExistingMethod(Method source, Class target) |
| 49 | { |
| 50 | _logger.error( target.getName() + " class does not implement method " + |
| 51 | source.getName() + " of " + |
| 52 | source.getClass().getName() + |
| 53 | " service interface"); |
| 54 | } |
| 55 | |
| 56 | private final Log _logger; |
| 57 | } |