// ** This class was generated with DemFGen (vers:06/04/2009)

package http.gen;

import edu.neu.ccs.demeterf.demfgen.lib.*;
import java.net.Socket;
import java.net.ServerSocket;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.InputStream;




/** Representation of ReqHandler */
public class ReqHandler{

    /** Construct a(n) ReqHandler Instance */
    public ReqHandler(){
    }
    /** Is the given object Equal to this ReqHandler? */
    public boolean equals(Object o){
        if(!(o instanceof ReqHandler))return false;
        if(o == this)return true;
        ReqHandler oo = (ReqHandler)o;
        return true;
    }
    /** Parse an instance of ReqHandler from the given String */
    public static ReqHandler parse(String inpt) throws ParseException{
        return new TheParser(new java.io.StringReader(inpt)).parse_ReqHandler();
    }
    /** Parse an instance of ReqHandler from the given Stream */
    public static ReqHandler parse(java.io.InputStream inpt) throws ParseException{
        return new TheParser(inpt).parse_ReqHandler();
    }
    /** Parse an instance of ReqHandler from the given Reader */
    public static ReqHandler parse(java.io.Reader inpt) throws ParseException{
        return new TheParser(inpt).parse_ReqHandler();
    }


    /** Respond to a possible ServerSocket Connection */
    public void respond(ServerSocket s){
        try{ respond(s.accept()); }catch(IOException io){ throw new RuntimeException(io); }
    }

    /** Respond to a Socket Connection */
    public void respond(Socket in){
        try{
            HTTPReq req = HTTPReq.fromSocket(in);
            HTTPResp resp = req.handle(this);
            resp.toSocket(in);
            in.close();
        }catch(IOException io){ throw new RuntimeException(io); }
    }

    /** Handle a GET request */
    public HTTPResp get(HTTPReq r){ return other(r); }
    /** Handle a POST request */
    public HTTPResp post(HTTPReq r){ return other(r); }
    /** Handle a HEAD request */
    public HTTPResp head(HTTPReq r){ return other(r); }
    /** Handle any Other/unknown request */
    public HTTPResp other(HTTPReq r){ return HTTPResp.ok("text/plain",""); }

    /** DGP method from Class PrintToString */
    public  String toString(){ return http.gen.PrintToString.PrintToStringM(this); }

}