1 /*
2 * Copyright 2010, 2011 Chris Pheby
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.jadira.bindings.core.provider;
17
18 import java.lang.reflect.Constructor;
19 import java.lang.reflect.Method;
20
21 import org.jadira.bindings.core.annotation.typesafe.FromString;
22 import org.jadira.bindings.core.annotation.typesafe.ToString;
23 import org.jadira.bindings.core.spi.ConverterProvider;
24
25 /**
26 * Provider that is aware of {@link org.jadira.bindings.core.annotation.typesafe.ToString} and {@link org.jadira.bindings.core.annotation.typesafe.FromString} annotations
27 */
28 public class StringConverterProvider extends AbstractAnnotationMatchingConverterProvider<ToString, FromString> implements ConverterProvider {
29
30 /**
31 * Subclasses can override this template method with their own matching strategy
32 * @param method The method to be determined
33 * @return True if match
34 */
35 protected boolean isToMatch(Method method) {
36 return String.class.equals(method.getReturnType());
37 }
38
39 /**
40 * Subclasses can override this template method with their own matching strategy
41 * @param constructor The constructor to be determined
42 * @return True if match
43 */
44 protected boolean isFromMatch(Constructor<?> constructor) {
45 return String.class.equals(constructor.getParameterTypes()[0]);
46 }
47
48 /**
49 * Subclasses can override this template method with their own matching strategy
50 * @param method The method to be determined
51 * @return True if match
52 */
53 protected boolean isFromMatch(Method method) {
54 return String.class.equals(method.getParameterTypes()[0]);
55 }
56 }