KickJava   Java API By Example, From Geeks To Geeks.

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


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.typesystem.declaration.AnnotationInstance;
21 import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
22 import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration;
23
24
25 public class RuntimeVersionChecker
26         implements JpfLanguageConstants
27 {
28     private String JavaDoc _runtimeVersion;
29     
30     /**
31      * This package-protected constructor allows a RuntimeVersionChecker to be created even if there's
32      * no webapp root. This will cause other compile errors -- in this case we'll just assume the version
33      * is high enough.
34      */

35     RuntimeVersionChecker()
36     {
37         _runtimeVersion = getHighVersion();
38     }
39     
40     /*
41     * TODO: in the future, we should have a way to (optionally) find the runtime jar(s) to check the versions.
42     * For now (1.0), this is unnecessary.
43     *
44     public RuntimeVersionChecker()
45     {
46         File pageflowJar = new File( webappRoot.getPath() + PAGEFLOW_RUNTIME_JAR );
47                 
48         if ( pageflowJar.exists() )
49         {
50             try
51             {
52                 Manifest mf = new JarFile( pageflowJar ).getManifest();
53                         
54                 if ( mf != null )
55                 {
56                     Attributes attrs = mf.getMainAttributes();
57                             
58                     if ( attrs != null )
59                     {
60                         String version = attrs.getValue( RUNTIME_VERSION_ATTRIBUTE );
61                         _runtimeVersion = ( version != null ? version : "0" );
62                     }
63                 }
64             }
65             catch ( IOException e )
66             {
67                 //
68                 // This will cause other compile errors. Just assume that the version is high enough.
69                 //
70                 _runtimeVersion = getHighVersion();
71             }
72         }
73         else
74         {
75             //
76             // This will cause other compile errors. Just assume that the version is high enough.
77             //
78             _runtimeVersion = getHighVersion();
79         }
80     }
81     */

82     
83     private static String JavaDoc getHighVersion()
84     {
85         return new Integer JavaDoc( Integer.MAX_VALUE ).toString();
86     }
87     
88     int getRuntimeVersion()
89     {
90         return Integer.parseInt( _runtimeVersion );
91     }
92     
93     public boolean checkRuntimeVersion( String JavaDoc requiredRuntimeVersion, AnnotationValue value, Diagnostics diags,
94                                         String JavaDoc errMsg, Object JavaDoc[] errMsgParams )
95     {
96         if ( requiredRuntimeVersion != null )
97         {
98             int runtimeVersion = getRuntimeVersion();
99             
100             if ( Integer.parseInt( requiredRuntimeVersion ) > runtimeVersion )
101             {
102                 diags.addError( value, errMsg, errMsgParams );
103                 return false;
104             }
105         }
106         
107         return true;
108     }
109     
110     public boolean checkRuntimeVersion( String JavaDoc requiredRuntimeVersion, Declaration element, Diagnostics diags,
111                                         String JavaDoc errMsg, Object JavaDoc[] errMsgParams )
112     {
113         if ( requiredRuntimeVersion != null )
114         {
115             int runtimeVersion = getRuntimeVersion();
116             
117             if ( Integer.parseInt( requiredRuntimeVersion ) > runtimeVersion )
118             {
119                 diags.addError( element, errMsg, errMsgParams );
120                 return false;
121             }
122         }
123         
124         return true;
125     }
126     
127     public boolean checkRuntimeVersion( String JavaDoc requiredRuntimeVersion, AnnotationInstance element, Diagnostics diags,
128                                         String JavaDoc errMsg, Object JavaDoc[] errMsgParams )
129     {
130         if ( requiredRuntimeVersion != null )
131         {
132             int runtimeVersion = getRuntimeVersion();
133         
134             if ( Integer.parseInt( requiredRuntimeVersion ) > runtimeVersion )
135             {
136                 diags.addError( element, errMsg, errMsgParams );
137                 return false;
138             }
139         }
140         
141         return true;
142     }
143 }
144
Popular Tags