KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyBuild > splitmessages


1 /*
2
3    Derby - Class org.apache.derbyBuild.splitmessages
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyBuild;
23
24 import java.io.*;
25 import java.util.*;
26
27 import org.apache.derby.iapi.services.i18n.MessageService;
28 import org.apache.derby.shared.common.reference.SQLState;
29
30 public class splitmessages {
31     /**
32         arg[0] is the destination directory
33         arg[1] is the source file.
34     */

35     
36     /**
37      * This is the list of message ids that are shared between
38      * the network client and the engine. This is used to generate
39      * a set of 'shared' messages. This avoids us having to maintain
40      * two separate message files.
41      *
42      * NOTE: We already assume all message ids starting with XJ are shared.
43      * This covers 90% of the cases. Only add ids here if you have a
44      * message id that is not in the XJ class.
45      */

46     private static TreeSet clientMessageIds = new TreeSet();
47     
48     /**
49      * Initialize the set of message ids that the network client will use.
50      * <p>
51      * Note that all message ids that start with "XJ" are automatically added,
52      * these are just for message ids that have a different prefix.
53      */

54     static void initClientMessageIds()
55     {
56         // Add message ids that don't start with XJ here
57
clientMessageIds.add(SQLState.NO_CURRENT_CONNECTION);
58         clientMessageIds.add(SQLState.NOT_IMPLEMENTED);
59         clientMessageIds.add(SQLState.CANNOT_CLOSE_ACTIVE_CONNECTION);
60         clientMessageIds.add(SQLState.XACT_SAVEPOINT_RELEASE_ROLLBACK_FAIL);
61         clientMessageIds.add(SQLState.UNSUPPORTED_ENCODING);
62         clientMessageIds.add(SQLState.LANG_FORMAT_EXCEPTION);
63         clientMessageIds.add(SQLState.LANG_DATA_TYPE_GET_MISMATCH);
64         clientMessageIds.add(SQLState.LANG_DATA_TYPE_SET_MISMATCH);
65         clientMessageIds.add(SQLState.LANG_DATE_SYNTAX_EXCEPTION);
66         clientMessageIds.add(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE);
67         clientMessageIds.add(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE);
68         clientMessageIds.add(SQLState.LANG_STATEMENT_CLOSED_NO_REASON);
69         clientMessageIds.add(SQLState.LANG_INVALID_COLUMN_POSITION);
70         clientMessageIds.add(SQLState.INVALID_COLUMN_NAME);
71         clientMessageIds.add(SQLState.HOLDABLE_RESULT_SET_NOT_AVAILABLE);
72         clientMessageIds.add(SQLState.LANG_RETURN_OUTPUT_PARAM_CANNOT_BE_SET);
73         clientMessageIds.add(SQLState.LANG_NULL_INTO_NON_NULL);
74         clientMessageIds.add(SQLState.JDBC_METHOD_NOT_IMPLEMENTED);
75         clientMessageIds.add(SQLState.JDBC_METHOD_NOT_SUPPORTED_BY_SERVER);
76         clientMessageIds.add(SQLState.DRDA_NO_AUTOCOMMIT_UNDER_XA);
77         clientMessageIds.add(SQLState.DRDA_INVALID_XA_STATE_ON_COMMIT_OR_ROLLBACK);
78         clientMessageIds.add(SQLState.HOLDABLE_RESULT_SET_NOT_AVAILABLE);
79         clientMessageIds.add(SQLState.INVALID_RESULTSET_TYPE);
80         clientMessageIds.add(SQLState.INVALID_RESULTSET_CONCURRENCY);
81         clientMessageIds.add(SQLState.SCROLL_SENSITIVE_NOT_SUPPORTED);
82         clientMessageIds.add(SQLState.INSENSITIVE_UPDATABLE_NOT_SUPPORTED);
83         clientMessageIds.add(SQLState.UNABLE_TO_OBTAIN_MESSAGE_TEXT_FROM_SERVER );
84         clientMessageIds.add(SQLState.NUMBER_OF_ROWS_TOO_LARGE_FOR_INT);
85         clientMessageIds.add(SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION);
86         clientMessageIds.add(SQLState.LOB_METHOD_ON_CLOSED_CONNECTION);
87         clientMessageIds.add(SQLState.QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);
88         clientMessageIds.add(SQLState.MULTIPLE_RESULTS_ON_EXECUTE_QUERY);
89         clientMessageIds.add(SQLState.USE_EXECUTE_UPDATE_WITH_NO_RESULTS);
90         clientMessageIds.add(SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
91         clientMessageIds.add(SQLState.LANG_CANT_INVALIDATE_OPEN_RESULT_SET);
92         clientMessageIds.add(SQLState.YEAR_EXCEEDS_MAXIMUM);
93         clientMessageIds.add(SQLState.LANG_INVALID_PARAM_POSITION);
94         clientMessageIds.add(SQLState.LANG_MISSING_PARMS);
95         clientMessageIds.add(SQLState.LANG_NO_CURRENT_ROW);
96         clientMessageIds.add(SQLState.LANG_STREAM_RETRIEVED_ALREADY);
97         clientMessageIds.add(SQLState.CONNECTION_FAILED_ON_RESET);
98         clientMessageIds.add(SQLState.DECIMAL_TOO_MANY_DIGITS);
99         clientMessageIds.add(SQLState.NUMERIC_OVERFLOW);
100         clientMessageIds.add(SQLState.UNSUPPORTED_HOLDABILITY_PROPERTY);
101         clientMessageIds.add(SQLState.CANCEL_NOT_SUPPORTED_BY_SERVER);
102         clientMessageIds.add(SQLState.LANG_INVALID_CALL_STATEMENT);
103         clientMessageIds.add(SQLState.LOSS_OF_PRECISION_EXCEPTION);
104         clientMessageIds.add(SQLState.LANG_INVALID_SQL_IN_BATCH);
105         clientMessageIds.add(SQLState.CLIENT_RESULT_SET_NOT_OPEN);
106         clientMessageIds.add(SQLState.CANT_CONVERT_UNICODE_TO_EBCDIC);
107         clientMessageIds.add(SQLState.SECMECH_NOT_SUPPORTED);
108         clientMessageIds.add(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED);
109         clientMessageIds.add(SQLState.DATA_TYPE_NOT_SUPPORTED);
110         clientMessageIds.add(SQLState.JDBC_DRIVER_REGISTER);
111         clientMessageIds.add(SQLState.NO_CURRENT_ROW);
112         clientMessageIds.add(SQLState.LANG_IDENTIFIER_TOO_LONG);
113         clientMessageIds.add(SQLState.DRDA_CURSOR_NOT_OPEN);
114         clientMessageIds.add(SQLState.PROPERTY_UNSUPPORTED_CHANGE);
115         clientMessageIds.add(SQLState.NET_INVALID_JDBC_TYPE_FOR_PARAM);
116         clientMessageIds.add(SQLState.UNRECOGNIZED_JAVA_SQL_TYPE);
117         clientMessageIds.add(SQLState.NET_UNRECOGNIZED_JDBC_TYPE);
118         clientMessageIds.add(SQLState.NET_SQLCDTA_INVALID_FOR_RDBCOLID);
119         clientMessageIds.add(SQLState.NET_SQLCDTA_INVALID_FOR_PKGID);
120         clientMessageIds.add(SQLState.NET_PGNAMCSN_INVALID_AT_SQLAM);
121         clientMessageIds.add(SQLState.NET_VCM_VCS_LENGTHS_INVALID);
122         clientMessageIds.add(SQLState.LANG_STRING_TOO_LONG);
123     }
124
125     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
126
127         initClientMessageIds();
128
129         Properties p = new Properties();
130
131         File dir = new File(args[0]);
132
133         File source = new File(args[1]);
134         File clientDir = new File(args[2]);
135         
136         String JavaDoc s = source.getName();
137         // loose the suffix
138
s = s.substring(0, s.lastIndexOf('.'));
139         // now get the locale
140
String JavaDoc locale = s.substring(s.indexOf('_'));
141
142         boolean addBase = "_en".equals(locale);
143
144
145         InputStream is = new BufferedInputStream(new FileInputStream(source), 64 * 1024);
146
147         p.load(is);
148         is.close();
149
150         
151         Properties[] c = new Properties[50];
152         for (int i = 0; i < 50; i++) {
153             c[i] = new Properties();
154         }
155         
156         Properties clientProps = new Properties();
157
158         String JavaDoc clientPropsFileName = "clientmessages" + locale + ".properties";
159
160         for (Enumeration e = p.keys(); e.hasMoreElements(); ) {
161             String JavaDoc key = (String JavaDoc) e.nextElement();
162
163             c[MessageService.hashString50(key)].put(key, p.getProperty(key));
164             
165             // If we have a match, add it to the list of client messages
166
if ( isClientMessage(key) )
167             {
168                 clientProps.put(key, p.getProperty(key));
169             }
170         }
171
172         for (int i = 0; i < 50; i++) {
173             if (c[i].size() == 0)
174                 continue;
175             OutputStream fos = new BufferedOutputStream(
176                 new FileOutputStream(new File(dir, "m"+i+locale+".properties")), 16 * 1024);
177
178             
179             c[i].save(fos, (String JavaDoc) null);
180             fos.flush();
181             fos.close();
182             
183             if (addBase) {
184                 // add duplicate english file as the base
185
fos = new BufferedOutputStream(
186                     new FileOutputStream(new File(dir, "m"+i+".properties")), 16 * 1024);
187                 c[i].save(fos, (String JavaDoc) null);
188                 fos.flush();
189                 fos.close();
190             }
191
192
193         }
194         
195         System.out.println("split messages" + locale);
196
197         // Save the client messages (the combination of what was already
198
// there and what we added from the engine properties file) into
199
// the Derby locales directory
200
OutputStream clientOutStream = new BufferedOutputStream(
201             new FileOutputStream(new File(dir, clientPropsFileName)),
202             16 * 1024);
203
204         clientProps.save(clientOutStream, (String JavaDoc)null);
205         clientOutStream.flush();
206         clientOutStream.close();
207         
208         if ( addBase )
209         {
210             // Save the English messages as the base
211
clientOutStream = new BufferedOutputStream(
212                 new FileOutputStream(new File(dir, "clientmessages.properties")),
213                 16 * 1024);
214
215             clientProps.save(clientOutStream, (String JavaDoc)null);
216             clientOutStream.flush();
217             clientOutStream.close();
218         }
219         System.out.println("Copied client messages for " + locale);
220     }
221     
222     /**
223      * Determine if this is a message that the client is using
224      *
225      * There are some classes of ids that we assume are client messages
226      * (see code below for the definitive list).
227      *
228      * All other shared message ids should be added to the static array
229      * clientMessageIds, defined at the top of this class
230      */

231     static boolean isClientMessage(String JavaDoc messageId)
232     {
233         // Look for message ids that we assume are likely to be used
234
// on the client. These ones don't need to be explicitly added
235
// to clientMessageIds
236
if ( messageId.startsWith("XJ") || messageId.startsWith("J") ||
237              messageId.startsWith("XN") || messageId.startsWith("58") ||
238              messageId.startsWith("57") || messageId.startsWith("08"))
239         {
240             return true;
241         }
242         
243         if ( clientMessageIds.contains(messageId))
244         {
245             return true;
246         }
247         
248         return false;
249     }
250 }
251
Popular Tags