//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vhudson-jaxb-ri-2.1-520 
// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2009.05.15 at 12:16:57 PM MSD 
//


package org.spbu.benchmark.app;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.NClob;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;
import java.util.Map;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

import org.spbu.benchmark.LoggingSupport;

import com.progress.open4gl.InputResultSet;
import com.progress.open4gl.javaproxy.ParamArrayMode;



/**
 * <p>Java class for Parameter complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="Parameter">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="index" type="{http://www.w3.org/2001/XMLSchema}int"/>
 *         &lt;element name="direction">
 *           &lt;simpleType>
 *             &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string">
 *               &lt;enumeration value="IN"/>
 *               &lt;enumeration value="OUT"/>
 *               &lt;enumeration value="IN-OUT"/>
 *             &lt;/restriction>
 *           &lt;/simpleType>
 *         &lt;/element>
 *         &lt;element name="type" type="{}OEParameter"/>
 *         &lt;element name="value" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(name = "Parameter", propOrder = {
    "index",
    "direction",
    "type",
    "value"
})
public class Parameter{
	@XmlElement(required = true)
    protected int index;
    @XmlElement(required = true)
    protected String direction;
    @XmlElement(required = true)
    protected OEParameter type;
    @XmlElement(required = false)
    protected String value;
    protected Map<String, Object> context;
    public Parameter(){
    	
    }
    public Parameter(int index,String direction,OEParameter type,String value){
    	this.index = index;
    	this.direction = direction;
    	this.type = type;
    	this.value = value;
    }
    public int getMode(){
    	if(direction.equalsIgnoreCase("IN")) return ParamArrayMode.INPUT;
    	if(direction.equalsIgnoreCase("OUT")) return ParamArrayMode.OUTPUT;
    	if(direction.equalsIgnoreCase("IN-OUT")) return ParamArrayMode.INPUT_OUTPUT;
    	return ParamArrayMode.INPUT;
    }
   
    public Object getParsedValue() throws IOException,SQLException{
    	int t = type.get();
    	if(value==null){
    		return null;
    	}
    	if(value.length()>3)
    	if(value.startsWith("${")&&value.endsWith("}")){
    		if(this.getMode()==ParamArrayMode.OUTPUT) return null;
    		String var = value.substring(2, value.length()-1);
    		Object value = context.get(var);
    		return value;
    	}
    	switch(t){
    		case com.progress.open4gl.Parameter.PRO_CHARACTER: 
    			return value;
			case com.progress.open4gl.Parameter.PRO_INTEGER: 
				 try{
					 return Integer.parseInt(value);
				 }catch(NumberFormatException e){ throw new IOException(e);}
			case com.progress.open4gl.Parameter.PRO_LOGICAL: 
				 try{
					 return Boolean.valueOf(value);
				 }catch(Exception e){ throw new IOException(e);}				
			case com.progress.open4gl.Parameter.PRO_DATE: 
				try{
					GregorianCalendar g = new GregorianCalendar();
					DateFormat f = new SimpleDateFormat("dd/MM/yyyy");
					g.setTime(f.parse(value));
					return g;
				}catch(Exception e){throw new IOException(e);}
			case com.progress.open4gl.Parameter.PRO_DATETIME: 
				try{
					GregorianCalendar g = new GregorianCalendar();
					DateFormat f = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
					g.setTime(f.parse(value));
					return g;
				}catch(Exception e){throw new IOException(e);}				
			case com.progress.open4gl.Parameter.PRO_LONGCHAR:
				 return value;
			case com.progress.open4gl.Parameter.PRO_TEMPTABLE:
				return null;
			case com.progress.open4gl.Parameter.PRO_DECIMAL: 
				 try{
					 return BigDecimal.valueOf(Double.parseDouble(value));
				 }catch(NumberFormatException e){ throw new IOException(e);}
			default: return value;
    	}
    }
    /**
     * Gets the value of the index property.
     * 
     */
    public int getIndex() {
        return index;
    }

    /**
     * Sets the value of the index property.
     * 
     */
    public void setIndex(int value) {
        this.index = value;
    }

    /**
     * Gets the value of the direction property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getDirection() {
        return direction;
    }

    /**
     * Sets the value of the direction property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setDirection(String value) {
        this.direction = value;
    }

    /**
     * Gets the value of the type property.
     * 
     * @return
     *     possible object is
     *     {@link OEParameter }
     *     
     */
    public OEParameter getType() {
        return type;
    }

    /**
     * Sets the value of the type property.
     * 
     * @param value
     *     allowed object is
     *     {@link OEParameter }
     *     
     */
    public void setType(OEParameter value) {
        this.type = value;
    }

    /**
     * Gets the value of the value property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getValue() {
        return value;
    }

    /**
     * Sets the value of the value property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setValue(String value) {
        this.value = value;
    }
	public Map<String, Object> getContext() {
		return context;
	}
	public void setContext(Map<String, Object> context) {
		this.context = context;
	}

}
