// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 6/15/2001 17:06:32
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/commands/SetEnvironmentCommand

package com.macromedia.generator.commands;

import com.macromedia.generator.api.Context;
import com.macromedia.generator.api.Script;
import com.macromedia.generator.app.*;
import com.macromedia.generator.utils.DataSourceTokenizer;
import java.util.Properties;

public class SetEnvironmentCommand extends GenericCommand
{

    public SetEnvironmentCommand()
    {
    }

    public void doCommand(FlashEnvironment flashenvironment, Script script, Context context, int i, Properties properties)
        throws FlashCommandException
    {
        String s = null;
        s = properties.getProperty("datasource", "");
        s = context.apply(s);
        DataSourceTokenizer datasourcetokenizer = new DataSourceTokenizer(s);
        UrlDataSource urldatasource = new UrlDataSource();
        urldatasource.setEnvironment(flashenvironment);
        for(String s1 = datasourcetokenizer.nextDataSource(); s1 != null; s1 = datasourcetokenizer.nextDataSource())
        {
            String as[][] = urldatasource.getData(s1);
            if(as == null)
            {
                logError(flashenvironment, "DataSourceError", s);
                return;
            }
            if(as.length < 2)
            {
                logError(flashenvironment, "DataSourceFormatError", s);
                return;
            }
            int j;
            for(j = 0; j < as[0].length; j++)
                if(as[0][j].equalsIgnoreCase("NAME"))
                    break;

            if(j == as[0].length)
            {
                logError(flashenvironment, "NameColumnNotFound", s);
                return;
            }
            int k;
            for(k = 0; k < as[0].length; k++)
                if(as[0][k].equalsIgnoreCase("VALUE"))
                    break;

            if(k == as[0].length)
            {
                logError(flashenvironment, "ValueColumnNotFound", s);
                return;
            }
            for(int l = 1; l < as.length; l++)
                context.setValue(context.apply(as[l][j]), context.apply(as[l][k]));

        }

    }
}