2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
19 package gov.nasa.jpf.vm;
21 import gov.nasa.jpf.annotation.MJI;
22 import gov.nasa.jpf.vm.MJIEnv;
23 import gov.nasa.jpf.vm.NativePeer;
25 import java.text.DateFormat;
26 import java.text.Format;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
31 * (incomplete) native peer for SimpleDateFormat. See Format for details
32 * about native formatter delegation
34 public class JPF_java_text_SimpleDateFormat extends NativePeer {
36 SimpleDateFormat getInstance (MJIEnv env, int objref) {
37 Format fmt = JPF_java_text_Format.getInstance(env,objref);
38 assert fmt instanceof SimpleDateFormat;
40 return (SimpleDateFormat)fmt;
44 public void init0____V (MJIEnv env, int objref) {
45 SimpleDateFormat fmt = new SimpleDateFormat();
46 JPF_java_text_Format.putInstance(env,objref,fmt);
50 public void init0__Ljava_lang_String_2__V (MJIEnv env, int objref, int patternref) {
51 String pattern = env.getStringObject(patternref);
53 SimpleDateFormat fmt = new SimpleDateFormat(pattern);
54 JPF_java_text_Format.putInstance(env,objref,fmt);
58 public void init0__II__V (MJIEnv env, int objref, int timeStyle, int dateStyle) {
59 // we are lost here - can't call this SimpleDateFormat ctor because it's package private
60 // (this is called - and has to be intercepted - from the DateFormat.getInstance() factory)
62 DateFormat fmt = null;
65 fmt = DateFormat.getDateInstance(dateStyle);
66 } else if (dateStyle < 0) {
67 fmt = DateFormat.getTimeInstance(timeStyle);
69 fmt = DateFormat.getDateTimeInstance(dateStyle, timeStyle);
72 JPF_java_text_Format.putInstance(env,objref,fmt);
76 public int format0 (MJIEnv env, int objref, long dateTime) {
77 Date date = new Date(dateTime);
78 SimpleDateFormat f = getInstance(env,objref);
79 String s = f.format(date);
80 return env.newString(s);
84 public void applyPattern__Ljava_lang_String_2__V (MJIEnv env, int objRef, int patternRef) {
85 SimpleDateFormat format = getInstance (env, objRef);
86 String pattern = env.getStringObject(patternRef);
87 format.applyPattern(pattern);