001/* 002 * Copyright 2010, 2011 Chris Pheby 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.jadira.bindings.core.provider; 017 018import java.lang.reflect.Constructor; 019import java.lang.reflect.Method; 020 021import org.jadira.bindings.core.spi.ConverterProvider; 022import org.joda.convert.FromString; 023import org.joda.convert.ToString; 024 025/** 026 * Provider that is aware of Joda Convert annotations 027 */ 028public class JodaConvertConverterProvider extends AbstractAnnotationMatchingConverterProvider<ToString, FromString> implements ConverterProvider { 029 030 /** 031 * Subclasses can override this template method with their own matching strategy 032 * @param method The method to be determined 033 * @return True if match 034 */ 035 protected boolean isToMatch(Method method) { 036 return String.class.equals(method.getReturnType()); 037 } 038 039 /** 040 * Subclasses can override this template method with their own matching strategy 041 * @param constructor The constructor to be determined 042 * @return True if match 043 */ 044 protected boolean isFromMatch(Constructor<?> constructor) { 045 return String.class.equals(constructor.getParameterTypes()[0]); 046 } 047 048 /** 049 * Subclasses can override this template method with their own matching strategy 050 * @param method The method to be determined 051 * @return True if match 052 */ 053 protected boolean isFromMatch(Method method) { 054 return String.class.equals(method.getParameterTypes()[0]); 055 } 056}