001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (C) 2012  Paul Ferraro
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Lesser General Public License as published by
007 * the Free Software Foundation, either version 3 of the License, or
008 * (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018package net.sf.hajdbc;
019
020import java.text.MessageFormat;
021import java.util.ResourceBundle;
022
023/**
024 * Provides localized access to log/error messages.
025 * 
026 * @author  Paul Ferraro
027 * @version $Revision: 1948 $
028 * @since   1.0
029 */
030@SuppressWarnings("nls")
031public enum Messages
032{
033        CLUSTER_NOT_ACTIVE("cluster-not-active"),
034        CLUSTER_PANIC_DETECTED("cluster-panic-detected"),
035        CLUSTER_START_FAILED("cluster-start-failed"),
036        CLUSTER_STATE_LOAD_FAILED("cluster-state-load-failed"),
037        CLUSTER_STATE_STORE_FAILED("cluster-state-store-failed"),
038        COMMAND_RECEIVED("command-received"),
039        CONFIG_LOAD_FAILED("config-load-failed"),
040        CONFIG_STORE_FAILED("config-store-failed"),
041        CONFIG_NOT_FOUND("config-not-found"),
042        DATABASE_ACTIVATE_FAILED("database-activate-failed"),
043        DATABASE_ACTIVATED("database-activated"),
044        DATABASE_ALREADY_EXISTS("database-already-exists"),
045        DATABASE_DEACTIVATED("database-deactivated"),
046        DATABASE_IGNORED("database-ignored"),
047        DATABASE_INCONSISTENT("database-inconsistent"),
048        DATABASE_NOT_ACTIVE("database-not-active"),
049        DATABASE_NOT_ALIVE("database-not-alive"),
050        DATABASE_STILL_ACTIVE("database-still-active"),
051        DATABASE_SYNC_END("database-sync-end"),
052        DATABASE_SYNC_START("database-sync-start"),
053        DELETE_COUNT("delete-count"),
054        DRIVER_NOT_FOUND("driver-not-found"),
055        DRIVER_REGISTER_FAILED("driver-register-failed"),
056        DUMP_RESTORE_UNSUPPORTED("dump-restore-unsupported"),
057        GROUP_MEMBER_JOINED("group-member-joined"),
058        GROUP_MEMBER_LEFT("group-member-left"),
059        HA_JDBC_INIT("ha-jdbc-init"),
060        INITIAL_CLUSTER_STATE_LOCAL("initial-cluster-state-local"),
061        INITIAL_CLUSTER_STATE_NONE("initial-cluster-state-none"),
062        INITIAL_CLUSTER_STATE_REMOTE("initial-cluster-state-remote"),
063        INSERT_COUNT("insert-count"),
064        INVALID_DATABASE("invalid-database"),
065        INVALID_DATABASE_CLUSTER("invalid-database-cluster"),
066        INVALID_PROPERTY("invalid-property"),
067        INVALID_PROPERTY_VALUE("invalid-property-value"),
068        INVALID_SYNC_STRATEGY("invalid-sync-strategy"),
069        JDBC_URL_REJECTED("jdbc-url-rejected"),
070        JNDI_LOOKUP_FAILED("jndi-lookup-failed"),
071        MBEAN_SERVER_NOT_FOUND("mbean-server-not-found"),
072        NO_ACTIVE_DATABASES("no-active-databases"),
073        PRIMARY_KEY_REQUIRED("primary-key-required"),
074        SCHEMA_LOOKUP_FAILED("schema-lookup-failed"),
075        SEQUENCE_OUT_OF_SYNC("sequence-out-of-sync"),
076        SHUT_DOWN("shut-down"),
077        SQL_OBJECT_INIT_FAILED("sql-object-init-failed"),
078        STATEMENT_FAILED("statement-failed"),
079        TABLE_LOCK_ACQUIRE("table-lock-acquire"),
080        TABLE_LOCK_RELEASE("table-lock-release"),
081        UPDATE_COUNT("update-count"),
082        WRITE_LOCK_FAILED("write-lock-failed");
083        
084        private static ResourceBundle resource = ResourceBundle.getBundle(Messages.class.getName());
085        
086        private String key;
087        
088        private Messages(String key)
089        {
090                this.key = key;
091        }
092        
093        /**
094         * {@inheritDoc}
095         * @see java.lang.Enum#toString()
096         */
097        @Override
098        public String toString()
099        {
100                return this.key;
101        }
102
103        /**
104         * Returns the localized message using the supplied arguments.
105         * @param args a variable number of arguments
106         * @return a localized message
107         */
108        public String getMessage(Object... args)
109        {
110                String pattern = resource.getString(this.key);
111                
112                return (args.length == 0) ? pattern : MessageFormat.format(pattern, args);
113        }
114}