1 package org.apache.beehive.controls.runtime.generator.apt; 2 19 20 import java.lang.annotation.Annotation ; 21 import java.util.Set ; 22 import java.text.ParseException ; 23 import java.text.SimpleDateFormat ; 24 25 import org.apache.beehive.controls.api.bean.AnnotationMemberTypes; 26 import org.apache.beehive.controls.runtime.generator.AptControlInterface; 27 import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor; 28 import org.apache.beehive.controls.runtime.bean.AnnotationConstraintValidator; 29 30 import com.sun.mirror.apt.AnnotationProcessorEnvironment; 31 import com.sun.mirror.declaration.AnnotationTypeDeclaration; 32 import com.sun.mirror.declaration.Declaration; 33 import com.sun.mirror.declaration.MethodDeclaration; 34 import com.sun.mirror.type.VoidType; 35 36 public class ControlMemberTypeAnnotationProcessor extends TwoPhaseAnnotationProcessor 37 { 38 42 public ControlMemberTypeAnnotationProcessor( 43 Set <AnnotationTypeDeclaration> atds, 44 AnnotationProcessorEnvironment env) 45 { 46 super(atds, env); 47 } 48 49 public void check() 50 { 51 super.check(); 52 53 } 54 public void check(Declaration decl) 55 { 56 if (decl.getAnnotation(AnnotationMemberTypes.Date.class) != null) 57 { 58 checkDate(decl); 59 } 60 } 61 62 public void generate(Declaration decl) 63 { 64 } 65 66 public void checkDate(Declaration decl) 67 { 68 AnnotationMemberTypes.Date date = decl.getAnnotation(AnnotationMemberTypes.Date.class); 69 70 try 71 { 72 String dateValue = date.minValue(); 73 String format = date.format(); 74 75 SimpleDateFormat sdFormat = new SimpleDateFormat (date.format()); 77 78 if (dateValue != null && dateValue.length() > 0) 80 AnnotationConstraintValidator.parseDate(format, dateValue); 81 dateValue = date.maxValue(); 82 if (dateValue != null && dateValue.length() > 0) 83 AnnotationConstraintValidator.parseDate(format, dateValue); 84 } 85 catch (ParseException pe) 86 { 87 printError( decl, "control.member.type.invalid.date.value.error"); 88 } 89 catch (Exception e) 90 { 91 printError( decl, "control.member.type.invalid.date.format.error"); 92 } 93 94 } 95 } 96 | Popular Tags |