/*
 *  Platform services root class
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTMass.core.jTMassPlatform.jTServices;

import jTMass.TMass;
import jTMass.core.jALLL.jTObjects.TAtom;
import jTMass.core.jALLL.jTObjects.TList;
import jTMass.core.jALLL.jTObjects.TObject;
import jTMass.core.jTMassPlatform.TPlatform;

public abstract class TAService {

    Long PInitTime;
    String PClientName;
    String PServiceName;
    String PServiceCode;
    TPlatform PPlatform;

    // ===== INTEGER PARSING =====
	
    protected Integer atomToInteger(TAtom object) throws NumberFormatException{
        Integer result=0;
	String source=object.getContent();
	Integer value=new Integer(source);
        result=value.intValue();
	return(result);
    }

    protected Integer objectToInteger(TObject object) throws NumberFormatException{
        if(object instanceof TAtom)
            return(atomToInteger((TAtom)object));
        if(object instanceof TList)
            if(((TList)object).size()==0)
                throw new NumberFormatException();
            else{
                TObject newObject=((TList)object).get(0);
                return(objectToInteger(newObject));
            }
        throw new NumberFormatException();
    }

    // ===== PARAMETERS ACCESS =====
    
    protected TObject getIth(int position, TObject params){
        if(params instanceof TList)
            if( ((TList)params).size()>=position)
                return(((TList)params).get(position-1));
        return(null);
    }

    // ===== READERS =====

    public Long getInitTime(){
        return(PInitTime);
    }

    public String getClientName(){
        return(PClientName);
    }

    public String getServiceName(){
        return(PServiceName);
    }

    // ===== SERVICE EXECUTION =====

    public TObject processService(TList parameters, String clientName, String serviceName){
        PClientName=clientName;
        PServiceName=serviceName;

        // === vycucnout serviceCode do PServiceCode;

        return(null);
    }

    // ===== CONSTRUCTOR =====

    public TAService(TPlatform platform){
        PPlatform=platform;
        PClientName="*not used*";
        PInitTime=TMass.getSimulator().getModelTime();
    }

}