alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.netbeans.jellytools.modules.db.util;

import java.util.ResourceBundle;
import java.util.MissingResourceException;

import java.text.MessageFormat;

/**
 * This class is support for generating ConnectionNode name.
 *
 * @author Patrik Knakal
 * @version 1.0
 */
public final class BuildConnectionNodeName extends Object {
    private static final String resourceBundle = "org.netbeans.modules.db.resources.Bundle"; //NOI18N
    private static final String connectionBundle = "ConnectionNodeUniqueName"; //NOI18N
    private static final String noSchemaBundle = "SchemaIsNotSet"; //NOI18N

    /**
     * This method constructs connection node name.
     * The name of the connection node is generated as: <databaseURL> [<userName> on <schemaName> schema]
     *
     * @param databaseURL  URL of used database
     * @param userName     the database user name
     * @param schemaName   selected schema for the connection, if the schemas are not supported by database insert null value
     *
     * @return connection node name
     *
     * @throws IllegalArgumentException if databaseURL or userName value is null
     * @throws MissingResourceException if the ConnectionNodeUniqueName is not available (ConnectionNodeUniqueName is bundle from which is builded original connection node name)
     * @throws Exception if there is another problem
     */
    public static String buildConnectionName(String databaseURL, String userName, String schemaName) throws IllegalArgumentException, MissingResourceException, Exception {
        if (databaseURL == null) {
            throw new IllegalArgumentException("'databaseURL' connot be null"); //NOI18N
        }

        if (userName == null) {
            throw new IllegalArgumentException("'userName' connot be null"); //NOI18N
        }

        if ((schemaName) != null && (schemaName != "")) { //NOI18N
            return MessageFormat.format(ResourceBundle.getBundle(resourceBundle).getString(connectionBundle), new String[] {databaseURL, userName, schemaName} );
        } else {
            return MessageFormat.format(ResourceBundle.getBundle(resourceBundle).getString(connectionBundle), new String[] {databaseURL, userName, ResourceBundle.getBundle(resourceBundle).getString(noSchemaBundle)} );
        }
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.