public void refreshOptions() {

    connectionBox = (XulListbox) document.getElementById( "connection-type-list" );
    accessBox = (XulListbox) document.getElementById( "access-type-list" );

    Object connectionKey = DataHandler.connectionNametoID.get( connectionBox.getSelectedItem() );
    String databaseName = null;
    try {
      databaseName = PluginRegistry.getInstance().getPlugin( DatabasePluginType.class, "" + connectionKey ).getIds()[0];
    } catch ( Exception e ) {
      log.error( e.getLocalizedMessage(), e );
    }

    DatabaseInterface database = DataHandler.connectionMap.get( connectionBox.getSelectedItem() );

    Object accessKey = accessBox.getSelectedItem();
    int access = DatabaseMeta.getAccessType( (String) accessKey );

    String fragment = null;

    DataHandler dataHandler = null;
    try {
      dataHandler = (DataHandler) xulDomContainer.getEventHandler( "dataHandler" );
      dataHandler.pushCache();
    } catch ( XulException e ) {
      // TODO not a critical function, but should log a problem...
    }

    switch ( access ) {
      case DatabaseMeta.TYPE_ACCESS_JNDI:
        fragment = getFragment( database, databaseName, "_jndi.xul", "common_jndi.xul" );
        break;
      case DatabaseMeta.TYPE_ACCESS_NATIVE:
        fragment = getFragment( database, databaseName, "_native.xul", "common_native.xul" );
        break;
      case DatabaseMeta.TYPE_ACCESS_OCI:
        fragment = getFragment( database, databaseName, "_oci.xul", "common_native.xul" );
        break;
      case DatabaseMeta.TYPE_ACCESS_ODBC:
        fragment = getFragment( database, databaseName, "_odbc.xul", "common_odbc.xul" );
        break;
      case DatabaseMeta.TYPE_ACCESS_PLUGIN:
        fragment = getFragment( database, databaseName, "_plugin.xul", "common_native.xul" );
        break;
      default:
        break;
    }

    if ( fragment != null ) {
      try {
        loadDatabaseOptionsFragment( fragment.toLowerCase(), dataHandler );
      } catch ( XulException e ) {
        // TODO should be reporting as an error dialog; need error dialog in XUL framework
        showMessage( Messages.getString( "FragmentHandler.USER.CANT_LOAD_OPTIONS", databaseName ) );
      }
    }

    XulTextbox portBox = (XulTextbox) document.getElementById( "port-number-text" );
    if ( portBox != null ) {
      int port = database.getDefaultDatabasePort();
      if ( port > 0 ) {
        portBox.setValue( Integer.toString( port ) );
      }
    }

    if ( dataHandler != null ) {
      dataHandler.popCache();
    }

  }
@Test
  public void testRefreshOptions() throws Exception {
    XulListbox connectionBox = mock( XulListbox.class );
    when( document.getElementById( "connection-type-list" ) ).thenReturn( connectionBox );
    when( connectionBox.getSelectedItem() ).thenReturn( "myDb" );
    XulListbox accessBox = mock( XulListbox.class );
    when( document.getElementById( "access-type-list" ) ).thenReturn( accessBox );
    when( accessBox.getSelectedItem() ).thenReturn( "Native" );
    DataHandler dataHandler = mock( DataHandler.class );
    when( xulDomContainer.getEventHandler( "dataHandler" ) ).thenReturn( dataHandler );
    DatabaseInterface dbInterface = mock( DatabaseInterface.class );
    when( dbInterface.getDefaultDatabasePort() ).thenReturn( 5309 );
    DataHandler.connectionMap.put( "myDb", dbInterface );

    XulComponent component = mock( XulComponent.class );
    XulComponent parent = mock( XulComponent.class );
    when( component.getParent() ).thenReturn( parent );
    when( document.getElementById( "database-options-box" ) ).thenReturn( component );
    XulDomContainer fragmentContainer = mock( XulDomContainer.class );
    Document mockDoc = mock( Document.class );
    XulComponent firstChild = mock( XulComponent.class );
    when( mockDoc.getFirstChild() ).thenReturn( firstChild );
    when( fragmentContainer.getDocumentRoot() ).thenReturn( mockDoc );
    when( xulDomContainer.loadFragment( anyString(), any( Object.class ) ) ).thenReturn( fragmentContainer );

    XulTextbox portBox = mock( XulTextbox.class );
    when( document.getElementById( "port-number-text" ) ).thenReturn( portBox );

    fragmentHandler.refreshOptions();

    // Iterate through the other database access types
    when( accessBox.getSelectedItem() ).thenReturn( "JNDI" );
    fragmentHandler.refreshOptions();
    when( accessBox.getSelectedItem() ).thenReturn( "ODBC" );
    fragmentHandler.refreshOptions();
    when( accessBox.getSelectedItem() ).thenReturn( "OCI" );
    fragmentHandler.refreshOptions();
    when( accessBox.getSelectedItem() ).thenReturn( "Plugin" );
    fragmentHandler.refreshOptions();
  }