1 15 package org.apache.tapestry.annotations; 16 17 import java.beans.Introspector ; 18 import java.lang.reflect.Method ; 19 20 import org.apache.hivemind.ApplicationRuntimeException; 21 22 26 27 public class AnnotationUtils 28 { 29 public static String getPropertyName(Method method) 30 { 31 String name = method.getName(); 32 33 if (name.startsWith("is")) 34 { 35 checkGetter(method); 36 return Introspector.decapitalize(name.substring(2)); 37 } 38 39 if (name.startsWith("get")) 40 { 41 checkGetter(method); 42 return Introspector.decapitalize(name.substring(3)); 43 } 44 45 if (name.startsWith("set")) 46 { 47 checkSetter(method); 48 return Introspector.decapitalize(name.substring(3)); 49 } 50 51 throw new ApplicationRuntimeException(AnnotationMessages.notAccessor(method)); 52 } 53 54 private static void checkGetter(Method method) 55 { 56 if (method.getParameterTypes().length > 0) 57 throw new ApplicationRuntimeException(AnnotationMessages.noParametersExpected(method)); 58 59 if (method.getReturnType().equals(void.class)) 60 throw new ApplicationRuntimeException(AnnotationMessages.voidAccessor(method)); 61 62 } 63 64 private static void checkSetter(Method method) 65 { 66 if (!method.getReturnType().equals(void.class)) 67 throw new ApplicationRuntimeException(AnnotationMessages.nonVoidMutator(method)); 68 69 if (method.getParameterTypes().length != 1) 70 throw new ApplicationRuntimeException(AnnotationMessages.wrongParameterCount(method)); 71 } 72 } 73 | Popular Tags |