ContentHandlerFactory.cs 1.42 KB
//*************************************************************************************************
// ContentHandlerFactory.cs
// Owner: Mahipal Kante
//
// Creates appropriate handler for a given content type
//
// Copyright(c) Microsoft Corporation, 2010
//*************************************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WebTest.WebService.Plugin.Runtime
{
    /// <summary>
    /// Creates appropriate handler for a given content type
    /// </summary>
    public class ContentHandlerFactory
    {
        /// <summary>
        /// Creates appropriate handler for a given content type
        /// </summary>
        /// <param name="contentType">content type</param>
        /// <returns></returns>
        public static ContentHandler GetHandler(string contentType)
        {
            if (contentType.ToLower().Contains("msbin1"))
            {
                return new Msbin1ContentHandler(contentType.ToLower().Contains("soap"));
            }
            else if (contentType.ToLower().Contains("json"))
            {
                return new JsonContentHandler();
            }
            else if (contentType.ToLower().Contains("xml"))
            {
                return new ContentHandler();
            }
            else
            {
                return null;
            }
        }
    }
}