package com.juliaaano.payload;

import com.juliaaano.payload.cache.CachedProviderStrategy;
import com.juliaaano.payload.json.JsonProviderStrategy;
import com.juliaaano.payload.xml.XmlProviderStrategy;

import static java.lang.String.format;

/**
 * Entry-point for payload conversion (serialization/deserialization).
 *
 * @author Juliano Boesel Mohr
 */
public enum MediaType {

    JSON("application/json",
            new GenericPayloadFactory(
                    new CachedProviderStrategy(
                            new JsonProviderStrategy()
                    )
            )
    ),

    XML("application/xml",
            new GenericPayloadFactory(
                    new CachedProviderStrategy(
                            new XmlProviderStrategy()
                    )
            )
    );

    private final String mediaType;

    private final PayloadFactory payloadFactory;

    MediaType(final String mediaType, final PayloadFactory payloadFactory) {

        this.mediaType = mediaType;
        this.payloadFactory = payloadFactory;
    }

    public static MediaType of(String mediaType) {

        mediaType = (mediaType != null) ? mediaType : "";

        if (mediaType.toLowerCase().contains("application/json"))
            return JSON;
        else if (mediaType.toLowerCase().contains("application/xml"))
            return XML;
        else
            throw new InvalidMediaTypeException(format("Invalid media type %s.", mediaType));
    }

    public PayloadFactory payload() {

        return payloadFactory;
    }

    @Override
    public String toString() {

        return mediaType;
    }
}

@@ -280,40 +280,635 @@
 sion
- (serialization/deserialization)
+.%0A *%0A * %3Cp%3EA MediaType contains an enumeration of represented %3Ci%3Emedia types%3C/i%3E%0A * that are capable to transform a literal %7B@link String%7D data into a Java%0A * object and vice-versa. A process also known as object data binding.%0A *%0A * %3Cp%3E%3Cstrong%3EExample:%3C/strong%3E%0A *%0A * %3Cblockquote%3E%3Cpre%3E%0A * JSON.payload().newInstance(new MyObject()); // From object to JSON%0A * JSON.payload().newInstance(%22%7B%7D%22, MyObject.class); // From JSON to object%0A * %3C/pre%3E%3C/blockquote%3E%0A *%0A * A MediaType, in this context, has the same semantics as the internet MIME%0A * type. Use it to retrieve %7B@link Payload%7D with the corresponding%0A * %7B@link PayloadFactory%7D
 .%0A *
@@ -964,24 +964,87 @@
 ediaType %7B%0A%0A
+    /**%0A     * The %3Ci%3Eapplication/json%3C/i%3E media type.%0A     */%0A
     JSON(%22ap
@@ -1246,16 +1246,78 @@
     ),%0A%0A
+    /**%0A     * The %3Ci%3Eapplication/xml%3C/i%3E media type.%0A     */%0A
     XML(
@@ -1782,490 +1782,1475 @@
     
-public static MediaType of(String mediaType) %7B%0A%0A        mediaType = (mediaType != null) ? mediaType : %22%22;%0A%0A        if (mediaType.toLowerCase().contains(%22application/json%22))%0A            return JSON;%0A        else if (mediaType.toLowerCase().contains(%22application/xml%22))%0A            return XML;%0A        else%0A            throw new InvalidMediaTypeException(format(%22Invalid media type %25s.%22, mediaType));%0A    %7D%0A%0A    public PayloadFactory payload() %7B%0A%0A        return payloadFactory;%0A    %7D%0A
+/**%0A     * Retrieves the MediaType for the given media type string.%0A     *%0A     * %3Cp%3EThe given mediaType string is based on the internet standards (e.g.%0A     * application/json).%0A     *%0A     * @param mediaType the representation of the MediaType based on internet%0A     *                  standards (e.g. application/xml).%0A     *%0A     * @return the MediaType enum instance%0A     *%0A     * @throws InvalidMediaTypeException if no corresponding type is found for%0A     *         the given mediaType%0A     */%0A    public static MediaType of(String mediaType) %7B%0A%0A        mediaType = (mediaType != null) ? mediaType : %22%22;%0A%0A        if (mediaType.toLowerCase().contains(%22application/json%22))%0A            return JSON;%0A        else if (mediaType.toLowerCase().contains(%22application/xml%22))%0A            return XML;%0A        else%0A            throw new InvalidMediaTypeException(format(%22Invalid media type %25s.%22, mediaType));%0A    %7D%0A%0A    /**%0A     * Gets the %7B@link PayloadFactory%7D for this MediaType.%0A     *%0A     * %3Cp%3E%7B@link Payload%7D cannot be created without a factory, therefore use it%0A     * to instantiate new payloads.%3C/p%3E%0A     *%0A     * @return the %7B@link PayloadFactory%7D for this MediaType%0A     */%0A    public PayloadFactory payload() %7B%0A%0A        return payloadFactory;%0A    %7D%0A%0A    /**%0A     * Returns the representation of this enum constant in the form of a%0A     * internet based media type (e.g. application/json).%0A     *%0A     * @return the representation of this enum constant%0A     */
 %0A   

Add javadoc to MediaType