CalendarProvider provider = LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale) .getCalendarProvider(); if (provider != null) { try { return provider.getInstance(zone, aLocale); } catch (IllegalArgumentException iae) { // fall back to the default instantiation } }
//上面部分跟下去最后到CalendarProvider的实现CalendarProviderImpl, //其最后getInstance的实现委托给了Calendar中的Build.build(),与下面类似也就是静态工厂模式 Calendar cal = null; if (aLocale.hasExtensions()) { String caltype = aLocale.getUnicodeLocaleType("ca"); if (caltype != null) { switch (caltype) { case"buddhist": cal = new BuddhistCalendar(zone, aLocale); break; case"japanese": cal = new JapaneseImperialCalendar(zone, aLocale); break; case"gregory": cal = new GregorianCalendar(zone, aLocale); break; } } } if (cal == null) { // If no known calendar type is explicitly specified, // perform the traditional way to create a Calendar: // create a BuddhistCalendar for th_TH locale, // a JapaneseImperialCalendar for ja_JP_JP locale, or // a GregorianCalendar for any other locales. // NOTE: The language, country and variant strings are interned. //如果是泰国地区就返回佛历,日本地区则返回日本帝国历 //其他国家和地区就返回格里高利历,即公历,没有阴历 if (aLocale.getLanguage() == "th" && aLocale.getCountry() == "TH") { cal = new BuddhistCalendar(zone, aLocale); } elseif (aLocale.getVariant() == "JP" && aLocale.getLanguage() == "ja" && aLocale.getCountry() == "JP") { cal = new JapaneseImperialCalendar(zone, aLocale); } else { cal = new GregorianCalendar(zone, aLocale); } } return cal; }
@Override public java.sql.Connection connect(String url, Properties info)throws SQLException {
try { if (!ConnectionUrl.acceptsUrl(url)) { /* * According to JDBC spec: * The driver should return "null" if it realizes it is the wrong kind of driver to connect to the given URL. This will be common, as when the * JDBC driver manager is asked to connect to a given URL it passes the URL to each loaded driver in turn. */ returnnull; }
packagePrefixList = java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction(protocolPathProp,"")); if (packagePrefixList != "") { packagePrefixList += "|"; }
// REMIND: decide whether to allow the "null" class prefix // or not. packagePrefixList += "sun.net.www.protocol";
StringTokenizer packagePrefixIter = new StringTokenizer(packagePrefixList, "|");
while (handler == null && packagePrefixIter.hasMoreTokens()) {
String packagePrefix = packagePrefixIter.nextToken().trim(); try { String clsName = packagePrefix + "." + protocol + ".Handler"; Class<?> cls = null; try { cls = Class.forName(clsName); } catch (ClassNotFoundException e) { ClassLoader cl = ClassLoader.getSystemClassLoader(); if (cl != null) { cls = cl.loadClass(clsName); } } if (cls != null) { handler = (URLStreamHandler)cls.newInstance(); } } catch (Exception e) { // any number of exceptions can get thrown here } } }
synchronized (streamHandlerLock) {
URLStreamHandler handler2 = null;
// Check again with hashtable just in case another // thread created a handler since we last checked handler2 = handlers.get(protocol);
if (handler2 != null) { return handler2; }
// Check with factory if another thread set a // factory since our last check if (!checkedWithFactory && factory != null) { handler2 = factory.createURLStreamHandler(protocol); }
if (handler2 != null) { // The handler from the factory must be given more // importance. Discard the default handler that // this thread created. handler = handler2; }
// Insert this handler into the hashtable if (handler != null) { handlers.put(protocol, handler); }