private static void load()

in ti/phase2/jars/core/src/java/org/apache/ti/util/type/TypeUtils.java [290:363]


    private static void load(Map /*<String, String>*/ map) {
        // load the properties and continue to populate the map
        for (Iterator i = map.keySet().iterator(); i.hasNext();) {
            String key = (String) i.next();
            String className = (String) map.get(key);

            if (((key == null) || key.equals(EMPTY_STRING)) || ((className == null) || className.equals(EMPTY_STRING))) {
                LOGGER.warn("Could not create a TypeConverter for type \"" + key + "\" and TypeConverter \"" + className + "\"");

                continue;
            }

            Class targetClazz = null;

            /* attempt to load the "convert-to" class */
            try {
                targetClazz = Class.forName(key);
            } catch (ClassNotFoundException cnf) {
                LOGGER.warn("Could not create a TypeConverter for type \"" + key +
                            "\" because the \"convert-to\" type could not be found.");

                continue;
            }

            Class tcClazz = null;
            BaseTypeConverter tc = null;

            // try to find the TypeConverter implementation
            try {
                tcClazz = Class.forName(className);

                Object obj = tcClazz.newInstance();

                // this supports existing TypeConverter implementations
                // but allows TypeUtils make calls against the BaseTypeConverter
                // API, which supports Locale-based conversion
                if (obj instanceof TypeConverter) {
                    tc = new DelegatingTypeConverter((TypeConverter) obj);
                } else if (obj instanceof BaseTypeConverter) {
                    tc = (BaseTypeConverter) obj;
                } else {
                    throw new IllegalStateException("Attempt to load illegal type converter type: " + tcClazz);
                }
            } catch (ClassNotFoundException cnf) {
                LOGGER.warn("Could not create a TypeConverter for type \"" + key +
                            "\" because the TypeConverter implementation class \"" +
                            ((tcClazz != null) ? tcClazz.getName() : null) + "\" could not be found.");

                continue;
            } catch (Exception e) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Could not create a TypeConverter for type \"" + key + "\" because the implementation class \"" +
                                ((tcClazz != null) ? tcClazz.getName() : null) + "\" could not be instantiated.");
                }

                continue;
            }

            /* found two type converters for the same class -- warn */
            if (TYPE_CONVERTERS.containsKey(targetClazz)) {
                if (LOGGER.isWarnEnabled()) {
                    LOGGER.warn("Overwriting a previously defined TypeConverter named \"" + targetClazz +
                                "\" with a new TypeConverter implementation of type \"" + className + "\"");
                }
            }

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("Adding a type converter; target type=\"" + targetClazz.getName() +
                            "\" TypeConverter implementation=\"" + tc.getClass().getName() + "\"");
            }

            TYPE_CONVERTERS.put(targetClazz, tc);
        }
    }