public DataNode elementToDataNode( final RepositoryElementInterface element ) throws KettleException {
    DatabaseMeta databaseMeta = (DatabaseMeta) element;
    DataNode rootNode = new DataNode( NODE_ROOT );

    // Then the basic db information
    //
    rootNode.setProperty( PROP_TYPE, databaseMeta.getPluginId() );
    rootNode.setProperty( PROP_CONTYPE, DatabaseMeta.getAccessTypeDesc( databaseMeta.getAccessType() ) );
    rootNode.setProperty( PROP_HOST_NAME, databaseMeta.getHostname() );
    rootNode.setProperty( PROP_DATABASE_NAME, databaseMeta.getDatabaseName() );
    rootNode.setProperty( PROP_PORT, Const.toInt( databaseMeta.getDatabasePortNumberString(), -1 ) );
    rootNode.setProperty( PROP_USERNAME, databaseMeta.getUsername() );
    rootNode.setProperty( PROP_PASSWORD, Encr.encryptPasswordIfNotUsingVariables( databaseMeta.getPassword() ) );
    rootNode.setProperty( PROP_SERVERNAME, databaseMeta.getServername() );
    rootNode.setProperty( PROP_DATA_TBS, databaseMeta.getDataTablespace() );
    rootNode.setProperty( PROP_INDEX_TBS, databaseMeta.getIndexTablespace() );

    rootNode.setProperty( PROP_CONNECT_SQL, setNull( databaseMeta.getConnectSQL() ) );
    rootNode.setProperty( PROP_INITIAL_POOL_SIZE, databaseMeta.getInitialPoolSize() );
    rootNode.setProperty( PROP_MAX_POOL_SIZE, databaseMeta.getMaximumPoolSize() );
    rootNode.setProperty( PROP_IS_POOLING, databaseMeta.isUsingConnectionPool() );
    rootNode.setProperty( PROP_IS_FORCING_TO_LOWER, databaseMeta.isForcingIdentifiersToLowerCase() );
    rootNode.setProperty( PROP_IS_FORCING_TO_UPPER, databaseMeta.isForcingIdentifiersToUpperCase() );
    rootNode.setProperty( PROP_IS_QUOTE_FIELDS, databaseMeta.isQuoteAllFields() );
    rootNode.setProperty( PROP_IS_DECIMAL_SEPERATOR, databaseMeta.isUsingDoubleDecimalAsSchemaTableSeparator() );
    rootNode.setProperty( PROP_SUPPORT_BOOLEAN_DATA_TYPE, databaseMeta.supportsBooleanDataType() );
    rootNode.setProperty( PROP_SUPPORT_TIMESTAMP_DATA_TYPE, databaseMeta.supportsTimestampDataType() );

    if ( databaseMeta.getAttributes() != null && !databaseMeta.getAttributes().isEmpty() ) {
      addNodeToElement( NODE_ATTRIBUTES, rootNode, databaseMeta.getAttributes().entrySet() );
    }

    if ( databaseMeta.getConnectionPoolingProperties() != null && !databaseMeta.getConnectionPoolingProperties().isEmpty() ) {
      addNodeToElement( NODE_POOLING_PROPS, rootNode, databaseMeta.getConnectionPoolingProperties().entrySet() );
    }

    if ( databaseMeta.getExtraOptions() != null && !databaseMeta.getExtraOptions().isEmpty() ) {
      addNodeToElement( NODE_EXTRA_OPTIONS, rootNode, new HashMap<Object, Object>( databaseMeta.getExtraOptions() ).entrySet() );
    }

    return rootNode;
  }
@Test
  public void testExtraOptionEscapeWithInvalidCharInDatabaseType() throws KettleException {
    DatabaseMeta dbMeta = mock( DatabaseMeta.class );
    when( dbMeta.getPluginId() ).thenReturn( "pluginId" );
    when( dbMeta.getAccessTypeDesc() ).thenReturn( "Native" );
    when( dbMeta.getHostname() ).thenReturn( "AS/400Host" );
    when( dbMeta.getDatabaseName() ).thenReturn( "mainframeTable" );
    when( dbMeta.getDatabasePortNumberString() ).thenReturn( "1234" );
    when( dbMeta.getUsername() ).thenReturn( "testUser" );
    when( dbMeta.getPassword() ).thenReturn( "123" );
    when( dbMeta.getServername() ).thenReturn( "as400.dot.com" );
    when( dbMeta.getDataTablespace() ).thenReturn( "tableSpace" );
    when( dbMeta.getIndexTablespace() ).thenReturn( "123" );

    // Create an extra options that has an unsupported character like '/'
    Properties extraOptions = new Properties();
    extraOptions.setProperty( "EXTRA_OPTION_AS/400.optionExtraOption", "true" );
    when( dbMeta.getAttributes() ).thenReturn( extraOptions );

    IUnifiedRepository purRepo = mock( IUnifiedRepository.class );
    when( purRepo.getReservedChars() ).thenReturn( Arrays.asList( new Character[] { '/' } ) );
    when( mockPurRepository.getUnderlyingRepository() ).thenReturn( purRepo );

    DataNode escapedAttributes = dbDelegate.elementToDataNode( dbMeta );

    // Should only be one option in list
    for ( Iterator<DataNode> iter = escapedAttributes.getNodes().iterator(); iter.hasNext(); ) {
      DataNode options = iter.next();

      assertTrue( "Invalid escaped extra options", options.hasProperty( "EXTRA_OPTION_AS%2F400.optionExtraOption" ) );
      assertFalse( "Should not contain un-escaped option", options
          .hasProperty( "EXTRA_OPTION_AS/400.optionExtraOption" ) );
    }
  }