Java3DVersionCheck.java :  » 6.0-JDK-Modules » java-3d » com » db » versioning » Java Open Source

Java Open Source » 6.0 JDK Modules » java 3d 
java 3d » com » db » versioning » Java3DVersionCheck.java
/*
 *
 * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
 *
 * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
 * royalty free, license to use, modify and redistribute this
 * software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Silvere Martin-Michiellot.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
 * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 *
 * @Author: Silvere Martin-Michiellot
 *
 */

package com.db.versioning;

/**
 * Check which version of Java3D is installed
 */

public class Java3DVersionCheck extends Object {
    
    private boolean patchNext = false;
    private int majorV=0;
    private int minorV=0;
    private int subV=0;
    private int patchV=0;
    
    private String version;
    /**
     * Check which version of Java3D we are using
     */
    public Java3DVersionCheck() {
        
        Package p;
        
        p = Package.getPackage( "javax.media.j3d" );
        version = p.getImplementationVersion();
        
        if (version!=null) {
            // Syntax of version number is <int>.<int>[.<int[_<int>]][_<int>] [<str>]
            // 1.2   1.2.1  1.2.1_001, 1.3_001,  1.2 text
            
            //version = "1.2";
            //version = "1.2.1";
            //version = "1.2.1_001";
            //version = "1.3_001";
            //version = "1.3_001 test data";
            //version = "1.2 test data";
            //version = "1.2.1 test data";
            //version = "1.2.1_001 test data";
            
            int tokenStart = 0;
            int tokenEnd = getTokenEnd( tokenStart, version );
            
            try {
                majorV = Integer.parseInt( version.substring( tokenStart, tokenEnd ));
                
                tokenStart = tokenEnd+1;
                tokenEnd = getTokenEnd( tokenStart, version );
                
                minorV = Integer.parseInt( version.substring( tokenStart, tokenEnd ));
                
                if (patchNext) {
                    tokenStart = tokenEnd+1;
                    tokenEnd = getTokenEnd( tokenStart, version );
                    if (tokenStart!=tokenEnd)
                        patchV = Integer.parseInt( version.substring( tokenStart, tokenEnd ));
                } else {
                    tokenStart = tokenEnd+1;
                    tokenEnd = getTokenEnd( tokenStart, version );
                    
                    if (tokenStart!=tokenEnd) {
                        subV = Integer.parseInt( version.substring( tokenStart, tokenEnd ));
                    } else
                        patchV = Integer.parseInt( version.substring( tokenStart, tokenEnd ));
                    
                    tokenStart = tokenEnd+1;
                    tokenEnd = getTokenEnd( tokenStart, version );
                    
                    if (tokenStart!=tokenEnd)
                        patchV = Integer.parseInt( version.substring( tokenStart, tokenEnd ));
                }
            } catch(NumberFormatException e) {
            }
            
        }
        
    }
    
    public boolean newerThan(int major, int minor, int sub, int patch) {
        
        if (version==null) {
            //System.out.println("Unable to determine Java3D version");
            return false;
        } else {
            
            if (majorV > major) {
                return true;
            } else {
            if (majorV == major) {
                if (minorV > minor) {
                    return true;
                } else {
                    if (minorV == minor) {
                        if (subV > sub) {
                            return true;
                        } else {
                            if (subV == sub) {
                                if (patchV >= patch) {
                                    return true;
                                } else {
                                    
                                    return false;
                                    
                                }
                            } else {
                                return false;
                            }
                            
                        }
                    } else {
                        return false;
                    }
                    
                }
                
            } else {
                return false;
            }
            
            }
            
        }
        
    }
    
    private int getTokenEnd( int start, String str ) {
        
        int ret = start;
        boolean finished = false;
        char c;
        
        while( ret < str.length() && !finished ) {
            c = str.charAt( ret );
            if ( c=='.' || c==' ')
                finished = true;
            else if ( c=='_' ) {
                finished = true;
                patchNext = true;
            } else {
                ret++;
            }
        }
        
        return ret;
    }
    
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.