public static void expand()

in src/java/org/apache/fulcrum/yaafi/framework/util/ConfigurationUtil.java [46:107]


    public static void expand(Logger logger, DefaultConfiguration defaultConfiguration, Map<?, ?> vars) throws ConfigurationException
    {
        if( vars == null || vars.size() == 0)
        {
            return;
        }

        // update the value of the configuration element

        if(defaultConfiguration.getValue(null) != null)
        {
            String oldValue = defaultConfiguration.getValue();
            String newValue = ConfigurationUtil.expand(oldValue, vars);
            defaultConfiguration.setValue(newValue);

            if(oldValue.equals(newValue) == false)
            {
                logger.debug("Changed element <"
                    + defaultConfiguration.getName()
                    + "> from '"
                    + oldValue
                    + "' ==> '"
                    + newValue
                    + "'"
                    );
            }
        }

        // update all attributes

        String attributeName = null;
        String[] attributeNames = defaultConfiguration.getAttributeNames();

        for(int i=0; i<attributeNames.length; i++)
        {
            attributeName = attributeNames[i];
            String oldAttributeValue = defaultConfiguration.getAttribute(attributeName);
            String newAttributeValue = ConfigurationUtil.expand(oldAttributeValue, vars);
            defaultConfiguration.setAttribute(attributeName, newAttributeValue);

            if(oldAttributeValue.equals(newAttributeValue) == false)
            {
                logger.debug("Changed attribute '"
                    + defaultConfiguration.getName() + "@" + attributeName
                    + "' from '"
                    + oldAttributeValue
                    + "' ==> '"
                    + newAttributeValue
                    + "'"
                    );
            }
        }

        // and now recurse through all children (children are in general a lot of work)

        Configuration[] children = defaultConfiguration.getChildren();

        for(int i=0; i<children.length; i++)
        {
            ConfigurationUtil.expand(logger, ((DefaultConfiguration) children[i]), vars);
        }
    }