/*
 * $Id: XMLRPCCallingConvention.java,v 1.54 2011/04/16 15:48:02 agoubard Exp $
 *
 * See the COPYRIGHT file for redistribution and use restrictions.
 */
package org.xins.server;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.xins.common.MandatoryArgumentChecker;

/**
 * The Protobuffer calling convention.
 *
 * @version $Revision: 1.54 $ $Date: 2011/04/16 15:48:02 $
 * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
 */
public class ProtobufCallingConvention extends CallingConvention {

   /**
    * The content type of the HTTP response.
    */
   protected static final String RESPONSE_CONTENT_TYPE = "application/x-protobuf";

   /**
    * The API. Never
    * <code>null</code>.
    */
   private final API _api;

   /**
    * Creates a new
    * <code>ProtobufCallingConvention</code> instance.
    *
    * @param api the API, needed for the XML-RPC messages, cannot be
    * <code>null</code>.
    *
    * @throws IllegalArgumentException if
    * <code>api == null</code>.
    */
   public ProtobufCallingConvention(API api)
           throws IllegalArgumentException {

      // Check arguments
      MandatoryArgumentChecker.check("api", api);

      // Store the API reference (can be null!)
      _api = api;
   }

   protected String[] getSupportedMethods() {
      return new String[]{"POST"};
   }

   protected boolean matches(HttpServletRequest httpRequest) throws Exception {
      return RESPONSE_CONTENT_TYPE.equals(httpRequest.getHeader("Accept"));
   }

   protected FunctionRequest convertRequestImpl(HttpServletRequest httpRequest)
           throws InvalidRequestException, FunctionNotSpecifiedException {
      return null;
   }

   protected void convertResultImpl(FunctionResult xinsResult,
           HttpServletResponse httpResponse,
           Map<String, Object> backpack)
           throws IOException {
   }
}