// Path: core/src/main/java/pt/webdetails/cda/connections/ConnectionCatalog.java
// public enum ConnectionType {
// 
//   SQL, MQL, MDX, OLAP4J, SCRIPTING, NONE, XPATH, KETTLE, DATASERVICES
// }
// 
// Path: core/src/main/java/pt/webdetails/cda/utils/Util.java
// public class Util extends pt.webdetails.cpf.Util {
// 
//   public static String getExceptionDescription( final Exception e ) {
//     final StringBuilder out = new StringBuilder();
//     out.append( "[ " ).append( e.getClass().getName() ).append( " ] - " );
//     out.append( e.getMessage() );
// 
//     if ( e.getCause() != null ) {
//       out.append( " .( Cause [ " ).append( e.getCause().getClass().getName() ).append( " ] " );
//       out.append( e.getCause().getMessage() );
// 
//       if ( e.getCause().getCause() != null ) {
//         out.append( " .( Parent [ " ).append( e.getCause().getCause().getClass().getName() ).append( " ] " );
//         out.append( e.getCause().getCause().getMessage() );
//       }
//     }
// 
//     return out.toString();
//   }
// 
// 
//   /**
//    * Extracts a string between after the first occurrence of begin, and before the last occurence of end
//    *
//    * @param source From where to extract
//    * @param begin
//    * @param end
//    * @return
//    */
//   public static String getContentsBetween( final String source, final String begin, final String end ) {
//     if ( source == null ) {
//       return null;
//     }
// 
//     int startIdx = source.indexOf( begin ) + begin.length();
//     int endIdx = source.lastIndexOf( end );
//     if ( startIdx < 0 || endIdx < 0 ) {
//       return null;
//     }
// 
//     return source.substring( startIdx, endIdx );
//   }
// 
//   @SuppressWarnings( "unchecked" )
//   public static List<Element> selectElements( Document document, String xpath ) {
//     return (List<Element>) (List<?>) document.selectNodes( xpath );
//   }
// 
//   @SuppressWarnings( "unchecked" )
//   public static List<Element> selectElements( Element element, String xpath ) {
//     return (List<Element>) (List<?>) element.selectNodes( xpath );
//   }
// }


import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import org.dom4j.Element;
import org.pentaho.reporting.engine.classic.extensions.datasources.olap4j.connections.DriverConnectionProvider;
import org.pentaho.reporting.engine.classic.extensions.datasources.olap4j.connections.OlapConnectionProvider;
import pt.webdetails.cda.connections.AbstractConnection;
import pt.webdetails.cda.connections.ConnectionCatalog.ConnectionType;
import pt.webdetails.cda.connections.InvalidConnectionException;
import pt.webdetails.cda.dataaccess.PropertyDescriptor;
import pt.webdetails.cda.utils.Util;
    final DefaultOlap4jConnection that = (DefaultOlap4jConnection) o;

    if ( !connectionInfo.equals( that.connectionInfo ) ) {
      return false;
    }

    return true;
  }

  public int hashCode() {
    return connectionInfo.hashCode();
  }

  public OlapConnectionProvider getInitializedConnectionProvider() throws InvalidConnectionException {

    final DriverConnectionProvider connectionProvider = new DriverConnectionProvider();
    connectionProvider.setDriver( connectionInfo.getDriver() );
    connectionProvider.setUrl( connectionInfo.getUrl() );

    final Properties properties = connectionInfo.getProperties();
    final Enumeration<Object> keys = properties.keys();
    while ( keys.hasMoreElements() ) {
      final String key = (String) keys.nextElement();
      final String value = properties.getProperty( key );
      connectionProvider.setProperty( key, value );
    }

    try {
      final Connection connection =
        connectionProvider.createConnection( connectionInfo.getUser(), connectionInfo.getPass() );
// Path: core/src/main/java/pt/webdetails/cda/connections/ConnectionCatalog.java
// public enum ConnectionType {
// 
//   SQL, MQL, MDX, OLAP4J, SCRIPTING, NONE, XPATH, KETTLE, DATASERVICES
// }
// 
// Path: core/src/main/java/pt/webdetails/cda/utils/Util.java
// public class Util extends pt.webdetails.cpf.Util {
// 
//   public static String getExceptionDescription( final Exception e ) {
//     final StringBuilder out = new StringBuilder();
//     out.append( "[ " ).append( e.getClass().getName() ).append( " ] - " );
//     out.append( e.getMessage() );
// 
//     if ( e.getCause() != null ) {
//       out.append( " .( Cause [ " ).append( e.getCause().getClass().getName() ).append( " ] " );
//       out.append( e.getCause().getMessage() );
// 
//       if ( e.getCause().getCause() != null ) {
//         out.append( " .( Parent [ " ).append( e.getCause().getCause().getClass().getName() ).append( " ] " );
//         out.append( e.getCause().getCause().getMessage() );
//       }
//     }
// 
//     return out.toString();
//   }
// 
// 
//   /**
//    * Extracts a string between after the first occurrence of begin, and before the last occurence of end
//    *
//    * @param source From where to extract
//    * @param begin
//    * @param end
//    * @return
//    */
//   public static String getContentsBetween( final String source, final String begin, final String end ) {
//     if ( source == null ) {
//       return null;
//     }
// 
//     int startIdx = source.indexOf( begin ) + begin.length();
//     int endIdx = source.lastIndexOf( end );
//     if ( startIdx < 0 || endIdx < 0 ) {
//       return null;
//     }
// 
//     return source.substring( startIdx, endIdx );
//   }
// 
//   @SuppressWarnings( "unchecked" )
//   public static List<Element> selectElements( Document document, String xpath ) {
//     return (List<Element>) (List<?>) document.selectNodes( xpath );
//   }
// 
//   @SuppressWarnings( "unchecked" )
//   public static List<Element> selectElements( Element element, String xpath ) {
//     return (List<Element>) (List<?>) element.selectNodes( xpath );
//   }
// }


// Path: core/src/main/java/pt/webdetails/cda/connections/olap4j/DefaultOlap4jConnection.java
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
import org.dom4j.Element;
import org.pentaho.reporting.engine.classic.extensions.datasources.olap4j.connections.DriverConnectionProvider;
import org.pentaho.reporting.engine.classic.extensions.datasources.olap4j.connections.OlapConnectionProvider;
import pt.webdetails.cda.connections.AbstractConnection;
import pt.webdetails.cda.connections.ConnectionCatalog.ConnectionType;
import pt.webdetails.cda.connections.InvalidConnectionException;
import pt.webdetails.cda.dataaccess.PropertyDescriptor;
import pt.webdetails.cda.utils.Util;

    final DefaultOlap4jConnection that = (DefaultOlap4jConnection) o;

    if ( !connectionInfo.equals( that.connectionInfo ) ) {
      return false;
    }

    return true;
  }

  public int hashCode() {
    return connectionInfo.hashCode();
  }

  public OlapConnectionProvider getInitializedConnectionProvider() throws InvalidConnectionException {

    final DriverConnectionProvider connectionProvider = new DriverConnectionProvider();
    connectionProvider.setDriver( connectionInfo.getDriver() );
    connectionProvider.setUrl( connectionInfo.getUrl() );

    final Properties properties = connectionInfo.getProperties();
    final Enumeration<Object> keys = properties.keys();
    while ( keys.hasMoreElements() ) {
      final String key = (String) keys.nextElement();
      final String value = properties.getProperty( key );
      connectionProvider.setProperty( key, value );
    }

    try {
      final Connection connection =
        connectionProvider.createConnection( connectionInfo.getUser(), connectionInfo.getPass() );
      connection.close();