// Path: src/main/java/org/turbogwt/net/serialization/client/DeserializationContext.java
// public abstract class DeserializationContext {
// 
//     private final ContainerFactoryManager containerFactoryManager;
// 
//     public DeserializationContext(ContainerFactoryManager containerFactoryManager) {
//         this.containerFactoryManager = containerFactoryManager;
//     }
// 
//     public <C extends Collection> C getContainerInstance(Class<C> type) {
//         final Factory<C> factory = containerFactoryManager.getFactory(type);
//         if (factory == null)
//             throw new UnableToDeserializeException("Could not get container instance because there's no factory " +
//                     "registered in the requestor.");
//         return factory.get();
//     }
// 
//     protected ContainerFactoryManager getContainerFactoryManager() {
//         return containerFactoryManager;
//     }
// }
// 
// Path: src/main/java/org/turbogwt/net/serialization/client/Deserializer.java
// public interface Deserializer<T> {
// 
//     /**
//      * Method for accessing type of the Object this deserializer can handle.
//      *
//      * @return The class which this deserializer can deserialize
//      */
//     Class<T> handledType();
// 
//     /**
//      * Tells the content-type patterns which this deserializer handles.
//      * <p/>
//      * 
//      * E.g., a deserializer for JSON can return {"application/json", "application/javascript"}.<br>
//      * If you want to create a deserializer for any content-type just return "*&#47;*".
//      * 
//      * @return The content-type patterns handled by this deserializer.
//      */
//     String[] accept();
// 
//     /**
//      * Deserialize the plain text into an object of type T.
//      *
//      * @param response  Http response body content
//      * @param context   Context of deserialization
//      *
//      * @return The object deserialized
//      */
//     T deserialize(String response, DeserializationContext context);
// 
//     /**
//      * Deserialize the plain text into a collection T.
//      * <p/>
//      * 
//      * The collection instance can be retrieved from its {@link org.turbogwt.core.util.shared.Factory},
//      * obtained in {@link ContainerFactoryManager#getFactory}.<br>
//      * The ContainerFactoryManager can be retrieved from {@link DeserializationContext#getContainerInstance(Class)}.
//      *
//      * @param collectionType    The class of the collection
//      * @param response          Http response body content
//      * @param context           Context of deserialization
//      *
//      * @return The object deserialized
//      */
//     <C extends Collection<T>> C deserializeAsCollection(Class<C> collectionType, String response,
//                                                         DeserializationContext context);
// }


import java.util.Collection;
import org.turbogwt.net.serialization.client.DeserializationContext;
import org.turbogwt.net.serialization.client.Deserializer;
/*
 * Copyright 2014 Grow Bit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.turbogwt.net.serialization.client.misc;



/**
 * Pass-through deserializer for plain text and generic stuff.
 *
 * @author Danilo Reinert
 */
public class TextDeserializer implements Deserializer<String> {

    public static String[] ACCEPT_PATTERNS = new String[]{"text/plain", "*/*"};

    private static final TextDeserializer INSTANCE = new TextDeserializer();

    public static TextDeserializer getInstance() {
        return INSTANCE;
    }

    /**
     * Method for accessing type of Objects this deserializer can handle.
     *
     * @return The class which this deserializer can deserialize
     */
    @Override
    public Class<String> handledType() {
        return String.class;
    }

    /**
     * Informs the content type this serializer handle.
     *
     * @return The content type handled by this serializer.
     */
    @Override
    public String[] accept() {
        return ACCEPT_PATTERNS;
    }

    /**
     * Deserialize the plain text into an object of type T.
     *
     * @param response Http response body content
     * @param context  Context of deserialization
     *
     * @return The object deserialized
     */
    @Override
    public String deserialize(String response, DeserializationContext context) {
        return response;
    }

