private void addConfig()

in src/main/java/org/apache/directory/fortress/core/ant/FortressAntTask.java [2513:2585]


    private void addConfig() throws BuildException
    {
        LOG.info( "addConfig" );
        if( addconfig == null )
        {
            return;
        }

        // Loop through the entityclass elements
        for ( Addconfig addcfg : addconfig )
        {
            Properties props = new Properties();
            Configuration configuration = new Configuration();
            try
            {
                List<ConfigAnt> cfgs = addcfg.getConfig();
                for ( ConfigAnt cfg : cfgs )
                {
                    String val = cfg.getProps();
                    int indx = val.indexOf( GlobalIds.PROP_SEP );
                    if ( indx >= 1 )
                    {
                        String name = val.substring( 0, indx );
                        String value = val.substring( indx + 1 );

                        // The config realm property is required on updconfig op and points to the existing node in ldap to update with these new props.
                        if( name.equalsIgnoreCase( GlobalIds.CONFIG_REALM ))
                        {
                            configuration.setName( value );
                        }
                        else if( name.equalsIgnoreCase( GlobalIds.CONFIG_UID_NUMBER ))
                        {
                            configuration.setUidNumber( value );
                        }
                        else if( name.equalsIgnoreCase( GlobalIds.CONFIG_GID_NUMBER ))
                        {
                            configuration.setGidNumber( value );
                        }
                        else
                        {
                            props.setProperty( name, value );
                            LOG.info( "addConfig name [{}] value [{}]", name, value );
                        }
                    }
                }
                configuration.addProperties( props );
                LOG.info( "addConfig realm name [{}]", configuration.getName() );
                LOG.info( "addConfig gid.number [{}]", configuration.getGidNumber() );
                LOG.info( "addConfig uid.number [{}]", configuration.getUidNumber() );
                cfgMgr.add( configuration );
            }
            catch ( SecurityException se )
            {
                if ( se.getErrorId() == GlobalErrIds.FT_CONFIG_ALREADY_EXISTS )
                {
                    try
                    {
                        LOG.info( "addConfig realm name={} entry already exists, attempt to update", configuration.getName() );
                        cfgMgr.update( configuration );
                        LOG.info( "addConfig realm name={} update [{}] successful", configuration.getName(), configuration.getName() );
                    }
                    catch ( SecurityException se2 )
                    {
                        LOG.warn( "addConfig realm name={] update failed SecurityException={}", configuration.getName(), se2 );
                    }
                }
                else
                {
                    LOG.warn( "addConfig realm name={} failed SecurityException={}", configuration.getName(), se );
                }
            }
        }
    }