简体   繁体   中英

Calendar.getInstance method not loading userdefined locale classes

In JDK 6

I have implemented CalendarData_en_AT class for locale(en, AT) which is a user defined locale(not defined in jre). I see that when I try to load the locale using Calendar.getInstance() method it loads CalendarData_en.class

When further debugged, I found that it picks up only the locales that are specified in LocaleMetaDataInfo class

What needs to be done so that when we call Calendar.getInstance(new Locale(en, AT)) it loads CalendarData_en_AT.class

Code below:

I have a class CalendarData_en_AT.java

public class CalendarData_en_AT extends LocaleNamesBundle{

    public CalendarData_en_AT(){
    }

    protected final Object[][] getContents(){
        return
            new Object[][] { 
                new Object[] { "firstDayOfWeek", "2" },
                new Object[] { "minimalDaysInFirstWeek", "4" }
            };
    }
}

The compiled class is enclosed in a .jar file and have been placed in jre/lib/ext

Now from my test class

if I call Calendar.getInstance(new Locale("en","AT")).getFirstDayOfWeek()

it should return 2, but as of now it returns 1, reason being it loads CalendarData_en.class provide by and not CalendarData_en_AT.class which is user implemented

Not sure whether you can actually do this for the Calendar class. You'll have to create a provider conforming to the Locale Sensitive Services SPI.

Take a look at this blog post by a Sun employee for further details on creating and packaging such a provider

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM