KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > controls > runtime > generator > apt > ControlMemberTypeAnnotationProcessor


1 package org.apache.beehive.controls.runtime.generator.apt;
2 /*
3  * Copyright 2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * $Header:$
18  */

19
20 import java.lang.annotation.Annotation JavaDoc;
21 import java.util.Set JavaDoc;
22 import java.text.ParseException JavaDoc;
23 import java.text.SimpleDateFormat JavaDoc;
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     /**
39      * @param atds
40      * @param env
41      */

42     public ControlMemberTypeAnnotationProcessor(
43             Set JavaDoc<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 JavaDoc dateValue = date.minValue();
73             String JavaDoc format = date.format();
74             
75             //Validate the date format specified
76
SimpleDateFormat JavaDoc sdFormat = new SimpleDateFormat JavaDoc(date.format());
77
78             //Validate that the date specified is in the specified format.
79
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 JavaDoc pe)
86         {
87             printError( decl, "control.member.type.invalid.date.value.error");
88         }
89         catch (Exception JavaDoc e)
90         {
91             printError( decl, "control.member.type.invalid.date.format.error");
92         }
93
94     }
95 }
96
Popular Tags