KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > processor > PageFlowAnnotationProcessor


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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  * $Header:$
17  */

18 package org.apache.beehive.netui.compiler.processor;
19
20 import org.apache.beehive.netui.compiler.*;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
22 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationTypeDeclaration;
23 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
24 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment;
25
26 import java.io.File JavaDoc;
27
28
29 public class PageFlowAnnotationProcessor
30         extends BaseAnnotationProcessor
31         implements JpfLanguageConstants
32 {
33     public PageFlowAnnotationProcessor( AnnotationTypeDeclaration[] annotationTypeDecls,
34                                         AnnotationProcessorEnvironment env )
35     {
36         super( annotationTypeDecls, env );
37     }
38
39     public BaseChecker getChecker( ClassDeclaration classDecl, Diagnostics diagnostics )
40     {
41         AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
42         
43         if ( CompilerUtils.isAssignableFrom( JPF_BASE_CLASS, classDecl, env ) )
44         {
45             if ( expectAnnotation( classDecl, CONTROLLER_TAG_NAME, JPF_FILE_EXTENSION_DOT, JPF_BASE_CLASS, diagnostics ) )
46             {
47                 FlowControllerInfo fcInfo = new FlowControllerInfo( classDecl );
48                 setSourceFileInfo( classDecl, fcInfo );
49                 
50                 return new PageFlowChecker( env, diagnostics, fcInfo );
51             }
52         }
53         else if ( CompilerUtils.isAssignableFrom( SHARED_FLOW_BASE_CLASS, classDecl, env ) )
54         {
55             if ( expectAnnotation( classDecl, CONTROLLER_TAG_NAME, SHARED_FLOW_FILE_EXTENSION_DOT,
56                                    SHARED_FLOW_BASE_CLASS, diagnostics ) )
57             {
58                 FlowControllerInfo fcInfo = new FlowControllerInfo( classDecl );
59                 setSourceFileInfo( classDecl, fcInfo );
60                 
61                 return new SharedFlowChecker( env, fcInfo, diagnostics );
62             }
63         }
64         else if ( CompilerUtils.isAssignableFrom( GLOBALAPP_BASE_CLASS, classDecl, env ) )
65         {
66             if ( expectAnnotation( classDecl, CONTROLLER_TAG_NAME, GLOBALAPP_FILE_EXTENSION_DOT, GLOBALAPP_BASE_CLASS,
67                                    diagnostics ) )
68             {
69                 FlowControllerInfo fcInfo = new FlowControllerInfo( classDecl );
70                 setSourceFileInfo( classDecl, fcInfo );
71                 
72                 return new SharedFlowChecker( env, fcInfo, diagnostics );
73             }
74         }
75         else if ( CompilerUtils.isAssignableFrom( FACES_BACKING_BEAN_CLASS, classDecl, env ) )
76         {
77             if ( expectAnnotation( classDecl, FACES_BACKING_TAG_NAME, JPF_FILE_EXTENSION_DOT, JPF_BASE_CLASS, diagnostics ) )
78             {
79                 File JavaDoc originalFile = CompilerUtils.getSourceFile( classDecl, true );
80                 FacesBackingInfo fbInfo = new FacesBackingInfo( originalFile, classDecl.getQualifiedName() );
81                 setSourceFileInfo( classDecl, fbInfo );
82                 return new FacesBackingChecker( env, fbInfo, diagnostics );
83             }
84         }
85         else
86         {
87             AnnotationInstance ann = CompilerUtils.getAnnotation( classDecl, CONTROLLER_TAG_NAME );
88             
89             if ( ann != null )
90             {
91                 diagnostics.addError( ann, "error.annotation-invalid-base-class2",
92                                       CONTROLLER_TAG_NAME, JPF_BASE_CLASS, SHARED_FLOW_BASE_CLASS );
93             }
94             
95             ann = CompilerUtils.getAnnotation( classDecl, FACES_BACKING_TAG_NAME );
96             
97             if ( ann != null )
98             {
99                 diagnostics.addError( ann, "error.annotation-invalid-base-class",
100                                       FACES_BACKING_TAG_NAME, FACES_BACKING_BEAN_CLASS );
101             }
102         }
103         
104         return null;
105     }
106
107     public BaseGenerator getGenerator( ClassDeclaration classDecl, Diagnostics diags )
108     {
109         AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
110         SourceFileInfo sourceFileInfo = getSourceFileInfo( classDecl );
111         
112         if ( CompilerUtils.isAssignableFrom( JPF_BASE_CLASS, classDecl, env ) )
113         {
114             assert sourceFileInfo != null : classDecl.getQualifiedName();
115             assert sourceFileInfo instanceof FlowControllerInfo : sourceFileInfo.getClass().getName();
116             return new PageFlowGenerator( env, ( FlowControllerInfo ) sourceFileInfo, diags );
117         }
118         else if ( CompilerUtils.isAssignableFrom( SHARED_FLOW_BASE_CLASS, classDecl, env ) )
119         {
120             assert sourceFileInfo != null : classDecl.getQualifiedName();
121             assert sourceFileInfo instanceof FlowControllerInfo : sourceFileInfo.getClass().getName();
122             return new SharedFlowGenerator( env, ( FlowControllerInfo ) sourceFileInfo, diags );
123         }
124         else if ( CompilerUtils.isAssignableFrom( FACES_BACKING_BEAN_CLASS, classDecl, env ) )
125         {
126             assert sourceFileInfo != null : classDecl.getQualifiedName();
127             assert sourceFileInfo instanceof FacesBackingInfo : sourceFileInfo.getClass().getName();
128             return new FacesBackingGenerator( env, sourceFileInfo, diags );
129         }
130         
131         return null;
132     }
133 }
134
Popular Tags