KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wsif > providers > jca > WSIFResource_JCA


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "WSIF" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, 2002, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58
59 package org.apache.wsif.providers.jca;
60
61 import java.text.MessageFormat JavaDoc;
62 import java.util.HashMap JavaDoc;
63 import java.util.Locale JavaDoc;
64 import java.util.MissingResourceException JavaDoc;
65 import java.util.ResourceBundle JavaDoc;
66
67 /**
68  * The WSIFResource_JCA class accesses message resources.
69  *
70  * @author John Green
71  * @author Michael Beisiegel
72  * @author Piotr Przybylski <piotrp@ca.ibm.com>
73  */

74 public class WSIFResource_JCA {
75
76     private static final long serialVersionUID = 1L;
77     private static ResourceBundle JavaDoc messages = ResourceBundle.getBundle("org.apache.wsif.providers.jca.WSIFResource_JCA", Locale.getDefault());
78     private static HashMap JavaDoc defaultMessages = new HashMap JavaDoc();
79
80     // Initialize default messages, used if the NL resources are not available.
81
static {
82         defaultMessages.put("WSIF1000E", "WSIF1000E: ResourceException thrown during execution of the interaction, check target exception for details.");
83         defaultMessages.put("WSIF1001E", "WSIF1001E: Could not instantiate Format Handler.");
84         defaultMessages.put("WSIF1002E", "WSIF1002E: Exception thrown during instantiation of the format handler.");
85         defaultMessages.put("WSIF1003E", "WSIF1003E: Exception thrown during execute method of the Interaction, check target exception for details.");
86         defaultMessages.put("WSIF1004E", "WSIF1004E: Exception thrown in WSIFMessage_JCAStreamable read method.");
87         defaultMessages.put("WSIF1005E", "WSIF1005E: Exception thrown in WSIFMessage_JCAStreamable write method.");
88         defaultMessages.put("WSIF1006E", "WSIF1006E: Exception thrown in the initialization of the Service SessionBean.");
89         defaultMessages.put("WSIF1007E", "WSIF1007E: Exception thrown in getObjectPart() method.");
90         defaultMessages.put("WSIF1008E", "WSIF1008E: Exception thrown during execution of the interaction, check target exception for details.");
91         defaultMessages.put("WSIF1009E", "UNKNOWN MESSAGE");
92     }
93
94     private WSIFResource_JCA() {
95         super();
96     }
97
98     /**
99      * Returns a message, where no substitution variables are used.
100      */

101     public static String JavaDoc get(String JavaDoc key) {
102         try {
103             if (key != null && messages != null)
104                 return messages.getString(key);
105         }
106         catch (MissingResourceException JavaDoc exn) {
107             return ((String JavaDoc) WSIFResource_JCA.defaultMessages.get(key));
108         }
109         return null;
110     }
111
112     /**
113      * Returns a message, where one substitution variable is used.
114      */

115     public static String JavaDoc get(String JavaDoc key, Object JavaDoc arg) {
116         return get(key, new Object JavaDoc[] { arg });
117     }
118
119     /**
120      * Returns a message, where two substitution variable is used.
121      */

122     public static String JavaDoc get(String JavaDoc key, Object JavaDoc arg1, Object JavaDoc arg2) {
123         return get(key, new Object JavaDoc[] { arg1, arg2 });
124     }
125
126     /**
127      * Returns a message, where three substitution variable is used.
128      */

129     public static String JavaDoc get(String JavaDoc key, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3) {
130         return get(key, new Object JavaDoc[] { arg1, arg2, arg3 });
131     }
132
133     /**
134      * Returns a message, where four substitution variable is used.
135      */

136     public static String JavaDoc get(String JavaDoc key, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4) {
137         return get(key, new Object JavaDoc[] { arg1, arg2, arg3, arg4 });
138     }
139     
140     /**
141      * Returns a message, where five substitution variable is used.
142      */

143     public static String JavaDoc get(String JavaDoc key, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4, Object JavaDoc arg5) {
144         return get(key, new Object JavaDoc[] { arg1, arg2, arg3, arg4, arg5 });
145     }
146     
147     /**
148      * Returns a message, where an array of substitution variables is used.
149      */

150     public static String JavaDoc get(String JavaDoc key, Object JavaDoc[] args) {
151         String JavaDoc text = get(key);
152         if (text == null) {
153             text = (String JavaDoc) WSIFResource_JCA.defaultMessages.get(key);
154         }
155         if (text == null) {
156             return null;
157         }
158         return MessageFormat.format(text, args);
159     }
160
161 }
Popular Tags