KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > i18n > DefaultLocale


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.i18n.DefaultLocale
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.derbyTesting.functionTests.tests.i18n;
23
24 import java.util.Locale JavaDoc;
25
26 import java.security.AccessController JavaDoc;
27 import java.security.PrivilegedAction JavaDoc;
28 import java.sql.DriverManager JavaDoc;
29 import java.sql.Connection JavaDoc;
30 import java.sql.SQLException JavaDoc;
31
32 public class DefaultLocale {
33
34     static String JavaDoc savedLocale;
35
36     static {
37         savedLocale=java.util.Locale.getDefault().toString();
38         setDefaultLocale("rr", "TT");
39     }
40
41
42     // used in messageLocale test
43
public static void checkDefaultLocale() throws SQLException JavaDoc
44     {
45         String JavaDoc defLocale = java.util.Locale.getDefault().toString();
46         //System.out.println(defLocale);
47
if (!defLocale.equals("rr_TT"))
48             throw new SQLException JavaDoc("wrong_locale");
49     }
50
51     // used in urlLocale test
52
public static void checkRDefaultLocale() throws SQLException JavaDoc
53     {
54         String JavaDoc dbLocale = org.apache.derby.iapi.db.Factory.getDatabaseOfConnection().getLocale().toString();
55         //System.out.println(savedLocale);
56
//System.out.println(dbLocale);
57
if (!savedLocale.equals(dbLocale))
58             throw new SQLException JavaDoc("wrong_locale");
59     }
60
61     // used in urlLocale test and messageLocale test
62
public static void checkDatabaseLocale(String JavaDoc Locale) throws SQLException JavaDoc
63     {
64         String JavaDoc dbLocale = org.apache.derby.iapi.db.Factory.getDatabaseOfConnection().getLocale().toString();
65         //System.out.println(dbLocale + "-");
66
//System.out.println(Locale + "-");
67
if (!dbLocale.toUpperCase().equals(Locale.toUpperCase().trim()))
68             throw new SQLException JavaDoc("wrong locale");
69     }
70
71     // used in messageLocale test
72
public static void setDefaultLocale(final String JavaDoc Locale, final String JavaDoc Code)
73     {
74         // needs to run in a privileged block as it will be
75
// called through a SQL statement and thus a generated
76
// class. The generated class on the stack has no permissions
77
// granted to it. Needs write permission on user.language
78
AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
79             public Object JavaDoc run() {
80                 java.util.Locale.setDefault(new java.util.Locale JavaDoc(Locale.trim(),Code.trim()));
81                 return null; // nothing to return
82
}
83         });
84         
85     }
86
87
88
89
90 }
91
Popular Tags