package net.peierls.restlet.example;

import com.google.inject.*;
import com.google.inject.name.Named;

import org.restlet.*;
import org.restlet.data.*;
import org.restlet.resource.*;

/**
 * Resource which has only one representation.
 *
 */
public class HelloWorldResource extends Resource {

    static final String HELLO_MSG = "hello.message";

    @Inject public HelloWorldResource(@Named(HELLO_MSG) String msg,
                                      Request request,
                                      Response response,
                                      Context context) {
        super(context, request, response);

        this.msg = msg;

        // This representation has only one type of representation.
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));
    }

    /**
     * Returns a full representation for a given variant.
     */
    @Override public Representation represent(Variant variant) throws ResourceException {
        Representation representation = new StringRepresentation(msg, MediaType.TEXT_PLAIN);
        return representation;
    }

    private final String msg;
}