    /**
     * Deserialize the plain text into an object of type T.
     *
     * @param collectionType The class of the collection
     * @param response       Http response body content
     * @param context        Context of deserialization
     *
     * @return The object deserialized
     */
    @Override
    public <C extends Collection<String>> C deserializeAsCollection(Class<C> collectionType, String response,
                                                                    DeserializationContext context) {
        final C col = context.getContainerInstance(collectionType);
// Path: src/main/java/org/turbogwt/net/serialization/client/DeserializationContext.java
// public abstract class DeserializationContext {
// 
//     private final ContainerFactoryManager containerFactoryManager;
// 
//     public DeserializationContext(ContainerFactoryManager containerFactoryManager) {
//         this.containerFactoryManager = containerFactoryManager;
//     }
// 
//     public <C extends Collection> C getContainerInstance(Class<C> type) {
//         final Factory<C> factory = containerFactoryManager.getFactory(type);
//         if (factory == null)
//             throw new UnableToDeserializeException("Could not get container instance because there's no factory " +
//                     "registered in the requestor.");
//         return factory.get();
//     }
// 
//     protected ContainerFactoryManager getContainerFactoryManager() {
//         return containerFactoryManager;
//     }
// }
// 
// Path: src/main/java/org/turbogwt/net/serialization/client/Deserializer.java
// public interface Deserializer<T> {
// 
//     /**
//      * Method for accessing type of the Object this deserializer can handle.
//      *
//      * @return The class which this deserializer can deserialize
//      */
//     Class<T> handledType();
// 
//     /**
//      * Tells the content-type patterns which this deserializer handles.
//      * <p/>
//      * 
//      * E.g., a deserializer for JSON can return {"application/json", "application/javascript"}.<br>
//      * If you want to create a deserializer for any content-type just return "*&#47;*".
//      * 
//      * @return The content-type patterns handled by this deserializer.
//      */
//     String[] accept();
// 
//     /**
//      * Deserialize the plain text into an object of type T.
//      *
//      * @param response  Http response body content
//      * @param context   Context of deserialization
//      *
//      * @return The object deserialized
//      */
//     T deserialize(String response, DeserializationContext context);
// 
//     /**
//      * Deserialize the plain text into a collection T.
//      * <p/>
//      * 
//      * The collection instance can be retrieved from its {@link org.turbogwt.core.util.shared.Factory},
//      * obtained in {@link ContainerFactoryManager#getFactory}.<br>
//      * The ContainerFactoryManager can be retrieved from {@link DeserializationContext#getContainerInstance(Class)}.
//      *
//      * @param collectionType    The class of the collection
//      * @param response          Http response body content
//      * @param context           Context of deserialization
//      *
//      * @return The object deserialized
//      */
//     <C extends Collection<T>> C deserializeAsCollection(Class<C> collectionType, String response,
//                                                         DeserializationContext context);
// }


// Path: src/main/java/org/turbogwt/net/serialization/client/misc/TextDeserializer.java
import java.util.Collection;
import org.turbogwt.net.serialization.client.DeserializationContext;
import org.turbogwt.net.serialization.client.Deserializer;

/*
 * Copyright 2014 Grow Bit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.turbogwt.net.serialization.client.misc;



/**
 * Pass-through deserializer for plain text and generic stuff.
 *
 * @author Danilo Reinert
 */
public class TextDeserializer implements Deserializer<String> {

    public static String[] ACCEPT_PATTERNS = new String[]{"text/plain", "*/*"};

    private static final TextDeserializer INSTANCE = new TextDeserializer();

    public static TextDeserializer getInstance() {
        return INSTANCE;
    }

    /**
     * Method for accessing type of Objects this deserializer can handle.
     *
     * @return The class which this deserializer can deserialize
     */
    @Override
    public Class<String> handledType() {
        return String.class;
    }

    /**
     * Informs the content type this serializer handle.
     *
     * @return The content type handled by this serializer.
     */
    @Override
    public String[] accept() {
        return ACCEPT_PATTERNS;
    }

    /**
     * Deserialize the plain text into an object of type T.
     *
     * @param response Http response body content
     * @param context  Context of deserialization
     *
     * @return The object deserialized
     */
    @Override
    public String deserialize(String response, DeserializationContext context) {
        return response;
    }

    /**
     * Deserialize the plain text into an object of type T.
     *
     * @param collectionType The class of the collection
     * @param response       Http response body content
     * @param context        Context of deserialization
     *
     * @return The object deserialized
     */
    @Override
    public <C extends Collection<String>> C deserializeAsCollection(Class<C> collectionType, String response,
                                                                    DeserializationContext context) {
        final C col = context.getContainerInstance(collectionType);
        col.add(response);