001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: * $Header:$
018: */
019: package org.apache.beehive.netui.compiler;
020:
021: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationInstance;
022: import org.apache.beehive.netui.compiler.typesystem.declaration.AnnotationValue;
023: import org.apache.beehive.netui.compiler.typesystem.declaration.Declaration;
024:
025: public class RuntimeVersionChecker implements JpfLanguageConstants {
026: private String _runtimeVersion;
027:
028: /**
029: * This package-protected constructor allows a RuntimeVersionChecker to be created even if there's
030: * no webapp root. This will cause other compile errors -- in this case we'll just assume the version
031: * is high enough.
032: */
033: RuntimeVersionChecker() {
034: _runtimeVersion = getHighVersion();
035: }
036:
037: /*
038: * TODO: in the future, we should have a way to (optionally) find the runtime jar(s) to check the versions.
039: * For now (1.0), this is unnecessary.
040: *
041: public RuntimeVersionChecker()
042: {
043: File pageflowJar = new File( webappRoot.getPath() + PAGEFLOW_RUNTIME_JAR );
044:
045: if ( pageflowJar.exists() )
046: {
047: try
048: {
049: Manifest mf = new JarFile( pageflowJar ).getManifest();
050:
051: if ( mf != null )
052: {
053: Attributes attrs = mf.getMainAttributes();
054:
055: if ( attrs != null )
056: {
057: String version = attrs.getValue( RUNTIME_VERSION_ATTRIBUTE );
058: _runtimeVersion = ( version != null ? version : "0" );
059: }
060: }
061: }
062: catch ( IOException e )
063: {
064: //
065: // This will cause other compile errors. Just assume that the version is high enough.
066: //
067: _runtimeVersion = getHighVersion();
068: }
069: }
070: else
071: {
072: //
073: // This will cause other compile errors. Just assume that the version is high enough.
074: //
075: _runtimeVersion = getHighVersion();
076: }
077: }
078: */
079:
080: private static String getHighVersion() {
081: return new Integer(Integer.MAX_VALUE).toString();
082: }
083:
084: int getRuntimeVersion() {
085: return Integer.parseInt(_runtimeVersion);
086: }
087:
088: public boolean checkRuntimeVersion(String requiredRuntimeVersion,
089: AnnotationValue value, Diagnostics diags, String errMsg,
090: Object[] errMsgParams) {
091: if (requiredRuntimeVersion != null) {
092: int runtimeVersion = getRuntimeVersion();
093:
094: if (Integer.parseInt(requiredRuntimeVersion) > runtimeVersion) {
095: diags.addError(value, errMsg, errMsgParams);
096: return false;
097: }
098: }
099:
100: return true;
101: }
102:
103: public boolean checkRuntimeVersion(String requiredRuntimeVersion,
104: Declaration element, Diagnostics diags, String errMsg,
105: Object[] errMsgParams) {
106: if (requiredRuntimeVersion != null) {
107: int runtimeVersion = getRuntimeVersion();
108:
109: if (Integer.parseInt(requiredRuntimeVersion) > runtimeVersion) {
110: diags.addError(element, errMsg, errMsgParams);
111: return false;
112: }
113: }
114:
115: return true;
116: }
117:
118: public boolean checkRuntimeVersion(String requiredRuntimeVersion,
119: AnnotationInstance element, Diagnostics diags,
120: String errMsg, Object[] errMsgParams) {
121: if (requiredRuntimeVersion != null) {
122: int runtimeVersion = getRuntimeVersion();
123:
124: if (Integer.parseInt(requiredRuntimeVersion) > runtimeVersion) {
125: diags.addError(element, errMsg, errMsgParams);
126: return false;
127: }
128: }
129:
130: return true;
131: }
132: }
|