Mercurial > hg > Members > kono > jpf-core
comparison src/peers/gov/nasa/jpf/vm/JPF_java_util_Locale.java @ 0:61d41facf527
initial v8 import (history reset)
author | Peter Mehlitz <Peter.C.Mehlitz@nasa.gov> |
---|---|
date | Fri, 23 Jan 2015 10:14:01 -0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:61d41facf527 |
---|---|
1 /* | |
2 * Copyright (C) 2014, United States Government, as represented by the | |
3 * Administrator of the National Aeronautics and Space Administration. | |
4 * All rights reserved. | |
5 * | |
6 * The Java Pathfinder core (jpf-core) platform is licensed under the | |
7 * Apache License, Version 2.0 (the "License"); you may not use this file except | |
8 * in compliance with the License. You may obtain a copy of the License at | |
9 * | |
10 * http://www.apache.org/licenses/LICENSE-2.0. | |
11 * | |
12 * Unless required by applicable law or agreed to in writing, software | |
13 * distributed under the License is distributed on an "AS IS" BASIS, | |
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 * See the License for the specific language governing permissions and | |
16 * limitations under the License. | |
17 */ | |
18 | |
19 package gov.nasa.jpf.vm; | |
20 | |
21 import gov.nasa.jpf.annotation.MJI; | |
22 import gov.nasa.jpf.vm.ClassInfo; | |
23 import gov.nasa.jpf.vm.ElementInfo; | |
24 import gov.nasa.jpf.vm.FieldInfo; | |
25 import gov.nasa.jpf.vm.MJIEnv; | |
26 import gov.nasa.jpf.vm.NativePeer; | |
27 | |
28 import java.util.Locale; | |
29 | |
30 public class JPF_java_util_Locale extends NativePeer { | |
31 | |
32 static Locale getLocale (MJIEnv env, int locref) { | |
33 | |
34 //--- check first if it's one of the standard locales (ci is obviously loaded at this point | |
35 ClassInfo ci = env.getClassInfo(locref); // Locale is final, so we can do this | |
36 ElementInfo sei = ci.getStaticElementInfo(); | |
37 | |
38 if (locref == sei.getReferenceField("US")) return Locale.US; | |
39 if (locref == sei.getReferenceField("GERMAN")) return Locale.GERMAN; | |
40 if (locref == sei.getReferenceField("ENGLISH")) return Locale.ENGLISH; | |
41 if (locref == sei.getReferenceField("FRENCH")) return Locale.FRENCH; | |
42 if (locref == sei.getReferenceField("JAPANESE")) return Locale.JAPANESE; | |
43 if (locref == sei.getReferenceField("CHINESE")) return Locale.CHINESE; | |
44 //... we should have a bunch more | |
45 | |
46 | |
47 //--- if it wasn't any of these, get the fields and just construct it | |
48 | |
49 String country, language, variant; | |
50 FieldInfo fiBase = ci.getInstanceField("baseLocale"); | |
51 if (fiBase != null){ // Java >= 1.7 | |
52 int baseLocref = env.getReferenceField(locref, fiBase); | |
53 country = env.getStringObject(env.getReferenceField(baseLocref,"region")); | |
54 language = env.getStringObject(env.getReferenceField(baseLocref, "language")); | |
55 variant = env.getStringObject(env.getReferenceField(baseLocref, "variant")); | |
56 | |
57 } else { // Java < 1.7 | |
58 country = env.getStringObject(env.getReferenceField(locref,"country")); | |
59 language = env.getStringObject(env.getReferenceField(locref, "language")); | |
60 variant = env.getStringObject(env.getReferenceField(locref, "variant")); | |
61 } | |
62 | |
63 Locale locale = new Locale(language,country,variant); | |
64 return locale; | |
65 } | |
66 | |
67 @MJI | |
68 public int getDisplayName__Ljava_util_Locale_2__Ljava_lang_String_2 (MJIEnv env, int objref, int locref) { | |
69 Locale locale = getLocale(env, locref); | |
70 String name = locale.getDisplayName(); | |
71 return env.newString(name); | |
72 } | |
73 | |
74 @MJI | |
75 public int getDisplayVariant__Ljava_util_Locale_2__Ljava_lang_String_2 (MJIEnv env, int objref, int locref) { | |
76 Locale locale = getLocale(env, locref); | |
77 String variant = locale.getDisplayVariant(); | |
78 return env.newString(variant); | |
79 } | |
80 | |
81 @MJI | |
82 public int getDisplayCountry__Ljava_util_Locale_2__Ljava_lang_String_2 (MJIEnv env, int objref, int locref) { | |
83 Locale locale = getLocale(env, locref); | |
84 String country = locale.getDisplayCountry(); | |
85 return env.newString(country); | |
86 | |
87 } | |
88 | |
89 @MJI | |
90 public int getDisplayLanguage__Ljava_util_Locale_2__Ljava_lang_String_2 (MJIEnv env, int objref, int locref) { | |
91 Locale locale = getLocale(env, locref); | |
92 String language = locale.getDisplayLanguage(); | |
93 return env.newString(language); | |
94 } | |
95 | |
96 @MJI | |
97 public int getISO3Country____Ljava_lang_String_2 (MJIEnv env, int objref) { | |
98 Locale locale = getLocale(env, objref); | |
99 String s = locale.getISO3Country(); | |
100 return env.newString(s); | |
101 } | |
102 | |
103 @MJI | |
104 public int getISO3Language____Ljava_lang_String_2 (MJIEnv env, int objref) { | |
105 Locale locale = getLocale(env, objref); | |
106 String s = locale.getISO3Language(); | |
107 return env.newString(s); | |
108 } | |
109 | |
110 //--- the static ones | |
111 @MJI | |
112 public int getISOCountries_____3Ljava_lang_String_2 (MJIEnv env, int clsref) { | |
113 String[] s = Locale.getISOCountries(); | |
114 | |
115 int aref = env.newObjectArray("java.lang.String", s.length); | |
116 for (int i=0; i<s.length; i++) { | |
117 env.setReferenceArrayElement(aref, i, env.newString(s[i])); | |
118 } | |
119 | |
120 return aref; | |
121 } | |
122 | |
123 @MJI | |
124 public int getISOLanguages_____3Ljava_lang_String_2 (MJIEnv env, int clsref) { | |
125 String[] s = Locale.getISOLanguages(); | |
126 | |
127 int aref = env.newObjectArray("java.lang.String", s.length); | |
128 for (int i=0; i<s.length; i++) { | |
129 env.setReferenceArrayElement(aref, i, env.newString(s[i])); | |
130 } | |
131 | |
132 return aref; | |
133 } | |
134 | |
135 } |