~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/juti/java/com/sun/grid/ca/RB.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 *
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 *
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 *
 
9
 *
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 *
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 *
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 *
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 *
 
28
 *   All Rights Reserved.
 
29
 *
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
package com.sun.grid.ca;
 
33
 
 
34
import java.text.MessageFormat;
 
35
import java.util.ResourceBundle;
 
36
import javax.security.auth.login.LoginException;
 
37
 
 
38
/**
 
39
 * Helper class for i18n.
 
40
 *
 
41
 */
 
42
class RB {
 
43
    
 
44
    public static final String BUNDLE = "com.sun.grid.ca.Resources";
 
45
 
 
46
    /**
 
47
     * Get the resource bundle for this package
 
48
     * @return the resource bundle
 
49
     */
 
50
    public static ResourceBundle rb() {
 
51
        return ResourceBundle.getBundle(BUNDLE);
 
52
    }
 
53
    
 
54
    /**
 
55
     * Get a string from the resource bundle
 
56
     * @param key the key for the string
 
57
     * @return the string
 
58
     */
 
59
    public static String getString(String key) {
 
60
        return rb().getString(key);
 
61
    }
 
62
 
 
63
    /**
 
64
     * Get a formatted message from the resource bundle
 
65
     * @param key    the key of the message
 
66
     * @param param  single parameter for the format
 
67
     * @return the formatted message
 
68
     */
 
69
    public static String getString(String key, Object param) {
 
70
        return getString(key, new Object[] { param });
 
71
    }
 
72
    
 
73
    /**
 
74
     * Get a formatted message from the resource bundle
 
75
     * @param key    the key of the message
 
76
     * @param param  arra with parameters for the format
 
77
     * @return the formatted message
 
78
     */
 
79
    public static String getString(String key, Object [] params) {
 
80
        String ret = rb().getString(key);
 
81
        if(params != null) {
 
82
            ret = MessageFormat.format(ret, params);
 
83
        }
 
84
        return ret;
 
85
    }
 
86
    
 
87
    /**
 
88
     * Create a <code>GridCAException</code> with a localized message
 
89
     * @param key  the key of the message 
 
90
     * @return the <code>GridCAException</code> with a localized message
 
91
     */
 
92
    public static GridCAException newGridCAException(String key) {
 
93
        return newGridCAException(key, null);
 
94
    }
 
95
    
 
96
    /**
 
97
     * Create a <code>GridCAException</code> with a localized message
 
98
     * @param key  the key of the message 
 
99
     * @param params parameters for the message
 
100
     * @return the <code>GridCAException</code> with a localized message
 
101
     */
 
102
    public static GridCAException newGridCAException(String key, Object params) {
 
103
        return newGridCAException(key, params == null ? null : new Object [] { params } );
 
104
    }
 
105
    
 
106
    /**
 
107
     * Create a <code>GridCAException</code> with a localized message
 
108
     * @param key  the key of the message 
 
109
     * @param params parameters for the message
 
110
     * @return the <code>GridCAException</code> with a localized message
 
111
     */
 
112
    public static GridCAException newGridCAException(String key, Object [] params) {
 
113
        String message = rb().getString(key);
 
114
        if(params != null) {
 
115
            message = MessageFormat.format(message, params);
 
116
        }
 
117
        return new GridCAException(message);
 
118
    }
 
119
    
 
120
    /**
 
121
     * Create a <code>GridCAException</code> with a localized message
 
122
     * @param key  the key of the message 
 
123
     * @param cause cause of the exception
 
124
     * @param params parameters for the message
 
125
     * @return the <code>GridCAException</code> with a localized message
 
126
     */
 
127
    public static GridCAException newGridCAException(Throwable cause, String key, Object params) {
 
128
        return newGridCAException(cause, key, 
 
129
                  params == null ? null : new Object [] { params });
 
130
    }
 
131
    
 
132
    /**
 
133
     * Create a <code>GridCAException</code> with a localized message
 
134
     * @param key  the key of the message 
 
135
     * @param cause cause of the exception
 
136
     * @param params parameters for the message
 
137
     * @return the <code>GridCAException</code> with a localized message
 
138
     */
 
139
    public static GridCAException newGridCAException(Throwable cause, String key, Object [] params) {
 
140
        GridCAException ret = newGridCAException(key, params);
 
141
        ret.initCause(cause);
 
142
        return ret;
 
143
    }
 
144
}