Package br.com.caelum.restfulie.mediatype

Source Code of br.com.caelum.restfulie.mediatype.MediaTypes

package br.com.caelum.restfulie.mediatype;

import java.util.LinkedList;

import br.com.caelum.restfulie.RestfulieException;

/**
* A media type registry.<br/>
* Invoke register to add a new media types. Whenever two media type handlers can
* handle the same media type, the latest added will be used to resolve the
* conflict.
*
* @author guilherme silveira
*/
public class MediaTypes {

  public static final String XML = "application/xml";

  private final LinkedList<MediaType> types = new LinkedList<MediaType>();

  public MediaType forContentType(String searching) {
    for (MediaType type : types) {
      if (type.answersTo(searching)) {
        return type;
      }
    }
    throw new RestfulieException("Unsupported media type '" + searching + "'");
  }

  public void register(MediaType mediaType) {
    this.types.addFirst(mediaType);
  }

}
TOP

Related Classes of br.com.caelum.restfulie.mediatype.MediaTypes

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.