當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceBundle.getBaseBundleName方法代碼示例

本文整理匯總了Java中java.util.ResourceBundle.getBaseBundleName方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourceBundle.getBaseBundleName方法的具體用法?Java ResourceBundle.getBaseBundleName怎麽用?Java ResourceBundle.getBaseBundleName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.ResourceBundle的用法示例。


在下文中一共展示了ResourceBundle.getBaseBundleName方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setResourceBundle

import java.util.ResourceBundle; //導入方法依賴的package包/類
/**
 * Sets a resource bundle on this logger.
 * All messages will be logged using the given resource bundle for its
 * specific {@linkplain ResourceBundle#getLocale locale}.
 * @param bundle The resource bundle that this logger shall use.
 * @throws NullPointerException if the given bundle is {@code null}.
 * @throws IllegalArgumentException if the given bundle doesn't have a
 *         {@linkplain ResourceBundle#getBaseBundleName base name},
 *         or if this logger already has a resource bundle set but
 *         the given bundle has a different base name.
 * @throws SecurityException if a security manager exists,
 *         this logger is not anonymous, and the caller
 *         does not have LoggingPermission("control").
 * @since 1.8
 */
public void setResourceBundle(ResourceBundle bundle) {
    checkPermission();

    // Will throw NPE if bundle is null.
    final String baseName = bundle.getBaseBundleName();

    // bundle must have a name
    if (baseName == null || baseName.isEmpty()) {
        throw new IllegalArgumentException("resource bundle must have a name");
    }

    synchronized (this) {
        LoggerBundle lb = loggerBundle;
        final boolean canReplaceResourceBundle = lb.resourceBundleName == null
                || lb.resourceBundleName.equals(baseName);

        if (!canReplaceResourceBundle) {
            throw new IllegalArgumentException("can't replace resource bundle");
        }


        loggerBundle = LoggerBundle.get(baseName, bundle);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:40,代碼來源:Logger.java

示例2: call

import java.util.ResourceBundle; //導入方法依賴的package包/類
@Override
public Exception call() throws Exception {
    try {
        final String name = logger.getResourceBundleName();
        if (!Objects.equals(name, rbName)) {
            throw new RuntimeException("Unexpected rbname for "
                + logger.getName() + ": " + name);
        }
        final ResourceBundle b = logger.getResourceBundle();
        if (!Objects.equals(b == null ? null : b.getBaseBundleName(), rbName)) {
            throw new RuntimeException("Unexpected base name for "
                + logger.getName() + ": " + b.getBaseBundleName());
        }
    } catch(Exception x) {
        return x;
    }
    return null;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:TestLoggerBundleSync.java

示例3: getBaseName

import java.util.ResourceBundle; //導入方法依賴的package包/類
static String getBaseName(ResourceBundle bundle) {
    return bundle == null ? null : bundle.getBaseBundleName();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:4,代碼來源:TestLogrbResourceBundle.java

示例4: run

import java.util.ResourceBundle; //導入方法依賴的package包/類
@Override
public void run() {
    try {
        handler.setLevel(Level.FINEST);
        while (goOn) {
            Logger l;
            Logger foo = Logger.getLogger("foo");
            Logger bar = Logger.getLogger("foo.bar");
            for (long i=0; i < nextLong.longValue() + 100 ; i++) {
                if (!goOn) break;
                l = Logger.getLogger("foo.bar.l"+i);
                final ResourceBundle b = l.getResourceBundle();
                final String name = l.getResourceBundleName();
                if (b != null) {
                    if (!name.equals(b.getBaseBundleName())) {
                        throw new RuntimeException("Unexpected bundle name: "
                                +b.getBaseBundleName());
                    }
                }
                Logger ll = Logger.getLogger(l.getName()+".bie.bye");
                ResourceBundle hrb;
                String hrbName;
                if (handler.getLevel() != Level.FINEST) {
                    throw new RuntimeException("Handler level is not finest: "
                            + handler.getLevel());
                }
                final int countBefore = handler.count;
                handler.reset();
                ll.setLevel(Level.FINEST);
                ll.addHandler(handler);
                ll.log(Level.FINE, "dummy {0}", this);
                ll.removeHandler(handler);
                final int countAfter = handler.count;
                if (countBefore == countAfter) {
                    throw new RuntimeException("Handler not called for "
                            + ll.getName() + "("+ countAfter +")");
                }
                hrb = handler.rb;
                hrbName = handler.rbName;
                if (name != null) {
                    // if name is not null, then it implies that it
                    // won't change, since setResourceBundle() cannot
                    // replace a non null name.
                    // Since we never set the resource bundle on 'll',
                    // then ll must inherit its resource bundle [name]
                    // from l - and therefor we should find it in
                    // handler.rb/handler.rbName
                    if (!name.equals(hrbName)) {
                        throw new RuntimeException("Unexpected bundle name: "
                                +hrbName);
                    }
                    // here we know that hrbName is not null so hrb
                    // should not be null either.
                    if (!name.equals(hrb.getBaseBundleName())) {
                        throw new RuntimeException("Unexpected bundle name: "
                                +hrb.getBaseBundleName());
                    }
                }

                // Make sure to refer to 'l' explicitly in order to
                // prevent eager garbage collecting before the end of
                // the test (JDK-8030192)
                if (!ll.getName().startsWith(l.getName())) {
                    throw new RuntimeException("Logger " + ll.getName()
                            + "does not start with expected prefix "
                            + l.getName());
                }

                getRBcount.incrementAndGet();
                if (!goOn) break;
                Thread.sleep(1);
            }
        }
   } catch (Exception x) {
       fail(x);
   }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:78,代碼來源:TestLoggerBundleSync.java

示例5: getBaseName

import java.util.ResourceBundle; //導入方法依賴的package包/類
public static String getBaseName(ResourceBundle bundle) {
    return bundle == null ? null : bundle.getBaseBundleName();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:4,代碼來源:TestGetBaseBundleName.java


注:本文中的java.util.ResourceBundle.getBaseBundleName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。