protected void initMapping()

in src/java/org/apache/turbine/services/BaseServiceBroker.java [246:306]


    protected void initMapping() throws InitializationException
    {
        // we need to temporarily store the earlyInit flags to avoid
        // ConcurrentModificationExceptions
        Map<String, String> earlyInitFlags = new LinkedHashMap<>();

        /*
         * These keys returned in an order that corresponds
         * to the order the services are listed in
         * the TR.props.
         */
        for (Iterator<String> keys = configuration.getKeys(); keys.hasNext();)
        {
            String key = keys.next();
            String[] keyParts = StringUtils.split(key, ".");

            if (keyParts.length == 3
                    && (keyParts[0] + ".").equals(SERVICE_PREFIX)
                    && ("." + keyParts[2]).equals(CLASSNAME_SUFFIX))
            {
                String serviceKey = keyParts[1];
                log.info("Added Mapping for Service: {}", serviceKey);

                if (!mapping.containsKey(serviceKey))
                {
                    String className = configuration.getString(key);
                    try
                    {
                        Class<?> clazz = Class.forName(className);
                        mapping.put(serviceKey, clazz);

                        // detect TurbineServiceProviders
                        if (checkForInterface(TurbineServiceProvider.class, clazz.getInterfaces()))
                        {
                            log.info("Found a TurbineServiceProvider: {} - initializing it early", serviceKey);
                            earlyInitFlags.put(SERVICE_PREFIX + serviceKey + ".earlyInit", "true");
                        }
                    }
                    // those two errors must be passed to the VM
                    catch (ThreadDeath t)
                    {
                        throw t;
                    }
                    catch (OutOfMemoryError t)
                    {
                        throw t;
                    }
                    catch (ClassNotFoundException | NoClassDefFoundError e)
                    {
                        throw new InitializationException("Class " + className +
                            " is unavailable. Check your jars and classes.", e);
                    }
                }
            }
        }

        for (Map.Entry<String, String> entry : earlyInitFlags.entrySet())
        {
            configuration.setProperty(entry.getKey(), entry.getValue());
        }
    }