modules/kernel/src/org/apache/axis2/i18n/ProjectResourceBundle.java [52:276]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class ProjectResourceBundle extends ResourceBundle {
    private static final Log log = LogFactory.getLog(ProjectResourceBundle.class);


    // The static cache of ResourceBundles.
    // The key is the 'basename + locale + default locale'
    // The element is a ResourceBundle object
    private static final Hashtable bundleCache = new Hashtable();

    private static final Locale defaultLocale = Locale.getDefault();

    private final ResourceBundle resourceBundle;
    private final String resourceName;


    protected Object handleGetObject(String key)
            throws MissingResourceException {
        if (log.isDebugEnabled()) {
            log.debug(this.toString() + "::handleGetObject(" + key + ")");
        }
        Object obj;
        try {
            obj = resourceBundle.getObject(key);
        } catch (MissingResourceException e) {
            /* catch missing resource, ignore, & return null
             * if this method doesn't return null, then parents
             * are not searched
             */
            obj = null;
        }
        return obj;
    }

    public Enumeration getKeys() {
        Enumeration myKeys = resourceBundle.getKeys();
        if (parent == null) {
            return myKeys;
        } else {
            final HashSet set = new HashSet();
            while (myKeys.hasMoreElements()) {
                set.add(myKeys.nextElement());
            }

            Enumeration pKeys = parent.getKeys();
            while (pKeys.hasMoreElements()) {
                set.add(pKeys.nextElement());
            }

            return new Enumeration() {
                private Iterator it = set.iterator();

                public boolean hasMoreElements() {
                    return it.hasNext();
                }

                public Object nextElement() {
                    return it.next();
                }
            };
        }
    }


    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName  The name of the project to which the class belongs.
     *                     It must be a proper prefix of the caller's package.
     * @param packageName  The package name to further construct
     *                     the basename.
     * @param resourceName The name of the resource without the
     *                     ".properties" extension
     * @throws MissingResourceException if projectName is not a prefix of
     *                                  the caller's package name, or if the resource could not be
     *                                  found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  String packageName,
                                                  String resourceName)
            throws MissingResourceException {
        return getBundle(projectName, packageName, resourceName, null, null, null);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName  The name of the project to which the class belongs.
     *                     It must be a proper prefix of the caller's package.
     * @param caller       The calling class.
     * @param resourceName The name of the resource without the
     *                     ".properties" extension
     * @throws MissingResourceException if projectName is not a prefix of
     *                                  the caller's package name, or if the resource could not be
     *                                  found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  Class caller,
                                                  String resourceName,
                                                  Locale locale)
            throws MissingResourceException {
        return getBundle(projectName,
                         caller,
                         resourceName,
                         locale,
                         null);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName  The name of the project to which the class belongs.
     *                     It must be a proper prefix of the caller's package.
     * @param packageName  The package name to construct base name.
     * @param resourceName The name of the resource without the
     *                     ".properties" extension
     * @param locale       The locale
     * @throws MissingResourceException if projectName is not a prefix of
     *                                  the caller's package name, or if the resource could not be
     *                                  found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  String packageName,
                                                  String resourceName,
                                                  Locale locale,
                                                  ClassLoader loader)
            throws MissingResourceException {
        return getBundle(projectName, packageName, resourceName, locale, loader, null);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName   The name of the project to which the class belongs.
     *                      It must be a proper prefix of the caller's package.
     * @param caller        The calling class.
     *                      This is used to get the package name to further construct
     *                      the basename as well as to get the proper ClassLoader.
     * @param resourceName  The name of the resource without the
     *                      ".properties" extension
     * @param locale        The locale
     * @param extendsBundle If non-null, then this ExtendMessages will
     *                      default to extendsBundle.
     * @throws MissingResourceException if projectName is not a prefix of
     *                                  the caller's package name, or if the resource could not be
     *                                  found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  Class caller,
                                                  String resourceName,
                                                  Locale locale,
                                                  ResourceBundle extendsBundle)
            throws MissingResourceException {
        return getBundle(projectName,
                         getPackage(caller.getClass().getName()),
                         resourceName,
                         locale,
                         caller.getClass().getClassLoader(),
                         extendsBundle);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName   The name of the project to which the class belongs.
     *                      It must be a proper prefix of the caller's package.
     * @param packageName   The package name to further construct
     *                      the basename.
     * @param resourceName  The name of the resource without the
     *                      ".properties" extension
     * @param locale        The locale
     * @param extendsBundle If non-null, then this ExtendMessages will
     *                      default to extendsBundle.
     * @throws MissingResourceException if projectName is not a prefix of
     *                                  the caller's package name, or if the resource could not be
     *                                  found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  String packageName,
                                                  String resourceName,
                                                  Locale locale,
                                                  ClassLoader loader,
                                                  ResourceBundle extendsBundle)
            throws MissingResourceException {
        if (log.isDebugEnabled()) {
            log.debug("getBundle(" + projectName + ","
                    + packageName + ","
                    + resourceName + ","
                    + String.valueOf(locale) + ",...)");
        }

        Context context = new Context();
        context.setLocale(locale);
        context.setLoader(loader);
        context.setProjectName(projectName);
        context.setResourceName(resourceName);
        context.setParentBundle(extendsBundle);

        packageName = context.validate(packageName);

        ProjectResourceBundle bundle = null;
        try {
            bundle = getBundle(context, packageName);
        } catch (RuntimeException e) {
            log.debug("Exception: ", e);
            throw e;
        }

        if (bundle == null) {
            throw new MissingResourceException("Cannot find resource '" +
                    packageName + '.' + resourceName + "'",
                                               resourceName, "");
        }

        return bundle;
    }

    /**
     * get bundle...
     * - check cache
     * - try up hierarchy
     * - if at top of hierarchy, use (link to) context.getParentBundle()
     */
    private static synchronized ProjectResourceBundle getBundle(Context context, String packageName)
            throws MissingResourceException {
        String cacheKey = context.getCacheKey(packageName);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/metadata/src/org/apache/axis2/jaxws/i18n/ProjectResourceBundle.java [47:254]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class ProjectResourceBundle extends ResourceBundle {
    private static final Log log = LogFactory.getLog(ProjectResourceBundle.class);


    // The static cache of ResourceBundles.
    // The key is the 'basename + locale + default locale'
    // The element is a ResourceBundle object
    private static final Hashtable bundleCache = new Hashtable();

    private static final Locale defaultLocale = Locale.getDefault();

    private final ResourceBundle resourceBundle;
    private final String resourceName;


    protected Object handleGetObject(String key)
            throws MissingResourceException {
        if (log.isDebugEnabled()) {
            log.debug(this.toString() + "::handleGetObject(" + key + ")");
        }
        Object obj;
        try {
            obj = resourceBundle.getObject(key);
        } catch (MissingResourceException e) {
            /* catch missing resource, ignore, & return null
             * if this method doesn't return null, then parents
             * are not searched
             */
            obj = null;
        }
        return obj;
    }

    public Enumeration getKeys() {
        Enumeration myKeys = resourceBundle.getKeys();
        if (parent == null) {
            return myKeys;
        } else {
            final HashSet set = new HashSet();
            while (myKeys.hasMoreElements()) {
                set.add(myKeys.nextElement());
            }

            Enumeration pKeys = parent.getKeys();
            while (pKeys.hasMoreElements()) {
                set.add(pKeys.nextElement());
            }

            return new Enumeration() {
                private Iterator it = set.iterator();

                public boolean hasMoreElements() {
                    return it.hasNext();
                }

                public Object nextElement() {
                    return it.next();
                }
            };
        }
    }


    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName  The name of the project to which the class belongs. It must be a proper
     *                     prefix of the caller's package.
     * @param packageName  The package name to further construct the basename.
     * @param resourceName The name of the resource without the ".properties" extension
     * @throws MissingResourceException if projectName is not a prefix of the caller's package name,
     *                                  or if the resource could not be found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  String packageName,
                                                  String resourceName)
            throws MissingResourceException {
        return getBundle(projectName, packageName, resourceName, null, null, null);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName  The name of the project to which the class belongs. It must be a proper
     *                     prefix of the caller's package.
     * @param caller       The calling class.
     * @param resourceName The name of the resource without the ".properties" extension
     * @throws MissingResourceException if projectName is not a prefix of the caller's package name,
     *                                  or if the resource could not be found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  Class caller,
                                                  String resourceName,
                                                  Locale locale)
            throws MissingResourceException {
        return getBundle(projectName,
                         caller,
                         resourceName,
                         locale,
                         null);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName  The name of the project to which the class belongs. It must be a proper
     *                     prefix of the caller's package.
     * @param packageName  The package name to construct base name.
     * @param resourceName The name of the resource without the ".properties" extension
     * @param locale       The locale
     * @throws MissingResourceException if projectName is not a prefix of the caller's package name,
     *                                  or if the resource could not be found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  String packageName,
                                                  String resourceName,
                                                  Locale locale,
                                                  ClassLoader loader)
            throws MissingResourceException {
        return getBundle(projectName, packageName, resourceName, locale, loader, null);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName   The name of the project to which the class belongs. It must be a proper
     *                      prefix of the caller's package.
     * @param caller        The calling class. This is used to get the package name to further
     *                      construct the basename as well as to get the proper ClassLoader.
     * @param resourceName  The name of the resource without the ".properties" extension
     * @param locale        The locale
     * @param extendsBundle If non-null, then this ExtendMessages will default to extendsBundle.
     * @throws MissingResourceException if projectName is not a prefix of the caller's package name,
     *                                  or if the resource could not be found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  Class caller,
                                                  String resourceName,
                                                  Locale locale,
                                                  ResourceBundle extendsBundle)
            throws MissingResourceException {
        return getBundle(projectName,
                         getPackage(caller.getClass().getName()),
                         resourceName,
                         locale,
                         caller.getClass().getClassLoader(),
                         extendsBundle);
    }

    /**
     * Construct a new ProjectResourceBundle
     *
     * @param projectName   The name of the project to which the class belongs. It must be a proper
     *                      prefix of the caller's package.
     * @param packageName   The package name to further construct the basename.
     * @param resourceName  The name of the resource without the ".properties" extension
     * @param locale        The locale
     * @param extendsBundle If non-null, then this ExtendMessages will default to extendsBundle.
     * @throws MissingResourceException if projectName is not a prefix of the caller's package name,
     *                                  or if the resource could not be found/loaded.
     */
    public static ProjectResourceBundle getBundle(String projectName,
                                                  String packageName,
                                                  String resourceName,
                                                  Locale locale,
                                                  ClassLoader loader,
                                                  ResourceBundle extendsBundle)
            throws MissingResourceException {
        if (log.isDebugEnabled()) {
            log.debug("getBundle(" + projectName + ","
                    + packageName + ","
                    + resourceName + ","
                    + String.valueOf(locale) + ",...)");
        }

        Context context = new Context();
        context.setLocale(locale);
        context.setLoader(loader);
        context.setProjectName(projectName);
        context.setResourceName(resourceName);
        context.setParentBundle(extendsBundle);

        packageName = context.validate(packageName);

        ProjectResourceBundle bundle = null;
        try {
            bundle = getBundle(context, packageName);
        } catch (RuntimeException e) {
            log.debug("Exception: ", e);
            throw e;
        }

        if (bundle == null) {
            throw new MissingResourceException("Cannot find resource '" +
                    packageName + '.' + resourceName + "'",
                                               resourceName, "");
        }

        return bundle;
    }

    /**
     * get bundle... - check cache - try up hierarchy - if at top of hierarchy, use (link to)
     * context.getParentBundle()
     */
    private static synchronized ProjectResourceBundle getBundle(Context context, String packageName)
            throws MissingResourceException {
        String cacheKey = context.getCacheKey(packageName);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



