/*
 * Copyright
 *   2008 axYus - www.axyus.com
 *   2008 C.Marchand - christophe.marchand@axyus.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package fr.gouv.finances.dgfip.xemelios.web.gwt.client.widget.search;

import java.util.ArrayList;

/**
 * A piece of code to run after an AJAX call
 * @author chm
 */
public abstract class PostRunnable {
    private int intValue;
    private ArrayList<MapEntry> additionalObjects = new ArrayList<MapEntry>();
    private String name;

    public PostRunnable(String name) {
        this.name=name;
    }

    public abstract void run();
    public void setAdditionalInt(int value) {
        this.intValue = value;
    }
    public int getIntValue() { return intValue; }
    public void setAdditionalObject(String objectName, Object value) {
        additionalObjects.add(new MapEntry(objectName, value));
    }
    public Object getAdditionalObject(String objectName) {
        Object ret = null;
        for(MapEntry entry:additionalObjects) {
            if(entry.getName().equals(objectName)) {
                ret = entry.getValue();
                break;
            }
        }
        return ret;
    }

    private static class MapEntry {
        private String name;
        private Object value;
        public MapEntry(String name, Object value) {
            this.name=name;
            this.value=value;
        }

        public String getName() {
            return name;
        }

        public Object getValue() {
            return value;
        }
    }
}
