001: /*
002: *
003: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
004: *
005: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
006: * royalty free, license to use, modify and redistribute this
007: * software in source and binary code form,
008: * provided that i) this copyright notice and license appear on all copies of
009: * the software; and ii) Licensee does not utilize the software in a manner
010: * which is disparaging to Silvere Martin-Michiellot.
011: *
012: * This software is provided "AS IS," without a warranty of any kind. ALL
013: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
014: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
015: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
016: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
017: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
018: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
019: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
020: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
021: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
022: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
023: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
024: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
025: *
026: * This software is not designed or intended for use in on-line control of
027: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
028: * the design, construction, operation or maintenance of any nuclear
029: * facility. Licensee represents and warrants that it will not use or
030: * redistribute the Software for such purposes.
031: *
032: * @Author: Silvere Martin-Michiellot
033: *
034: */
035:
036: package com.db.versioning;
037:
038: /**
039: * Check which version of Java3D is installed
040: */
041:
042: public class Java3DVersionCheck extends Object {
043:
044: private boolean patchNext = false;
045: private int majorV = 0;
046: private int minorV = 0;
047: private int subV = 0;
048: private int patchV = 0;
049:
050: private String version;
051:
052: /**
053: * Check which version of Java3D we are using
054: */
055: public Java3DVersionCheck() {
056:
057: Package p;
058:
059: p = Package.getPackage("javax.media.j3d");
060: version = p.getImplementationVersion();
061:
062: if (version != null) {
063: // Syntax of version number is <int>.<int>[.<int[_<int>]][_<int>] [<str>]
064: // 1.2 1.2.1 1.2.1_001, 1.3_001, 1.2 text
065:
066: //version = "1.2";
067: //version = "1.2.1";
068: //version = "1.2.1_001";
069: //version = "1.3_001";
070: //version = "1.3_001 test data";
071: //version = "1.2 test data";
072: //version = "1.2.1 test data";
073: //version = "1.2.1_001 test data";
074:
075: int tokenStart = 0;
076: int tokenEnd = getTokenEnd(tokenStart, version);
077:
078: try {
079: majorV = Integer.parseInt(version.substring(tokenStart,
080: tokenEnd));
081:
082: tokenStart = tokenEnd + 1;
083: tokenEnd = getTokenEnd(tokenStart, version);
084:
085: minorV = Integer.parseInt(version.substring(tokenStart,
086: tokenEnd));
087:
088: if (patchNext) {
089: tokenStart = tokenEnd + 1;
090: tokenEnd = getTokenEnd(tokenStart, version);
091: if (tokenStart != tokenEnd)
092: patchV = Integer.parseInt(version.substring(
093: tokenStart, tokenEnd));
094: } else {
095: tokenStart = tokenEnd + 1;
096: tokenEnd = getTokenEnd(tokenStart, version);
097:
098: if (tokenStart != tokenEnd) {
099: subV = Integer.parseInt(version.substring(
100: tokenStart, tokenEnd));
101: } else
102: patchV = Integer.parseInt(version.substring(
103: tokenStart, tokenEnd));
104:
105: tokenStart = tokenEnd + 1;
106: tokenEnd = getTokenEnd(tokenStart, version);
107:
108: if (tokenStart != tokenEnd)
109: patchV = Integer.parseInt(version.substring(
110: tokenStart, tokenEnd));
111: }
112: } catch (NumberFormatException e) {
113: }
114:
115: }
116:
117: }
118:
119: public boolean newerThan(int major, int minor, int sub, int patch) {
120:
121: if (version == null) {
122: //System.out.println("Unable to determine Java3D version");
123: return false;
124: } else {
125:
126: if (majorV > major) {
127: return true;
128: } else {
129: if (majorV == major) {
130: if (minorV > minor) {
131: return true;
132: } else {
133: if (minorV == minor) {
134: if (subV > sub) {
135: return true;
136: } else {
137: if (subV == sub) {
138: if (patchV >= patch) {
139: return true;
140: } else {
141:
142: return false;
143:
144: }
145: } else {
146: return false;
147: }
148:
149: }
150: } else {
151: return false;
152: }
153:
154: }
155:
156: } else {
157: return false;
158: }
159:
160: }
161:
162: }
163:
164: }
165:
166: private int getTokenEnd(int start, String str) {
167:
168: int ret = start;
169: boolean finished = false;
170: char c;
171:
172: while (ret < str.length() && !finished) {
173: c = str.charAt(ret);
174: if (c == '.' || c == ' ')
175: finished = true;
176: else if (c == '_') {
177: finished = true;
178: patchNext = true;
179: } else {
180: ret++;
181: }
182: }
183:
184: return ret;
185: }
186:
187: }
|