/*******************************************************************************
 * Copyright (c) 2005 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Actuate Corporation  - initial API and implementation
 *******************************************************************************/

package org.eclipse.birt.report.data.oda.jdbc.ui.util;

import java.sql.Driver;


/**
 * This class maintains information about a specific JDBC driver
 * such as its name, version, class etc.
 * It cannot be instantiated directly.
 * 
 * call the {@link #getInstance(java.sql.Driver) getInstance} method to create an instance
 * 
 * 
 * @version $Revision: 1.11 $ $Date: 2007/11/13 09:31:55 $
 */
public final class JDBCDriverInformation
{    
    private String driverClassName = null;
    private int majorVersion = 0;
    private int minorVersion = 0;
    private String urlFormat = null;
    private String driverDisplayName = null;
    
    /**
     * Since factory methods are provided, it is recommended to make
     * construction method private.
     */
    private JDBCDriverInformation(){}
    
    public static JDBCDriverInformation newInstance( Class driverClass )
	{
		try
		{
			Driver d = (Driver) driverClass.newInstance( );
			if ( d != null )
			{
				JDBCDriverInformation info = newInstance( driverClass.getName( ) );
				try
				{
					info.setMajorVersion( d.getMajorVersion( ) );
					info.setMinorVersion( d.getMinorVersion( ) );
				}
				catch ( Throwable e )
				{
					//just do nothing here
				}
				return info;
			}
		}
		catch ( Exception e )
		{
		}

		return null;
	}
    
    public static JDBCDriverInformation newInstance( String driverClassName )
	{
		JDBCDriverInformation info = new JDBCDriverInformation( );
		info.setDriverClassName( driverClassName );
		return info;
	}
  
    /**
     * @return Returns the driverClassName.
     */
    public String getDriverClassName()
    {
        return driverClassName;
    }
    
    /**
     * @param driverClassName The driverClassName to set.
     */
    public void setDriverClassName(String driverClassName)
    {
        this.driverClassName = driverClassName;
    }
    
    /**
     * @return Returns the majorVersion.
     */
    public int getMajorVersion()
    {
        return majorVersion;
    }
    
    /**
     * @param majorVersion The majorVersion to set.
     */
    protected void setMajorVersion(int majorVersion)
    {
        this.majorVersion = majorVersion;
    }
    
    /**
     * @return Returns the minorVersion.
     */
    public int getMinorVersion()
    {
        return minorVersion;
    }
    
    /**
     * @param minorVersion The minorVersion to set.
     */
    protected void setMinorVersion(int minorVersion)
    {
        this.minorVersion = minorVersion;
    }
	
    /**
     * @return Returns the urlFormat.
     */
    public String getUrlFormat()
    {
        return urlFormat;
    }
    
    /**
     * @param urlFormat The urlFormat to set.
     */
    protected void setUrlFormat(String urlFormat)
    {
        this.urlFormat = urlFormat;
    }
    
	/**
	 * @return Returns the displayName.
	 */
	public String getDisplayName(){
	   return driverDisplayName;	
	}
	
	/**
	 * @param displayName The displayName to set.
	 */
	public void setDisplayName(String displayName){
	    this.driverDisplayName = displayName;
	}
	
    /*
     * @see java.lang.Object#toString()
     */
    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(driverClassName);
        if ( majorVersion != 0 || minorVersion != 0 )
        {
	        buffer.append(" (");
	        buffer.append(majorVersion);
	        buffer.append(".");
	        buffer.append(minorVersion);
	        buffer.append(")");
        }
        return buffer.toString();
    }
    
    /** Gets a display-friendly string which has driver class, driver name and version */
    public String getDisplayString()
    {
        StringBuffer buffer = new StringBuffer();
        buffer.append(driverClassName);
        if ( majorVersion != 0 || minorVersion != 0 ||
        	driverDisplayName != null )
        {
	        buffer.append(" (");
	        if ( driverDisplayName != null )
	        	buffer.append( driverDisplayName );
	        if ( majorVersion != 0 || minorVersion != 0 )
	        {
		        if ( driverDisplayName != null )
		        	buffer.append(" ");
		        buffer.append("v");
				buffer.append(majorVersion);
		        buffer.append(".");
		        buffer.append(minorVersion);
	        }
	        buffer.append(")");
        }
        return buffer.toString();
    }
    
    /**
     * Overwrite the equals() method
     * 
     */
    public boolean equals( Object anotherObj )
	{
		if ( this == anotherObj )
		{
			return true;
		}
		if ( !( anotherObj instanceof JDBCDriverInformation ) )
		{
			return false;
		}
		JDBCDriverInformation info = (JDBCDriverInformation) anotherObj;
		if ( this.driverClassName != null
				&& this.driverClassName.equalsIgnoreCase( info.driverClassName )
				&& this.majorVersion == info.majorVersion
				&& this.minorVersion == info.minorVersion )
		{
			return true;
		}
		return false;
	}

    /**
     * Overwrite the hashCode() method
     * 
     */
    public int hashCode( )
	{
		int hashcode = 0;
		if ( this.driverClassName != null )
		{
			hashcode += this.driverClassName.hashCode( ) * 11;
		}
		return ( hashcode + this.majorVersion * 13 ) + this.minorVersion * 17;
	}

}

@@ -604,16 +604,81 @@
 Driver;%0A
+import java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A
 %0A%0A/**%0A *
@@ -949,17 +949,17 @@
 ion: 1.1
-1
+2
  $ $Date
@@ -967,24 +967,24 @@
  200
-7/11/13 09:31:55
+8/04/24 09:44:32
  $%0A 
@@ -1792,90 +1792,286 @@
 %09%09%09%09
-//just do nothing here%0A%09%09%09%09%7D%0A%09%09%09%09return info;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09catch ( Exception e )%0A%09%09%7B
+Logger.getLogger( JDBCDriverInformation.class.getName( ) )%0A%09%09%09%09%09%09%09.log( Level.WARNING, e.getMessage( ), e );%0A%09%09%09%09%7D%0A%09%09%09%09return info;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09catch ( Throwable e )%0A%09%09%7B%0A%09%09%09Logger.getLogger( JDBCDriverInformation.class.getName( ) )%0A%09%09%09%09%09.log( Level.WARNING, e.getMessage( ), e );
 %0A%09%09%7D

Fix bugzilla bug 235038 Exception blocks to leave the Manage JDBC Drivers dialog