KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > compiler > SharedFlowChecker


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;
19
20 import org.apache.beehive.netui.compiler.genmodel.GenSharedFlowStrutsApp;
21 import org.apache.beehive.netui.compiler.genmodel.GenStrutsApp;
22 import org.apache.beehive.netui.compiler.grammar.ControllerGrammar;
23 import org.apache.beehive.netui.compiler.typesystem.declaration.ClassDeclaration;
24 import org.apache.beehive.netui.compiler.typesystem.env.AnnotationProcessorEnvironment;
25 import org.apache.xmlbeans.XmlException;
26
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29
30
31 public class SharedFlowChecker
32         extends FlowControllerChecker
33 {
34     public SharedFlowChecker( AnnotationProcessorEnvironment env, FlowControllerInfo fcInfo, Diagnostics diagnostics )
35     {
36         super( env, fcInfo, diagnostics );
37     }
38
39     protected void doAdditionalClassChecks( ClassDeclaration jclass )
40     {
41         // Make sure there are no other shared flows in this package/directory.
42
checkForOverlappingClasses( jclass, SHARED_FLOW_BASE_CLASS, SHARED_FLOW_FILE_EXTENSION_DOT,
43                                     "error.overlapping-sharedflows" );
44         
45         String JavaDoc pkg = jclass.getPackage().getQualifiedName();
46         
47         //
48
// If it's Global.app, make sure the package is "global".
49
//
50
if ( CompilerUtils.isAssignableFrom( GLOBALAPP_BASE_CLASS, jclass, getEnv() ) )
51         {
52             if ( ! pkg.equals( GLOBALAPP_PACKAGE ) )
53             {
54                 getDiagnostics().addError( jclass, "error.wrong-package", GLOBALAPP_PACKAGE );
55             }
56             
57             if ( ! jclass.getPosition().file().getParentFile().getName().endsWith( GLOBALAPP_PACKAGE ) )
58             {
59                 getDiagnostics().addError( jclass, "error.global-app-wrong-dir",
60                                            GLOBALAPP_SOURCE_NAME, GLOBALAPP_PARENT_PATH );
61             }
62         }
63     }
64     
65     protected String JavaDoc getDesiredBaseClass( ClassDeclaration jclass )
66     {
67         File JavaDoc sourceFile = CompilerUtils.getSourceFile( jclass, true );
68         if ( sourceFile.getName().endsWith( GLOBALAPP_FILE_EXTENSION_DOT ) ) return GLOBALAPP_BASE_CLASS;
69         if ( sourceFile.getName().endsWith( SHARED_FLOW_FILE_EXTENSION_DOT ) ) return SHARED_FLOW_BASE_CLASS;
70         return null;
71     }
72
73     protected GenStrutsApp createStrutsApp( ClassDeclaration jclass )
74         throws XmlException, IOException JavaDoc, FatalCompileTimeException
75     {
76         File JavaDoc sourceFile = CompilerUtils.getSourceFile( jclass, true );
77         return new GenSharedFlowStrutsApp( sourceFile, jclass, getEnv(), getFCSourceFileInfo(), true, getDiagnostics() );
78     }
79
80     protected AnnotationGrammar getControllerGrammar()
81     {
82         return new ControllerGrammar( getEnv(), getDiagnostics(), getRuntimeVersionChecker(), getFCSourceFileInfo() );
83     }
84 }
85
Popular Tags